cgv
Loading...
Searching...
No Matches
mouse_event.cxx
1#include <cgv/gui/mouse_event.h>
2#include <string>
3namespace cgv {
4 namespace gui {
5
6
7// construct a key event from its textual description
8mouse_event::mouse_event(int _x, int _y, MouseAction _action, unsigned char _button_state, unsigned char _button, short _dx, short _dy, unsigned char _modifiers, unsigned char _toggle_keys, double _time)
9 : event(EID_MOUSE,_modifiers,_toggle_keys,_time),
10 x(_x), y(_y), dx(_dx), dy(_dy), action(_action), button_state(_button_state), button(_button)
11{
12}
13// write to stream
14void mouse_event::stream_out(std::ostream& os) const
15{
16 const char* action_strs[] = {
17 "press", "release", "wheel", "move", "drag", "enter", "leave"
18 };
19 const char* button_strs[] = {
20 "", "Left_Button", "Middle_Button", "", "Right_Button"
21 };
24 os << "Left_Button+";
26 os << "Middle_Button+";
28 os << "Right_Button+";
29 os << "mouse " << action_strs[get_action()];
30 if ((get_action() == MA_RELEASE) && ((get_flags() & EF_DND) != 0))
31 os << "<" << get_dnd_text() << ">";
33 os << " " << button_strs[get_button()];
34 if (get_action() == MA_WHEEL)
35 os << "(" << get_dy() << ")";
36 os << " at " << get_x() << "," << get_y();
37 if (get_action() == MA_DRAG || get_action() == MA_MOVE)
38 os << "(" << get_dx() << "," << get_dy() << ")";
39}
40// read from stream
41void mouse_event::stream_in(std::istream&)
42{
43}
44//
45short mouse_event::get_x() const
46{
47 return x;
48}
49//
50short mouse_event::get_y() const
51{
52 return y;
53}
54// not used yet
56{
57 return dx;
58}
59// used for mouse wheel delta
61{
62 return dy;
63}
64//
69//
70unsigned char mouse_event::get_button_state() const
71{
72 return button_state;
73}
74//
75unsigned char mouse_event::get_button() const
76{
77 return button;
78}
79
81const std::string& mouse_event::get_dnd_text() const
82{
83 return dnd_text;
84}
85
87void mouse_event::set_x(short _x)
88{
89 x = _x;
90}
91
93void mouse_event::set_y(short _y)
94{
95 y = _y;
96}
97
99void mouse_event::set_dx(short _dx)
100{
101 dx = _dx;
102}
103
105void mouse_event::set_dy(short _dy)
106{
107 dy = _dy;
108}
109
112{
113 action = _action;
114}
115
117void mouse_event::set_button_state(unsigned char _button_state)
118{
119 button_state = _button_state;
120}
121
123void mouse_event::set_button(unsigned char _button)
124{
125 button = _button;
126}
127
129void mouse_event::set_dnd_text(const std::string& text)
130{
131 dnd_text = text;
132}
133
134
135 }
136}
gui independent button class that provides a click signal
Definition button.h:13
virtual void stream_out(std::ostream &os) const
write to stream
Definition event.cxx:139
unsigned get_flags() const
return the event flags
Definition event.cxx:214
void set_dy(short _dy)
set for move and drag events the difference in y to the previous position, for wheel events the amoun...
void set_dx(short _dx)
set for move and drag events the difference in x to the previous position
short get_y() const
current mouse y position (origin is top-left of window)
short dx
change in x position
Definition mouse_event.h:40
void set_x(short _x)
set current mouse x position
short y
y position of mouse pointer
Definition mouse_event.h:38
void set_button_state(unsigned char _button_state)
set the button state as values from MouseButton combined with a logical or-operation
unsigned char action
store MouseAction
Definition mouse_event.h:44
void stream_in(std::istream &is)
read from stream
short dy
change in y position
Definition mouse_event.h:42
void set_button(unsigned char _button)
set the pressed or released button for a button press or release action
MouseAction get_action() const
return the mouse action
unsigned char button
store the pressed button
Definition mouse_event.h:48
void set_action(MouseAction _action)
return the mouse action
short get_dx() const
for move and drag events the difference in x to the previous position
std::string dnd_text
the texted resulting from a drag and drop event
Definition mouse_event.h:52
void stream_out(std::ostream &os) const
write to stream
short get_x() const
current mouse x position (origin is top-left of window)
unsigned char button_state
store the button state
Definition mouse_event.h:46
void set_y(short _y)
set current mouse y position
unsigned char get_button_state() const
return the button state as values from MouseButton combined with a logical or-operation
void set_dnd_text(const std::string &text)
set the drag&drop text
short x
x position of mouse pointer
Definition mouse_event.h:36
mouse_event(int x, int y, MouseAction _action, unsigned char _button_state=0, unsigned char _button=0, short _dx=0, short _dy=0, unsigned char _modifiers=0, unsigned char _toggle_keys=0, double _time=0)
construct a mouse
short get_dy() const
for move and drag events the difference in y to the previous position, for wheel events the amount th...
const std::string & get_dnd_text() const
only valid in a MA_RELEASE event with the flag MF_DND set, return the text resulting from the drag&dr...
unsigned char get_button() const
return the pressed or released button for a button press or release action
@ MB_MIDDLE_BUTTON
middle button
Definition mouse_event.h:27
@ MB_RIGHT_BUTTON
right button
Definition mouse_event.h:28
@ MB_LEFT_BUTTON
left button
Definition mouse_event.h:26
MouseAction
different actions that a mouse can perform
Definition mouse_event.h:12
@ MA_PRESS
mouse button pressed
Definition mouse_event.h:13
@ MA_MOVE
mouse pointer moved
Definition mouse_event.h:16
@ MA_WHEEL
mouse wheel moved
Definition mouse_event.h:15
@ MA_DRAG
mouse drag action
Definition mouse_event.h:17
@ MA_RELEASE
mouse button released
Definition mouse_event.h:14
@ EID_MOUSE
id for mouse event
Definition event.h:18
@ EF_DND
whether mouse has a drag and drop target attached
Definition event.h:33
the cgv namespace
Definition print.h:11