Beispiel #1
0
/*
 * Function: canvas_update_proc
 * ----------------------------------------------------------------------------
 *   Draws the mood graph on the screen.
 *
 *   this_layer: the layer on which to draw on
 *   ctx: the drawing context
 * ----------------------------------------------------------------------------
 */
void canvas_update_proc(Layer *this_layer, GContext *ctx) {
  if (s_path) {
    gpath_destroy(s_path);
  }
  GRect bounds = layer_get_bounds(this_layer);
  int bounds_size_w = bounds.size.w;
  int bounds_size_h = bounds.size.h;
  
  GPathBuilder *builder = gpath_builder_create(MAX_POINTS);

  // Draw a black filled rectangle with sharp corners
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, bounds, 0, GCornerNone);
  
  // Draw the mood lines
  graphics_context_set_fill_color(ctx, GColorWhite);
  
  // Draw the Mood (color) coding rectangles
  draw_mood_areas(ctx, bounds_size_w);
#if PBL_PLATFORM_BASALT
  graphics_context_set_stroke_width(ctx, 1);
#endif

  // Create the mood data graph  
  create_graph(ctx, bounds_size_h, builder);
  // Set the graph line color to white
  graphics_context_set_stroke_color(ctx, GColorWhite); 
  
#ifdef PBL_PLATFORM_BASALT
  // On Pebble Time (Basalt) create path from builder
  s_path = gpath_builder_create_path(builder);
#endif
  gpath_builder_destroy(builder);
#ifdef PBL_PLATFORM_APLITE
  //gpath_draw_outline(ctx, s_path);
#elif PBL_PLATFORM_BASALT
  gpath_draw_outline_open(ctx, s_path);
#endif
  
}
Beispiel #2
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);
    }
}