Skip to content

Commit 48fd6e0

Browse files
StefanStefan
authored andcommitted
[v0.5]
* Replace spiral image with arc drawing routines. * UI is redrawn using the UI Editor on CloudPebble.
1 parent fa5ecd3 commit 48fd6e0

File tree

6 files changed

+164
-92
lines changed

6 files changed

+164
-92
lines changed

Fibonacci_Clock.pbw

77 Bytes
Binary file not shown.

Fibonacci_Clock.png

997 Bytes
Loading

appinfo.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,19 @@
88
"projectType": "native",
99
"resources": {
1010
"media": [
11-
{
12-
"file": "images/spiral.png",
13-
"name": "IMAGE_SPIRAL",
14-
"type": "png"
15-
},
1611
{
1712
"file": "images/charging.png",
1813
"name": "IMAGE_CHARGING",
1914
"type": "png"
2015
},
2116
{
22-
"file": "images/plugged.png",
23-
"name": "IMAGE_PLUGGED",
17+
"file": "images/battery.png",
18+
"name": "IMAGE_BATTERY",
2419
"type": "png"
2520
},
2621
{
27-
"file": "images/battery.png",
28-
"name": "IMAGE_BATTERY",
22+
"file": "images/plugged.png",
23+
"name": "IMAGE_PLUGGED",
2924
"type": "png"
3025
},
3126
{
@@ -42,7 +37,7 @@
4237
"basalt"
4338
],
4439
"uuid": "1289bd91-5811-40a5-a270-e8f97c126f18",
45-
"versionLabel": "0.4",
40+
"versionLabel": "0.5",
4641
"watchapp": {
4742
"watchface": true
4843
}

resources/images/spiral.png

-880 Bytes
Binary file not shown.

src/main.c

Lines changed: 157 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,96 @@
11
#include <pebble.h>
2+
#include "main.h"
23

3-
// Windows
4-
static Window *s_main_window;
4+
#define USE_FIXED_TIME_FOR_PUBLISHING_IMAGE 0
55

6-
// Layers
7-
static Layer *s_grid_layer;
6+
// BEGIN AUTO-GENERATED UI CODE; DO NOT MODIFY
7+
static Window *s_window;
8+
static GFont s_res_bitham_30_black;
9+
static Layer *s_fibo_layer;
810
static TextLayer *s_time_layer;
911
static Layer *s_charge_layer;
12+
static Layer *s_arc5x5_layer;
13+
static Layer *s_arc3x3_layer;
14+
static Layer *s_arc2x2_layer;
15+
static Layer *s_arc1x1L_layer;
16+
static Layer *s_arc1x1R_layer;
17+
18+
static void initialise_ui(void) {
19+
s_window = window_create();
20+
window_set_background_color(s_window, GColorBlack);
21+
#ifndef PBL_SDK_3
22+
window_set_fullscreen(s_window, true);
23+
#endif
24+
25+
s_res_bitham_30_black = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK);
26+
// s_fibo_layer
27+
s_fibo_layer = layer_create(GRect(19, 1, 105, 165));
28+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_fibo_layer);
29+
30+
// s_time_layer
31+
s_time_layer = text_layer_create(GRect(0, 65, 144, 40));
32+
text_layer_set_background_color(s_time_layer, GColorClear);
33+
text_layer_set_text(s_time_layer, "10:30");
34+
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
35+
text_layer_set_font(s_time_layer, s_res_bitham_30_black);
36+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_time_layer);
37+
38+
// s_charge_layer
39+
s_charge_layer = layer_create(GRect(127, 142, 15, 22));
40+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_charge_layer);
41+
42+
// s_arc5x5_layer
43+
s_arc5x5_layer = layer_create(GRect(21, 63, 101, 101));
44+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_arc5x5_layer);
45+
46+
// s_arc3x3_layer
47+
s_arc3x3_layer = layer_create(GRect(21, 3, 61, 61));
48+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_arc3x3_layer);
49+
50+
// s_arc2x2_layer
51+
s_arc2x2_layer = layer_create(GRect(81, 3, 41, 41));
52+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_arc2x2_layer);
53+
54+
// s_arc1x1L_layer
55+
s_arc1x1L_layer = layer_create(GRect(81, 43, 21, 21));
56+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_arc1x1L_layer);
57+
58+
// s_arc1x1R_layer
59+
s_arc1x1R_layer = layer_create(GRect(101, 43, 21, 21));
60+
layer_add_child(window_get_root_layer(s_window), (Layer *)s_arc1x1R_layer);
61+
}
1062

63+
static void destroy_ui(void) {
64+
window_destroy(s_window);
65+
layer_destroy(s_fibo_layer);
66+
text_layer_destroy(s_time_layer);
67+
layer_destroy(s_charge_layer);
68+
layer_destroy(s_arc5x5_layer);
69+
layer_destroy(s_arc3x3_layer);
70+
layer_destroy(s_arc2x2_layer);
71+
layer_destroy(s_arc1x1L_layer);
72+
layer_destroy(s_arc1x1R_layer);
73+
}
74+
// END AUTO-GENERATED UI CODE
75+
1176
#if 1
1277
// GRects (Vertical)
78+
static struct GRect s_3x3_square = {{ 2, 2}, { 61, 61}}; // 3x3 Square
79+
static struct GRect s_2x2_square = {{62, 2}, { 41, 41}}; // 2x2 Square
80+
static struct GRect s_1x1L_square = {{62, 42}, { 21, 21}}; // 1x1 Square (left)
81+
static struct GRect s_1x1R_square = {{82, 42}, { 21, 21}}; // 1x1 Square (right)
82+
static struct GRect s_5x5_square = {{ 2, 62}, {101, 101}}; // 5x5 Square
83+
static struct GRect s_outline = {{ 0, 0}, {105, 165}};
84+
#elif 0
85+
// GRects (Vertical) (WARNING! coordinates are for the OLD layer position/size, replaced by above)
1386
static struct GRect s_3x3_square = {{ 21, 3}, { 61, 61}}; // 3x3 Square
1487
static struct GRect s_2x2_square = {{ 81, 3}, { 41, 41}}; // 2x2 Square
1588
static struct GRect s_1x1L_square = {{ 81, 43}, { 21, 21}}; // 1x1 Square (left)
1689
static struct GRect s_1x1R_square = {{101, 43}, { 21, 21}}; // 1x1 Square (right)
1790
static struct GRect s_5x5_square = {{ 21, 63}, {101, 101}}; // 5x5 Square
1891
static struct GRect s_outline = {{ 19, 1}, {105, 165}};
1992
#else
20-
// GRects (Horizontal)
93+
// GRects (Horizontal) (WARNING! coordinates are for the OLD layer position/size)
2194
static struct GRect s_3x3_square = {{ 3, 75}, { 52, 52}}; // 3x3 Square
2295
static struct GRect s_2x2_square = {{ 3, 41}, { 35, 35}}; // 2x2 Square
2396
static struct GRect s_1x1L_square = {{ 37, 58}, { 18, 18}}; // 1x1 Square (bottom)
@@ -27,14 +100,17 @@ static Layer *s_charge_layer;
27100
#endif
28101

29102
// GBitmap
30-
static GBitmap *s_spiral_image;
31103
static GBitmap *s_battery_image;
32104
static GBitmap *s_charging_image;
33105
static GBitmap *s_plugged_image;
34106

35107
// Global time
36108
static int s_curr_hour;
37-
static int s_curr_min;
109+
static int s_curr_min;
110+
111+
static void handle_window_unload(Window* window) {
112+
destroy_ui();
113+
}
38114

39115
static void update_time() {
40116
// Create a long-lived buffer
@@ -43,17 +119,56 @@ static void update_time() {
43119
// Write the current hours and minutes into the buffer
44120
clock_copy_time_string(time_str, sizeof(time_str));
45121

122+
#if USE_FIXED_TIME_FOR_PUBLISHING_IMAGE
123+
strcpy(time_str, "10:30");
124+
#endif
125+
46126
// Update current time on the TextLayer
47127
text_layer_set_text(s_time_layer, time_str);
48128
}
49129

50-
static void grid_layer_update_callback(Layer *layer, GContext *ctx) {
130+
static void draw_spiral_arc(GContext *ctx, GPoint center, uint16_t radius ) {
131+
graphics_context_set_stroke_color(ctx, GColorDarkGray);
132+
graphics_context_set_stroke_width(ctx, 3);
133+
graphics_draw_circle(ctx, center, radius - 2);
134+
}
135+
136+
static void arc3x3_layer_update_callback(Layer *layer, GContext *ctx) {
137+
GRect bound = layer_get_frame(layer);
138+
draw_spiral_arc(ctx, GPoint(bound.size.w, bound.size.h), bound.size.w);
139+
}
140+
141+
static void arc2x2_layer_update_callback(Layer *layer, GContext *ctx) {
142+
GRect bound = layer_get_frame(layer);
143+
draw_spiral_arc(ctx, GPoint(0, bound.size.h), bound.size.w);
144+
}
145+
146+
static void arc1x1L_layer_update_callback(Layer *layer, GContext *ctx) {
147+
GRect bound = layer_get_frame(layer);
148+
draw_spiral_arc(ctx, GPoint(bound.size.w, 0), bound.size.w);
149+
}
150+
151+
static void arc1x1R_layer_update_callback(Layer *layer, GContext *ctx) {
152+
GRect bound = layer_get_frame(layer);
153+
draw_spiral_arc(ctx, GPoint(0, 0), bound.size.w);
154+
}
155+
156+
static void arc5x5_layer_update_callback(Layer *layer, GContext *ctx) {
157+
GRect bound = layer_get_frame(layer);
158+
draw_spiral_arc(ctx, GPoint(bound.size.w, 0), bound.size.w);
159+
}
51160

161+
static void fibo_layer_update_callback(Layer *layer, GContext *ctx) {
52162
GColor fill_color[] = {GColorWhite, GColorRed, GColorGreen, GColorBlue};
53163
int8_t fc1L = 0, fc1R = 0, fc2 = 0, fc3 = 0, fc5 = 0;
54164
int8_t h = s_curr_hour;
55165
int8_t m = s_curr_min / 5; // Since only values from 1-12 can be displayed
56166

167+
#if USE_FIXED_TIME_FOR_PUBLISHING_IMAGE
168+
h = 10;
169+
m = 30 / 5;
170+
#endif
171+
57172
// Determine what fill color to use in each box
58173
if (h >= 5) { fc5 |= 0x01; h -= 5; }
59174
if (h >= 3) { fc3 |= 0x01; h -= 3; }
@@ -96,10 +211,6 @@ static void grid_layer_update_callback(Layer *layer, GContext *ctx) {
96211
}
97212
}
98213

99-
// Draw spiral
100-
graphics_context_set_compositing_mode(ctx, GCompOpSet);
101-
graphics_draw_bitmap_in_rect(ctx, s_spiral_image, gbitmap_get_bounds(s_spiral_image));
102-
103214
// Draw the outline
104215
graphics_context_set_stroke_color(ctx, GColorDarkGray);
105216
graphics_context_set_stroke_width(ctx, 1);
@@ -135,83 +246,42 @@ static void charge_layer_update_callback(Layer *layer, GContext *ctx) {
135246
}
136247
}
137248

138-
static void main_window_load(Window *window) {
139-
// Get windows root layer and its bounds
140-
Layer *root_layer = window_get_root_layer(window);
141-
GRect root_bounds = layer_get_frame(root_layer);
142-
143-
// Create the grid layer
144-
s_grid_layer = layer_create(root_bounds);
145-
layer_set_update_proc(s_grid_layer, grid_layer_update_callback);
146-
147-
// Add it as a child layer to the Window's root layer
148-
layer_add_child(root_layer, s_grid_layer);
149-
150-
// Create time TextLayer
151-
s_time_layer = text_layer_create(GRect(root_bounds.origin.x, 65, root_bounds.size.w, 40));
152-
text_layer_set_background_color(s_time_layer, GColorClear);
153-
text_layer_set_text_color(s_time_layer, GColorBlack);
154-
155-
// Improve the layout to be more like a watchface
156-
text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
157-
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
158-
159-
// Add it as a child layer to the Window's root layer
160-
layer_add_child(root_layer, text_layer_get_layer(s_time_layer));
161-
162-
// Create charge layer
163-
s_charge_layer = layer_create(GRect(127, 142, 15, 22));
164-
layer_set_update_proc(s_charge_layer, charge_layer_update_callback);
165-
166-
// Add it as a child layer to the Window's root layer
167-
layer_add_child(root_layer, s_charge_layer);
168-
169-
// Createing bitmaps
170-
s_spiral_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SPIRAL);
171-
s_battery_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY);
172-
s_charging_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CHARGING);
173-
s_plugged_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PLUGGED);
174-
175-
// Make sure that the currnet time is displayed from the start
176-
update_time();
177-
}
178-
179-
static void main_window_unload(Window *window) {
180-
gbitmap_destroy(s_plugged_image);
181-
gbitmap_destroy(s_charging_image);
182-
gbitmap_destroy(s_battery_image);
183-
gbitmap_destroy(s_spiral_image);
184-
layer_destroy(s_charge_layer);
185-
text_layer_destroy(s_time_layer);
186-
layer_destroy(s_grid_layer);
187-
}
188-
189249
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
190250
update_time();
191251

192252
s_curr_hour = (tick_time->tm_hour > 12) ? tick_time->tm_hour - 12 : tick_time->tm_hour;
193253
s_curr_min = tick_time->tm_min;
194254

195-
layer_mark_dirty(s_grid_layer);
255+
layer_mark_dirty(s_fibo_layer);
196256
}
197257

198-
void battery_charge_handler(BatteryChargeState charge) {
258+
static void battery_charge_handler(BatteryChargeState charge) {
199259
layer_mark_dirty(s_charge_layer);
200260
}
201261

202-
void init(void) {
203-
// Create main Window element and assign to pointer
204-
s_main_window = window_create();
205-
window_set_background_color(s_main_window, GColorBlack);
206-
207-
// Set handlers to manage the elements inside the Window
208-
window_set_window_handlers(s_main_window, (WindowHandlers) {
209-
.load = main_window_load,
210-
.unload = main_window_unload
262+
void show_main(void) {
263+
initialise_ui();
264+
window_set_window_handlers(s_window, (WindowHandlers) {
265+
.unload = handle_window_unload,
211266
});
212-
213-
// Show the Window on the watch, with animated = true
214-
window_stack_push(s_main_window, true);
267+
window_stack_push(s_window, true);
268+
269+
// Set up layer callbacks
270+
layer_set_update_proc(s_fibo_layer, fibo_layer_update_callback);
271+
layer_set_update_proc(s_charge_layer, charge_layer_update_callback);
272+
layer_set_update_proc(s_arc3x3_layer, arc3x3_layer_update_callback);
273+
layer_set_update_proc(s_arc2x2_layer, arc2x2_layer_update_callback);
274+
layer_set_update_proc(s_arc1x1L_layer, arc1x1L_layer_update_callback);
275+
layer_set_update_proc(s_arc1x1R_layer, arc1x1R_layer_update_callback);
276+
layer_set_update_proc(s_arc5x5_layer, arc5x5_layer_update_callback);
277+
278+
// Create bitmaps
279+
s_battery_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BATTERY);
280+
s_charging_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_CHARGING);
281+
s_plugged_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PLUGGED);
282+
283+
// Make sure that the currnet time is displayed from the start
284+
update_time();
215285

216286
// Register with TickTimerService
217287
tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
@@ -220,14 +290,19 @@ void init(void) {
220290
battery_state_service_subscribe(battery_charge_handler);
221291
}
222292

223-
void deinit(void) {
224-
battery_state_service_unsubscribe();
293+
void hide_main(void) {
294+
window_stack_remove(s_window, true);
295+
296+
gbitmap_destroy(s_battery_image);
297+
gbitmap_destroy(s_charging_image);
298+
gbitmap_destroy(s_plugged_image);
299+
225300
tick_timer_service_unsubscribe();
226-
window_destroy(s_main_window);
301+
battery_state_service_unsubscribe();
227302
}
228303

229304
int main(void) {
230-
init();
305+
show_main();
231306
app_event_loop();
232-
deinit();
307+
hide_main();
233308
}

src/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void show_main(void);
2+
void hide_main(void);

0 commit comments

Comments
 (0)