Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "gui/dialogs/tip.hpp"
00019
00020 #include "gui/dialogs/dialog.hpp"
00021 #include "gui/dialogs/popup.hpp"
00022 #include "gui/widgets/settings.hpp"
00023 #include "gui/widgets/window.hpp"
00024
00025 static lg::log_domain log_config("config");
00026 #define ERR_CFG LOG_STREAM(warn , log_config)
00027
00028 namespace gui2 {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 REGISTER_WINDOW(tooltip_large)
00059
00060
00061
00062
00063
00064
00065
00066
00067 class ttip
00068 : public tpopup
00069 {
00070 public:
00071
00072 ttip()
00073 : tpopup()
00074 , window_id_()
00075 , message_()
00076 , mouse_(tpoint(0, 0))
00077 {
00078 }
00079
00080 void set_window_id(const std::string& window_id)
00081 {
00082 window_id_ = window_id;
00083 }
00084
00085 void set_message(const t_string& message)
00086 {
00087 message_ = message;
00088 }
00089
00090 void set_mouse(const tpoint& mouse)
00091 {
00092 mouse_ = mouse;
00093 }
00094
00095 private:
00096
00097
00098 std::string window_id_;
00099
00100
00101 t_string message_;
00102
00103
00104 tpoint mouse_;
00105
00106
00107 virtual const std::string& window_id() const;
00108
00109
00110 void pre_show(CVideo& video, twindow& window);
00111
00112 };
00113
00114 void ttip::pre_show(CVideo& , twindow& window)
00115 {
00116 find_widget<tcontrol>(&window, "label", false).set_label(message_);
00117
00118 window.set_variable("mouse_x", variant(mouse_.x));
00119 window.set_variable("mouse_y", variant(mouse_.y));
00120 }
00121
00122 const std::string& ttip::window_id() const
00123 {
00124 return window_id_;
00125 }
00126
00127 namespace tip {
00128
00129 static ttip& tip()
00130 {
00131
00132
00133
00134
00135 static ttip *t = new ttip();
00136 return *t;
00137 }
00138
00139 void show(CVideo& video
00140 , const std::string& window_id
00141 , const t_string& message
00142 , const tpoint& mouse)
00143 {
00144
00145
00146
00147
00148 ttip& t = tip();
00149 t.set_window_id(window_id);
00150 t.set_message(message);
00151 t.set_mouse(mouse);
00152 try {
00153 t.show(video);
00154 } catch(twindow_builder_invalid_id&) {
00155 ERR_CFG << "Tip with the requested id '" << window_id
00156 << "' doesn't exist, fall back to the default.\n";
00157 t.set_window_id("tooltip_large");
00158 try {
00159 t.show(video);
00160 } catch(twindow_builder_invalid_id&) {
00161 ERR_CFG << "Default tooltip doesn't exist, no message shown.\n";
00162 }
00163 }
00164 }
00165
00166 void remove()
00167 {
00168 tip().hide();
00169 }
00170
00171 }
00172
00173 }
00174