aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/TextButton.cc
diff options
context:
space:
mode:
authorsimonb <simonb>2006-03-26 04:02:30 (GMT)
committersimonb <simonb>2006-03-26 04:02:30 (GMT)
commitaf74a2284551c8511b66d77112c7bf32831c1522 (patch)
tree35a8830352f5facc1fc9c58b82c0c6dce8fc921e /src/FbTk/TextButton.cc
parent872f6a0e1e4230f702ad69fa2d7e10a2fa78b7a3 (diff)
downloadfluxbox_pavel-af74a2284551c8511b66d77112c7bf32831c1522.zip
fluxbox_pavel-af74a2284551c8511b66d77112c7bf32831c1522.tar.bz2
rotated fonts, buttons, containers. Used for tabs for now
Diffstat (limited to 'src/FbTk/TextButton.cc')
-rw-r--r--src/FbTk/TextButton.cc49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc
index ba15280..1d5936c 100644
--- a/src/FbTk/TextButton.cc
+++ b/src/FbTk/TextButton.cc
@@ -28,16 +28,18 @@
28namespace FbTk { 28namespace FbTk {
29 29
30TextButton::TextButton(const FbTk::FbWindow &parent, 30TextButton::TextButton(const FbTk::FbWindow &parent,
31 const FbTk::Font &font, 31 FbTk::Font &font,
32 const std::string &text): 32 const std::string &text):
33 FbTk::Button(parent, 0, 0, 10, 10), 33 FbTk::Button(parent, 0, 0, 10, 10),
34 m_font(&font), 34 m_font(&font),
35 m_text(text), 35 m_text(text),
36 m_justify(FbTk::LEFT), m_bevel(1), 36 m_justify(FbTk::LEFT),
37 m_orientation(FbTk::ROT0),
38 m_bevel(1),
37 m_left_padding(0), 39 m_left_padding(0),
38 m_right_padding(0) { 40 m_right_padding(0) {
39 setRenderer(*this);
40 41
42 setRenderer(*this);
41} 43}
42 44
43void TextButton::resize(unsigned int width, unsigned int height) { 45void TextButton::resize(unsigned int width, unsigned int height) {
@@ -60,6 +62,23 @@ void TextButton::setJustify(FbTk::Justify just) {
60 m_justify = just; 62 m_justify = just;
61} 63}
62 64
65bool TextButton::setOrientation(FbTk::Orientation orient) {
66 if (!m_font->validOrientation(orient))
67 return false;
68
69 if ((m_orientation == FbTk::ROT0 || m_orientation == FbTk::ROT180) &&
70 (orient == FbTk::ROT90 || orient == FbTk::ROT270) ||
71 (m_orientation == FbTk::ROT90 || m_orientation == FbTk::ROT270) &&
72 (orient == FbTk::ROT0 || orient == FbTk::ROT180)) {
73 // flip width and height
74 m_orientation = orient;
75 resize(height(), width());
76 } else {
77 m_orientation = orient;
78 }
79 return true;
80}
81
63void TextButton::setText(const std::string &text) { 82void TextButton::setText(const std::string &text) {
64 if (m_text != text) { 83 if (m_text != text) {
65 m_text = text; 84 m_text = text;
@@ -68,7 +87,7 @@ void TextButton::setText(const std::string &text) {
68 } 87 }
69} 88}
70 89
71void TextButton::setFont(const FbTk::Font &font) { 90void TextButton::setFont(FbTk::Font &font) {
72 // no need to set new font if it's the same 91 // no need to set new font if it's the same
73 if (&font == m_font) 92 if (&font == m_font)
74 return; 93 return;
@@ -109,10 +128,16 @@ void TextButton::clearArea(int x, int y,
109 drawText(0, 0, this); 128 drawText(0, 0, this);
110} 129}
111 130
131
112unsigned int TextButton::textWidth() const { 132unsigned int TextButton::textWidth() const {
113 return font().textWidth(text().c_str(), text().size()); 133 return font().textWidth(text().c_str(), text().size());
114} 134}
115 135
136unsigned int TextButton::textHeight() const {
137 return font().height();
138
139}
140
116void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) { 141void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) {
117 // (win should always be *this, no need to check) 142 // (win should always be *this, no need to check)
118 drawText(0, 0, &drawable); 143 drawText(0, 0, &drawable);
@@ -122,7 +147,10 @@ void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) {
122 unsigned int textlen = text().size(); 147 unsigned int textlen = text().size();
123 // do text alignment 148 // do text alignment
124 149
125 int align_x = FbTk::doAlignment(width() - x_offset - m_left_padding - m_right_padding, 150 unsigned int textw = width(), texth = height();
151 translateSize(m_orientation, textw, texth);
152
153 int align_x = FbTk::doAlignment(textw - x_offset - m_left_padding - m_right_padding,
126 bevel(), 154 bevel(),
127 justify(), 155 justify(),
128 font(), 156 font(),
@@ -130,17 +158,22 @@ void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) {
130 textlen); // return new text lne 158 textlen); // return new text lne
131 159
132 // center text by default 160 // center text by default
133 int center_pos = height()/2 + font().ascent()/2 - 1; 161 int center_pos = texth/2 + font().ascent()/2 - 1;
162
163 int textx = align_x + x_offset + m_left_padding;
164 int texty = center_pos + y_offset;
134 165
135 if (drawable == 0) 166 if (drawable == 0)
136 drawable = this; 167 drawable = this;
137 168
169 // give it ROT0 style coords
170 translateCoords(m_orientation, textx, texty, textw, texth);
171
138 font().drawText(*drawable, 172 font().drawText(*drawable,
139 screenNumber(), 173 screenNumber(),
140 gc(), // graphic context 174 gc(), // graphic context
141 text().c_str(), textlen, // string and string size 175 text().c_str(), textlen, // string and string size
142 align_x + x_offset + m_left_padding, center_pos + y_offset); // position 176 textx, texty, m_orientation); // position
143
144} 177}
145 178
146void TextButton::exposeEvent(XExposeEvent &event) { 179void TextButton::exposeEvent(XExposeEvent &event) {