Skip to content

Commit

Permalink
Fix sunrise or sunset lines overlapping precipitation histogram
Browse files Browse the repository at this point in the history
Refs: #93
  • Loading branch information
orontee committed Jul 8, 2024
1 parent d3ac797 commit 0e9ffcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Binary file modified docs/screenshot-hourly-forecast.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions src/hourlyforecastbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ HourlyForecastBox::HourlyForecastBox(int pos_x, int pos_y, int width,
void HourlyForecastBox::do_paint() {
this->draw_labels();
this->draw_frame_and_values();

this->draw_sunrise_sunset_lines();
this->draw_precipitation_histogram();
// ⚠️ Draw sunrise and sunset lines before precipitation histogram
// otherwise vertical lines related to sun may overlap the histogram
// bars… See also draw_precipitation_histogram() implementation for
// more ugly stuff related to that!

this->draw_temperature_curve();
this->draw_sunrise_sunset_lines();
}

bool HourlyForecastBox::handle_key_press(int key) {
Expand Down Expand Up @@ -370,6 +376,12 @@ void HourlyForecastBox::draw_precipitation_histogram() const {
max_number(forecast.rain, forecast.snow), false);
// rain and snow are in mm/h but save space with shortest unit

FillArea(x_screen + 1,
y_screen - tiny_font.get()->height - this->vertical_padding,
this->bar_width - 2, tiny_font.get()->height - 1, WHITE);
// ⚠️ Clear the bottom of a possible vertical line
// corresponding to sunrise or sunset

SetFont(tiny_font.get(), DGRAY);
DrawString(bar_center_x - StringWidth(precipitation_text.c_str()) / 2.0,
y_screen - tiny_font.get()->height - 2,
Expand Down Expand Up @@ -398,8 +410,8 @@ void HourlyForecastBox::draw_precipitation_histogram() const {
void HourlyForecastBox::draw_sunrise_sunset_lines() const {
BOOST_LOG_TRIVIAL(debug) << "Drawing sunrise and sunset lines";
const auto separator_start_y =
this->weather_icon_y + this->icon_size + this->vertical_padding;
const auto separator_stop_y = this->temperature_y - vertical_padding;
this->weather_icon_y + this->icon_size;
const auto separator_stop_y = this->curve_y_offset;

for (size_t bar_index = 0; bar_index < HourlyForecastBox::visible_bars;
++bar_index) {
Expand Down

0 comments on commit 0e9ffcc

Please sign in to comment.