update the editor code to use the dialog_frame object

This commit is contained in:
Patrick Parker 2007-05-28 18:38:33 +00:00
parent 286cbd4a04
commit 814ed55745
11 changed files with 63 additions and 44 deletions

View file

@ -222,14 +222,14 @@ void show_about(display &disp, std::string campaign)
SDL_BlitSurface(map_image,&middle_src,video.getSurface(),&middle_dest);
std::string style = "mainmenu";
SDL_Rect frame = {
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::frame f(disp.video(), "", &style);
f.layout(frame.x, frame.y, frame.w, frame.h);
gui::dialog_frame f(disp.video(), "", &style);
f.layout(frame_area);
f.draw_background();
// draw one screen full of text

View file

@ -322,10 +322,10 @@ void dialog::draw_frame()
frame_buttons.push_back(*b);
}
bg_restore_ = new surface_restorer;
frame f(screen, title_, &style_, &frame_buttons, bg_restore_,
dialog_frame frame(screen, title_, &style_, &frame_buttons, bg_restore_,
help_button_.topic().empty() ? NULL : &help_button_);
dim_.frame_dim = f.layout(dim_.interior.x, dim_.interior.y, dim_.interior.w, dim_.interior.h);
f.draw();
dim_.frame = frame.layout(dim_.interior.x, dim_.interior.y, dim_.interior.w, dim_.interior.h);
frame.draw();
}
void dialog::update_widget_positions()
@ -696,7 +696,7 @@ int dialog::process(dialog_process_info &info)
// but that may be changed to allow right-click selection instead.
if (new_right_button && !info.right_button) {
if( standard_buttons_.empty()
|| (!point_in_rect(mousex,mousey,dim_.frame_dim.exterior)
|| (!point_in_rect(mousex,mousey,dim_.frame.exterior)
&& !(type_ == OK_ONLY && use_menu)))
return CLOSE_DIALOG;
}

View file

@ -133,7 +133,7 @@ public:
int menu_x, menu_y;
int image_x, image_y, caption_x, caption_y;
std::map<dialog_button *const, std::pair<int,int> > buttons;
frame::dimension_measurements frame_dim;
dialog_frame::dimension_measurements frame;
};
private:
typedef std::vector<preview_pane *>::iterator pp_iterator;

View file

@ -856,8 +856,8 @@ void campaign_preview_pane::draw_contents()
/* background frame */
static const std::string default_style("mainmenu");
const std::string* style = &default_style;
gui::frame f(video(), "", style);
f.layout(area.x,area.y,area.w,area.h);
gui::dialog_frame f(video(), "", style);
f.layout(area);
f.draw_background();
f.draw_border();

View file

