From ec5c1ad9f16772434f0f49811c87ec58a3569e83 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 23 Apr 2023 18:48:32 +0200 Subject: Add conditional redrawing This covers most of the previous functionality, but separating the input handling and rendering functions. Only cursor drawing and a few corner cases missing. --- src/main.c | 64 +++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 19 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 8ee4945..b6be6b9 100644 --- a/src/main.c +++ b/src/main.c @@ -21,27 +21,53 @@ WITH REGARD TO THIS SOFTWARE. void render(void) { - // TODO: Make sure we are drawing the proper cursor color. // TODO: Decouple update from rendering. - PROF(screen_fill(0), clear_cycles); + // PROF(screen_fill(0), clear_cycles); PROF(draw_rect(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1), clear_cycles); - PROF(draw_triggers(), draw_trigs_cycles); - PROF(draw_channels(), draw_btn_cycles); - PROF(draw_pattern_buttons(), draw_btn_cycles); - PROF(draw_bank_buttons(), draw_btn_cycles); - PROF(draw_bpm(), draw_btn_cycles); - PROF(draw_play(), draw_btn_cycles); - PROF(draw_stop(), draw_btn_cycles); - PROF(draw_piano(), draw_piano_cycles); - // TODO: Draw the notes currently playing with a fade off animation for the - // first 3 channels. - TriggerNote *trig = get_current_trig(); - PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles); - PROF(draw_parameters(), draw_param_cycles); - PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles); - PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles); - PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles); - PROF(draw_current_step(COL_RED), draw_cursor_cycles); + if (redraw_trigs) { + PROF(draw_triggers(), draw_trigs_cycles); + redraw_trigs = false; + } + if (redraw_channels) { + PROF(draw_channels(), draw_btn_cycles); + redraw_channels = false; + } + if (redraw_pattern_buttons) { + PROF(draw_pattern_buttons(), draw_btn_cycles); + redraw_pattern_buttons = false; + } + if (redraw_bank_buttons) { + PROF(draw_bank_buttons(), draw_btn_cycles); + redraw_bank_buttons = false; + } + if (redraw_bpm) { + PROF(draw_bpm(), draw_btn_cycles); + redraw_bpm = false; + } + if (redraw_play_pause) { + PROF(draw_play(), draw_btn_cycles); + PROF(draw_stop(), draw_btn_cycles); + redraw_play_pause = false; + } + if (redraw_piano_note) { + PROF(draw_piano(), draw_piano_cycles); + // TODO: Draw the notes currently playing with a fade off animation for + // the first 3 channels. + TriggerNote *trig = get_current_trig(); + PROF(draw_note(trig->note, COL_NOTE_PRESSED), draw_piano_cycles); + redraw_piano_note = false; + } + if (redraw_params) { + PROF(draw_parameters(), draw_param_cycles); + redraw_params = false; + } + + // TODO: Make sure we are drawing the cursors properly. + // PROF(draw_trig_cursor(trig_selection_loc, COL_CURSOR), draw_cursor_cycles); + // PROF(draw_channel_cursor(channel_selection_loc, COL_GREY), draw_cursor_cycles); + // PROF(draw_pattern_cursor(pattern_selection_loc, COL_GREY), draw_cursor_cycles); + + // PROF(draw_current_step(COL_RED), draw_cursor_cycles); } int -- cgit v1.2.1