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 uint8_t *first_visible
,
35 badge_framebuffer fb
= { { { 0 } } };
37 bool arrow_down
= true;
39 uint8_t first_used_row
= 0;
40 uint8_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(*first_visible
+ MENU_ENTRIES_VISIBLE
> n
) {
51 *first_visible
= n
- MENU_ENTRIES_VISIBLE
;
52 } else if(selected
+ 1 == n
) {
53 *first_visible
= n
- MENU_ENTRIES_VISIBLE
;
54 } else if(selected
<= *first_visible
) {
55 *first_visible
= selected
== 0 ? 0 : selected
- 1;
56 } else if(selected
- *first_visible
+ 2 > MENU_ENTRIES_VISIBLE
) {
57 *first_visible
= selected
- MENU_ENTRIES_VISIBLE
+ 2;
60 if(*first_visible
== 0) {
64 if(*first_visible
+ MENU_ENTRIES_VISIBLE
>= n
) {
68 for(uint8_t i
= 0; i
< used_rows
; ++i
) {
69 badge_framebuffer_render_text(&fb
,
70 (int8_t) (MENU_MARGIN_LEFT
+ BADGE_FONT_WIDTH
),
71 (int8_t) (MENU_MARGIN_TOP
+ (first_used_row
+ i
) * MENU_ENTRIES_HEIGHT
),
72 menu
[*first_visible
+ i
]);
75 badge_framebuffer_render_char(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
+ MENU_ENTRIES_HEIGHT
* (selected
- *first_visible
+ first_used_row
), selector
);
76 if(arrow_up
) { badge_framebuffer_blt(&fb
, MENU_MARGIN_LEFT
, MENU_MARGIN_TOP
, &arrows
[MENU_ARROW_UP
], 0); }
77 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); }
79 badge_framebuffer_flush(&fb
);
82 uint8_t badge_menu(char const *const *menu
,
84 uint8_t *first_visible
,
87 unsigned scroll_ticks
= 0;
88 int scroll_direction
= 0;
91 if(scroll_ticks
== 0) {
92 if (scroll_direction
== 1 && selected
+ 1 < n
) {
94 } else if(scroll_direction
== -1 && selected
!= 0) {
98 badge_menu_show(menu
, n
, first_visible
, selected
, '*');
100 scroll_ticks
= MENU_SCROLL_TICKS
;
105 ev
= badge_event_wait();
106 switch(badge_event_type(ev
)) {
107 case BADGE_EVENT_USER_INPUT
:
109 uint8_t old_state
= badge_event_old_input_state(ev
);
110 uint8_t new_state
= badge_event_new_input_state(ev
);
111 uint8_t new_buttons
= new_state
& (old_state
^ new_state
);
113 if(new_buttons
& (BADGE_EVENT_KEY_BTN_A
| BADGE_EVENT_KEY_BTN_B
)) {
115 } else if((new_buttons
& BADGE_EVENT_KEY_UP
)) {
116 scroll_direction
= -1;
117 } else if((new_buttons
& BADGE_EVENT_KEY_DOWN
)) {
118 scroll_direction
= 1;
120 scroll_direction
= 0;
126 case BADGE_EVENT_GAME_TICK
:
135 void badge_scroll_text(char const *const *lines
, uint8_t n
) {
136 uint8_t first_visible
= 0;
137 int scroll_direction
= 0;
138 unsigned scroll_ticks
= 0;
141 if(scroll_ticks
== 0) {
142 if (scroll_direction
== 1 && first_visible
+ MENU_ENTRIES_VISIBLE
< n
) {
144 } else if(scroll_direction
== -1 && first_visible
!= 0) {
148 badge_menu_show(lines
, n
, &first_visible
, first_visible
+ (first_visible
+ 1 == n
? 0 : 1), ' ');
150 scroll_ticks
= MENU_SCROLL_TICKS
;
155 ev
= badge_event_wait();
156 switch(badge_event_type(ev
)) {
157 case BADGE_EVENT_USER_INPUT
:
159 uint8_t old_state
= badge_event_old_input_state(ev
);
160 uint8_t new_state
= badge_event_new_input_state(ev
);
161 uint8_t new_buttons
= new_state
& (old_state
^ new_state
);
163 if(new_buttons
& (BADGE_EVENT_KEY_BTN_A
| BADGE_EVENT_KEY_BTN_B
)) {
165 } else if((new_buttons
& BADGE_EVENT_KEY_UP
)) {
166 scroll_direction
= -1;
167 } else if((new_buttons
& BADGE_EVENT_KEY_DOWN
)) {
168 scroll_direction
= 1;
170 scroll_direction
= 0;
176 case BADGE_EVENT_GAME_TICK
:
This page took 0.052057 seconds and 5 git commands to generate.