Okay, configurable, but not persistent

This commit is contained in:
Neale Pickett 2015-11-11 21:05:13 -07:00
parent 61b5ba2176
commit a1c9083d4f
3 changed files with 56 additions and 36 deletions

View File

@ -1,8 +1,8 @@
{
"appKeys": {
"bt": 1,
"color-bg": 2,
"bluetooth": 1,
"color-day": 4,
"color-face": 2,
"color-hr": 9,
"color-min": 8,
"color-mon": 5,

View File

@ -5,26 +5,24 @@ static Window *window;
static Layer *s_simple_bg_layer, *s_date_layer, *s_hands_layer;
static TextLayer *s_bt_label, *s_day_label, *s_mon_label;
static GColor second_color;
static GColor colors[KEY_LAST];
static GPath *s_tic_path;
static GPath *s_second_arrow, *s_minute_arrow, *s_hour_arrow;
static char s_mon_buffer[4], s_day_buffer[6];
static TextLayer *s_hour_label[4];
static char s_hour[4][4];
GColor fg;
GColor bg;
bool seconds = true;
bool bt_connected = true;
static bool seconds = true;
static bool bluetooth = true;
static bool bt_connected = true;
static void bg_update_proc(Layer *layer, GContext *ctx) {
// Fill background
graphics_context_set_fill_color(ctx, bg);
graphics_context_set_fill_color(ctx, colors[KEY_COLOR_FACE]);
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
// Draw tics
graphics_context_set_fill_color(ctx, fg);
graphics_context_set_fill_color(ctx, colors[KEY_COLOR_TIC]);
for (int i = 0; i < 12; i += 1) {
switch (i) {
case 0:
@ -57,6 +55,7 @@ static void bg_update_proc(Layer *layer, GContext *ctx) {
snprintf(s_hour[i], 3, "%d", hour);
text_layer_set_text(s_hour_label[i], s_hour[i]);
text_layer_set_text_color(s_hour_label[i], colors[KEY_COLOR_NUM]);
}
}
@ -66,28 +65,30 @@ static void hands_update_proc(Layer *layer, GContext *ctx) {
time_t now = time(NULL);
struct tm *t = localtime(&now);
graphics_context_set_fill_color(ctx, fg);
graphics_context_set_stroke_color(ctx, bg);
graphics_context_set_stroke_color(ctx, colors[KEY_COLOR_FACE]);
// minute/hour hand
// minute hand
graphics_context_set_fill_color(ctx, colors[KEY_COLOR_MIN]);
gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
gpath_draw_filled(ctx, s_minute_arrow);
gpath_draw_outline(ctx, s_minute_arrow);
// hour hand
graphics_context_set_fill_color(ctx, colors[KEY_COLOR_HR]);
gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
gpath_draw_filled(ctx, s_hour_arrow);
gpath_draw_outline(ctx, s_hour_arrow);
if (seconds) {
// second hand
graphics_context_set_fill_color(ctx, second_color);
graphics_context_set_fill_color(ctx, colors[KEY_COLOR_SEC]);
gpath_rotate_to(s_second_arrow, TRIG_MAX_ANGLE * t->tm_sec / 60);
gpath_draw_filled(ctx, s_second_arrow);
//gpath_draw_outline(ctx, s_second_arrow);
}
// dot in the middle
graphics_context_set_fill_color(ctx, fg);
graphics_context_set_fill_color(ctx, colors[KEY_COLOR_TIC]);
graphics_fill_circle(ctx, GPoint(bounds.size.w / 2, bounds.size.h / 2), 2);
}
@ -104,12 +105,14 @@ static void date_update_proc(Layer *layer, GContext *ctx) {
strftime(s_mon_buffer, sizeof(s_mon_buffer), "%b", t);
text_layer_set_text(s_mon_label, s_mon_buffer);
text_layer_set_text_color(s_mon_label, colors[KEY_COLOR_MON]);
strftime(s_day_buffer, sizeof(s_day_buffer), "%d", t);
if (b[0] == '0') {
b += 1;
}
text_layer_set_text(s_day_label, b);
text_layer_set_text_color(s_day_label, colors[KEY_COLOR_DAY]);
}
static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {
@ -157,8 +160,7 @@ static void window_load(Window *window) {
s_hour_label[i] = text_layer_create(GRect(x, y, NUM_WIDTH, NUM_HEIGHT));
text_layer_set_text_alignment(s_hour_label[i], align);
text_layer_set_background_color(s_hour_label[i], bg);
text_layer_set_text_color(s_hour_label[i], fg);
text_layer_set_background_color(s_hour_label[i], GColorClear);
text_layer_set_font(s_hour_label[i], fonts_load_custom_font(resource_get_handle(NUM_FONT)));
layer_add_child(s_simple_bg_layer, text_layer_get_layer(s_hour_label[i]));
@ -177,7 +179,7 @@ static void window_load(Window *window) {
text_layer_set_text_alignment(s_bt_label, GTextAlignmentLeft);
text_layer_set_text(s_bt_label, "");
text_layer_set_background_color(s_bt_label, GColorClear);
text_layer_set_text_color(s_bt_label, fg);
text_layer_set_text_color(s_bt_label, colors[KEY_COLOR_TIC]);
text_layer_set_font(s_bt_label, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_SYMBOLS_52)));
layer_add_child(s_date_layer, text_layer_get_layer(s_bt_label));
@ -192,7 +194,7 @@ static void window_load(Window *window) {
text_layer_set_text_alignment(s_mon_label, GTextAlignmentRight);
text_layer_set_text(s_mon_label, s_mon_buffer);
text_layer_set_background_color(s_mon_label, GColorClear);
text_layer_set_text_color(s_mon_label, fg);
text_layer_set_text_color(s_mon_label, colors[KEY_COLOR_MON]);
layer_add_child(s_date_layer, text_layer_get_layer(s_mon_label));
// Day
@ -206,7 +208,7 @@ static void window_load(Window *window) {
text_layer_set_text_alignment(s_day_label, GTextAlignmentRight);
text_layer_set_text(s_day_label, s_day_buffer);
text_layer_set_background_color(s_day_label, GColorClear);
text_layer_set_text_color(s_day_label, fg);
text_layer_set_text_color(s_day_label, colors[KEY_COLOR_DAY]);
layer_add_child(s_date_layer, text_layer_get_layer(s_day_label));
s_hands_layer = layer_create(bounds);
@ -236,6 +238,7 @@ static GColor color_of_int(int color) {
#ifdef PBL_COLOR
return GColorFromHEX(color);
#else
// XXX: This is surely going to turn out to be naïve
if (color & 0x808080) {
return GColorWhite;
} else {
@ -245,18 +248,29 @@ static GColor color_of_int(int color) {
}
static void in_received_handler(DictionaryIterator *rec, void *context) {
Tuple *sec_color_tuple = dict_find(rec, KEY_COLOR_SEC);
int i;
if (sec_color_tuple) {
#ifdef PBL_COLOR
second_color = GColorFromHEX(sec_color_tuple->value->int32);
#else
if (sec_color_tuple->value->int32) {
second_color = GColorWhite;
} else {
second_color = GColorBlack;
for (i = 0; i < KEY_LAST; i += 1) {
Tuple *cur = dict_find(rec, i);
switch (i) {
case KEY_COLOR_FACE:
case KEY_COLOR_TIC:
case KEY_COLOR_NUM:
case KEY_COLOR_DAY:
case KEY_COLOR_MON:
case KEY_COLOR_SEC:
case KEY_COLOR_MIN:
case KEY_COLOR_HR:
colors[i] = color_of_int(cur->value->int32);
break;
case KEY_SECONDS:
seconds = !!cur->value->int32;
break;
case KEY_BLUETOOTH:
bluetooth = !!cur->value->int32;
break;
}
#endif
}
}
@ -265,9 +279,13 @@ static void in_dropped_handler(AppMessageResult reason, void *context) {
}
static void init() {
fg = GColorBlack;
bg = GColorWhite;
second_color = COLOR_FALLBACK(GColorWindsorTan, GColorBlack);
int i;
for (i = 0; i < KEY_LAST; i += 1) {
colors[i] = GColorBlack;
}
colors[KEY_COLOR_FACE] = GColorWhite;
colors[KEY_COLOR_SEC] = COLOR_FALLBACK(GColorWindsorTan, GColorBlack);
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
@ -312,6 +330,7 @@ static void deinit() {
gpath_destroy(s_second_arrow);
gpath_destroy(s_minute_arrow);
gpath_destroy(s_hour_arrow);
// XXX: text destroy?
tick_timer_service_unsubscribe();
window_destroy(window);

View File

@ -3,15 +3,16 @@
typedef enum {
KEY_SECONDS = 0,
KEY_BT,
KEY_COLOR_BG,
KEY_BLUETOOTH,
KEY_COLOR_FACE,
KEY_COLOR_NUM,
KEY_COLOR_DAY,
KEY_COLOR_MON,
KEY_COLOR_TIC,
KEY_COLOR_SEC,
KEY_COLOR_MIN,
KEY_COLOR_HR
KEY_COLOR_HR,
KEY_LAST
} MessageKey;
static const struct GPathInfo TIC_POINTS = {