Add civic font
@@ -29,7 +29,78 @@
|
|||||||
"CLAY_FG_COLOR"
|
"CLAY_FG_COLOR"
|
||||||
],
|
],
|
||||||
"resources": {
|
"resources": {
|
||||||
"media": []
|
"media": [
|
||||||
|
{
|
||||||
|
"file": "0.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "0",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "1.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "1",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "2.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "2",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "3.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "3",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "4.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "4",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "5.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "5",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "6.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "6",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "7.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "7",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "8.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "8",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "9.png",
|
||||||
|
"memoryFormat": "Smallest",
|
||||||
|
"name": "9",
|
||||||
|
"spaceOptimization": "storage",
|
||||||
|
"type": "bitmap"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
After Width: | Height: | Size: 543 B |
|
After Width: | Height: | Size: 436 B |
|
After Width: | Height: | Size: 547 B |
|
After Width: | Height: | Size: 532 B |
|
After Width: | Height: | Size: 510 B |
|
After Width: | Height: | Size: 530 B |
|
After Width: | Height: | Size: 545 B |
|
After Width: | Height: | Size: 482 B |
|
After Width: | Height: | Size: 542 B |
|
After Width: | Height: | Size: 535 B |
@@ -1,11 +1,13 @@
|
|||||||
|
#include "palette_manip.h"
|
||||||
#include <pebble.h>
|
#include <pebble.h>
|
||||||
|
|
||||||
// window statics
|
// window statics
|
||||||
static Window *s_main_window;
|
static Window *s_main_window;
|
||||||
static TextLayer *s_time_mg_layer;
|
static BitmapLayer *s_time_mg_layers[4];
|
||||||
static TextLayer *s_time_layer;
|
static BitmapLayer *s_time_fg_layers[4];
|
||||||
// static GFont s_civic_font;
|
static const uint8_t s_x_r = (PBL_DISPLAY_WIDTH / 2) + 2;
|
||||||
static const GRect s_time_grect = GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT);
|
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
|
// persist statics&defines
|
||||||
static GColor8 s_led_color;
|
static GColor8 s_led_color;
|
||||||
@@ -17,6 +19,9 @@ static GColor8 s_fg_color;
|
|||||||
#define storage_key_mg_color 2
|
#define storage_key_mg_color 2
|
||||||
#define storage_key_fg_color 3
|
#define storage_key_fg_color 3
|
||||||
|
|
||||||
|
// font
|
||||||
|
static GBitmap *s_font_bitmaps[10];
|
||||||
|
|
||||||
static void main_window_load() {
|
static void main_window_load() {
|
||||||
Layer *window_layer = window_get_root_layer(s_main_window);
|
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)) {
|
if (persist_exists(storage_key_mg_color)) {
|
||||||
s_time_mg_layer = text_layer_create(s_time_grect);
|
s_time_mg_layers[0] = bitmap_layer_create(s_time_grects[0]);
|
||||||
text_layer_set_background_color(s_time_mg_layer, GColorClear);
|
s_time_mg_layers[1] = bitmap_layer_create(s_time_grects[1]);
|
||||||
text_layer_set_text_color(s_time_mg_layer, (GColor8){.argb = persist_read_int(storage_key_mg_color)});
|
s_time_mg_layers[2] = bitmap_layer_create(s_time_grects[2]);
|
||||||
// text_layer_set_font(s_time_mg_layer, s_civic_font);
|
s_time_mg_layers[3] = bitmap_layer_create(s_time_grects[3]);
|
||||||
text_layer_set_text_alignment(s_time_mg_layer, GTextAlignmentCenter);
|
bitmap_layer_set_compositing_mode(s_time_mg_layers[0], GCompOpSet);
|
||||||
text_layer_set_text(s_time_mg_layer, "88\n88");
|
bitmap_layer_set_compositing_mode(s_time_mg_layers[1], GCompOpSet);
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_time_mg_layer));
|
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)) {
|
if (persist_exists(storage_key_fg_color)) {
|
||||||
text_layer_set_text_color(s_time_layer, (GColor8){.argb = persist_read_int(storage_key_fg_color)});
|
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[0], NULL);
|
||||||
} else {
|
replace_gbitmap_color(GColorWhite, (GColor8){.argb = persist_read_int(storage_key_fg_color)}, s_font_bitmaps[1], NULL);
|
||||||
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[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() {
|
static void main_window_unload() {
|
||||||
if (s_time_mg_layer) {
|
if (s_time_mg_layers[0]) {
|
||||||
text_layer_destroy(s_time_mg_layer);
|
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() {
|
static void update_minute_1() {
|
||||||
time_t temp = time(NULL);
|
time_t temp = time(NULL);
|
||||||
struct tm *tick_time = localtime(&temp);
|
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);
|
uint8_t hour = (uint8_t)tick_time->tm_hour;
|
||||||
text_layer_set_text(s_time_layer, s_time_buffer);
|
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) {
|
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() {
|
static void init() {
|
||||||
// s_civic_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_CIVIC_FONT_100));
|
// initialize font array
|
||||||
s_time_layer = text_layer_create(s_time_grect);
|
s_font_bitmaps[0] = gbitmap_create_with_resource(RESOURCE_ID_0);
|
||||||
text_layer_set_background_color(s_time_layer, GColorClear);
|
s_font_bitmaps[1] = gbitmap_create_with_resource(RESOURCE_ID_1);
|
||||||
// text_layer_set_font(s_time_layer, s_civic_font);
|
s_font_bitmaps[2] = gbitmap_create_with_resource(RESOURCE_ID_2);
|
||||||
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
|
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();
|
update_minute_1();
|
||||||
soft_reload(true);
|
soft_reload(true);
|
||||||
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
|
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
|
||||||
@@ -94,8 +150,20 @@ static void init() {
|
|||||||
|
|
||||||
static void deinit() {
|
static void deinit() {
|
||||||
tick_timer_service_unsubscribe();
|
tick_timer_service_unsubscribe();
|
||||||
// fonts_unload_custom_font(s_civic_font);
|
bitmap_layer_destroy(s_time_fg_layers[0]);
|
||||||
text_layer_destroy(s_time_layer);
|
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);
|
window_destroy(s_main_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// TAKEN FROM https://github.com/rebootsramblings/GBitmap-Colour-Palette-Manipulator
|
||||||
|
|
||||||
|
#include "palette_manip.h"
|
||||||
|
|
||||||
|
#ifdef PBL_COLOR
|
||||||
|
|
||||||
|
int get_num_palette_colors(GBitmap *b){
|
||||||
|
GBitmapFormat format = gbitmap_get_format(b);
|
||||||
|
switch (format) {
|
||||||
|
case GBitmapFormat1Bit: return 0;
|
||||||
|
case GBitmapFormat8Bit: return 0;
|
||||||
|
case GBitmapFormat1BitPalette: return 2;
|
||||||
|
case GBitmapFormat2BitPalette: return 4;
|
||||||
|
case GBitmapFormat4BitPalette: return 16;
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void replace_gbitmap_color(GColor color_to_replace, GColor replace_with_color, GBitmap *im, BitmapLayer *bml){
|
||||||
|
//First determine what the number of colors in the palette
|
||||||
|
int num_palette_items = get_num_palette_colors(im);
|
||||||
|
|
||||||
|
//Get the gbitmap's current palette
|
||||||
|
GColor *current_palette = gbitmap_get_palette(im);
|
||||||
|
|
||||||
|
//Iterate through the palette finding the color we want to replace and replacing
|
||||||
|
//it with the new color
|
||||||
|
for(int i = 0; i < num_palette_items; i++){
|
||||||
|
if ((color_to_replace.argb & 0x3F)==(current_palette[i].argb & 0x3F)){
|
||||||
|
current_palette[i].argb = (current_palette[i].argb & 0xC0)| (replace_with_color.argb & 0x3F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mark the bitmaplayer dirty
|
||||||
|
if(bml != NULL){
|
||||||
|
layer_mark_dirty(bitmap_layer_get_layer(bml));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// TAKEN FROM https://github.com/rebootsramblings/GBitmap-Colour-Palette-Manipulator
|
||||||
|
|
||||||
|
#include <pebble.h>
|
||||||
|
|
||||||
|
#ifdef PBL_COLOR
|
||||||
|
void replace_gbitmap_color(GColor color_to_replace, GColor replace_with_color, GBitmap *im, BitmapLayer *bml);
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from bdfparser import Font
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
font = Font("civic-segments.bdf")
|
||||||
|
print(
|
||||||
|
f"This font's global size is "
|
||||||
|
f"{font.headers['fbbx']} x {font.headers['fbby']} (pixel), "
|
||||||
|
f"it contains {len(font)} glyphs."
|
||||||
|
)
|
||||||
|
chars_to_export = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
|
||||||
|
for char_str in chars_to_export:
|
||||||
|
char = font.glyph(char_str)
|
||||||
|
bitmap = char.draw()
|
||||||
|
im = Image.frombytes(
|
||||||
|
"RGBA",
|
||||||
|
(bitmap.width(), bitmap.height()),
|
||||||
|
bitmap.tobytes(
|
||||||
|
"RGBA",
|
||||||
|
bytesdict={
|
||||||
|
0: b"\x00\x00\x00\x00", # transparent background
|
||||||
|
1: b"\xff\xff\xff\xff", # white glyph
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
im.save(f"../resources/{char_str}.png", "PNG")
|
||||||