Scale more dynamically; add Chalk support
This commit is contained in:
87
src/c/main.c
87
src/c/main.c
@@ -24,21 +24,36 @@ static GBitmap *s_butt_next;
|
||||
static GBitmap *s_bt_icon;
|
||||
|
||||
// declare positions for animation stages
|
||||
static GRect s_guy_head_grect_on_screen_raised = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(-15, -31), 260, 115);
|
||||
static GRect s_guy_head_grect_off_screen_raised = GRect(PBL_IF_ROUND_ELSE(-260, -230), PBL_IF_ROUND_ELSE(-15, -31), 260, 115);
|
||||
static GRect s_guy_head_grect_on_screen_resting = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(0, -16), 260, 115);
|
||||
static GRect s_guy_butt_grect_on_screen_raised = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(160, 144), 260, 115);
|
||||
static GRect s_guy_butt_grect_off_screen_raised = GRect(PBL_IF_ROUND_ELSE(260, 170), PBL_IF_ROUND_ELSE(160, 144), 260, 115);
|
||||
static GRect s_guy_butt_grect_on_screen_resting = GRect(PBL_IF_ROUND_ELSE(0, -30), PBL_IF_ROUND_ELSE(145, 129), 260, 115);
|
||||
static GRect s_guy_head_grect_on_screen_raised;
|
||||
static GRect s_guy_head_grect_off_screen_raised;
|
||||
static GRect s_guy_head_grect_on_screen_resting;
|
||||
static GRect s_guy_butt_grect_on_screen_raised;
|
||||
static GRect s_guy_butt_grect_off_screen_raised;
|
||||
static GRect s_guy_butt_grect_on_screen_resting;
|
||||
#if PBL_DISPLAY_WIDTH == 180
|
||||
// 8x+20(4-x)+20,
|
||||
// where x=one_count,
|
||||
// 8=width of "1",
|
||||
// first 20=width of other,
|
||||
// second 20=combined width of spaces+colon
|
||||
static const uint8_t s_max_time_width = 100;
|
||||
#else
|
||||
// 10x+25(4-x)+21,
|
||||
// where x=one_count,
|
||||
// 10=width of "1",
|
||||
// 25=width of other,
|
||||
// 21=combined width of spaces+colon
|
||||
static const uint8_t s_max_time_width = 121;
|
||||
#endif
|
||||
static const uint8_t s_date_pos_x = 0;
|
||||
static const uint8_t s_date_pos_y = PBL_IF_ROUND_ELSE(121, 105);
|
||||
static const uint8_t s_date_bt_width = PBL_IF_ROUND_ELSE(69, 39);
|
||||
static const uint8_t s_date_height = 14;
|
||||
static GRect s_date_grect_a = GRect(s_date_pos_x, s_date_pos_y, s_date_bt_width, s_date_height);
|
||||
static const uint8_t s_bt_pos_x = PBL_IF_ROUND_ELSE(191, 161);
|
||||
static const uint8_t s_bt_pos_y = PBL_IF_ROUND_ELSE(118, 102);
|
||||
static const uint8_t s_bt_height = 24;
|
||||
static GRect s_bt_grect_a = GRect(s_bt_pos_x, s_bt_pos_y, s_date_bt_width, s_bt_height);
|
||||
static uint8_t s_date_pos_y;
|
||||
static uint8_t s_date_bt_width;
|
||||
static GRect s_date_grect_a;
|
||||
static uint8_t s_bt_pos_x;
|
||||
static uint8_t s_bt_pos_y;
|
||||
static GRect s_bt_grect_a;
|
||||
static GRect s_date_grect_b;
|
||||
static GRect s_bt_grect_b;
|
||||
|
||||
@@ -50,7 +65,11 @@ static Animation *s_butt_raise_template;
|
||||
static Animation *s_butt_out_template;
|
||||
|
||||
// declare lookup tables
|
||||
#if PBL_DISPLAY_WIDTH == 180
|
||||
static const uint8_t s_ones_offset[] = {0, 3, 6, 9, 12};
|
||||
#else
|
||||
static const uint8_t s_ones_offset[] = {0, 4, 7, 11, 15};
|
||||
#endif
|
||||
static const uint8_t s_head_count = 25;
|
||||
static const uint32_t s_random_heads[] = {
|
||||
RESOURCE_ID_H001, RESOURCE_ID_H002, RESOURCE_ID_H003, RESOURCE_ID_H004,
|
||||
@@ -234,7 +253,16 @@ static void time_bar_update_proc(Layer *layer, GContext *ctx) {
|
||||
|
||||
// define contents of the Window upon load
|
||||
static void main_window_load(Window *window) {
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
// dynamically calculate coordinates for silly guy animations
|
||||
int8_t part_x_on_screen = (260 - PBL_DISPLAY_WIDTH) / -2;
|
||||
int8_t head_y_resting = (260 - PBL_DISPLAY_HEIGHT) / -2;
|
||||
int8_t head_y_rasied = head_y_resting - 15;
|
||||
s_guy_head_grect_on_screen_raised = GRect(part_x_on_screen, head_y_rasied, 260, 115);
|
||||
s_guy_head_grect_off_screen_raised = GRect(-PBL_DISPLAY_WIDTH + part_x_on_screen, head_y_rasied, 260, 115);
|
||||
s_guy_head_grect_on_screen_resting = GRect(part_x_on_screen, head_y_resting, 260, 115);
|
||||
s_guy_butt_grect_on_screen_raised = GRect(part_x_on_screen, head_y_resting + 180, 260, 115);
|
||||
s_guy_butt_grect_off_screen_raised = GRect(PBL_DISPLAY_WIDTH + part_x_on_screen, head_y_resting + 160, 260, 115);
|
||||
s_guy_butt_grect_on_screen_resting = GRect(part_x_on_screen, head_y_resting + 145, 260, 115);
|
||||
|
||||
// format silly guy layers
|
||||
s_guy_head_layer = bitmap_layer_create(s_guy_head_grect_on_screen_resting);
|
||||
@@ -247,11 +275,12 @@ static void main_window_load(Window *window) {
|
||||
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
|
||||
|
||||
// create time bar layer
|
||||
s_time_bar_layer = layer_create(GRect(0, PBL_IF_ROUND_ELSE(115, 99), PBL_IF_ROUND_ELSE(260, 200), 30));
|
||||
s_time_bar_layer = layer_create(GRect(0, PBL_DISPLAY_HEIGHT / 2 - 15, PBL_DISPLAY_WIDTH, 30));
|
||||
layer_set_update_proc(s_time_bar_layer, time_bar_update_proc);
|
||||
text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
|
||||
|
||||
// add layers as children to window
|
||||
Layer *window_layer = window_get_root_layer(window);
|
||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_head_layer));
|
||||
layer_add_child(window_layer, bitmap_layer_get_layer(s_guy_butt_layer));
|
||||
layer_add_child(window_layer, s_time_bar_layer);
|
||||
@@ -343,15 +372,35 @@ static void init() {
|
||||
// don't overwrite current color, as it will need to be replaced
|
||||
s_random_color_next = s_dark_bg_colors[rand() % s_color_count];
|
||||
|
||||
// load custom font
|
||||
// load custom font
|
||||
#if PBL_DISPLAY_WIDTH == 180
|
||||
s_custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_RETRO_COMPUTER_28));
|
||||
#else
|
||||
s_custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_RETRO_COMPUTER_34));
|
||||
#endif
|
||||
|
||||
// load bluetooth indicator
|
||||
s_bt_icon = gbitmap_create_with_resource(RESOURCE_ID_BT);
|
||||
|
||||
// pre-create layers used in update_minute_1
|
||||
//// time
|
||||
s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(109, 93), PBL_IF_ROUND_ELSE(260, 200), 34));
|
||||
// dynamically calculate coordinates for date/bt indicators
|
||||
s_date_pos_y = PBL_DISPLAY_HEIGHT / 2 - 9;
|
||||
s_date_bt_width = (PBL_DISPLAY_WIDTH - s_max_time_width) / 2;
|
||||
s_date_grect_a = GRect(s_date_pos_x, s_date_pos_y, s_date_bt_width, s_date_height);
|
||||
#if PBL_DISPLAY_WIDTH == 180
|
||||
s_bt_pos_x = s_date_bt_width + s_max_time_width;
|
||||
#else
|
||||
s_bt_pos_x = s_date_bt_width + s_max_time_width + 1;
|
||||
#endif
|
||||
s_bt_pos_y = (PBL_DISPLAY_HEIGHT / 2) - 12;
|
||||
s_bt_grect_a = GRect(s_bt_pos_x, s_bt_pos_y, s_date_bt_width, s_bt_height);
|
||||
|
||||
// pre-create layers used in update_minute_1
|
||||
//// time
|
||||
#if PBL_DISPLAY_WIDTH == 180
|
||||
s_time_layer = text_layer_create(GRect(0, (PBL_DISPLAY_HEIGHT / 2) - 18, PBL_DISPLAY_WIDTH, 28));
|
||||
#else
|
||||
s_time_layer = text_layer_create(GRect(0, (PBL_DISPLAY_HEIGHT / 2) - 21, PBL_DISPLAY_WIDTH, 34));
|
||||
#endif
|
||||
text_layer_set_background_color(s_time_layer, GColorClear);
|
||||
text_layer_set_font(s_time_layer, s_custom_font);
|
||||
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
|
||||
@@ -366,7 +415,7 @@ static void init() {
|
||||
bitmap_layer_set_alignment(s_bt_layer, GAlignCenter);
|
||||
bitmap_layer_set_bitmap(s_bt_layer, s_bt_icon);
|
||||
//// DEBUG memory usage layer
|
||||
s_memory_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(220, 190), PBL_IF_ROUND_ELSE(260, 200), 14));
|
||||
s_memory_layer = text_layer_create(GRect(0, PBL_DISPLAY_HEIGHT - 24, PBL_DISPLAY_WIDTH, 14));
|
||||
text_layer_set_background_color(s_memory_layer, GColorClear);
|
||||
text_layer_set_font(s_memory_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
|
||||
text_layer_set_text_color(s_memory_layer, GColorWhite);
|
||||
|
||||
Reference in New Issue
Block a user