18Uint32 getpixel(CST_Surface *surface, 
int x, 
int y)
 
   20    int bpp = surface->format->BytesPerPixel;
 
   22    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
 
   35        if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
 
   36            return p[0] << 16 | p[1] << 8 | p[2];
 
   38            return p[0] | p[1] << 8 | p[2] << 16;
 
   56    CST_Renderer* renderer = getRenderer();
 
   59    CST_Texture *texture = CST_CreateTextureFromSurface(renderer, surface, 
true);
 
   60    SDL_SetTextureBlendMode(texture, 
blendMode);
 
   65    auto pixelcolor = getpixel(surface, 0, 0);
 
   69    CST_QueryTexture(texture, &
texW, &texH);
 
  124    rect.w = this->
width;
 
  125    rect.h = this->height;
 
  127    if (CST_isRectOffscreen(&rect))
 
  130    CST_Renderer* renderer = getRenderer();
 
  134        CST_SetDrawBlend(RootDisplay::renderer, 
false);
 
  142            color = (CST_Color){0xFF,0xFF,0xFF,0xFF};
 
  144        CST_SetDrawColor(renderer, color);
 
  145        CST_FillRect(renderer, &rect);
 
  152            rect.w = (
texW * rect.h) / texH;
 
  158            rect.h = (texH * rect.w) / 
texW;
 
  162        rect.x += (
width - rect.w) / 2;
 
  163        rect.y += (height - rect.h) / 2;
 
  168        CST_SetQualityHint(
"best");
 
  169        CST_RenderCopyRotate(renderer, 
mTexture, NULL, &rect, this->
angle);
 
  174        CST_RenderCopy(renderer, 
mTexture, NULL, &rect);
 
  175        SDL_SetTextureColorMod(
mTexture, 0xFF, 0xFF, 0xFF);
 
  178        CST_RenderCopy(renderer, 
mTexture, NULL, &rect);
 
  188Texture* Texture::setSize(
int w, 
int h)
 
  213    CST_Texture* target = SDL_CreateTexture(getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 
texW, texH);
 
  218    SDL_SetRenderTarget(getRenderer(), target);
 
  221    SDL_RenderCopy(getRenderer(), 
mTexture, NULL, NULL);
 
  224    SDL_SetRenderTarget(getRenderer(), NULL);
 
  228    return CST_SavePNG(target, path.c_str());
 
  234        CST_Surface *surface = IMG_Load(path.c_str());
 
  236        CST_FreeSurface(surface);
 
bool hidden
whether this element should skip rendering or not
 
virtual void render(Element *parent)
display the current state of the display
 
bool useColorMask
whether or not to overlay a color mask on top of this element
 
double angle
rotation angle in degrees
 
CST_Color maskColor
The color to overlay on top.
 
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
 
Element * parent
the parent element (can sometimes be null if it isn't set)
 
void getTextureSize(int *w, int *h)
Return texture's original size.
 
bool loadFromSurfaceSaveToCache(std::string &key, CST_Surface *surface)
Loads the texture from a surface and saves the results in caches Returns true if successful.
 
static std::unordered_map< std::string, TextureData > texCache
Cache previously displayed textures.
 
SDL_BlendMode blendMode
Blend mode to use for this texture.
 
CST_Color texFirstPixel
The color of the first pixel.
 
int texW
The size of the texture.
 
void resize(int w, int h)
Resizes the texture.
 
bool loadFromCache(std::string &key)
Loads the texture from caches Returns true if successful.
 
void clear(void)
Reinitialize Texture Resets texture content, size and color.
 
void render(Element *parent)
Renders the texture.
 
bool saveTo(std::string &path)
save this texture to the given file path as a PNG
 
void setScaleMode(TextureScaleMode mode)
Sets texture scaling mode.
 
bool loadFromSurface(CST_Surface *surface)
Loads the texture from a surface Returns true if successful.
 
TextureScaleMode texScaleMode
Texture's scaling mode.
 
void loadPath(std::string &path, bool forceReload=false)
update and load or reload the texture
 
CST_Texture * mTexture
The actual texture.