RumPi Linux Client 1.0
A wxWidgets desktop dashboard that visualizes a RumPi robot's live sensor data as a condition-reactive scene
HomeScenePanel.h
Go to the documentation of this file.
1#pragma once
2
3#include <wx/panel.h>
4#include <wx/bmpbndl.h>
5#include <wx/bitmap.h>
6#include <wx/timer.h>
7#include <wx/string.h>
8#include <wx/colour.h>
9#include <RumPi/Data/SelectedSensorReadings.h>
10
11class wxGraphicsContext;
12class wxPaintDC;
13
25class HomeScenePanel : public wxPanel
26{
27protected:
28 //Overlay/pill positions are authored in the SVG's 1920x1080 space and scaled to the real panel; the
29 //kiosk is 16:9, so a single uniform scale (panel width / DESIGN_WIDTH) keeps proportions.
30 static constexpr double DESIGN_WIDTH = 1920.0;
31
33
34 //Base art, loaded once as resolution-independent SVG bundles.
35 wxBitmapBundle myDayScene;
36 wxBitmapBundle myNightScene;
37
38 //The latest curated readings that drive the overlays (set from the UI thread via Update()).
39 RumPi::SelectedSensorReadings myReadings;
40
41 //Cached day/night-crossfaded base, rebuilt only when the draw size or the (bucketed) blend changes.
42 wxBitmap myBaseCache;
46
47 //Reused off-screen buffer for flicker-free compositing (recreated only on resize).
48 wxBitmap myFrameBuffer;
49
50 //Animation phases advanced by the timer: the readings set how fast/how much, the phase sets where.
51 double myWindPhase;
52 double myCloudPhase;
54
55 //Loaded from ClientConfig at construction.
56 wxString myLocationName;
69 wxColour myCo2HighColour;
70
83 double LocalTimeInHours() const;
84
98 double NightAmount() const;
99
115 wxColour Co2DotColour(float co2) const;
116
132 wxColour AirQualityDotColour(RumPi::E_AirQualityLevel airQualityLevel) const;
133
151 wxBitmapBundle LoadSceneBundle(const wxString& folder, const wxString& baseName, const char* embeddedSvg) const;
152
166 void CreateDefaultScenesIfMissing(const wxString& folder) const;
167
183 void EnsureBaseCache(int width, int height, int blendBucket);
184
200 void DrawCelestialBody(wxGraphicsContext* graphicsContext, int width, int height);
201
217 void DrawAtmosphere(wxGraphicsContext* graphicsContext, int width, int height);
218
234 void DrawStreetlights(wxGraphicsContext* graphicsContext, int width, int height);
235
251 void DrawPills(wxGraphicsContext* graphicsContext, int width, int height);
252
266 void OnPaint(wxPaintEvent& event);
267
282 void RenderScene(wxPaintDC& drawContext);
283
296 void OnSize(wxSizeEvent& event);
297
311 void OnTimer(wxTimerEvent& event);
312
313public:
327 HomeScenePanel(wxWindow* parent);
328
341 void Update(const RumPi::SelectedSensorReadings& readings);
342};
The Home tab's stylized, condition-reactive backdrop.
Definition: HomeScenePanel.h:26
wxColour myCo2FreshColour
Indicator colour for the "fresh" CO2 band.
Definition: HomeScenePanel.h:67
void OnPaint(wxPaintEvent &event)
Paint handler: cover-scales and blits the cached base, then composites the celestial body,...
Definition: HomeScenePanel.cpp:480
wxBitmap myFrameBuffer
Definition: HomeScenePanel.h:48
int myBaseCacheHeight
Height the base cache was built at.
Definition: HomeScenePanel.h:44
double myTemperatureTintOpacity
Maximum temperature-tint overlay opacity.
Definition: HomeScenePanel.h:62
wxColour myCo2ElevatedColour
Indicator colour for the "elevated" CO2 band.
Definition: HomeScenePanel.h:68
double myTempWarmAbove
Temperature above which the tint reads "warm".
Definition: HomeScenePanel.h:59
double myCo2ElevatedMax
Upper CO2 bound for the "elevated" band.
Definition: HomeScenePanel.h:58
void CreateDefaultScenesIfMissing(const wxString &folder) const
Seeds the images folder with editable copies of the default day/night SVG art, but only when the fold...
Definition: HomeScenePanel.cpp:313
double myMistOpacity
Maximum mist overlay opacity.
Definition: HomeScenePanel.h:65
wxColour AirQualityDotColour(RumPi::E_AirQualityLevel airQualityLevel) const
Picks the status-dot colour for an air-quality level, collapsing the six levels onto the same good/wa...
Definition: HomeScenePanel.cpp:224
wxString myLocationName
Configured location name.
Definition: HomeScenePanel.h:56
void RenderScene(wxPaintDC &drawContext)
Composites one frame (base art, celestial body, atmosphere, streetlights, pills) into the off-screen ...
Definition: HomeScenePanel.cpp:496
int myBaseCacheBlendBucket
Bucketed day/night blend the base cache was built at.
Definition: HomeScenePanel.h:45
wxColour Co2DotColour(float co2) const
Picks the status-dot colour for a CO2 reading, using the configured fresh/elevated thresholds and (ac...
Definition: HomeScenePanel.cpp:189
void EnsureBaseCache(int width, int height, int blendBucket)
Rebuilds the cached day/night-crossfaded base image, but only when the draw size or the bucketed blen...
Definition: HomeScenePanel.cpp:358
static constexpr double DESIGN_WIDTH
The SVG authoring width overlays are positioned against.
Definition: HomeScenePanel.h:30
void Update(const RumPi::SelectedSensorReadings &readings)
Stores the latest sensor snapshot (on the UI thread) and schedules a repaint so the overlays reflect ...
Definition: HomeScenePanel.cpp:127
void DrawCelestialBody(wxGraphicsContext *graphicsContext, int width, int height)
Draws the procedural sun (day) or moon (night) arcing across the sky by real local time,...
Definition: HomeScenePanel.cpp:580
void OnTimer(wxTimerEvent &event)
Timer handler: advances the wind and cloud animation phases (a baseline drift plus an amount proporti...
Definition: HomeScenePanel.cpp:445
wxColour myCo2HighColour
Indicator colour for the "high" CO2 band.
Definition: HomeScenePanel.h:69
double mySceneAspect
The scene's aspect ratio.
Definition: HomeScenePanel.h:32
wxBitmapBundle LoadSceneBundle(const wxString &folder, const wxString &baseName, const char *embeddedSvg) const
Loads a scene image bundle, preferring a user-supplied file (svg, then raster) in the images folder a...
Definition: HomeScenePanel.cpp:258
RumPi::SelectedSensorReadings myReadings
Definition: HomeScenePanel.h:39
void DrawAtmosphere(wxGraphicsContext *graphicsContext, int width, int height)
Draws the reading-driven atmospheric overlays: dawn/dusk glow, temperature tint, humidity clouds,...
Definition: HomeScenePanel.cpp:668
wxBitmapBundle myNightScene
Night base art (SVG bundle).
Definition: HomeScenePanel.h:36
void DrawStreetlights(wxGraphicsContext *graphicsContext, int width, int height)
Draws the default scene's lamp posts, lit by the TSL2591 light level (brighter the darker it gets) an...
Definition: HomeScenePanel.cpp:836
void OnSize(wxSizeEvent &event)
Size handler: schedules a repaint so the scene re-scales to the new panel size.
Definition: HomeScenePanel.cpp:426
wxBitmapBundle myDayScene
Day base art (SVG bundle).
Definition: HomeScenePanel.h:35
double myHazeOpacity
Maximum haze overlay opacity.
Definition: HomeScenePanel.h:64
double myDuskGlowOpacity
Maximum dusk-glow overlay opacity.
Definition: HomeScenePanel.h:61
double myTempCoolBelow
Temperature below which the tint reads "cool".
Definition: HomeScenePanel.h:60
void DrawPills(wxGraphicsContext *graphicsContext, int width, int height)
Draws the glanceable info pills: the location and clock along the top, and a bottom strip of reading ...
Definition: HomeScenePanel.cpp:911
double myCloudPhase
Current cloud animation phase.
Definition: HomeScenePanel.h:52
double myWindPhase
Current wind animation phase.
Definition: HomeScenePanel.h:51
double LocalTimeInHours() const
Gets the current local time as a fractional number of hours (e.g.
Definition: HomeScenePanel.cpp:146
HomeScenePanel(wxWindow *parent)
Builds the scene panel: loads the tunable settings from ClientConfig, seeds and loads the day/night S...
Definition: HomeScenePanel.cpp:52
double myWindOpacity
Maximum wind overlay opacity.
Definition: HomeScenePanel.h:66
double NightAmount() const
Computes how "night" it is now, from 0.0 (full day) to 1.0 (full night), using a sun-elevation proxy ...
Definition: HomeScenePanel.cpp:165
wxBitmap myBaseCache
Cached crossfaded base image.
Definition: HomeScenePanel.h:42
double myCo2FreshMax
Upper CO2 bound for the "fresh" band.
Definition: HomeScenePanel.h:57
double myCloudOpacity
Maximum cloud overlay opacity.
Definition: HomeScenePanel.h:63
int myBaseCacheWidth
Width the base cache was built at.
Definition: HomeScenePanel.h:43
wxTimer myAnimationTimer
Timer that advances the animation phases between snapshots.
Definition: HomeScenePanel.h:53