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_border;
00077 };
00078
00079
00080
00081 void
00082 Button::initialize
00083 (
00084 IN const Datahash * hash,
00085 IN smart_ptr<Drawer>& drawer
00086 )
00087 {
00088 ASSERT(hash, "null");
00089 ASSERT(drawer, "null");
00090
00091 m_drawer = drawer;
00092 m_label = getString(hash, "label");
00093 m_submit = getString(hash, "submit");
00094
00095 font_size_t fs =
00096 m_drawer->getFontSizing(eElement_Button, m_label.c_str());
00097
00098 m_width = fs.width;
00099 m_height = fs.height;
00100
00101
00102 border_size_t bs = m_drawer->getBorderSizing(eElement_Button);
00103 m_border = bs.size;
00104 m_width += 2 * m_border;
00105 m_height += 2 * m_border;
00106 }
00107
00108
00109
00110 void
00111 Button::draw
00112 (
00113 IN const point_t& offset
00114 )
00115 {
00116 ASSERT(m_drawer, "null");
00117
00118
00119 rect_t r(offset.x, offset.y, offset.x + m_width, offset.y + m_height);
00120
00121
00122 m_drawer->drawRectWithBorder(eElement_Button, r);
00123
00124
00125 point_t pos(offset.x + m_border, offset.y + m_border);
00126 m_drawer->drawString(eElement_Button, pos, m_label.c_str());
00127 }
00128
00129
00130
00131 const char *
00132 Button::button
00133 (
00134 IN int button,
00135 IN int state,
00136 IN const point_t& pos
00137 )
00138 {
00139
00140
00141
00142 return m_submit.c_str();
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 smart_ptr<Element>
00154 createButtonElement
00155 (
00156 IN Manager * mgr,
00157 IN const Datahash * hash
00158 )
00159 {
00160 ASSERT(mgr, "null");
00161 ASSERT(hash, "null");
00162
00163 smart_ptr<Button> local = new Button;
00164 ASSERT(local, "out of memory");
00165
00166 smart_ptr<Drawer> drawer = mgr->getDrawer();
00167 local->initialize(hash, drawer);
00168
00169 return local;
00170 }
00171
00172
00173
00174 };
00175