Skip to content

Instantly share code, notes, and snippets.

@dogtopus
Created March 5, 2023 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogtopus/12dbf284a2922616d659daa8c5a5def3 to your computer and use it in GitHub Desktop.
Save dogtopus/12dbf284a2922616d659daa8c5a5def3 to your computer and use it in GitHub Desktop.
Besta RTOS font rendering API test
#include <stdbool.h>
#include <muteki/common.h>
#include <muteki/ui/canvas.h>
#include <muteki/ui/event.h>
const UTF16 i_can_eat_glass_w[] = u"我能吞下玻璃而不伤身体。";
void redraw(int font_type) {
ClearScreen(0);
rgbSetColor(0x0);
int height = GetFontHeight(font_type);
SetFontType(font_type);
PrintfXY(3, 3, "Font %ld h=%d", font_type, height);
WriteString(3, 3 + height, u"The quick brown fox", false);
WriteString(3, 3 + height * 2, u"jumps over the lazy dog.", false);
WriteString(3, 3 + height * 3, i_can_eat_glass_w, false);
}
int main(void) {
ui_event_t uievent = {0};
int font_type = 0;
bool need_redraw = true;
bool need_exit = false;
rgbSetBkColor(0xffffff);
rgbSetColor(0x0);
while (true) {
if ((TestPendEvent(&uievent) || TestKeyEvent(&uievent)) && GetEvent(&uievent)) {
switch (uievent.key_code0) {
case KEY_LEFT:
case KEY_UP:
case KEY_PGUP:
font_type--;
need_redraw = true;
break;
case KEY_RIGHT:
case KEY_DOWN:
case KEY_PGDN:
font_type++;
need_redraw = true;
break;
case KEY_ESC:
need_exit = true;
break;
default:
break;
}
}
if (need_exit) {
break;
}
if (need_redraw) {
redraw(font_type);
need_redraw = false;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment