Exemplo n.º 1
0
static void init(void) {
	time_t t = time(NULL);
	
	window = window_create();
	window_set_background_color(window, GColorBlack);
	window_stack_push(window, true);
	rootLayer = window_get_root_layer(window);

	layer = layer_create(GRect(0, 0, 144, 168));
	layer_set_update_proc(layer, updateLayer);
	layer_add_child(rootLayer, layer);

	textLayer = text_layer_create(GRect(72-30, 84-10, 60, 20));
	text_layer_set_background_color(textLayer, GColorClear);
	text_layer_set_text_color(textLayer, GColorWhite);
	text_layer_set_text_alignment(textLayer, GTextAlignmentCenter);
	layer_add_child(rootLayer, text_layer_get_layer(textLayer));
	
	minuteHandBitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HAND_MINUTE);
	minuteHandLayer = rot_bitmap_layer_create(minuteHandBitmap);
	rot_bitmap_set_compositing_mode(minuteHandLayer, GCompOpOr);
	layer_add_child(rootLayer, (Layer *)minuteHandLayer);

	hourHandBitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HAND_HOUR);
	hourHandLayer = rot_bitmap_layer_create(hourHandBitmap);
	rot_bitmap_set_compositing_mode(hourHandLayer, GCompOpOr);
	layer_add_child(rootLayer, (Layer *)hourHandLayer);
	
	// Init rotations
	handleTick(localtime(&t), SECOND_UNIT|MINUTE_UNIT|HOUR_UNIT);
	
	tick_timer_service_subscribe(SECOND_UNIT, handleTick);
}
Exemplo n.º 2
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
 
  //background
  background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
  background_img = gbitmap_create_with_resource(RESOURCE_ID_BACK);
  bitmap_layer_set_bitmap(background_layer, background_img);
  layer_add_child(window_layer, bitmap_layer_get_layer(background_layer));
  
  //hour
  hour_img = gbitmap_create_with_resource(RESOURCE_ID_HOUR);
  rot_hour = rot_bitmap_layer_create(hour_img);
  rot_bitmap_set_compositing_mode(rot_hour, GCompOpSet);
  rot_bitmap_set_src_ic(rot_hour,GPoint(10, 47));
  layer_set_frame((Layer*)rot_hour, GRect(22, 36, 108, 108));
  layer_add_child(window_layer, (Layer*)rot_hour);
  
  //minute
  minute_img = gbitmap_create_with_resource(RESOURCE_ID_MINUTE);
  rot_minute = rot_bitmap_layer_create(minute_img);
  rot_bitmap_set_compositing_mode(rot_minute, GCompOpSet);
  rot_bitmap_set_src_ic(rot_minute,GPoint(13, 67));
  layer_set_frame((Layer*)rot_minute, GRect(0, 16, 144, 144));
  layer_add_child(window_layer, (Layer*)rot_minute);
  
}
Exemplo n.º 3
0
void handle_main_window_load(Window *window) {
  // Create GBitmap, then set to created BitmapLayer
  s_background_bitmap = gbitmap_create_with_resource(IMAGE_RESOURCE_IDS_BACKGROUNDS[4]);
  s_point_bitmap = gbitmap_create_with_resource(IMAGE_RESOURCE_IDS_HANDS[1]);
  
  s_background_layer = bitmap_layer_create(GRect(0, 12, 144, 144));
  bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);

#if defined(USER_ROT_BITMAP)
  s_hour_point_layer = rot_bitmap_layer_create(s_point_bitmap);
  rot_bitmap_set_compositing_mode(s_hour_point_layer, GCompOpAnd);
  
  s_min_point_layer = rot_bitmap_layer_create(s_point_bitmap);
  rot_bitmap_set_compositing_mode(s_min_point_layer, GCompOpAnd);
#else
  GRect rec= {{0, 0}, {16, 16}};
  s_hour_point_layer = bitmap_layer_create(rec);
  bitmap_layer_set_bitmap(s_hour_point_layer, s_point_bitmap);
  bitmap_layer_set_compositing_mode(s_hour_point_layer, GCompOpAnd);
  
  s_min_point_layer = bitmap_layer_create(rec);
  bitmap_layer_set_bitmap(s_min_point_layer, s_point_bitmap);
  bitmap_layer_set_compositing_mode(s_min_point_layer, GCompOpAnd);
#endif

  // Update the time now
  handle_update();
  
  Layer * root_layer = window_get_root_layer(window);
  
  // Add it as a child layer to the Window's root layer
  layer_add_child(root_layer, bitmap_layer_get_layer(s_background_layer));
  
#if defined(USER_ROT_BITMAP)
  layer_add_child(root_layer, (Layer*)(s_hour_point_layer));
  layer_add_child(root_layer, (Layer*)(s_min_point_layer));
#else
  layer_add_child(root_layer, bitmap_layer_get_layer(s_hour_point_layer));
  layer_add_child(root_layer, bitmap_layer_get_layer(s_min_point_layer));
#endif
  
  add_invert(root_layer);
  
  // Register with TickTimerService
#if defined(USE_TEST_SECONDS)
  tick_timer_service_subscribe(SECOND_UNIT, handle_tick);
#else
  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
#endif
}
Exemplo n.º 4
0
// Handle the start-up of the app
void handle_init() {

  // Create our app's base window
  window = window_create();
  Layer *root_window_layer = window_get_root_layer(window);
  GRect root_window_bounds = layer_get_bounds(root_window_layer);

  window_stack_push(window, true);
  window_set_background_color(window, GColorBlack);

  // Set up a layer for the static watch face background
  background_layer = bitmap_layer_create(root_window_bounds);
  background_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
  bitmap_layer_set_bitmap(background_layer, background_image);
  layer_add_child(root_window_layer,
		  bitmap_layer_get_layer(background_layer));

  // Set up a layer for the minute hand.
  // Compositing tricks take the place of PNG transparency.
  minute_hand_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MINUTE_TRAIL);
  minute_hand_layer = rot_bitmap_layer_create(minute_hand_image);

  // Default frame for RotBitmapLayers is according to some
  // opaque algorithm. Automatically centre it now.
  GRect minute_frame = layer_get_frame(bitmap_layer_get_layer((BitmapLayer *)minute_hand_layer));
  GRect new_minute_frame = GRect((144-minute_frame.size.w)/2,
				 (168-minute_frame.size.h)/2,
				 minute_frame.size.w, minute_frame.size.h);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "minute frame: %i, %i, %i, %i",
	  minute_frame.origin.x, minute_frame.origin.y,
	  minute_frame.size.w, minute_frame.size.h);
  layer_set_frame(bitmap_layer_get_layer((BitmapLayer *)minute_hand_layer),
		  new_minute_frame);

  rot_bitmap_set_compositing_mode(minute_hand_layer, GCompOpOr);
  layer_add_child(root_window_layer,
		  bitmap_layer_get_layer((BitmapLayer *)minute_hand_layer));


  // Set up a layer for the hour hand.
  // Compositing tricks take the place of PNG transparency.
  hour_hand_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_HOUR_TRAIL);
  hour_hand_layer = rot_bitmap_layer_create(hour_hand_image);

  GRect hour_frame = layer_get_frame(bitmap_layer_get_layer((BitmapLayer *)hour_hand_layer));
  // The current images seem to look best if this frame is offset
  // one more pixel. Still not perfect though.
  GRect new_hour_frame = GRect((144-hour_frame.size.w)/2 + 1,
			       (168-hour_frame.size.h)/2 + 1,
			       hour_frame.size.w, hour_frame.size.h);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "hour frame: %i, %i, %i, %i",
	  hour_frame.origin.x, hour_frame.origin.y,
	  hour_frame.size.w, hour_frame.size.h);
  layer_set_frame(bitmap_layer_get_layer((BitmapLayer *)hour_hand_layer),
		  new_hour_frame);
  rot_bitmap_set_compositing_mode(hour_hand_layer, GCompOpOr);
  layer_add_child(root_window_layer,
		  bitmap_layer_get_layer((BitmapLayer *)hour_hand_layer));

  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  update_watch(t);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);

}
static void draw_watchface(Layer *layer, GContext *ctx) {
	GRect bounds = layer_get_bounds(layer);
	uint16_t width = bounds.size.w - (2 * PADDING);
	uint16_t max_height = bounds.size.h - (2 * PADDING);

	//set the colour
	graphics_context_set_fill_color(ctx, COLOR_FALLBACK(GColorRed, GColorWhite));	

	//display the seconds
	graphics_fill_rect(ctx, GRect(((s_sec * width)/60) + PADDING, 84 - 10, 2, 19), 0 ,0);

	//display the hours

	//left hours------------------------------ 
	int8_t cur_hours = s_hour % 12;
	if (cur_hours == 0) {
		cur_hours = 12;
	}

	int8_t left_hours = cur_hours;
	if (cur_hours > 6) {
		left_hours = 6;
	}
	GPathInfo HOURS_LEFT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(left_hours*width/12) + 2,0},{(left_hours*width/12) + 2,27},{0,27}}
	};

	GPath *s_hours_path_left = gpath_create(&HOURS_LEFT_PATH_INFO);
	gpath_rotate_to(s_hours_path_left, DEG_TO_TRIGANGLE(-45));
	gpath_move_to(s_hours_path_left, GPoint(3,32 + PADDING));
	gpath_draw_filled(ctx, s_hours_path_left);

	//right hours------------------------------ 
	
	int8_t right_hours = cur_hours;
	if (cur_hours < 6) {
		right_hours = 0;
	} else {
		right_hours = cur_hours - 6;
	}

	GPathInfo HOURS_RIGHT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(right_hours*width/12) + 2,0},{(right_hours*width/12) + 2,27},{0,27}}
	};

	GPath *s_hours_path_right = gpath_create(&HOURS_RIGHT_PATH_INFO);
	gpath_rotate_to(s_hours_path_right, DEG_TO_TRIGANGLE(45));
	gpath_move_to(s_hours_path_right, GPoint(width - 32 + 8, 1));
	gpath_draw_filled(ctx, s_hours_path_right);

	//display the minutes
	
	//left minutes------------------------------ 
	int8_t left_mins = s_min;
	if (s_min > 30) {
		left_mins = 30;
	}

	GPathInfo MINS_LEFT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(left_mins*width/60) + 1,0},{(left_mins*width/60) + 1, 27},{0,27}}
	};
	
	GPath *s_mins_path_left = gpath_create(&MINS_LEFT_PATH_INFO);
	gpath_rotate_to(s_mins_path_left, DEG_TO_TRIGANGLE(45));
	gpath_move_to(s_mins_path_left, GPoint(PADDING + 10, max_height - 32 - 11));
	gpath_draw_filled(ctx, s_mins_path_left);

	//right minutes------------------------------ 
	int8_t right_mins = s_min;
	if (s_min < 30) {
		right_mins = 0;
	} else {
		right_mins = s_min - 30;
	}

	GPathInfo MINS_RIGHT_PATH_INFO = {
		.num_points = 4,
		.points = (GPoint []) {{0,0},{(right_mins*width/60) + 1,0},{(right_mins*width/60) + 1, 27},{0,27}}
	};

	GPath *s_mins_path_right = gpath_create(&MINS_RIGHT_PATH_INFO);
	gpath_rotate_to(s_mins_path_right, DEG_TO_TRIGANGLE(-45));
	gpath_move_to(s_mins_path_right, GPoint(width - 32 - PADDING + 1, max_height));
	gpath_draw_filled(ctx, s_mins_path_right);
}

static void set_background_color(int color) {
	GColor background_color = GColorFromHEX(color);
	window_set_background_color(window, background_color);
}

static void inbox_received_handler(DictionaryIterator *iter, void *context) {
	APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler");
	Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR);

	if (background_color_t) {
		int background_color = background_color_t->value->int32;
		if (background_color == 0) { //quick fix so that black colour persists
			background_color++;
		}
		persist_write_int(KEY_BACKGROUND_COLOR, background_color);
		set_background_color(background_color);

		APP_LOG(APP_LOG_LEVEL_DEBUG, "background color: %d", background_color);
	}
}

static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);

	s_layer = layer_create(layer_get_bounds(window_get_root_layer(window)));
	layer_add_child(window_get_root_layer(window), s_layer);
	layer_set_update_proc(s_layer, draw_watchface);

	uint16_t width = bounds.size.w - (2 * PADDING);
	uint16_t max_height = bounds.size.h - (2 * PADDING);

	//create the ternary seconds image
	s_ternary_seconds_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SECONDS_TERNARY_REFLECT);
	s_ternary_seconds_layer = bitmap_layer_create(GRect(PADDING, 0, width + 1, 168));
	bitmap_layer_set_background_color(s_ternary_seconds_layer, GColorClear);
	bitmap_layer_set_bitmap(s_ternary_seconds_layer, s_ternary_seconds_bitmap);
	bitmap_layer_set_compositing_mode(s_ternary_seconds_layer, GCompOpSet);
	layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_ternary_seconds_layer));

	//create the left hours image
	s_unary_hours_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_6_SINGLE_BLOCKS);
	s_unary_hours_layer_left = rot_bitmap_layer_create(s_unary_hours_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_unary_hours_layer_left, GColorClear);
	rot_bitmap_set_compositing_mode(s_unary_hours_layer_left, GCompOpSet);
	rot_bitmap_layer_set_angle(s_unary_hours_layer_left, DEG_TO_TRIGANGLE(-45));

	//position the frame
	GRect r = layer_get_frame((Layer *) s_unary_hours_layer_left);
	r.origin.x = 2;
	layer_set_frame((Layer *) s_unary_hours_layer_left, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_unary_hours_layer_left);

	//create the right hours image
	s_unary_hours_layer_right = rot_bitmap_layer_create(s_unary_hours_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_unary_hours_layer_right, GColorClear);
	rot_bitmap_set_compositing_mode(s_unary_hours_layer_right, GCompOpSet);
	rot_bitmap_layer_set_angle(s_unary_hours_layer_right, DEG_TO_TRIGANGLE(45));

	//position the frame
	r = layer_get_frame((Layer *) s_unary_hours_layer_right);
	r.origin.x = width - 32 - PADDING; 
	layer_set_frame((Layer *) s_unary_hours_layer_right, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_unary_hours_layer_right);

	//create the left minutes image
	s_ternary_minutes_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_30_TERNARY);	
	s_ternary_minutes_layer_left = rot_bitmap_layer_create(s_ternary_minutes_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_ternary_minutes_layer_left, GColorClear);
	rot_bitmap_set_compositing_mode(s_ternary_minutes_layer_left, GCompOpSet);
	rot_bitmap_layer_set_angle(s_ternary_minutes_layer_left, DEG_TO_TRIGANGLE(45));

	//position the frame
	r = layer_get_frame((Layer *) s_ternary_minutes_layer_left);
	r.origin.x = 2;
	r.origin.y = max_height - 32 - PADDING;
	layer_set_frame((Layer *) s_ternary_minutes_layer_left, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_ternary_minutes_layer_left);

	//create the right minutes image
	s_ternary_minutes_layer_right = rot_bitmap_layer_create(s_ternary_minutes_bitmap);
	rot_bitmap_layer_set_corner_clip_color(s_ternary_minutes_layer_right, GColorClear);
	rot_bitmap_set_compositing_mode(s_ternary_minutes_layer_right, GCompOpSet);
	rot_bitmap_layer_set_angle(s_ternary_minutes_layer_right, DEG_TO_TRIGANGLE(-45));

	//position the frame
	r = layer_get_frame((Layer *) s_ternary_minutes_layer_right);
	r.origin.x = width - 32 - PADDING;
	r.origin.y = max_height - 32 - PADDING;
	layer_set_frame((Layer *) s_ternary_minutes_layer_right, r);
	layer_add_child(window_get_root_layer(window), (Layer *) s_ternary_minutes_layer_right);

	if (persist_read_int(KEY_BACKGROUND_COLOR)) {
		set_background_color(persist_read_int(KEY_BACKGROUND_COLOR));
	}
}

static void window_unload(Window *window) {
	gbitmap_destroy(s_ternary_seconds_bitmap);
	bitmap_layer_destroy(s_ternary_seconds_layer);

	gbitmap_destroy(s_unary_hours_bitmap);
	rot_bitmap_layer_destroy(s_unary_hours_layer_left);
	rot_bitmap_layer_destroy(s_unary_hours_layer_right);

	gbitmap_destroy(s_ternary_minutes_bitmap);
	rot_bitmap_layer_destroy(s_ternary_minutes_layer_left);
	rot_bitmap_layer_destroy(s_ternary_minutes_layer_right);
}