cgv
Loading...
Searching...
No Matches
stick_event.cxx
1#include "stick_event.h"
2
3namespace cgv {
4 namespace gui {
5
6
9{
10 switch (action) {
11 case SA_TOUCH: return "touch";
12 case SA_PRESS: return "press";
13 case SA_UNPRESS: return "unpress";
14 case SA_RELEASE: return "release";
15 case SA_MOVE: return "move";
16 case SA_DRAG: return "drag";
17 default: return "unknown";
18 }
19}
20
22stick_event::stick_event(StickAction _action, float _x, float _y, float _dx, float _dy,
23 unsigned _player_index, unsigned _controller_index, unsigned _stick_index, double _time)
24 : event(EID_STICK, 0,0,_time), action(_action), position(_x, _y), difference(_dx, _dy),
25 player_index(_player_index), controller_index(_controller_index), stick_index(_stick_index)
26{}
27
30{
31 return player_index;
32}
35{
36 return controller_index;
37}
40{
41 return stick_index;
42}
43
45void stick_event::stream_out(std::ostream& os) const
46{
48 os << get_stick_action_string(StickAction(action)) << "(" << position[0] << "," << position[1] << ")[";
49 if (difference[0] > 0)
50 os << "+";
51 os << difference[0] << ",";
52 if (difference[1] > 0)
53 os << "+";
54 os << difference[1] << "]";
55 os << "<" << (int)player_index << ":" << (int)controller_index << ":" << (int)stick_index << ">";
56}
58void stick_event::stream_in(std::istream& is)
59{
60 std::cout << "not implemented" << std::endl;
61}
67
69float stick_event::get_x() const
70{
71 return position[0];
72}
74float stick_event::get_y() const
75{
76 return position[1];
77}
80{
81 return difference[0];
82}
85{
86 return difference[1];
87}
90{
91 return position;
92}
93
96{
97 return difference;
98}
99
105
108{
109 return position[0] - difference[0];
110}
113{
114 return position[1] - difference[1];
115}
116
117 }
118}
virtual void stream_out(std::ostream &os) const
write to stream
Definition event.cxx:139
vec2 difference
change in stick location
Definition stick_event.h:38
unsigned get_stick_index() const
return stick index
const vec2 & get_position() const
return current position
float get_last_x() const
return the last x value of the stick
float get_y() const
return the current y value of the stick
void stream_in(std::istream &is)
read from stream
const vec2 & get_difference() const
return the vector of coordinate differences (dx,dy)
vec2 position
current stick location
Definition stick_event.h:36
stick_event(StickAction _action, float _x, float _y, float _dx, float _dy, unsigned _player_index=0, unsigned _controller_index=0, unsigned _stick_index=0, double _time=0)
construct a key event from its textual description
float get_dy() const
return the current change in y value of the stick
float get_last_y() const
return the last y value of the stick
unsigned get_controller_index() const
return controller index
unsigned char action
store stick action
Definition stick_event.h:34
void stream_out(std::ostream &os) const
write to stream
float get_dx() const
return the current change in x value of the stick
vec2 get_last_position() const
return last position
unsigned get_player_index() const
return player index
StickAction get_action() const
return the stick action
float get_x() const
return the current x value of the stick
std::string get_stick_action_string(StickAction action)
convert a key action into a readable string
StickAction
different actions that a stick can perform
Definition stick_event.h:15
@ SA_DRAG
stick moved in pressed state
Definition stick_event.h:21
@ SA_RELEASE
stick release action
Definition stick_event.h:19
@ SA_PRESS
stick press action
Definition stick_event.h:17
@ SA_TOUCH
stick touch action
Definition stick_event.h:16
@ SA_UNPRESS
stick unpress repeated press action
Definition stick_event.h:18
@ SA_MOVE
stick moved with respect to last event
Definition stick_event.h:20
@ EID_STICK
id of a stick event describing a two axis controller that optionally can be touched and pressed
Definition event.h:20
the cgv namespace
Definition print.h:11