Blurring is back.
This time, menu styles are controlled by a structure which presently contains dtem of the panel component names and a blur radius. This design is extensible; we can easily add controls for other style elements now.
This commit is contained in:
parent
1908601672
commit
fa74853a85
13 changed files with 65 additions and 59 deletions
|
@ -12,6 +12,7 @@
|
|||
*/
|
||||
|
||||
#include "about.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "display.hpp"
|
||||
#include "font.hpp"
|
||||
#include "game_config.hpp"
|
||||
|
@ -221,14 +222,13 @@ void show_about(display &disp, std::string campaign)
|
|||
// draw map to screen, thus erasing all text
|
||||
|
||||
SDL_BlitSurface(map_image,&middle_src,video.getSurface(),&middle_dest);
|
||||
std::string style = "translucent65";
|
||||
SDL_Rect frame_area = {
|
||||
map_rect.x + map_rect.w * 3/32,
|
||||
map_rect.y + top_margin,
|
||||
map_rect.w * 13 / 16,
|
||||
map_rect.h - top_margin - bottom_margin
|
||||
};
|
||||
gui::dialog_frame f(disp.video(), "", &style);
|
||||
gui::dialog_frame f(disp.video(), "", &gui::dialog::message_style);
|
||||
f.layout(frame_area);
|
||||
f.draw_background();
|
||||
|
||||
|
|
|
@ -52,8 +52,14 @@
|
|||
|
||||
namespace gui {
|
||||
|
||||
// This is where the connections between styles and the panel images
|
||||
// in the data tree gets made.
|
||||
const struct style dialog::default_style = {"opaque", 0};
|
||||
const struct style dialog::message_style = {"translucent65", 3};
|
||||
const struct style dialog::titlescreen_style = {"translucent54", 0};
|
||||
const struct style dialog::hotkeys_style = {"menu2", 0};
|
||||
|
||||
//static initialization
|
||||
const std::string dialog::default_style("opaque");
|
||||
const std::string dialog::no_help("");
|
||||
const int dialog::message_font_size = font::SIZE_PLUS;
|
||||
const int dialog::caption_font_size = font::SIZE_LARGE;
|
||||
|
@ -110,10 +116,9 @@ dialog::dimension_measurements::dimension_measurements() :x(-1), y(-1), interior
|
|||
}
|
||||
|
||||
dialog::dialog(display &disp, const std::string& title, const std::string& message,
|
||||
const DIALOG_TYPE type, const std::string& dialog_style,
|
||||
const bool blur,
|
||||
const DIALOG_TYPE type, const struct style* dialog_style,
|
||||
const std::string& help_topic) : disp_(disp), image_(NULL),
|
||||
title_(title), style_(dialog_style), blur_(blur), title_widget_(NULL), message_(NULL),
|
||||
title_(title), style_(dialog_style), title_widget_(NULL), message_(NULL),
|
||||
type_(type), menu_(NULL),
|
||||
help_button_(disp, help_topic), text_widget_(NULL),
|
||||
frame_(NULL), bg_restore_(NULL), result_(CONTINUE_DIALOG)
|
||||
|
@ -153,6 +158,7 @@ dialog::dialog(display &disp, const std::string& title, const std::string& messa
|
|||
ERR_DP << "Problem handling utf8 in message '" << message << "'\n";
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dialog::~dialog()
|
||||
|
@ -329,7 +335,7 @@ dialog_frame& dialog::get_frame()
|
|||
}
|
||||
delete bg_restore_;
|
||||
bg_restore_ = new surface_restorer;
|
||||
frame_ = new dialog_frame(screen, title_, &style_, blur_, &frame_buttons_, bg_restore_,
|
||||
frame_ = new dialog_frame(screen, title_, style_, &frame_buttons_, bg_restore_,
|
||||
help_button_.topic().empty() ? NULL : &help_button_);
|
||||
}
|
||||
return *frame_;
|
||||
|
|
|
@ -26,6 +26,11 @@
|
|||
|
||||
namespace gui {
|
||||
|
||||
struct style {
|
||||
std::string panel;
|
||||
int blur_radius;
|
||||
};
|
||||
|
||||
struct dialog_process_info
|
||||
{
|
||||
public:
|
||||
|
@ -160,7 +165,10 @@ private:
|
|||
public:
|
||||
|
||||
//Static members
|
||||
static const std::string default_style;
|
||||
static const struct style default_style;
|
||||
static const struct style message_style;
|
||||
static const struct style titlescreen_style;
|
||||
static const struct style hotkeys_style;
|
||||
static const std::string no_help;
|
||||
static const int message_font_size;
|
||||
static const int caption_font_size;
|
||||
|
@ -176,8 +184,7 @@ public:
|
|||
// throws utils::invalid_utf8_exception() if message is invalid
|
||||
dialog(display &disp, const std::string& title="", const std::string& message="",
|
||||
const DIALOG_TYPE type=MESSAGE,
|
||||
const std::string& dialog_style=default_style,
|
||||
const bool blur=false,
|
||||
const struct style *dialog_style=&default_style,
|
||||
const std::string& help_topic=no_help);
|
||||
virtual ~dialog();
|
||||
|
||||
|
@ -254,8 +261,8 @@ private:
|
|||
//Members
|
||||
display &disp_;
|
||||
dialog_image *image_;
|
||||
const std::string title_, style_;
|
||||
bool blur_;
|
||||
const std::string title_;
|
||||
const struct style *style_;
|
||||
label *title_widget_, *message_;
|
||||
const DIALOG_TYPE type_;
|
||||
gui::menu *menu_;
|
||||
|
@ -279,7 +286,7 @@ class message_dialog : public gui::dialog
|
|||
{
|
||||
public:
|
||||
message_dialog(display &disp, const std::string& title="", const std::string& message="", const gui::DIALOG_TYPE type=gui::MESSAGE)
|
||||
: dialog(disp, title, message, type, "translucent65"), prevent_misclick_until_(0)
|
||||
: dialog(disp, title, message, type, &message_style), prevent_misclick_until_(0)
|
||||
{}
|
||||
~message_dialog();
|
||||
int show(msecs minimum_lifetime = three_blinks);
|
||||
|
|
|
@ -854,9 +854,7 @@ void campaign_preview_pane::draw_contents()
|
|||
location().h-campaign_preview_border*6 };
|
||||
|
||||
/* background frame */
|
||||
static const std::string default_style("translucent65");
|
||||
const std::string* style = &default_style;
|
||||
gui::dialog_frame f(video(), "", style);
|
||||
gui::dialog_frame f(video(), "", &gui::dialog::message_style);
|
||||
f.layout(area);
|
||||
f.draw_background();
|
||||
f.draw_border();
|
||||
|
|
|
@ -1346,7 +1346,7 @@ void map_editor::show_menu(const std::vector<std::string>& items_arg, const int
|
|||
}
|
||||
static const std::string style = "menu2";
|
||||
const int res = gui::show_dialog(gui_, NULL, "", "", gui::MESSAGE, &menu, NULL, "",
|
||||
NULL, 256, NULL, xloc, yloc, &style);
|
||||
NULL, 256, NULL, xloc, yloc, &gui::dialog::hotkeys_style);
|
||||
if(res < 0 || (unsigned)res >= items.size())
|
||||
return;
|
||||
const hotkey::HOTKEY_COMMAND cmd = hotkey::get_hotkey(items[res]).get_id();
|
||||
|
|
|
@ -248,7 +248,7 @@ void preferences_dialog(display &disp, config &prefs) {
|
|||
buttons.push_back(&close_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame frame(disp.video(),_("Preferences"),NULL,false,&buttons,&restorer);
|
||||
gui::dialog_frame frame(disp.video(),_("Preferences"),NULL,&buttons,&restorer);
|
||||
frame.layout(xpos,ypos,width,height);
|
||||
frame.draw();
|
||||
|
||||
|
|
|
@ -2600,7 +2600,7 @@ void show_help(display &disp, const section &toplevel_sec, const std::string sho
|
|||
surface_restorer restorer;
|
||||
|
||||
gui::dialog_frame f(disp.video(), _("The Battle for Wesnoth Help"),
|
||||
NULL, false, &buttons_ptr, &restorer);
|
||||
NULL, &buttons_ptr, &restorer);
|
||||
f.layout(xloc, yloc, width, height);
|
||||
f.draw();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "display.hpp"
|
||||
#include "events.hpp"
|
||||
#include "hotkeys.hpp"
|
||||
|
@ -804,9 +805,8 @@ void command_executor::show_menu(const std::vector<std::string>& items_arg, int
|
|||
|
||||
std::vector<std::string> menu = get_menu_images(items);
|
||||
|
||||
static const std::string style = "menu2";
|
||||
const int res = gui::show_dialog(gui,NULL,"","",
|
||||
gui::MESSAGE,&menu,NULL,"",NULL,-1,NULL,xloc,yloc,&style);
|
||||
gui::MESSAGE,&menu,NULL,"",NULL,-1,NULL,xloc,yloc,&gui::dialog::hotkeys_style);
|
||||
if (size_t(res) >= items.size())
|
||||
return;
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ void default_map_generator::user_config(display& disp)
|
|||
gui::button close_button(screen,_("Close Window"));
|
||||
std::vector<gui::button*> buttons(1,&close_button);
|
||||
|
||||
gui::dialog_frame f(screen,_("Map Generator"),NULL,false,&buttons,&restorer);
|
||||
gui::dialog_frame f(screen,_("Map Generator"),NULL,&buttons,&restorer);
|
||||
f.layout(xpos,ypos,width,height);
|
||||
f.draw();
|
||||
|
||||
|
|
|
@ -1300,7 +1300,7 @@ void show_hotkeys_dialog (display & disp, config *save_config)
|
|||
buttons.push_back(&close_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame f(disp.video(),_("Hotkey Settings"),NULL,false,&buttons,&restorer);
|
||||
gui::dialog_frame f(disp.video(),_("Hotkey Settings"),NULL,&buttons,&restorer);
|
||||
f.layout(xpos,ypos,width,height);
|
||||
f.draw();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "cursor.hpp"
|
||||
#include "display.hpp"
|
||||
#include "events.hpp"
|
||||
|
@ -26,7 +27,6 @@
|
|||
#include "key.hpp"
|
||||
#include "log.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "thread.hpp"
|
||||
#include "language.hpp"
|
||||
#include "sdl_utils.hpp"
|
||||
|
@ -58,7 +58,7 @@ namespace gui {
|
|||
const int ButtonHPadding = 10;
|
||||
const int ButtonVPadding = 10;
|
||||
|
||||
const std::string dialog_frame::default_style("opaque");
|
||||
const struct style dialog_frame::default_style = {"opaque", false};
|
||||
const int dialog_frame::title_border_w = 10;
|
||||
const int dialog_frame::title_border_h = 5;
|
||||
|
||||
|
@ -87,20 +87,19 @@ dialog_manager::~dialog_manager()
|
|||
}
|
||||
|
||||
dialog_frame::dialog_frame(CVideo &video, const std::string& title,
|
||||
const std::string* style, bool blur, std::vector<button*>* buttons,
|
||||
const struct style *style, std::vector<button*>* buttons,
|
||||
surface_restorer* restorer, button* help_button) : title_(title),
|
||||
video_(video), dialog_style_(style ? style : &default_style),
|
||||
blur_(blur),
|
||||
buttons_(buttons), help_button_(help_button), restorer_(restorer),
|
||||
top_(image::get_image("dialogs/" + *dialog_style_ + "-border-top.png",image::UNSCALED)),
|
||||
bot_(image::get_image("dialogs/" + *dialog_style_ + "-border-bottom.png",image::UNSCALED)),
|
||||
left_(image::get_image("dialogs/" + *dialog_style_ + "-border-left.png",image::UNSCALED)),
|
||||
right_(image::get_image("dialogs/" + *dialog_style_ + "-border-right.png",image::UNSCALED)),
|
||||
top_left_(image::get_image("dialogs/" + *dialog_style_ + "-border-topleft.png",image::UNSCALED)),
|
||||
bot_left_(image::get_image("dialogs/" + *dialog_style_ + "-border-botleft.png",image::UNSCALED)),
|
||||
top_right_(image::get_image("dialogs/" + *dialog_style_ + "-border-topright.png",image::UNSCALED)),
|
||||
bot_right_(image::get_image("dialogs/" + *dialog_style_ + "-border-botright.png",image::UNSCALED)),
|
||||
bg_(image::get_image("dialogs/" + *dialog_style_ + "-background.png",image::UNSCALED))
|
||||
top_(image::get_image("dialogs/" + dialog_style_->panel + "-border-top.png",image::UNSCALED)),
|
||||
bot_(image::get_image("dialogs/" + dialog_style_->panel + "-border-bottom.png",image::UNSCALED)),
|
||||
left_(image::get_image("dialogs/" + dialog_style_->panel + "-border-left.png",image::UNSCALED)),
|
||||
right_(image::get_image("dialogs/" + dialog_style_->panel + "-border-right.png",image::UNSCALED)),
|
||||
top_left_(image::get_image("dialogs/" + dialog_style_->panel + "-border-topleft.png",image::UNSCALED)),
|
||||
bot_left_(image::get_image("dialogs/" + dialog_style_->panel + "-border-botleft.png",image::UNSCALED)),
|
||||
top_right_(image::get_image("dialogs/" + dialog_style_->panel + "-border-topright.png",image::UNSCALED)),
|
||||
bot_right_(image::get_image("dialogs/" + dialog_style_->panel + "-border-botright.png",image::UNSCALED)),
|
||||
bg_(image::get_image("dialogs/" + dialog_style_->panel + "-background.png",image::UNSCALED))
|
||||
{
|
||||
have_border_ = top_ != NULL && bot_ != NULL && left_ != NULL && right_ != NULL;
|
||||
}
|
||||
|
@ -253,15 +252,14 @@ void dialog_frame::draw_background()
|
|||
}
|
||||
|
||||
|
||||
if (blur_) {
|
||||
if (dialog_style_->blur_radius) {
|
||||
surface surf = ::get_surface_portion(video_.getSurface(), dim_.exterior);
|
||||
const int blur_radius = 5; // Blur out to 5 pixels.
|
||||
surf = blur_surface(surf, blur_radius);
|
||||
surf = blur_surface(surf, dialog_style_->blur_radius);
|
||||
SDL_BlitSurface(surf, NULL, video_.getSurface(), &dim_.exterior);
|
||||
}
|
||||
|
||||
if(bg_ == NULL) {
|
||||
ERR_DP << "could not find dialog background '" << *dialog_style_ << "'\n";
|
||||
ERR_DP << "could not find dialog background '" << dialog_style_->panel << "'\n";
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < dim_.interior.w; i += bg_->w) {
|
||||
|
@ -361,16 +359,14 @@ int show_dialog(display& screen, surface image,
|
|||
std::string* text_widget_text,
|
||||
int text_widget_max_chars,
|
||||
std::vector<check_item>* options, int xloc, int yloc,
|
||||
const std::string* dialog_style, std::vector<dialog_button_info>* action_buttons,
|
||||
const struct style* dialog_style, std::vector<dialog_button_info>* action_buttons,
|
||||
const std::string& help_topic, const menu::sorter* sorter, menu::style* menu_style)
|
||||
{
|
||||
const std::string& title = (image.null())? caption : "";
|
||||
const std::string& style = (dialog_style)? *dialog_style : dialog::default_style;
|
||||
const struct style *style = (dialog_style)? dialog_style : &dialog::default_style;
|
||||
CVideo &disp = screen.video();
|
||||
|
||||
// We don't let old-style dialogs have blurring because this call is
|
||||
// (a) only used for opaque popups, and (b) is being phased out.
|
||||
gui::dialog d(screen, title, message, type, style, false, help_topic);
|
||||
gui::dialog d(screen, title, message, type, style, help_topic);
|
||||
|
||||
//add the components
|
||||
if(!image.null()) {
|
||||
|
@ -438,7 +434,7 @@ network::connection network_data_dialog(display& disp, const std::string& msg, c
|
|||
std::vector<gui::button*> buttons_ptr(1,&cancel_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,false,&buttons_ptr,&restorer);
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
|
||||
frame.layout(left,top,width,height);
|
||||
frame.draw();
|
||||
|
||||
|
@ -535,7 +531,7 @@ network::connection network_connect_dialog(display& disp, const std::string& msg
|
|||
std::vector<gui::button*> buttons_ptr(1,&cancel_button);
|
||||
|
||||
surface_restorer restorer;
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,false,&buttons_ptr,&restorer);
|
||||
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
|
||||
frame.layout(left,top,width,height);
|
||||
frame.draw();
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ private:
|
|||
class dialog_frame {
|
||||
public:
|
||||
//Static members
|
||||
static const std::string default_style;
|
||||
static const struct style default_style;
|
||||
static const int title_border_w, title_border_h;
|
||||
|
||||
int vertical_padding() const;
|
||||
|
@ -67,7 +67,8 @@ public:
|
|||
SDL_Rect interior, exterior, title, button_row;
|
||||
};
|
||||
dialog_frame(CVideo &video, const std::string& title="",
|
||||
const std::string* dialog_style=NULL, bool blur=false, std::vector<button*>* buttons=NULL,
|
||||
const struct style *dialog_style=NULL,
|
||||
std::vector<button*>* buttons=NULL,
|
||||
surface_restorer* restorer=NULL, button* help_button=NULL);
|
||||
~dialog_frame();
|
||||
|
||||
|
@ -88,8 +89,7 @@ public:
|
|||
private:
|
||||
std::string title_;
|
||||
CVideo &video_;
|
||||
const std::string *dialog_style_;
|
||||
bool blur_;
|
||||
const struct style *dialog_style_;
|
||||
std::vector<button*>* buttons_;
|
||||
button* help_button_;
|
||||
surface_restorer* restorer_;
|
||||
|
@ -174,7 +174,7 @@ int show_dialog(display &screen, surface image,
|
|||
std::string* text_widget_text=NULL,
|
||||
const int text_widget_max_chars = 256,
|
||||
std::vector<check_item>* options=NULL, int xloc=-1, int yloc=-1,
|
||||
const std::string* dialog_style=NULL,
|
||||
const struct style *dialog_style=NULL,
|
||||
std::vector<dialog_button_info>* buttons=NULL,
|
||||
const std::string& help_topic="",
|
||||
const menu::sorter* sorter=NULL,
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "construct_dialog.hpp"
|
||||
#include "cursor.hpp"
|
||||
#include "display.hpp"
|
||||
#include "events.hpp"
|
||||
|
@ -150,7 +151,7 @@ static const config get_tips_of_day()
|
|||
|
||||
|
||||
|
||||
static void draw_tip_of_day(display& screen, config& tips_of_day, int* ntip, const std::string& style, gui::button* const next_tip_button, gui::button* const help_tip_button, const SDL_Rect* const main_dialog_area, surface_restorer& tip_of_day_restorer)
|
||||
static void draw_tip_of_day(display& screen, config& tips_of_day, int* ntip, const struct gui::style *style, gui::button* const next_tip_button, gui::button* const help_tip_button, const SDL_Rect* const main_dialog_area, surface_restorer& tip_of_day_restorer)
|
||||
{
|
||||
|
||||
// Restore the previous tip of day area to its old state (section of the title image).
|
||||
|
@ -187,8 +188,7 @@ static void draw_tip_of_day(display& screen, config& tips_of_day, int* ntip, con
|
|||
help_tip_button->set_location(area.x + pad,
|
||||
area.y + area.h - pad - next_tip_button->location().h);
|
||||
help_tip_button->set_dirty(); //force redraw even if location did not change.
|
||||
// No blurring. Should we do that here?
|
||||
gui::dialog_frame f(screen.video(), "", &style, false, NULL, &tip_of_day_restorer);
|
||||
gui::dialog_frame f(screen.video(), "", style, NULL, &tip_of_day_restorer);
|
||||
f.layout(area);
|
||||
f.draw_background();
|
||||
f.draw_border();
|
||||
|
@ -297,8 +297,7 @@ TITLE_RESULT show_title(display& screen, config& tips_of_day, int* ntip)
|
|||
|
||||
SDL_Rect main_dialog_area = {menu_xbase-padding,menu_ybase-padding,max_width+padding*2,menu_yincr*(nbuttons-1)+buttons.back().height()+padding*2};
|
||||
|
||||
const std::string style = "translucent54";
|
||||
gui::dialog_frame main_frame(screen.video(), "", &style);
|
||||
gui::dialog_frame main_frame(screen.video(), "", &gui::dialog::titlescreen_style);
|
||||
main_frame.layout(main_dialog_area);
|
||||
main_frame.draw_background();
|
||||
main_frame.draw_border();
|
||||
|
@ -321,7 +320,7 @@ TITLE_RESULT show_title(display& screen, config& tips_of_day, int* ntip)
|
|||
|
||||
surface_restorer tip_of_day_restorer;
|
||||
|
||||
draw_tip_of_day(screen, tips_of_day, ntip, style, &next_tip_button, &help_tip_button, &main_dialog_area, tip_of_day_restorer);
|
||||
draw_tip_of_day(screen, tips_of_day, ntip, &gui::dialog::titlescreen_style, &next_tip_button, &help_tip_button, &main_dialog_area, tip_of_day_restorer);
|
||||
|
||||
const int pad = game_config::title_tip_padding;
|
||||
beg_button.set_location(screen.w() - pad - beg_button.location().w,
|
||||
|
@ -350,7 +349,7 @@ TITLE_RESULT show_title(display& screen, config& tips_of_day, int* ntip)
|
|||
*ntip = *ntip + 1;
|
||||
}
|
||||
|
||||
draw_tip_of_day(screen, tips_of_day, ntip, style, &next_tip_button, &help_tip_button, &main_dialog_area, tip_of_day_restorer);
|
||||
draw_tip_of_day(screen, tips_of_day, ntip, &gui::dialog::titlescreen_style, &next_tip_button, &help_tip_button, &main_dialog_area, tip_of_day_restorer);
|
||||
}
|
||||
|
||||
if(help_tip_button.pressed()) {
|
||||
|
|
Loading…
Add table
Reference in a new issue