@ -71,7 +71,10 @@ std::string new_map_dialog(display& disp, const t_translation::t_letter fill_ter
SDL_Rect dialog_rect = {xpos-10,ypos-10,width+20,height+20};
surface_restorer restorer(&disp.video(),dialog_rect);
gui::draw_dialog_frame(xpos,ypos,width,height,disp.video());
gui::dialog_frame frame(disp.video());
frame.layout(xpos,ypos,width,height);
frame.draw_background();
frame.draw_border();
SDL_Rect title_rect = font::draw_text(NULL,screen_area(),24,font::NORMAL_COLOUR,
_("Create New Map"),0,0);
@ -184,7 +187,8 @@ std::string new_map_dialog(display& disp, const t_translation::t_letter fill_ter
if (draw) {
map_width = width_slider.value();
map_height = height_slider.value();
gui::draw_dialog_frame(xpos,ypos,width,height,disp.video());
frame.draw_background();
frame.draw_border();
title_rect = font::draw_text(&disp.video(),screen_area(),24,font::NORMAL_COLOUR,
_("Create New Map"),
xpos+(width-title_rect.w)/2,ypos+10);
@ -244,7 +248,9 @@ void preferences_dialog(display &disp, config &prefs) {
buttons.push_back(&close_button);
surface_restorer restorer;
gui::draw_dialog(xpos,ypos,width,height,disp.video(),_("Preferences"),NULL,&buttons,&restorer);
gui::dialog_frame frame(disp.video(),_("Preferences"),NULL,&buttons,&restorer);
frame.layout(xpos,ypos,width,height);
frame.draw();
const std::string& scroll_label = _("Scroll Speed:");
@ -346,7 +352,7 @@ void preferences_dialog(display &disp, config &prefs) {
if(redraw_all) {
restorer.cancel();
gui::draw_dialog(xpos,ypos,width,height,disp.video(),_("Preferences"),NULL,&buttons,&restorer);
frame.draw();
fullscreen_button.set_dirty();
close_button.set_dirty();
resolution_button.set_dirty();
@ -426,7 +432,10 @@ resize_dialog(display &disp, const unsigned curr_w, const unsigned curr_h) {
SDL_Rect dialog_rect = {xpos-10,ypos-10,width+20,height+20};
surface_restorer restorer(&disp.video(),dialog_rect);
gui::draw_dialog_frame(xpos,ypos,width,height,disp.video());
gui::dialog_frame frame(disp.video());
frame.layout(xpos,ypos,width,height);
frame.draw_background();
frame.draw_border();
SDL_Rect title_rect = font::draw_text(NULL,screen_area(),24,font::NORMAL_COLOUR,
_("Resize Map"),0,0);
@ -487,7 +496,9 @@ resize_dialog(display &disp, const unsigned curr_w, const unsigned curr_h) {
if (draw) {
map_width = width_slider.value();
map_height = height_slider.value();
gui::draw_dialog_frame(xpos,ypos,width,height,disp.video());
frame.draw_background();
frame.draw_border();
title_rect = font::draw_text(&disp.video(),screen_area(),24,font::NORMAL_COLOUR,
_("Resize Map"),
xpos+(width-title_rect.w)/2,ypos+10);

View file

@ -2598,7 +2598,7 @@ void show_help(display &disp, const section &toplevel_sec, const std::string sho
buttons_ptr.push_back(&close_button_);
surface_restorer restorer;
gui::frame f(disp.video(), _("The Battle for Wesnoth Help"),
gui::dialog_frame f(disp.video(), _("The Battle for Wesnoth Help"),
NULL, &buttons_ptr, &restorer);
f.layout(xloc, yloc, width, height);
f.draw();

View file

@ -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::frame f(screen,_("Map Generator"),NULL,&buttons,&restorer);
gui::dialog_frame f(screen,_("Map Generator"),NULL,&buttons,&restorer);
f.layout(xpos,ypos,width,height);
f.draw();

View file

@ -1274,7 +1274,7 @@ void show_hotkeys_dialog (display & disp, config *save_config)
buttons.push_back(&close_button);
surface_restorer restorer;
gui::frame f(disp.video(),_("Hotkey Settings"),NULL,&buttons,&restorer);
gui::dialog_frame f(disp.video(),_("Hotkey Settings"),NULL,&buttons,&restorer);
f.layout(xpos,ypos,width,height);
f.draw();
@ -1328,7 +1328,7 @@ void show_hotkeys_dialog (display & disp, config *save_config)
text_size.w+60,
text_size.h+32};
surface_restorer restorer(&disp.video(),dlgr);
gui::frame mini_frame(disp.video());
gui::dialog_frame mini_frame(disp.video());
mini_frame.layout(centerx-text_size.w/2 - 20,
centery-text_size.h/2 - 6,
text_size.w+40,

View file

@ -58,9 +58,9 @@ namespace gui {
const int ButtonHPadding = 10;
const int ButtonVPadding = 10;
const std::string frame::default_style("menu");
const int frame::title_border_w = 10;
const int frame::title_border_h = 5;
const std::string dialog_frame::default_style("menu");
const int dialog_frame::title_border_w = 10;
const int dialog_frame::title_border_h = 5;
@ -86,7 +86,7 @@ dialog_manager::~dialog_manager()
SDL_PushEvent(&pb_event);
}
frame::frame(CVideo &video, const std::string& title,
dialog_frame::dialog_frame(CVideo &video, const std::string& title,
const std::string* style, std::vector<button*>* buttons,
surface_restorer* restorer, button* help_button) : video_(video),
title_(title), dialog_style_(style ? style : &default_style),
@ -104,14 +104,18 @@ frame::frame(CVideo &video, const std::string& title,
}
frame::~frame()
dialog_frame::~dialog_frame()
{}
frame::dimension_measurements::dimension_measurements() :
dialog_frame::dimension_measurements::dimension_measurements() :
interior(empty_rect), exterior(empty_rect), title(empty_rect), button_row(empty_rect)
{}
frame::dimension_measurements frame::layout(int x, int y, int w, int h) {
dialog_frame::dimension_measurements dialog_frame::layout(SDL_Rect const& rect) {
return layout(rect.x, rect.y, rect.w, rect.h);
}
dialog_frame::dimension_measurements dialog_frame::layout(int x, int y, int w, int h) {
dim_ = dimension_measurements();
if(!title_.empty()) {
dim_.title = draw_title(NULL);
@ -184,7 +188,7 @@ frame::dimension_measurements frame::layout(int x, int y, int w, int h) {
return dim_;
}
void frame::draw_border()
void dialog_frame::draw_border()
{
if(have_border_ == false) {
return;
@ -226,7 +230,7 @@ void frame::draw_border()
video_.blit_surface(dim_.interior.x + dim_.interior.w, dim_.interior.y + dim_.interior.h, bot_right_);
}
void frame::draw_background()
void dialog_frame::draw_background()
{
if(restorer_ != NULL) {
*restorer_ = surface_restorer(&video_, dim_.exterior);
@ -248,7 +252,7 @@ void frame::draw_background()
}
}
SDL_Rect frame::draw_title(CVideo* video)
SDL_Rect dialog_frame::draw_title(CVideo* video)
{
SDL_Rect rect = {0, 0, 10000, 10000};
rect = screen_area();
@ -256,7 +260,7 @@ SDL_Rect frame::draw_title(CVideo* video)
title_, dim_.title.x, dim_.title.y, false, TTF_STYLE_BOLD);
}
void frame::draw()
void dialog_frame::draw()
{
//draw background
draw_background();
@ -410,9 +414,9 @@ 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::frame f(disp.video(),msg,NULL,&buttons_ptr,&restorer);
f.layout(left,top,width,height);
f.draw();
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
frame.layout(left,top,width,height);
frame.draw();
const SDL_Rect progress_rect = {left+border,top+border,width-border*2,height-border*2};
gui::progress_bar progress(disp.video());
@ -507,9 +511,9 @@ network::connection network_connect_dialog(display& disp, const std::string& msg
std::vector<gui::button*> buttons_ptr(1,&cancel_button);
surface_restorer restorer;
gui::frame f(disp.video(),msg,NULL,&buttons_ptr,&restorer);
f.layout(left,top,width,height);
f.draw();
gui::dialog_frame frame(disp.video(),msg,NULL,&buttons_ptr,&restorer);
frame.layout(left,top,width,height);
frame.draw();
events::raise_draw_event();
disp.flip();

View file

@ -54,7 +54,7 @@ private:
bool reset_to;
};
class frame {
class dialog_frame {
public:
//Static members
static const std::string default_style;
@ -64,12 +64,16 @@ public:
dimension_measurements();
SDL_Rect interior, exterior, title, button_row;
};
frame(CVideo &video, const std::string& title="",
dialog_frame(CVideo &video, const std::string& title="",
const std::string* dialog_style=NULL, std::vector<button*>* buttons=NULL,
surface_restorer* restorer=NULL, button* help_button=NULL);
~frame();
~dialog_frame();
dimension_measurements layout(int x, int y, int w, int h);
dimension_measurements layout(SDL_Rect const& frame_area);
void set_layout(dimension_measurements &new_dim) { dim_ = new_dim; }
dimension_measurements get_layout() const { return dim_; }
void draw();
//called by draw

View file

@ -187,8 +187,8 @@ 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.
gui::frame f(screen.video(), "", &style, NULL, &tip_of_day_restorer);
f.layout(area.x,area.y,area.w,area.h);
gui::dialog_frame f(screen.video(), "", &style, NULL, &tip_of_day_restorer);
f.layout(area);
f.draw_background();
f.draw_border();
@ -297,8 +297,8 @@ 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 = "mainmenu";
gui::frame main_frame(screen.video(), "", &style);
main_frame.layout(main_dialog_area.x,main_dialog_area.y,main_dialog_area.w,main_dialog_area.h);
gui::dialog_frame main_frame(screen.video(), "", &style);
main_frame.layout(main_dialog_area);
main_frame.draw_background();
main_frame.draw_border();