show_dialog.hpp

Go to the documentation of this file.
00001 /* $Id: show_dialog.hpp 23842 2008-02-16 08:47:16Z mordante $ */
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 #ifndef SHOW_DIALOG_HPP_INCLUDED
00016 #define SHOW_DIALOG_HPP_INCLUDED
00017 
00018 class config;
00019 class CVideo;
00020 class display;
00021 
00022 #include "cursor.hpp"
00023 #include "font.hpp"
00024 #include "network.hpp"
00025 #include "tooltips.hpp"
00026 
00027 #include "widgets/menu.hpp"
00028 
00029 #include "SDL.h"
00030 
00031 #include <string>
00032 #include <vector>
00033 
00034 namespace gui
00035 {
00036 
00037 extern const int ButtonHPadding;
00038 extern const int ButtonVPadding;
00039 enum DIALOG_RESULT {
00040     DIALOG_BACK=-7,
00041     DIALOG_FORWARD=-6,
00042     CREATE_ITEM =-5,
00043     DELETE_ITEM=-4,
00044     ESCAPE_DIALOG=-3, //special return used by WML event dialogs
00045     CONTINUE_DIALOG=-2,
00046     CLOSE_DIALOG=-1
00047     /* results (0..N) reserved for standard button indeces */
00048 };
00049 
00050 bool in_dialog();
00051 
00052 struct dialog_manager : private cursor::setter, private font::floating_label_context {
00053     dialog_manager();
00054     ~dialog_manager();
00055 
00056 private:
00057     bool reset_to;
00058 };
00059 
00060 class dialog_frame {
00061 public:
00062     struct dimension_measurements {
00063         dimension_measurements();
00064         SDL_Rect interior, exterior, title, button_row;
00065     };
00066     class style {
00067     public:
00068         style(std::string const& p, int br) : panel(p), blur_radius(br) {}
00069         std::string panel;
00070         int blur_radius;
00071     };
00072 
00073     //Static members
00074     static const int title_border_w, title_border_h;
00075     static const style default_style;
00076     static const style message_style;
00077     static const style preview_style;
00078     static const style titlescreen_style;
00079 
00080     dialog_frame(CVideo &video, const std::string& title="",
00081         const style& dialog_style=default_style,
00082         bool auto_restore=true, std::vector<button*>* buttons=NULL,
00083         button* help_button=NULL);
00084     ~dialog_frame();
00085 
00086     dimension_measurements layout(int x, int y, int w, int h);
00087     dimension_measurements layout(SDL_Rect const& frame_area);
00088     void set_layout(dimension_measurements &new_dim) { dim_ = new_dim; }
00089     dimension_measurements get_layout() const { return dim_; }
00090 
00091     int top_padding() const;
00092     int bottom_padding() const;
00093 
00094     void draw();
00095 
00096     //called by draw
00097     void draw_border();
00098     void draw_background();
00099 
00100     //also called by layout with null param
00101     SDL_Rect draw_title(CVideo *video);
00102 
00103 private:
00104     void clear_background();
00105 
00106     std::string title_;
00107     CVideo &video_;
00108     const style& dialog_style_;
00109     std::vector<button*>* buttons_;
00110     button* help_button_;
00111     surface_restorer* restorer_;
00112     bool auto_restore_;
00113     dimension_measurements dim_;
00114     surface top_, bot_, left_, right_, top_left_, bot_left_, top_right_, bot_right_, bg_;
00115     bool have_border_;
00116 };
00117 
00118 //frame_measurements draw_dialog_frame(int x, int y, int w, int h, CVideo &video, const std::string* dialog_style=NULL, surface_restorer* restorer=NULL);
00119 
00120 //SDL_Rect draw_dialog_background(int x, int y, int w, int h, CVideo &video, const std::string& dialog_style);
00121 
00122 //given the location of a dialog, will draw its title.
00123 //Returns the area the title takes up
00124 //SDL_Rect draw_dialog_title(int x, int y, CVideo* disp, const std::string& text, label** label_widget);
00125 
00126 //function to draw a dialog on the screen. x,y,w,h give the dimensions of the client area
00127 //of the dialog. 'title' is the title of the dialog. The title will be displayed at the
00128 //top of the dialog above the client area. 'dialog_style' if present gives the style of
00129 //the dialog to use.
00130 //'buttons' contains pointers to standard dialog buttons such as 'ok' and 'cancel' that
00131 //will appear on the dialog. If present, they will be located at the bottom of the dialog,
00132 //below the client area.
00133 //if 'restorer' is present, it will be set to a restorer that will reset the screen area
00134 //to its original state after the dialog is drawn.
00135 //void draw_dialog(int x, int y, int w, int h, CVideo &video, const std::string& title,
00136  //                const std::string* dialog_style=NULL, std::vector<button*>* buttons=NULL,
00137  //                surface_restorer* restorer=NULL, button* help_button=NULL, label** label_widget);
00138 //void draw_dialog(frame_measurements &fm, CVideo &video, const std::string& title,
00139  //                const std::string* dialog_style=NULL, std::vector<button*>* buttons=NULL,
00140  //                surface_restorer* restorer=NULL, button* help_button=NULL, label** label_widget);
00141 
00142 class dialog_button_action
00143 {
00144 public:
00145     virtual ~dialog_button_action() {}
00146 
00147     typedef DIALOG_RESULT RESULT;
00148 
00149     virtual RESULT button_pressed(int menu_selection) = 0;
00150 };
00151 
00152 struct dialog_button_info
00153 {
00154     dialog_button_info(dialog_button_action* handler, const std::string& label) : handler(handler), label(label)
00155     {}
00156 
00157     dialog_button_action* handler;
00158     std::string label;
00159 };
00160 
00161 enum DIALOG_TYPE { MESSAGE, OK_ONLY, YES_NO, OK_CANCEL, CANCEL_ONLY, CLOSE_ONLY, NULL_DIALOG };
00162 
00163 struct check_item {
00164     check_item(const std::string& label, bool checked) : label(label), checked(checked) {}
00165     std::string label;
00166     bool checked;
00167 };
00168 
00169 //an interface for a 'preview pane'. A preview pane is shown beside a dialog created
00170 //by 'show_dialog' and shows information about the selection.
00171 class preview_pane : public widget {
00172 public:
00173     preview_pane(CVideo &video) : widget(video, false) {}
00174     virtual ~preview_pane() { tooltips::clear_tooltips(location()); }
00175 
00176     virtual bool show_above() const { return false; }
00177     virtual bool left_side() const = 0;
00178     virtual void set_selection(int index) = 0;
00179     virtual handler_vector handler_members() { return widget::handler_members(); }
00180 };
00181 
00182 //if a menu is given, then returns -1 if the dialog was cancelled, and the
00183 //index of the selection otherwise. If no menu is given, returns the index
00184 //of the button that was pressed
00185 int show_dialog(display &screen, surface image,
00186                 const std::string& caption, const std::string& message,
00187                 DIALOG_TYPE type=MESSAGE,
00188                 const std::vector<std::string>* menu_items=NULL,
00189                 const std::vector<preview_pane*>* preview_panes=NULL,
00190                 const std::string& text_widget_label="",
00191                 std::string* text_widget_text=NULL,
00192                 const int text_widget_max_chars = 256,
00193                 std::vector<check_item>* options=NULL, 
00194                 int xloc=-1, 
00195                 int yloc=-1,
00196                 const dialog_frame::style* dialog_style=NULL,
00197                 std::vector<dialog_button_info>* buttons=NULL,
00198                 const menu::sorter* sorter=NULL,
00199                 menu::style* menu_style=NULL
00200              );
00201 
00202 void show_error_message(display &disp, std::string const &message);
00203 
00204 void check_quit(CVideo &video);
00205 
00206 }
00207 
00208 #endif

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