diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2010-09-08 18:17:21 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2010-09-08 18:17:21 (GMT) |
commit | 690d926ac444243611cd875fb84fabb4e6db2cf2 (patch) | |
tree | c8ef84056b295071f9a9207ffea5393c6cf4ad4d /src/FbTk/TextButton.cc | |
parent | 1e8fe2bc14856fa16508686a28a85e72cb0e422c (diff) | |
download | fluxbox_paul-690d926ac444243611cd875fb84fabb4e6db2cf2.zip fluxbox_paul-690d926ac444243611cd875fb84fabb4e6db2cf2.tar.bz2 |
introduced FbTk::BidiString
a 'BidiString' holds both the logical content and the visual reordered
version of the content of a string. this helps to reduce the number of
calls to reorder the string before drawing it (as introduced in the patch
from Ken Bloom) and to be more consistent in menus and textboxes (drawing
cursors and underlining text).
Diffstat (limited to 'src/FbTk/TextButton.cc')
-rw-r--r-- | src/FbTk/TextButton.cc | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc index 04aa367..c31e3d6 100644 --- a/src/FbTk/TextButton.cc +++ b/src/FbTk/TextButton.cc | |||
@@ -28,7 +28,7 @@ namespace FbTk { | |||
28 | 28 | ||
29 | TextButton::TextButton(const FbTk::FbWindow &parent, | 29 | TextButton::TextButton(const FbTk::FbWindow &parent, |
30 | FbTk::Font &font, | 30 | FbTk::Font &font, |
31 | const std::string &text): | 31 | const FbTk::BiDiString &text): |
32 | FbTk::Button(parent, 0, 0, 10, 10), | 32 | FbTk::Button(parent, 0, 0, 10, 10), |
33 | m_font(&font), | 33 | m_font(&font), |
34 | m_text(text), | 34 | m_text(text), |
@@ -81,8 +81,8 @@ bool TextButton::setOrientation(FbTk::Orientation orient) { | |||
81 | return true; | 81 | return true; |
82 | } | 82 | } |
83 | 83 | ||
84 | void TextButton::setText(const std::string &text) { | 84 | void TextButton::setText(const FbTk::BiDiString &text) { |
85 | if (m_text != text) { | 85 | if (m_text.logical() != text.logical()) { |
86 | m_text = text; | 86 | m_text = text; |
87 | updateBackground(false); | 87 | updateBackground(false); |
88 | clear(); | 88 | clear(); |
@@ -126,7 +126,7 @@ void TextButton::clearArea(int x, int y, | |||
126 | 126 | ||
127 | 127 | ||
128 | unsigned int TextButton::textWidth() const { | 128 | unsigned int TextButton::textWidth() const { |
129 | return font().textWidth(text(), text().size()); | 129 | return font().textWidth(text()); |
130 | } | 130 | } |
131 | 131 | ||
132 | void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) { | 132 | void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) { |
@@ -135,15 +135,15 @@ void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) { | |||
135 | } | 135 | } |
136 | 136 | ||
137 | void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) { | 137 | void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) { |
138 | unsigned int textlen = text().size(); | 138 | const FbString& visual = text().visual(); |
139 | // do text alignment | 139 | unsigned int textlen = visual.size(); |
140 | 140 | unsigned int textw = width(); | |
141 | unsigned int textw = width(), texth = height(); | 141 | unsigned int texth = height(); |
142 | translateSize(m_orientation, textw, texth); | 142 | translateSize(m_orientation, textw, texth); |
143 | 143 | ||
144 | int align_x = FbTk::doAlignment(textw - x_offset - m_left_padding - m_right_padding, | 144 | int align_x = FbTk::doAlignment(textw - x_offset - m_left_padding - m_right_padding, |
145 | bevel(), justify(), font(), | 145 | bevel(), justify(), font(), |
146 | text().data(), text().size(), | 146 | visual.data(), visual.size(), |
147 | textlen); // return new text len | 147 | textlen); // return new text len |
148 | 148 | ||
149 | // center text by default | 149 | // center text by default |
@@ -161,25 +161,24 @@ void TextButton::drawText(int x_offset, int y_offset, FbDrawable *drawable) { | |||
161 | font().drawText(*drawable, | 161 | font().drawText(*drawable, |
162 | screenNumber(), | 162 | screenNumber(), |
163 | gc(), // graphic context | 163 | gc(), // graphic context |
164 | text(), textlen, // string and string size | 164 | visual.c_str(), textlen, // string and string size |
165 | textx, texty, m_orientation); // position | 165 | textx, texty, m_orientation); // position |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | bool TextButton::textExceeds(int x_offset) { | 169 | bool TextButton::textExceeds(int x_offset) { |
170 | |||
171 | unsigned int textlen = text().size(); | ||
172 | // do text alignment | ||
173 | 170 | ||
174 | unsigned int textw = width(), texth = height(); | 171 | const FbString& visual = text().visual(); |
172 | unsigned int textlen = visual.size(); | ||
173 | unsigned int textw = width(); | ||
174 | unsigned int texth = height(); | ||
175 | translateSize(m_orientation, textw, texth); | 175 | translateSize(m_orientation, textw, texth); |
176 | 176 | ||
177 | FbTk::doAlignment(textw - x_offset - m_left_padding - m_right_padding, | 177 | FbTk::doAlignment(textw - x_offset - m_left_padding - m_right_padding, |
178 | bevel(), justify(), font(), text().data(), text().size(), | 178 | bevel(), justify(), font(), visual.data(), visual.size(), |
179 | textlen); // return new text len | 179 | textlen); // return new text len |
180 | 180 | ||
181 | return text().size()>textlen; | 181 | return visual.size()>textlen; |
182 | |||
183 | } | 182 | } |
184 | 183 | ||
185 | void TextButton::exposeEvent(XExposeEvent &event) { | 184 | void TextButton::exposeEvent(XExposeEvent &event) { |