void game_display::new_turn() { const time_of_day& tod = tod_manager_.get_time_of_day(); if( !first_turn_) { const time_of_day& old_tod = tod_manager_.get_previous_time_of_day(); if(old_tod.image_mask != tod.image_mask) { const surface old_mask(image::get_image(old_tod.image_mask,image::SCALED_TO_HEX)); const surface new_mask(image::get_image(tod.image_mask,image::SCALED_TO_HEX)); const int niterations = static_cast<int>(10/turbo_speed()); const int frame_time = 30; const int starting_ticks = SDL_GetTicks(); for(int i = 0; i != niterations; ++i) { if(old_mask != NULL) { const fixed_t proportion = ftofxp(1.0) - fxpdiv(i,niterations); tod_hex_mask1.assign(adjust_surface_alpha(old_mask,proportion)); } if(new_mask != NULL) { const fixed_t proportion = fxpdiv(i,niterations); tod_hex_mask2.assign(adjust_surface_alpha(new_mask,proportion)); } invalidate_all(); draw(); const int cur_ticks = SDL_GetTicks(); const int wanted_ticks = starting_ticks + i*frame_time; if(cur_ticks < wanted_ticks) { SDL_Delay(wanted_ticks - cur_ticks); } } } tod_hex_mask1.assign(NULL); tod_hex_mask2.assign(NULL); } first_turn_ = false; display::update_tod(); invalidate_all(); draw(); }
void mouse_action_starting_position::set_mouse_overlay(editor_display& disp) { surface image = image::get_image("editor/tool-overlay-starting-position.png"); Uint8 alpha = 196; int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
void mouse_action::set_terrain_mouse_overlay(editor_display& disp, const t_translation::t_terrain & fg, const t_translation::t_terrain & bg) { surface image_fg(image::get_image(disp.get_map().get_terrain_info(fg).editor_image())); surface image_bg(image::get_image(disp.get_map().get_terrain_info(bg).editor_image())); if (image_fg == nullptr || image_bg == nullptr) { ERR_ED << "Missing terrain icon" << std::endl; disp.set_mouseover_hex_overlay(nullptr); return; } // Create a transparent surface of the right size. surface image = create_neutral_surface(image_fg->w, image_fg->h); // For efficiency the size of the tile is cached. // We assume all tiles are of the same size. // The zoom factor can change, so it's not cached. // NOTE: when zooming and not moving the mouse, there are glitches. // Since the optimal alpha factor is unknown, it has to be calculated // on the fly, and caching the surfaces makes no sense yet. static const fixed_t alpha = 196; static const int size = image_fg->w; static const int half_size = size / 2; static const int quarter_size = size / 4; static const int offset = 2; static const int new_size = half_size - 2; // Blit left side image_fg = scale_surface(image_fg, new_size, new_size); SDL_Rect rcDestLeft = sdl::create_rect(offset, quarter_size, 0, 0); blit_surface ( image_fg, nullptr, image, &rcDestLeft ); // Blit right side image_bg = scale_surface(image_bg, new_size, new_size); SDL_Rect rcDestRight = sdl::create_rect(half_size, quarter_size, 0, 0); blit_surface ( image_bg, nullptr, image, &rcDestRight ); //apply mask so the overlay is contained within the mouseover hex image = mask_surface(image, image::get_hexmask()); // Add the alpha factor image = adjust_surface_alpha(image, alpha); // scale the image const int zoom = disp.hex_size(); if (zoom != game_config::tile_size) { image = scale_surface(image, zoom, zoom); } // Set as mouseover disp.set_mouseover_hex_overlay(image); }
void mouse_action::set_terrain_mouse_overlay(editor_display& disp, t_translation::t_terrain fg, t_translation::t_terrain bg) { surface image_fg(image::get_image("terrain/" + disp.get_map().get_terrain_info(fg).editor_image() + ".png")); surface image_bg(image::get_image("terrain/" + disp.get_map().get_terrain_info(bg).editor_image() + ".png")); if (image_fg == NULL || image_bg == NULL) { ERR_ED << "Missing terrain icon\n"; disp.set_mouseover_hex_overlay(NULL); return; } // Create a transparent surface of the right size. surface image = create_compatible_surface(image_fg, image_fg->w, image_fg->h); SDL_FillRect(image,NULL,SDL_MapRGBA(image->format,0,0,0, 0)); // For efficiency the size of the tile is cached. // We assume all tiles are of the same size. // The zoom factor can change, so it's not cached. // NOTE: when zooming and not moving the mouse, there are glitches. // Since the optimal alpha factor is unknown, it has to be calculated // on the fly, and caching the surfaces makes no sense yet. static const Uint8 alpha = 196; static const int size = image_fg->w; static const int half_size = size / 2; static const int quarter_size = size / 4; static const int offset = 2; static const int new_size = half_size - 2; const int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Blit left side image_fg = scale_surface(image_fg, new_size, new_size); SDL_Rect rcDestLeft = { offset, quarter_size, 0, 0 }; SDL_BlitSurface ( image_fg, NULL, image, &rcDestLeft ); // Blit left side image_bg = scale_surface(image_bg, new_size, new_size); SDL_Rect rcDestRight = { half_size, quarter_size, 0, 0 }; SDL_BlitSurface ( image_bg, NULL, image, &rcDestRight ); //apply mask so the overlay is contained within the mouseover hex surface mask(image::get_image("terrain/alphamask.png")); image = mask_surface(image, mask); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); // Set as mouseover disp.set_mouseover_hex_overlay(image); }
void mouse_action_select::set_mouse_overlay(editor_display& disp) { surface image; if (has_shift_modifier()) { image = image::get_image("editor/tool-overlay-select-wand.png"); } else { image = image::get_image("editor/tool-overlay-select-brush.png"); } Uint8 alpha = 196; int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
void mouse_action_village::set_mouse_overlay(editor_display& disp) { surface image60 = image::get_image("icons/action/editor-tool-village_60.png"); //TODO avoid hardcoded hex field size surface image = create_neutral_surface(72,72); SDL_Rect r = sdl::create_rect(6, 6, 0, 0); blit_surface(image60, NULL, image, &r); Uint8 alpha = 196; int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
void mouse_action_unit::set_unit_mouse_overlay(editor_display& disp, const unit_type& u) { std::stringstream filename; filename << u.image() << "~RC(" << u.flag_rgb() << '>' << team::get_side_color_index(disp.viewing_side()) << ')'; surface image(image::get_image(filename.str())); Uint8 alpha = 196; //TODO don't hardcode int size = 72; //int size = image->w; int zoom = static_cast<int>(size * disp.get_zoom_factor()); // Add the alpha factor and scale the image image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom); disp.set_mouseover_hex_overlay(image); }
surface o_modification::operator()(const surface& src) const { return adjust_surface_alpha(src, ftofxp(opacity_)); }
surface floating_label::create_surface() { if(surf_.null()) { font::pango_text text; text.set_foreground_color(color_); text.set_font_size(font_size_); text.set_maximum_width(width_ < 0 ? clip_rect_.w : width_); text.set_maximum_height(height_ < 0 ? clip_rect_.h : height_, true); // ignore last '\n' if(!text_.empty() && *(text_.rbegin()) == '\n') { text.set_text(std::string(text_.begin(), text_.end() - 1), use_markup_); } else { text.set_text(text_, use_markup_); } surface foreground = text.render(); if(foreground == nullptr) { ERR_FT << "could not create floating label's text" << std::endl; return nullptr; } // combine foreground text with its background if(bgalpha_ != 0) { // background is a dark tooltip box surface background = create_neutral_surface(foreground->w + border_ * 2, foreground->h + border_ * 2); if(background == nullptr) { ERR_FT << "could not create tooltip box" << std::endl; return surf_ = foreground; } uint32_t color = SDL_MapRGBA(foreground->format, bgcolor_.r, bgcolor_.g, bgcolor_.b, bgalpha_); sdl::fill_surface_rect(background, nullptr, color); // we make the text less transparent, because the blitting on the // dark background will darken the anti-aliased part. // This 1.13 value seems to restore the brightness of version 1.4 // (where the text was blitted directly on screen) adjust_surface_alpha(foreground, ftofxp(1.13)); SDL_Rect r{border_, border_, 0, 0}; adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE); sdl_blit(foreground, nullptr, background, &r); surf_ = background; } else { // background is blurred shadow of the text surface background = create_neutral_surface(foreground->w + 4, foreground->h + 4); sdl::fill_surface_rect(background, nullptr, 0); SDL_Rect r{2, 2, 0, 0}; sdl_blit(foreground, nullptr, background, &r); background = shadow_image(background); if(background == nullptr) { ERR_FT << "could not create floating label's shadow" << std::endl; return surf_ = foreground; } sdl_blit(foreground, nullptr, background, &r); surf_ = background; } } return surf_; }
surface adjust_alpha_modification::operator()(const surface & src) const { return adjust_surface_alpha(src, amount_); }
void textbox::draw_contents() { SDL_Rect const &loc = inner_location(); surface surf = video().getSurface(); draw_solid_tinted_rectangle(loc.x,loc.y,loc.w,loc.h,0,0,0, focus(NULL) ? alpha_focus_ : alpha_, surf); SDL_Rect src; if(text_image_ == NULL) { update_text_cache(true); } if(text_image_ != NULL) { src.y = yscroll_; src.w = std::min<size_t>(loc.w,text_image_->w); src.h = std::min<size_t>(loc.h,text_image_->h); src.x = text_pos_; SDL_Rect dest = screen_area(); dest.x = loc.x; dest.y = loc.y; // Fills the selected area if(enabled() && is_selection()) { const int start = std::min<int>(selstart_,selend_); const int end = std::max<int>(selstart_,selend_); int startx = char_x_[start]; int starty = char_y_[start]; const int endx = char_x_[end]; const int endy = char_y_[end]; while(starty <= endy) { const size_t right = starty == endy ? endx : text_image_->w; if(right <= size_t(startx)) { break; } SDL_Rect rect = create_rect(loc.x + startx , loc.y + starty - src.y , right - startx , line_height_); const clip_rect_setter clipper(surf, &loc); Uint32 color = SDL_MapRGB(surf->format, 0, 0, 160); fill_rect_alpha(rect, color, 140, surf); starty += int(line_height_); startx = 0; } } if(enabled()) { sdl_blit(text_image_, &src, surf, &dest); } else { // HACK: using 30% opacity allows white text to look as though it is grayed out, // while not changing any applicable non-grayscale AA. Actual colored text will // not look as good, but this is not currently a concern since GUI1 textboxes // are not used much nowadays, and they will eventually all go away. sdl_blit(adjust_surface_alpha(text_image_, ftofxp(0.3)), &src, surf, &dest); } } draw_cursor((cursor_pos_ == 0 ? 0 : cursor_pos_ - 1), video()); update_rect(loc); }