Example #1
0
void update_clock_area_layer(Layer *l, GContext* ctx) {
  // check layer bounds
  GRect bounds = layer_get_unobstructed_bounds(l);

  #ifdef PBL_ROUND
    bounds = GRect(0, ROUND_VERTICAL_PADDING, screen_rect.size.w, screen_rect.size.h - ROUND_VERTICAL_PADDING * 2);
  #endif

  // initialize FCTX, the fancy 3rd party drawing library that all the cool kids use
  FContext fctx;

  fctx_init_context(&fctx, ctx);
  fctx_set_color_bias(&fctx, 0);
  fctx_set_fill_color(&fctx, globalSettings.timeColor);


  // calculate font size
  int font_size = 4 * bounds.size.h / 7;

  // avenir + avenir bold metrics
  int v_padding = bounds.size.h / 16;
  int h_adjust = 0;
  int v_adjust = 0;

  // alternate metrics for LECO
  if(globalSettings.clockFontId == FONT_SETTING_LECO) {
    font_size = 4 * bounds.size.h / 7 + 6;
    v_padding = bounds.size.h / 20;
    h_adjust = -4;
    v_adjust = 0;

    // leco looks awful with antialiasing
    #ifdef PBL_COLOR
      fctx_enable_aa(false);
    #endif
  } else {
    #ifdef PBL_COLOR
      fctx_enable_aa(true);
    #endif
  }

  // if it's a round watch, EVERYTHING CHANGES
  #ifdef PBL_ROUND
    v_adjust = ROUND_VERTICAL_PADDING;

    if(globalSettings.clockFontId != FONT_SETTING_LECO) {
      h_adjust = -1;
    }
  #else
    // for rectangular watches, adjust X position based on sidebar position
    if(globalSettings.sidebarOnLeft) {
      h_adjust += ACTION_BAR_WIDTH / 2;
    } else {
      h_adjust -= ACTION_BAR_WIDTH / 2 + 1;
    }
  #endif

  FPoint time_pos;
  fctx_begin_fill(&fctx);
  fctx_set_text_em_height(&fctx, hours_font, font_size);
  fctx_set_text_em_height(&fctx, minutes_font, font_size);

  // draw hours
  time_pos.x = INT_TO_FIXED(bounds.size.w / 2 + h_adjust);
  time_pos.y = INT_TO_FIXED(v_padding + v_adjust);
  fctx_set_offset(&fctx, time_pos);
  fctx_draw_string(&fctx, time_hours, hours_font, GTextAlignmentCenter, FTextAnchorTop);

  //draw minutes
  time_pos.y = INT_TO_FIXED(bounds.size.h - v_padding + v_adjust);
  fctx_set_offset(&fctx, time_pos);
  fctx_draw_string(&fctx, time_minutes, minutes_font, GTextAlignmentCenter, FTextAnchorBaseline);
  fctx_end_fill(&fctx);

  fctx_deinit_context(&fctx);
}
Example #2
0
void on_layer_update(Layer* layer, GContext* ctx) {

    GRect bounds = layer_get_bounds(layer);
    FPoint center = FPointI(bounds.size.w / 2, bounds.size.h / 2);
    int16_t outer_radius = bounds.size.w / 2 - BEZEL_INSET;
    int16_t pip_size = 6;
    int32_t minute_angle = g_local_time.tm_min * TRIG_MAX_ANGLE / 60;
    int32_t hour_angle = (g_local_time.tm_hour % 12) * TRIG_MAX_ANGLE / 12
                       +  g_local_time.tm_min        * TRIG_MAX_ANGLE / (12 * 60);
    char date_string[3];
    strftime(date_string, sizeof date_string, "%d", &g_local_time);

    FContext fctx;
    fctx_init_context(&fctx, ctx);
    fctx_set_color_bias(&fctx, 0);
    fctx_set_fill_color(&fctx, GColorBlack);

    /* Draw the pips. */
    fixed_t bar_length = INT_TO_FIXED(pip_size);
    fixed_t dot_radius = INT_TO_FIXED(pip_size - 4) / 2;
    fixed_t pips_radius = INT_TO_FIXED(outer_radius) - INT_TO_FIXED(pip_size) / 2;
    fctx_begin_fill(&fctx);
    fctx_set_pivot(&fctx, FPoint(0, pips_radius));
    fctx_set_offset(&fctx, center);
    for (int m = 0; m < 60; ++m) {
        int32_t angle = m * TRIG_MAX_ANGLE / 60;
        if (0 == m % 5) {
            fixed_t pipw = (m % 15 == 0) ? INT_TO_FIXED(2) : INT_TO_FIXED(1);
            fctx_set_rotation(&fctx, angle);
            fctx_move_to(&fctx, FPoint(-pipw, -bar_length / 2));
            fctx_line_to(&fctx, FPoint( pipw, -bar_length / 2));
            fctx_line_to(&fctx, FPoint( pipw,  bar_length / 2));
            fctx_line_to(&fctx, FPoint(-pipw,  bar_length / 2));
            fctx_close_path(&fctx);
        } else {
            FPoint p = clockToCartesian(center, pips_radius, angle);
            fctx_plot_circle(&fctx, &p, dot_radius);
        }
    }
    fctx_end_fill(&fctx);

    /* Set up for drawing the hands. */
    int16_t from_size = 90;
    int16_t to_size = outer_radius - pip_size;
    fctx_set_scale(&fctx, FPoint(from_size, from_size), FPoint(to_size, to_size));
    fctx_set_pivot(&fctx, FPointI(90, 90));
    fctx_set_offset(&fctx, center);

    /* Draw the hour hand. */
    fctx_begin_fill(&fctx);
    fctx_set_fill_color(&fctx, GColorDarkGray);
    fctx_set_rotation(&fctx, hour_angle);
    fctx_draw_commands(&fctx, FPointZero, g_hour->data, g_hour->size);
    fctx_end_fill(&fctx);

    /* Draw the minute hand. */
    fctx_begin_fill(&fctx);
    fctx_set_fill_color(&fctx, GColorBlack);
    fctx_set_rotation(&fctx, minute_angle);
    fctx_draw_commands(&fctx, FPointZero, g_minute->data, g_minute->size);
    fctx_end_fill(&fctx);

    /* Draw the body. */
    fctx_begin_fill(&fctx);
    fctx_set_fill_color(&fctx, GColorBlack);
    fctx_set_rotation(&fctx, 0);
    fctx_draw_commands(&fctx, FPointZero, g_body->data, g_body->size);
    fctx_end_fill(&fctx);

    /* Draw the date. */
    FPoint date_pos;
    date_pos.x = center.x + INT_TO_FIXED( 5) * to_size / from_size;
    date_pos.y = center.y + INT_TO_FIXED(48) * to_size / from_size;
    fctx_begin_fill(&fctx);
    fctx_set_text_em_height(&fctx, g_font, 30 * to_size / from_size);
    fctx_set_fill_color(&fctx, GColorWhite);
    fctx_set_pivot(&fctx, FPointZero);
    fctx_set_offset(&fctx, date_pos);
    fctx_set_rotation(&fctx, -5 * TRIG_MAX_ANGLE / (2*360));
    fctx_draw_string(&fctx, date_string, g_font, GTextAlignmentCenter, FTextAnchorBaseline);
    fctx_end_fill(&fctx);

    fctx_deinit_context(&fctx);
}