aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/TextButton.cc
diff options
context:
space:
mode:
authorsimonb <simonb>2005-04-26 01:41:55 (GMT)
committersimonb <simonb>2005-04-26 01:41:55 (GMT)
commit1c2f92a3d2288b1cae9500110a72173506a18072 (patch)
treecdb695da16dcee74872790c772bb535def9f2895 /src/FbTk/TextButton.cc
parentb49432be05c6cf748e662e196778463e2190b4c3 (diff)
downloadfluxbox-1c2f92a3d2288b1cae9500110a72173506a18072.zip
fluxbox-1c2f92a3d2288b1cae9500110a72173506a18072.tar.bz2
extension of previous big patch. Move a bunch of menu things onto
background pixmap. Same for textbuttons.
Diffstat (limited to 'src/FbTk/TextButton.cc')
-rw-r--r--src/FbTk/TextButton.cc30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc
index fdbdc78..9a16c2c 100644
--- a/src/FbTk/TextButton.cc
+++ b/src/FbTk/TextButton.cc
@@ -24,8 +24,6 @@
24#include "TextButton.hh" 24#include "TextButton.hh"
25#include "Font.hh" 25#include "Font.hh"
26#include "GContext.hh" 26#include "GContext.hh"
27#include <iostream>
28using namespace std;
29 27
30namespace FbTk { 28namespace FbTk {
31 29
@@ -38,6 +36,7 @@ TextButton::TextButton(const FbTk::FbWindow &parent,
38 m_justify(FbTk::LEFT), m_bevel(1), 36 m_justify(FbTk::LEFT), m_bevel(1),
39 m_left_padding(0), 37 m_left_padding(0),
40 m_right_padding(0) { 38 m_right_padding(0) {
39 setRenderer(*this);
41 40
42} 41}
43 42
@@ -62,7 +61,11 @@ void TextButton::setJustify(FbTk::Justify just) {
62} 61}
63 62
64void TextButton::setText(const std::string &text) { 63void TextButton::setText(const std::string &text) {
65 m_text = text; 64 if (m_text != text) {
65 m_text = text;
66 parentMoved();
67 clear();
68 }
66} 69}
67 70
68void TextButton::setFont(const FbTk::Font &font) { 71void TextButton::setFont(const FbTk::Font &font) {
@@ -102,30 +105,37 @@ void TextButton::clearArea(int x, int y,
102 unsigned int width, unsigned int height, 105 unsigned int width, unsigned int height,
103 bool exposure) { 106 bool exposure) {
104 Button::clearArea(x, y, width, height, exposure); 107 Button::clearArea(x, y, width, height, exposure);
105 // TODO: do we need to check if the text overlaps the clearing area 108 if (backgroundPixmap() == ParentRelative)
106 // and if so, then clear a rectangle that encompases all the text plus the 109 drawText(0, 0, this);
107 // requested area?
108 drawText();
109} 110}
110 111
111unsigned int TextButton::textWidth() const { 112unsigned int TextButton::textWidth() const {
112 return font().textWidth(text().c_str(), text().size()); 113 return font().textWidth(text().c_str(), text().size());
113} 114}
114 115
115void TextButton::drawText(int x_offset, int y_offset) { 116void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) {
117 // (win should always be *this, no need to check)
118 drawText(0, 0, &drawable);
119}
120
121void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) {
116 unsigned int textlen = text().size(); 122 unsigned int textlen = text().size();
117 // do text alignment 123 // do text alignment
124
118 int align_x = FbTk::doAlignment(width() - x_offset - m_left_padding - m_right_padding, 125 int align_x = FbTk::doAlignment(width() - x_offset - m_left_padding - m_right_padding,
119 bevel(), 126 bevel(),
120 justify(), 127 justify(),
121 font(), 128 font(),
122 text().c_str(), text().size(), 129 text().c_str(), text().size(),
123 textlen); // return new text len 130 textlen); // return new text lne
124 131
125 // center text by default 132 // center text by default
126 int center_pos = height()/2 + font().ascent()/2 - 1; 133 int center_pos = height()/2 + font().ascent()/2 - 1;
127 134
128 font().drawText(*this, 135 if (drawable == 0)
136 drawable = this;
137
138 font().drawText(*drawable,
129 screenNumber(), 139 screenNumber(),
130 gc(), // graphic context 140 gc(), // graphic context
131 text().c_str(), textlen, // string and string size 141 text().c_str(), textlen, // string and string size