13 MENU_SCROLL_TICKS
= 25
16 static badge_sprite
const arrows
[] = {
17 { 5, 7, (uint8_t const *) "\x04\xc3\xdf\x40" },
18 { 5, 7, (uint8_t const *) "\x10\xd8\x1f\x06\x01" }
23 MENU_MARGIN_BOTTOM
= 2,
25 MENU_ENTRIES_HEIGHT
= 1 + BADGE_FONT_HEIGHT
,
26 MENU_ENTRIES_VISIBLE
= (BADGE_DISPLAY_HEIGHT
- MENU_MARGIN_TOP
- MENU_MARGIN_BOTTOM
) / MENU_ENTRIES_HEIGHT
29 static void badge_menu_show(char const *const *menu
,
31 size_t *first_visible
,
35 badge_framebuffer fb
= { { { 0 } } };
37 bool arrow_down
= true;
39 size_t first_used_row
= 0;
40 size_t used_rows
= MENU_ENTRIES_VISIBLE
;
46 if(n
<= MENU_ENTRIES_VISIBLE
) {
49 first_used_row
= (MENU_ENTRIES_VISIBLE
- used_rows
) / 2;
50 } else if(selected
+ 1 == n
) {
51 *first_visible
= n
- MENU_ENTRIES_VISIBLE
;
52 } else if(selected
<= *first_visible
) {
53 *first_visible
= selected
== 0 ? 0 : selected
- 1;
54 } else if(selected
- *first_visible
+ 2 > MENU_ENTRIES_VISIBLE
) {
55 *first_visible
= selected
- MENU_ENTRIES_VISIBLE
+ 2;
58 if(*first_visible
== 0) {
62 if(*first_visible
+ MENU_ENTRIES_VISIBLE
>= n
) {
66 for(size_t i
= 0; i
< used_rows
; ++i
) {
67 badge_framebuffer_render_text(&fb
,
68 (int8_t) (MENU_MARGIN_LEFT
+ BADGE_FONT_WIDTH
),
69 (int8_t) (MENU_MARGIN_TOP
+ (first_used_row
+ i
) * MENU_ENTRIES_HEIGHT
),
70 menu
[*first_visible
+ i
]);
73 badge_framebuffer_render_char(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
+ MENU_ENTRIES_HEIGHT
* (selected
- *first_visible
+ first_used_row
), selector
);
74 if(arrow_up
) { badge_framebuffer_blt(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
, &arrows
[MENU_ARROW_UP
], 0); }
75 if(arrow_down
) { badge_framebuffer_blt(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
+ (MENU_ENTRIES_VISIBLE
- 1) * MENU_ENTRIES_HEIGHT
, &arrows
[MENU_ARROW_DOWN
], 0); }
77 badge_framebuffer_flush(&fb
);
80 size_t badge_menu(char const *const *menu
,
82 size_t *first_visible
,
85 unsigned scroll_ticks
= 0;
86 int scroll_direction
= 0;
89 if(scroll_ticks
== 0) {
90 if (scroll_direction
== 1 && selected
+ 1 < n
) {
92 } else if(scroll_direction
== -1 && selected
!= 0) {
96 badge_menu_show(menu
, n
, first_visible
, selected
, '*');
98 scroll_ticks
= MENU_SCROLL_TICKS
;
103 ev
= badge_event_wait();
104 switch(badge_event_type(ev
)) {
105 case BADGE_EVENT_USER_INPUT
:
107 uint8_t old_state
= badge_event_old_input_state(ev
);
108 uint8_t new_state
= badge_event_new_input_state(ev
);
109 uint8_t new_buttons
= new_state
& (old_state
^ new_state
);
111 if(new_buttons
& (BADGE_EVENT_KEY_BTN_A
| BADGE_EVENT_KEY_BTN_B
)) {
113 } else if((new_buttons
& BADGE_EVENT_KEY_UP
)) {
114 scroll_direction
= -1;
115 } else if((new_buttons
& BADGE_EVENT_KEY_DOWN
)) {
116 scroll_direction
= 1;
118 scroll_direction
= 0;
124 case BADGE_EVENT_GAME_TICK
:
133 void badge_scroll_text(char const *const *lines
, size_t n
) {
134 size_t first_visible
= 0;
135 int scroll_direction
= 0;
136 unsigned scroll_ticks
= 0;
139 if(scroll_ticks
== 0) {
140 if (scroll_direction
== 1 && first_visible
+ MENU_ENTRIES_VISIBLE
< n
) {
142 } else if(scroll_direction
== -1 && first_visible
!= 0) {
146 badge_menu_show(lines
, n
, &first_visible
, first_visible
+ (first_visible
+ 1 == n
? 0 : 1), ' ');
148 scroll_ticks
= MENU_SCROLL_TICKS
;
153 ev
= badge_event_wait();
154 switch(badge_event_type(ev
)) {
155 case BADGE_EVENT_USER_INPUT
:
157 uint8_t old_state
= badge_event_old_input_state(ev
);
158 uint8_t new_state
= badge_event_new_input_state(ev
);
159 uint8_t new_buttons
= new_state
& (old_state
^ new_state
);
161 if(new_buttons
& (BADGE_EVENT_KEY_BTN_A
| BADGE_EVENT_KEY_BTN_B
)) {
163 } else if((new_buttons
& BADGE_EVENT_KEY_UP
)) {
164 scroll_direction
= -1;
165 } else if((new_buttons
& BADGE_EVENT_KEY_DOWN
)) {
166 scroll_direction
= 1;
168 scroll_direction
= 0;
174 case BADGE_EVENT_GAME_TICK
:
This page took 0.061865 seconds and 5 git commands to generate.