diff options
Diffstat (limited to 'src/displayapp/screens/WatchFaceAnalog.cpp')
| -rw-r--r-- | src/displayapp/screens/WatchFaceAnalog.cpp | 73 |
1 files changed, 36 insertions, 37 deletions
diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index 4cfc969..251a560 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -12,35 +12,33 @@ LV_IMG_DECLARE(bg_clock); using namespace Pinetime::Applications::Screens; namespace { -constexpr int16_t HourLength = 70; -constexpr int16_t MinuteLength = 90; -constexpr int16_t SecondLength = 110; + constexpr int16_t HourLength = 70; + constexpr int16_t MinuteLength = 90; + constexpr int16_t SecondLength = 110; -// sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor -const auto LV_TRIG_SCALE = _lv_trigo_sin(90); + // sin(90) = 1 so the value of _lv_trigo_sin(90) is the scaling factor + const auto LV_TRIG_SCALE = _lv_trigo_sin(90); -int16_t Cosine(int16_t angle) { - return _lv_trigo_sin(angle + 90); -} + int16_t Cosine(int16_t angle) { + return _lv_trigo_sin(angle + 90); + } -int16_t Sine(int16_t angle) { - return _lv_trigo_sin(angle); -} + int16_t Sine(int16_t angle) { + return _lv_trigo_sin(angle); + } -int16_t CoordinateXRelocate(int16_t x) { - return (x + LV_HOR_RES / 2); -} + int16_t CoordinateXRelocate(int16_t x) { + return (x + LV_HOR_RES / 2); + } -int16_t CoordinateYRelocate(int16_t y) { - return std::abs(y - LV_HOR_RES / 2); -} + int16_t CoordinateYRelocate(int16_t y) { + return std::abs(y - LV_HOR_RES / 2); + } -lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) { - return lv_point_t{ - .x = CoordinateXRelocate(radius * static_cast<int32_t>(Sine(angle)) / LV_TRIG_SCALE), - .y = CoordinateYRelocate(radius * static_cast<int32_t>(Cosine(angle)) / LV_TRIG_SCALE) - }; -} + lv_point_t CoordinateRelocate(int16_t radius, int16_t angle) { + return lv_point_t {.x = CoordinateXRelocate(radius * static_cast<int32_t>(Sine(angle)) / LV_TRIG_SCALE), + .y = CoordinateYRelocate(radius * static_cast<int32_t>(Cosine(angle)) / LV_TRIG_SCALE)}; + } } @@ -66,10 +64,13 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, lv_img_set_src(bg_clock_img, &bg_clock); lv_obj_align(bg_clock_img, NULL, LV_ALIGN_CENTER, 0, 0); - batteryIcon = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(batteryIcon, Symbols::batteryHalf); - lv_obj_align(batteryIcon, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); - lv_obj_set_auto_realign(batteryIcon, true); + batteryIcon.Create(lv_scr_act()); + lv_obj_align(batteryIcon.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); + + plugIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(plugIcon, Symbols::plug); + lv_obj_set_style_local_text_color(plugIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_obj_align(plugIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0); notificationIcon = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FF00)); @@ -79,7 +80,7 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, // Date - Day / Week day label_date_day = lv_label_create(lv_scr_act(), NULL); - lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xf0a500)); + lv_obj_set_style_local_text_color(label_date_day, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0)); lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day()); lv_label_set_align(label_date_day, LV_LABEL_ALIGN_CENTER); lv_obj_align(label_date_day, NULL, LV_ALIGN_CENTER, 50, 0); @@ -121,7 +122,8 @@ WatchFaceAnalog::WatchFaceAnalog(Pinetime::Applications::DisplayApp* app, lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); - UpdateClock(); + + Refresh(); } WatchFaceAnalog::~WatchFaceAnalog() { @@ -180,21 +182,18 @@ void WatchFaceAnalog::UpdateClock() { void WatchFaceAnalog::SetBatteryIcon() { auto batteryPercent = batteryPercentRemaining.Get(); - if (batteryPercent == 100) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); - } else { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - } - lv_label_set_text_static(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); + batteryIcon.SetBatteryPercentage(batteryPercent); } void WatchFaceAnalog::Refresh() { isCharging = batteryController.IsCharging(); if (isCharging.IsUpdated()) { if (isCharging.Get()) { - lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - lv_label_set_text_static(batteryIcon, Symbols::plug); + lv_obj_set_hidden(batteryIcon.GetObject(), true); + lv_obj_set_hidden(plugIcon, false); } else { + lv_obj_set_hidden(batteryIcon.GetObject(), false); + lv_obj_set_hidden(plugIcon, true); SetBatteryIcon(); } } |
