Trammell Hudson avatar Trammell Hudson committed 38ca31f

timer redraw and scaling almost works

Comments (0)

Files changed (2)

 	int h
 )
 {
-	graphics_context_set_stroke_color(ctx, GColorBlack);
-	graphics_draw_round_rect(ctx, GRect(x,y,w,h), 0);
+	graphics_context_set_stroke_color(ctx, GColorWhite);
+	graphics_draw_round_rect(ctx, GRect(y*2,x*2,h*2,w*2), 0);
 }
 
 static inline void
 )
 {
 	graphics_context_set_fill_color(ctx, inverted ? GColorWhite : GColorBlack);
-	graphics_fill_rect(ctx, GRect(x, y, w, h), 0, GCornerNone);
+	graphics_fill_rect(ctx, GRect(y*2, x*2, h*2, w*2), 0, GCornerNone);
 }
 
 
 	int y
 )
 {
-	graphics_context_set_stroke_color(ctx, GColorBlack);
-	graphics_draw_pixel(ctx, GPoint(x,y));
+	graphics_context_set_fill_color(ctx, GColorBlack);
+	graphics_fill_rect(ctx, GRect(y*2, x*2, 2, 2), 0, GCornerNone);
 }
 
 static inline void
 	int y
 )
 {
-	graphics_context_set_stroke_color(ctx, GColorWhite);
-	graphics_draw_pixel(ctx, GPoint(x,y));
+	graphics_context_set_fill_color(ctx, GColorWhite);
+	graphics_fill_rect(ctx, GRect(y*2, x*2, 2, 2), 0, GCornerNone);
 }
 
 extern volatile uint8_t time_s, time_m, time_h;
 
 void draw(GContext * gctx)
 {
-   ctx = gctx;
-	//glcdFillRectangle(0, 0, 32, 32, 0);
-	//glcdClearDot(16, 16);
-	//glcdSetDot(64, 16);
+  ctx = gctx;
 
-	initdisplay(0);
+  // init display must draw the background every time
+  initdisplay(0);
 
   // Animation Loop + delay
   animation_loop();
 static Window window;
 static Layer layer;
 
+static AppTimerHandle timer_handle;
+#define COOKIE_MY_TIMER 1
+
+
 extern void draw(GContext * gctx);
 
 static void
 
 
 static void
+handle_timer(
+	AppContextRef ctx,
+	AppTimerHandle handle,
+	uint32_t cookie
+)
+{
+	(void)handle;
+
+	if (cookie != COOKIE_MY_TIMER)
+		return;
+
+	layer_mark_dirty(&layer);
+
+	timer_handle = app_timer_send_event(
+		ctx,
+		50 /* milliseconds */,
+		COOKIE_MY_TIMER
+	);
+}
+
+
+static void
 handle_tick(
 	AppContextRef ctx,
 	PebbleTickEvent * const event
 	date_m = ptm->tm_mon + 1;
 	date_d = ptm->tm_mday;
 	date_y = ptm->tm_year;
-
-	layer_mark_dirty(&layer);
 }
 
 
 	window_stack_push(&window, true);
 
 	// Mario Layer
-	layer_init(&layer, GRect(0,0, 128, 64));
+	layer_init(&layer, GRect(0,0, 144, 168));
 	layer.update_proc = layer_update;
 	layer_add_child(&window.layer, &layer);
+
+	timer_handle = app_timer_send_event(
+		ctx,
+		50 /* milliseconds */,
+		COOKIE_MY_TIMER
+	);
 }
 
 
 )
 {
 	PebbleAppHandlers handlers = {
-		.init_handler	= &handle_init,
+		.init_handler	= handle_init,
+		.timer_handler	= handle_timer,
 		.tick_info	= {
-			.tick_handler = &handle_tick,
+			.tick_handler = handle_tick,
 			.tick_units = SECOND_UNIT,
 		},
 	};
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.