Skip to content

Commit efc45c7

Browse files
committed
init
1 parent a86af2b commit efc45c7

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

src/wind_instrument.cpp

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,30 @@ double WindAngleGauge::clamp_180(double deg) {
1212
WindAngleGauge::WindAngleGauge() {
1313
set_title("APP WIND");
1414
set_unit("AWA");
15-
1615
set_range(-180.0, 180.0);
1716

17+
apply_geometry_overrides_();
18+
}
19+
20+
void WindAngleGauge::apply_theme(const CircularGauge::Theme& theme) {
21+
CircularGauge::apply_theme(theme);
22+
apply_geometry_overrides_(); // re-apply 30°/10° geometry after theme overwrite
23+
}
24+
25+
void WindAngleGauge::apply_geometry_overrides_() {
1826
// Full 360° dial:
1927
// 0° at top (bow), +90° right, -90° left, ±180° bottom (stern).
2028
style().start_deg = -90.0 - 180.0; // -270
2129
style().end_deg = -90.0 + 180.0; // +90
2230

23-
// Major every 30° across -180..+180 => 13 majors.
24-
// Minor every 10° => 2 minors between majors.
31+
// Major every 30° across -180..+180 => 13 majors (12 intervals => 360/12=30°).
32+
// Minor every 10° => 2 minors between majors (30/(2+1)=10°).
2533
style().major_ticks = 13;
2634
style().minor_ticks = 2;
2735

28-
// Move readout down so it doesn't get covered by the needle.
29-
style().value_radius_frac = 0.28;
36+
// Lower the AWS readout noticeably so it doesn't get covered by the needle.
37+
// (Your previous 0.28 was still close to center.)
38+
style().value_radius_frac = 0.48;
3039

3140
style().value_precision = 0;
3241
}
@@ -42,8 +51,8 @@ double WindAngleGauge::value_to_angle_rad(double v) const {
4251
}
4352

4453
std::string WindAngleGauge::format_major_label(int /*major_index*/, double major_value) const {
45-
int v = static_cast<int>(std::lround(clamp_180(major_value)));
46-
if (std::abs(v) == 180) v = 180;
54+
// -180, -150, ... 0 ... +150, +180
55+
const int v = static_cast<int>(std::lround(clamp_180(major_value)));
4756
return std::to_string(v);
4857
}
4958

@@ -54,21 +63,35 @@ std::string WindAngleGauge::format_value_readout(double /*v*/) const {
5463
return std::string(buf);
5564
}
5665

66+
// ---------------- WindSpeedGauge ----------------
67+
5768
WindSpeedGauge::WindSpeedGauge() {
5869
set_title("WIND SPD");
5970
set_unit("kn");
60-
6171
set_range(0.0, 40.0);
6272

73+
apply_geometry_overrides_();
74+
}
75+
76+
void WindSpeedGauge::apply_theme(const CircularGauge::Theme& theme) {
77+
CircularGauge::apply_theme(theme);
78+
apply_geometry_overrides_();
79+
}
80+
81+
void WindSpeedGauge::apply_geometry_overrides_() {
6382
style().start_deg = -225.0;
64-
style().end_deg = 45.0;
83+
style().end_deg = 45.0;
84+
6585
style().major_ticks = 9; // 0..40 step 5
6686
style().minor_ticks = 4;
6787
style().value_precision = 1;
6888

69-
style().value_radius_frac = 0.22;
89+
// Slightly below center for speed gauge, but not as low as wind angle readout.
90+
style().value_radius_frac = 0.30;
7091
}
7192

93+
// ---------------- Panel ----------------
94+
7295
WindInstrumentPanel::WindInstrumentPanel()
7396
: Gtk::Box(Gtk::Orientation::VERTICAL) {
7497
set_spacing(12);
@@ -98,19 +121,22 @@ WindInstrumentPanel::WindInstrumentPanel()
98121
void WindInstrumentPanel::apply_theme(const SailTheme& t) {
99122
theme_ = t;
100123

124+
// These now keep their 30°/10° and readout offsets after theming
101125
angle_.apply_theme(theme_.gauge);
102126
speed_.apply_theme(theme_.gauge);
103127

104128
// Zones per request:
105-
// - no-go: -20..+20 (NOT red; use amber/orange)
129+
// - no-go: -20..+20 (NOT red; "usual" caution color)
106130
// - port scale: -60..-20 (red)
107131
// - stbd scale: +20..+60 (green)
132+
// - mirrored downwind: red on port side, green on stbd side
108133
std::vector<CircularGauge::Zone> zones;
109-
//zones.push_back({ -20.0, 20.0, theme_.accent_no_go, 0.90 }); // no-go (caution)
110-
zones.push_back({ -60.0, -20.0, theme_.accent_red, 1.0 }); // port scale (red)
111-
zones.push_back({ 20.0, 60.0, theme_.accent_green, 1.0 }); // stbd scale (green)
112-
zones.push_back({-160.0, -120.0, theme_.accent_red, 1.0 }); // port scale (red)
113-
zones.push_back({ 120.0, 160.0, theme_.accent_green, 1.0 }); // stbd scale (green)
134+
zones.push_back({ -20.0, 20.0, theme_.accent_no_go, 1.0 }); // no-go (caution)
135+
zones.push_back({ -60.0, -20.0, theme_.accent_red, 1.0 }); // port red
136+
zones.push_back({ 20.0, 60.0, theme_.accent_green, 1.0 }); // stbd green
137+
138+
zones.push_back({-160.0, -120.0, theme_.accent_red, 1.0 }); // downwind port red
139+
zones.push_back({ 120.0, 160.0, theme_.accent_green, 1.0 }); // downwind stbd green
114140

115141
angle_.set_zones(std::move(zones));
116142
speed_.set_zones({});

src/wind_instrument.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ struct SailTheme {
88
Gdk::RGBA panel_bg = Gdk::RGBA("#0b0e12");
99

1010
// Zone colors
11-
Gdk::RGBA accent_red = Gdk::RGBA("#ff3b30");
12-
Gdk::RGBA accent_green = Gdk::RGBA("#34c759");
13-
Gdk::RGBA accent_no_go = Gdk::RGBA("#ff9f0a"); // amber/orange (not red)
11+
Gdk::RGBA accent_red = Gdk::RGBA("#ff3b30");
12+
Gdk::RGBA accent_green = Gdk::RGBA("#34c759");
13+
14+
// "No-go" should be a usual caution color (not red)
15+
Gdk::RGBA accent_no_go = Gdk::RGBA("#ff9f0a"); // amber
1416
};
1517

1618
// Apparent wind angle: -180..+180 (port -, starboard +).
@@ -21,13 +23,18 @@ class WindAngleGauge final : public CircularGauge {
2123
void set_angle_deg(double deg); // clamps to [-180, 180]
2224
void set_speed_kn(double kn) { speed_kn_ = kn; queue_draw(); }
2325

26+
// IMPORTANT: theme application overwrites style_, so we re-apply gauge geometry after theming.
27+
void apply_theme(const CircularGauge::Theme& theme);
28+
2429
protected:
2530
double value_to_angle_rad(double v) const override;
2631
std::string format_major_label(int major_index, double major_value) const override;
2732
std::string format_value_readout(double v) const override;
2833

2934
private:
3035
static double clamp_180(double deg);
36+
void apply_geometry_overrides_();
37+
3138
double speed_kn_ = 0.0;
3239
};
3340

@@ -36,6 +43,11 @@ class WindSpeedGauge final : public CircularGauge {
3643
public:
3744
WindSpeedGauge();
3845
void set_speed_kn(double kn) { set_value(kn); }
46+
47+
void apply_theme(const CircularGauge::Theme& theme);
48+
49+
private:
50+
void apply_geometry_overrides_();
3951
};
4052

4153
class WindInstrumentPanel final : public Gtk::Box {

0 commit comments

Comments
 (0)