summaryrefslogtreecommitdiff
path: root/plugingui/button.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-01-23 20:08:12 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2012-01-23 20:08:12 +0100
commitaf9c9091ed69394171485aa4c4814504f86f2004 (patch)
tree070b911dc8faed486c8e8829f0f41aec7d5b4350 /plugingui/button.cc
parent5e4cb10f72ef69d73fbd2c1bc42465c9111a4c41 (diff)
Simple image blit. New slider class. New filenamelineedit. New pixelbuffer used for drawing everything but the root window - with alpha blending...
Diffstat (limited to 'plugingui/button.cc')
-rw-r--r--plugingui/button.cc69
1 files changed, 47 insertions, 22 deletions
diff --git a/plugingui/button.cc b/plugingui/button.cc
index a833ad3..0e42e27 100644
--- a/plugingui/button.cc
+++ b/plugingui/button.cc
@@ -30,53 +30,78 @@
#include <stdio.h>
-Button::Button(GlobalContext *gctx, Widget *parent)
- : Widget(gctx, parent)
+GUI::Button::Button(Widget *parent)
+ : GUI::Widget(parent)
{
state = up;
+ handler = NULL;
+ ptr = NULL;
}
-void Button::button(ButtonEvent *e)
+void GUI::Button::registerClickHandler(void (*handler)(void *), void *ptr)
+{
+ this->handler = handler;
+ this->ptr = ptr;
+}
+
+void GUI::Button::buttonEvent(ButtonEvent *e)
{
if(e->direction == 1) {
state = down;
- repaint(NULL);
+ repaintEvent(NULL);
}
if(e->direction == -1) {
state = up;
- repaint(NULL);
+ repaintEvent(NULL);
clicked();
+ if(handler) handler(ptr);
}
}
-void Button::repaint(RepaintEvent *e)
+void GUI::Button::repaintEvent(GUI::RepaintEvent *e)
{
- Painter p(gctx, wctx);
-
- p.setColour(Colour(0.5));
- p.drawFilledRectangle(1,1,width()-1,height()-1);
+ // printf("Button::repaintEvent\n");
- p.setColour(Colour(0.1));
- p.drawRectangle(0,0,width()-1,height()-1);
+ Painter p(this);
+
+ float alpha = 0.8;
- p.setColour(Colour(0.8));
- if(state == up) {
- p.drawLine(1,1,1,height());
- p.drawLine(1,1,width(),1);
+ if(hasKeyboardFocus()) {
+ p.setColour(Colour(0.6, alpha));
+ } else {
+ p.setColour(Colour(0.5, alpha));
}
- if(state == down) {
- p.drawLine(width()-2,0, width()-2,height()-2);
- p.drawLine(width()-2,height()-2,0, height()-2);
+ p.drawFilledRectangle(0,0,width()-1,height()-1);
+
+ p.setColour(Colour(0.1, alpha));
+ p.drawRectangle(0,0,width()-1,height()-1);
+
+ p.setColour(Colour(0.8, alpha));
+ switch(state) {
+ case up:
+ p.drawLine(0,0,0,height()-1);
+ p.drawLine(0,0,width()-1,0);
+ break;
+ case down:
+ p.drawLine(width()-1,0, width()-1,height()-1);
+ p.drawLine(width()-1,height()-1,0, height()-1);
+ break;
}
- p.setColour(Colour(0.9));
+ p.setColour(Colour(0.3, alpha));
+ p.drawPoint(0,height()-1);
+ p.drawPoint(width()-1,0);
+
+ Font font;
+ p.setColour(Colour(0.9, alpha));
p.drawText(width()/2-(text.length()*3)+(state==up?0:1),
- height()/2+4+(state==up?0:1), text);
+ height()/2+4+(state==up?0:1), font, text);
}
-void Button::setText(std::string text)
+void GUI::Button::setText(std::string text)
{
this->text = text;
+ repaintEvent(NULL);
}
#ifdef TEST_BUTTON