aboutsummaryrefslogtreecommitdiff
path: root/src/TextButton.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/TextButton.cc')
-rw-r--r--src/TextButton.cc92
1 files changed, 0 insertions, 92 deletions
diff --git a/src/TextButton.cc b/src/TextButton.cc
deleted file mode 100644
index 3424533..0000000
--- a/src/TextButton.cc
+++ /dev/null
@@ -1,92 +0,0 @@
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.4 2003/08/13 10:12:36 fluxgen Exp $
23
24#include "TextButton.hh"
25#include "Font.hh"
26
27#include <iostream>
28using namespace std;
29
30TextButton::TextButton(const FbTk::FbWindow &parent,
31 const FbTk::Font &font,
32 const std::string &text):
33 FbTk::Button(parent, 0, 0, 10, 10),
34 m_font(&font),
35 m_text(text),
36 m_justify(FbTk::LEFT), m_bevel(1) {
37
38}
39
40void TextButton::setJustify(FbTk::Justify just) {
41 m_justify = just;
42}
43
44void TextButton::setText(const std::string &text) {
45 m_text = text;
46}
47
48void TextButton::setFont(const FbTk::Font &font) {
49 // no need to set new font if it's the same
50 if (&font == m_font)
51 return;
52 m_font = &font;
53 clear(); // redraw text with new font
54}
55
56/// set bevel and redraw text
57void TextButton::setBevel(int bevel) {
58 if (m_bevel == bevel)
59 return;
60 m_bevel = bevel;
61}
62
63/// clear window and redraw text
64void TextButton::clear() {
65 FbTk::Button::clear();
66 drawText();
67}
68
69unsigned int TextButton::textWidth() const {
70 return font().textWidth(text().c_str(), text().size());
71}
72
73void TextButton::drawText(int x_offset, int y_offset) {
74 unsigned int textlen = text().size();
75 // do text alignment
76 int align_x = FbTk::doAlignment(width() - x_offset,
77 bevel(),
78 justify(),
79 font(),
80 text().c_str(), text().size(),
81 textlen // return new text len
82 );
83
84 // center text by default
85 int center_pos = height()/2 + font().ascent()/2;
86
87 font().drawText(window(), // drawable
88 screenNumber(),
89 gc(), // graphic context
90 text().c_str(), textlen, // string and string size
91 align_x + x_offset, center_pos + y_offset); // position
92}