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 0000000..63588f7 Binary files /dev/null and b/resources/confirm_sequence.pdc differ diff --git a/src/main.c b/src/main.c index cf7b19a..2baabb6 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,7 @@ */ #include -#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