1 /*
2 * gravity.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 __GRAVITY
9 #define __GRAVITY
10 
11 #include "widget.h"
12 #include "arrow_button.h"
13 #include "checkbutton.h"
14 #include "spinner2.h"
15 #include "point.h"
16 #include "mouse_slider.h"
17 #include "multi_curve.h"
18 #include "mod_params.h"
19 #include "curve_editor.h"
20 #include "ui_list.h"
21 
22 struct drone;
23 struct gravity_t : widget, click_listener, mouse_slider_listener {
24 
25   // ui
26   arrow_button fold;
27   button zero, reset;
28   arrow_button left, right, up, down;
29   checkbutton mouse, dron, keepsize;
30   button changesize;
31   MAKE_STATE_LISTENER (mousel, ml)
32 
33   int modyes;
34   double modparin;
35   struct modulatet {
36     checkbutton yes;
37     MAKE_STATE_LISTENER(yesl, yl)
38     spinner2<float> depth, bpm;
39     MAKE_FIELD_LISTENER (depthl, dl)
40     MAKE_FIELD_LISTENER (bpml, bl)
41     multi_curve crv;
42     button edit;
43     curve_editor ed;
44     MAKE_CLICK_LISTENER (editl, el)
45     CURVE_LISTENER(curvel)
46     curvel cl;
47     mod_params params;
modulatetgravity_t::modulatet48     modulatet () : crv ("gravmod.crv"), ed ("gravmod.ed"), params (&crv) {
49       t = ui_clk ();
50       LISTEN(yes,&yl)
51       LISTEN(edit, &el)
52       ed.add (&crv, &cl);
53     }
54     double t;
55     float eval ();
56   } mod;
57   void modulate ();
58 
59   int lmb_clicked;
60   int hitt;
61   enum {NEXT_TO_NOTHING = -1, NOTHING, BASE, TIP};
62   int hit (const point<int>& p, int mx, int my);
63 
64   int handlesize;
65   point<int> base;
66   point<int> tip;
67   point<int> base2tip, base2tip_ms;
68   point<int> p_base2tip;
69   point<int> bottomleft, topright;
70   point<int> textpos;
71 
72   double btux, btuy;
73 
74   float strength;
75   float gx, gy;
76 
77   drone* tracked_drone;
78   int forcetrack;
79   void track (int vx, int vy);
80   int maos;
81   int dronn;
82 
83   double mag0, mag;
84 	int keep_size;
85   void updmag (double m);
86 
87 
88   gravity_t ();
89   void load (std::ifstream& file);
90   void save (std::ofstream& file);
91   int handle_input ();
92   void set (point<int>& p, int mx, int my, int calc_mag = 1);
93   void calc (int calc_mag = 1);
94   void calcui ();
95   void initui ();
96   void preset (int id);
97   void doreset (int keep_size = 0);
98 	int stop_editing ();
99 
100   int gl_base [8];
101   float gl_arrow[12];
102 
103   void draw ();
104 
105   void clicked (button& b);
106   void moused (int dir, double scl);
107 
108   int unfolded ();
109 
110   int ldwx, ldwy; // last tracked drone pos on din window
111 
112 };
113 #endif
114 
115 
116 
117