Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "element.h"
00036
00037 #include "dialog.h"
00038
00039 #include "datahash/datahash_util.h"
00040
00041
00042 namespace dialog {
00043
00044
00045
00046
00047
00048
00049
00050
00051 class Button : public Element {
00052 public:
00053 ~Button(void) throw() { }
00054
00055
00056 void initialize(IN const Datahash * hash,
00057 IN smart_ptr<Drawer>& drawer);
00058
00059
00060 int getWidth(void) { return m_width; }
00061 int getHeight(void) { return m_height; }
00062 void draw(IN const point_t& offset);
00063 void cursor(IN const point_t& pos) { }
00064 const char * button(IN int button, IN int state,
00065 IN const point_t& pos);
00066
00067 private:
00068
00069
00070
00071 smart_ptr<Drawer> m_drawer;
00072 std::string m_label;
00073 std::string m_submit;
00074 int m_width;
00075 int m_height;
00076 int m_rise;
00077 int m_border;
00078 };
00079
00080
00081
00082 void
00083 Button::initialize
00084 (
00085 IN const Datahash * hash,
00086 IN smart_ptr<Drawer>& drawer
00087 )
00088 {
00089 ASSERT(hash, "null");
00090 ASSERT(drawer, "null");
00091
00092 m_drawer = drawer;
00093 m_label = getString(hash, "label");
00094 m_submit = getString(hash, "submit");
00095
00096 font_size_t fs =
00097 m_drawer->getFontSizing(eElement_Button, m_label.c_str());
00098
00099 m_width = fs.lead + fs.trail + 1;
00100 m_height = fs.drop + fs.rise + 1;
00101 m_rise = fs.rise;
00102
00103
00104
00105
00106
00107
00108 border_size_t bs = m_drawer->getBorderSizing(eElement_Button);
00109 m_border = bs.size;
00110 m_width += 2 * m_border;
00111 m_height += 2 * m_border;
00112 }
00113
00114
00115
00116 void
00117 Button::draw
00118 (
00119 IN const point_t& offset
00120 )
00121 {
00122 ASSERT(m_drawer, "null");
00123
00124
00125 rect_t r(offset.x, offset.y, offset.x + m_width, offset.y + m_height);
00126
00127
00128 m_drawer->drawRectWithBorder(eElement_Button, r);
00129
00130
00131 point_t pos(offset.x + m_border, offset.y + m_border + m_rise);
00132 m_drawer->drawString(eElement_Button, pos, m_label.c_str());
00133 }
00134
00135
00136
00137 const char *
00138 Button::button
00139 (
00140 IN int button,
00141 IN int state,
00142 IN const point_t& pos
00143 )
00144 {
00145
00146
00147
00148 return m_submit.c_str();
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 smart_ptr<Element>
00160 createButtonElement
00161 (
00162 IN Manager * mgr,
00163 IN const Datahash * hash
00164 )
00165 {
00166 ASSERT(mgr, "null");
00167 ASSERT(hash, "null");
00168
00169 smart_ptr<Button> local = new Button;
00170 ASSERT(local, "out of memory");
00171
00172 smart_ptr<Drawer> drawer = mgr->getDrawer();
00173 local->initialize(hash, drawer);
00174
00175 return local;
00176 }
00177
00178
00179
00180 };
00181