diff --git a/crates/alkane-gui/src/ui.rs b/crates/alkane-gui/src/ui.rs index b245c4ed..aa54e224 100644 --- a/crates/alkane-gui/src/ui.rs +++ b/crates/alkane-gui/src/ui.rs @@ -255,6 +255,9 @@ const SHAPE_HASHING: &str = "\u{0004}"; const SHAPE_SLOW: &str = "\u{0005}"; const SHAPE_NOTHASHING: &str = "\u{0006}"; const SHAPE_PAUSED: &str = "\u{0008}"; +/// Locate-light dot that fades in and out (round 12 #6); distinct from the static +/// `SHAPE_DOT` so only the flashing light pulses, not the hashboard health dots. +const SHAPE_PULSE_DOT: &str = "\u{000B}"; /// Register every SVG-backed table-cell icon with the bridge (round 12 #9/#11): /// the access padlocks and the four status KPI icons. Called once at startup; @@ -325,10 +328,11 @@ fn encode_access_icon(pal: &Palette, write_locked: Option) -> String { } /// Light column: a yellow dot while the miner's locate light is flashing, else -/// blank (round 11 #10). +/// blank (round 11 #10). The dot fades in and out (round 12 #6) via the pulsing +/// sentinel, so a flashing light reads as a live pulse rather than a static dot. fn encode_light_dot(pal: &Palette, flashing: Option) -> String { match flashing { - Some(true) => encode_segments(&[(Some(pal.amber), SHAPE_DOT.to_string())]), + Some(true) => encode_segments(&[(Some(pal.amber), SHAPE_PULSE_DOT.to_string())]), _ => encode_segments(&[(None, String::new())]), } } @@ -1081,6 +1085,14 @@ impl App { if !sel.is_empty() { t.dvlc_select_rows(&sel); } + // Run the locate-light fade timer only while a visible row's light is + // actually flashing (round 12 #6), so the table isn't repainted on a timer + // when there is nothing to animate. + let any_flashing = self + .view_idx + .iter() + .any(|&ri| self.rows[ri].light_flashing == Some(true)); + wx_rs::set_light_pulse(any_flashing); self.refresh_kpis(); } diff --git a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch index 916f249c..35e308c2 100644 --- a/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch +++ b/thirdparty/wx-rs/patches/0002-widget-bridge-rs.patch @@ -10,7 +10,7 @@ +pub use widgets::*; --- a/src/widgets.rs +++ b/src/widgets.rs -@@ -0,0 +1,806 @@ +@@ -0,0 +1,814 @@ +// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge +// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the +// wxWidgets object tree (parents own children; nothing to free in Rust). @@ -118,6 +118,7 @@ + pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void; + pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void; + pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int); ++ pub fn wxbr_set_light_pulse(on: c_int); + pub fn wxbr_bind_sys_colour(win: *mut c_void); + pub fn wxbr_destroy(win: *mut c_void); + pub fn wxbr_destroy_children(win: *mut c_void); @@ -225,6 +226,13 @@ + } +} + ++/// Start (or stop) the locate-light dot fade animation. Call with `true` while at ++/// least one miner's locate light is flashing so the table repaint timer only ++/// runs when there is a pulsing dot to animate (round 12 #6). ++pub fn set_light_pulse(on: bool) { ++ unsafe { notsafe::wxbr_set_light_pulse(on as c_int) } ++} ++ +/// Open a URL in the system default browser. Returns true on success. +pub fn launch_browser(url: &str) -> bool { + let c = CString::new(url).unwrap_or_default(); diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index d4749d10..ceca1056 100644 --- a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch +++ b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch @@ -1,6 +1,6 @@ --- a/cpp_src/widgets_bridge.cpp +++ b/cpp_src/widgets_bridge.cpp -@@ -0,0 +1,1547 @@ +@@ -0,0 +1,1622 @@ +// widgets_bridge.cpp — alkane-toolkit extension to wx-rs +// Adds the widget/event surface the toolkit UI needs on top of the upstream +// render-callback bridge (which is kept untouched). @@ -37,6 +37,7 @@ +#include +#include +#include ++#include +#include +#include +#ifdef __WXGTK__ @@ -167,20 +168,71 @@ +const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow) +const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing) +const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused) ++const wxUniChar SHAPE_PULSE_DOT = 0x0B; // locate-light dot that fades in/out (round 12 #6) +const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies + ++// Animation phase for the pulsing locate-light dot (round 12 #6), advanced by a ++// wxTimer while any such dot is on screen; the treeview it repaints is tracked so ++// the timer can invalidate exactly it. ++double g_pulse_phase = 0.0; ++wxDataViewCtrl* g_pulse_target = nullptr; ++ +bool IsShapeSentinel(const wxString& s, wxUniChar& out) { + if (s.length() != 1) return false; + wxUniChar c = s[0]; + if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK || + c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING || -+ c == SHAPE_PAUSED) { ++ c == SHAPE_PAUSED || c == SHAPE_PULSE_DOT) { + out = c; + return true; + } + return false; +} + ++// Blend `fg` toward `bg` by alpha (1.0 = fully fg), used to fade the locate dot. ++wxColour BlendColour(const wxColour& bg, const wxColour& fg, double a) { ++ auto mix = [a](unsigned char b, unsigned char f) { ++ double v = (double)b * (1.0 - a) + (double)f * a + 0.5; ++ if (v < 0) v = 0; ++ if (v > 255) v = 255; ++ return (unsigned char)v; ++ }; ++ return wxColour(mix(bg.Red(), fg.Red()), mix(bg.Green(), fg.Green()), mix(bg.Blue(), fg.Blue())); ++} ++ ++// Drives the locate-light dot's fade (round 12 #6): while running it advances the ++// phase and repaints the treeview so the SHAPE_PULSE_DOT cells re-render at the ++// new opacity. Runs only while at least one locate light is flashing. ++class PulseTimer : public wxTimer { ++ public: ++ void Notify() override { ++ g_pulse_phase += 0.4; // ~1.6 s cycle at the 100 ms tick below ++ if (!g_pulse_target) return; ++ // A plain Refresh() does not re-invoke the custom cell renderer under wxGTK ++ // (GtkTreeView caches rendered cells); emitting a row change does, so the ++ // SHAPE_PULSE_DOT cells re-render at the new phase. The timer only runs while ++ // a light is flashing, so touching every row here is cheap. ++ AttrListStore* store = dynamic_cast(g_pulse_target->GetModel()); ++ if (store) { ++ unsigned int n = store->GetItemCount(); ++ for (unsigned int r = 0; r < n; r++) store->RowChanged(r); ++ } else { ++ g_pulse_target->Refresh(); ++ } ++ } ++}; ++PulseTimer* g_pulse_timer = nullptr; ++ ++void SetLightPulse(bool on) { ++ if (!g_pulse_timer) g_pulse_timer = new PulseTimer(); ++ if (on) { ++ if (!g_pulse_timer->IsRunning()) g_pulse_timer->Start(100); ++ } else { ++ g_pulse_timer->Stop(); ++ if (g_pulse_target) g_pulse_target->Refresh(); ++ } ++} ++ +// Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status +// icons). The Rust side registers a raw SVG (with its viewBox dims for aspect) +// per sentinel; DrawShape recolours it to the segment colour, rasterises once @@ -225,7 +277,9 @@ + +// Draw one shape sentinel centred at x; returns the horizontal space it used +// (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon). -+int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) { ++// `bg` is the cell background the shape sits on, used to fade the pulsing dot. ++int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, ++ const wxColour& colour, const wxColour& bg) { + int cy = cell.y + cell.height / 2; + // SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the + // segment colour, rasterise (cached), and draw centred in its slot. @@ -243,9 +297,15 @@ + } + } + int cx = x + SHAPE_ADVANCE / 2; -+ if (shape == SHAPE_DOT) { ++ if (shape == SHAPE_DOT || shape == SHAPE_PULSE_DOT) { ++ wxColour fill = colour; ++ if (shape == SHAPE_PULSE_DOT) { ++ // Fade between ~0.3 and 1.0 opacity over a ~1.6 s cycle (round 12 #6). ++ double a = 0.3 + 0.7 * (0.5 + 0.5 * std::sin(g_pulse_phase)); ++ fill = BlendColour(bg, colour, a); ++ } + dc->SetPen(*wxTRANSPARENT_PEN); -+ dc->SetBrush(wxBrush(colour)); ++ dc->SetBrush(wxBrush(fill)); + dc->DrawCircle(cx, cy, 4); + return SHAPE_ADVANCE; + } @@ -344,7 +404,16 @@ + // selection highlight (round 11 #10/#13). + wxUniChar shape; + if (IsShapeSentinel(seg.text, shape)) { -+ x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain); ++ // Background the shape sits on, so the pulsing locate dot fades toward it. ++ wxColour cellbg; ++ if (selected) { ++ cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); ++ } else if (GetAttr().HasBackgroundColour()) { ++ cellbg = GetAttr().GetBackgroundColour(); ++ } else { ++ cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); ++ } ++ x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain, cellbg); + continue; + } + if (seg.text.IsEmpty()) continue; @@ -768,6 +837,7 @@ + AttrListStore* store = new AttrListStore(); + dv->AssociateModel(store); + store->DecRef(); // the control owns a reference now ++ g_pulse_target = dv; // the locate-dot pulse timer repaints this control + dv->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) { + if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0); + }); @@ -1468,6 +1538,11 @@ + g_shape_bmp_cache.clear(); +} + ++// Start/stop the locate-light dot fade animation (round 12 #6). The Rust side ++// calls this after each refresh with whether any miner's locate light is ++// flashing, so the repaint timer only runs when there is a dot to animate. ++void wxbr_set_light_pulse(int on) { SetLightPulse(on != 0); } ++ +// ---- live theme changes ----------------------------------------------------- + +// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp index beac2606..38478c5b 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #ifdef __WXGTK__ @@ -164,20 +165,71 @@ const wxUniChar SHAPE_HASHING = 0x04; // rabbit (hashing) const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow) const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing) const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused) +const wxUniChar SHAPE_PULSE_DOT = 0x0B; // locate-light dot that fades in/out (round 12 #6) const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies +// Animation phase for the pulsing locate-light dot (round 12 #6), advanced by a +// wxTimer while any such dot is on screen; the treeview it repaints is tracked so +// the timer can invalidate exactly it. +double g_pulse_phase = 0.0; +wxDataViewCtrl* g_pulse_target = nullptr; + bool IsShapeSentinel(const wxString& s, wxUniChar& out) { if (s.length() != 1) return false; wxUniChar c = s[0]; if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK || c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING || - c == SHAPE_PAUSED) { + c == SHAPE_PAUSED || c == SHAPE_PULSE_DOT) { out = c; return true; } return false; } +// Blend `fg` toward `bg` by alpha (1.0 = fully fg), used to fade the locate dot. +wxColour BlendColour(const wxColour& bg, const wxColour& fg, double a) { + auto mix = [a](unsigned char b, unsigned char f) { + double v = (double)b * (1.0 - a) + (double)f * a + 0.5; + if (v < 0) v = 0; + if (v > 255) v = 255; + return (unsigned char)v; + }; + return wxColour(mix(bg.Red(), fg.Red()), mix(bg.Green(), fg.Green()), mix(bg.Blue(), fg.Blue())); +} + +// Drives the locate-light dot's fade (round 12 #6): while running it advances the +// phase and repaints the treeview so the SHAPE_PULSE_DOT cells re-render at the +// new opacity. Runs only while at least one locate light is flashing. +class PulseTimer : public wxTimer { + public: + void Notify() override { + g_pulse_phase += 0.4; // ~1.6 s cycle at the 100 ms tick below + if (!g_pulse_target) return; + // A plain Refresh() does not re-invoke the custom cell renderer under wxGTK + // (GtkTreeView caches rendered cells); emitting a row change does, so the + // SHAPE_PULSE_DOT cells re-render at the new phase. The timer only runs while + // a light is flashing, so touching every row here is cheap. + AttrListStore* store = dynamic_cast(g_pulse_target->GetModel()); + if (store) { + unsigned int n = store->GetItemCount(); + for (unsigned int r = 0; r < n; r++) store->RowChanged(r); + } else { + g_pulse_target->Refresh(); + } + } +}; +PulseTimer* g_pulse_timer = nullptr; + +void SetLightPulse(bool on) { + if (!g_pulse_timer) g_pulse_timer = new PulseTimer(); + if (on) { + if (!g_pulse_timer->IsRunning()) g_pulse_timer->Start(100); + } else { + g_pulse_timer->Stop(); + if (g_pulse_target) g_pulse_target->Refresh(); + } +} + // Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status // icons). The Rust side registers a raw SVG (with its viewBox dims for aspect) // per sentinel; DrawShape recolours it to the segment colour, rasterises once @@ -222,7 +274,9 @@ const wxBitmap& ShapeBitmap(wxUniChar shape, const ShapeSvg& sv, const wxColour& // Draw one shape sentinel centred at x; returns the horizontal space it used // (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon). -int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wxColour& colour) { +// `bg` is the cell background the shape sits on, used to fade the pulsing dot. +int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, + const wxColour& colour, const wxColour& bg) { int cy = cell.y + cell.height / 2; // SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the // segment colour, rasterise (cached), and draw centred in its slot. @@ -240,9 +294,15 @@ int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell, const wx } } int cx = x + SHAPE_ADVANCE / 2; - if (shape == SHAPE_DOT) { + if (shape == SHAPE_DOT || shape == SHAPE_PULSE_DOT) { + wxColour fill = colour; + if (shape == SHAPE_PULSE_DOT) { + // Fade between ~0.3 and 1.0 opacity over a ~1.6 s cycle (round 12 #6). + double a = 0.3 + 0.7 * (0.5 + 0.5 * std::sin(g_pulse_phase)); + fill = BlendColour(bg, colour, a); + } dc->SetPen(*wxTRANSPARENT_PEN); - dc->SetBrush(wxBrush(colour)); + dc->SetBrush(wxBrush(fill)); dc->DrawCircle(cx, cy, 4); return SHAPE_ADVANCE; } @@ -341,7 +401,16 @@ class SegmentRenderer : public wxDataViewCustomRenderer { // selection highlight (round 11 #10/#13). wxUniChar shape; if (IsShapeSentinel(seg.text, shape)) { - x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain); + // Background the shape sits on, so the pulsing locate dot fades toward it. + wxColour cellbg; + if (selected) { + cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); + } else if (GetAttr().HasBackgroundColour()) { + cellbg = GetAttr().GetBackgroundColour(); + } else { + cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + } + x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain, cellbg); continue; } if (seg.text.IsEmpty()) continue; @@ -765,6 +834,7 @@ void* wxbr_dvlc(void* parent) { AttrListStore* store = new AttrListStore(); dv->AssociateModel(store); store->DecRef(); // the control owns a reference now + g_pulse_target = dv; // the locate-dot pulse timer repaints this control dv->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) { if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0); }); @@ -1465,6 +1535,11 @@ void wxbr_register_shape_svg(int sentinel, const char* svg, int vbw, int vbh) { g_shape_bmp_cache.clear(); } +// Start/stop the locate-light dot fade animation (round 12 #6). The Rust side +// calls this after each refresh with whether any miner's locate light is +// flashing, so the repaint timer only runs when there is a dot to animate. +void wxbr_set_light_pulse(int on) { SetLightPulse(on != 0); } + // ---- live theme changes ----------------------------------------------------- // Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs index 5495e6dd..bb6d2a94 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/src/widgets.rs @@ -105,6 +105,7 @@ mod notsafe { pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void; pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void; pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int); + pub fn wxbr_set_light_pulse(on: c_int); pub fn wxbr_bind_sys_colour(win: *mut c_void); pub fn wxbr_destroy(win: *mut c_void); pub fn wxbr_destroy_children(win: *mut c_void); @@ -212,6 +213,13 @@ pub fn register_shape_svg(sentinel: u32, svg: &str, vbw: i32, vbh: i32) { } } +/// Start (or stop) the locate-light dot fade animation. Call with `true` while at +/// least one miner's locate light is flashing so the table repaint timer only +/// runs when there is a pulsing dot to animate (round 12 #6). +pub fn set_light_pulse(on: bool) { + unsafe { notsafe::wxbr_set_light_pulse(on as c_int) } +} + /// Open a URL in the system default browser. Returns true on success. pub fn launch_browser(url: &str) -> bool { let c = CString::new(url).unwrap_or_default();