Rev 2097 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
964 | jag | 1 | /* |
2 | * checkbutton.cc |
||
2097 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2024 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1479 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
964 | jag | 6 | */ |
7 | |||
8 | |||
9 | #include "checkbutton.h" |
||
10 | using namespace std; |
||
11 | |||
1377 | jag | 12 | checkbutton::checkbutton () : state (0), lsnr (0), colorize_ (1) { |
964 | jag | 13 | set_state (0); |
14 | button::set_listener (this); |
||
15 | } |
||
16 | |||
17 | void checkbutton::clicked (button& b) { |
||
18 | toggle (); |
||
19 | } |
||
20 | |||
21 | |||
22 | void checkbutton::set_state (int s, int cl) { |
||
23 | if (s) turn_on (cl); else turn_off (cl); |
||
24 | } |
||
25 | |||
26 | void checkbutton::turn_on (int call) { |
||
27 | if (colorize_) set_color (on_color); |
||
28 | if (state != 1) { |
||
29 | state = 1; |
||
1269 | jag | 30 | if (call && lsnr) lsnr->changed (*this); |
964 | jag | 31 | } |
32 | } |
||
33 | |||
34 | void checkbutton::turn_off (int call) { |
||
35 | if (colorize_) set_color (off_color); |
||
36 | if (state != 0) { |
||
37 | state = 0; |
||
1269 | jag | 38 | if (call && lsnr) lsnr->changed (*this); |
964 | jag | 39 | } |
40 | } |
||
41 | |||
42 | void checkbutton::toggle () { |
||
43 | if (state) turn_off (); else turn_on (); |
||
44 | } |
||
45 | |||
46 | void checkbutton::blend_on_off_color (float blend) { |
||
47 | |||
48 | color result; |
||
49 | |||
50 | if (state) |
||
51 | ::blend_color (off_color, on_color, result, blend); |
||
52 | else |
||
53 | ::blend_color (on_color, off_color, result, blend); |
||
54 | |||
55 | set_color (result); |
||
56 | |||
57 | } |
||
1132 | jag | 58 | |
2076 | jag | 59 | void perpbutton::draw () { |
60 | widget::draw (); |
||
61 | glBegin (GL_LINES); |
||
62 | glVertex2i (extents.left, extents.bottom); |
||
63 | glVertex2i (extents.right, extents.bottom); |
||
64 | glVertex2i (extents.midx, extents.bottom); |
||
65 | glVertex2i (extents.midx, extents.top); |
||
66 | glEnd (); |
||
67 | } |
||
2078 | jag | 68 | |
69 | void rotdir::draw () { |
||
70 | static int pts [16]; |
||
71 | static const int dy = 6; |
||
72 | static const int vals [] = {1, -1}; |
||
73 | val = vals [state]; |
||
74 | box<int>& e = extents; |
||
75 | if (state) { |
||
76 | pts[0]=e.midx; pts[1]=e.top+dy; |
||
77 | pts[2]=e.right; pts[3]=e.top; |
||
78 | pts[4]=e.left; pts[5]=e.top; |
||
79 | pts[6]=e.left; pts[7]=e.bottom; |
||
80 | pts[8]=e.right; pts[9]=e.bottom; |
||
81 | } else { |
||
82 | pts[0]=e.midx; pts[1]=e.top+dy; |
||
83 | pts[2]=e.left; pts[3]=e.top; |
||
84 | pts[4]=e.right; pts[5]=e.top; |
||
85 | pts[6]=e.right; pts[7]=e.bottom; |
||
86 | pts[8]=e.left; pts[9]=e.bottom; |
||
87 | } |
||
88 | glVertexPointer (2, GL_INT, 0, pts); |
||
89 | glDrawArrays (GL_LINE_STRIP, 0, 5); |
||
90 | glBegin (GL_LINES); |
||
91 | glVertex2i (e.midx, e.top-dy); |
||
92 | glVertex2i (pts[2], pts[3]); |
||
93 | glEnd (); |
||
94 | } |
||
2146 | jag | 95 | |
96 | void justset (checkbutton& cb, int state) { |
||
97 | if (state) cb.turn_on (DONT_CALL_LISTENER); else cb.turn_off (DONT_CALL_LISTENER); |
||
98 | } |