classic-lite

Minimalist rewrite of Łukasz Zalewski's "classic" pebble watchface
git clone https://git.instinctive.eu/classic-lite.git
Log | Files | Refs | README | LICENSE

commit e2711ebc4befc39176364b9ce0a1739685cb45ba
parent 3828a6c440be52beb4e42cc8deaf3f5ef67ee9ad
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date:   Tue,  5 Jan 2016 19:35:41 +0000

Allow different colors for hour hand, minute hand and central pin
Diffstat:
Mconfig.html | 21+++++++++++++++++----
Msrc/classic-lite.c | 54++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/js/pebble-js-app.js | 22++++++++++++++++++++--
3 files changed, 81 insertions(+), 16 deletions(-)

diff --git a/config.html b/config.html @@ -34,7 +34,9 @@ var selectedFormat = document.getElementById("textFormat").value; var options = { "backgroundColor": document.getElementById("backgroundColorPicker").value, - "handColor": document.getElementById("handColorPicker").value, + "hourHandColor": document.getElementById("hourHandColorPicker").value, + "minuteHandColor": document.getElementById("minuteHandColorPicker").value, + "pinColor": document.getElementById("pinColorPicker").value, "hourColor": document.getElementById("hourColorPicker").value, "innerColor": document.getElementById("innerColorPicker").value, "minuteColor": document.getElementById("minuteColorPicker").value, @@ -70,8 +72,16 @@ <input id="backgroundColorPicker" type="text" class="item-color item-color-normal" value="0xFFFFFF"> </label> <label class="item"> - Hand Color - <input id="handColorPicker" type="text" class="item-color item-color-normal" value="0x000000"> + Hour Hand Color + <input id="hourHandColorPicker" type="text" class="item-color item-color-normal" value="0x000000"> + </label> + <label class="item"> + Minute Hand Color + <input id="minuteHandColorPicker" type="text" class="item-color item-color-normal" value="0x000000"> + </label> + <label class="item"> + Central Pin Color + <input id="pinColorPicker" type="text" class="item-color item-color-normal" value="0x000000"> </label> <label class="item"> Hour Mark Color @@ -169,8 +179,11 @@ <script src="https://cdn.rawgit.com/pebble/slate/v0.0.3/dist/js/slate.min.js"></script> <script> + var handColor = getQueryParam("hands", "0x000000"); document.getElementById("backgroundColorPicker").value = getQueryParam("background", "0xFFFFFF"); - document.getElementById("handColorPicker").value = getQueryParam("hands", "0x000000"); + document.getElementById("hourHandColorPicker").value = getQueryParam("hhand", handColor); + document.getElementById("minuteHandColorPicker").value = getQueryParam("mhand", handColor); + document.getElementById("pinColorPicker").value = getQueryParam("pin", handColor); document.getElementById("hourColorPicker").value = getQueryParam("hours", "0x000000"); document.getElementById("innerColorPicker").value = getQueryParam("inner", "0xAAAAAA"); document.getElementById("minuteColorPicker").value = getQueryParam("minutes", "0x000000"); diff --git a/src/classic-lite.c b/src/classic-lite.c @@ -27,7 +27,9 @@ static GColor background_color; static GColor battery_color; static GColor battery_color2; static GColor bluetooth_color; -static GColor hand_color; +static GColor hour_hand_color; +static GColor minute_hand_color; +static GColor pin_color; static GColor hour_mark_color; static GColor inner_rectangle_color; static GColor minute_mark_color; @@ -36,7 +38,7 @@ static unsigned text_font = 0; static char text_format[32] = "%a %d"; static bool bluetooth_vibration = true; static uint8_t show_battery_icon_below = 100; -#define PERSIST_BUFFER_SIZE 45 +#define PERSIST_BUFFER_SIZE 47 #define TEXT_FONT_NUMBER 4 static const char *const text_fonts[] = { @@ -93,7 +95,7 @@ read_config(void) { return; } - if (buffer[0] > 2) { + if (buffer[0] > 3) { APP_LOG(APP_LOG_LEVEL_WARNING, "loading data from future version %u, " "data will be lost on the next write", @@ -110,7 +112,7 @@ read_config(void) { READ_COLOR(background_color, buffer[1]); READ_COLOR(battery_color, buffer[2]); READ_COLOR(bluetooth_color, buffer[3]); - READ_COLOR(hand_color, buffer[4]); + READ_COLOR(hour_hand_color, buffer[4]); READ_COLOR(hour_mark_color, buffer[5]); READ_COLOR(inner_rectangle_color, buffer[6]); READ_COLOR(minute_mark_color, buffer[7]); @@ -122,6 +124,7 @@ read_config(void) { memcpy(text_format, buffer + 11, sizeof text_format); battery_color2 = battery_color; + pin_color = minute_hand_color = hour_hand_color; if (buffer[0] < 2) return; @@ -134,6 +137,18 @@ read_config(void) { READ_COLOR(battery_color2, buffer[43]); text_font = buffer[44]; + + if (buffer[0] < 3) return; + + if (i < 47) { + APP_LOG(APP_LOG_LEVEL_ERROR, + "truncated persistent buffer (size %d), using only v2", + i); + return; + } + + READ_COLOR(minute_hand_color, buffer[45]); + READ_COLOR(pin_color, buffer[46]); } static void @@ -141,11 +156,13 @@ write_config(void) { uint8_t buffer[PERSIST_BUFFER_SIZE]; int i; - buffer[0] = 2; + buffer[0] = 3; SAVE_COLOR(buffer[1], background_color); SAVE_COLOR(buffer[2], battery_color); SAVE_COLOR(buffer[3], bluetooth_color); - SAVE_COLOR(buffer[4], hand_color); + SAVE_COLOR(buffer[4], hour_hand_color); + SAVE_COLOR(buffer[45], minute_hand_color); + SAVE_COLOR(buffer[46], pin_color); SAVE_COLOR(buffer[5], hour_mark_color); SAVE_COLOR(buffer[6], inner_rectangle_color); SAVE_COLOR(buffer[7], minute_mark_color); @@ -571,13 +588,15 @@ static void hand_layer_draw(Layer *layer, GContext *ctx) { (void)layer; - graphics_context_set_fill_color(ctx, hand_color); + graphics_context_set_fill_color(ctx, hour_hand_color); graphics_context_set_stroke_color(ctx, background_color); gpath_rotate_to(minute_hand_path, TRIG_MAX_ANGLE * tm_now.tm_min / 60); gpath_draw_filled(ctx, minute_hand_path); gpath_draw_outline(ctx, minute_hand_path); + graphics_context_set_fill_color(ctx, minute_hand_color); + gpath_rotate_to(hour_hand_path, TRIG_MAX_ANGLE * (tm_now.tm_hour * 60 + tm_now.tm_min) / 720); gpath_draw_filled(ctx, hour_hand_path); @@ -589,7 +608,7 @@ hand_layer_draw(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, background_color); graphics_fill_circle(ctx, center, 2); - graphics_context_set_fill_color(ctx, hand_color); + graphics_context_set_fill_color(ctx, pin_color); graphics_fill_circle(ctx, center, 1); } @@ -723,7 +742,8 @@ inbox_received_handler(DictionaryIterator *iterator, void *context) { layer_mark_dirty(icon_layer); break; case 4: - hand_color = color_from_tuple(tuple); + hour_hand_color = color_from_tuple(tuple); + pin_color = minute_hand_color = hour_hand_color; layer_mark_dirty(hand_layer); break; case 5: @@ -793,6 +813,18 @@ inbox_received_handler(DictionaryIterator *iterator, void *context) { "show_battery_icon_below entry", (int)tuple->type); break; + case 20: + hour_hand_color = color_from_tuple(tuple); + layer_mark_dirty(hand_layer); + break; + case 21: + minute_hand_color = color_from_tuple(tuple); + layer_mark_dirty(hand_layer); + break; + case 22: + pin_color = color_from_tuple(tuple); + layer_mark_dirty(hand_layer); + break; default: APP_LOG(APP_LOG_LEVEL_ERROR, "unknown configuration key %lu", @@ -885,7 +917,9 @@ init(void) { background_color = GColorWhite; bluetooth_color = GColorBlack; - hand_color = GColorBlack; + hour_hand_color = GColorBlack; + minute_hand_color = GColorBlack; + pin_color = GColorBlack; hour_mark_color = GColorBlack; minute_mark_color = GColorBlack; text_color = GColorBlack; diff --git a/src/js/pebble-js-app.js b/src/js/pebble-js-app.js @@ -16,7 +16,9 @@ const settings = { /* "name in local storage": "form input parameter" */ "backgroundColor": "background", - "handColor": "hands", + "hourHandColor": "hhand", + "minuteHandColor": "mhand", + "pinColor": "pin", "hourColor": "hours", "innerColor": "inner", "minuteColor": "minutes", @@ -31,6 +33,20 @@ const settings = { /* "name in local storage": "form input parameter" */ }; function encodeStored(names) { + var handColorValue = localStorage.getItem("handColor"); + if (handColorValue != null) { + if (localStorage.getItem("hourHandColor") == null) { + localStorage.setItem("hourHandColor", handColorValue); + } + if (localStorage.getItem("minuteHandColor") == null) { + localStorage.setItem("minuteHandColor", handColorValue); + } + if (localStorage.getItem("pinColor") == null) { + localStorage.setItem("pinColor", handColorValue); + } + localStorage.removeItem("handColor"); + } + var result = "?v=1.3"; for (var key in names) { var value = localStorage.getItem(key); @@ -60,7 +76,6 @@ Pebble.addEventListener("webviewclosed", function(e) { 1: parseInt(configData["backgroundColor"]), 2: parseInt(configData["batteryColor"]), 3: parseInt(configData["bluetoothColor"]), - 4: parseInt(configData["handColor"]), 5: parseInt(configData["hourColor"]), 6: parseInt(configData["innerColor"]), 7: parseInt(configData["minuteColor"]), @@ -70,6 +85,9 @@ Pebble.addEventListener("webviewclosed", function(e) { 11: configData["textFormat"], 12: parseInt(configData["bluetoothVibration"]), 13: parseInt(configData["lowBatteryLevel"]), + 20: parseInt(configData["hourHandColor"]), + 21: parseInt(configData["minuteHandColor"]), + 22: parseInt(configData["pinColor"]), }; Pebble.sendAppMessage(dict, function() {