Use rotated authentic C64 bitmap font
This commit is contained in:
+82
-4
@@ -1,6 +1,84 @@
|
||||
#include "c64_ui.h"
|
||||
#include <lvgl.h>
|
||||
#define C64_BLUE lv_color_make(64,49,141)
|
||||
#define C64_LIGHT_BLUE lv_color_make(120,105,196)
|
||||
static void cursor_blink(void*o,int32_t v){lv_obj_set_style_opa((lv_obj_t*)o,v?LV_OPA_COVER:LV_OPA_TRANSP,LV_PART_MAIN);}
|
||||
void c64_ui_create(void){lv_obj_t*s=lv_scr_act();lv_obj_set_style_bg_color(s,C64_BLUE,LV_PART_MAIN);lv_obj_set_style_bg_opa(s,LV_OPA_COVER,LV_PART_MAIN);lv_obj_clear_flag(s,LV_OBJ_FLAG_SCROLLABLE);lv_obj_t*r=lv_label_create(s);lv_label_set_text(r,"READY.");lv_obj_set_style_text_color(r,C64_LIGHT_BLUE,LV_PART_MAIN);lv_obj_set_style_text_font(r,&lv_font_montserrat_48,LV_PART_MAIN);lv_obj_align(r,LV_ALIGN_TOP_LEFT,12,44);lv_obj_t*c=lv_obj_create(s);lv_obj_remove_style_all(c);lv_obj_set_size(c,29,8);lv_obj_set_style_bg_color(c,C64_LIGHT_BLUE,LV_PART_MAIN);lv_obj_set_style_bg_opa(c,LV_OPA_COVER,LV_PART_MAIN);lv_obj_align_to(c,r,LV_ALIGN_OUT_BOTTOM_LEFT,0,10);lv_anim_t a;lv_anim_init(&a);lv_anim_set_var(&a,c);lv_anim_set_values(&a,1,0);lv_anim_set_time(&a,500);lv_anim_set_playback_time(&a,500);lv_anim_set_repeat_count(&a,LV_ANIM_REPEAT_INFINITE);lv_anim_set_exec_cb(&a,cursor_blink);lv_anim_start(&a);}
|
||||
#include <stdint.h>
|
||||
|
||||
#define C64_BLUE lv_color_make(64, 49, 141)
|
||||
#define C64_LIGHT_BLUE lv_color_make(120, 105, 196)
|
||||
#define PIXEL_SCALE 6
|
||||
#define CELL_SIZE (8 * PIXEL_SCALE)
|
||||
|
||||
typedef struct {
|
||||
char character;
|
||||
uint8_t rows[8];
|
||||
} c64_glyph_t;
|
||||
|
||||
/* Exact uppercase/graphics glyph rows from the C64 system character ROM. */
|
||||
static const c64_glyph_t glyphs[] = {
|
||||
{'R', {0x7C, 0x66, 0x66, 0x7C, 0x78, 0x6C, 0x66, 0x00}},
|
||||
{'E', {0x7E, 0x60, 0x60, 0x78, 0x60, 0x60, 0x7E, 0x00}},
|
||||
{'A', {0x18, 0x3C, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00}},
|
||||
{'D', {0x78, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0x78, 0x00}},
|
||||
{'Y', {0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00}},
|
||||
{'.', {0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00}},
|
||||
};
|
||||
|
||||
static const uint8_t *find_glyph(char character) {
|
||||
for (unsigned i = 0; i < sizeof(glyphs) / sizeof(glyphs[0]); ++i) {
|
||||
if (glyphs[i].character == character) return glyphs[i].rows;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void draw_glyph(lv_obj_t *parent, char character, lv_coord_t x, lv_coord_t y) {
|
||||
const uint8_t *rows = find_glyph(character);
|
||||
if (!rows) return;
|
||||
|
||||
for (int row = 0; row < 8; ++row) {
|
||||
for (int column = 0; column < 8; ++column) {
|
||||
if ((rows[row] & (0x80 >> column)) == 0) continue;
|
||||
lv_obj_t *pixel = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(pixel);
|
||||
lv_obj_set_size(pixel, PIXEL_SCALE, PIXEL_SCALE);
|
||||
lv_obj_set_pos(pixel, x + column * PIXEL_SCALE, y + row * PIXEL_SCALE);
|
||||
lv_obj_set_style_bg_color(pixel, C64_LIGHT_BLUE, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(pixel, LV_OPA_COVER, LV_PART_MAIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cursor_blink(void *object, int32_t visible) {
|
||||
lv_obj_set_style_bg_opa((lv_obj_t *)object,
|
||||
visible ? LV_OPA_COVER : LV_OPA_TRANSP,
|
||||
LV_PART_MAIN);
|
||||
}
|
||||
|
||||
void c64_ui_create(void) {
|
||||
static const char text[] = "READY.";
|
||||
lv_obj_t *screen = lv_scr_act();
|
||||
lv_obj_set_style_bg_color(screen, C64_BLUE, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(screen, LV_OPA_COVER, LV_PART_MAIN);
|
||||
lv_obj_clear_flag(screen, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
const lv_coord_t start_x = 48;
|
||||
const lv_coord_t text_y = 24;
|
||||
for (unsigned i = 0; i < sizeof(text) - 1; ++i) {
|
||||
draw_glyph(screen, text[i], start_x + (lv_coord_t)i * CELL_SIZE, text_y);
|
||||
}
|
||||
|
||||
lv_obj_t *cursor = lv_obj_create(screen);
|
||||
lv_obj_remove_style_all(cursor);
|
||||
lv_obj_set_size(cursor, CELL_SIZE, CELL_SIZE);
|
||||
lv_obj_set_pos(cursor, start_x, text_y + CELL_SIZE + 16);
|
||||
lv_obj_set_style_bg_color(cursor, C64_LIGHT_BLUE, LV_PART_MAIN);
|
||||
lv_obj_set_style_bg_opa(cursor, LV_OPA_COVER, LV_PART_MAIN);
|
||||
|
||||
lv_anim_t blink;
|
||||
lv_anim_init(&blink);
|
||||
lv_anim_set_var(&blink, cursor);
|
||||
lv_anim_set_values(&blink, 1, 0);
|
||||
lv_anim_set_time(&blink, 900);
|
||||
lv_anim_set_playback_time(&blink, 900);
|
||||
lv_anim_set_repeat_count(&blink, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_set_exec_cb(&blink, cursor_blink);
|
||||
lv_anim_start(&blink);
|
||||
}
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@
|
||||
|
||||
#define USER_DISP_ROT_90 1
|
||||
#define USER_DISP_ROT_NONO 0
|
||||
#define Rotated USER_DISP_ROT_NONO //软件实现旋转
|
||||
#define Rotated USER_DISP_ROT_90 //软件实现旋转
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user