Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/otk/button.cc

Go to the documentation of this file.
00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 # include "../config.h"
00005 #endif
00006 
00007 #include "button.hh"
00008 
00009 namespace otk {
00010 
00011 Button::Button(Widget *parent)
00012   : FocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
00013     _pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
00014 {
00015   setStyle(_style);
00016 }
00017 
00018 Button::~Button()
00019 {
00020 }
00021 
00022 
00023 void Button::setStyle(RenderStyle *style)
00024 {
00025   FocusLabel::setStyle(style);
00026 
00027   setTexture(style->buttonUnpressFocusBackground());
00028   setUnfocusTexture(style->buttonUnpressUnfocusBackground());
00029   _pressed_focus_tx = style->buttonPressFocusBackground();
00030   _pressed_unfocus_tx = style->buttonPressUnfocusBackground();
00031 }
00032 
00033 
00034 void Button::press(unsigned int mouse_button)
00035 {
00036   if (_pressed) return;
00037 
00038   if (_pressed_focus_tx)
00039     FocusWidget::setTexture(_pressed_focus_tx);
00040   if (_pressed_unfocus_tx)
00041     FocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
00042   _pressed = true;
00043   _mouse_button = mouse_button;
00044 }
00045 
00046 void Button::release(unsigned int mouse_button)
00047 {
00048   if (_mouse_button != mouse_button) return; // wrong button
00049 
00050   FocusWidget::setTexture(_unpr_focus_tx);
00051   FocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
00052   _pressed = false;
00053 }
00054 
00055 void Button::setTexture(RenderTexture *texture)
00056 {
00057   FocusWidget::setTexture(texture);
00058   _unpr_focus_tx = texture;
00059 }
00060 
00061 void Button::setUnfocusTexture(RenderTexture *texture)
00062 {
00063   FocusWidget::setUnfocusTexture(texture);
00064   _unpr_unfocus_tx = texture;
00065 }
00066 
00067 void Button::buttonPressHandler(const XButtonEvent &e)
00068 {
00069   press(e.button);
00070   update();
00071   FocusWidget::buttonPressHandler(e);
00072 }
00073 
00074 void Button::buttonReleaseHandler(const XButtonEvent &e)
00075 {
00076   release(e.button);
00077   update();
00078   FocusWidget::buttonReleaseHandler(e);
00079 }
00080 
00081 }

Generated on Tue Feb 4 22:58:55 2003 for Openbox by doxygen1.3-rc2