using number for buttons and max five buttons
This commit is contained in:
parent
2202914053
commit
885ddd9322
2 changed files with 18 additions and 29 deletions
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: Button.cc,v 1.2 2002/12/16 11:05:35 fluxgen Exp $
|
||||
// $Id: Button.cc,v 1.3 2002/12/25 11:27:29 fluxgen Exp $
|
||||
|
||||
#include "Button.hh"
|
||||
|
||||
|
@ -56,6 +56,14 @@ Button::~Button() {
|
|||
FbTk::EventManager::instance()->remove(m_win);
|
||||
}
|
||||
|
||||
void Button::setOnClick(RefCount<Command> &cmd, int button) {
|
||||
// we only handle buttons 1 to 5
|
||||
if (button > 5 || button == 0)
|
||||
return;
|
||||
//set on click command for the button
|
||||
m_onclick[button - 1] = cmd;
|
||||
}
|
||||
|
||||
void Button::move(int x, int y) {
|
||||
m_win.move(x, y);
|
||||
}
|
||||
|
@ -124,22 +132,8 @@ void Button::buttonReleaseEvent(XButtonEvent &event) {
|
|||
event.x > width() || event.y > height())
|
||||
return;
|
||||
|
||||
// call commands
|
||||
switch (event.button) {
|
||||
case Button1:
|
||||
if (*m_onclick_left != 0)
|
||||
m_onclick_left->execute();
|
||||
break;
|
||||
case Button2:
|
||||
if (*m_onclick_middle != 0)
|
||||
m_onclick_middle->execute();
|
||||
break;
|
||||
case Button3:
|
||||
if (*m_onclick_right != 0)
|
||||
m_onclick_right->execute();
|
||||
break;
|
||||
};
|
||||
|
||||
if (event.button > 0 && event.button <= 5)
|
||||
m_onclick[event.button - 1]->execute();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: Button.hh,v 1.2 2002/12/16 11:02:41 fluxgen Exp $
|
||||
// $Id: Button.hh,v 1.3 2002/12/25 11:28:43 fluxgen Exp $
|
||||
|
||||
#ifndef FBTK_BUTTON_HH
|
||||
#define FBTK_BUTTON_HH
|
||||
|
@ -42,12 +42,9 @@ public:
|
|||
Button(int screen_num, int x, int y, unsigned int width, unsigned int height);
|
||||
Button(const FbWindow &parent, int x, int y, unsigned int width, unsigned int height);
|
||||
virtual ~Button();
|
||||
/// sets action when the button is clicked with left mouse btn
|
||||
void setOnClick(RefCount<Command> &com) { m_onclick_left = com; }
|
||||
/// sets action when the button is clicked with middle mouse btn
|
||||
void setOnClickMiddle(RefCount<Command> &com) { m_onclick_middle = com; }
|
||||
/// sets action when the button is clicked with right mouse btn
|
||||
void setOnClickRight(RefCount<Command> &com) { m_onclick_right = com; }
|
||||
|
||||
/// sets action when the button is clicked with #button mouse btn
|
||||
void setOnClick(RefCount<Command> &com, int button = 1);
|
||||
|
||||
void move(int x, int y);
|
||||
void resize(unsigned int width, unsigned int height);
|
||||
|
@ -100,9 +97,7 @@ private:
|
|||
Pixmap m_pressed_pm; ///< pressed pixmap
|
||||
GC m_gc; ///< graphic context for button
|
||||
bool m_pressed; ///< if the button is pressed
|
||||
RefCount<Command> m_onclick_left; ///< what to do when this button is clicked with lmb
|
||||
RefCount<Command> m_onclick_middle; ///< what to do when this button is clicked with mmb
|
||||
RefCount<Command> m_onclick_right; ///< what to do when this button is clicked with rmb
|
||||
RefCount<Command> m_onclick[5]; ///< what to do when this button is clicked with button num
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue