Пример #1
0
void BatteryMeter_draw(GContext* ctx, int yPosition) {

  BatteryChargeState chargeState = battery_state_service_peek();

  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  char batteryString[6];
  int batteryPositionY = yPosition - 5; // correct for vertical empty space on battery icon

  if (batteryImage) {
    gdraw_command_image_recolor(batteryImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);
    gdraw_command_image_draw(ctx, batteryImage, GPoint(3 + SidebarWidgets_xOffset, batteryPositionY));
  }

  if(chargeState.is_charging) {
    if(batteryChargeImage) {
      // the charge "bolt" icon uses inverted colors
      gdraw_command_image_recolor(batteryChargeImage, globalSettings.iconStrokeColor, globalSettings.iconFillColor);
      gdraw_command_image_draw(ctx, batteryChargeImage, GPoint(3 + SidebarWidgets_xOffset, batteryPositionY));
    }
  } else {

    int width = roundf(18 * chargeState.charge_percent / 100.0f);

    graphics_context_set_fill_color(ctx, globalSettings.iconStrokeColor);

    if(chargeState.charge_percent <= 20) {
      graphics_context_set_fill_color(ctx, GColorRed);
    }

    graphics_fill_rect(ctx, GRect(6 + SidebarWidgets_xOffset, 8 + batteryPositionY, width, 8), 0, GCornerNone);
  }

  // never show battery % while charging, because of this issue:
  // https://github.com/freakified/TimeStylePebble/issues/11
  if(globalSettings.showBatteryPct && !chargeState.is_charging) {
    if(!globalSettings.useLargeFonts) {
      snprintf(batteryString, sizeof(batteryString), "%d%%", chargeState.charge_percent);

      graphics_draw_text(ctx,
                         batteryString,
                         batteryFont,
                         GRect(-4 + SidebarWidgets_xOffset, 18 + batteryPositionY, 38, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    } else {
      snprintf(batteryString, sizeof(batteryString), "%d", chargeState.charge_percent);

      graphics_draw_text(ctx,
                         batteryString,
                         batteryFont,
                         GRect(-4 + SidebarWidgets_xOffset, 14 + batteryPositionY, 38, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    }
  }
}
Пример #2
0
static void icon_layer_update_proc(Layer *layer, GContext *ctx) {
  switch (current_mood) {
    case TERRIBLE:
      mood_icon = gdraw_command_image_create_with_resource(RESOURCE_ID_ICON_TERRIBLE);
      break;
    case BAD:
      mood_icon = gdraw_command_image_create_with_resource(RESOURCE_ID_ICON_BAD);
      break;
    case GREAT:
      mood_icon = gdraw_command_image_create_with_resource(RESOURCE_ID_ICON_GREAT);
      break;
    case AWESOME:
      mood_icon = gdraw_command_image_create_with_resource(RESOURCE_ID_ICON_AWESOME);
      break;
    default:
    case OK:
      mood_icon = gdraw_command_image_create_with_resource(RESOURCE_ID_ICON_OK);
  }
  if (!mood_icon) {
    return;
  }

  GDrawCommandImage *temp_copy = gdraw_command_image_clone(mood_icon);
  graphics_context_set_antialiased(ctx, true);
  gdraw_command_image_draw(ctx, temp_copy, GPoint(0, 0));
  free(temp_copy);
  free(mood_icon);
  return;
}
Пример #3
0
void Steps_draw(GContext* ctx, int yPosition) {

  if(stepsImage) {
    gdraw_command_image_recolor(stepsImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);
    gdraw_command_image_draw(ctx, stepsImage, GPoint(3 + SidebarWidgets_xOffset, yPosition - 7));
  }

  char steps_text[8];

  if(globalSettings.healthUseDistance) {
    int meters = (int)health_service_sum_today(HealthMetricWalkedDistanceMeters);

    // format distance string
    if(globalSettings.useMetric) {
      if(meters < 1000) {
        snprintf(steps_text, sizeof(steps_text), "%im", meters);
      } else {
        meters /= 1000; // convert to km
        snprintf(steps_text, sizeof(steps_text), "%ikm", meters);
      }
    } else {
      int miles_tenths = meters * 10 / 1609 % 10;
      int miles_whole  = (int)roundf(meters / 1609.0f);

      if(miles_whole > 0) {
        snprintf(steps_text, sizeof(steps_text), "%imi", miles_whole);
      } else {
        snprintf(steps_text, sizeof(steps_text), "%c%imi", globalSettings.decimalSeparator, miles_tenths);
      }
    }
  } else {
    int steps = (int)health_service_sum_today(HealthMetricStepCount);

    // format step string
    if(steps < 1000) {
      snprintf(steps_text, sizeof(steps_text), "%i", steps);
    } else {
      int steps_thousands = steps / 1000;
      int steps_hundreds  = steps / 100 % 10;

      if (steps < 10000) {
        snprintf(steps_text, sizeof(steps_text), "%i%c%ik", steps_thousands, globalSettings.decimalSeparator, steps_hundreds);
      } else {
        snprintf(steps_text, sizeof(steps_text), "%ik", steps_thousands);
      }
    }
  }


  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  graphics_draw_text(ctx,
                     steps_text,
                     mdSidebarFont,
                     GRect(-2 + SidebarWidgets_xOffset, yPosition + 13, 34, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);
}
Пример #4
0
void BTDisconnect_draw(GContext* ctx, int yPosition) {
  if(disconnectImage) {
    gdraw_command_image_recolor(disconnectImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);


    gdraw_command_image_draw(ctx, disconnectImage, GPoint(3 + SidebarWidgets_xOffset, yPosition));
  }
}
Пример #5
0
void render_calendar_background(Layer *layer, GContext *ctx)
{
    // Kill the old struct!
    GDrawCommandImage* oldImage = calendar_background;
    calendar_background = gdraw_command_image_create_with_resource(RESOURCE_ID_CALENDAR_BACKGROUND);
    gdraw_command_image_destroy(oldImage);
    gdraw_command_image_draw(ctx, calendar_background, GPoint(114, 4));
}
Пример #6
0
static void update_weather_cmd_img_proc(Layer *layer, GContext *ctx) {

  // If the image was loaded successfully...
  if (s_weather_cmd_img) {
    // Draw it
    gdraw_command_image_draw(ctx, s_weather_cmd_img, GPoint(0,0));
  }
}
Пример #7
0
void CurrentWeather_draw(GContext* ctx, int yPosition) {
  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  if (Weather_currentWeatherIcon) {
    gdraw_command_image_recolor(Weather_currentWeatherIcon, globalSettings.iconFillColor, globalSettings.iconStrokeColor);

    gdraw_command_image_draw(ctx, Weather_currentWeatherIcon, GPoint(3 + SidebarWidgets_xOffset, yPosition));
  }

  // draw weather data only if it has been set
  if(Weather_weatherInfo.currentTemp != INT32_MIN) {

    int currentTemp = Weather_weatherInfo.currentTemp;

    if(!globalSettings.useMetric) {
      currentTemp = roundf(currentTemp * 1.8f + 32);
    }

    char tempString[8];

    // in large font mode, omit the degree symbol and move the text
    if(!globalSettings.useLargeFonts) {
      snprintf(tempString, sizeof(tempString), " %d°", currentTemp);

      graphics_draw_text(ctx,
                         tempString,
                         currentSidebarFont,
                         GRect(-5 + SidebarWidgets_xOffset, yPosition + 24, 38, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    } else {
      snprintf(tempString, sizeof(tempString), " %d", currentTemp);

      graphics_draw_text(ctx,
                         tempString,
                         currentSidebarFont,
                         GRect(-5 + SidebarWidgets_xOffset, yPosition + 20, 35, 20),
                         GTextOverflowModeFill,
                         GTextAlignmentCenter,
                         NULL);
    }
  } else {
    // if the weather data isn't set, draw a loading indication
    graphics_draw_text(ctx,
                       "...",
                       currentSidebarFont,
                       GRect(-5 + SidebarWidgets_xOffset, yPosition, 38, 20),
                       GTextOverflowModeFill,
                       GTextAlignmentCenter,
                       NULL);
  }
}
Пример #8
0
void Sleep_draw(GContext* ctx, int yPosition) {
  if(sleepImage) {
    gdraw_command_image_recolor(sleepImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);
    gdraw_command_image_draw(ctx, sleepImage, GPoint(3 + SidebarWidgets_xOffset, yPosition - 7));
  }

  // get sleep in seconds
  int sleep_seconds;

  if(globalSettings.healthUseRestfulSleep) {
    sleep_seconds = (int)health_service_sum_today(HealthMetricSleepSeconds);
  } else {
    sleep_seconds = (int)health_service_sum_today(HealthMetricSleepRestfulSeconds);
  }

  // convert to hours/minutes
  int sleep_minutes = sleep_seconds / 60;
  int sleep_hours   = sleep_minutes / 60;

  // find minutes remainder
  sleep_minutes %= 60;

  char sleep_text[4];

  snprintf(sleep_text, sizeof(sleep_text), "%ih", sleep_hours);

  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);
  graphics_draw_text(ctx,
                     sleep_text,
                     mdSidebarFont,
                     GRect(-2 + SidebarWidgets_xOffset, yPosition + 14, 34, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

  snprintf(sleep_text, sizeof(sleep_text), "%im", sleep_minutes);

  graphics_draw_text(ctx,
                     sleep_text,
                     smSidebarFont,
                     GRect(-2 + SidebarWidgets_xOffset, yPosition + 30, 34, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

}
Пример #9
0
void drawBatteryStatus(GContext* ctx) {
  BatteryChargeState chargeState = battery_state_service_peek();
  char batteryString[6];

  #ifdef PBL_COLOR
    int width = roundf(17 * chargeState.charge_percent / 100.0f);
  #else
    int width = roundf(18 * chargeState.charge_percent / 100.0f);
  #endif

  snprintf(batteryString, sizeof(batteryString), "%d%%", chargeState.charge_percent);

  if (batteryImage) {
    #ifdef PBL_COLOR
      gdraw_command_image_draw(ctx, batteryImage, GPoint(2, 68));
    #else
      graphics_draw_bitmap_in_rect(ctx, batteryImage, GRect(2, 68, 25, 25));
    #endif
  }

  graphics_context_set_fill_color(ctx, GColorBlack);

  #ifdef PBL_COLOR
    if(chargeState.charge_percent <= 20) {
      graphics_context_set_fill_color(ctx, GColorRed);
    }

    graphics_fill_rect(ctx, GRect(6, 72, width, 7), 0, GCornerNone);
  #else
    if(globalSettings.sidebarTextColor == GColorWhite) {
      graphics_context_set_fill_color(ctx, GColorWhite);
    }

    graphics_fill_rect(ctx, GRect(5, 71, width, 8), 0, GCornerNone);
  #endif

  // graphics_draw_text(ctx,
  //                    batteryString,
  //                    sidebarFont,
  //                    GRect(-5, 72, 38, 20),
  //                    GTextOverflowModeFill,
  //                    GTextAlignmentCenter,
  //                    NULL);
}
Пример #10
0
void DateWidget_draw(GContext* ctx, int yPosition) {
  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  // compensate for extra space that appears on the top of the date widget
  yPosition -= (globalSettings.useLargeFonts) ? 10 : 7;

  // first draw the day name
  graphics_draw_text(ctx,
                     currentDayName,
                     currentSidebarFont,
                     GRect(-5 + SidebarWidgets_xOffset, yPosition, 40, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

  // next, draw the date background
  // (an image in normal mode, a rectangle in large font mode)
  if(!globalSettings.useLargeFonts) {
    if(dateImage) {
      gdraw_command_image_recolor(dateImage, globalSettings.iconFillColor, globalSettings.iconStrokeColor);
      gdraw_command_image_draw(ctx, dateImage, GPoint(3 + SidebarWidgets_xOffset, yPosition + 23));
    }
  } else {
    graphics_context_set_fill_color(ctx, globalSettings.iconStrokeColor);
    graphics_fill_rect(ctx, GRect(2 + SidebarWidgets_xOffset, yPosition + 30, 26, 22), 2, GCornersAll);

    graphics_context_set_fill_color(ctx, globalSettings.iconFillColor);
    graphics_fill_rect(ctx, GRect(4 + SidebarWidgets_xOffset, yPosition + 32, 22, 18), 0, GCornersAll);
  }

  // next, draw the date number
  graphics_context_set_text_color(ctx, globalSettings.iconStrokeColor);

  int yOffset = 0;
  yOffset = globalSettings.useLargeFonts ? 24 : 26;

  graphics_draw_text(ctx,
                     currentDayNum,
                     currentSidebarFont,
                     GRect(0 + SidebarWidgets_xOffset, yPosition + yOffset, 30, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);


   // switch back to normal color for the rest
  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  // don't draw the month if we're in compact mode
  if(!SidebarWidgets_useCompactMode) {
    yOffset = globalSettings.useLargeFonts ? 48 : 47;

    graphics_draw_text(ctx,
                       currentMonth,
                       currentSidebarFont,
                       GRect(0 + SidebarWidgets_xOffset, yPosition + yOffset, 30, 20),
                       GTextOverflowModeFill,
                       GTextAlignmentCenter,
                       NULL);
  }


}
Пример #11
0
void sidebarLayerUpdateProc(Layer *l, GContext* ctx) {
  graphics_context_set_fill_color(ctx, globalSettings.sidebarColor);
  graphics_fill_rect(ctx, layer_get_bounds(l), 0, GCornerNone);
  graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);

  // on black and white pebbles, invert the icons if we're using the dark bar
  #ifndef PBL_COLOR
    if(globalSettings.sidebarTextColor == GColorWhite) {
      graphics_context_set_compositing_mode(ctx, GCompOpAssignInverted);
    } else {
      graphics_context_set_compositing_mode(ctx, GCompOpAssign);
    }
  #endif

  if (Weather_currentWeatherIcon) {
    #ifdef PBL_COLOR
      gdraw_command_image_draw(ctx, Weather_currentWeatherIcon, GPoint(2, 7));
    #else
      graphics_draw_bitmap_in_rect(ctx, Weather_currentWeatherIcon, GRect(2, 7, 25, 25));
    #endif
  }

  // draw weather data only if it has been set
  if(Weather_weatherInfo.currentTemp != INT32_MIN) {

    int currentTemp = Weather_weatherInfo.currentTemp;

    if(!globalSettings.useMetric) {
      currentTemp = roundf((currentTemp * 9.0f) / 5.0f + 32);
    }

    char tempString[8];
    snprintf(tempString, sizeof(tempString), " %d°", currentTemp);

    graphics_draw_text(ctx,
                       tempString,
                       sidebarFont,
                       GRect(-5, 31, 38, 20),
                       GTextOverflowModeFill,
                       GTextAlignmentCenter,
                       NULL);
  }

  // if the pebble is disconnected, display the disconnection image
  if (disconnectImage && !isPhoneConnected) {
    #ifdef PBL_COLOR
      gdraw_command_image_draw(ctx, disconnectImage, GPoint(2, 60));
    #else
      graphics_draw_bitmap_in_rect(ctx, disconnectImage, GRect(2, 60, 25, 25));
    #endif
  } else {
    // otherwise, display the battery life, if enabled
    if(globalSettings.showBatteryLevel) {
      drawBatteryStatus(ctx);
    }
  }

  // now draw in the date info
  graphics_draw_text(ctx,
                     currentDayName,
                     sidebarFont,
                     GRect(0, 95, 30, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

  if (dateImage) {
    #ifdef PBL_COLOR
      gdraw_command_image_draw(ctx, dateImage, GPoint(2, 118));
    #else
      graphics_draw_bitmap_in_rect(ctx, dateImage, GRect(2, 118, 26, 25));
    #endif
  }

  // color pebble should always use black for the date number...
  #ifdef PBL_COLOR
    graphics_context_set_text_color(ctx, GColorBlack);
  #endif

  graphics_draw_text(ctx,
                     currentDayNum,
                     dateFont,
                     GRect(4, 121, 22, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);

 // ...but only for the date number
  #ifdef PBL_COLOR
    graphics_context_set_text_color(ctx, globalSettings.sidebarTextColor);
  #endif

  graphics_draw_text(ctx,
                     currentMonth,
                     sidebarFont,
                     GRect(0, 142, 30, 20),
                     GTextOverflowModeFill,
                     GTextAlignmentCenter,
                     NULL);
}