diff options
Diffstat (limited to 'keyboards/lily58/keymaps/druotoni/layer_frame.c')
| -rw-r--r-- | keyboards/lily58/keymaps/druotoni/layer_frame.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/keyboards/lily58/keymaps/druotoni/layer_frame.c b/keyboards/lily58/keymaps/druotoni/layer_frame.c new file mode 100644 index 000000000..6f7ae1a25 --- /dev/null +++ b/keyboards/lily58/keymaps/druotoni/layer_frame.c | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | // Copyright 2021 Nicolas Druoton (druotoni) | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include QMK_KEYBOARD_H | ||
| 5 | |||
| 6 | #include "gui_state.h" | ||
| 7 | #include "layer_frame.h" | ||
| 8 | #include "draw_helper.h" | ||
| 9 | |||
| 10 | #define ANIM_LAYER_FRAME_DURATION 2 | ||
| 11 | #define ANIM_LAYER_FRAME_MAX 7 | ||
| 12 | |||
| 13 | // current layer | ||
| 14 | uint8_t current_layer = _QWERTY; | ||
| 15 | |||
| 16 | // layer animation stuff | ||
| 17 | uint16_t anim_layer_frame_timer = 0; | ||
| 18 | uint8_t current_layer_frame = ANIM_LAYER_FRAME_MAX; | ||
| 19 | uint8_t layer_frame_destination = ANIM_LAYER_FRAME_MAX; | ||
| 20 | |||
| 21 | // layer name for display | ||
| 22 | const char* layer_name; | ||
| 23 | static const char* layer_ref[3] = {LAYER_NAME_0, LAYER_NAME_1, LAYER_NAME_2}; | ||
| 24 | |||
| 25 | void update_layer_frame(layer_state_t state) { | ||
| 26 | // reset timer | ||
| 27 | anim_layer_frame_timer = timer_read(); | ||
| 28 | |||
| 29 | // direction for animation base on layer selected | ||
| 30 | current_layer = get_highest_layer(state); | ||
| 31 | if (current_layer == _QWERTY) { | ||
| 32 | layer_frame_destination = 0; | ||
| 33 | } else { | ||
| 34 | layer_frame_destination = ANIM_LAYER_FRAME_MAX; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | static void draw_black_screen(void) { | ||
| 39 | // clean frame center | ||
| 40 | draw_rectangle_fill(3, 42, 26, 20, false); | ||
| 41 | drawline_hr(17, 62, 12, false); | ||
| 42 | } | ||
| 43 | |||
| 44 | void render_gears(void) { | ||
| 45 | // 64 bytes, 8x8 font, 8 characters, 32x16 image, 4 columns, 2 rows | ||
| 46 | static const char PROGMEM raw_logo[] = { | ||
| 47 | 0, 6, 6, 54, 118, 96, 230, 192, 192, 128, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 18, 226, 2, 18, 226, 2, 18, 226, 2, 1, 0, 0, 0, 0, 0, 128, 128, 128, 185, 187, 187, 131, 128, 184, 128, 128, 128, 128, 128, 128, 128, 128, 128, 191, 128, 128, 191, 128, 128, 191, 128, 0, | ||
| 48 | }; | ||
| 49 | |||
| 50 | // extra line for complete the gui | ||
| 51 | oled_write_raw_P_cursor(0, 8, raw_logo, sizeof(raw_logo)); | ||
| 52 | } | ||
| 53 | |||
| 54 | void render_layer_frame(gui_state_t t) { | ||
| 55 | // 96 bytes, 8x8 font, 12 characters, 32x24 image, 4 columns, 3 rows | ||
| 56 | static const char PROGMEM raw_logo[] = { | ||
| 57 | 62, 1, 0, 56, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 124, 248, 241, 226, 4, 8, 240, 0, 28, 28, 28, 0, 0, 127, 4, 8, 16, 127, 0, 124, 18, 17, 18, 124, 0, 31, 32, 64, 32, 31, 0, 0, 0, 0, 255, 255, 0, 0, 255, 62, 64, 64, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 142, 30, 62, 126, 126, 70, 70, 126, 70, 70, 126, 70, 70, 127, 127, 0, 0, 255, | ||
| 58 | }; | ||
| 59 | oled_write_raw_P_cursor(0, 5, raw_logo, sizeof(raw_logo)); | ||
| 60 | |||
| 61 | // extra line for complete the gui | ||
| 62 | drawline_hr(2, 39, 25, 1); | ||
| 63 | |||
| 64 | if (current_layer_frame != layer_frame_destination) { | ||
| 65 | if (timer_elapsed(anim_layer_frame_timer) > ANIM_LAYER_FRAME_DURATION) { | ||
| 66 | anim_layer_frame_timer = timer_read(); | ||
| 67 | |||
| 68 | if (layer_frame_destination > current_layer_frame) { | ||
| 69 | current_layer_frame++; | ||
| 70 | } else { | ||
| 71 | current_layer_frame--; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | // black screen | ||
| 76 | draw_black_screen(); | ||
| 77 | |||
| 78 | // gradient animation on layer selection | ||
| 79 | draw_gradient(3, 42, current_layer_frame * 4, 10, 0, 255, 7); | ||
| 80 | draw_gradient(3 + (27 - current_layer_frame * 4), 57, current_layer_frame * 4, 6, 255, 0, 7); | ||
| 81 | |||
| 82 | drawline_hr(3, 46, 22, false); | ||
| 83 | drawline_hr(3, 47, 23, false); | ||
| 84 | |||
| 85 | draw_rectangle_fill(3, 55, 24, 2, false); | ||
| 86 | draw_rectangle_fill(24, 48, 3, 7, false); | ||
| 87 | |||
| 88 | draw_rectangle_fill(3, 60, 12, 2, false); | ||
| 89 | oled_write_pixel(15, 61, false); | ||
| 90 | drawline_hr(14, 62, 3, false); | ||
| 91 | drawline_hr(14, 62, 3, false); | ||
| 92 | drawline_hr(3, 62, 11, true); | ||
| 93 | } | ||
| 94 | |||
| 95 | // get current layer name | ||
| 96 | layer_name = layer_ref[current_layer]; | ||
| 97 | |||
| 98 | // gui on pause : no layer name on screen | ||
| 99 | if (t == _IDLE || t == _SLEEP || t == _WAKINGUP) { | ||
| 100 | layer_name = " "; | ||
| 101 | } | ||
| 102 | |||
| 103 | // display layer name in the frame | ||
| 104 | oled_write_cursor(1, 6, layer_name, false); | ||
| 105 | } | ||
