コード例 #1
0
static void init(void) {

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

  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  // Init the layer for the minute display
  minute_display_layer = layer_create(bounds);
  layer_set_update_proc(minute_display_layer, minute_display_layer_update_callback);
  layer_add_child(window_layer, minute_display_layer);


  // Init the minute segment path
  minute_segment_path = gpath_create(&MINUTE_SEGMENT_PATH_POINTS);
  gpath_move_to(minute_segment_path, grect_center_point(&bounds));


  // Init the layer for the hour display
  hour_display_layer = layer_create(bounds);
  layer_set_update_proc(hour_display_layer, hour_display_layer_update_callback);
  layer_add_child(window_layer, hour_display_layer);


  // Init the hour segment path
  hour_segment_path = gpath_create(&HOUR_SEGMENT_PATH_POINTS);
  gpath_move_to(hour_segment_path, grect_center_point(&bounds));

  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
}
コード例 #2
0
ファイル: modern.c プロジェクト: BUSHA/pebble
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Modern Watch");
  window_stack_push(&window, true /* Animated */);
  resource_init_current_app(&APP_RESOURCES);

#if DISPLAY_DATE_ANALOG
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_DATEBOX, &background_image_container);
#elif INVERTED
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_INVERTED, &background_image_container);
#else
  bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container);
#endif
  layer_add_child(&window.layer, &background_image_container.layer.layer);

#if DISPLAY_DATE_ANALOG
  date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ORBITRON_MEDIUM_12));
  text_layer_init(&date_layer, GRect(116, 77, 20, 20));
#else
  date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DIGITALDREAM_NARROW_12));
  text_layer_init(&date_layer, GRect(27, 110, 90, 30));
#endif
#if DISPLAY_DATE_ANALOG
  text_layer_set_text_color(&date_layer, GColorBlack);
#elif INVERTED
  text_layer_set_text_color(&date_layer, GColorBlack);
#else
  text_layer_set_text_color(&date_layer, GColorWhite);
#endif
  text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter);
  text_layer_set_background_color(&date_layer, GColorClear);
  text_layer_set_font(&date_layer, date_font);
  layer_add_child(&window.layer, &date_layer.layer);

  draw_date();

  layer_init(&hour_display_layer, window.layer.frame);
  hour_display_layer.update_proc = &hour_display_layer_update_callback;
  layer_add_child(&window.layer, &hour_display_layer);

  gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS);
  gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame));

  layer_init(&minute_display_layer, window.layer.frame);
  minute_display_layer.update_proc = &minute_display_layer_update_callback;
  layer_add_child(&window.layer, &minute_display_layer);

  gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS);
  gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame));

  layer_init(&center_display_layer, window.layer.frame);
  center_display_layer.update_proc = &center_display_layer_update_callback;
  layer_add_child(&window.layer, &center_display_layer);
#if DISPLAY_SECONDS
  layer_init(&second_display_layer, window.layer.frame);
  second_display_layer.update_proc = &second_display_layer_update_callback;
  layer_add_child(&window.layer, &second_display_layer);
#endif
}
コード例 #3
0
ファイル: zerozero7.c プロジェクト: cloud74pebble/zz7
//Funktionen MainWindow
static void draw_background(Layer *layer, GContext *ctx) {

  // Get a tm structure
  time_t temp = time(NULL); 
  struct tm *tick_time = localtime(&temp);

  int hour = tick_time->tm_hour;
  int i_corr = 0;
  
  if (hour > 12){
    hour = hour -12;
  }
  
  if ((hour == 3) || (hour == 9)) {
    i_corr = 0;
  }
 
  // Get image center
  GRect img_bounds = gbitmap_get_bounds(s_background_bitmap);
  GPoint src_ic = grect_center_point(&img_bounds);

  // Get context center
  GRect ctx_bounds = layer_get_bounds(layer);
  GPoint ctx_ic = grect_center_point(&ctx_bounds);
  
  // Angle of rotation
  int angle = ((hour * TRIG_MAX_ANGLE) / 12) + i_corr ;

  // Draw!
  graphics_draw_rotated_bitmap(ctx, s_background_bitmap, src_ic, angle, ctx_ic);
}
コード例 #4
0
ファイル: plain.c プロジェクト: 7bp/pebble
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Plain Watch");
  window_stack_push(&window, true /* Animated */);
  window_set_background_color(&window, GColorBlack);

  resource_init_current_app(&APP_RESOURCES);

  layer_init(&hour_display_layer, window.layer.frame);
  hour_display_layer.update_proc = &hour_display_layer_update_callback;
  layer_add_child(&window.layer, &hour_display_layer);

  gpath_init(&hour_hand_outline_path, &HOUR_HAND_OUTLINE_PATH_POINTS);
  gpath_move_to(&hour_hand_outline_path, grect_center_point(&hour_display_layer.frame));
  gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS);
  gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame));

  layer_init(&minute_display_layer, window.layer.frame);
  minute_display_layer.update_proc = &minute_display_layer_update_callback;
  layer_add_child(&window.layer, &minute_display_layer);

  gpath_init(&minute_hand_outline_path, &MINUTE_HAND_OUTLINE_PATH_POINTS);
  gpath_move_to(&minute_hand_outline_path, grect_center_point(&minute_display_layer.frame));
  gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS);
  gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame));
}
コード例 #5
0
ファイル: Pinwheel.c プロジェクト: DHKaplan/Pinwheel
void handle_init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);
  
  fontRobotoCondensed19  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_19));
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  triangle_overlay_layer = layer_create(bounds);
	layer_set_update_proc(triangle_overlay_layer, triangle_display_layer_update_callback);
	layer_add_child(window_layer, triangle_overlay_layer);
	triangle_overlay_path = gpath_create(&TRIANGLE_OVERLAY_POINTS);
	gpath_move_to(triangle_overlay_path, grect_center_point(&bounds));
  
  // init hand paths
  minute_arrow_path = gpath_create(&MINUTE_HAND_POINTS);
  gpath_move_to(minute_arrow_path, grect_center_point(&bounds));
  
  hour_arrow_path = gpath_create(&HOUR_HAND_POINTS);
  gpath_move_to(hour_arrow_path, grect_center_point(&bounds));

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
  

  s_hands_layer = layer_create(bounds);

  layer_set_update_proc(s_hands_layer, hands_update_proc);
  layer_add_child(window_layer, s_hands_layer);
  
  // Battery Line Basalt
   #ifdef PBL_PLATFORM_BASALT
      GRect line_frame = GRect(22, 160, 104, 6);
      LineLayer = layer_create(line_frame);
      layer_set_update_proc(LineLayer, line_layer_update_callback);
      layer_add_child(window_layer, LineLayer);
   #else //Chalk
      GRect line_round_frame = GRect(1, 1, 180, 180);
      RoundBatteryLayer = layer_create(line_round_frame);
      layer_set_update_proc(RoundBatteryLayer, RoundBatteryLayer_update_callback);
      layer_add_child(window_layer,RoundBatteryLayer);
   #endif
     
  //Service subscribes:
  battery_state_service_subscribe(&handle_battery);
  
  handle_battery(battery_state_service_peek());
  
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  handle_bluetooth(bluetooth_connection_service_peek());
     
  app_focus_service_subscribe(&handle_appfocus);

}
コード例 #6
0
ファイル: brown.c プロジェクト: Japh/pebble-1
void handle_init(AppContextRef ctx) {
    (void)ctx;

    window_init(&window, "Brown Watch");
    window_stack_push(&window, true /* Animated */);

    resource_init_current_app(&APP_RESOURCES);
#if DISPLAY_DATE_SHORT
    bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND_BOX, &background_image_container);
#else
    bmp_init_container(RESOURCE_ID_IMAGE_BACKGROUND, &background_image_container);
#endif
    layer_add_child(&window.layer, &background_image_container.layer.layer);


#if DISPLAY_DATE_SHORT || DISPLAY_DATE_LONG
    date_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_OPENSANS_REGULAR_14));
    text_layer_init(&date_layer, GRect(27, 110, 90, 30));
    text_layer_set_text_alignment(&date_layer, GTextAlignmentCenter);
    text_layer_set_text_color(&date_layer, GColorWhite);
    text_layer_set_background_color(&date_layer, GColorClear);
    text_layer_set_font(&date_layer, date_font);
    layer_add_child(&window.layer, &date_layer.layer);
    draw_date();
#endif

    layer_init(&hour_display_layer, window.layer.frame);
    hour_display_layer.update_proc = &hour_display_layer_update_callback;
    layer_add_child(&window.layer, &hour_display_layer);

    gpath_init(&hour_hand_outline_path, &HOUR_HAND_OUTLINE_PATH_POINTS);
    gpath_move_to(&hour_hand_outline_path, grect_center_point(&hour_display_layer.frame));
    gpath_init(&hour_hand_path, &HOUR_HAND_PATH_POINTS);
    gpath_move_to(&hour_hand_path, grect_center_point(&hour_display_layer.frame));

    layer_init(&minute_display_layer, window.layer.frame);
    minute_display_layer.update_proc = &minute_display_layer_update_callback;
    layer_add_child(&window.layer, &minute_display_layer);

    gpath_init(&minute_hand_outline_path, &MINUTE_HAND_OUTLINE_PATH_POINTS);
    gpath_move_to(&minute_hand_outline_path, grect_center_point(&minute_display_layer.frame));
    gpath_init(&minute_hand_path, &MINUTE_HAND_PATH_POINTS);
    gpath_move_to(&minute_hand_path, grect_center_point(&minute_display_layer.frame));

    layer_init(&center_display_layer, window.layer.frame);
    center_display_layer.update_proc = &center_display_layer_update_callback;
    layer_add_child(&window.layer, &center_display_layer);

#if DISPLAY_SECONDS
    layer_init(&second_display_layer, window.layer.frame);
    second_display_layer.update_proc = &second_display_layer_update_callback;
    layer_add_child(&window.layer, &second_display_layer);
#endif
}
コード例 #7
0
void minute_display_layer_update_callback(Layer *me, GContext* ctx) {

  PblTm t;
  get_time(&t);
  unsigned int angle = t.tm_min * 6;
  unsigned int hr_angle = (t.tm_min / 5) *30;	
  GPoint center = grect_center_point(&me->frame);

  // minute background white
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_fill_circle(ctx, center, 72);

  // five minute sector black 
  graphics_context_set_fill_color(ctx, GColorBlack);
  gpath_rotate_to(&minute5_segment_path, (TRIG_MAX_ANGLE / 360) * hr_angle);  
  gpath_draw_filled(ctx, &minute5_segment_path);
	
  // minute sector white	
  graphics_context_set_fill_color(ctx, GColorWhite);
  gpath_rotate_to(&minute_segment_path, (TRIG_MAX_ANGLE / 360) * angle);	
  gpath_draw_filled(ctx, &minute_segment_path);
  
  // minute markers black	
  graphics_context_set_stroke_color(ctx, GColorBlack);	  
  for (unsigned int i = 0; i < 360; i+=30) {
      gpath_rotate_to(&minute_marker_path, (TRIG_MAX_ANGLE / 360) * i);
      gpath_draw_outline(ctx, &minute_marker_path);
  }

  // black out outer ring	
  graphics_context_set_stroke_color(ctx, GColorBlack);	
  graphics_draw_circle(ctx, center, 73); 	
  graphics_draw_circle(ctx, center, 74); 	
}
コード例 #8
0
void hour_display_layer_update_callback(Layer *me, GContext* ctx) {

  PblTm t;
  get_time(&t);
  unsigned int angle = (t.tm_hour % 12) * 30;
  GPoint center = grect_center_point(&me->frame);
	
  // hour background black
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_circle(ctx, center, 52);
	
  // hour sector white
  graphics_context_set_fill_color(ctx, GColorWhite);
  gpath_rotate_to(&hour_segment_path, (TRIG_MAX_ANGLE / 360) * angle);
  gpath_draw_filled(ctx, &hour_segment_path);

  // rounding hour "sector"	
  graphics_context_set_stroke_color(ctx, GColorBlack);	
  graphics_draw_circle(ctx, center, 50); 	
  graphics_draw_circle(ctx, center, 49); 	
  graphics_draw_circle(ctx, center, 48); 	
  graphics_draw_circle(ctx, center, 47); 	

/*	
 	graphics_context_set_fill_color(ctx, GColorBlack);
 	graphics_fill_circle(ctx, center, 25);	
*/
}
コード例 #9
0
static void hour_display_update_proc(Layer *layer, GContext* ctx) {
  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  unsigned int angle = (t->tm_hour % 12) * 30;
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);

  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_fill_circle(ctx, center, 48);

  for (unsigned int i = 0; i < 360; i += 15) {
    if ((i != angle) && (i != (angle + 15)) && (i != ((angle - 15 + 360) % 360)) ) {
      gpath_rotate_to(s_hour_segment_path, (TRIG_MAX_ANGLE / 360) * i);
      graphics_context_set_fill_color(ctx, GColorBlack);
      gpath_draw_filled(ctx, s_hour_segment_path);
    }
  }

  // Stray pixels
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_circle(ctx, center, 5);
  graphics_context_set_stroke_color(ctx, GColorBlack);
  if ((angle != 0) && (angle != 330)) {
    graphics_draw_pixel(ctx, GPoint(71, 77));
    graphics_draw_pixel(ctx, GPoint(71, 78));
  }
}
コード例 #10
0
ファイル: main.c プロジェクト: x/pebble-test
void pge_init() {
  // Start the game
  pge_begin(GColorWhite, game_logic, game_draw, game_click);

  // Keep a Window reference for adding other UI
  sg_window = pge_get_window();
  sg_window_layer = window_get_root_layer(sg_window);
  sg_bounds = layer_get_bounds(sg_window_layer);
  sg_center = grect_center_point(&sg_bounds);

  // Create players
  player1.color = GColorBlue;
  player1.inset = GEdgeInsets(10);
  player1.velocity = 0;
  player1.loc = 0;
  player1.len = 10000;

  player2.color = GColorRed;
  player2.inset = GEdgeInsets(10);
  player2.velocity = 0.0;
  player2.loc = 0.0;
  player2.len = 10000;

  // create ball
  ball.color = GColorDarkCandyAppleRed;
  ball.center = sg_center;
  ball.vx = 1;
  ball.vy = 1;
}
コード例 #11
0
ファイル: main.c プロジェクト: dombeef/Circumflexus
void layer_ring_update_callback(Layer *layer, GContext* ctx) {	
	time_t tt = time(NULL);
	struct tm *t = localtime(&tt);
	
	unsigned int angle = 0;
	if (t->tm_min != 0) {
		angle = ( t->tm_min + 1 ) * 6;
	}
	
	GRect bounds = layer_get_bounds(layer);
	GPoint center = grect_center_point(&bounds);
	
	graphics_context_set_fill_color(ctx, s_color_ring_1);
	graphics_fill_circle(ctx, center, 73);
	
	graphics_context_set_fill_color(ctx, s_color_ring_2);
	for(; angle < 355; angle += 6) {
		gpath_rotate_to(s_path_ring_segment, (TRIG_MAX_ANGLE / 360) * angle);
		gpath_draw_filled(ctx, s_path_ring_segment);
	}
	
	graphics_context_set_stroke_color(ctx, s_color_bg_out);
	graphics_context_set_stroke_width(ctx, 4);
	graphics_draw_circle(ctx, center, 73);
}
コード例 #12
0
ファイル: main.c プロジェクト: dombeef/Circumflexus
void layer_bg_in_update_callback(Layer *layer, GContext* ctx) {
	GRect bounds = layer_get_bounds(layer);
	GPoint center = grect_center_point(&bounds);
	
	graphics_context_set_fill_color(ctx, s_color_bg_in);
	graphics_fill_circle(ctx, center, 64);
}
コード例 #13
0
static void hands_update_proc(Layer* me, GContext* ctx) {
  const GPoint center = grect_center_point(&me->bounds);
  const int16_t secondHandLength = me->bounds.size.w / 2;

  GPoint secondHand;

  PblTm t;
  get_time(&t);

  int32_t second_angle = TRIG_MAX_ANGLE * t.tm_sec / 60;
  secondHand.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.y;
  secondHand.x = (int16_t)(sin_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.x;

  // second hand
  graphics_context_set_stroke_color(ctx, GColorWhite);
  graphics_draw_line(ctx, secondHand, center);

  // minute/hour hand
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_context_set_stroke_color(ctx, GColorBlack);

  gpath_rotate_to(&s_data.minute_arrow, TRIG_MAX_ANGLE * t.tm_min / 60);
  gpath_draw_filled(ctx, &s_data.minute_arrow);
  gpath_draw_outline(ctx, &s_data.minute_arrow);

  gpath_rotate_to(&s_data.hour_arrow, (TRIG_MAX_ANGLE * (((t.tm_hour % 12) * 6) + (t.tm_min / 10))) / (12 * 6));
  gpath_draw_filled(ctx, &s_data.hour_arrow);
  gpath_draw_outline(ctx, &s_data.hour_arrow);

  // dot in the middle
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, GRect(me->bounds.size.w / 2-1, me->bounds.size.h / 2-1, 3, 3), 0, GCornerNone);
}
コード例 #14
0
ファイル: speed.c プロジェクト: performa62/pebble
void second_display_layer_update_callback(Layer *me, GContext* ctx) {
  (void)me;

  PblTm t;
  get_time(&t);

  int32_t second_angle = t.tm_sec * (0xffff/60);
  int32_t counter_second_angle = t.tm_sec * (0xffff/60);
  if(t.tm_sec<30)
  {
     counter_second_angle += 0xffff/2;
  }
  else
  {
     counter_second_angle -= 0xffff/2;
  }
  int second_hand_length = 60;
  int counter_second_hand_length = 15;

  graphics_context_set_fill_color(ctx, GColorWhite);

  GPoint center = grect_center_point(&me->frame);
  GPoint counter_second = GPoint(center.x + counter_second_hand_length * sin_lookup(counter_second_angle)/0xffff,
				center.y + (-counter_second_hand_length) * cos_lookup(counter_second_angle)/0xffff);
  GPoint second = GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
				center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);

  graphics_draw_line(ctx, counter_second, second);
}
コード例 #15
0
static void hands_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  const GPoint center = grect_center_point(&bounds);
  const int16_t secondHandLength = bounds.size.w / 2;

  GPoint secondHand;

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

  int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
  secondHand.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.y;
  secondHand.x = (int16_t)(sin_lookup(second_angle) * (int32_t)secondHandLength / TRIG_MAX_RATIO) + center.x;

  // second hand
  graphics_context_set_stroke_color(ctx, GColorWhite);
  graphics_draw_line(ctx, secondHand, center);

  // minute/hour hand
  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_context_set_stroke_color(ctx, GColorBlack);

  gpath_rotate_to(minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
  gpath_draw_filled(ctx, minute_arrow);
  gpath_draw_outline(ctx, minute_arrow);

  gpath_rotate_to(hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
  gpath_draw_filled(ctx, hour_arrow);
  gpath_draw_outline(ctx, hour_arrow);

  // dot in the middle
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, GRect(bounds.size.w / 2 - 1, bounds.size.h / 2 - 1, 3, 3), 0, GCornerNone);
}
コード例 #16
0
ファイル: forecast.c プロジェクト: rcgale/PebblePrecipitation
void paths_create() {
    for (int i = 0; i < NUM_WEDGES; i++) {
        if (s_paths[i]) {
            gpath_destroy(s_paths[i]);
        }

        GPathInfo path_info = (GPathInfo) {
            .num_points = 3,
             .points = s_points[i]
        };
        s_paths[i] = gpath_create(&path_info);
        gpath_move_to(s_paths[i], s_center);
    }
}

void paths_destroy() {
    for (int i = 0; i < NUM_WEDGES; i++) {
        gpath_destroy(s_paths[i]);
    }
}

Layer* forecast_create(GRect window_bounds) {
    s_center = grect_center_point(&window_bounds);
    init_points();
    paths_create();
    s_canvas_layer = layer_create(window_bounds);
    //layer_add_child(s_canvas_layer, textlayer_create());
    layer_set_update_proc(s_canvas_layer, draw_forecast);

    static Layer* icons_layer;
    icons_layer = forecast_icons_create(window_bounds);
    layer_add_child(s_canvas_layer, icons_layer);

    return s_canvas_layer;
}
コード例 #17
0
ファイル: main.c プロジェクト: GeekJosh/Pebble-Gaptime
static void main_window_load(Window *window) {
	//get root layer of window
	Layer *window_layer = window_get_root_layer(window);

	//get window dimensions
	GRect bounds = layer_get_bounds(window_layer);

	//add drawing layers
	s_clock_layer_outer = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_outer, draw_clock_layer_outer);
	layer_add_child(window_layer, s_clock_layer_outer);

	s_clock_layer_center = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_center, draw_clock_layer_center);
	layer_add_child(window_layer, s_clock_layer_center);

	s_clock_layer_inner = layer_create(GRect(EDGE, EDGE, bounds.size.w - (EDGE * 2), bounds.size.h - (EDGE * 2)));
	layer_set_update_proc(s_clock_layer_inner, draw_clock_layer_inner);
	layer_add_child(window_layer, s_clock_layer_inner);

	//init text time layer
	GSize max_size = graphics_text_layout_get_content_size(
		"00:00",
		fonts_get_system_font(FONT_KEY_GOTHIC_14),
		GRect(0, 0, bounds.size.w, bounds.size.h),
		GTextOverflowModeTrailingEllipsis,
		GTextAlignmentCenter
	);
	s_text_time = text_layer_create(GRect(
		(bounds.size.w / 2) - (max_size.w / 2),
		(bounds.size.h / 2) - (max_size.h / 2),
		max_size.w,
		max_size.h)
	);
	text_layer_set_background_color(s_text_time, GColorClear);
	text_layer_set_text_color(s_text_time, GColorBlack);
	text_layer_set_font(s_text_time, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	text_layer_set_text_alignment(s_text_time, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(s_text_time));
	toggle_text_time();

	//init inverter layer
	s_layer_invert = inverter_layer_create(GRect(0, 0, bounds.size.w, bounds.size.h));
	layer_add_child(window_layer, inverter_layer_get_layer(s_layer_invert));
	invert_face();

	//store clock layer bounds
	s_clock_bounds = layer_get_bounds(s_clock_layer_outer);
	s_clock_center = grect_center_point(&s_clock_bounds);

	//init hand paths
	s_hand_path_outer = gpath_create(&OUTER_HAND_POINTS);
	gpath_move_to(s_hand_path_outer, s_clock_center);

	s_hand_path_center = gpath_create(&CENTER_HAND_POINTS);
	gpath_move_to(s_hand_path_center, s_clock_center);

	s_hand_path_inner = gpath_create(&INNER_HAND_POINTS);
	gpath_move_to(s_hand_path_inner, s_clock_center);
}
コード例 #18
0
static void hands_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);
  const int16_t second_hand_length = PBL_IF_ROUND_ELSE((bounds.size.w / 2) - 19, bounds.size.w / 2);

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

  // minute/hour hand
  // 時
  graphics_context_set_stroke_color(ctx, s_backColor);

  graphics_context_set_fill_color(ctx, s_hourHandColor);
  gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
  gpath_draw_filled(ctx, s_hour_arrow);
  // 分
  graphics_context_set_fill_color(ctx, s_backColor);
  gpath_rotate_to(s_minute_arrow, (TRIG_MAX_ANGLE * (t->tm_min * 10 + (t->tm_sec/6)) / (60 * 10)));
  graphics_context_set_stroke_width(ctx, 2);
  graphics_context_set_stroke_color(ctx, s_minuteHandColor);
  gpath_draw_outline(ctx, s_minute_arrow);

  // 秒
  int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
  GPoint second_hand = {
    .x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x,
    .y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y,
  };
if (s_show_seconds_hand){
    // second hand
    graphics_context_set_stroke_width(ctx, 3);
    graphics_context_set_stroke_color(ctx, s_secondHandColor);
    graphics_draw_line(ctx, second_hand, center);
    graphics_context_set_stroke_width(ctx, 1);
    graphics_context_set_stroke_color(ctx, s_backColor);
    graphics_draw_line(ctx, second_hand, center);
  }
  // dot in the middle
  // 黒に設定
  graphics_context_set_fill_color(ctx, s_backColor);
  // 円を塗り潰し
  graphics_fill_circle(ctx, center, 7);
  // 線の色を白に設定
  graphics_context_set_stroke_color(ctx, s_secondHandColor);
  graphics_context_set_stroke_width(ctx, 1);
  graphics_draw_circle(ctx, center, 7);
  graphics_draw_circle(ctx, center, 1);
  
}

static void date_update_proc(Layer *layer, GContext *ctx) {
  time_t now = time(NULL);
  struct tm *t = localtime(&now);

  strftime(s_day_buffer, sizeof(s_day_buffer), "%a", t);
  text_layer_set_text(s_day_label, s_day_buffer);

  strftime(s_num_buffer, sizeof(s_num_buffer), "%d", t);
  text_layer_set_text(s_num_label, s_num_buffer);
}
コード例 #19
0
ファイル: storm.c プロジェクト: distantcam/pebble
void month_display_layer_update_callback(Layer *me, GContext* ctx) {
  (void)me;

  PblTm t;

  get_time(&t);

  unsigned int angle = (t.tm_mon + 1) * 15;

  GPoint center = grect_center_point(&me->frame);
  center.y += 10;

  graphics_context_set_fill_color(ctx, GColorWhite);

  graphics_draw_arc(ctx, center, 42, 20, 0, angle);

  //graphics_draw_line(ctx, GPoint(7, center.y), GPoint(20, center.y));
  //graphics_draw_line(ctx, GPoint(124, center.y), GPoint(137, center.y));

  for (int x = 0; x < 2; x++)
    for (int y = 0; y < 2; y++)
    {
      graphics_draw_pixel(ctx, GPoint(center.x - 01 + x, center.y + 18 + y));
      graphics_draw_pixel(ctx, GPoint(center.x - 13 + x, center.y + 13 + y));
      graphics_draw_pixel(ctx, GPoint(center.x + 13 + x, center.y + 13 + y));
    }
}
コード例 #20
0
static void minute_display_layer_update_callback(Layer *layer, GContext* ctx) {

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

  unsigned int angle = t->tm_min * 6;

  gpath_rotate_to(minute_segment_path, (TRIG_MAX_ANGLE / 360) * angle);

  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);

  graphics_context_set_fill_color(ctx, GColorWhite);

  graphics_fill_circle(ctx, center, 77);

  graphics_context_set_fill_color(ctx, GColorBlack);

  // Note: I had intended to use the `GCompOpAssignInverted` mode here
  //       but it appears it's ignored for path/shape drawing.

  gpath_draw_filled(ctx, minute_segment_path);

  graphics_fill_circle(ctx, center, 52);
}
コード例 #21
0
ファイル: main.c プロジェクト: Prieni/revolving
static void minute_display_layer_update_callback(Layer *layer, GContext* ctx) {

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

  unsigned int angle = t->tm_min * 6;

  GRect bounds = layer_get_bounds(layer);
  GRect min_rect;
  GPoint center = grect_center_point(&bounds);
  
  GPoint min_center; // center of the minute circle
  min_center.x = sin_lookup((TRIG_MAX_ANGLE / 360) * angle)*54/TRIG_MAX_RATIO + center.x;
  min_center.y = -cos_lookup((TRIG_MAX_ANGLE / 360) * angle)*54/TRIG_MAX_RATIO + center.y;
  graphics_context_set_fill_color(ctx, FOREGROUND_COLOR);
  graphics_context_set_stroke_color(ctx, FOREGROUND_COLOR);
  graphics_fill_circle(ctx, min_center, 17);
  
  strftime(min_text,sizeof(hour_text),"%M",t);

  min_rect.origin.x = min_center.x - 15;
  min_rect.origin.y = min_center.y - 18;
  min_rect.size.w = 30;
  min_rect.size.h = 15;
  graphics_context_set_text_color(ctx,BACKGROUND_COLOR);
  graphics_draw_text(ctx,min_text,fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD),min_rect,GTextOverflowModeWordWrap,GTextAlignmentCenter,NULL);
}
コード例 #22
0
ファイル: polar_clock.c プロジェクト: culverg/polar5arc
//added by gac and is probably wrong
void month_display_layer_update_callback(Layer *me, GContext* ctx) {

  PblTm t;

  get_time(&t);
  
  unsigned int angle;
  
  //angle = (( t.tm_mon % 12 ) * 30) + (t.tm_mday / 2);
  angle = (( ( t.tm_mon + 1 ) % 12 ) * 30);
  
  angle = angle - (angle % 2);  //use modulo 2 for smaller black overlaps

  GPoint center = grect_center_point(&me->frame);

  graphics_context_set_fill_color(ctx, GColorWhite);

  graphics_fill_circle(ctx, center, 25);

  graphics_context_set_fill_color(ctx, GColorBlack);

  for(; angle < 355; angle += 2) {  //has to be same increment as the modulo in line 231

    gpath_rotate_to(&month_segment_path, (TRIG_MAX_ANGLE / 360) * angle);

    gpath_draw_filled(ctx, &month_segment_path);
  }

  graphics_fill_circle(ctx, center, 20);
}
コード例 #23
0
void initLayerPathAndCenter(Layer *layer, GPath *path, const GPathInfo *pathInfo, const void *updateProc) {
	layer_init(layer, GRect(0, 0, 70, 70));
	layer->update_proc = updateProc;
	layer_add_child(&window.layer, layer);
	gpath_init(path, pathInfo);
	gpath_move_to(path, grect_center_point(&layer->frame));
}
コード例 #24
0
ファイル: polar_clock.c プロジェクト: Japh/pebble
void second_display_layer_update_callback(Layer *me, GContext* ctx) {

  PblTm t;

  get_time(&t);

  unsigned int angle = t.tm_sec * 6;

  GPoint center = grect_center_point(&me->frame);

  graphics_context_set_fill_color(ctx, GColorWhite);

  graphics_fill_circle(ctx, center, 65);

  graphics_context_set_fill_color(ctx, GColorBlack);

  for(; angle < 355; angle += 6) {

    gpath_rotate_to(&second_segment_path, (TRIG_MAX_ANGLE / 360) * angle);

    gpath_draw_filled(ctx, &second_segment_path);

  }

  graphics_fill_circle(ctx, center, 60);

}
コード例 #25
0
ファイル: sprinkles.c プロジェクト: gregoiresage/sprinkles
static void prv_hands_layer_update_proc(Layer *layer, GContext *ctx) {
  const SprinklesConfiguration *configuration = sprinkles_configuration_get_configuration();
  const GRect layer_bounds = layer_get_bounds(layer);
  const GPoint center = grect_center_point(&layer_bounds);

  // Minutes
  const int32_t minutes_angle = s_app_data->current_minutes * TRIG_MAX_ANGLE / 60;
  const int32_t minutes_hand_length = layer_bounds.size.w * 4 / 9;
  prv_draw_major_hands(ctx, &center, minutes_hand_length, minutes_angle,
                       configuration->minute_hand_color);

  // Hours
  int32_t hours_angle = ((s_app_data->current_hours * TRIG_MAX_ANGLE) + minutes_angle) / 12;
  const int32_t hours_hand_length = layer_bounds.size.w * 32 / 100;
  prv_draw_major_hands(ctx, &center, hours_hand_length, hours_angle,
                       configuration->hour_hand_color);

  // Seconds (if enabled in the configuration)
  if (configuration->seconds_hand_enabled) {
    prv_draw_seconds_hand(ctx, &layer_bounds, &center);
  }

  // Draw the dot in the center of the watchface
  const int16_t center_circle_radius = 5;
  graphics_context_set_fill_color(ctx, configuration->center_dot_color);
  graphics_fill_circle(ctx, center, center_circle_radius);

  // Draw the donut
  const int32_t donut_angle = prv_get_donut_angle();
  const GRect donut_rect = prv_get_donut_rect(&layer_bounds, donut_angle);
  graphics_context_set_compositing_mode(ctx, GCompOpSet);
  graphics_draw_bitmap_in_rect(ctx, s_app_data->donut_bitmap, donut_rect);
}
コード例 #26
0
ファイル: polar_clock.c プロジェクト: Japh/pebble
void hour_display_layer_update_callback(Layer *me, GContext* ctx) {

  PblTm t;

  get_time(&t);

  unsigned int angle;

  #if TWENTY_FOUR_HOUR_DIAL
    angle = (t.tm_hour * 15) + (t.tm_min / 4);
  #else
    angle = (( t.tm_hour % 12 ) * 30) + (t.tm_min / 2);
  #endif

  angle = angle - (angle % 6);

  GPoint center = grect_center_point(&me->frame);

  graphics_context_set_fill_color(ctx, GColorWhite);

  graphics_fill_circle(ctx, center, 45);

  graphics_context_set_fill_color(ctx, GColorBlack);

  for(; angle < 355; angle += 6) {

    gpath_rotate_to(&hour_segment_path, (TRIG_MAX_ANGLE / 360) * angle);

    gpath_draw_filled(ctx, &hour_segment_path);
  }

  graphics_fill_circle(ctx, center, 40);
}
コード例 #27
0
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  const GPoint center = grect_center_point(&bounds);
  
  //Load bitmap image
  background_layer = layer_create(bounds);
  layer_set_update_proc(background_layer, background_layer_update);
  layer_add_child(window_layer, background_layer);

  custom_font_text = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BOXY_TEXT_20));
  custom_font_outline = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BOXY_OUTLINE_20));
  
  //Add analog hands
  analog_init(my_window);

  // Render layer ontop for cool transparency
  render_layer = layer_create(bounds);
  layer_set_update_proc(render_layer, render_layer_update);
  layer_add_child(window_layer, render_layer);

  //Force time update
  time_t current_time = time(NULL);
  struct tm *current_tm = localtime(&current_time);
  tick_handler(current_tm, MINUTE_UNIT | DAY_UNIT);

  //Setup tick time handler
  tick_timer_service_subscribe((MINUTE_UNIT), tick_handler);
}
コード例 #28
0
ファイル: main.c プロジェクト: yatul/ModernExtra20
void second_display_layer_update_callback(Layer *me, GContext* ctx) {
	(void) me;

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

	int32_t second_angle = t->tm_sec * (0xffff / 60);
	int second_hand_length = 70;
	GPoint center = grect_center_point(&GRECT_FULL_WINDOW);
	GPoint second = GPoint(center.x, center.y - second_hand_length);

	if (init_anim < ANIM_SECONDS) {
		second = GPoint(center.x, center.y - 70);
	} else if (init_anim == ANIM_SECONDS) {
		second_angle_anim += 0xffff / 60;
		if (second_angle_anim >= second_angle) {
			init_anim = ANIM_DONE;
			second =
					GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
							center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);
		} else {
			second =
					GPoint(center.x + second_hand_length * sin_lookup(second_angle_anim)/0xffff,
							center.y + (-second_hand_length) * cos_lookup(second_angle_anim)/0xffff);
		}
	} else {
		second =
				GPoint(center.x + second_hand_length * sin_lookup(second_angle)/0xffff,
						center.y + (-second_hand_length) * cos_lookup(second_angle)/0xffff);
	}

	graphics_context_set_stroke_color(ctx, GColorWhite);

	graphics_draw_line(ctx, center, second);
}
コード例 #29
0
ファイル: pomodoro.c プロジェクト: jojonki/pomodoro
static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  
  window_set_click_config_provider(window, main_click_config_provider);

  s_center = grect_center_point(&bounds);

  s_main_layer = layer_create(bounds);
  layer_add_child(window_layer, s_main_layer);
  
  // left time label
  s_left_time_label = text_layer_create(GRect(46, 102, 110, 40));
  text_layer_set_background_color(s_left_time_label, GColorClear);
  if(persist_read_int(MODE_REST)) {
    text_layer_set_text_color(s_left_time_label, REST_COLOR);
  } else {
    text_layer_set_text_color(s_left_time_label, CONCENTRATION_COLOR);
  }
  text_layer_set_font(s_left_time_label, fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS));
  layer_add_child(window_layer, text_layer_get_layer(s_left_time_label));

  layer_set_update_proc(s_main_layer, update_main_proc);
  
  // fire timer
  app_timer_register(0, count_timer_handler, NULL);
}
コード例 #30
0
ファイル: ppf.c プロジェクト: reini1305/pastpresentfuture
static void hands_update_proc(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  GPoint center = grect_center_point(&bounds);
  const int16_t hourHandLength = bounds.size.w / 2 +20;
  const int16_t minuteHandLength = hourHandLength - 30;

  GPoint minuteHand;
  center.y +=20;

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

  for (int i=0;i<12;i++)
  {
    int16_t minute_angle = TRIG_MAX_ANGLE * (((59-t->tm_min)+i*5)%60) / 60;
    minuteHand.y = (int16_t)(-cos_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.y;
    minuteHand.x = (int16_t)(sin_lookup(minute_angle) * (int32_t)minuteHandLength / TRIG_MAX_RATIO) + center.x;

    GRect frame = layer_get_frame(text_layer_get_layer(num_layer[i]));
    frame.origin.x = minuteHand.x-frame.size.w/2;
    frame.origin.y = minuteHand.y-frame.size.h/2;
    layer_set_frame(text_layer_get_layer(num_layer[i]),frame);
    layer_set_hidden(text_layer_get_layer(num_layer[i]),false);
    
    int16_t hour_angle = (TRIG_MAX_ANGLE * (((24-t->tm_hour+i) % 12) * 6) +
                         ((TRIG_MAX_ANGLE * (60-t->tm_min)) / 10))     / (12 * 6);
    minuteHand.y = (int16_t)(-cos_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.y;
    minuteHand.x = (int16_t)(sin_lookup(hour_angle) * (int32_t)hourHandLength / TRIG_MAX_RATIO) + center.x;
    
    frame = layer_get_frame(text_layer_get_layer(hour_layer[i]));
    frame.origin.x = minuteHand.x-frame.size.w/2;
    frame.origin.y = minuteHand.y-frame.size.h/2;
    layer_set_frame(text_layer_get_layer(hour_layer[i]),frame);
    layer_set_hidden(text_layer_get_layer(hour_layer[i]),false);

  }
  
  // draw minute line
  if(getDrawline())
  {
    if(getInvert())
      graphics_context_set_stroke_color(ctx,GColorWhite);
    else
      graphics_context_set_stroke_color(ctx,GColorBlack);
    graphics_draw_line(ctx,GPoint(144/2,0),GPoint(144/2,167));
  }
  // draw background
  transbitmap_draw_in_rect(background_bitmap, ctx, bounds);
  
  // draw date
  if(draw_date)
  {
    graphics_context_set_fill_color(ctx,GColorBlack);
    graphics_fill_circle(ctx,GPoint(120,120),16);
    layer_set_hidden(text_layer_get_layer(date_layer),false);
  }
  else
    layer_set_hidden(text_layer_get_layer(date_layer),true);
}