diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/TextButton.cc | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/TextButton.cc b/src/TextButton.cc index c977a53..7498ee1 100644 --- a/src/TextButton.cc +++ b/src/TextButton.cc | |||
@@ -19,7 +19,7 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 20 | // DEALINGS IN THE SOFTWARE. |
21 | 21 | ||
22 | // $Id: TextButton.cc,v 1.2 2003/04/14 12:08:50 fluxgen Exp $ | 22 | // $Id: TextButton.cc,v 1.3 2003/08/11 14:34:46 fluxgen Exp $ |
23 | 23 | ||
24 | #include "TextButton.hh" | 24 | #include "TextButton.hh" |
25 | #include "Font.hh" | 25 | #include "Font.hh" |
@@ -29,10 +29,11 @@ using namespace std; | |||
29 | 29 | ||
30 | TextButton::TextButton(const FbTk::FbWindow &parent, | 30 | TextButton::TextButton(const FbTk::FbWindow &parent, |
31 | const FbTk::Font &font, | 31 | const FbTk::Font &font, |
32 | const std::string &text):FbTk::Button(parent, 0, 0, 10, 10), | 32 | const std::string &text): |
33 | m_font(&font), | 33 | FbTk::Button(parent, 0, 0, 10, 10), |
34 | m_text(text), | 34 | m_font(&font), |
35 | m_justify(FbTk::LEFT), m_bevel(1) { | 35 | m_text(text), |
36 | m_justify(FbTk::LEFT), m_bevel(1) { | ||
36 | 37 | ||
37 | } | 38 | } |
38 | 39 | ||
@@ -61,21 +62,29 @@ void TextButton::setBevel(int bevel) { | |||
61 | 62 | ||
62 | /// clear window and redraw text | 63 | /// clear window and redraw text |
63 | void TextButton::clear() { | 64 | void TextButton::clear() { |
64 | FbTk::Button::clear(); // clear window and draw background | 65 | FbTk::Button::clear(); |
66 | drawText(); | ||
67 | } | ||
68 | |||
69 | unsigned int TextButton::textWidth() const { | ||
70 | return font().textWidth(text().c_str(), text().size()); | ||
71 | } | ||
72 | |||
73 | void TextButton::drawText(int x_offset, int y_offset) { | ||
65 | unsigned int textlen = text().size(); | 74 | unsigned int textlen = text().size(); |
66 | // do text alignment | 75 | // do text alignment |
67 | int align_x = FbTk::doAlignment(width(), | 76 | int align_x = FbTk::doAlignment(width() - x_offset, |
68 | bevel(), | 77 | bevel(), |
69 | justify(), | 78 | justify(), |
70 | font(), | 79 | font(), |
71 | text().c_str(), text().size(), | 80 | text().c_str(), text().size(), |
72 | textlen // return new text len | 81 | textlen // return new text len |
73 | ); | 82 | ); |
74 | 83 | // center text by default | |
84 | int center_pos = height()/2 + font().ascent()/2; | ||
75 | font().drawText(window().window(), // drawable | 85 | font().drawText(window().window(), // drawable |
76 | window().screenNumber(), | 86 | window().screenNumber(), |
77 | gc(), // graphic context | 87 | gc(), // graphic context |
78 | text().c_str(), textlen, // string and string size | 88 | text().c_str(), textlen, // string and string size |
79 | align_x, font().ascent());// position | 89 | align_x + x_offset, center_pos + y_offset); // position |
80 | } | 90 | } |
81 | |||