1 /*
2 * levels.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 
9 #ifndef __levels__
10 #define __levels__
11 
12 #include "widget.h"
13 #include "box.h"
14 #include "button.h"
15 #include "checkbutton.h"
16 #include "plus_button.h"
17 #include "minus_button.h"
18 #include "cross_button.h"
19 #include "filled_button.h"
20 #include "mouse_slider.h"
21 #include "state_button.h"
22 
23 #include <string>
24 #include <vector>
25 
26 struct levels;
27 
28 struct paint_listener {
29   virtual void paint (levels&) = 0;
30 };
31 
32 struct shift_listener {
33   virtual void shifted (levels&) = 0;
34 };
35 
36 struct bookmark : state_button {
37   std::vector<int> ids;
38 };
39 
40 struct levels : widget, move_listener {
41 
42   int n;
43   int last;
44 
45   int elem; // element width
46   int height;
47 
48   int lev; // edited level
49   float val; // edited val
50   int hgt; // edited height
51 
52   int saveable;
53 	int editable;
54 
55 	enum {STARTED=1, FINISH};
56   int editing; // editing element?
57 	int stop_editing ();
58 
59 	int paint; // paint levels with mouse?
60   paint_listener* paintl;
61 
62   std::vector<float> values; // 0 to 1 for each level
63   std::vector<int> heights; // 0 to height
64 
65 	bool* selection;
66 	int nsel;
67 	int sel_sz;
68 
69   std::vector<bookmark*> bmk; // bookmarks of selections
70   void addbookmark ();
71   void removebookmark ();
72   void removeallbookmarks ();
73   void clearbookmarks ();
74 
75   MAKE_STATE_LISTENER (bmlis, bml)
76 
77   levels (const std::string& s);
78   void load ();
79 
80   void save ();
81   ~levels ();
82 
83   int handle_input ();
84 
85   float a, a0;
86   void draw ();
87 
88   void clear_hgt_val ();
89   void calc_lev ();
90 	void calc_hgt_val ();
91   int set (int i, float v, int h = -1);
92 	void set_only (int i, float v);
93 	int change (int i, float d);
94 	int update_mul_lev (int dy);
95 
96 	void update ();
97 
98   change_listener<levels>* chgl;
99 
100 	int rshift ();
101 	int lshift ();
102   shift_listener* shftl;
103 
104   void chkpos ();
105 	void reheight ();
106 
107   // manipulation
108   button ball, binvert, bnone;
109   button bslide, blshift, brshift;
110   checkbutton cbwrap;
111   MAKE_CLICK_LISTENER(alllis, alll)
112   MAKE_CLICK_LISTENER(invlis, invl)
113   MAKE_CLICK_LISTENER(nonlis, nonl)
114   MAKE_CLICK_LISTENER(lshiftlis, lsl)
115   MAKE_CLICK_LISTENER(rshiftlis, rsl)
116 
117   struct slide : click_listener, mouse_slider_listener {
118     void clicked (button& b);
119     void moused (int dir, double scl);
120   } sll;
121 
122   void selall ();
123   void selnon ();
124   void invsel ();
125 
126   plus_button plus;
127   MAKE_CLICK_LISTENER(pluslis, pll)
128   minus_button minus;
129   MAKE_CLICK_LISTENER(minuslis, mil)
130   cross_button cross;
131   MAKE_CLICK_LISTENER (crosslis, crol)
132 
133   filled_button szr;
134   //MAKE_MOVE_LISTENER (szrlis, szl)
135   void moved ();
136 
137   void moused (int dir, double scl);
138 
139   void set_pos (int x, int y);
140 
141   int lmb_clicked;
142   int prev_mousey;
143 
144 
145 };
146 
147 #endif
148