Commits

Trammell Hudson  committed dfd62e0

Animation attempt

  • Participants
  • Parent commits 018db16

Comments (0)

Files changed (1)

File hoelaat/src/nederlands.c

 static GFont font_thin;
 static GFont font_thick;
 
-static const char * min_text;
-static const char * rel_text;
-static const char * hour_text;
-static const char * ampm_text;
+typedef struct
+{
+	TextLayer layer;
+	PropertyAnimation anim;
+	const char * text;
+	const char * old_text;
+} word_t;
 
-static TextLayer min_layer;
-static TextLayer rel_layer;
-static TextLayer hour_layer;
-static TextLayer ampm_layer;
+static word_t min_word;
+static word_t rel_word;
+static word_t hour_word;
+static word_t ampm_word;
+
 
 static const char *nums[] = {
 	"",
 {
 	if (min == 0)
 	{
-		min_text = "";
-		rel_text = "";
+		min_word.text = "";
+		rel_word.text = "";
 	} else
 	if (min <= 15)
 	{
 		// over the hour
-		min_text = min_string(min);
-		rel_text = "over";
+		min_word.text = min_string(min);
+		rel_word.text = "over";
 	} else
 	if (min < 30)
 	{
 		// over the kwart
-		min_text = min_string(30 - min);
-		rel_text = "voor half";
+		min_word.text = min_string(30 - min);
+		rel_word.text = "voor half";
 		hour++;
 	} else
 	if (min == 30)
 	{
 		// just the half
-		min_text = "";
-		rel_text = "half";
+		min_word.text = "";
+		rel_word.text = "half";
 		hour++;
 	} else
 	if (min < 45)
 	{
 		// over the half
-		min_text = min_string(min - 30);
-		rel_text = "over half";
+		min_word.text = min_string(min - 30);
+		rel_word.text = "over half";
 		hour++;
 	} else
 	if (min == 45)
 	{
 		// just the kwart
-		min_text = "";
-		rel_text = "kwart voor";
+		min_word.text = "";
+		rel_word.text = "kwart voor";
 		hour++;
 	} else
 	if (min < 60)
 	{
 		// over the kwart
-		min_text = min_string(60 - min);
-		rel_text = "voor";
+		min_word.text = min_string(60 - min);
+		rel_word.text = "voor";
 		hour++;
 	}
 
-	hour_text = hour_string(hour);
+	hour_word.text = hour_string(hour);
 
 	// at midnight and noon do not display an am/pm notation
 	// but don't say "before midnight"
 	if (hour == 0 || hour == 12)
 	{
 		// nothing to do
-		ampm_text = "";
+		ampm_word.text = "";
 	} else
 	if (hour < 6)
-		ampm_text = "'s nachts";
+		ampm_word.text = "'s nachts";
 	else
 	if (hour <= 12)
-		ampm_text = "'s morgens";
+		ampm_word.text = "'s morgens";
 	else
 	if (hour <= 17)
-		ampm_text = "'s middags";
+		ampm_word.text = "'s middags";
 	else
 	if (hour <= 24)
-		ampm_text = "'s avonds";
+		ampm_word.text = "'s avonds";
 }
 
 
 
 
 
+static void
+update_word(
+	word_t * const word
+)
+{
+	text_layer_set_text(&word->layer, word->text);
+	if (word->text != word->old_text)
+		animation_schedule(&word->anim.animation);
+}
+
+
 /** Called once per minute */
 static void
 handle_tick(
 	int hour = ptm->tm_hour;
 	int min = ptm->tm_min;
 
-	const char * old_min = min_text;
-	const char * old_rel = rel_text;
-	const char * old_hour = hour_text;
-	const char * old_ampm = ampm_text;
+	ampm_word.old_text = ampm_word.text;
+	hour_word.old_text = hour_word.text;
+	rel_word.old_text = rel_word.text;
+	min_word.old_text = min_word.text;
 
 	nederlands_format(hour,  min);
 
 	);
 */
 
-	text_layer_set_text(&ampm_layer, ampm_text);
-	text_layer_set_text(&hour_layer, hour_text);
-	text_layer_set_text(&rel_layer, rel_text);
-	text_layer_set_text(&min_layer, min_text);
+	update_word(&ampm_word);
+	update_word(&hour_word);
+	update_word(&rel_word);
+	update_word(&min_word);
 }
 
 
 static void
 text_layer(
-	TextLayer * layer,
+	word_t * word,
 	GRect frame,
 	GFont font
 )
 {
-	text_layer_init(layer, frame);
-	text_layer_set_text(layer, "");
-	text_layer_set_text_color(layer, GColorWhite);
-	text_layer_set_background_color(layer, GColorClear);
-	text_layer_set_font(layer, font);
+	text_layer_init(&word->layer, frame);
+	text_layer_set_text(&word->layer, "");
+	text_layer_set_text_color(&word->layer, GColorWhite);
+	text_layer_set_background_color(&word->layer, GColorClear);
+	text_layer_set_font(&word->layer, font);
 
-	layer_add_child(&window.layer, &layer->layer);
+	layer_add_child(&window.layer, &word->layer.layer);
+
+	GRect frame_right = frame;
+	frame_right.origin.x = 150;
+
+	property_animation_init_layer_frame(
+		&word->anim,
+		&word->layer.layer,
+		&frame_right,
+		&frame
+	);
+
+	animation_set_duration(&word->anim.animation, 500);
+	animation_set_curve(&word->anim.animation, AnimationCurveEaseIn);
 }
 
 
 
 	// Stack top to bottom.  Note that the hour can take up
 	// two rows at midnight.
-	text_layer(&ampm_layer, GRect(4, y + 3*h, 144, h+8), font_thin);
-	text_layer(&hour_layer, GRect(4, y + 2*h, 144, 2*h+8), font_thin);
-	text_layer(&rel_layer, GRect(4, y + 1*h, 144, h+8), font_thick);
-	text_layer(&min_layer, GRect(4, y + 0*h, 144, h+8), font_thin);
+	text_layer(&ampm_word, GRect(4, y + 3*h, 144, h+8), font_thin);
+	text_layer(&hour_word, GRect(4, y + 2*h, 144, 2*h+8), font_thick);
+	text_layer(&rel_word, GRect(4, y + 1*h, 144, h+8), font_thin);
+	text_layer(&min_word, GRect(4, y + 0*h, 144, h+8), font_thin);
+
 }