コード例 #1
0
ファイル: nyan_watch.c プロジェクト: MWells14/Nyan-Watch
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Main");
  window_stack_push(&window, true /* Animated */);
  window_set_background_color(&window, GColorBlack);
  resource_init_current_app(&APP_RESOURCES);

  frame_animation_init(&gif_animation, &window.layer, GPoint(0,0), RESOURCE_ID_FRAME_1, 12, false, true);
  timer_handle = app_timer_send_event(ctx, 100, 1);


  text_layer_init(&text_time_layer, GRect(0, 5, 144, 30));
  text_layer_set_text_color(&text_time_layer, GColorWhite);
  text_layer_set_background_color(&text_time_layer, GColorClear);
  text_layer_set_text_alignment(&text_time_layer, GTextAlignmentCenter);
  text_layer_set_font(&text_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  layer_add_child(&window.layer, &text_time_layer.layer);

  text_layer_init(&date_layer, GRect(0, 130, 144, 30));
  text_layer_set_text_color(&date_layer, GColorWhite);
  text_layer_set_background_color(&date_layer, GColorClear);
  text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter);
  text_layer_set_font(&date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  layer_add_child(&window.layer, &date_layer.layer);

}
コード例 #2
0
ファイル: dragon_clock.c プロジェクト: BitHangar/watch-dragon
void handle_init(AppContextRef ctx) {
	(void)ctx;
    	
	window_init(&window, "Dragon Clock");
	window_stack_push(&window, true /* Animated */);
	
	resource_init_current_app(&APP_RESOURCES);
    
    // Set up layer for the hour hand
	rotbmp_init_container(RESOURCE_ID_DRAGON_HOUR_HAND, &hour_hand_image_container);
	rot_bitmap_set_src_ic(&hour_hand_image_container.layer, GPoint(2, 28));
	layer_add_child(&window.layer, &hour_hand_image_container.layer.layer);
	
	// Set up layer for the minute hand
	rotbmp_init_container(RESOURCE_ID_DRAGON_MINUTE_HAND, &minute_hand_image_container);
	rot_bitmap_set_src_ic(&minute_hand_image_container.layer, GPoint(0, 45));
	layer_add_child(&window.layer, &minute_hand_image_container.layer.layer);
    
    // Set up layer for dragon background image
	layer_init(&background_layer, window.layer.frame);

	// Using a "hack" to get a transparent png to render without slowing the watch down to a crawl.
	// Usually a transparent png needs a RotBmpPairContainer, but in this case we are taking both
	// the white part and the black part and rendering them in separate BmpContainers, then setting
	// the compositing of each, and finally putting images on the same layer, thus creating a 
	// "transparent" bitmap. Thanks to Philip from Pebble for this "completely un-endorsed, 
	// un-official, don't-actually-do-this-in-production-code" suggestion :)
    bmp_init_container(RESOURCE_ID_DRAGON_BACKGROUND_WHITE, &background_image_container_white);
    background_image_container_white.layer.compositing_mode = GCompOpOr;
    layer_add_child(&background_layer, &background_image_container_white.layer.layer);
    
    bmp_init_container(RESOURCE_ID_DRAGON_BACKGROUND_BLACK, &background_image_container_black);
    background_image_container_black.layer.compositing_mode = GCompOpClear;
    layer_add_child(&background_layer, &background_image_container_black.layer.layer);
    
    layer_add_child(&window.layer, &background_layer);

    // Set up layer that will hold the blink animation
   	frame_animation_init(&blink_animation, &window.layer, GPoint(11, 111), RESOURCE_ID_DRAGON_BLINK_1_WHITE, 4, true, true);

	update_hand_positions(&hour_hand_image_container, &minute_hand_image_container);	
}