-
Notifications
You must be signed in to change notification settings - Fork 0
/
cvButtons.h
129 lines (105 loc) · 2.91 KB
/
cvButtons.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef CVBUTTONS_H_
#define CVBUTTONS_H_
#include <opencv/cv.h>
#include <vector>
using std::vector;
/**
Global OpenCV mouse button callback.
Must be set with cvSetMouseCallback(..) to make buttons work.
*/
void cvButtonsOnMouse( int event, int x, int y, int flags, void* param );
/**
\class PushButton
\brief <b>Class PushButton</b>\n
\brief Implements a single push button object.\n
\author Andreas Geiger
\author Karlsruhe Institute of Technology
\version 1.0
\date 16.07.2007
*/
class PushButton {
public:
/**
Constructor takes parameters such as:
- \b x , \b y : x/y position of a push button
- \b w , \b h : width/height of a push button
- \b t: -1 if normal button or 0/1 as state of a toggle button
- \b text: button description
- \b cb: button callback function. Takes a function pointer.
The argument will be the button toggle state when pressed.
*/
PushButton( int x, int y, int w, int h, int t, char *text, void (*cb)(int) ):
x_pos(x), y_pos(y), width(w), height(h), toggle(t), text(text), cb(cb) {}
/**
x/y position of a push button
*/
int x_pos, y_pos;
/**
width/height of a push button
*/
int width, height;
/**
-1 if normal button or 0/1 as state of a toggle button
*/
int toggle;
/**
button description
*/
char *text;
/**
button callback function. Takes a function pointer.
*/
void (*cb)(int);
};
/**
\class CvButtons
\brief <b>Class CvButtons</b>\n
\brief Implements functions to enhance the OpenCV GUI elements\n
\brief by simple, platform-independet push buttons and toggle elements.\n
\author Andreas Geiger
\author Karlsruhe Institute of Technology
\version 1.0
\date 16.07.2007
*/
class CvButtons {
public:
/**
Constructor creates button font
*/
CvButtons(){ cvInitFont( &font, CV_FONT_HERSHEY_PLAIN, 1, 1, 0, 1, CV_AA ); }
void release(){ buttonList.clear(); }
/**
Deconstructor clears the button list
*/
~CvButtons(){ release(); }
/**
Called by cvButtonsOnMouse() when button was pressed
*/
void setMouseState(int e, int x, int y, int f) {me=e; mx=x; my=y; mf=f;}
/**
Paint all buttons to an image
*/
void paintButtons(IplImage *img);
/**
Add button to list
*/
void addButton(PushButton pb){ buttonList.push_back(pb); }
/**
Delete button from list
*/
void delButton(int pos){ buttonList.erase( buttonList.begin()+pos ); }
private:
/**
The list of all buttons in this class
*/
vector<PushButton> buttonList;
/**
The last event (mouse state)
*/
int me, mx, my, mf;
/**
The font to draw the buttons
*/
CvFont font;
};
#endif /*CVBUTTONS_H_*/