Trammell Hudson avatar Trammell Hudson committed f45c141

draw bargraphs

Comments (0)

Files changed (1)

interval/src/interval.c

 );
 
 
+static const int intervals[] = {
+	 -300,
+	 60, -30,
+	 60, -30,
+	 60, -30,
+	 60, -30,
+	 60, -30,
+	 60, -30,
+	 60, -30,
+	 60, -300,
+};
+
+static const int interval_count = sizeof(intervals)/sizeof(*intervals);
+static const int run_count = 8;
+static int interval = 0;
+
+
 static Window window;
 static TextLayer time_layer;
 static TextLayer remaining_layer;
-static Layer line_layer;
+static Layer layer;
 static char time_buffer[12];
 static char remaining_buffer[12];
 
-static int remaining = 120;
+static int remaining = -1;
 
 
+/**
+ * Draw the bargraphs for the running segments.
+ * [++++++]  // run
+ */
 static void
 layer_update(
 	Layer * const me,
 	GContext * ctx
 )
 {
-#if 0
-	// Draw a white rectangle across the entire bottom
 	const unsigned w = me->bounds.size.w;
 	const unsigned h = me->bounds.size.h;
+	const int bar_h = (h - run_count) / (run_count);
+	int y = 0;
+
 	graphics_context_set_fill_color(ctx, GColorWhite);
-	graphics_fill_rect(ctx, GRect(0, 0, w, h), 0, GCornersAll);
 
-	graphics_context_set_fill_color(ctx, GColorBlack);
-	graphics_fill_rect(ctx, GRect(0, 0, (w * remaining) / 30, h), 4, GCornersRight);
-#endif
+	for (int i = 0 ; i < interval_count ; i++)
+	{
+		if (intervals[i] < 0)
+			continue;
+
+		graphics_fill_rect(ctx, GRect(0, y, w, bar_h), 2, GCornersAll);
+		y += bar_h + 1;
+	}
 }
 
 
 	remaining_buffer[3] = '\0';
 
 	text_layer_set_text(&remaining_layer, remaining_buffer);
+
+	layer_mark_dirty(&layer);
 }
 
 
 	resource_init_current_app(&RESOURCES);
 
 
-	text_layer_init(&time_layer, GRect(10,10,134,30));
-	text_layer_init(&remaining_layer, GRect(10,40,134,30));
+	text_layer_init(&time_layer, GRect(20,10,100,30));
+	text_layer_init(&remaining_layer, GRect(10,40,134,45));
 
 	text_layer_set_text_color(&time_layer, GColorWhite);
 	text_layer_set_text_color(&remaining_layer, GColorWhite);
 	text_layer_set_text(&time_layer, "");
 	text_layer_set_text(&remaining_layer, "");
 
-	text_layer_set_font(&time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
-	text_layer_set_font(&remaining_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
+	text_layer_set_font(&time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
+	text_layer_set_font(&remaining_layer, fonts_get_system_font(FONT_KEY_GOTHAM_42_BOLD));
 
+	// Layer to draw the bargraphs
 	layer_add_child(&window.layer, &time_layer.layer);
 	layer_add_child(&window.layer, &remaining_layer.layer);
 
-#if 0
-	// Bargraph layer is across the bottom
-	const unsigned bargraph_height = 20;
-	layer_init(&bargraph_layer, GRect(0,168-bargraph_height-15,144,bargraph_height));
-	bargraph_layer.update_proc = bargraph_layer_update;
+	layer_init(&layer, GRect(0,50,144,168-50));
+	layer.update_proc = layer_update;
 
-	layer_add_child(&window.layer, &bargraph_layer);
-#endif
+	layer_add_child(&window.layer, &layer);
 }
 
 
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.