Compare commits
1 Commits
c6454c5a5f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bfd88af248 |
@@ -1,11 +1,26 @@
|
|||||||
#include <pebble.h>
|
#include <pebble.h>
|
||||||
#include <pebble-effect-layer/pebble-effect-layer.h>
|
#include <pebble-effect-layer/pebble-effect-layer.h>
|
||||||
|
|
||||||
|
|
||||||
static Window *s_main_window;
|
static Window *s_main_window;
|
||||||
static TextLayer *s_time_layer;
|
static TextLayer *s_time_layer;
|
||||||
static TextLayer *s_date_layer;
|
static TextLayer *s_date_layer;
|
||||||
static TextLayer *s_cd_layer;
|
|
||||||
static EffectLayer *s_effect_layer;
|
static EffectLayer *s_effect_layer;
|
||||||
|
static Layer *s_battery_layer;
|
||||||
|
static Layer *s_countdown_layer;
|
||||||
|
static int s_battery_level;
|
||||||
|
|
||||||
|
static void battery_update_proc(Layer *layer, GContext *ctx) {
|
||||||
|
GRect bounds = layer_get_bounds(layer);
|
||||||
|
|
||||||
|
int width = (s_battery_level * 114)/ 100;
|
||||||
|
|
||||||
|
graphics_context_set_fill_color(ctx, GColorWhite);
|
||||||
|
graphics_fill_rect(ctx,bounds,0,GCornerNone);
|
||||||
|
|
||||||
|
graphics_context_set_fill_color(ctx,GColorWhite);
|
||||||
|
graphics_fill_rect(ctx, GRect(0,0,width,bounds.size.h), 0, GCornerNone);
|
||||||
|
}
|
||||||
|
|
||||||
static void main_window_load(Window *window) {
|
static void main_window_load(Window *window) {
|
||||||
Layer *window_layer = window_get_root_layer(window);
|
Layer *window_layer = window_get_root_layer(window);
|
||||||
@@ -43,26 +58,19 @@ static void main_window_load(Window *window) {
|
|||||||
// Add it as a child layer to the Window's root layer
|
// Add it as a child layer to the Window's root layer
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
|
layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
|
||||||
|
|
||||||
s_cd_layer = text_layer_create(
|
// Battery
|
||||||
GRect(0, PBL_IF_ROUND_ELSE(18,12), bounds.size.w, 50)
|
s_battery_layer = layer_create(GRect(14,54,115,2));
|
||||||
);
|
layer_set_update_proc(s_battery_layer, battery_update_proc);
|
||||||
|
|
||||||
// Improve the layout to be more like a watchface
|
layer_add_child(window_layer, s_battery_layer);
|
||||||
text_layer_set_background_color(s_cd_layer, GColorClear);
|
layer_mark_dirty(s_battery_layer);
|
||||||
text_layer_set_text_color(s_cd_layer, GColorWhite);
|
|
||||||
text_layer_set_text(s_cd_layer, "-----==========");
|
|
||||||
text_layer_set_font(s_cd_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
|
|
||||||
text_layer_set_text_alignment(s_cd_layer, GTextAlignmentCenter);
|
|
||||||
|
|
||||||
// Add it as a child layer to the Window's root layer
|
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_cd_layer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void main_window_unload(Window *window) {
|
static void main_window_unload(Window *window) {
|
||||||
text_layer_destroy(s_time_layer);
|
text_layer_destroy(s_time_layer);
|
||||||
text_layer_destroy(s_date_layer);
|
text_layer_destroy(s_date_layer);
|
||||||
text_layer_destroy(s_cd_layer);
|
|
||||||
effect_layer_destroy(s_effect_layer);
|
effect_layer_destroy(s_effect_layer);
|
||||||
|
layer_destroy(s_battery_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_time() {
|
static void update_time() {
|
||||||
@@ -85,6 +93,11 @@ static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
|
|||||||
update_time();
|
update_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void battery_callback(BatteryChargeState state) {
|
||||||
|
s_battery_level = state.charge_percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
s_main_window = window_create();
|
s_main_window = window_create();
|
||||||
|
|
||||||
@@ -96,14 +109,15 @@ static void init() {
|
|||||||
window_stack_push(s_main_window, true);
|
window_stack_push(s_main_window, true);
|
||||||
|
|
||||||
tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
|
tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
|
||||||
|
battery_state_service_subscribe(battery_callback);
|
||||||
update_time();
|
update_time();
|
||||||
|
battery_callback(battery_state_service_peek());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deinit() {
|
static void deinit() {
|
||||||
window_destroy(s_main_window);
|
window_destroy(s_main_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
init();
|
init();
|
||||||
app_event_loop();
|
app_event_loop();
|
||||||
|
|||||||
Reference in New Issue
Block a user