new button that is a focuslabel
This commit is contained in:
parent
3ce8b540aa
commit
d4d15160fe
3 changed files with 18 additions and 60 deletions
|
@ -1,12 +1,10 @@
|
||||||
#include <iostream>
|
|
||||||
#include "button.hh"
|
#include "button.hh"
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
OtkButton::OtkButton(OtkWidget *parent)
|
OtkButton::OtkButton(OtkWidget *parent)
|
||||||
: OtkFocusWidget(parent), _text(""), _pressed(false), _dirty(false),
|
: OtkFocusLabel(parent), _pressed(false), _pressed_focus_tx(0),
|
||||||
_pressed_focus_tx(0), _pressed_unfocus_tx(0), _unpr_focus_tx(0),
|
_pressed_unfocus_tx(0), _unpr_focus_tx(0), _unpr_unfocus_tx(0)
|
||||||
_unpr_unfocus_tx(0)
|
|
||||||
{
|
{
|
||||||
setTexture(getStyle()->getButtonFocus());
|
setTexture(getStyle()->getButtonFocus());
|
||||||
setUnfocusTexture(getStyle()->getButtonUnfocus());
|
setUnfocusTexture(getStyle()->getButtonUnfocus());
|
||||||
|
@ -20,17 +18,22 @@ OtkButton::~OtkButton()
|
||||||
if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
|
if (_pressed_unfocus_tx) delete _pressed_unfocus_tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtkButton::press(void)
|
void OtkButton::press(unsigned int mouse_button)
|
||||||
{
|
{
|
||||||
|
if (_pressed) return;
|
||||||
|
|
||||||
if (_pressed_focus_tx)
|
if (_pressed_focus_tx)
|
||||||
OtkFocusWidget::setTexture(_pressed_focus_tx);
|
OtkFocusWidget::setTexture(_pressed_focus_tx);
|
||||||
if (_pressed_unfocus_tx)
|
if (_pressed_unfocus_tx)
|
||||||
OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
|
OtkFocusWidget::setUnfocusTexture(_pressed_unfocus_tx);
|
||||||
_pressed = true;
|
_pressed = true;
|
||||||
|
_mouse_button = mouse_button;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtkButton::release(void)
|
void OtkButton::release(unsigned int mouse_button)
|
||||||
{
|
{
|
||||||
|
if (_mouse_button != mouse_button) return; // wrong button
|
||||||
|
|
||||||
OtkFocusWidget::setTexture(_unpr_focus_tx);
|
OtkFocusWidget::setTexture(_unpr_focus_tx);
|
||||||
OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
|
OtkFocusWidget::setUnfocusTexture(_unpr_unfocus_tx);
|
||||||
_pressed = false;
|
_pressed = false;
|
||||||
|
@ -48,52 +51,18 @@ void OtkButton::setUnfocusTexture(BTexture *texture)
|
||||||
_unpr_unfocus_tx = texture;
|
_unpr_unfocus_tx = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtkButton::update(void)
|
|
||||||
{
|
|
||||||
if (_dirty) {
|
|
||||||
const BFont ft = getStyle()->getFont();
|
|
||||||
BColor *text_color = (isFocused() ? getStyle()->getTextFocus()
|
|
||||||
: getStyle()->getTextUnfocus());
|
|
||||||
unsigned int bevel = getStyle()->getBevelWidth();
|
|
||||||
|
|
||||||
OtkFocusWidget::resize(ft.measureString(_text) + bevel * 2,
|
|
||||||
ft.height() + bevel * 2);
|
|
||||||
OtkFocusWidget::update();
|
|
||||||
|
|
||||||
ft.drawString(getWindow(), bevel, bevel, *text_color, _text);
|
|
||||||
} else
|
|
||||||
OtkFocusWidget::update();
|
|
||||||
|
|
||||||
_dirty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int OtkButton::buttonPressHandler(const XButtonEvent &e)
|
int OtkButton::buttonPressHandler(const XButtonEvent &e)
|
||||||
{
|
{
|
||||||
press();
|
press(e.button);
|
||||||
_dirty = true;
|
|
||||||
update();
|
update();
|
||||||
return OtkFocusWidget::buttonPressHandler(e);
|
return OtkFocusWidget::buttonPressHandler(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int OtkButton::buttonReleaseHandler(const XButtonEvent &e)
|
int OtkButton::buttonReleaseHandler(const XButtonEvent &e)
|
||||||
{
|
{
|
||||||
release();
|
release(e.button);
|
||||||
_dirty = true;
|
|
||||||
update();
|
update();
|
||||||
return OtkFocusWidget::buttonReleaseHandler(e);
|
return OtkFocusWidget::buttonReleaseHandler(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
int OtkButton::exposeHandler(const XExposeEvent &e)
|
|
||||||
{
|
|
||||||
_dirty = true;
|
|
||||||
return OtkFocusWidget::exposeHandler(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
int OtkButton::configureHandler(const XConfigureEvent &e)
|
|
||||||
{
|
|
||||||
if (!(e.width == width() && e.height == height()))
|
|
||||||
_dirty = true;
|
|
||||||
return OtkFocusWidget::configureHandler(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#ifndef __button_hh
|
#ifndef __button_hh
|
||||||
#define __button_hh
|
#define __button_hh
|
||||||
|
|
||||||
#include "focuswidget.hh"
|
#include "focuslabel.hh"
|
||||||
//#include "pixmap.hh"
|
|
||||||
|
|
||||||
namespace otk {
|
namespace otk {
|
||||||
|
|
||||||
class OtkButton : public OtkFocusWidget {
|
class OtkButton : public OtkFocusLabel {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -26,28 +25,17 @@ public:
|
||||||
void setTexture(BTexture *texture);
|
void setTexture(BTexture *texture);
|
||||||
void setUnfocusTexture(BTexture *texture);
|
void setUnfocusTexture(BTexture *texture);
|
||||||
|
|
||||||
inline const std::string &getText(void) const { return _text; }
|
|
||||||
void setText(const std::string &text) { _text = text; _dirty = true; }
|
|
||||||
|
|
||||||
//inline const OtkPixmap &getPixmap(void) const { return _pixmap; }
|
|
||||||
//void setPixmap(const OtkPixmap &pixmap);
|
|
||||||
|
|
||||||
inline bool isPressed(void) const { return _pressed; }
|
inline bool isPressed(void) const { return _pressed; }
|
||||||
void press(void);
|
void press(unsigned int mouse_button);
|
||||||
void release(void);
|
void release(unsigned int mouse_button);
|
||||||
|
|
||||||
void update(void);
|
|
||||||
int exposeHandler(const XExposeEvent &e);
|
|
||||||
int configureHandler(const XConfigureEvent &e);
|
|
||||||
int buttonPressHandler(const XButtonEvent &e);
|
int buttonPressHandler(const XButtonEvent &e);
|
||||||
int buttonReleaseHandler(const XButtonEvent &e);
|
int buttonReleaseHandler(const XButtonEvent &e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string _text;
|
|
||||||
//OtkPixmap _pixmap;
|
|
||||||
bool _pressed;
|
bool _pressed;
|
||||||
bool _dirty;
|
unsigned int _mouse_button;
|
||||||
|
|
||||||
BTexture *_pressed_focus_tx;
|
BTexture *_pressed_focus_tx;
|
||||||
BTexture *_pressed_unfocus_tx;
|
BTexture *_pressed_unfocus_tx;
|
||||||
|
|
|
@ -31,13 +31,14 @@ int main(int argc, char **argv) {
|
||||||
right.setUnfocusTexture(app.getStyle()->getTitleUnfocus());
|
right.setUnfocusTexture(app.getStyle()->getTitleUnfocus());
|
||||||
|
|
||||||
otk::OtkButton iconb(&left);
|
otk::OtkButton iconb(&left);
|
||||||
|
iconb.resize(40,20);
|
||||||
otk::OtkFocusWidget label(&left);
|
otk::OtkFocusWidget label(&left);
|
||||||
otk::OtkButton maxb(&left);
|
otk::OtkButton maxb(&left);
|
||||||
otk::OtkButton closeb(&left);
|
otk::OtkButton closeb(&left);
|
||||||
|
|
||||||
// fixed size
|
// fixed size
|
||||||
iconb.setText("foo");
|
iconb.setText("foo");
|
||||||
iconb.press();
|
iconb.press(Button1);
|
||||||
|
|
||||||
// fix width to 60 and let the height be calculated by its parent
|
// fix width to 60 and let the height be calculated by its parent
|
||||||
//label.setHeight(20);
|
//label.setHeight(20);
|
||||||
|
|
Loading…
Reference in a new issue