00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __GUI_WIDGETS_WINDOW_HPP_INCLUDED__
00020 #define __GUI_WIDGETS_WINDOW_HPP_INCLUDED__
00021
00022 #include "gui/widgets/canvas.hpp"
00023 #include "gui/widgets/event_handler.hpp"
00024 #include "gui/widgets/helper.hpp"
00025 #include "gui/widgets/panel.hpp"
00026 #include "gui/widgets/settings.hpp"
00027 #include "gui/widgets/tooltip.hpp"
00028
00029 #include "sdl_utils.hpp"
00030 #include "video.hpp"
00031
00032 #include "tstring.hpp"
00033 #include "config.hpp"
00034 #include "variable.hpp"
00035
00036 #include "events.hpp"
00037 #include "SDL.h"
00038
00039 #include <string>
00040 #include <map>
00041
00042 namespace gui2{
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 class twindow : public tpanel, public tevent_handler
00053 {
00054 public:
00055 twindow(CVideo& video,
00056 const int x, const int y, const int w, const int h,
00057 const bool automatic_placement,
00058 const unsigned horizontal_placement,
00059 const unsigned vertical_placement);
00060
00061
00062
00063 int show(const bool restore = true, void* flip_function = 0);
00064
00065
00066 void layout(const SDL_Rect position);
00067
00068 enum tstatus{ NEW, SHOWING, REQUEST_CLOSE, CLOSED };
00069
00070 void close() { status_ = REQUEST_CLOSE; }
00071
00072 void set_retval(const int retval, const bool close_window = true)
00073 { retval_ = retval; if(close_window) close(); }
00074
00075
00076 twindow& get_window() { return *this; }
00077 const twindow& get_window() const { return *this; }
00078
00079
00080 twidget* find_widget(const tpoint& coordinate, const bool must_be_active)
00081 { return tpanel::find_widget(coordinate, must_be_active); }
00082
00083
00084 const twidget* find_widget(const tpoint& coordinate,
00085 const bool must_be_active) const
00086 { return tpanel::find_widget(coordinate, must_be_active); }
00087
00088
00089 twidget* find_widget(const std::string& id, const bool must_be_active)
00090 { return tpanel::find_widget(id, must_be_active); }
00091
00092
00093 const twidget* find_widget(const std::string& id,
00094 const bool must_be_active) const
00095 { return tpanel::find_widget(id, must_be_active); }
00096
00097 tpoint client_position(const tpoint& screen_position) const
00098 { return tpoint(screen_position.x - get_x(), screen_position.y - get_y()); }
00099
00100 tpoint screen_position(const tpoint& client_position) const
00101 { return tpoint(client_position.x + get_x(), client_position.y + get_y()); }
00102
00103
00104 void window_resize(tevent_handler&,
00105 const unsigned new_width, const unsigned new_height);
00106
00107
00108 void set_active(const bool ) {}
00109 bool get_active() const { return true; }
00110 unsigned get_state() const { return 0; }
00111 bool full_redraw() const { return false; }
00112
00113
00114 void draw(surface& surface);
00115
00116
00117
00118
00119 SDL_Rect get_client_rect() const;
00120
00121
00122
00123
00124
00125
00126
00127
00128 void recalculate_size();
00129
00130 protected:
00131 private:
00132
00133
00134 void flip();
00135
00136 CVideo& video_;
00137
00138 tstatus status_;
00139
00140
00141 int retval_;
00142
00143
00144 bool need_layout_;
00145
00146
00147
00148 void do_show_tooltip(const tpoint& location, const t_string& tooltip);
00149 void do_remove_tooltip() { tooltip_.set_visible(false); }
00150 void do_show_help_popup(const tpoint& location, const t_string& help_popup);
00151 void do_remove_help_popup() { help_popup_.set_visible(false); }
00152
00153
00154 ttooltip tooltip_;
00155
00156
00157 ttooltip help_popup_;
00158
00159
00160 const std::string& get_control_type() const
00161 { static const std::string type = "window"; return type; }
00162
00163
00164
00165 const bool automatic_placement_;
00166
00167
00168
00169
00170
00171
00172
00173 const unsigned horizontal_placement_;
00174
00175
00176
00177
00178
00179
00180
00181 const unsigned vertical_placement_;
00182
00183 };
00184
00185 }
00186
00187 #endif