static void draw_rectangle(GContext *ctx, GRect rectangle, bool filled) {
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, rectangle, canvas_corner_radius, canvas_corner_mask);
  
  if (canvas_fill_px > 0) {
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_fill_rect(ctx, grect_crop(rectangle,canvas_fill_px), \
                       canvas_corner_radius, canvas_corner_mask);
  }
  
  if (!filled) {
    graphics_context_set_fill_color(ctx, GColorWhite);
    graphics_fill_rect(ctx, grect_crop(rectangle,canvas_border_px), \
                       canvas_corner_radius, canvas_corner_mask);
  }
}
Beispiel #2
0
static void handle_init(void) {
  s_main_window = window_create();
  
  Layer *window_layer = window_get_root_layer(s_main_window);
  GRect bounds = layer_get_frame(window_layer);

  s_battery_layer = text_layer_create(GRect(0, 0, 144, 20));
  window_stack_push(s_main_window, true);
  
  s_graph_layer = layer_create(grect_crop(GRect(0, 0, bounds.size.w, bounds.size.h - 34), 10));
  layer_set_update_proc(s_graph_layer, update_graph_layer);
  
  s_battery_layer = text_layer_create(GRect(0, bounds.size.h - 34, bounds.size.w, 34));
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentCenter);
  text_layer_set_text(s_battery_layer, "12/31 23:59 100%");
  
  layer_add_child(window_layer, s_graph_layer);
  layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
  
  wakeup_service_subscribe(handle_wakeup);
  
  wakeup_cancel_all();
  schedule_wakeup_measure_battery_state();
  
  BatteryChargeState charge_state = battery_state_service_peek();
  save_charge_state(&charge_state);
  
  update_last_charge_log();
}
Beispiel #3
0
void battery_level_layer_update_proc(Layer *layer, GContext *ctx) {
    if (!my_window) return;
    GRect bounds = layer_get_bounds(layer);
    bounds = layer_get_frame(layer);

    GRect r = GRect(0, 0, bounds.size.w, bounds.size.h);
    graphics_context_set_stroke_color(ctx, GColorOrange);
    graphics_draw_rect(ctx, r);
    graphics_draw_rect(ctx, grect_crop(r, 1));

    //battery level bar is coloured in the middle third (with 2 pixels top & bottom): ||   ===   ||
    int third = (bounds.size.h - 4) / 3; //height of screen
//    r = GRect(0, 0.5 * third + 2, bounds.size.w, 1.5 * third + 2);
    r = GRect(0, third + 2, bounds.size.w, 2 * third + 2);
    graphics_context_set_fill_color(ctx, GColorOrange);
    graphics_fill_rect(ctx, r, 0, GCornerNone);
}
void pptoaster_draw(struct Layer *layer, GContext *g) {
  static GTextLayoutCacheRef text_layout_cache;

  GRect bounds = layer_get_frame(layer);
  bounds.origin = GPointZero;

  graphics_context_set_fill_color(g, GColorWhite);
  graphics_context_set_stroke_color(g, GColorBlack);
  graphics_context_set_text_color(g, GColorBlack);
  graphics_fill_rect(g, bounds, PPTOASTER_CORNER_RADIUS, GCornersAll);
  graphics_draw_round_rect(g, bounds, PPTOASTER_CORNER_RADIUS);
  
  if (bounds.size.h > PPTOASTER_TEXT_INSET * 2) {
    bounds = grect_crop(bounds, PPTOASTER_TEXT_INSET);
  }

  graphics_draw_text(g, pptoaster.message, pptoaster.font, bounds, GTextOverflowModeFill, GTextAlignmentCenter, text_layout_cache);
}
Beispiel #5
0
static void my_hand_draw(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);
  
  time_t temp = time(NULL); 
  struct tm *tick_time = localtime(&temp);
  int bhour = tick_time->tm_hour;
  int bmin = tick_time->tm_min;
  
  float angle = 30 * ((float)(bhour % 12) + ((float)bmin / 60));
  if (debug) angle = 12 * tick_time->tm_sec; ;
  graphics_context_set_stroke_width(ctx, 2);
  graphics_context_set_stroke_color(ctx, GColorRed);
  graphics_draw_line(ctx,
                     gpoint_from_polar(grect_crop(bounds, 60), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                     gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle+180)));    
    
  
  //GPoint textLocation = gpoint_from_polar(grect_crop(bounds, 50), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle));
  //  layer_set_frame((Layer *)s_battery_layer,
  //    GRect(textLocation.x-10, textLocation.y-10, 20, 200));
}
Beispiel #6
0
static void my_face_draw(Layer *layer, GContext *ctx) {
  GRect bounds = layer_get_bounds(layer);

  // Draw a white filled circle a radius of half the layer height
  graphics_context_set_fill_color(ctx, GColorWhite);
  const int16_t half_h = bounds.size.h / 2;
  
  graphics_draw_circle (ctx, GPoint(half_h, half_h), 90);
  
  
  
  
  graphics_context_set_stroke_width(ctx, 2);
  graphics_context_set_text_color(ctx, GColorBlack);
  
  GPoint center = grect_center_point(&bounds);                   
                                     
  for(int i=0; i<12; i++) {
    int angle = i * 30;
  
    static char buf[] = "000";    /* <-- implicit NUL-terminator at the end here */
    snprintf(buf, sizeof(buf), "%02d", i==0?12:i);
    int ascender = 8;
    GPoint text_point = gpoint_from_polar(grect_crop(bounds, 50), GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle));
    GRect text_rect = GRect(text_point.x - 24, text_point.y - 24, 48, 48);

    GSize size = graphics_text_layout_get_content_size(buf,
                                                       fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
                                                       text_rect, GTextOverflowModeWordWrap, GTextAlignmentLeft);
      
    ///graphics_draw_bitmap_in_rect(ctx, image, layer_get_bounds(layer));
    
    text_rect.size = size;
    text_rect.size.h -= ascender;
    text_rect.origin = GPoint(text_point.x - size.w/2, text_point.y -size.h/2);
    
    graphics_draw_text(ctx, buf,
                       fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD),
                       grect_inset(text_rect, GEdgeInsets4(-8, 0, 0, 0)),
                       GTextOverflowModeWordWrap, GTextAlignmentRight, NULL);
 

    //graphics_draw_rect(ctx, text_rect);
    // Draw hour
    
   graphics_context_set_stroke_color(ctx, GColorBlack);
    graphics_context_set_stroke_width(ctx, 2);
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 30), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));    
    
    angle += 15;
    // Draw half hour
    
   graphics_context_set_stroke_color(ctx, GColorDarkGray);
    graphics_context_set_stroke_width(ctx, 2);
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 10), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));
    
    
    angle += 7.5;
    // Draw quarter hours
    
   graphics_context_set_stroke_color(ctx, GColorDarkGray);
    graphics_context_set_stroke_width(ctx, 2);
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 10), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));
    angle -= 15;
    graphics_draw_line(ctx,
                       gpoint_from_polar(grect_crop(bounds, 10), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle)),
                       gpoint_from_polar(bounds, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(angle)));
  } 

  
}