u8g2-copy/sys/sdl/menu/main.c

117 lines
2.3 KiB
C

#include "menu.h"
#include <stdio.h>
u8g2_t u8g2;
uint8_t h, mt, mo, st, so;
uint8_t d1, d2;
extern const me_t melist_top_menu[];
#define ME_TIME_Y 20
#define ME_TIME_XO 11
const me_t melist_setup_time[] =
{
{ me_cb_0_23, &h, NULL, ME_TIME_XO+2,ME_TIME_Y },
{ me_cb_num_label, NULL, ":", ME_TIME_XO+30,ME_TIME_Y-3 },
{ me_cb_0_5, &mt, NULL, ME_TIME_XO+39,ME_TIME_Y },
{ me_cb_0_9, &mo, NULL, ME_TIME_XO+52,ME_TIME_Y },
{ me_cb_num_label, NULL, ":", ME_TIME_XO+67,ME_TIME_Y-3 },
{ me_cb_0_5, &st, NULL, ME_TIME_XO+67+9,ME_TIME_Y },
{ me_cb_0_9, &so, NULL, ME_TIME_XO+80+9,ME_TIME_Y },
{ me_cb_text_line, (void *)melist_top_menu, "Speichern", 40,30 },
{ me_cb_null, NULL, NULL, 0, 0 },
};
const me_t melist_setup_alarm[] =
{
{ me_cb_str_toggle, &d1, "M", 10, 15},
{ me_cb_str_toggle, &d2, "D", 30, 15},
{ me_cb_null, NULL, NULL, 0, 0 },
};
const me_t melist_top_menu[] =
{
{ me_cb_text_line, NULL, "Zurück", 3,10 },
{ me_cb_text_line, NULL, "Alarm", 3,20 },
{ me_cb_text_line, NULL, "Einstellungen", 3,30 },
{ me_cb_null, NULL, 0, 0 },
};
menu_t menu;
int main(void)
{
int x, y;
int k;
int i;
u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
//u8g2_SetFont(&u8g2, u8g2_font_helvB18_tf);
u8g2_SetFont(&u8g2, u8g2_font_ncenR08_tf);
menu_Init(&menu, &u8g2);
menu_SetMEList(&menu, melist_top_menu, 0);
menu_SetMEList(&menu, melist_setup_time, 0);
menu_SetMEList(&menu, melist_setup_alarm, 0);
x = 50;
y = 50;
for(;;)
{
u8g2_FirstPage(&u8g2);
i = 0;
do
{
menu_Draw(&menu);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_SetFont(&u8g2, u8g2_font_ncenR08_tf);
u8g2_DrawStr(&u8g2, x, y, "-- 123");
i++;
} while( u8g2_NextPage(&u8g2) );
do
{
k = u8g_sdl_get_key();
} while( k < 0 );
if ( k == 'n' )
menu_NextFocus(&menu);
if ( k == 's' )
menu_Select(&menu);
if ( k == 273 ) y -= 1;
if ( k == 274 ) y += 1;
if ( k == 276 ) x -= 1;
if ( k == 275 ) x += 1;
if ( k == 'q' ) break;
}
//u8x8_Set8x8Font(u8g2_GetU8x8(&u8g2), bdf_font);
//u8x8_Draw8x8String(u8g2_GetU8x8(&u8g2), 0, 0, "Hello World!");
return 0;
}