Trammell Hudson avatar Trammell Hudson committed dcf051c

hour hand

Comments (0)

Files changed (1)

 static GFont font_thin;
 static GFont font_thick;
 
+
+// Dimensions of the watch face
+#define W PEBBLE_SCREEN_WIDTH
+#define H PEBBLE_SCREEN_WIDTH
+#define R (W/2 - 2)
+
 // Circle points computed at startup and the path is dynamically adjuste
 #define NUM_POINTS 256
 static GPoint circle_points[NUM_POINTS];
 static GPath circle_path;
-static GPathInfo circle_info = { NUM_POINTS, &circle_points };
+static GPathInfo circle_info = { NUM_POINTS, circle_points };
+
+// Hour markers
+static GPath hour_path;
+static GPoint hour_points[] = { { 0, R - 2 }, { 0, R + 2 } };
+static GPathInfo hour_info = { 2, hour_points };
+
+// Hour hand
+static GPath hand_path;
+static GPoint hand_points[] = {
+	{  0, 0 },
+	{ -5, -10 },
+	{  0, -R },
+	{ +5, -10 },
+	{  0, 0 },
+};
+static GPathInfo hand_info = { 5, hand_points };
 
 
 static void
 	graphics_context_set_fill_color(ctx, GColorWhite);
 
 	// Draw the outline circle
-	graphics_draw_circle(ctx, GPoint(w/2,h/2), w/2-1);
+	graphics_draw_circle(ctx, GPoint(w/2,h/2), R);
 
 	// Compute the sun up / sun down time and
 	// draw the semi-circle
-	//int sun_up = 64;
-	//int sun_down = 190;
+	int sun_up = 120;
+	int sun_down = 140;
 
-	circle_path.num_points = 90;
-	//circle_path.points = &circle_points[sun_up];
+	circle_path.num_points = sun_down - sun_up;
+	circle_path.points = &circle_points[sun_up];
+
+	GPoint temp = circle_path.points[0];
+	circle_path.points[0] = GPoint(w/2,h/2);
 	gpath_draw_filled(ctx, &circle_path);
+	circle_path.points[0] = temp;
+
+	// Draw the hour marks
+	for (int hour = 0 ; hour < 23 ; hour++)
+	{
+		gpath_rotate_to(&hour_path, (hour * TRIG_MAX_ANGLE) / 24);
+		gpath_draw_outline(ctx, &hour_path);
+	}
+
+	// Draw the hour hand outline and filled with black
+	int hand_angle = ((now.tm_hour * 60 + now.tm_min) * TRIG_MAX_ANGLE) / (60 * 24);
+
+	gpath_rotate_to(&hand_path, hand_angle);
+	graphics_context_set_fill_color(ctx, GColorBlack);
+	gpath_draw_filled(ctx, &hand_path);
+	graphics_context_set_stroke_color(ctx, GColorWhite);
+	gpath_draw_outline(ctx, &hand_path);
 
 #if 0
 	const timezone_t * const tz = container_of(me, timezone_t, layer);
 )
 {
 	(void) ctx;
-	const int w = PEBBLE_SCREEN_WIDTH - 4;
-	const int h = PEBBLE_SCREEN_WIDTH - 4;
-
 	// Compute the points around the circle
 	for (int i = 0 ; i < NUM_POINTS ; i++)
 	{
 		const uint32_t angle = (i * TRIG_MAX_ANGLE) / NUM_POINTS;
 		const int s = sin_lookup(angle);
 		const int c = cos_lookup(angle);
-		circle_points[i].x = (w/2) + ((w/2) * s) / 0x10000;
-		circle_points[i].y = (h/2) - ((h/2) * c) / 0x10000;
+		circle_points[i].x = (W/2) + (R * s) / 0x10000;
+		circle_points[i].y = (H/2) - (R * c) / 0x10000;
 	}
 
 	gpath_init(&circle_path, &circle_info);
 
+	gpath_init(&hour_path, &hour_info);
+	gpath_move_to(&hour_path, GPoint(W/2,H/2));
+
+	gpath_init(&hand_path, &hand_info);
+	gpath_move_to(&hand_path, GPoint(W/2,H/2));
+
 	get_time(&now);
 
 	window_init(&window, "Main");
 	//font_thin = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_16));
 	font_thick = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_BLACK_30));
 
-	layer_init(&graphics_layer, GRect(0, 0, w, h));
+	layer_init(&graphics_layer, GRect(0, 1, W, H));
 	layer_add_child(&window.layer, &graphics_layer);
 	graphics_layer.update_proc = graphics_layer_update;
 	layer_mark_dirty(&graphics_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.