aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-09-10 21:36:37 (GMT)
committerfluxgen <fluxgen>2003-09-10 21:36:37 (GMT)
commit8c9818a84bb6d0da24e1f91bc227ebea655bfdb1 (patch)
tree054fecb1cbe37ee723ea464e20936a1b318cb007 /src/FbTk
parent69583dc2666906234707aef041629c7724f84371 (diff)
downloadfluxbox_paul-8c9818a84bb6d0da24e1f91bc227ebea655bfdb1.zip
fluxbox_paul-8c9818a84bb6d0da24e1f91bc227ebea655bfdb1.tar.bz2
reduced flicker with buffer
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/TextButton.cc73
-rw-r--r--src/FbTk/TextButton.hh15
2 files changed, 75 insertions, 13 deletions
diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc
index 9518627..a9a867f 100644
--- a/src/FbTk/TextButton.cc
+++ b/src/FbTk/TextButton.cc
@@ -19,13 +19,11 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: TextButton.cc,v 1.1 2003/08/18 12:15:39 fluxgen Exp $ 22// $Id: TextButton.cc,v 1.2 2003/09/10 21:36:37 fluxgen Exp $
23 23
24#include "TextButton.hh" 24#include "TextButton.hh"
25#include "Font.hh" 25#include "Font.hh"
26 26#include "GContext.hh"
27#include <iostream>
28using namespace std;
29 27
30namespace FbTk { 28namespace FbTk {
31 29
@@ -35,10 +33,28 @@ TextButton::TextButton(const FbTk::FbWindow &parent,
35 FbTk::Button(parent, 0, 0, 10, 10), 33 FbTk::Button(parent, 0, 0, 10, 10),
36 m_font(&font), 34 m_font(&font),
37 m_text(text), 35 m_text(text),
38 m_justify(FbTk::LEFT), m_bevel(1) { 36 m_justify(FbTk::LEFT), m_bevel(1),
37 m_buffer(drawable(), width(), height(), depth()) {
39 38
40} 39}
41 40
41void TextButton::resize(unsigned int width, unsigned int height) {
42 m_buffer.resize(width, height);
43
44 if (backgroundPixmap() != ParentRelative)
45 FbWindow::setBackgroundPixmap(m_buffer.drawable());
46 Button::resize(width, height);
47}
48
49void TextButton::moveResize(int x, int y,
50 unsigned int width, unsigned int height) {
51 m_buffer.resize(width, height);
52
53 if (backgroundPixmap() != ParentRelative)
54 FbWindow::setBackgroundPixmap(m_buffer.drawable());
55 Button::moveResize(x, y, width, height);
56}
57
42void TextButton::setJustify(FbTk::Justify just) { 58void TextButton::setJustify(FbTk::Justify just) {
43 m_justify = just; 59 m_justify = just;
44} 60}
@@ -52,7 +68,6 @@ void TextButton::setFont(const FbTk::Font &font) {
52 if (&font == m_font) 68 if (&font == m_font)
53 return; 69 return;
54 m_font = &font; 70 m_font = &font;
55 clear(); // redraw text with new font
56} 71}
57 72
58/// set bevel and redraw text 73/// set bevel and redraw text
@@ -64,8 +79,45 @@ void TextButton::setBevel(int bevel) {
64 79
65/// clear window and redraw text 80/// clear window and redraw text
66void TextButton::clear() { 81void TextButton::clear() {
67 FbTk::Button::clear(); 82 TextButton::clearArea(0, 0,
68 drawText(); 83 width(), height());
84}
85
86void TextButton::clearArea(int x, int y,
87 unsigned int width, unsigned int height,
88 bool exposure) {
89
90 if (backgroundPixmap() != ParentRelative) {
91
92 if (backgroundPixmap()) {
93 m_buffer.copyArea(backgroundPixmap(),
94 gc(),
95 x, y,
96 x, y,
97 width, height);
98
99 } else { // fill with background color
100 FbTk::GContext gc(drawable());
101 gc.setForeground(backgroundColor());
102 m_buffer.fillRectangle(gc.gc(),
103 x, y,
104 width, height);
105 }
106
107 drawText();
108
109 FbWindow::setBackgroundPixmap(m_buffer.drawable());
110
111 Button::clearArea(x, y, width, height, exposure);
112
113 } else { // parent relative
114 FbWindow::setBackgroundPixmap(backgroundPixmap());
115 Button::clearArea(x, y, width, height, exposure);
116 drawText();
117 }
118
119
120
69} 121}
70 122
71unsigned int TextButton::textWidth() const { 123unsigned int TextButton::textWidth() const {
@@ -80,13 +132,12 @@ void TextButton::drawText(int x_offset, int y_offset) {
80 justify(), 132 justify(),
81 font(), 133 font(),
82 text().c_str(), text().size(), 134 text().c_str(), text().size(),
83 textlen // return new text len 135 textlen); // return new text len
84 );
85 136
86 // center text by default 137 // center text by default
87 int center_pos = height()/2 + font().ascent()/2; 138 int center_pos = height()/2 + font().ascent()/2;
88 139
89 font().drawText(window(), // drawable 140 font().drawText(backgroundPixmap() == ParentRelative ? window() : m_buffer.drawable(),
90 screenNumber(), 141 screenNumber(),
91 gc(), // graphic context 142 gc(), // graphic context
92 text().c_str(), textlen, // string and string size 143 text().c_str(), textlen, // string and string size
diff --git a/src/FbTk/TextButton.hh b/src/FbTk/TextButton.hh
index fa1149d..5d87804 100644
--- a/src/FbTk/TextButton.hh
+++ b/src/FbTk/TextButton.hh
@@ -19,13 +19,14 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: TextButton.hh,v 1.1 2003/08/18 12:15:38 fluxgen Exp $ 22// $Id: TextButton.hh,v 1.2 2003/09/10 21:36:37 fluxgen Exp $
23 23
24#ifndef FBTK_TEXTBUTTON_HH 24#ifndef FBTK_TEXTBUTTON_HH
25#define FBTK_TEXTBUTTON_HH 25#define FBTK_TEXTBUTTON_HH
26 26
27#include "Button.hh" 27#include "Button.hh"
28#include "Text.hh" 28#include "Text.hh"
29#include "FbPixmap.hh"
29 30
30#include <string> 31#include <string>
31 32
@@ -43,8 +44,17 @@ public:
43 void setText(const std::string &text); 44 void setText(const std::string &text);
44 void setFont(const FbTk::Font &font); 45 void setFont(const FbTk::Font &font);
45 void setBevel(int bevel); 46 void setBevel(int bevel);
47
48 void resize(unsigned int width, unsigned int height);
49 void moveResize(int x, int y,
50 unsigned int width, unsigned int height);
51
46 /// clears window and redraw text 52 /// clears window and redraw text
47 void clear(); 53 void clear();
54 /// clears area and redraws text
55 void clearArea(int x, int y,
56 unsigned int width, unsigned int height,
57 bool exposure = false);
48 58
49 inline FbTk::Justify justify() const { return m_justify; } 59 inline FbTk::Justify justify() const { return m_justify; }
50 inline const std::string &text() const { return m_text; } 60 inline const std::string &text() const { return m_text; }
@@ -53,9 +63,10 @@ public:
53 int bevel() const { return m_bevel; } 63 int bevel() const { return m_bevel; }
54 64
55protected: 65protected:
56 void drawText(int x_offset = 0, int y_offset = 0); 66 virtual void drawText(int x_offset = 0, int y_offset = 0);
57 67
58private: 68private:
69 FbTk::FbPixmap m_buffer; ///< for background buffer
59 const FbTk::Font *m_font; 70 const FbTk::Font *m_font;
60 std::string m_text; 71 std::string m_text;
61 FbTk::Justify m_justify; 72 FbTk::Justify m_justify;