00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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,
00040 CONTINUE_DIALOG=-2,
00041 CLOSE_DIALOG=-1
00042
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
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
00092 void draw_border();
00093 void draw_background();
00094
00095
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
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
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
00165
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
00178
00179
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