diff options
-rw-r--r-- | plugingui/button.cc | 208 | ||||
-rw-r--r-- | plugingui/button.h | 55 | ||||
-rw-r--r-- | plugingui/filebrowser.cc | 14 | ||||
-rw-r--r-- | plugingui/filebrowser.h | 3 | ||||
-rw-r--r-- | plugingui/plugingui.cc | 75 |
5 files changed, 189 insertions, 166 deletions
diff --git a/plugingui/button.cc b/plugingui/button.cc index c316ef3..dea376c 100644 --- a/plugingui/button.cc +++ b/plugingui/button.cc @@ -31,127 +31,131 @@ #include <stdio.h> #include <hugin.hpp> -GUI::Button::Button(Widget *parent) - : GUI::Widget(parent) -{ - box_up.topLeft = new Image(":pushbutton_tl.png"); - box_up.top = new Image(":pushbutton_t.png"); - box_up.topRight = new Image(":pushbutton_tr.png"); - box_up.left = new Image(":pushbutton_l.png"); - box_up.right = new Image(":pushbutton_r.png"); - box_up.bottomLeft = new Image(":pushbutton_bl.png"); - box_up.bottom = new Image(":pushbutton_b.png"); - box_up.bottomRight = new Image(":pushbutton_br.png"); - box_up.center = new Image(":pushbutton_c.png"); - - box_down.topLeft = new Image(":pushbuttondown_tl.png"); - box_down.top = new Image(":pushbuttondown_t.png"); - box_down.topRight = new Image(":pushbuttondown_tr.png"); - box_down.left = new Image(":pushbuttondown_l.png"); - box_down.right = new Image(":pushbuttondown_r.png"); - box_down.bottomLeft = new Image(":pushbuttondown_bl.png"); - box_down.bottom = new Image(":pushbuttondown_b.png"); - box_down.bottomRight = new Image(":pushbuttondown_br.png"); - box_down.center = new Image(":pushbuttondown_c.png"); - - draw_state = up; - button_state = up; - - handler = NULL; - ptr = NULL; -} +namespace GUI { -void GUI::Button::registerClickHandler(void (*handler)(void *), void *ptr) +Button::Button(Widget *parent) + : Widget(parent) + , draw_state(up) + , button_state(up) { - this->handler = handler; - this->ptr = ptr; + box_up.topLeft = new Image(":pushbutton_tl.png"); + box_up.top = new Image(":pushbutton_t.png"); + box_up.topRight = new Image(":pushbutton_tr.png"); + box_up.left = new Image(":pushbutton_l.png"); + box_up.right = new Image(":pushbutton_r.png"); + box_up.bottomLeft = new Image(":pushbutton_bl.png"); + box_up.bottom = new Image(":pushbutton_b.png"); + box_up.bottomRight = new Image(":pushbutton_br.png"); + box_up.center = new Image(":pushbutton_c.png"); + + box_down.topLeft = new Image(":pushbuttondown_tl.png"); + box_down.top = new Image(":pushbuttondown_t.png"); + box_down.topRight = new Image(":pushbuttondown_tr.png"); + box_down.left = new Image(":pushbuttondown_l.png"); + box_down.right = new Image(":pushbuttondown_r.png"); + box_down.bottomLeft = new Image(":pushbuttondown_bl.png"); + box_down.bottom = new Image(":pushbuttondown_b.png"); + box_down.bottomRight = new Image(":pushbuttondown_br.png"); + box_down.center = new Image(":pushbuttondown_c.png"); } -void GUI::Button::buttonEvent(ButtonEvent *e) +Button::~Button() { - if(e->direction == 1) { - draw_state = down; - button_state = down; - in_button = true; - repaintEvent(NULL); - } - if(e->direction == -1) { - draw_state = up; - button_state = up; - repaintEvent(NULL); - if(in_button) { - clicked(); - if(handler) handler(ptr); - } - } + delete(box_up.topLeft); + delete(box_up.top); + delete(box_up.topRight); + delete(box_up.left); + delete(box_up.right); + delete(box_up.bottomLeft); + delete(box_up.bottom); + delete(box_up.bottomRight); + delete(box_up.center); + delete(box_down.topLeft); + delete(box_down.top); + delete(box_down.topRight); + delete(box_down.left); + delete(box_down.right); + delete(box_down.bottomLeft); + delete(box_down.bottom); + delete(box_down.bottomRight); + delete(box_down.center); } -void GUI::Button::repaintEvent(GUI::RepaintEvent *e) +void Button::buttonEvent(ButtonEvent *e) { - Painter p(this); - - p.clear(); - - int w = width(); - int h = height(); - if(w == 0 || h == 0) return; - - switch(draw_state) { - case up: - p.drawBox(0, 0, &box_up, w, h); - break; - case down: - p.drawBox(0, 0, &box_down, w, h); - break; - } - - Font font(":fontemboss.png"); - p.setColour(Colour(0.1)); - p.drawText(width()/2-(text.length()*3)+(draw_state==up?0:1), - height()/2+5+1+(draw_state==up?0:1), font, text, true); + if(e->direction == 1) + { + draw_state = down; + button_state = down; + in_button = true; + repaintEvent(nullptr); + } + + if(e->direction == -1) + { + draw_state = up; + button_state = up; + repaintEvent(nullptr); + if(in_button) + { + clicked(); + clickNotifier(); + } + } } -void GUI::Button::setText(std::string text) +void Button::repaintEvent(RepaintEvent *e) { - this->text = text; - repaintEvent(NULL); + Painter p(this); + + p.clear(); + + int w = width(); + int h = height(); + if(w == 0 || h == 0) + { + return; + } + + switch(draw_state) { + case up: + p.drawBox(0, 0, &box_up, w, h); + break; + case down: + p.drawBox(0, 0, &box_down, w, h); + break; + } + + Font font(":fontemboss.png"); + p.setColour(Colour(0.1)); + p.drawText(width()/2-(text.length()*3)+(draw_state==up?0:1), + height()/2+5+1+(draw_state==up?0:1), font, text, true); } -void GUI::Button::mouseLeaveEvent() +void Button::setText(std::string text) { - in_button = false; - if(button_state == down) { - draw_state = up; - repaintEvent(NULL); - } + this->text = text; + repaintEvent(nullptr); } -void GUI::Button::mouseEnterEvent() +void Button::mouseLeaveEvent() { - in_button = true; - if(button_state == down) { - draw_state = down; - repaintEvent(NULL); - } + in_button = false; + if(button_state == down) + { + draw_state = up; + repaintEvent(nullptr); + } } -void GUI::Button::mouseMoveEvent(MouseMoveEvent *e) +void Button::mouseEnterEvent() { + in_button = true; + if(button_state == down) + { + draw_state = down; + repaintEvent(nullptr); + } } -#ifdef TEST_BUTTON -//Additional dependency files -//deps: -//Required cflags (autoconf vars may be used) -//cflags: -//Required link options (autoconf vars may be used) -//libs: -#include "test.h" - -TEST_BEGIN; - -// TODO: Put some testcode here (see test.h for usable macros). - -TEST_END; - -#endif/*TEST_BUTTON*/ +} //GUI:: diff --git a/plugingui/button.h b/plugingui/button.h index 682dfa2..7302b87 100644 --- a/plugingui/button.h +++ b/plugingui/button.h @@ -24,57 +24,52 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __DRUMGIZMO_BUTTON_H__ -#define __DRUMGIZMO_BUTTON_H__ +#pragma once #include <string> #include "widget.h" #include "painter.h" +#include "notifier.h" namespace GUI { class Button : public Widget { public: - Button(Widget *parent); + Button(Widget *parent); + ~Button(); - bool isFocusable() { return true; } - bool catchMouse() { return true; } + bool isFocusable() { return true; } + bool catchMouse() { return true; } - void setText(std::string text); + void setText(std::string text); - void registerClickHandler(void (*handler)(void *), void *ptr); + Notifier<> clickNotifier; - //protected: - virtual void clicked() {} +protected: + virtual void clicked() {} - virtual void repaintEvent(RepaintEvent *e); - virtual void buttonEvent(ButtonEvent *e); + virtual void repaintEvent(RepaintEvent *e); + virtual void buttonEvent(ButtonEvent *e); - virtual void mouseLeaveEvent(); - virtual void mouseEnterEvent(); - virtual void mouseMoveEvent(MouseMoveEvent *e); + virtual void mouseLeaveEvent(); + virtual void mouseEnterEvent(); private: - bool in_button; + bool in_button; - Painter::Box box_up; - Painter::Box box_down; + Painter::Box box_up; + Painter::Box box_down; - typedef enum { - up, - down - } state_t; + typedef enum { + up, + down + } state_t; - std::string text; - - state_t draw_state; - state_t button_state; - - void (*handler)(void *); - void *ptr; -}; + std::string text; + state_t draw_state; + state_t button_state; }; -#endif/*__DRUMGIZMO_BUTTON_H__*/ +} // GUI:: diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index f025c25..b32b586 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -196,10 +196,10 @@ GUI::FileBrowser::FileBrowser(GUI::Widget *parent) listbox.registerSelectHandler(changeDir, prv); btn_sel.setText("Select"); - btn_sel.registerClickHandler(changeDir, prv); + CONNECT((&btn_sel), clickNotifier, this, &FileBrowser::selectButtonClicked); btn_esc.setText("Cancel"); - btn_esc.registerClickHandler(cancel, this); + CONNECT((&btn_esc), clickNotifier, this, &FileBrowser::cancelButtonClicked); changeDir(prv); @@ -266,3 +266,13 @@ void GUI::FileBrowser::repaintEvent(GUI::RepaintEvent *e) Painter p(this); p.drawImageStretched(0,0, &back, width(), height()); } + +void GUI::FileBrowser::selectButtonClicked() +{ + changeDir(prv); +} + +void GUI::FileBrowser::cancelButtonClicked() +{ + cancel(this); +} diff --git a/plugingui/filebrowser.h b/plugingui/filebrowser.h index 6583b53..9eb9f54 100644 --- a/plugingui/filebrowser.h +++ b/plugingui/filebrowser.h @@ -57,6 +57,9 @@ public: virtual void resize(int w, int h); private: + void selectButtonClicked(); + void cancelButtonClicked(); + struct private_data *prv; GUI::Label lbl_path; diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 49dce85..da18f71 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -61,19 +61,6 @@ static void selectKitFile(void *ptr, std::string filename) msghandler.sendMessage(MSGRCV_ENGINE, msg); } -static void kitBrowseClick(void *ptr) -{ - PluginGUI *gui = (PluginGUI*)ptr; - - std::string path = gui->lineedit->text(); - if(path == "") path = gui->config->lastkit; - if(path == "") path = gui->lineedit2->text(); - - fb->setPath(path); - fb->registerFileSelectHandler(selectKitFile, gui); - fb->show(); -} - static void selectMapFile(void *ptr, std::string filename) { PluginGUI *gui = (PluginGUI*)ptr; @@ -97,19 +84,6 @@ static void selectMapFile(void *ptr, std::string filename) */ } -static void midimapBrowseClick(void *ptr) -{ - PluginGUI *gui = (PluginGUI*)ptr; - - std::string path = gui->lineedit2->text(); - if(path == "") path = gui->config->lastmidimap; - if(path == "") path = gui->lineedit->text(); - - fb->setPath(path); - fb->registerFileSelectHandler(selectMapFile, gui); - fb->show(); -} - /* void closeClick(void *ptr) { @@ -295,7 +269,8 @@ void PluginGUI::init() btn_brw->setText("Browse..."); btn_brw->move(266, y - 6 + 4); btn_brw->resize(85, 35 + 6 - 4); - btn_brw->registerClickHandler(kitBrowseClick, this); +// btn_brw->registerClickHandler(kitBrowseClick, this); + CONNECT(btn_brw, clickNotifier, this, &PluginGUI::kitBrowseClick); y += OFFSET2; progress = new ProgressBar(window); @@ -326,7 +301,7 @@ void PluginGUI::init() btn_brw->setText("Browse..."); btn_brw->move(266, y - 6 + 4); btn_brw->resize(85, 35 + 6 - 4); - btn_brw->registerClickHandler(midimapBrowseClick, this); + CONNECT(btn_brw, clickNotifier, this, &PluginGUI::midimapBrowseClick); y += OFFSET2; progress2 = new ProgressBar(window); @@ -490,10 +465,46 @@ void PluginGUI::falloffValueChanged(float value) void PluginGUI::velocityCheckClick(bool checked) { - ChangeSettingMessage *msg = - new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, - checked); - msghandler.sendMessage(MSGRCV_ENGINE, msg); + ChangeSettingMessage *msg = + new ChangeSettingMessage(ChangeSettingMessage::enable_velocity_modifier, + checked); + msghandler.sendMessage(MSGRCV_ENGINE, msg); +} + +void PluginGUI::kitBrowseClick() +{ + std::string path = lineedit->text(); + if(path == "") + { + path = config->lastkit; + } + + if(path == "") + { + path = lineedit2->text(); + } + + fb->setPath(path); + fb->registerFileSelectHandler(selectKitFile, this); + fb->show(); +} + +void PluginGUI::midimapBrowseClick() +{ + std::string path = lineedit2->text(); + if(path == "") + { + path = config->lastmidimap; + } + + if(path == "") + { + path = lineedit->text(); + } + + fb->setPath(path); + fb->registerFileSelectHandler(selectMapFile, this); + fb->show(); } } // GUI:: |