From e60aa7efdf7d3e8c52883d65913239368f754de8 Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Sat, 9 Jul 2016 22:58:02 -0400 Subject: [PATCH] Add animation window --- CMakeLists.txt | 20 ++- package.json | 5 + resources/confirm_sequence.pdc | Bin 0 -> 8698 bytes src/main.c | 2 +- .../action/action_menu_layer.c | 0 .../action/action_menu_layer.h | 0 .../action/action_window.c | 12 +- .../action/action_window.h | 2 + src/{windows => screens}/action/style.h | 2 +- src/screens/animation/animation_window.c | 167 ++++++++++++++++++ src/screens/animation/animation_window.h | 35 ++++ src/screens/animation/style.h | 23 +++ src/{windows => screens}/list/list_layer.c | 0 src/{windows => screens}/list/list_layer.h | 0 src/{windows => screens}/list/list_window.c | 1 + src/{windows => screens}/list/list_window.h | 0 src/{windows => screens}/list/style.h | 0 17 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 resources/confirm_sequence.pdc rename src/{windows => screens}/action/action_menu_layer.c (100%) rename src/{windows => screens}/action/action_menu_layer.h (100%) rename src/{windows => screens}/action/action_window.c (89%) rename src/{windows => screens}/action/action_window.h (90%) rename src/{windows => screens}/action/style.h (95%) create mode 100644 src/screens/animation/animation_window.c create mode 100644 src/screens/animation/animation_window.h create mode 100644 src/screens/animation/style.h rename src/{windows => screens}/list/list_layer.c (100%) rename src/{windows => screens}/list/list_layer.h (100%) rename src/{windows => screens}/list/list_window.c (98%) rename src/{windows => screens}/list/list_window.h (100%) rename src/{windows => screens}/list/style.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9cd15f..cd02316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,16 +14,20 @@ set(SOURCE_FILES src/main.c src/network.c src/network.h - src/windows/list/list_window.c - src/windows/list/list_window.h - src/windows/list/style.h src/util.h - src/windows/action/action_window.c - src/windows/action/action_window.h - src/windows/action/style.h src/layers/border_layer.c src/layers/border_layer.h - src/windows/action/action_menu_layer.c - src/windows/action/action_menu_layer.h src/windows/list/list_layer.c src/windows/list/list_layer.h) + src/screens/list/list_window.c + src/screens/list/list_window.h + src/screens/list/style.h + src/screens/action/action_window.c + src/screens/action/action_window.h + src/screens/action/style.h + src/screens/action/action_menu_layer.c + src/screens/action/action_menu_layer.h + src/screens/list/list_layer.c + src/screens/list/list_layer.h + src/screens/animation/animation_window.c + src/screens/animation/animation_window.h src/screens/animation/style.h) add_executable(hello ${SOURCE_FILES}) \ No newline at end of file diff --git a/package.json b/package.json index 4c559e0..2aa15be 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,11 @@ ], "resources": { "media": [ + { + "type": "raw", + "name": "CONFIRM_SEQUENCE", + "file": "confirm_sequence.pdc" + } ] } } diff --git a/resources/confirm_sequence.pdc b/resources/confirm_sequence.pdc new file mode 100644 index 0000000000000000000000000000000000000000..63588f7daa661d744eadf76585bda384f623e3af GIT binary patch literal 8698 zcmeI1d2p6R62_nIFUS!{fFvdeD&C4H5)LJDs3<5PAd19A0TGBCY5^jOkN`nKAmIwj zf}$dq7{voY5m1mz?lW=-Nw~s|+{)oP`@A9F%==Yp_y4V;Qj@C8+cVw2>7JgRN$bZO zKYR8TK+u{$f@-)8We~v9Faw06zO0kksH7{&Y_16DZgA6OGK}NF%8R3e7hFY7|L2cJD1B+O4eC`U099hT;BinT(%FWV2 z8o43GijsKLVTDo0Nq7Z`SD4ruq^gvco8AX+>lcNH#L~L6IX%X!losyYH7S(!fc~z;dE~>m-VSRF&#d zQJT9U#j2|&w5K7PB}+hp#IuD|S8dT$4&x3|jKes&LvGWi@*OEQNDOH=$mfXBWu*1w zEZHSwux6ZCNS7i$pC#Z?s(3Ugsc52&XoSxrRi%zZ%F|Aw8&xN=)0$ZfwLre(lC5%! zk%b>we{OIcK_`ZgeNT$@5=DxQ@&%&wXHq2M8Pe9E$`43eU8-s;@#HL73M=8O74anc zEF<_qktp>fNgj3`1+th{t#?Kgv%85lCVNQDyq#Y4ffVyuJXblvt+ZE&*OPM6GSp`a zq#vvJiX_`4b5K#2qMy8g=j0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n!@wXs6i9Xwn@F|IPqvVe__I!>&%!*Z zt2N&Q-UxH~A~}l`M@X?sN~mGxkKqnWVUb-Q<8YR=o}49{AbWYK4`;PrTDG$KvsR_h z%Pw)$Q`9$>j?OLAmx|*|8|#Jt{GgoGIZ5(Z di -#include "windows/list/list_window.h" +#include "screens/list/list_window.h" int main(void) { diff --git a/src/windows/action/action_menu_layer.c b/src/screens/action/action_menu_layer.c similarity index 100% rename from src/windows/action/action_menu_layer.c rename to src/screens/action/action_menu_layer.c diff --git a/src/windows/action/action_menu_layer.h b/src/screens/action/action_menu_layer.h similarity index 100% rename from src/windows/action/action_menu_layer.h rename to src/screens/action/action_menu_layer.h diff --git a/src/windows/action/action_window.c b/src/screens/action/action_window.c similarity index 89% rename from src/windows/action/action_window.c rename to src/screens/action/action_window.c index b4a5a0d..3960cd3 100644 --- a/src/windows/action/action_window.c +++ b/src/screens/action/action_window.c @@ -23,10 +23,17 @@ #include "../../util.h" #include "action_menu_layer.h" #include "style.h" +#include "../animation/animation_window.h" static void on_select(void *callback_context) { - window_stack_pop(true); + struct ActionWindow *window = callback_context; + + ANIMATION_WINDOW_destroy(window->animation_window); + window->animation_window = ANIMATION_WINDOW_create( + RESOURCE_ID_CONFIRM_SEQUENCE); + + window_stack_push(window->animation_window->raw_window, true); } static int add_menu_layer(struct ActionWindow *window, @@ -89,6 +96,7 @@ static void on_unload(Window *raw_window) struct ActionWindow *window = window_get_user_data(raw_window); ACTION_MENU_LAYER_destroy(window->menu_layer); BORDER_LAYER_destroy(window->border_layer); + ANIMATION_WINDOW_destroy(window->animation_window); } static void set_raw_window_handlers(Window *raw_window) @@ -115,6 +123,8 @@ struct ActionWindow *ACTION_WINDOW_create() window_set_user_data(raw_window, window); set_raw_window_handlers(raw_window); + window->animation_window = 0; + return window; } diff --git a/src/windows/action/action_window.h b/src/screens/action/action_window.h similarity index 90% rename from src/windows/action/action_window.h rename to src/screens/action/action_window.h index 766ad5c..9879d51 100644 --- a/src/windows/action/action_window.h +++ b/src/screens/action/action_window.h @@ -26,6 +26,8 @@ struct ActionWindow struct ActionMenuLayer *menu_layer; struct BorderLayer *border_layer; + + struct AnimationWindow *animation_window; }; struct ActionWindow* ACTION_WINDOW_create(); diff --git a/src/windows/action/style.h b/src/screens/action/style.h similarity index 95% rename from src/windows/action/style.h rename to src/screens/action/style.h index a4644fb..f9555a8 100644 --- a/src/windows/action/style.h +++ b/src/screens/action/style.h @@ -31,6 +31,6 @@ #define BORDER_COLOR GColorFolly -#define BORDER_WIDTH 10 +#define BORDER_WIDTH 6 #define CELL_HEIGHT 36 \ No newline at end of file diff --git a/src/screens/animation/animation_window.c b/src/screens/animation/animation_window.c new file mode 100644 index 0000000..4385ea0 --- /dev/null +++ b/src/screens/animation/animation_window.c @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +#include +#include "animation_window.h" +#include "style.h" +#include "../../util.h" + +#define FRAME_DELAY 33 + +void next_frame(struct AnimationWindow *window); + +static void on_tick(void *context) +{ + struct AnimationWindow *window = context; + window->timer = 0; + + if(window->current_frame + 1 < window->num_frames) + next_frame(window); + else + { + window_stack_pop(true); + window_stack_pop(true); + } +} + +static void set_timer(struct AnimationWindow *window) +{ + window->timer = app_timer_register(FRAME_DELAY, on_tick, window); +} + +void next_frame(struct AnimationWindow *window) +{ + window->current_frame++; + layer_mark_dirty(window->animation_layer); + set_timer(window); +} + +static void update_proc(Layer *layer, GContext *ctx) +{ + void **data_region = layer_get_data(layer); + struct AnimationWindow *window = *data_region; + + GRect bounds = layer_get_bounds(layer); + GSize seq_bounds = gdraw_command_sequence_get_bounds_size(window->sequence); + + GDrawCommandFrame *frame = gdraw_command_sequence_get_frame_by_index( + window->sequence, window->current_frame); + + if(!frame) return; + + uint16_t x = (uint16_t) ((bounds.size.w - seq_bounds.w) / 2); + uint16_t y = (uint16_t) ((bounds.size.h - seq_bounds.h) / 2); + gdraw_command_frame_draw(ctx, window->sequence, frame, GPoint(x, y)); +} + +static void on_load(Window *raw_window) +{ + struct AnimationWindow *window = window_get_user_data(raw_window); + struct Layer *root_layer = window_get_root_layer(raw_window); + GRect bounds = layer_get_bounds(root_layer); + + + int16_t animation_y = (int16_t) (bounds.size.h * 5 / 6); + GRect animation_bounds = GRect(bounds.origin.x, bounds.origin.y, + bounds.size.w, animation_y); + + int16_t text_y = (int16_t) (bounds.size.h * 6 / 10); + GRect text_bounds = GRect((int16_t) (bounds.origin.x + PADDING), text_y, + (int16_t) (bounds.size.w - 2 * PADDING), bounds.size.h - text_y); + + window->animation_layer = layer_create_with_data(animation_bounds, + sizeof(struct AnimationWindow *)); + + void **data_region = layer_get_data(window->animation_layer); + *data_region = window; + + window->text_layer = text_layer_create(text_bounds); + text_layer_set_text(window->text_layer, "Checkmark Added"); + text_layer_set_background_color(window->text_layer, BACKGROUND_COLOR); + text_layer_set_text_color(window->text_layer, GColorBlack); + text_layer_set_text_alignment(window->text_layer, GTextAlignmentCenter); + text_layer_set_overflow_mode(window->text_layer, GTextOverflowModeWordWrap); + + GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); + text_layer_set_font(window->text_layer, font); + + layer_set_update_proc(window->animation_layer, update_proc); + layer_add_child(root_layer, text_layer_get_layer(window->text_layer)); + layer_add_child(root_layer, window->animation_layer); +} + +static void on_unload(Window *raw_window) +{ + struct AnimationWindow *window = window_get_user_data(raw_window); + layer_destroy(window->animation_layer); + text_layer_destroy(window->text_layer); + if(window->timer) app_timer_cancel(window->timer); +} + +static int set_sequence(struct AnimationWindow *window, uint32_t sequence_id) +{ + int rval = 0; + window->sequence = gdraw_command_sequence_create_with_resource(sequence_id); + abort_if(!window->sequence, "gdraw_command_sequence_create failed"); + + window->current_frame = 0; + window->num_frames = gdraw_command_sequence_get_num_frames( + window->sequence); + +CLEANUP: + return rval; +} + +struct AnimationWindow *ANIMATION_WINDOW_create(uint32_t sequence_id) +{ + struct AnimationWindow *window = 0; + window = malloc(sizeof(struct AnimationWindow)); + if(!window) return NULL; + + set_sequence(window, sequence_id); + set_timer(window); + + window->animation_layer = 0; + window->text_layer = 0; + + struct Window *raw_window = window_create(); + if(!raw_window) return NULL; + + window->raw_window = raw_window; + + window_set_user_data(raw_window, window); + window_set_window_handlers(raw_window, (WindowHandlers) { + .load = on_load, + .unload = on_unload, + }); + + window_set_background_color(raw_window, BACKGROUND_COLOR); + + return window; +} + +void ANIMATION_WINDOW_destroy(struct AnimationWindow *window) +{ + if(!window) return; + window_destroy(window->raw_window); + gdraw_command_sequence_destroy(window->sequence); + //app_timer_cancel(window->timer); + free(window); +} + + diff --git a/src/screens/animation/animation_window.h b/src/screens/animation/animation_window.h new file mode 100644 index 0000000..b3a444c --- /dev/null +++ b/src/screens/animation/animation_window.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +#pragma once + +struct AnimationWindow +{ + uint32_t current_frame; + uint32_t num_frames;// + + struct Layer *animation_layer; + struct TextLayer *text_layer; + struct AppTimer *timer;// + struct GDrawCommandSequence *sequence;// + struct Window *raw_window;// +}; + +struct AnimationWindow *ANIMATION_WINDOW_create(uint32_t sequence_id); + +void ANIMATION_WINDOW_destroy(struct AnimationWindow *window); \ No newline at end of file diff --git a/src/screens/animation/style.h b/src/screens/animation/style.h new file mode 100644 index 0000000..f38513e --- /dev/null +++ b/src/screens/animation/style.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +#pragma once + +#define PADDING 10 + +#define BACKGROUND_COLOR GColorFolly \ No newline at end of file diff --git a/src/windows/list/list_layer.c b/src/screens/list/list_layer.c similarity index 100% rename from src/windows/list/list_layer.c rename to src/screens/list/list_layer.c diff --git a/src/windows/list/list_layer.h b/src/screens/list/list_layer.h similarity index 100% rename from src/windows/list/list_layer.h rename to src/screens/list/list_layer.h diff --git a/src/windows/list/list_window.c b/src/screens/list/list_window.c similarity index 98% rename from src/windows/list/list_window.c rename to src/screens/list/list_window.c index f1697e6..33e5a1c 100644 --- a/src/windows/list/list_window.c +++ b/src/screens/list/list_window.c @@ -21,6 +21,7 @@ #include "list_window.h" #include "../action/action_window.h" #include "list_layer.h" +#include "../animation/animation_window.h" static void on_select(void *callback_context) { diff --git a/src/windows/list/list_window.h b/src/screens/list/list_window.h similarity index 100% rename from src/windows/list/list_window.h rename to src/screens/list/list_window.h diff --git a/src/windows/list/style.h b/src/screens/list/style.h similarity index 100% rename from src/windows/list/style.h rename to src/screens/list/style.h