Commits

Trammell Hudson committed b5bef46

Draw minutes, too

  • Participants
  • Parent commits 682c3e3

Comments (0)

Files changed (1)

words/src/words.c

 
 static Window window;
 static TextLayer layers[WORD_COUNT];
+static Layer minute_layer;
+static int minute_num;
+
+
+/** Draw a box in a corner to indicate the number of minutes past the five.
+ */
+static void
+minute_layer_update(
+        Layer * const me,
+        GContext * ctx
+)
+{
+	const int w = 6;
+	GRect r = GRect(0, 0, w, w);
+
+	if (minute_num == 0)
+		return; // nothing to draw
+	else
+	if (minute_num == 1)
+		r.origin = GPoint(0,0);
+	else
+	if (minute_num == 2)
+		r.origin = GPoint(144-w,0);
+	else
+	if (minute_num == 3)
+		r.origin = GPoint(144-w,168-w);
+	else
+	if (minute_num == 4)
+		r.origin = GPoint(0,168-w);
+
+	graphics_context_set_fill_color(ctx, GColorWhite);
+	graphics_fill_rect(ctx, r, 2, GCornersAll);
+}
+
 
 static void
-layer_mark(
+word_mark(
 	int which,
 	int on
 )
 
 	// mark all of the minutes as off,
 	// and then turn on the ones that count
-	layer_mark(LAYER_OCLOCK, 0);
-	layer_mark(LAYER_FIVE, 0);
-	layer_mark(LAYER_TEN, 0);
-	layer_mark(LAYER_A, 0);
-	layer_mark(LAYER_QUARTER, 0);
-	layer_mark(LAYER_TWENTY, 0);
-	layer_mark(LAYER_HALF, 0);
-	layer_mark(LAYER_PAST, 0);
-	layer_mark(LAYER_TO, 0);
+	word_mark(LAYER_OCLOCK, 0);
+	word_mark(LAYER_FIVE, 0);
+	word_mark(LAYER_TEN, 0);
+	word_mark(LAYER_A, 0);
+	word_mark(LAYER_QUARTER, 0);
+	word_mark(LAYER_TWENTY, 0);
+	word_mark(LAYER_HALF, 0);
+	word_mark(LAYER_PAST, 0);
+	word_mark(LAYER_TO, 0);
 
-	
 	if (min < 5)
 	{
-		layer_mark(LAYER_OCLOCK, 1);
+		word_mark(LAYER_OCLOCK, 1);
 	} else
 	if (min < 10)
 	{
-		layer_mark(LAYER_FIVE, 1);
-		layer_mark(LAYER_PAST, 1);
+		word_mark(LAYER_FIVE, 1);
+		word_mark(LAYER_PAST, 1);
 	} else
 	if (min < 15)
 	{
-		layer_mark(LAYER_TEN, 1);
-		layer_mark(LAYER_PAST, 1);
+		word_mark(LAYER_TEN, 1);
+		word_mark(LAYER_PAST, 1);
 	} else
 	if (min < 20)
 	{
-		layer_mark(LAYER_A, 1);
-		layer_mark(LAYER_QUARTER, 1);
-		layer_mark(LAYER_PAST, 1);
+		word_mark(LAYER_A, 1);
+		word_mark(LAYER_QUARTER, 1);
+		word_mark(LAYER_PAST, 1);
 	} else
 	if (min < 25)
 	{
-		layer_mark(LAYER_TWENTY, 1);
-		layer_mark(LAYER_PAST, 1);
+		word_mark(LAYER_TWENTY, 1);
+		word_mark(LAYER_PAST, 1);
 	} else
 	if (min < 30)
 	{
-		layer_mark(LAYER_TWENTY, 1);
-		layer_mark(LAYER_FIVE, 1);
-		layer_mark(LAYER_PAST, 1);
+		word_mark(LAYER_TWENTY, 1);
+		word_mark(LAYER_FIVE, 1);
+		word_mark(LAYER_PAST, 1);
 	} else
 	if (min < 35)
 	{
-		layer_mark(LAYER_HALF, 1);
-		layer_mark(LAYER_PAST, 1);
+		word_mark(LAYER_HALF, 1);
+		word_mark(LAYER_PAST, 1);
 	} else
 	if (min < 40)
 	{
-		layer_mark(LAYER_TWENTY, 1);
-		layer_mark(LAYER_FIVE, 1);
-		layer_mark(LAYER_TO, 1);
+		word_mark(LAYER_TWENTY, 1);
+		word_mark(LAYER_FIVE, 1);
+		word_mark(LAYER_TO, 1);
 		hour++;
 	} else
 	if (min < 45)
 	{
-		layer_mark(LAYER_TWENTY, 1);
-		layer_mark(LAYER_TO, 1);
+		word_mark(LAYER_TWENTY, 1);
+		word_mark(LAYER_TO, 1);
 		hour++;
 	} else
 	if (min < 50)
 	{
-		layer_mark(LAYER_A, 1);
-		layer_mark(LAYER_QUARTER, 1);
-		layer_mark(LAYER_TO, 1);
+		word_mark(LAYER_A, 1);
+		word_mark(LAYER_QUARTER, 1);
+		word_mark(LAYER_TO, 1);
 		hour++;
 	} else
 	if (min < 55)
 	{
-		layer_mark(LAYER_TEN, 1);
-		layer_mark(LAYER_TO, 1);
+		word_mark(LAYER_TEN, 1);
+		word_mark(LAYER_TO, 1);
 		hour++;
 	} else {
-		layer_mark(LAYER_FIVE, 1);
-		layer_mark(LAYER_TO, 1);
+		word_mark(LAYER_FIVE, 1);
+		word_mark(LAYER_TO, 1);
 		hour++;
 	}
 
+	// update the minute box
+	minute_num = min % 5;
+	layer_mark_dirty(&minute_layer);
 
 	// Convert from 24-hour to 12-hour time
 	if (hour == 0)
 
 	// light up the one hour marker
 	for (int i = 1 ; i < 12 ; i++)
-		layer_mark(i, i == hour ? 1 : 0);
+		word_mark(i, i == hour ? 1 : 0);
 }
 
 
 static void
-text_layer(
+word_layer_init(
 	int which
 )
 {
 	text_layer_init(layer, frame);
 	text_layer_set_text_color(layer, GColorWhite);
 	text_layer_set_background_color(layer, GColorClear);
-	layer_mark(which, 0); // all are "off" initially
+	word_mark(which, 0); // all are "off" initially
 
 	layer_add_child(&window.layer, &layer->layer);
 }
 	resource_init_current_app(&RESOURCES);
 
 	for (unsigned i = 0 ; i < WORD_COUNT ; i++)
-	{
-		text_layer(i);
-	}
+		word_layer_init(i);
 
 	// Flag the ones that are always on
-	layer_mark(LAYER_IT, 1);
-	layer_mark(LAYER_IS, 1);
+	word_mark(LAYER_IT, 1);
+	word_mark(LAYER_IS, 1);
+
+	// Create a graphics layer for the entire background
+	layer_init(&minute_layer, GRect(0, 0, 144, 168));
+	minute_layer.update_proc = minute_layer_update;
+	layer_add_child(&window.layer, &minute_layer);
 }