mirror of
https://github.com/Valeh2012/PersonalVotingMachine
synced 2025-12-08 18:15:11 +02:00
first commit
This commit is contained in:
12
basic-setup/components/u8g2/sys/sdl/text_strwidth/Makefile
Normal file
12
basic-setup/components/u8g2/sys/sdl/text_strwidth/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
CFLAGS = -g -Wall -I../../../csrc/. `sdl2-config --cflags`
|
||||
|
||||
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
helloworld: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) `sdl2-config --libs` -o u8g2_sdl
|
||||
|
||||
clean:
|
||||
-rm $(OBJ) u8g2_sdl
|
||||
|
||||
80
basic-setup/components/u8g2/sys/sdl/text_strwidth/main.c
Normal file
80
basic-setup/components/u8g2/sys/sdl/text_strwidth/main.c
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <stdio.h>
|
||||
|
||||
u8g2_t u8g2;
|
||||
|
||||
void draw(int x, int y)
|
||||
{
|
||||
char *list[] = {"|", ">", "-|", "lazydog|", "lazydog!", "lazy|dog"};
|
||||
u8g2_uint_t fh, w;
|
||||
u8g2_DrawLine(&u8g2, 120, 0, 120, 63);
|
||||
|
||||
u8g2_SetFont(&u8g2, u8g2_font_6x10_tr);
|
||||
//u8g2_SetFont(&u8g2, u8g2_font_helvB08_tf);
|
||||
u8g2_SetFontPosTop(&u8g2);
|
||||
fh = u8g2_GetFontAscent(&u8g2) - u8g2_GetFontDescent(&u8g2);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < sizeof(list)/sizeof(char*); i++) {
|
||||
w = u8g2_GetStrWidth(&u8g2, list[i]);
|
||||
u8g2_DrawStr(&u8g2, 120 - w, fh * i, list[i]);
|
||||
//u8g2.setCursor(0,fh * i);
|
||||
//u8g2.print(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int x, y;
|
||||
int k;
|
||||
|
||||
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_tr);
|
||||
u8g2_SetFont(&u8g2, u8g2_font_helvB18_tf);
|
||||
|
||||
x = 50;
|
||||
y = 30;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
|
||||
u8g2_FirstPage(&u8g2);
|
||||
do
|
||||
{
|
||||
draw(x,y);
|
||||
/*
|
||||
u8g2_SetFontDirection(&u8g2, 0);
|
||||
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
|
||||
u8g2_SetFontDirection(&u8g2, 1);
|
||||
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
|
||||
u8g2_SetFontDirection(&u8g2, 2);
|
||||
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
|
||||
u8g2_SetFontDirection(&u8g2, 3);
|
||||
u8g2_DrawUTF8(&u8g2, x, y, "WAV");
|
||||
*/
|
||||
} while( u8g2_NextPage(&u8g2) );
|
||||
|
||||
do
|
||||
{
|
||||
k = u8g_sdl_get_key();
|
||||
} while( k < 0 );
|
||||
|
||||
if ( k == 273 ) y -= 7;
|
||||
if ( k == 274 ) y += 7;
|
||||
if ( k == 276 ) x -= 7;
|
||||
if ( k == 275 ) x += 7;
|
||||
|
||||
if ( k == 'e' ) y -= 1;
|
||||
if ( k == 'x' ) y += 1;
|
||||
if ( k == 's' ) x -= 1;
|
||||
if ( k == 'd' ) x += 1;
|
||||
if ( k == 'q' ) break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user