Exemplo n.º 1
0
static void render_bg(Layer* layer, GContext* ctx) 
{
    APP_LOG(APP_LOG_LEVEL_DEBUG, "render_bg");
    
    GPoint p0 = GPoint(SCREEN_CENTER_X, SCREEN_HEIGHT-CIRCLE_OFFSET);
    
#if PBL_COLOR
    draw_dithered_rect(ctx, GRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT),
                       darkColor, GColorBlack, DITHER_50_PERCENT);
    draw_dithered_circle(ctx, p0.x, p0.y, CIRCLE_RADIUS,
                             darkColor, GColorBlack, DITHER_10_PERCENT);
    draw_dithered_circle(ctx, p0.x, p0.y, CIRCLE_RADIUS/2,
                        darkColor, GColorBlack, DITHER_50_PERCENT);

    graphics_context_set_stroke_color(ctx, lightColor);
    graphics_context_set_fill_color(ctx, lightColor);
#else
    draw_dithered_circle(ctx, p0.x, p0.y, CIRCLE_RADIUS,
                         mTextColor, mBackgroundColor, DITHER_90_PERCENT);
    graphics_fill_circle(ctx, GPoint(p0.x, p0.y), CIRCLE_RADIUS/2);
    
    graphics_context_set_stroke_color(ctx, mTextColor);
    graphics_context_set_fill_color(ctx, mTextColor);
#endif // PBL_COLOR

    // Create GPathBuilder object
    GPathBuilder* builder = gpath_builder_create(MAX_POINTS);
    
    // Move to the starting point of the GPath
    for (int line = 0; line < NUM_LINES; ++line)
    {
        gpath_builder_move_to_point(builder, p0);
        
        const int px = XOFFSET + line*14;
        const int py = GRIDOFFSET*2 + GRIDOFFSET*line;
        GPoint p1 = GPoint(px, py);
        gpath_builder_line_to_point(builder, p1);

        GPoint p2 = GPoint(SCREEN_WIDTH-px, py);
        
        const int cpy = py - GRIDOFFSET + line*4;
        GPoint cp1 = GPoint(SCREEN_WIDTH/3 + line*2, cpy);
        GPoint cp2 = GPoint(SCREEN_WIDTH/3*2 - line*2, cpy);
        gpath_builder_curve_to_point(builder, p2, cp1, cp2);
        
        gpath_builder_line_to_point(builder, p0);
    }
    
    // Create GPath object out of our GPathBuilder object
    s_path = gpath_builder_create_path(builder);
    
    // Display the path
    gpath_draw_outline(ctx, s_path);
    //gpath_draw_filled(ctx, s_path);

    gpath_builder_destroy(builder);
    
    // Draw the bisecting lines
    const int linex = (SCREEN_CENTER_X + XOFFSET) / 2;
    graphics_draw_line(ctx, p0, GPoint(linex, GRIDOFFSET));
    graphics_draw_line(ctx, p0, GPoint(SCREEN_CENTER_X, GRIDOFFSET));
    graphics_draw_line(ctx, p0, GPoint(SCREEN_WIDTH-linex, GRIDOFFSET));
    
    // Draw the black bars
    graphics_context_set_fill_color(ctx, GColorBlack);
    graphics_fill_rect(ctx, GRect(0,0,XOFFSET/2+2,SCREEN_HEIGHT), 0, GCornerNone);
    graphics_fill_rect(ctx, GRect(SCREEN_WIDTH-XOFFSET/2-2,0,SCREEN_WIDTH,SCREEN_HEIGHT), 0, GCornerNone);
    graphics_fill_rect(ctx, GRect(0,SCREEN_HEIGHT-TEXT_SIZE,SCREEN_WIDTH,TEXT_SIZE), 0, GCornerNone);
    
    // Draw the side markers
#if PBL_COLOR
    graphics_context_set_fill_color(ctx, GColorRed);
#else
    graphics_context_set_fill_color(ctx, mTextColor);
