Simplify part loading
This commit is contained in:
67
src/c/main.c
67
src/c/main.c
@@ -17,10 +17,8 @@ static BitmapLayer *s_guy_butt_layer;
|
||||
// declare silly guy parts
|
||||
static GColor8 s_random_color_current;
|
||||
static GColor8 s_random_color_next;
|
||||
static GBitmap *s_head_current;
|
||||
static GBitmap *s_butt_current;
|
||||
static GBitmap *s_head_next;
|
||||
static GBitmap *s_butt_next;
|
||||
static GBitmap *s_head;
|
||||
static GBitmap *s_butt;
|
||||
static GBitmap *s_bt0_icon;
|
||||
static GBitmap *s_bt1_icon;
|
||||
|
||||
@@ -194,22 +192,19 @@ static void schedule_guy_animation(Animation *raise_tmpl, Animation *out_tmpl, A
|
||||
}
|
||||
|
||||
static void update_minute_30_out_handler(Animation *animation, bool finished, void *context) {
|
||||
// destroy and reassign current
|
||||
gbitmap_destroy(s_butt_current);
|
||||
s_butt_current = s_butt_next;
|
||||
// destroy and reassign
|
||||
gbitmap_destroy(s_butt);
|
||||
s_butt = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
|
||||
|
||||
// swap colors
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_next, s_butt_current, NULL);
|
||||
replace_gbitmap_color(s_random_color_current, s_random_color_next, s_head_current, NULL);
|
||||
s_random_color_current = s_random_color_next; // must be referenced for later replacement
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_next, s_butt, NULL);
|
||||
replace_gbitmap_color(s_random_color_current, s_random_color_next, s_head, NULL);
|
||||
s_random_color_current = s_random_color_next;
|
||||
s_random_color_next = s_dark_bg_colors[rand() % s_color_count];
|
||||
|
||||
// force update bitmap layers
|
||||
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
|
||||
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
|
||||
|
||||
// calc next values
|
||||
s_butt_next = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
|
||||
s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color
|
||||
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt);
|
||||
bitmap_layer_set_bitmap(s_guy_head_layer, s_head);
|
||||
}
|
||||
|
||||
static void update_minute_30() {
|
||||
@@ -218,22 +213,19 @@ static void update_minute_30() {
|
||||
}
|
||||
|
||||
static void update_minute_60_out_handler(Animation *animation, bool finished, void *context) {
|
||||
// destroy and reassign current
|
||||
gbitmap_destroy(s_head_current);
|
||||
s_head_current = s_head_next;
|
||||
// destroy and reassign
|
||||
gbitmap_destroy(s_head);
|
||||
s_head = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
|
||||
|
||||
// swap colors
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_next, s_head_current, NULL);
|
||||
replace_gbitmap_color(s_random_color_current, s_random_color_next, s_butt_current, NULL);
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_next, s_head, NULL);
|
||||
replace_gbitmap_color(s_random_color_current, s_random_color_next, s_butt, NULL);
|
||||
s_random_color_current = s_random_color_next;
|
||||
s_random_color_next = s_dark_bg_colors[rand() % s_color_count];
|
||||
|
||||
// force update bitmap layers
|
||||
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
|
||||
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
|
||||
|
||||
// calc next values
|
||||
s_head_next = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
|
||||
s_random_color_next = s_dark_bg_colors[rand() % s_color_count]; // next color
|
||||
bitmap_layer_set_bitmap(s_guy_head_layer, s_head);
|
||||
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt);
|
||||
}
|
||||
|
||||
static void update_minute_60() {
|
||||
@@ -274,15 +266,14 @@ static void main_window_load(Window *window) {
|
||||
s_guy_butt_layer = bitmap_layer_create(s_guy_butt_grect_on_screen_resting);
|
||||
bitmap_layer_set_compositing_mode(s_guy_head_layer, GCompOpSet);
|
||||
bitmap_layer_set_alignment(s_guy_head_layer, GAlignLeft);
|
||||
bitmap_layer_set_bitmap(s_guy_head_layer, s_head_current);
|
||||
bitmap_layer_set_bitmap(s_guy_head_layer, s_head);
|
||||
bitmap_layer_set_compositing_mode(s_guy_butt_layer, GCompOpSet);
|
||||
bitmap_layer_set_alignment(s_guy_butt_layer, GAlignTopLeft);
|
||||
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt_current);
|
||||
bitmap_layer_set_bitmap(s_guy_butt_layer, s_butt);
|
||||
|
||||
// create time bar layer
|
||||
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);
|
||||
@@ -373,15 +364,13 @@ static void init() {
|
||||
window_set_background_color(s_main_window, GColorBlack);
|
||||
|
||||
// load initial batch of silly guy parts into memory
|
||||
s_head_current = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
|
||||
s_butt_current = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
|
||||
s_head_next = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
|
||||
s_butt_next = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
|
||||
s_head = gbitmap_create_with_resource(s_random_heads[rand() % s_head_count]);
|
||||
s_butt = gbitmap_create_with_resource(s_random_butts[rand() % s_butt_count]);
|
||||
|
||||
// pick starting colors
|
||||
s_random_color_current = s_dark_bg_colors[rand() % s_color_count];
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_current, s_head_current, NULL);
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_current, s_butt_current, NULL);
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_current, s_head, NULL);
|
||||
replace_gbitmap_color(GColorGreen, s_random_color_current, s_butt, NULL);
|
||||
// don't overwrite current color, as it will need to be replaced
|
||||
s_random_color_next = s_dark_bg_colors[rand() % s_color_count];
|
||||
|
||||
@@ -480,10 +469,8 @@ static void deinit() {
|
||||
fonts_unload_custom_font(s_custom_font);
|
||||
|
||||
// destroy gbitmaps
|
||||
gbitmap_destroy(s_head_current);
|
||||
gbitmap_destroy(s_butt_current);
|
||||
gbitmap_destroy(s_head_next);
|
||||
gbitmap_destroy(s_butt_next);
|
||||
gbitmap_destroy(s_head);
|
||||
gbitmap_destroy(s_butt);
|
||||
gbitmap_destroy(s_bt0_icon);
|
||||
gbitmap_destroy(s_bt1_icon);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user