1 /* 2 * basic_editor.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 __basic_editor 10 #define __basic_editor 11 12 #include "viewwin.h" 13 #include "point.h" 14 #include "mocap.h" 15 #include "ui.h" 16 #include "textboard.h" 17 18 #include <map> 19 20 struct click_point_t { 21 point<float> pt; 22 int noted; 23 click_point_t (); 24 void note (float x, float y); 25 }; 26 27 struct basic_editor : ui { 28 29 window win; // edit window 30 31 // object space <> window space mapping 32 point<int> win_chunk; 33 point<float> obj_chunk; 34 point<float> win_per_obj; 35 point<float> obj_per_win; 36 int win_resolution; 37 float obj_resolution; 38 39 void obj2win (const point<float>& p, float& wx, float& wy); 40 void obj2win (const float& ox, const float& oy, float& wx, float& wy); 41 void obj2view (const float& ox, const float& oy, int& vx, int& vy); 42 void obj2mouse (const float& ox, const float& oy); 43 void view2obj (const int& vx, const int& vy, float& ox, float& oy); 44 void win2obj (const float& dx, const float& dy, float& cx, float& cy); 45 46 // snapping support 47 int snap_what; 48 click_point_t shft_clk, ctrl_clk; 49 point<float> clk; 50 enum {SNAP_NONE, SNAP_X, SNAP_Y, SNAP_BOTH}; 51 void snap (float& x, float& y); 52 int is_snapx (); 53 int is_snapy (); 54 void do_snapx (float& x); 55 void do_snapy (float& y); 56 57 std::vector<int> xlines, ylines; 58 int nxpts, nypts; 59 60 int startx, endx, starty, endy; 61 void update_snaps (); 62 void draw_snaps (); 63 void set_snap (int what); 64 65 std::string cursor_mesg; 66 float cursor_x, cursor_y; 67 68 mocap mocap0; 69 void toggle_mouse_capture (); 70 void start_mouse_capture (); 71 void stop_mouse_capture (); 72 73 int pan, zoom; // pan & zoom deltas to control pan and zoom speed 74 void do_panx (int dir); 75 void do_pany (int dir); 76 void do_zoom (int dir); 77 78 basic_editor (); 79 virtual ~basic_editor (); 80 81 void calc_win_mouse (); 82 get_obj_chunkbasic_editor83 inline const point<float>& get_obj_chunk () { 84 return obj_chunk; 85 } 86 get_obj_resolutionbasic_editor87 inline float get_obj_resolution () { 88 return obj_resolution; 89 } 90 91 void load (const std::string& fname); 92 void load (std::ifstream& file); 93 void save (std::ofstream& file); 94 95 void set_win_chunk (int x, int y); 96 int handle_input (); 97 int lmb_clicked; 98 99 void project (); 100 void unproject (); 101 102 void draw (); 103 104 static int hide_cursor; 105 int draw_guide; 106 void draw_cursor (); 107 108 textboard tb; 109 int ntexts; 110 111 int kbkb_attack_editor; 112 int edit_sustain; 113 float susx, susy; 114 box<float> susbox; 115 void update_sustain (float s); 116 void calc_visual_params (); 117 118 static float* gl_pts; 119 static int n_pts; 120 static int ref; alloc_gl_ptsbasic_editor121 inline static void alloc_gl_pts (int n) { 122 if (n > n_pts) { 123 if (gl_pts) delete[] gl_pts; 124 gl_pts = new float [2 * n]; 125 n_pts = n; 126 } 127 } 128 129 }; 130 131 132 #endif 133