-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'flyout-anim': add segment view flyout/flyin animations
* flyout-anim: Remove flyin/flyout animation from TODO Change parameter name in progress_layer_init for clarity Use accessors for layer frame get and set I should probably be updating the app version define Add comments to flyout animation Push sublayer removal into flyout animation Factor flyout animation out of segment view Factor progress layer out of segment view Clean up some variables and code cruft Fix a bug where flyin/out occurred even if segment type wasn't changing Hack a Z-order bug affecting fly in/out animation and add a TODO Add reworked flyout animation and new flyin animation Add a terrible first hack flyout animation for segment layer
- Loading branch information
Showing
9 changed files
with
231 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// ---------------------------------------------------------------------------- | ||
// flyout_animation - Switches between two layers with flyout/flyin animation | ||
// Copyright (c) 2013 Jonathan Speicher ([email protected]) | ||
// Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <pebble_os.h> | ||
#include "flyout_animation.h" | ||
|
||
// Public functions ----------------------------------------------------------- | ||
|
||
void flyout_animation_init(FlyoutAnimation* animation, Layer* on, Layer* off) { | ||
GRect on_screen_frame, off_screen_frame; | ||
|
||
animation->on_screen_layer = on; | ||
animation->off_screen_layer = off; | ||
|
||
on_screen_frame = layer_get_frame(animation->on_screen_layer); | ||
animation->target_rect = on_screen_frame; | ||
|
||
off_screen_frame = on_screen_frame; | ||
off_screen_frame.origin.x = -on_screen_frame.size.w; | ||
layer_set_frame(animation->off_screen_layer, off_screen_frame); | ||
|
||
animation_set_curve(&animation->flyout.animation, AnimationCurveEaseInOut); | ||
animation_set_curve(&animation->flyin.animation, AnimationCurveEaseInOut); | ||
} | ||
|
||
void flyout_animation_add_child(Layer* layer, FlyoutAnimation* animation) { | ||
layer_add_child(layer, animation->on_screen_layer); | ||
layer_add_child(layer, animation->off_screen_layer); | ||
} | ||
|
||
void flyout_animation_remove_from_parent(FlyoutAnimation* animation) { | ||
layer_remove_from_parent(animation->on_screen_layer); | ||
layer_remove_from_parent(animation->off_screen_layer); | ||
} | ||
|
||
void flyout_animation_swap_layers(FlyoutAnimation* animation) { | ||
Layer* temp = animation->on_screen_layer; | ||
animation->on_screen_layer = animation->off_screen_layer; | ||
animation->off_screen_layer = temp; | ||
} | ||
|
||
void flyout_animation_schedule(FlyoutAnimation* animation) { | ||
GRect offscreen_left_rect, offscreen_right_rect; | ||
|
||
offscreen_left_rect = animation->target_rect; | ||
offscreen_left_rect.origin.x = -animation->target_rect.size.w; | ||
|
||
offscreen_right_rect = animation->target_rect; | ||
offscreen_right_rect.origin.x = animation->target_rect.size.w; | ||
|
||
property_animation_init_layer_frame(&animation->flyout, | ||
animation->off_screen_layer, &animation->target_rect, &offscreen_left_rect); | ||
property_animation_init_layer_frame(&animation->flyin, | ||
animation->on_screen_layer, &offscreen_right_rect, &animation->target_rect); | ||
|
||
animation_schedule(&animation->flyout.animation); | ||
animation_schedule(&animation->flyin.animation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// ---------------------------------------------------------------------------- | ||
// flyout_animation - Switches between two layers with flyout/flyin animation | ||
// Copyright (c) 2013 Jonathan Speicher ([email protected]) | ||
// Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include <pebble_os.h> | ||
|
||
// Defines a type to hold the layers to be animated, as well as the elements | ||
// necessary to perform the animation. | ||
|
||
typedef struct { | ||
Layer* on_screen_layer; | ||
Layer* off_screen_layer; | ||
GRect target_rect; | ||
PropertyAnimation flyout; | ||
PropertyAnimation flyin; | ||
} FlyoutAnimation; | ||
|
||
// Initializes the animation. The on-screen layer's frame will be used as the | ||
// target "landing-zone" frame for the flyin animation, and the off-screen | ||
// layer will be moved off-screen at initialization time automatically. | ||
|
||
void flyout_animation_init(FlyoutAnimation* animation, Layer* on_screen_layer, | ||
Layer* off_screen_layer); | ||
|
||
// Adds the entire animation structure as a child of the layer specified. This | ||
// will add the on- and off-screen layers as necessary. | ||
|
||
void flyout_animation_add_child(Layer* layer, FlyoutAnimation* animation); | ||
|
||
// Removes the entire animation structure from its parent layer. This will | ||
// remove the on- and off-screen layers as necessary. | ||
|
||
void flyout_animation_remove_from_parent(FlyoutAnimation* animation); | ||
|
||
// Swaps the layers such that the on-screen layer becomes the off-screen layer, | ||
// and vice-versa. Note that this function does not initiate any animation. | ||
|
||
void flyout_animation_swap_layers(FlyoutAnimation* animation); | ||
|
||
// Schedules the flyin and flyout animation. The layer that is currently set as | ||
// the off-screen layer will be animated to a position that is off the screen, | ||
// and the layer that is currently set as the on-screen layer will be animated | ||
// to a position that is on the screen, defined by the target "landing-zone" | ||
// frame originally identified when the animation was initialized. | ||
|
||
void flyout_animation_schedule(FlyoutAnimation* animation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// ---------------------------------------------------------------------------- | ||
// progress_layer - Displays a configurable progress bar | ||
// Copyright (c) 2013 Jonathan Speicher ([email protected]) | ||
// Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <pebble_os.h> | ||
#include "progress_layer.h" | ||
|
||
// Define a variable to hold the number of steps indicated by the layer. | ||
|
||
static unsigned int num_steps; | ||
|
||
// Define a variable to hold the number of steps completed. | ||
|
||
static unsigned int steps_completed; | ||
|
||
// Private functions. | ||
|
||
static void update_progress_layer(Layer* layer, GContext* ctx); | ||
|
||
// Public functions ----------------------------------------------------------- | ||
|
||
void progress_layer_init(Layer* layer, GRect frame) { | ||
layer_init(layer, frame); | ||
layer_set_update_proc(layer, update_progress_layer); | ||
} | ||
|
||
void progress_layer_set_num_steps(Layer* layer, unsigned int steps) { | ||
num_steps = steps; | ||
} | ||
|
||
void progress_layer_set_num_steps_completed(Layer* layer, unsigned int steps) { | ||
if (steps > num_steps) steps = num_steps; | ||
steps_completed = steps; | ||
} | ||
|
||
// Private functions ---------------------------------------------------------- | ||
|
||
void update_progress_layer(Layer* layer, GContext* ctx) { | ||
GRect frame = layer_get_frame(layer); | ||
unsigned int span = frame.size.w / (num_steps + 1); | ||
unsigned int radius = 5; | ||
GPoint center = GPoint(span, 20); | ||
|
||
graphics_context_set_stroke_color(ctx, GColorBlack); | ||
graphics_context_set_fill_color(ctx, GColorBlack); | ||
|
||
for (unsigned int i = 0; i < num_steps; i++) { | ||
center.x = span * (i + 1); | ||
if (i < steps_completed) { | ||
graphics_fill_circle(ctx, center, radius); | ||
} else { | ||
graphics_draw_circle(ctx, center, radius); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// ---------------------------------------------------------------------------- | ||
// progress_layer - Displays a configurable progress bar | ||
// Copyright (c) 2013 Jonathan Speicher ([email protected]) | ||
// Licensed under the MIT license: http://opensource.org/licenses/MIT | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include <pebble_os.h> | ||
|
||
// Initializes the progress layer. | ||
|
||
void progress_layer_init(Layer* layer, GRect frame); | ||
|
||
// Sets the number of steps that can be displayed by this progress layer. | ||
|
||
void progress_layer_set_num_steps(Layer* layer, unsigned int steps); | ||
|
||
// Sets the number of steps completed to be displayed by this progress layer. | ||
// If this number is larger than the maximum number of steps, it will be | ||
// clipped. | ||
|
||
void progress_layer_set_num_steps_completed(Layer* layer, unsigned int steps); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters