editor_dialogs.cpp

Go to the documentation of this file.
00001 /* $Id: editor_dialogs.cpp 25683 2008-04-08 14:59:32Z shadowmaster $ */
00002 /*
00003   Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
00004   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License version 2
00008   or at your option any later version.
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY.
00011 
00012   See the COPYING file for more details.
00013 */
00014 
00015 //! @file editor/editor_dialogs.cpp
00016 //!
00017 
00018 #include "SDL.h"
00019 
00020 #define GETTEXT_DOMAIN "wesnoth-lib"
00021 
00022 #include "../config.hpp"
00023 #include "../construct_dialog.hpp"
00024 #include "../display.hpp"
00025 #include "../events.hpp"
00026 #include "../filesystem.hpp"
00027 #include "../game_config.hpp"
00028 #include "../gettext.hpp"
00029 #include "../language.hpp"
00030 #include "../map.hpp"
00031 #include "../mapgen.hpp"
00032 #include "../map_create.hpp"
00033 #include "../marked-up_text.hpp"
00034 #include "../util.hpp"
00035 #include "../preferences_display.hpp"
00036 #include "../video.hpp"
00037 #include "../widgets/slider.hpp"
00038 
00039 #include "editor_dialogs.hpp"
00040 
00041 namespace {
00042     const int map_min_height = 1;
00043     const int map_min_width = 1;
00044     const int map_max_height = 200;
00045     const int map_max_width = 200;
00046 }
00047 
00048 namespace map_editor {
00049 
00050 bool confirm_modification_disposal(display& disp) {
00051     const int res = gui::dialog(disp, "",
00052                      _("Your modifications to the map will be lost. Continue?"),
00053                      gui::OK_CANCEL).show();
00054     return res == 0;
00055 }
00056 
00057 
00058 std::string new_map_dialog(display& disp, const t_translation::t_terrain fill_terrain,
00059     const bool confirmation_needed, const config &game_config)
00060 {
00061     const resize_lock prevent_resizing;
00062     const events::event_context dialog_events_context;
00063     const gui::dialog_manager dialog_mgr;
00064 
00065     int map_width(40), map_height(40);
00066     const int width = 600;
00067     const int height = 400;
00068     const int xpos = disp.w()/2 - width/2;
00069     const int ypos = disp.h()/2 - height/2;
00070     const int horz_margin = 5;
00071     const int vertical_margin = 20;
00072 
00073     SDL_Rect dialog_rect = {xpos-10,ypos-10,width+20,height+20};
00074     surface_restorer restorer(&disp.video(),dialog_rect);
00075 
00076     gui::dialog_frame frame(disp.video());
00077     frame.layout(xpos,ypos,width,height);
00078     frame.draw_background();
00079     frame.draw_border();
00080 
00081     SDL_Rect title_rect = font::draw_text(NULL,screen_area(),24,font::NORMAL_COLOUR,
00082                           _("Create New Map"),0,0);
00083 
00084     const std::string& width_label = _("Width:");
00085     const std::string& height_label = _("Height:");
00086 
00087     SDL_Rect width_rect = font::draw_text(NULL, screen_area(), 14, font::NORMAL_COLOUR,
00088                                           width_label, 0, 0);
00089     SDL_Rect height_rect = font::draw_text(NULL, screen_area(), 14, font::NORMAL_COLOUR,
00090                                            height_label, 0, 0);
00091 
00092     const int text_right = xpos + horz_margin +
00093             maximum<int>(width_rect.w,height_rect.w);
00094 
00095     width_rect.x = text_right - width_rect.w;
00096     height_rect.x = text_right - height_rect.w;
00097 
00098     width_rect.y = ypos + title_rect.h + vertical_margin*2;
00099     height_rect.y = width_rect.y + width_rect.h + vertical_margin;
00100 
00101     gui::button new_map_button(disp.video(), _("Generate New Map"));
00102     gui::button random_map_button(disp.video(), _("Generate Random Map"));
00103     gui::button random_map_setting_button(disp.video(), _("Random Generator Settings"));
00104     gui::button cancel_button(disp.video(), _("Cancel"));
00105 
00106     new_map_button.set_location(xpos + horz_margin,height_rect.y + height_rect.h + vertical_margin);
00107     random_map_button.set_location(xpos + horz_margin,ypos + height - random_map_button.height()-14*2-vertical_margin);
00108     random_map_setting_button.set_location(random_map_button.location().x + random_map_button.width() + horz_margin,
00109                                            ypos + height - random_map_setting_button.height()
00110                                            - 14*2 - vertical_margin);
00111     cancel_button.set_location(xpos + width - cancel_button.width() - horz_margin,
00112                                ypos + height - cancel_button.height()-14);
00113 
00114     const int right_space = 100;
00115 
00116     const int slider_left = text_right + 10;
00117     const int slider_right = xpos + width - horz_margin - right_space;
00118     SDL_Rect slider_rect = { slider_left,width_rect.y,slider_right-slider_left,width_rect.h};
00119 
00120     slider_rect.y = width_rect.y;
00121     gui::slider width_slider(disp.video());
00122     width_slider.set_location(slider_rect);
00123     width_slider.set_min(map_min_width);
00124     width_slider.set_max(map_max_width);
00125     width_slider.set_value(map_width);
00126 
00127     slider_rect.y = height_rect.y;
00128     gui::slider height_slider(disp.video());
00129     height_slider.set_location(slider_rect);
00130     height_slider.set_min(map_min_height);
00131     height_slider.set_max(map_max_height);
00132     height_slider.set_value(map_height);
00133 
00134     static util::scoped_ptr<map_generator> random_map_generator(NULL);
00135     if (random_map_generator == NULL) {
00136         // Initialize the map generator if this is the first call,
00137         // otherwise keep the settings and such.
00138         const config* const toplevel_cfg = game_config.find_child("multiplayer","id","multiplayer_Random_Map");
00139         const config* const cfg = toplevel_cfg == NULL ? NULL : toplevel_cfg->child("generator");
00140         if (cfg == NULL) {
00141             config dummy_cfg;
00142             random_map_generator.assign(create_map_generator("", &dummy_cfg));
00143         }
00144         else {
00145             random_map_generator.assign(create_map_generator("", cfg));
00146         }
00147     }
00148 
00149     for(bool draw = true;; draw = false) {
00150         if(cancel_button.pressed()) {
00151             return "";
00152         }
00153 
00154         if(new_map_button.pressed()) {
00155             draw = true;
00156             if ((confirmation_needed &&
00157                  confirm_modification_disposal(disp))
00158                 || !confirmation_needed) {
00159 
00160                 return map_editor::new_map(width_slider.value() + 2 * gamemap::default_border, 
00161                     height_slider.value() + 2 * gamemap::default_border, fill_terrain);
00162             }
00163         }
00164         if(random_map_setting_button.pressed()) {
00165             draw = true;
00166             if (random_map_generator.get()->allow_user_config()) {
00167                 random_map_generator.get()->user_config(disp);
00168             }
00169         }
00170 
00171         if(random_map_button.pressed()) {
00172             draw = true;
00173             if ((confirmation_needed
00174                  && confirm_modification_disposal(disp))
00175                 || !confirmation_needed) {
00176 
00177                 const std::string map =
00178                     random_map_generator.get()->create_map(std::vector<std::string>());
00179                 if (map == "") {
00180                     gui::message_dialog(disp, "",
00181                                      _("Map creation failed.")).show();
00182                 }
00183                 return map;
00184             }
00185         }
00186         if (width_slider.value() != map_width
00187             || height_slider.value() != map_height) {
00188             draw = true;
00189         }
00190         if (draw) {
00191             map_width = width_slider.value();
00192             map_height = height_slider.value();
00193             frame.draw_background();
00194             frame.draw_border();
00195             title_rect = font::draw_text(&disp.video(),screen_area(),24,font::NORMAL_COLOUR,
00196                                          _("Create New Map"),
00197                                          xpos+(width-title_rect.w)/2,ypos+10);
00198 
00199             font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,
00200                             width_label,width_rect.x,width_rect.y);
00201             font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,
00202                             height_label,height_rect.x,height_rect.y);
00203 
00204             std::stringstream width_str;
00205             width_str << map_width;
00206             font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,width_str.str(),
00207                             slider_right+horz_margin,width_rect.y);
00208 
00209             std::stringstream height_str;
00210             height_str << map_height;
00211             font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,height_str.str(),
00212                             slider_right+horz_margin,height_rect.y);
00213 
00214         }
00215 
00216         new_map_button.set_dirty();
00217         random_map_button.set_dirty();
00218         random_map_setting_button.set_dirty();
00219         cancel_button.set_dirty();
00220 
00221         width_slider.set_dirty();
00222         height_slider.set_dirty();
00223 
00224         events::raise_process_event();
00225         events::raise_draw_event();
00226 
00227         if (draw) {
00228             update_rect(xpos,ypos,width,height);
00229         }
00230         disp.update_display();
00231         SDL_Delay(20);
00232         events::pump();
00233     }
00234 }
00235 
00236 
00237 void preferences_dialog(display &disp, config &prefs) {
00238     const events::event_context dialog_events_context;
00239     const gui::dialog_manager dialog_mgr;
00240 
00241     const int width = 600;
00242     const int height = 400;
00243     const int xpos = disp.w()/2 - width/2;
00244     const int ypos = disp.h()/2 - height/2;
00245 
00246     SDL_Rect clip_rect = disp.screen_area();
00247 
00248     gui::button close_button(disp.video(),_("Close Window"));
00249 
00250     std::vector<gui::button*> buttons;
00251     buttons.push_back(&close_button);
00252 
00253     gui::dialog_frame frame(disp.video(),_("Preferences"),gui::dialog_frame::default_style,true,&buttons);
00254     frame.layout(xpos,ypos,width,height);
00255     frame.draw();
00256 
00257     const std::string& scroll_label = _("Scroll Speed:");
00258 
00259     SDL_Rect scroll_rect = {0,0,0,0};
00260     scroll_rect = font::draw_text(NULL,clip_rect,14,font::NORMAL_COLOUR,
00261                                   scroll_label,0,0);
00262 
00263     const int text_right = xpos + scroll_rect.w + 5;
00264 
00265     const int scroll_pos = ypos + 20;
00266 
00267     scroll_rect.x = text_right - scroll_rect.w;
00268     scroll_rect.y = scroll_pos;
00269 
00270     const int slider_left = text_right + 10;
00271     const int slider_right = xpos + width - 5;
00272     if(slider_left >= slider_right)
00273         return;
00274 
00275     SDL_Rect slider_rect = { slider_left, scroll_pos, slider_right - slider_left, 10  };
00276 
00277     slider_rect.y = scroll_pos;
00278     gui::slider scroll_slider(disp.video());
00279     scroll_slider.set_location(slider_rect);
00280     scroll_slider.set_min(1);
00281     scroll_slider.set_max(100);
00282     scroll_slider.set_value(preferences::scroll_speed());
00283 
00284     gui::button fullscreen_button(disp.video(),_("Toggle Full Screen"),
00285                                   gui::button::TYPE_CHECK);
00286 
00287     fullscreen_button.set_check(preferences::fullscreen());
00288 
00289     fullscreen_button.set_location(slider_left,scroll_pos + 80);
00290 
00291     gui::button grid_button(disp.video(),_("Show Grid"),
00292                             gui::button::TYPE_CHECK);
00293     grid_button.set_check(preferences::grid());
00294 
00295     grid_button.set_location(slider_left + fullscreen_button.width() + 100,
00296                              scroll_pos + 80);
00297 
00298     gui::button resolution_button(disp.video(),_("Video Mode"));
00299     resolution_button.set_location(slider_left,scroll_pos + 80 + 50);
00300 
00301     gui::button hotkeys_button (disp.video(),_("Hotkeys"));
00302     hotkeys_button.set_location(slider_left + fullscreen_button.width() + 100,
00303                                 scroll_pos + 80 + 50);
00304 
00305     // Time of Day lighting level sliders, etc.
00306     const std::string& lighting_header_label = _("Lighting levels (time of day):");
00307     SDL_Rect lighting_header_rect = font::draw_text(NULL,clip_rect,14,font::NORMAL_COLOUR,
00308                                                     lighting_header_label,0,0
00309                                                    );
00310     lighting_header_rect.x = scroll_rect.x;
00311     lighting_header_rect.y = resolution_button.location().y + resolution_button.height() + 40;
00312     
00313     const std::string& lighting_r_label = _("light_level^Red:");
00314     const std::string& lighting_g_label = _("light_level^Green:");
00315     const std::string& lighting_b_label = _("light_level^Blue:");
00316     SDL_Rect lighting_r_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_r_label,0,0);
00317     SDL_Rect lighting_g_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_g_label,0,0);
00318     SDL_Rect lighting_b_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_b_label,0,0);
00319 
00320     lighting_r_rect.x = resolution_button.location().x;
00321     lighting_r_rect.y = lighting_header_rect.y + 40;
00322     
00323     lighting_g_rect.x = resolution_button.location().x;
00324     lighting_g_rect.y = lighting_r_rect.y + 40;
00325     
00326     lighting_b_rect.x = resolution_button.location().x;
00327     lighting_b_rect.y = lighting_g_rect.y + 40;
00328 
00329     gui::slider lighting_r_slider(disp.video());
00330     gui::slider lighting_g_slider(disp.video());
00331     gui::slider lighting_b_slider(disp.video());
00332     
00333     const int rgb_sliders_ref_x = lighting_r_rect.x +
00334                                   maximum<int>(maximum<int>(lighting_r_rect.w, lighting_g_rect.w), lighting_b_rect.w);
00335     const int rgb_sliders_ref_width = hotkeys_button.location().x + hotkeys_button.location().w - rgb_sliders_ref_x;
00336     
00337     SDL_Rect r_rect = { rgb_sliders_ref_x, lighting_r_rect.y, rgb_sliders_ref_width, 10};
00338     SDL_Rect g_rect = { rgb_sliders_ref_x, lighting_g_rect.y, rgb_sliders_ref_width, 10};
00339     SDL_Rect b_rect = { rgb_sliders_ref_x, lighting_b_rect.y, rgb_sliders_ref_width, 10};
00340 
00341     lighting_r_slider.set_value(preferences::editor_r());
00342     lighting_g_slider.set_value(preferences::editor_g());
00343     lighting_b_slider.set_value(preferences::editor_b());
00344     
00345     lighting_r_slider.set_min(-255);
00346     lighting_g_slider.set_min(-255);
00347     lighting_b_slider.set_min(-255);
00348     
00349     lighting_r_slider.set_max(255);
00350     lighting_g_slider.set_max(255);
00351     lighting_b_slider.set_max(255);
00352     
00353     lighting_r_slider.set_location(r_rect);
00354     lighting_g_slider.set_location(g_rect);
00355     lighting_b_slider.set_location(b_rect);
00356     
00357     // NOTE: padding
00358     std::string lighting_value_r = "0000";
00359     std::string lighting_value_g = "0000";
00360     std::string lighting_value_b = "0000";
00361     
00362     SDL_Rect lighting_value_r_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_value_r,0,0);
00363     SDL_Rect lighting_value_g_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_value_g,0,0);
00364     SDL_Rect lighting_value_b_rect = font::draw_text(NULL,clip_rect,12,font::NORMAL_COLOUR,lighting_value_b,0,0);
00365     
00366     lighting_value_r_rect.x = rgb_sliders_ref_x + rgb_sliders_ref_width + 20;
00367     lighting_value_g_rect.x = rgb_sliders_ref_x + rgb_sliders_ref_width + 20;
00368     lighting_value_b_rect.x = rgb_sliders_ref_x + rgb_sliders_ref_width + 20;
00369     
00370     lighting_value_r_rect.y = r_rect.y;
00371     lighting_value_g_rect.y = g_rect.y;
00372     lighting_value_b_rect.y = b_rect.y;
00373 
00374     bool redraw_all = true;
00375     bool redraw_slider_values = false;
00376     
00377     for(;;) {
00378         if(close_button.pressed()) {
00379             break;
00380         }
00381 
00382         if(fullscreen_button.pressed()) {
00383             preferences::set_fullscreen(fullscreen_button.checked());
00384             redraw_all = true;
00385         }
00386 
00387         if(redraw_all) {
00388             frame.draw();
00389             fullscreen_button.set_dirty();
00390             close_button.set_dirty();
00391             resolution_button.set_dirty();
00392             grid_button.set_dirty();
00393             hotkeys_button.set_dirty();
00394             scroll_slider.set_dirty();
00395             lighting_r_slider.set_dirty();
00396             lighting_g_slider.set_dirty();
00397             lighting_b_slider.set_dirty();
00398 
00399             font::draw_text(&disp.video(),clip_rect,14,font::NORMAL_COLOUR,scroll_label,
00400                         scroll_rect.x,scroll_rect.y);
00401             font::draw_text(&disp.video(),clip_rect,14,font::NORMAL_COLOUR,lighting_header_label,lighting_header_rect.x,lighting_header_rect.y);
00402 
00403             font::draw_text(&disp.video(),clip_rect,12,font::NORMAL_COLOUR,lighting_r_label,lighting_r_rect.x,lighting_r_rect.y);
00404             font::draw_text(&disp.video(),clip_rect,12,font::NORMAL_COLOUR,lighting_g_label,lighting_g_rect.x,lighting_g_rect.y);
00405             font::draw_text(&disp.video(),clip_rect,12,font::NORMAL_COLOUR,lighting_b_label,lighting_b_rect.x,lighting_b_rect.y);
00406 
00407             update_rect(screen_area());
00408 
00409             redraw_all = false;
00410             redraw_slider_values = true;
00411         }
00412 
00413         if(grid_button.pressed()) {
00414             preferences::set_grid(grid_button.checked());
00415         }
00416 
00417         if(resolution_button.pressed()) {
00418             preferences::show_video_mode_dialog(disp);
00419             break;
00420         }
00421 
00422         if(hotkeys_button.pressed()) {
00423             preferences::show_hotkeys_dialog(disp, &prefs);
00424             break;
00425         }
00426 
00427         events::pump();
00428         events::raise_process_event();
00429         events::raise_draw_event();
00430         
00431         //!@todo FIXME: this could be made simpler with gui::label widgets, but I'm too lazy to go
00432         //! and learn how to use them, thus I'll concentrate on the real feature -- shadowmaster
00433         if (lighting_r_slider.value_change() || redraw_slider_values) {
00434             draw_solid_tinted_rectangle(
00435                 lighting_value_r_rect.x-2, lighting_value_r_rect.y-2,
00436                 lighting_value_r_rect.w+4, lighting_value_r_rect.h+4,
00437                 30, 30, 30,
00438                 1.0,
00439                 disp.video().getSurface()
00440                 );
00441             lighting_value_r = str_cast<int>(lighting_r_slider.value());
00442             font::draw_text(&disp.video(), clip_rect, 12, font::NORMAL_COLOUR,
00443                 lighting_value_r, lighting_value_r_rect.x, lighting_value_r_rect.y);
00444             update_rect(lighting_value_r_rect);
00445         }
00446         if (lighting_g_slider.value_change() || redraw_slider_values) {
00447             draw_solid_tinted_rectangle(
00448                 lighting_value_g_rect.x-2, lighting_value_g_rect.y-2,
00449                 lighting_value_g_rect.w+4, lighting_value_g_rect.h+4,
00450                 30, 30, 30,
00451                 1.0,
00452                 disp.video().getSurface()
00453                 );
00454             lighting_value_g = str_cast<int>(lighting_g_slider.value());
00455             font::draw_text(&disp.video(), clip_rect, 12, font::NORMAL_COLOUR,
00456                 lighting_value_g, lighting_value_g_rect.x, lighting_value_g_rect.y
00457                 );
00458             update_rect(lighting_value_g_rect);
00459         }
00460         if (lighting_b_slider.value_change() || redraw_slider_values) {
00461             draw_solid_tinted_rectangle(
00462                 lighting_value_b_rect.x-2, lighting_value_b_rect.y-2,
00463                 lighting_value_b_rect.w+4, lighting_value_b_rect.h+4,
00464                 30, 30, 30,
00465                 1.0,
00466                 disp.video().getSurface()
00467                 );
00468             lighting_value_b = str_cast<int>(lighting_b_slider.value());
00469             font::draw_text(&disp.video(), clip_rect, 12, font::NORMAL_COLOUR,
00470                 lighting_value_b, lighting_value_b_rect.x, lighting_value_b_rect.y
00471                 );
00472             update_rect(lighting_value_b_rect);
00473         }
00474         redraw_slider_values = false;
00475 
00476         preferences::set_scroll_speed(scroll_slider.value());
00477         preferences::set_editor_r(lighting_r_slider.value());
00478         preferences::set_editor_g(lighting_g_slider.value());
00479         preferences::set_editor_b(lighting_b_slider.value());
00480 
00481         disp.update_display();
00482 
00483         SDL_Delay(20);
00484     }
00485 }
00486 
00487 
00488 bool resize_dialog(display &disp, unsigned& width, unsigned& height,
00489     int& x_offset, int& y_offset, bool& do_expand)
00490 {
00491     const resize_lock prevent_resizing;
00492     const events::event_context dialog_events_context;
00493     const gui::dialog_manager dialog_mgr;
00494 
00495     const int dlg_width = 600;
00496     const int dlg_height = 350;
00497     const int xpos = disp.w() / 2 - dlg_width / 2;
00498     const int ypos = disp.h() / 2 - dlg_height / 2;
00499     const int horz_margin = 5;
00500     const int vertical_margin = 20;
00501     const int button_padding = 20;
00502 
00503     SDL_Rect dialog_rect = {xpos - 10,
00504         ypos - 10, dlg_width + 20, dlg_height + 20};
00505     surface_restorer restorer(&disp.video(), dialog_rect);
00506 
00507     gui::dialog_frame frame(disp.video());
00508     frame.layout(xpos,ypos,dlg_width, dlg_height);
00509     frame.draw_background();
00510     frame.draw_border();
00511 
00512     SDL_Rect title_rect = font::draw_text(NULL, screen_area(), 24,
00513         font::NORMAL_COLOUR, _("Resize Map"), 0, 0);
00514 
00515     const std::string& width_label = _("Width:");
00516     const std::string& height_label = _("Height:");
00517     const std::string& x_offset_label = _("X offset:");
00518     const std::string& y_offset_label = _("Y offset:");
00519 
00520     SDL_Rect width_rect = font::draw_text(NULL, screen_area(), 14,
00521         font::NORMAL_COLOUR, width_label, 0, 0);
00522 
00523     SDL_Rect height_rect = font::draw_text(NULL, screen_area(), 14,
00524         font::NORMAL_COLOUR, height_label, 0, 0);
00525 
00526     SDL_Rect x_offset_rect = font::draw_text(NULL, screen_area(), 14,
00527         font::NORMAL_COLOUR, x_offset_label, 0, 0);
00528 
00529     SDL_Rect y_offset_rect = font::draw_text(NULL, screen_area(), 14,
00530         font::NORMAL_COLOUR, y_offset_label, 0, 0);
00531 
00532     // store the width of all labels in an array to determine the maximum
00533     const int label_arr_size = 4;
00534     int label_arr[label_arr_size] =
00535         { width_rect.w, height_rect.w, x_offset_rect.w, y_offset_rect.w };
00536 
00537     // use the biggest label to deterimine the right side for the labels
00538     const int text_right = xpos + horz_margin +
00539             *std::max_element(label_arr, label_arr + label_arr_size);
00540 
00541     width_rect.x = text_right - width_rect.w;
00542     height_rect.x = text_right - height_rect.w;
00543     x_offset_rect.x = text_right - x_offset_rect.w;
00544     y_offset_rect.x = text_right - y_offset_rect.w;
00545 
00546     width_rect.y = ypos + title_rect.h + vertical_margin * 2;
00547     height_rect.y = width_rect.y + width_rect.h + vertical_margin;
00548     x_offset_rect.y = height_rect.y + height_rect.h + vertical_margin * 2;
00549     y_offset_rect.y = x_offset_rect.y + x_offset_rect.h + vertical_margin;
00550 
00551     gui::button cancel_button(disp.video(), _("Cancel"));
00552     gui::button ok_button(disp.video(), _("OK"));
00553 
00554     cancel_button.set_location(
00555         xpos + dlg_width - cancel_button.width() - horz_margin,
00556         ypos + dlg_height - cancel_button.height() - 14);
00557 
00558     ok_button.set_location(
00559         xpos + dlg_width - cancel_button.width() - horz_margin - ok_button.width() - button_padding,
00560         ypos + dlg_height - ok_button.height()-14);
00561 
00562     const int right_space = 100;
00563     const int slider_left = text_right + 10;
00564     const int slider_right = xpos + dlg_width - horz_margin - right_space;
00565     SDL_Rect slider_rect =
00566         { slider_left, width_rect.y, slider_right-slider_left, width_rect.h};
00567 
00568     slider_rect.y = width_rect.y;
00569     gui::slider width_slider(disp.video());
00570     width_slider.set_location(slider_rect);
00571     width_slider.set_min(map_min_width);
00572     width_slider.set_max(map_max_width);
00573     width_slider.set_value(width);
00574 
00575     slider_rect.y = height_rect.y;
00576     gui::slider height_slider(disp.video());
00577     height_slider.set_location(slider_rect);
00578     height_slider.set_min(map_min_height);
00579     height_slider.set_max(map_max_height);
00580     height_slider.set_value(height);
00581 
00582     slider_rect.y = x_offset_rect.y;
00583     gui::slider x_offset_slider(disp.video());
00584     x_offset_slider.set_location(slider_rect);
00585     x_offset_slider.set_min(-map_max_height);
00586     x_offset_slider.set_max(map_max_height);
00587     x_offset_slider.set_value(x_offset);
00588 
00589     slider_rect.y = y_offset_rect.y;
00590     gui::slider y_offset_slider(disp.video());
00591     y_offset_slider.set_location(slider_rect);
00592     y_offset_slider.set_min(-map_max_height);
00593     y_offset_slider.set_max(map_max_height);
00594     y_offset_slider.set_value(y_offset);
00595 
00596     slider_rect.y += y_offset_rect.h + vertical_margin * 2;
00597     gui::button do_expand_button(disp.video(), _("Smart expand"), gui::button::TYPE_CHECK);
00598     // assume the width will be correct for this widget
00599     do_expand_button.set_location(slider_rect);
00600     do_expand_button.set_check(do_expand);
00601 
00602     for(bool draw = true;; draw = false) {
00603         if(cancel_button.pressed()) {
00604             return false;
00605         }
00606         if (static_cast<unsigned>(width_slider.value()) != width
00607                 || static_cast<unsigned>(height_slider.value()) != height
00608                 || x_offset_slider.value() != x_offset
00609                 || y_offset_slider.value() != y_offset
00610                 || do_expand_button.checked() != do_expand) {
00611 
00612             draw = true;
00613         }
00614         if (draw) {
00615             width = width_slider.value();
00616             height = height_slider.value();
00617             x_offset = x_offset_slider.value();
00618             y_offset = y_offset_slider.value();
00619             do_expand = do_expand_button.checked();
00620 
00621             frame.draw_background();
00622             frame.draw_border();
00623 
00624             title_rect = font::draw_text(&disp.video(), screen_area(), 24,
00625                 font::NORMAL_COLOUR, _("Resize Map"),
00626                 xpos + (dlg_width - title_rect.w) / 2, ypos + 10);
00627 
00628             font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
00629                 width_label, width_rect.x, width_rect.y);
00630 
00631             font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
00632                 height_label, height_rect.x, height_rect.y);
00633 
00634             font::draw_text(&disp.video(), screen_area(), 14, font::NORMAL_COLOUR,
00635                 x_offset_label, x_offset_rect.x, x_offset_rect.y);
00636 
00637             font::draw_text(&disp.video(),screen_area(),14,font::NORMAL_COLOUR,
00638                 y_offset_label, y_offset_rect.x, y_offset_rect.y);
00639 
00640             font::draw_text(&disp.video(), screen_area(), 14,
00641                 font::NORMAL_COLOUR, lexical_cast<std::string>(width),
00642                 slider_right + horz_margin, width_rect.y);
00643 
00644             font::draw_text(&disp.video(), screen_area(), 14,
00645                 font::NORMAL_COLOUR, lexical_cast<std::string>(height),
00646                 slider_right + horz_margin, height_rect.y);
00647 
00648             font::draw_text(&disp.video(), screen_area(), 14,
00649                 font::NORMAL_COLOUR, lexical_cast<std::string>(x_offset),
00650                 slider_right + horz_margin, x_offset_rect.y);
00651 
00652             font::draw_text(&disp.video(), screen_area(), 14,
00653                 font::NORMAL_COLOUR, lexical_cast<std::string>(y_offset),
00654                 slider_right + horz_margin, y_offset_rect.y);
00655 
00656         }
00657         if (ok_button.pressed()) {
00658             return true;
00659         }
00660         // make sure the all elements are redrawn
00661         cancel_button.set_dirty();
00662         ok_button.set_dirty();
00663 
00664         width_slider.set_dirty();
00665         height_slider.set_dirty();
00666         x_offset_slider.set_dirty();
00667         y_offset_slider.set_dirty();
00668         do_expand_button.set_dirty();
00669 
00670         events::raise_process_event();
00671         events::raise_draw_event();
00672 
00673         if (draw) {
00674             update_rect(xpos, ypos, dlg_width, dlg_height);
00675         }
00676 
00677         disp.update_display();
00678         SDL_Delay(20);
00679         events::pump();
00680     }
00681 
00682 }
00683 
00684 FLIP_AXIS flip_dialog(display &disp) {
00685     std::vector<std::string> items;
00686     items.push_back(_("X-Axis"));
00687     items.push_back(_("Y-Axis"));
00688     const std::string msg = _("Flip around (this may change the dimensions of the map):");
00689      gui::dialog flipmenu = gui::dialog(disp, "",
00690                          font::word_wrap_text(msg, 12, 180),
00691                          gui::OK_CANCEL);
00692     flipmenu.set_menu(items);
00693     switch (flipmenu.show()) {
00694     case 0:
00695         return FLIP_X;
00696     case 1:
00697         return FLIP_Y;
00698     default:
00699         return NO_FLIP;
00700     }
00701 }
00702 
00703 }
00704 
00705 
00706 

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs