Created
April 12, 2013 23:34
-
-
Save mmdumi/5376026 to your computer and use it in GitHub Desktop.
Pebble watchface inspired by Phosphor watch. Screenshot: http://c.wip.ro/image/263O2t2q2n1D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pebble_os.h" | |
#include "pebble_app.h" | |
#include "pebble_fonts.h" | |
#include "resource_ids.auto.h" | |
#define MY_UUID { 0xCE, 0xC0, 0x94, 0xD9, 0xE7, 0xC8, 0x4E, 0xFA, 0xB8, 0xAD, 0xA1, 0x41, 0xC8, 0x6A, 0x7D, 0xB0 } | |
PBL_APP_INFO(MY_UUID, | |
"Phosphor", "Wip Interactive", | |
1, 0, 0, | |
APP_INFO_WATCH_FACE); | |
Window window; | |
TextLayer hourLayer; | |
TextLayer dotsLayer; | |
TextLayer minuteLayer; | |
int hour = -1; | |
void display_time(PblTm *t) | |
{ | |
static char timeText[] = "00"; | |
static char hourText[] = "00"; | |
string_format_time(timeText, sizeof(timeText), "%M", t); | |
text_layer_set_text(&minuteLayer, timeText); | |
if (hour != t->tm_hour) { | |
hour = t->tm_hour; | |
string_format_time(hourText, sizeof(hourText), "%I", t); | |
text_layer_set_text(&hourLayer, hourText); | |
} | |
} | |
void handle_init(AppContextRef ctx) { | |
(void)ctx; | |
window_init(&window, "Phosphor"); | |
window_stack_push(&window, true /* Animated */); | |
window_set_background_color(&window, GColorBlack); | |
resource_init_current_app(&APP_RESOURCES); | |
// Custom font | |
GFont custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OSP_DIN_44)); | |
text_layer_init(&hourLayer, GRect(0, 65, 144-65, 50)); | |
//text_layer_set_text(&hourLayer, "1"); | |
text_layer_set_font(&hourLayer, custom_font); //fonts_get_system_font(FONT_KEY_GOTHAM_34_LIGHT_SUBSET)); | |
text_layer_set_text_color(&hourLayer, GColorWhite); | |
text_layer_set_background_color(&hourLayer, GColorClear); | |
text_layer_set_text_alignment(&hourLayer, GTextAlignmentRight); | |
GRect rect = layer_get_frame(&hourLayer.layer); | |
rect.origin.x = rect.size.w; | |
rect.size.w = 20; | |
text_layer_init(&dotsLayer, rect); | |
text_layer_set_text(&dotsLayer, ":"); | |
text_layer_set_font(&dotsLayer, custom_font); //fonts_get_system_font(FONT_KEY_GOTHAM_34_LIGHT_SUBSET)); | |
text_layer_set_text_color(&dotsLayer, GColorWhite); | |
text_layer_set_background_color(&dotsLayer, GColorClear); | |
text_layer_set_text_alignment(&dotsLayer, GTextAlignmentCenter); | |
rect = layer_get_frame(&dotsLayer.layer); | |
rect.origin.x += rect.size.w; | |
rect.size.w = 144-rect.origin.x; | |
text_layer_init(&minuteLayer, rect); | |
//text_layer_set_text(&minuteLayer, "50"); | |
text_layer_set_font(&minuteLayer, custom_font); //fonts_get_system_font(FONT_KEY_GOTHAM_34_LIGHT_SUBSET)); | |
text_layer_set_text_color(&minuteLayer, GColorWhite); | |
text_layer_set_background_color(&minuteLayer, GColorClear); | |
text_layer_set_text_alignment(&minuteLayer, GTextAlignmentLeft); | |
PblTm t; | |
get_time(&t); | |
display_time(&t); | |
layer_add_child(&window.layer, &hourLayer.layer); | |
layer_add_child(&window.layer, &dotsLayer.layer); | |
layer_add_child(&window.layer, &minuteLayer.layer); | |
} | |
void handle_deinit(AppContextRef ctx) { | |
(void)ctx; | |
} | |
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *t) { | |
(void)ctx; | |
display_time(t->tick_time); | |
} | |
void pbl_main(void *params) { | |
PebbleAppHandlers handlers = { | |
.init_handler = &handle_init, | |
.tick_info = { | |
.tick_handler = &handle_minute_tick, | |
.tick_units = MINUTE_UNIT | |
} | |
}; | |
app_event_loop(params, &handlers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment