Add civic font

This commit is contained in:
2026-05-16 15:34:49 -04:00
parent 07289358ca
commit f42eaa7cac
16 changed files with 1444 additions and 28 deletions
+95 -27
View File
@@ -1,11 +1,13 @@
#include "palette_manip.h"
#include <pebble.h>
// window statics
static Window *s_main_window;
static TextLayer *s_time_mg_layer;
static TextLayer *s_time_layer;
// static GFont s_civic_font;
static const GRect s_time_grect = GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT);
static BitmapLayer *s_time_mg_layers[4];
static BitmapLayer *s_time_fg_layers[4];
static const uint8_t s_x_r = (PBL_DISPLAY_WIDTH / 2) + 2;
static const uint8_t s_x_l = (s_x_r - 2 * (69 / 2)) - 5;
static const GRect s_time_grects[4] = {GRect(s_x_l, 2, 69, 110), GRect(s_x_r, 2, 69, 110), GRect(s_x_l, 116, 69, 110), GRect(s_x_r, 116, 69, 110)};
// persist statics&defines
static GColor8 s_led_color;
@@ -17,6 +19,9 @@ static GColor8 s_fg_color;
#define storage_key_mg_color 2
#define storage_key_fg_color 3
// font
static GBitmap *s_font_bitmaps[10];
static void main_window_load() {
Layer *window_layer = window_get_root_layer(s_main_window);
@@ -33,36 +38,71 @@ static void main_window_load() {
}
if (persist_exists(storage_key_mg_color)) {
s_time_mg_layer = text_layer_create(s_time_grect);
text_layer_set_background_color(s_time_mg_layer, GColorClear);
text_layer_set_text_color(s_time_mg_layer, (GColor8){.argb = persist_read_int(storage_key_mg_color)});
// text_layer_set_font(s_time_mg_layer, s_civic_font);
text_layer_set_text_alignment(s_time_mg_layer, GTextAlignmentCenter);
text_layer_set_text(s_time_mg_layer, "88\n88");
layer_add_child(window_layer, text_layer_get_layer(s_time_mg_layer));
s_time_mg_layers[0] = bitmap_layer_create(s_time_grects[0]);
s_time_mg_layers[1] = bitmap_layer_create(s_time_grects[1]);
s_time_mg_layers[2] = bitmap_layer_create(s_time_grects[2]);
s_time_mg_layers[3] = bitmap_layer_create(s_time_grects[3]);
bitmap_layer_set_compositing_mode(s_time_mg_layers[0], GCompOpSet);
bitmap_layer_set_compositing_mode(s_time_mg_layers[1], GCompOpSet);
bitmap_layer_set_compositing_mode(s_time_mg_layers[2], GCompOpSet);
bitmap_layer_set_compositing_mode(s_time_mg_layers[3], GCompOpSet);
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_mg_layers[0]));
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_mg_layers[1]));
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_mg_layers[2]));
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_mg_layers[3]));
}
if (persist_exists(storage_key_fg_color)) {
text_layer_set_text_color(s_time_layer, (GColor8){.argb = persist_read_int(storage_key_fg_color)});
} else {
text_layer_set_text_color(s_time_layer, GColorWhite);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[0], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[1], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[2], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[3], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[4], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[5], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[6], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[7], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[8], NULL);
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[9], NULL);
}
layer_add_child(window_layer, text_layer_get_layer(s_time_layer));
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_fg_layers[0]));
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_fg_layers[1]));
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_fg_layers[2]));
layer_add_child(window_layer, bitmap_layer_get_layer(s_time_fg_layers[3]));
}
static void main_window_unload() {
if (s_time_mg_layer) {
text_layer_destroy(s_time_mg_layer);
if (s_time_mg_layers[0]) {
bitmap_layer_destroy(s_time_mg_layers[0]);
bitmap_layer_destroy(s_time_mg_layers[1]);
bitmap_layer_destroy(s_time_mg_layers[2]);
bitmap_layer_destroy(s_time_mg_layers[3]);
}
}
static void update_minute_1() {
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
static char s_time_buffer[8];
strftime(s_time_buffer, sizeof(s_time_buffer), clock_is_24h_style() ? "%H\n%M" : "%I\n%M", tick_time);
text_layer_set_text(s_time_layer, s_time_buffer);
uint8_t hour = (uint8_t)tick_time->tm_hour;
if (!clock_is_24h_style()) {
hour = hour % 12;
if (hour == 0) {
hour = 12;
}
}
uint8_t minute = (uint8_t)tick_time->tm_min;
static uint8_t s_time_digits[4];
s_time_digits[0] = hour / 10;
s_time_digits[1] = hour % 10;
s_time_digits[2] = minute / 10;
s_time_digits[3] = minute % 10;
bitmap_layer_set_bitmap(s_time_fg_layers[0], s_font_bitmaps[s_time_digits[0]]);
bitmap_layer_set_bitmap(s_time_fg_layers[1], s_font_bitmaps[s_time_digits[1]]);
bitmap_layer_set_bitmap(s_time_fg_layers[2], s_font_bitmaps[s_time_digits[2]]);
bitmap_layer_set_bitmap(s_time_fg_layers[3], s_font_bitmaps[s_time_digits[3]]);
}
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
@@ -82,11 +122,27 @@ static void soft_reload(bool first_load) {
}
static void init() {
// s_civic_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_CIVIC_FONT_100));
s_time_layer = text_layer_create(s_time_grect);
text_layer_set_background_color(s_time_layer, GColorClear);
// text_layer_set_font(s_time_layer, s_civic_font);
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
// initialize font array
s_font_bitmaps[0] = gbitmap_create_with_resource(RESOURCE_ID_0);
s_font_bitmaps[1] = gbitmap_create_with_resource(RESOURCE_ID_1);
s_font_bitmaps[2] = gbitmap_create_with_resource(RESOURCE_ID_2);
s_font_bitmaps[3] = gbitmap_create_with_resource(RESOURCE_ID_3);
s_font_bitmaps[4] = gbitmap_create_with_resource(RESOURCE_ID_4);
s_font_bitmaps[5] = gbitmap_create_with_resource(RESOURCE_ID_5);
s_font_bitmaps[6] = gbitmap_create_with_resource(RESOURCE_ID_6);
s_font_bitmaps[7] = gbitmap_create_with_resource(RESOURCE_ID_7);
s_font_bitmaps[8] = gbitmap_create_with_resource(RESOURCE_ID_8);
s_font_bitmaps[9] = gbitmap_create_with_resource(RESOURCE_ID_9);
// do everything else
s_time_fg_layers[0] = bitmap_layer_create(s_time_grects[0]);
s_time_fg_layers[1] = bitmap_layer_create(s_time_grects[1]);
s_time_fg_layers[2] = bitmap_layer_create(s_time_grects[2]);
s_time_fg_layers[3] = bitmap_layer_create(s_time_grects[3]);
bitmap_layer_set_compositing_mode(s_time_fg_layers[0], GCompOpSet);
bitmap_layer_set_compositing_mode(s_time_fg_layers[1], GCompOpSet);
bitmap_layer_set_compositing_mode(s_time_fg_layers[2], GCompOpSet);
bitmap_layer_set_compositing_mode(s_time_fg_layers[3], GCompOpSet);
update_minute_1();
soft_reload(true);
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
@@ -94,8 +150,20 @@ static void init() {
static void deinit() {
tick_timer_service_unsubscribe();
// fonts_unload_custom_font(s_civic_font);
text_layer_destroy(s_time_layer);
bitmap_layer_destroy(s_time_fg_layers[0]);
bitmap_layer_destroy(s_time_fg_layers[1]);
bitmap_layer_destroy(s_time_fg_layers[2]);
bitmap_layer_destroy(s_time_fg_layers[3]);
gbitmap_destroy(s_font_bitmaps[0]);
gbitmap_destroy(s_font_bitmaps[1]);
gbitmap_destroy(s_font_bitmaps[2]);
gbitmap_destroy(s_font_bitmaps[3]);
gbitmap_destroy(s_font_bitmaps[4]);
gbitmap_destroy(s_font_bitmaps[5]);
gbitmap_destroy(s_font_bitmaps[6]);
gbitmap_destroy(s_font_bitmaps[7]);
gbitmap_destroy(s_font_bitmaps[8]);
gbitmap_destroy(s_font_bitmaps[9]);
window_destroy(s_main_window);
}