summaryrefslogtreecommitdiff
path: root/engine.c
diff options
context:
space:
mode:
authorerdgeist <erdgeist@bauklotz.fritz.box>2017-04-09 22:07:54 +0200
committererdgeist <erdgeist@bauklotz.fritz.box>2017-04-09 22:07:54 +0200
commit0ab1e4878f9e2b592032dc7c67ae8018293058f6 (patch)
tree8bf546c933d3582d3d51de53c53756cd4ded1e1e /engine.c
parent62d3d6d5278972797dda57348ebaae4ca74b8828 (diff)
Extend short lines, if min and max is manually edited
Diffstat (limited to 'engine.c')
-rw-r--r--engine.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/engine.c b/engine.c
index 43892fb..0e8c34e 100644
--- a/engine.c
+++ b/engine.c
@@ -22,10 +22,11 @@ static void highlight_line(int value, int y, int max_x, uint32_t color);
22void 22void
23engine_redraw() 23engine_redraw()
24{ 24{
25 const char *config_hints[] = { "No", "Harfe", "File", "Edit" };
25 char text[32]; 26 char text[32];
26 char *config_hints[] = { "No", "Harfe", "File", "Edit" }; 27 const int tos1 = g_midi_three_octave_split_1, tos2 = g_midi_three_octave_split_2;
27 int i, MAX_X, MAX_Y, FONT_HEIGHT; 28 const int height = g_max_y - g_min_y;
28 int height = g_max_y - g_min_y; 29 int i, x2, MAX_X, MAX_Y, FONT_HEIGHT;
29 30
30 display_redraw(); 31 display_redraw();
31 display_clear(); 32 display_clear();
@@ -36,7 +37,6 @@ engine_redraw()
36 37
37 if (height) { 38 if (height) {
38 int b = g_midi_three_octave_split_inverse; 39 int b = g_midi_three_octave_split_inverse;
39 int tos1 = g_midi_three_octave_split_1, tos2 = g_midi_three_octave_split_2;
40 display_text( b ? "+1" : "-1", 4, scale(g_min_y + tos1 * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff); 40 display_text( b ? "+1" : "-1", 4, scale(g_min_y + tos1 * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff);
41 display_text( " 0", 4, scale(g_min_y + (tos1 + tos2) * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff); 41 display_text( " 0", 4, scale(g_min_y + (tos1 + tos2) * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff);
42 display_text( b ? "-1" : "+1", 4, scale(g_min_y + (tos2 / 2 + 50 ) * height / 100) + FONT_HEIGHT / 2, 0x007f7f7fff); 42 display_text( b ? "-1" : "+1", 4, scale(g_min_y + (tos2 / 2 + 50 ) * height / 100) + FONT_HEIGHT / 2, 0x007f7f7fff);
@@ -49,7 +49,6 @@ engine_redraw()
49 display_line_color(0, scale(g_min_y + tos1 * height / 100), MAX_X, scale(g_min_y + tos1 * height / 100), 0x00ff00ff); 49 display_line_color(0, scale(g_min_y + tos1 * height / 100), MAX_X, scale(g_min_y + tos1 * height / 100), 0x00ff00ff);
50 display_line_color(0, scale(g_min_y + tos2 * height / 100), MAX_X, scale(g_min_y + tos2 * height / 100), 0x00ff00ff); 50 display_line_color(0, scale(g_min_y + tos2 * height / 100), MAX_X, scale(g_min_y + tos2 * height / 100), 0x00ff00ff);
51 51
52
53 switch (g_selected_config) { 52 switch (g_selected_config) {
54 case sel_min_y: highlight_line(g_min_y, g_min_y, MAX_X, 0xff00ffff); break; 53 case sel_min_y: highlight_line(g_min_y, g_min_y, MAX_X, 0xff00ffff); break;
55 case sel_max_y: highlight_line(g_max_y, g_max_y, MAX_X, 0xff00ffff); break; 54 case sel_max_y: highlight_line(g_max_y, g_max_y, MAX_X, 0xff00ffff); break;
@@ -61,17 +60,28 @@ engine_redraw()
61 60
62 for (i = 0; i < g_string_count; ++i) { 61 for (i = 0; i < g_string_count; ++i) {
63 LLine *l = &g_string_conf[i].line; 62 LLine *l = &g_string_conf[i].line;
63 LLine _l = g_string_conf[i].line; // Copy for extension
64 uint32_t color = ( ( i == g_selected_string ) ? 0xff00ffff : 0x00ffffffff ); 64 uint32_t color = ( ( i == g_selected_string ) ? 0xff00ffff : 0x00ffffffff );
65 uint32_t text_color = ( ( i == g_selected_string ) ? 0xff00ffff : 0x007f7f7fff ); 65 uint32_t text_color = ( ( i == g_selected_string ) ? 0xff00ffff : 0x007f7f7fff );
66 int extended = 0, center_y = g_min_y+height/2;
66 67
67 int center_y = g_min_y+height/2; 68 if (_l.p0.y > g_min_y) {
68 int x2 = l->p1.x; 69 _l.p0.x = get_x_for_y(&_l.p0, &_l.p1, g_min_y);
69 70 _l.p0.y = g_min_y;
70 if (l->p1.x!=l->p0.x) { 71 extended = 1;
71 double m = (double)(l->p1.y-l->p0.y) / (double)(l->p1.x-l->p0.x); 72 }
72 double _x2 = ((double)center_y) - (double)l->p0.y + m * (double)l->p0.x; 73 if (_l.p1.y < g_max_y) {
73 x2 = (int)(_x2/m); 74 _l.p1.x = get_x_for_y(&l->p0 /* Using unmodified original! */, &_l.p1, g_max_y);
75 _l.p1.y = g_max_y;
76 extended = 1;
74 } 77 }
78 if (extended) {
79 display_line_color(scale(_l.p0.x), scale(_l.p0.y), scale(_l.p1.x), scale(_l.p1.y), 0x007f3f00);
80 display_circle_color(scale(_l.p0.x), scale(_l.p0.y), 4, 0x007f3f00);
81 display_circle_color(scale(_l.p1.x), scale(_l.p1.y), 4, 0x007f3f00);
82 }
83
84 x2 = get_x_for_y(&l->p0,&l->p1,center_y);
75 85
76 if (g_string_conf[i].playing) 86 if (g_string_conf[i].playing)
77 display_text(config_midi_note_to_string(g_string_conf[i].note+12*g_string_conf[i].octave), scale(x2-20), scale(center_y) + FONT_HEIGHT, text_color ); 87 display_text(config_midi_note_to_string(g_string_conf[i].note+12*g_string_conf[i].octave), scale(x2-20), scale(center_y) + FONT_HEIGHT, text_color );
@@ -100,11 +110,29 @@ highlight_line(int value, int y, int max_x, uint32_t color) {
100 display_line_color(max_x, scale(y+10), max_x-10, scale(y), color); 110 display_line_color(max_x, scale(y+10), max_x-10, scale(y), color);
101 111
102 display_rect_color(max_x/2-40, scale(y+20), 80, 40, 0xffffffff); 112 display_rect_color(max_x/2-40, scale(y+20), 80, 40, 0xffffffff);
113 snprintf(text, sizeof(text), "%d", value);
103 display_text(text, max_x/2-20, scale(y+20), 0); 114 display_text(text, max_x/2-20, scale(y+20), 0);
104} 115}
105 116
106void 117void
107engine_select_config(ConfigSelect sel) { 118engine_select_config(ConfigSelect sel) {
119 // test if we have moved g_min_y or g_max_y and resize lines accordingly
120 if (sel == sel_none) {
121 int i;
122 for (i=0; i<g_string_count; ++i) {
123 LLine *l = &g_string_conf[i].line;
124 LLine _l = g_string_conf[i].line; // Copy for extension
125
126 if (l->p0.y > g_min_y) {
127 l->p0.x = get_x_for_y(&l->p0, &l->p1, g_min_y);
128 l->p0.y = g_min_y;
129 }
130 if (l->p1.y < g_max_y) {
131 l->p1.x = get_x_for_y(&_l.p0 /* Using unmodified original! */, &l->p1, g_max_y);
132 l->p1.y = g_max_y;
133 }
134 }
135 }
108 g_selected_config = sel; 136 g_selected_config = sel;
109} 137}
110 138
@@ -112,6 +140,12 @@ ConfigSelect
112engine_change_selected(int off) 140engine_change_selected(int off)
113{ 141{
114 switch(g_selected_config) { 142 switch(g_selected_config) {
143 case sel_min_y:
144 g_min_y += off;
145 break;
146 case sel_max_y:
147 g_max_y += off;
148 break;
115 case sel_3_oct_top: 149 case sel_3_oct_top:
116 g_midi_three_octave_split_2 += off; 150 g_midi_three_octave_split_2 += off;
117 if (g_midi_three_octave_split_2<0) g_midi_three_octave_split_2 = 0; 151 if (g_midi_three_octave_split_2<0) g_midi_three_octave_split_2 = 0;