#endif // PBL_COLOR
    for (int bar = 0; bar < BAR_NUM; ++bar)
    {
        bool drawBar = (BAR_NUM-bar-1 < mBatteryLevel/10);
        if (drawBar)
        {
            GRect barRect = GRect(0, (BAR_OFFSET+SCREEN_HEIGHT-TEXT_SIZE)/BAR_NUM*bar,
                                  XOFFSET/2, BAR_OFFSET/4);
            graphics_fill_rect(ctx, barRect, 0, GCornerNone);
        
            // Draw the other side
            barRect.origin.x = SCREEN_WIDTH - XOFFSET/2;
            graphics_fill_rect(ctx, barRect, 0, GCornerNone);
        }
    }
    
    // Draw dot for BT indicator. Position is random.
    if (mIsBluetooth)
    {
        int index = rand() % NUM_BLIPS;
        graphics_fill_circle(ctx, GPoint(blipX[index], blipY[index]), 4);
    }
}
Exemplo n.º 2
0
/*
 * Function: draw_graph_part_base
 * ----------------------------------------------------------------------------
 *   Draws the graph curve part between the current weekday and the next day.
 *
 *   ctx: the drawing context
 *   bounds_size_h: the drawing bounds height
 *   s_day: string for the current weekday label
 *   day0: the current weekday
 *   day1: the next weekday
 *   builder: the GPathBuilder used to create the curve
 *   day_shift: used to calculate how many days day0 and day1 should be shifted
 *              by.
 *              When this is not equal to 0 it is used change at what x-
 *              coordinates the days should use.
 *   first_time: Is this the first/initial call to this function?
 * ----------------------------------------------------------------------------
 */
void draw_graph_part_base(GContext *ctx, int bounds_size_h, char* s_day, 
                          int day0, int day1, GPathBuilder *builder, 
                          int day_shift, bool first_time) {
  if (day0 > 6) {day0 -= 7;}
  if (day1 > 6) {day1 -= 7;}
  
  int mood0 = storage_get_mood(day0);
  int mood1 = storage_get_mood(day1);
  if (s_num_moods > 10) {
    // If the number of moods is greater than 10 we need to re-calculate the
    // moods to keep them within the 0 - 10 range of the graph.
    
    // Shift the moods to keep them above or equal to 0:
    // - If Minimum Mood is less than 0 then the absolute min value is added
    //   to the moods ("minus minus equals pluss")
    // - If the Minimum Mood is greater then 0 then the min value is 
    //   subtracted from the moods
    mood0 = mood0 - s_mood_min; // Shift to positive
    mood1 = mood1 - s_mood_min; // Shift to positive
    
    // Divide the mmods by a 10nth of Number of Moods. This ensures that the
    // moods always are within the 0 - 10 range of the graph.
    mood0 = mood0 / (s_num_moods / 10); // divide by 10nth of num moods
    mood1 = mood1 / (s_num_moods / 10); // divide by 10nth of num moods
  }
  
  if (day_shift != 0) {
    day0 += day_shift;
    day1 += day_shift;
    
    if (day0 < 0) { day0 += 7; } 
    else if (day0 > 6) { day0 -= 7; }
    
    if (day1 < 0) { day1 += 7; }
    else if (day1 > 6) { day1 -= 7; }
  }
  GPoint p0 = GPoint(s_day_points[day0], s_mood_points[mood0]);
  GPoint p1 = GPoint(s_day_points[day1], s_mood_points[mood1]);
  
  APP_LOG(APP_LOG_LEVEL_DEBUG, "x(%d) = %d", day0, p0.x);
#ifdef PBL_PLATFORM_APLITE
  // On Original Pebble (Aplite) the graph is only drawn with separate lines 
  // and not as a bezier curve
  // This is due to the aplite platform only supports drawing closed paths 
  // (non-open)
  graphics_draw_line(ctx, p0, p1);
#elif PBL_PLATFORM_BASALT
  // On Pebble Time (Basalt) the graph is drawn as a bezier curve
  
  // Calculations to find bezier curve control points
  int c_x = (p0.x + p1.x) / 2; // Mid-point between p0 and p1
  int c_y = (p0.y + p1.y) / 2; // Mid-point between p0 and p1
  int a_x = (p0.x + c_x) / 2; // Mid-point between p0 and c
  // Find the control point based on that are furthest from the mid-point 
  // y-axis
  int a_y = math_int_find_bezier_control_point(c_y, 100); 
  int b_x = (p1.x + c_x) / 2; // Mid-point between p1 and c
  GPoint p_a = GPoint(a_x, a_y); // 1st control point between p0 and mid-point
  GPoint p_b = GPoint(b_x, a_y); // 2nd control point between mid-point and p1
  if (first_time == true) { // Move the builder to the starting point
    gpath_builder_move_to_point(builder, p0);
  }
  gpath_builder_curve_to_point(builder, p1, p_b, p_a);
#endif
  // Draw the day labels at bottom
  draw_graph_part_day(ctx, bounds_size_h, s_day, day0);
}