void button::draw_contents() { surface image = image_; const int image_w = image_->w; int offset = 0; switch(state_) { case ACTIVE: image = activeImage_; break; case PRESSED: image = pressedImage_; if (type_ == TYPE_PRESS) offset = 1; break; case PRESSED_ACTIVE: image = pressedActiveImage_; break; default: break; } SDL_Rect const &loc = location(); SDL_Rect clipArea = loc; const int texty = loc.y + loc.h / 2 - textRect_.h / 2 + offset; int textx; if (type_ != TYPE_CHECK) textx = loc.x + image->w / 2 - textRect_.w / 2 + offset; else { clipArea.w += image_w + checkbox_horizontal_padding; textx = loc.x + image_w + checkbox_horizontal_padding / 2; } SDL_Color button_color = font::BUTTON_COLOR; if (!enabled()) { static const Uint32 disabled_btn_color = 0xAAAAAA; static const double disabled_btn_adjust = 0.18; image = blend_surface(greyscale_image(image), disabled_btn_adjust, disabled_btn_color); button_color = font::GRAY_COLOR; } video().blit_surface(loc.x, loc.y, image); if (type_ != TYPE_IMAGE){ clipArea.x += offset; clipArea.y += offset; clipArea.w -= 2*offset; clipArea.h -= 2*offset; font::draw_text(&video(), clipArea, font_size, button_color, label_, textx, texty); } update_rect(loc); }
inline void blend_image(const surface& src, tblend_functor functor) { for(Uint32 color = 0x00FF0000; color != 0x00000000; color >>= 8) { for(int i = 0xf; i < 0x100; i += 0x10) { const surface dst = blend_surface(src, i / 255., color); if(functor) { functor(dst, i, color); } } } }
/**************************************************************************** Draw a full sprite onto the canvas. If "fog" is specified draw it with fog. ****************************************************************************/ void canvas_put_sprite_fogged(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *psprite, bool fog, int fog_x, int fog_y) { SDL_Rect dst = {canvas_x, canvas_y, 0, 0}; if (fog) { SDL_Surface *tmp_surf = blend_surface(GET_SURF(psprite), 160); alphablit(tmp_surf, NULL, pcanvas->surf, &dst); FREESURFACE(tmp_surf); } else { canvas_put_sprite_full(pcanvas, canvas_x, canvas_y, psprite); } }
static void blend(surface& surf, const std::string& parameters) { float amount; unsigned color; const int count = sscanf(parameters.c_str(), "%f,%x", &amount, &color); if(count != 2) { std::cerr << "Error: Arguments to blend »" << parameters << "« are not compatible.\n"; throw texit(EXIT_FAILURE); } surf = blend_surface(surf, amount, color); }
surface blend_modification::operator()(const surface& src) const { return blend_surface(src, a_, display::rgb(r_, g_, b_)); }
void button::load_images() { std::string size_postfix; switch (location().h) { case 25: size_postfix = "_25"; break; case 30: size_postfix = "_30"; break; case 60: size_postfix = "_60"; break; default: break; } surface button_image(image::get_image(button_image_name_ + ".png")); surface pressed_image(image::get_image(button_image_name_ + "-pressed.png")); surface active_image(image::get_image(button_image_name_ + "-active.png")); surface disabled_image; if (file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png")) disabled_image.assign((image::get_image(button_image_name_ + "-disabled.png"))); surface pressed_disabled_image, pressed_active_image, touched_image; static const Uint32 disabled_btn_color = 0xAAAAAA; static const double disabled_btn_adjust = 0.18; if (!button_overlay_image_name_.empty()) { overlayImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + ".png")); overlayPressedImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png")); if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png")) overlayActiveImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-active.png")); if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-pressed-disabled.png")) overlayPressedDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-pressed-disabled.png")); if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + "_30-disabled.png")) overlayDisabledImage_.assign(image::get_image(button_overlay_image_name_ + "_30-disabled.png")); if (overlayDisabledImage_.null()) overlayDisabledImage_ = blend_surface(greyscale_image(overlayImage_), disabled_btn_adjust, disabled_btn_color); if (overlayPressedDisabledImage_.null()) overlayPressedDisabledImage_ = blend_surface(greyscale_image(overlayPressedImage_), disabled_btn_adjust, disabled_btn_color); } else { overlayImage_.assign(NULL); } if (disabled_image == NULL) { disabled_image = blend_surface(greyscale_image(button_image), disabled_btn_adjust, disabled_btn_color); } if (pressed_image.null()) pressed_image.assign(button_image); if (active_image.null()) active_image.assign(button_image); if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) { touched_image.assign(image::get_image(button_image_name_ + "-touched.png")); if (touched_image.null()) touched_image.assign(pressed_image); pressed_active_image.assign(image::get_image(button_image_name_ + "-active-pressed.png")); if (pressed_active_image.null()) pressed_active_image.assign(pressed_image); pressed_disabled_image.assign(image::get_image(button_image_name_ + "-disabled-pressed.png")); if (pressed_disabled_image.null()) pressed_disabled_image = blend_surface(greyscale_image(pressed_image), disabled_btn_adjust, disabled_btn_color); } if (button_image.null()) { ERR_DP << "error initializing button!\n"; throw error(); } base_height_ = button_image->h; base_width_ = button_image->w; if (type_ != TYPE_IMAGE) { set_label(label_); } if(type_ == TYPE_PRESS || type_ == TYPE_TURBO) { image_.assign(scale_surface(button_image,location().w,location().h)); pressedImage_.assign(scale_surface(pressed_image,location().w,location().h)); activeImage_.assign(scale_surface(active_image,location().w,location().h)); disabledImage_.assign(scale_surface(disabled_image,location().w,location().h)); } else { image_.assign(scale_surface(button_image,button_image->w,button_image->h)); activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h)); disabledImage_.assign(scale_surface(disabled_image,button_image->w,button_image->h)); pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h)); if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) { pressedDisabledImage_.assign(scale_surface(pressed_disabled_image,button_image->w,button_image->h)); pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h)); touchedImage_.assign(scale_surface(touched_image, button_image->w, button_image->h)); } } if (type_ == TYPE_IMAGE){ calculate_size(); } }