@@ -16,76 +16,85 @@ Licensed under the MIT license.
16
16
17
17
int main (int argc, const char *argv[])
18
18
{
19
- cv::Mat frame = cv::Mat (300 , 600 , CV_8UC3);
20
19
bool checked = false ;
21
20
bool checked2 = true ;
22
21
int count = 0 ;
23
- double countFloat = 0.0 ;
24
22
double trackbarValue = 0.0 ;
25
23
26
24
// Init cvui and tell it to create a OpenCV window, i.e. cv::namedWindow(WINDOW_NAME).
27
25
cvui::init (WINDOW_NAME);
28
26
27
+ double scaling = 1.0 ;
28
+ double currentScaling = -1 ;
29
+ cv::Mat frame;
30
+
29
31
while (true ) {
32
+ if (scaling != currentScaling) {
33
+ frame = cv::Mat (std::lround (scaling * 300 ), std::lround (scaling * 600 ), CV_8UC3);
34
+ currentScaling = scaling;
35
+ }
36
+
30
37
// Fill the frame with a nice color
31
38
frame = cv::Scalar (49 , 52 , 49 );
32
39
33
40
// Show some pieces of text.
34
- cvui::text (frame, 50 , 30 , " Hey there!" );
41
+ cvui::text (frame, std::lround (scaling * 50 ), std::lround (scaling * 30 ) , " Hey there!" , scaling*cvui::DEFAULT_FONT_SCALE );
35
42
36
43
// You can also specify the size of the text and its color
37
44
// using hex 0xRRGGBB CSS-like style.
38
- cvui::text (frame, 200 , 30 , " Use hex 0xRRGGBB colors easily" , 0.4 , 0xff0000 );
45
+ cvui::text (frame, std::lround (scaling * 200 ), std::lround (scaling * 30 ) , " Use hex 0xRRGGBB colors easily" , scaling*cvui::DEFAULT_FONT_SCALE , 0xff0000 );
39
46
40
47
// Sometimes you want to show text that is not that simple, e.g. strings + numbers.
41
48
// You can use cvui::printf for that. It accepts a variable number of parameter, pretty
42
49
// much like printf does.
43
- cvui::printf (frame, 200 , 50 , 0.4 , 0x00ff00 , " Use printf formatting: %d + %.2f = %f" , 2 , 3.2 , 5.2 );
50
+ cvui::printf (frame, std::lround (scaling * 200 ), std::lround (scaling * 50 ), scaling*cvui::DEFAULT_FONT_SCALE , 0x00ff00 , " Use printf formatting: %d + %.2f = %f" , 2 , 3.2 , 5.2 );
44
51
45
52
// Buttons will return true if they were clicked, which makes
46
53
// handling clicks a breeze.
47
- if (cvui::button (frame, 50 , 60 , " Button" )) {
54
+ if (cvui::button (frame, std::lround (scaling * 50 ), std::lround (scaling * 60 ) , " Colored Button" , scaling*cvui::DEFAULT_FONT_SCALE, 0xa05050 )) {
48
55
std::cout << " Button clicked" << std::endl;
49
56
}
50
57
51
58
// If you do not specify the button width/height, the size will be
52
59
// automatically adjusted to properly house the label.
53
- cvui::button (frame, 200 , 70 , " Button with large label" );
60
+ cvui::button (frame, std::lround (scaling * 200 ), std::lround (scaling * 70 ) , " Button with large label" , scaling*cvui::DEFAULT_FONT_SCALE );
54
61
55
62
// You can tell the width and height you want
56
- cvui::button (frame, 410 , 70 , 15 , 15 , " x" );
63
+ cvui::button (frame, std::lround (scaling * 410 ), std::lround (scaling * 70 ), std::lround (scaling * 15 ), std::lround (scaling * 15 ) , " x" , scaling*cvui::DEFAULT_FONT_SCALE );
57
64
58
65
// Window components are useful to create HUDs and similars. At the
59
66
// moment, there is no implementation to constraint content within a
60
67
// a window.
61
- cvui::window (frame, 50 , 120 , 120 , 100 , " Window" );
68
+ cvui::window (frame, std::lround (scaling * 50 ), std::lround (scaling * 120 ), std::lround (scaling * 120 ), std::lround (scaling * 100 ) , " Window" , scaling*cvui::DEFAULT_FONT_SCALE );
62
69
63
70
// The counter component can be used to alter int variables. Use
64
71
// the 4th parameter of the function to point it to the variable
65
72
// to be changed.
66
- cvui::counter (frame, 200 , 120 , &count);
73
+ cvui::counter (frame, std::lround (scaling * 200 ), std::lround (scaling * 120 ) , &count, 1 , " %d " , scaling*cvui::DEFAULT_FONT_SCALE );
67
74
68
75
// Counter can be used with doubles too. You can also specify
69
76
// the counter's step (how much it should change
70
77
// its value after each button press), as well as the format
71
78
// used to print the value.
72
- cvui::counter (frame, 320 , 120 , &countFloat, 0.1 , " %.1f" );
79
+ cvui::counter (frame, std::lround (scaling * 320 ), std::lround (scaling * 120 ), &scaling, 0.1 , " %.1f" , scaling*cvui::DEFAULT_FONT_SCALE, 0x50a050 );
80
+
81
+ cvui::printf (frame, std::lround (scaling * 340 ), std::lround (scaling * 150 ), scaling*cvui::DEFAULT_FONT_SCALE, 0xCECECE , " Scaling" );
73
82
74
83
// The trackbar component can be used to create scales.
75
84
// It works with all numerical types (including chars).
76
- cvui::trackbar (frame, 420 , 110 , 150 , &trackbarValue, 0 ., 50 .);
85
+ cvui::trackbar (frame, std::lround (scaling * 420 ), std::lround (scaling * 110 ), std::lround (scaling * 150 ) , &trackbarValue, 0 ., 50 ., 1 , " %.1Lf " , 0 , 1.0 , scaling*cvui::DEFAULT_FONT_SCALE );
77
86
78
87
// Checkboxes also accept a pointer to a variable that controls
79
88
// the state of the checkbox (checked or not). cvui::checkbox() will
80
89
// automatically update the value of the boolean after all
81
90
// interactions, but you can also change it by yourself. Just
82
91
// do "checked = true" somewhere and the checkbox will change
83
92
// its appearance.
84
- cvui::checkbox (frame, 200 , 160 , " Checkbox" , &checked);
85
- cvui::checkbox (frame, 200 , 190 , " A checked checkbox" , &checked2);
93
+ cvui::checkbox (frame, std::lround (scaling * 200 ), std::lround (scaling * 190 ) , " Checkbox" , &checked, 0x000000 , scaling*cvui::DEFAULT_FONT_SCALE );
94
+ cvui::checkbox (frame, std::lround (scaling * 200 ), std::lround (scaling * 220 ) , " A checked checkbox" , &checked2, 0x000000 , scaling*cvui::DEFAULT_FONT_SCALE );
86
95
87
96
// Display the lib version at the bottom of the screen
88
- cvui::printf (frame, frame.cols - 80 , frame.rows - 20 , 0.4 , 0xCECECE , " cvui v.%s" , cvui::VERSION);
97
+ cvui::printf (frame, frame.cols - std::lround (scaling * 80 ) , frame.rows - std::lround (scaling * 20 ), scaling*cvui::DEFAULT_FONT_SCALE , 0xCECECE , " cvui v.%s" , cvui::VERSION);
89
98
90
99
// This function must be called *AFTER* all UI components. It does
91
100
// all the behind the scenes magic to handle mouse clicks, etc.
@@ -101,4 +110,4 @@ int main(int argc, const char *argv[])
101
110
}
102
111
103
112
return 0 ;
104
- }
113
+ }
0 commit comments