00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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,
00045 CONTINUE_DIALOG=-2,
00046 CLOSE_DIALOG=-1
00047
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
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
00097 void draw_border();
00098 void draw_background();
00099
00100
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
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
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
00170
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
00183
00184
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