aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/TextButton.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-08-18 12:15:39 (GMT)
committerfluxgen <fluxgen>2003-08-18 12:15:39 (GMT)
commit443874957b66380a6017314cb7fd6ad40df79f2a (patch)
tree57981cd682d9d9fb4aefcb02bbee32172ce7aac3 /src/FbTk/TextButton.cc
parent8bf640a79948368a9bb325af6176a1676ef36b71 (diff)
downloadfluxbox-443874957b66380a6017314cb7fd6ad40df79f2a.zip
fluxbox-443874957b66380a6017314cb7fd6ad40df79f2a.tar.bz2
moved from fluxbox main source
Diffstat (limited to 'src/FbTk/TextButton.cc')
-rw-r--r--src/FbTk/TextButton.cc96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc
new file mode 100644
index 0000000..9518627
--- /dev/null
+++ b/src/FbTk/TextButton.cc
@@ -0,0 +1,96 @@
1// TextButton.cc for Fluxbox Window Manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen[at]fluxbox.org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: TextButton.cc,v 1.1 2003/08/18 12:15:39 fluxgen Exp $
23
24#include "TextButton.hh"
25#include "Font.hh"
26
27#include <iostream>
28using namespace std;
29
30namespace FbTk {
31
32TextButton::TextButton(const FbTk::FbWindow &parent,
33 const FbTk::Font &font,
34 const std::string &text):
35 FbTk::Button(parent, 0, 0, 10, 10),
36 m_font(&font),
37 m_text(text),
38 m_justify(FbTk::LEFT), m_bevel(1) {
39
40}
41
42void TextButton::setJustify(FbTk::Justify just) {
43 m_justify = just;
44}
45
46void TextButton::setText(const std::string &text) {
47 m_text = text;
48}
49
50void TextButton::setFont(const FbTk::Font &font) {
51 // no need to set new font if it's the same
52 if (&font == m_font)
53 return;
54 m_font = &font;
55 clear(); // redraw text with new font
56}
57
58/// set bevel and redraw text
59void TextButton::setBevel(int bevel) {
60 if (m_bevel == bevel)
61 return;
62 m_bevel = bevel;
63}
64
65/// clear window and redraw text
66void TextButton::clear() {
67 FbTk::Button::clear();
68 drawText();
69}
70
71unsigned int TextButton::textWidth() const {
72 return font().textWidth(text().c_str(), text().size());
73}
74
75void TextButton::drawText(int x_offset, int y_offset) {
76 unsigned int textlen = text().size();
77 // do text alignment
78 int align_x = FbTk::doAlignment(width() - x_offset,
79 bevel(),
80 justify(),
81 font(),
82 text().c_str(), text().size(),
83 textlen // return new text len
84 );
85
86 // center text by default
87 int center_pos = height()/2 + font().ascent()/2;
88
89 font().drawText(window(), // drawable
90 screenNumber(),
91 gc(), // graphic context
92 text().c_str(), textlen, // string and string size
93 align_x + x_offset, center_pos + y_offset); // position
94}
95
96}; // end namespace FbTk