From 8c9818a84bb6d0da24e1f91bc227ebea655bfdb1 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Wed, 10 Sep 2003 21:36:37 +0000 Subject: reduced flicker with buffer --- src/FbTk/TextButton.cc | 73 ++++++++++++++++++++++++++++++++++++++++++-------- src/FbTk/TextButton.hh | 15 +++++++++-- 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: TextButton.cc,v 1.1 2003/08/18 12:15:39 fluxgen Exp $ +// $Id: TextButton.cc,v 1.2 2003/09/10 21:36:37 fluxgen Exp $ #include "TextButton.hh" #include "Font.hh" - -#include -using namespace std; +#include "GContext.hh" namespace FbTk { @@ -35,10 +33,28 @@ TextButton::TextButton(const FbTk::FbWindow &parent, FbTk::Button(parent, 0, 0, 10, 10), m_font(&font), m_text(text), - m_justify(FbTk::LEFT), m_bevel(1) { + m_justify(FbTk::LEFT), m_bevel(1), + m_buffer(drawable(), width(), height(), depth()) { } +void TextButton::resize(unsigned int width, unsigned int height) { + m_buffer.resize(width, height); + + if (backgroundPixmap() != ParentRelative) + FbWindow::setBackgroundPixmap(m_buffer.drawable()); + Button::resize(width, height); +} + +void TextButton::moveResize(int x, int y, + unsigned int width, unsigned int height) { + m_buffer.resize(width, height); + + if (backgroundPixmap() != ParentRelative) + FbWindow::setBackgroundPixmap(m_buffer.drawable()); + Button::moveResize(x, y, width, height); +} + void TextButton::setJustify(FbTk::Justify just) { m_justify = just; } @@ -52,7 +68,6 @@ void TextButton::setFont(const FbTk::Font &font) { if (&font == m_font) return; m_font = &font; - clear(); // redraw text with new font } /// set bevel and redraw text @@ -64,8 +79,45 @@ void TextButton::setBevel(int bevel) { /// clear window and redraw text void TextButton::clear() { - FbTk::Button::clear(); - drawText(); + TextButton::clearArea(0, 0, + width(), height()); +} + +void TextButton::clearArea(int x, int y, + unsigned int width, unsigned int height, + bool exposure) { + + if (backgroundPixmap() != ParentRelative) { + + if (backgroundPixmap()) { + m_buffer.copyArea(backgroundPixmap(), + gc(), + x, y, + x, y, + width, height); + + } else { // fill with background color + FbTk::GContext gc(drawable()); + gc.setForeground(backgroundColor()); + m_buffer.fillRectangle(gc.gc(), + x, y, + width, height); + } + + drawText(); + + FbWindow::setBackgroundPixmap(m_buffer.drawable()); + + Button::clearArea(x, y, width, height, exposure); + + } else { // parent relative + FbWindow::setBackgroundPixmap(backgroundPixmap()); + Button::clearArea(x, y, width, height, exposure); + drawText(); + } + + + } unsigned int TextButton::textWidth() const { @@ -80,13 +132,12 @@ void TextButton::drawText(int x_offset, int y_offset) { justify(), font(), text().c_str(), text().size(), - textlen // return new text len - ); + textlen); // return new text len // center text by default int center_pos = height()/2 + font().ascent()/2; - font().drawText(window(), // drawable + font().drawText(backgroundPixmap() == ParentRelative ? window() : m_buffer.drawable(), screenNumber(), gc(), // graphic context 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: TextButton.hh,v 1.1 2003/08/18 12:15:38 fluxgen Exp $ +// $Id: TextButton.hh,v 1.2 2003/09/10 21:36:37 fluxgen Exp $ #ifndef FBTK_TEXTBUTTON_HH #define FBTK_TEXTBUTTON_HH #include "Button.hh" #include "Text.hh" +#include "FbPixmap.hh" #include @@ -43,8 +44,17 @@ public: void setText(const std::string &text); void setFont(const FbTk::Font &font); void setBevel(int bevel); + + void resize(unsigned int width, unsigned int height); + void moveResize(int x, int y, + unsigned int width, unsigned int height); + /// clears window and redraw text void clear(); + /// clears area and redraws text + void clearArea(int x, int y, + unsigned int width, unsigned int height, + bool exposure = false); inline FbTk::Justify justify() const { return m_justify; } inline const std::string &text() const { return m_text; } @@ -53,9 +63,10 @@ public: int bevel() const { return m_bevel; } protected: - void drawText(int x_offset = 0, int y_offset = 0); + virtual void drawText(int x_offset = 0, int y_offset = 0); private: + FbTk::FbPixmap m_buffer; ///< for background buffer const FbTk::Font *m_font; std::string m_text; FbTk::Justify m_justify; -- cgit v0.11.2