void slider::draw_contents() { surface image(state_ != NORMAL ? highlightedImage_ : image_); if (image == NULL) return; SDL_Color line_color = font::NORMAL_COLOR; if (!enabled()) { image = greyscale_image(image); line_color = font::DISABLED_COLOR; } SDL_Rect const &loc = location(); if (image->w >= loc.w) return; surface screen = video().getSurface(); SDL_Rect line_rect = create_rect(loc.x + image->w / 2 , loc.y + loc.h / 2 , loc.w - image->w , 1); sdl_fill_rect(screen, &line_rect, SDL_MapRGB(screen->format, line_color.r, line_color.g, line_color.b)); SDL_Rect const &slider = slider_area(); video().blit_surface(slider.x, slider.y, image); }
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); }
surface gs_modification::operator()(const surface& src) const { return greyscale_image(src); }
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(); } }