GUIImage::GUIImage(const GUIImage& image_){ if (image_.sdl_impl == 0) throw Error("Cannot form a GUIImage from bad image"); SDL_Surface* temp = create_SDL_Surface(image_.getw(), image_.geth()); if (!temp){ throw Error("Could not copy GUIImage. Not enough memory."); } sdl_impl = SDL_DisplayFormat(temp); if (!sdl_impl){ throw Error("Could not copy GUIImage. Not enough memory."); } Uint32 colorkey = image_.sdl_impl->format->colorkey; Uint8 alpha = image_.sdl_impl->format->alpha; // First fill background with the clear color, then display and re-clear. SDL_FillRect(sdl_impl, 0, colorkey); display_image(image_.sdl_impl, sdl_impl, 0, 0, 1); if (image_.is_alpha /*|| alpha != 0*/) { //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent SDL_SetColorKey(sdl_impl, SDL_SRCCOLORKEY, colorkey); } }
GUIImage::GUIImage(SDL_Surface* surface) :is_alpha(false) { if (surface == 0) throw Error("Cannot form a GUIImage from NULL surface!"); sdl_impl = surface; }
GUIImage GUIImage::create_blank(int w, int h){ GUIImage result; result.sdl_impl = create_SDL_Surface(w, h); if (!result.sdl_impl){ throw Error("Could not create blank GUIImage. Not enough memory."); } return result; }
GUIImage::GUIImage(int w, int h, bool alpha, const SDL_Color& color_key) { SDL_Surface* temp = create_SDL_Surface(w, h); if (!temp){ throw Error("Could not create GUIImage. Not enough memory."); } sdl_impl = SDL_DisplayFormat(temp); SDL_FreeSurface(temp); if (!sdl_impl){ throw Error("Could not create GUIImage. Not enough memory."); } if (alpha){ //Map the color key Uint32 colorkey = SDL_MapRGB(sdl_impl->format, color_key.r, color_key.g, color_key.b); //Set all pixels of color R 0xFF, G 0, B 0xFF to be transparent SDL_SetColorKey(sdl_impl, SDL_SRCCOLORKEY, colorkey ); } }