From 0ab1e4878f9e2b592032dc7c67ae8018293058f6 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 9 Apr 2017 22:07:54 +0200 Subject: Extend short lines, if min and max is manually edited --- engine.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file 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); void engine_redraw() { + const char *config_hints[] = { "No", "Harfe", "File", "Edit" }; char text[32]; - char *config_hints[] = { "No", "Harfe", "File", "Edit" }; - int i, MAX_X, MAX_Y, FONT_HEIGHT; - int height = g_max_y - g_min_y; + const int tos1 = g_midi_three_octave_split_1, tos2 = g_midi_three_octave_split_2; + const int height = g_max_y - g_min_y; + int i, x2, MAX_X, MAX_Y, FONT_HEIGHT; display_redraw(); display_clear(); @@ -36,7 +37,6 @@ engine_redraw() if (height) { int b = g_midi_three_octave_split_inverse; - int tos1 = g_midi_three_octave_split_1, tos2 = g_midi_three_octave_split_2; display_text( b ? "+1" : "-1", 4, scale(g_min_y + tos1 * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff); display_text( " 0", 4, scale(g_min_y + (tos1 + tos2) * height / 200) + FONT_HEIGHT / 2, 0x007f7f7fff); 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() display_line_color(0, scale(g_min_y + tos1 * height / 100), MAX_X, scale(g_min_y + tos1 * height / 100), 0x00ff00ff); display_line_color(0, scale(g_min_y + tos2 * height / 100), MAX_X, scale(g_min_y + tos2 * height / 100), 0x00ff00ff); - switch (g_selected_config) { case sel_min_y: highlight_line(g_min_y, g_min_y, MAX_X, 0xff00ffff); break; case sel_max_y: highlight_line(g_max_y, g_max_y, MAX_X, 0xff00ffff); break; @@ -61,17 +60,28 @@ engine_redraw() for (i = 0; i < g_string_count; ++i) { LLine *l = &g_string_conf[i].line; + LLine _l = g_string_conf[i].line; // Copy for extension uint32_t color = ( ( i == g_selected_string ) ? 0xff00ffff : 0x00ffffffff ); uint32_t text_color = ( ( i == g_selected_string ) ? 0xff00ffff : 0x007f7f7fff ); + int extended = 0, center_y = g_min_y+height/2; - int center_y = g_min_y+height/2; - int x2 = l->p1.x; - - if (l->p1.x!=l->p0.x) { - double m = (double)(l->p1.y-l->p0.y) / (double)(l->p1.x-l->p0.x); - double _x2 = ((double)center_y) - (double)l->p0.y + m * (double)l->p0.x; - x2 = (int)(_x2/m); + if (_l.p0.y > g_min_y) { + _l.p0.x = get_x_for_y(&_l.p0, &_l.p1, g_min_y); + _l.p0.y = g_min_y; + extended = 1; + } + if (_l.p1.y < g_max_y) { + _l.p1.x = get_x_for_y(&l->p0 /* Using unmodified original! */, &_l.p1, g_max_y); + _l.p1.y = g_max_y; + extended = 1; } + if (extended) { + display_line_color(scale(_l.p0.x), scale(_l.p0.y), scale(_l.p1.x), scale(_l.p1.y), 0x007f3f00); + display_circle_color(scale(_l.p0.x), scale(_l.p0.y), 4, 0x007f3f00); + display_circle_color(scale(_l.p1.x), scale(_l.p1.y), 4, 0x007f3f00); + } + + x2 = get_x_for_y(&l->p0,&l->p1,center_y); if (g_string_conf[i].playing) 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) { display_line_color(max_x, scale(y+10), max_x-10, scale(y), color); display_rect_color(max_x/2-40, scale(y+20), 80, 40, 0xffffffff); + snprintf(text, sizeof(text), "%d", value); display_text(text, max_x/2-20, scale(y+20), 0); } void engine_select_config(ConfigSelect sel) { + // test if we have moved g_min_y or g_max_y and resize lines accordingly + if (sel == sel_none) { + int i; + for (i=0; ip0.y > g_min_y) { + l->p0.x = get_x_for_y(&l->p0, &l->p1, g_min_y); + l->p0.y = g_min_y; + } + if (l->p1.y < g_max_y) { + l->p1.x = get_x_for_y(&_l.p0 /* Using unmodified original! */, &l->p1, g_max_y); + l->p1.y = g_max_y; + } + } + } g_selected_config = sel; } @@ -112,6 +140,12 @@ ConfigSelect engine_change_selected(int off) { switch(g_selected_config) { + case sel_min_y: + g_min_y += off; + break; + case sel_max_y: + g_max_y += off; + break; case sel_3_oct_top: g_midi_three_octave_split_2 += off; if (g_midi_three_octave_split_2<0) g_midi_three_octave_split_2 = 0; -- cgit v1.2.3