added setting for tick marks

master
Alina Marquardt 2015-11-20 00:33:31 +01:00
parent b8508ce0fd
commit b48313dba4
3 changed files with 72 additions and 31 deletions

View File

@ -4,7 +4,9 @@
"colorh": 2, "colorh": 2,
"colorm": 1, "colorm": 1,
"colorp": 3, "colorp": 3,
"shadows": 4 "colort": 6,
"shadows": 4,
"ticks": 5
}, },
"capabilities": [ "capabilities": [
"configurable" "configurable"
@ -22,7 +24,7 @@
"chalk" "chalk"
], ],
"uuid": "ceeae81b-6b50-43b6-8bbb-6d6f6eb62b69", "uuid": "ceeae81b-6b50-43b6-8bbb-6d6f6eb62b69",
"versionLabel": "1.2", "versionLabel": "1.3",
"watchapp": { "watchapp": {
"watchface": true "watchface": true
} }

View File

@ -3,7 +3,7 @@ Pebble.addEventListener('ready', function() {
}); });
Pebble.addEventListener('showConfiguration', function() { Pebble.addEventListener('showConfiguration', function() {
var url='http://pebble.lastfuture.de/config/supersimple12/'; var url='http://pebble.lastfuture.de/config/supersimple13/';
console.log('Showing configuration page: '+url); console.log('Showing configuration page: '+url);
Pebble.openURL(url); Pebble.openURL(url);
}); });
@ -17,7 +17,9 @@ Pebble.addEventListener('webviewclosed', function(e) {
colorm: parseInt(configData.colorm, 16), colorm: parseInt(configData.colorm, 16),
colorh: parseInt(configData.colorh, 16), colorh: parseInt(configData.colorh, 16),
colorp: parseInt(configData.colorp, 16), colorp: parseInt(configData.colorp, 16),
shadows: configData.shadows === true shadows: configData.shadows === true,
ticks: configData.ticks,
colort: parseInt(configData.colort, 16)
}, function() { }, function() {
console.log('Send successful!'); console.log('Send successful!');
}, function() { }, function() {

View File

@ -5,19 +5,21 @@
#define KEY_HOUR_COLOR 2 #define KEY_HOUR_COLOR 2
#define KEY_PEG_COLOR 3 #define KEY_PEG_COLOR 3
#define KEY_SHADOWS 4 #define KEY_SHADOWS 4
#define KEY_TICKS 5
#define KEY_TICK_COLOR 6
#define ANTIALIASING true #define ANTIALIASING true
#define FINAL_RADIUS 88 #define FINAL_RADIUS 88
#define HAND_WIDTH 7 #define HAND_WIDTH 7
#define TICK_RADIUS 3
#define DOT_RADIUS HAND_WIDTH/4 #define DOT_RADIUS HAND_WIDTH/4
#define HAND_MARGIN_OUTER 10-(HAND_WIDTH/2) #define HAND_MARGIN_OUTER 10-(HAND_WIDTH/2)
#define HAND_MARGIN_INNER 0 #define HAND_MARGIN_INNER 0
#define SHADOW_OFFSET 2 #define SHADOW_OFFSET 2
#define ANIMATION_DURATION 600 #define ANIMATION_DURATION 400
#define ANIMATION_DELAY 150 #define ANIMATION_DELAY 100
static uint8_t shadowtable[] = {192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192, \ static uint8_t shadowtable[] = {192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192, \
192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192, \ 192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192, \
@ -49,11 +51,11 @@ static Layer *s_canvas_layer;
static GPoint s_center; static GPoint s_center;
static Time s_last_time; static Time s_last_time;
static int s_radius = 0; static int s_radius = 0, ticks;
static bool s_animating = false, shadows = true; static bool s_animating = false, shadows = true;
static float anim_offset; static float anim_offset;
static GColor gcolorbg, gcolorm, gcolorh, gcolorp, gcolorshadow; static GColor gcolorbg, gcolorm, gcolorh, gcolorp, gcolorshadow, gcolort;
static void inbox_received_handler(DictionaryIterator *iter, void *context) { static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *colorbg_t = dict_find(iter, KEY_BG_COLOR); Tuple *colorbg_t = dict_find(iter, KEY_BG_COLOR);
@ -61,6 +63,8 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *colorh_t = dict_find(iter, KEY_HOUR_COLOR); Tuple *colorh_t = dict_find(iter, KEY_HOUR_COLOR);
Tuple *colorp_t = dict_find(iter, KEY_PEG_COLOR); Tuple *colorp_t = dict_find(iter, KEY_PEG_COLOR);
Tuple *shadows_t = dict_find(iter, KEY_SHADOWS); Tuple *shadows_t = dict_find(iter, KEY_SHADOWS);
Tuple *ticknum_t = dict_find(iter, KEY_TICKS);
Tuple *colort_t = dict_find(iter, KEY_TICK_COLOR);
if(colorbg_t) { if(colorbg_t) {
int colorbg = colorbg_t->value->int32; int colorbg = colorbg_t->value->int32;
@ -90,6 +94,15 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
persist_write_bool(KEY_SHADOWS, false); persist_write_bool(KEY_SHADOWS, false);
shadows = false; shadows = false;
} }
if(ticknum_t) {
ticks = ticknum_t->value->uint8;
persist_write_int(KEY_TICKS, ticks);
}
if(colort_t) {
int colort = colort_t->value->int32;
persist_write_int(KEY_TICK_COLOR, colort);
gcolort = GColorFromHEX(colort);
}
if(s_canvas_layer) { if(s_canvas_layer) {
layer_mark_dirty(s_canvas_layer); layer_mark_dirty(s_canvas_layer);
} }
@ -135,13 +148,12 @@ static void tick_handler(struct tm *tick_time, TimeUnits changed) {
} }
static void update_proc(Layer *layer, GContext *ctx) { static void update_proc(Layer *layer, GContext *ctx) {
// Color background?
GRect bounds = layer_get_bounds(layer); GRect bounds = layer_get_bounds(layer);
graphics_context_set_fill_color(ctx, gcolorbg); graphics_context_set_fill_color(ctx, gcolorbg);
graphics_fill_rect(ctx, bounds, 0, GCornerNone); graphics_fill_rect(ctx, bounds, 0, GCornerNone);
graphics_context_set_antialiased(ctx, ANTIALIASING); graphics_context_set_antialiased(ctx, ANTIALIASING);
// Don't use current time while animating // Use current time while animating
Time mode_time = s_last_time; Time mode_time = s_last_time;
// Adjust for minutes through the hour // Adjust for minutes through the hour
@ -153,7 +165,6 @@ static void update_proc(Layer *layer, GContext *ctx) {
minute_angle -= anim_offset; minute_angle -= anim_offset;
} }
// Plot hands
GPoint minute_hand_outer = (GPoint) { GPoint minute_hand_outer = (GPoint) {
.x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(s_radius - HAND_MARGIN_OUTER) / TRIG_MAX_RATIO) + s_center.x, .x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(s_radius - HAND_MARGIN_OUTER) / TRIG_MAX_RATIO) + s_center.x,
.y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(s_radius - HAND_MARGIN_OUTER) / TRIG_MAX_RATIO) + s_center.y, .y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * mode_time.minutes / 60) * (int32_t)(s_radius - HAND_MARGIN_OUTER) / TRIG_MAX_RATIO) + s_center.y,
@ -170,8 +181,22 @@ static void update_proc(Layer *layer, GContext *ctx) {
.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)HAND_MARGIN_INNER / TRIG_MAX_RATIO) + s_center.x, .x = (int16_t)(sin_lookup(hour_angle) * (int32_t)HAND_MARGIN_INNER / TRIG_MAX_RATIO) + s_center.x,
.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)HAND_MARGIN_INNER / TRIG_MAX_RATIO) + s_center.y, .y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)HAND_MARGIN_INNER / TRIG_MAX_RATIO) + s_center.y,
}; };
// Draw hands with positive length only if (ticks > 0) {
//gcolorshadow gcolorh gcolorm graphics_context_set_fill_color(ctx, gcolort);
GRect insetbounds = GRect(2, 2, bounds.size.w-4, bounds.size.h-4);
GRect insetbounds12 = GRect(4, 4, bounds.size.w-8, bounds.size.h-8);
for(int i = 0; i < ticks; i++) {
int hour_angle = (i * 360) / ticks;
if (ticks == 12 && i%3!=0) {
GPoint pos = gpoint_from_polar(insetbounds12, GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(hour_angle));
graphics_fill_circle(ctx, pos, TICK_RADIUS/2);
} else {
GPoint pos = gpoint_from_polar(insetbounds, GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(hour_angle));
graphics_fill_circle(ctx, pos, TICK_RADIUS);
}
}
}
if((s_radius - HAND_MARGIN_OUTER) > HAND_MARGIN_INNER) { if((s_radius - HAND_MARGIN_OUTER) > HAND_MARGIN_INNER) {
if(shadows) { if(shadows) {
if(s_radius > 2 * HAND_MARGIN_OUTER) { if(s_radius > 2 * HAND_MARGIN_OUTER) {
@ -241,6 +266,17 @@ static void window_load(Window *window) {
} else { } else {
shadows = false; shadows = false;
} }
if (persist_exists(KEY_TICKS)) {
ticks = persist_read_int(KEY_TICKS);
} else {
ticks = 0;
}
if (persist_exists(KEY_TICK_COLOR)) {
int colort = persist_read_int(KEY_TICK_COLOR);
gcolort = GColorFromHEX(colort);
} else {
gcolort = GColorWhite;
}
s_canvas_layer = layer_create(window_bounds); s_canvas_layer = layer_create(window_bounds);
layer_set_update_proc(s_canvas_layer, update_proc); layer_set_update_proc(s_canvas_layer, update_proc);
@ -265,7 +301,8 @@ static void radius_update(Animation *anim, AnimationProgress dist_normalized) {
static void init() { static void init() {
srand(time(NULL)); srand(time(NULL));
if (watch_info_get_model()==WATCH_INFO_MODEL_UNKNOWN) { // keep lit only in emulator // keep lit only in emulator
if (watch_info_get_model()==WATCH_INFO_MODEL_UNKNOWN) {
light_enable(true); light_enable(true);
} }