Commits

Trammell Hudson committed 985734d

switch to layers

Comments (0)

Files changed (1)

 /** \file
- * Word clock, with Dutch time
+ * Word clock, with Dutch time.
+ *
+ * Four lines:
+ *
+ * minutes (or blank)
+ * over/voor/half (or blank)
+ * HOUR (in bold)
+ * 's ochtends / 's middags 
+ *
+ * \todo: When any line changes, it is pushed to the side
  *
  * een uur
  * een over een
 #include "pebble_app.h"
 #include "pebble_fonts.h"
 
+static Window window;
+
+static const char * min_text;
+static const char * rel_text;
+static const char * hour_text;
+static const char * ampm_text;
+
+static TextLayer min_layer;
+static TextLayer rel_layer;
+static TextLayer hour_layer;
+static TextLayer ampm_layer;
 
 static const char *nums[] = {
 	"",
 	"kwart",
 };
 
-
 static const char *
 min_string(
 	int i
 
 static void
 nederlands_format(
-	char * buf,
 	int hour,
 	int min
 )
 {
-	buf[0] = '\0';
-
 	if (min == 0)
 	{
-		// just the hour + uur, except at midnight and noon
-		strcat(buf, hour_string(hour));
-		if (hour != 0 && hour != 12)
-			strcat(buf, "\nuur");
+		min_text = "";
+		rel_text = "";
 	} else
 	if (min <= 15)
 	{
 		// over the hour
-		strcat(buf, min_string(min));
-		strcat(buf, "\nover\n");
-		strcat(buf, hour_string(hour));
+		min_text = min_string(min);
+		rel_text = "over";
 	} else
 	if (min < 30)
 	{
 		// over the kwart
-		strcat(buf, min_string(30 - min));
-		strcat(buf, "\nvoor half\n");
-		strcat(buf, hour_string(++hour));
+		min_text = min_string(30 - min);
+		rel_text = "voor half";
+		hour++;
 	} else
 	if (min == 30)
 	{
 		// just the half
-		strcat(buf, "half\n");
-		strcat(buf, hour_string(++hour));
+		min_text = "";
+		rel_text = "half";
+		hour++;
 	} else
 	if (min < 45)
 	{
 		// over the half
-		strcat(buf, min_string(min - 30));
-		strcat(buf, "\nover half\n");
-		strcat(buf, hour_string(++hour));
+		min_text = min_string(min - 30);
+		rel_text = "over half";
+		hour++;
 	} else
 	if (min == 45)
 	{
 		// just the kwart
-		strcat(buf, "kwart voor\n");
-		strcat(buf, hour_string(++hour));
+		min_text = "";
+		rel_text = "kwart voor";
+		hour++;
 	} else
 	if (min < 60)
 	{
 		// over the kwart
-		strcat(buf, min_string(60 - min));
-		strcat(buf, "\nvoor\n");
-		strcat(buf, hour_string(++hour));
+		min_text = min_string(60 - min);
+		rel_text = "voor";
+		hour++;
 	}
 
+	hour_text = hour_string(hour);
+
 	// add am/pm like phrase
 	if (hour == 0 || hour == 12 || hour == 24)
 	{
 		// nothing to do
+		ampm_text = "";
 	} else
 	if (hour < 12)
-		strcat(buf, "\ns'ochtends");
+		ampm_text = "'s ochtends";
 	else
 	if (hour < 18)
-		strcat(buf, "\ns'middags");
+		ampm_text = "'s middags";
 	else
 	if (hour < 21)
-		strcat(buf, "\ns'avonds");
+		ampm_text = "'s avonds";
 	else
-		strcat(buf, "\ns'nachts");
+		ampm_text = "'s nachts";
 }
 
+
 PBL_APP_INFO(
 	"Nederlandse",
 	"hudson",
 );
 
 
-static char time_buffer[32];
-static Window window;
-static TextLayer time_layer;
 
 /** Called once per minute */
 static void
 	int hour = ptm->tm_hour;
 	int min = ptm->tm_min;
 
-	nederlands_format(time_buffer, hour,  min);
+	nederlands_format(hour,  min);
 
 /*
 	string_format_time(
 		event->tick_time
 	);
 */
-	text_layer_set_text(&time_layer, time_buffer);
+
+	text_layer_set_text(&min_layer, min_text);
+	text_layer_set_text(&rel_layer, rel_text);
+	text_layer_set_text(&hour_layer, hour_text);
+	text_layer_set_text(&ampm_layer, ampm_text);
+}
+
+
+static void
+text_layer(
+	TextLayer * layer,
+	GRect frame,
+	const char * font
+)
+{
+	text_layer_init(layer, frame);
+	text_layer_set_text(layer, "");
+	text_layer_set_text_color(layer, GColorWhite);
+	text_layer_set_background_color(layer, GColorBlack);
+	text_layer_set_font(layer, fonts_get_system_font(font));
+
+	layer_add_child(&window.layer, &layer->layer);
 }
 
 
 	window_stack_push(&window, true);
 	window_set_background_color(&window, GColorBlack);
 
-	text_layer_init(&time_layer, GRect(0,0,144,168));
-	time_buffer[0] = '\0';
-	text_layer_set_text(&time_layer, time_buffer);
-	text_layer_set_text_color(&time_layer, GColorWhite);
-	text_layer_set_background_color(&time_layer, GColorBlack);
-	text_layer_set_font(&time_layer, fonts_get_system_font(FONT_KEY_GOTHAM_30_BLACK));
-	layer_add_child(&window.layer, &time_layer.layer);
+	int y = 10;
+	int h = 30+2;
+	text_layer(&min_layer, GRect(0, y + 0*h, 144, h), FONT_KEY_GOTHIC_28_BOLD);
+	text_layer(&rel_layer, GRect(0, y + 1*h, 144, h), FONT_KEY_GOTHIC_28_BOLD);
+	text_layer(&hour_layer, GRect(0, y + 2*h, 144, h), FONT_KEY_GOTHAM_30_BLACK);
+	text_layer(&ampm_layer, GRect(0, y + 3*h, 144, h), FONT_KEY_GOTHIC_28_BOLD);
 }
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.