1 /*
2 * options_list.h
3 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath
4 * DIN Is Noise is released under GNU Public License 2.0
5 * For more information, please visit https://dinisnoise.org/
6 */
7 
8 #ifndef __options_list
9 #define __options_list
10 
11 #include "arrow_button.h"
12 #include "font.h"
13 #include <string>
14 
15 extern int lmb;
16 
17 struct option_listener : voiddata {
18   virtual void picked (label& lbl, int dir) = 0;
19 };
20 
21 #define MAKE_OPTION_LISTENER(name,var)\
22 struct name : option_listener {\
23 	void picked (label& l, int dir);\
24 };\
25 name var;\
26 
27 
28 #define PICKED_OPTION(scope,name) void scope::name::picked (label& l, int dir)
29 
30 struct options_list : widget, click_listener {
31 
32 	button option;
33   arrow_button left;
34   arrow_button right;
35 	button apply;
36 
37   option_listener* olis;
38 
39   options_list (int show_apply = 0) {
40     option.add_child (this);
41     option.add_child (&left);
42     option.add_child (&right);
43 		option.add_child (&apply);
44     left.set_dir (arrow_button::left);
45     right.set_dir (arrow_button::right);
46     left.set_listener (this);
47     right.set_listener (this);
48 		apply.set_text ("Apply");
49 		if (show_apply) apply.show (); else apply.hide ();
50     olis = 0;
51   }
52 
set_textoptions_list53   void set_text (const std::string& t) {
54     option.set_text (t);
55     set_name (t);
56 		set_pos (posx, posy);
57   }
58 
set_listeneroptions_list59   void set_listener (option_listener* _olis) {
60     olis = _olis;
61   }
62 
set_posoptions_list63   void set_pos (int x, int y) {
64 
65     widget::set_pos (x, y);
66 
67     static const int spacing = 4;
68     left.set_pos (x, y + fnt.lift);
69     advance_right (x, left, spacing);
70 
71     right.set_pos (x, y + fnt.lift);
72     advance_right (x, right, spacing + 1);
73 
74     option.set_pos (x, y);
75 		advance_right (x, option, 4 * spacing);
76 
77 		apply.set_pos (x, y);
78 
79 		widget* rw = 0;
80 		if (apply.visible) rw = &apply; else rw = &option;
81 		set_extents (left.extents.left, option.extents.bottom, rw->extents.right, rw->extents.top);
82 
83   }
84 
handle_inputoptions_list85   int handle_input () {
86 		int r = option.handle_input();
87 		if (left.handle_input());
88 		else if (right.handle_input()) ;
89 		else if (apply.visible && apply.handle_input()) ;
90 		return r;
91   }
92 
drawoptions_list93   void draw () {
94 		widget::draw ();
95     option.draw ();
96     left.draw ();
97     right.draw ();
98 		if (apply.visible) apply.draw ();
99   }
100 
clickedoptions_list101   void clicked (button& b) {
102     if (olis) {
103       if (&b == &left)
104         olis->picked (option, -1);
105       else
106         olis->picked (option, 1);
107     }
108   }
109 
set_click_repeatoptions_list110   void set_click_repeat (int click_repeat) {
111     left.click_repeat = click_repeat;
112     right.click_repeat = click_repeat;
113   }
114 
set_moveableoptions_list115 	void set_moveable (int m, int mc, int* pmb) {
116     option.set_moveable (m, mc, pmb);
117     widget::set_moveable (m, mc, pmb);
118   }
119 
120 };
121 
122 #endif
123