show_dialog.hpp

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

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:10 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs