Ejemplo n.º 1
0
//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);
}
Ejemplo n.º 2
0
static void update_hands(Layer *layer, GContext *context) {
    // Get a tm structure
  time_t temp = time(NULL); 
  struct tm *tick_time = localtime(&temp);

  GRect bounds = layer_get_bounds(layer);
  GPoint layer_center_point = GPoint(bounds.size.w / 2, bounds.size.h / 2);
  
  graphics_context_set_antialiased(context, true);
  graphics_context_set_compositing_mode(context, GCompOpSet);

  int his_angle = (tick_time->tm_min - hand_his_correction) / 60.0f * TRIG_MAX_ANGLE;  
  graphics_draw_rotated_bitmap(context, hand_his, hand_his_rotation_center, his_angle, layer_center_point);

  float hours = tick_time->tm_hour + tick_time->tm_min / 60.0f;
  int her_angle = (hours - hand_her_correction) / 12.0f * TRIG_MAX_ANGLE;
  graphics_draw_rotated_bitmap(context, hand_her, hand_her_rotation_center, her_angle, layer_center_point);
  
  GRect batch_rect = GRect(layer_center_point.x - 14, layer_center_point.y - 15, 30, 30);
  graphics_draw_bitmap_in_rect(context, batch, batch_rect);
}