Skip to content
API Documentation
BastionGuard™
anonymous_namespace{NetworkPage.cpp} Namespace Reference

Classes

struct  AnimatedMarkerData
struct  HoverPayload

Functions

static gboolean animated_marker_tick (GtkWidget *widget, GdkFrameClock *, gpointer)
static void animated_marker_data_destroy (gpointer data)
static void hover_payload_destroy (gpointer data, GClosure *)
static void animated_marker_draw (GtkDrawingArea *, cairo_t *cr, int width, int height, gpointer user_data)
static GtkWidget * create_animated_dot_widget (int hits)
static void map_fx_draw (GtkDrawingArea *, cairo_t *cr, int width, int height, gpointer user_data)
std::string net_json_escape (const std::string &s)
std::string net_json_field_str (const std::string &line, const std::string &key)
double net_json_field_double (const std::string &line, const std::string &key)
int64_t net_json_field_i64 (const std::string &line, const std::string &key)

Variables

constexpr double kDefaultLat = 20.0
constexpr double kDefaultLon = 10.0
constexpr double kDefaultZoom = 2.2
constexpr double kFocusedZoom = 3.0
constexpr double kMaxZoom = 20.0
constexpr double kMinZoom = 1.0
constexpr auto kHoverHideDelay = std::chrono::milliseconds(140)
constexpr auto kUserViewportHold = std::chrono::seconds(8)

Function Documentation

◆ animated_marker_data_destroy()

void anonymous_namespace{NetworkPage.cpp}::animated_marker_data_destroy ( gpointer data)
static

◆ animated_marker_draw()

void anonymous_namespace{NetworkPage.cpp}::animated_marker_draw ( GtkDrawingArea * ,
cairo_t * cr,
int width,
int height,
gpointer user_data )
static

Definition at line 66 of file NetworkPage.cpp.

71 {
72 auto* data = static_cast<AnimatedMarkerData*>(user_data);
73 if (!data) return;
74
75 const gint64 now = g_get_monotonic_time();
76 const double t = (now - data->start_us) / 1000000.0;
77
78 const double cx = width * 0.5;
79 const double cy = height * 0.5;
80
81 const double base_r =
82 std::clamp(5.0 + std::log2(static_cast<double>(std::max(1, data->hits)) + 1.0) * 1.8,
83 5.0,
84 11.0);
85
86 const double pulse01 = (std::sin(t * 2.8) + 1.0) * 0.5;
87 const double ring_r = base_r + 4.0 + pulse01 * 10.0;
88 const double ring_alpha = 0.10 + (1.0 - pulse01) * 0.22;
89 const double glow_r = base_r + 7.0 + pulse01 * 4.0;
90 const double glow_alpha = 0.12 + pulse01 * 0.10;
91
92 cairo_save(cr);
93
94 cairo_pattern_t* glow =
95 cairo_pattern_create_radial(cx, cy, base_r * 0.3, cx, cy, glow_r);
96 cairo_pattern_add_color_stop_rgba(glow, 0.0, 1.0, 0.42, 0.28, glow_alpha);
97 cairo_pattern_add_color_stop_rgba(glow, 1.0, 1.0, 0.42, 0.28, 0.0);
98 cairo_set_source(cr, glow);
99 cairo_arc(cr, cx, cy, glow_r, 0.0, 2.0 * M_PI);
100 cairo_fill(cr);
101 cairo_pattern_destroy(glow);
102
103 cairo_set_source_rgba(cr, 1.0, 0.53, 0.30, ring_alpha);
104 cairo_set_line_width(cr, 2.0);
105 cairo_arc(cr, cx, cy, ring_r, 0.0, 2.0 * M_PI);
106 cairo_stroke(cr);
107
108 cairo_set_source_rgba(cr, 1.0, 0.36, 0.26, 0.98);
109 cairo_arc(cr, cx, cy, base_r, 0.0, 2.0 * M_PI);
110 cairo_fill(cr);
111
112 cairo_set_source_rgba(cr, 1.0, 0.95, 0.92, 0.95);
113 cairo_set_line_width(cr, 1.5);
114 cairo_arc(cr, cx, cy, base_r, 0.0, 2.0 * M_PI);
115 cairo_stroke(cr);
116
117 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.30);
118 cairo_arc(cr,
119 cx - base_r * 0.30,
120 cy - base_r * 0.32,
121 std::max(1.5, base_r * 0.33),
122 0.0,
123 2.0 * M_PI);
124 cairo_fill(cr);
125
126 cairo_restore(cr);
127 }

References animated_marker_draw().

Referenced by animated_marker_draw(), and create_animated_dot_widget().

◆ animated_marker_tick()

gboolean anonymous_namespace{NetworkPage.cpp}::animated_marker_tick ( GtkWidget * widget,
GdkFrameClock * ,
gpointer  )
static

Definition at line 48 of file NetworkPage.cpp.

51 {
52 gtk_widget_queue_draw(widget);
53 return G_SOURCE_CONTINUE;
54 }

References animated_marker_tick().

Referenced by animated_marker_tick(), and create_animated_dot_widget().

◆ create_animated_dot_widget()

GtkWidget * anonymous_namespace{NetworkPage.cpp}::create_animated_dot_widget ( int hits)
static

Definition at line 129 of file NetworkPage.cpp.

130 {
131 auto* area = gtk_drawing_area_new();
132
133 const int size = std::clamp(
134 32 + static_cast<int>(std::log2(static_cast<double>(std::max(1, hits)) + 1.0) * 8.0),
135 32,
136 54
137 );
138
139 auto* data = new AnimatedMarkerData{};
140 data->start_us = g_get_monotonic_time();
141 data->hits = hits;
142
143 gtk_widget_set_size_request(area, size, size);
144 gtk_drawing_area_set_content_width(GTK_DRAWING_AREA(area), size);
145 gtk_drawing_area_set_content_height(GTK_DRAWING_AREA(area), size);
146 gtk_drawing_area_set_draw_func(
147 GTK_DRAWING_AREA(area),
149 data,
151 );
152
153 gtk_widget_add_tick_callback(area, animated_marker_tick, nullptr, nullptr);
154 gtk_widget_set_halign(area, GTK_ALIGN_CENTER);
155 gtk_widget_set_valign(area, GTK_ALIGN_CENTER);
156
157 return area;
158 }
static void animated_marker_data_destroy(gpointer data)
static gboolean animated_marker_tick(GtkWidget *widget, GdkFrameClock *, gpointer)
static void animated_marker_draw(GtkDrawingArea *, cairo_t *cr, int width, int height, gpointer user_data)

References animated_marker_data_destroy(), animated_marker_draw(), animated_marker_tick(), and create_animated_dot_widget().

Referenced by create_animated_dot_widget().

◆ hover_payload_destroy()

void anonymous_namespace{NetworkPage.cpp}::hover_payload_destroy ( gpointer data,
GClosure *  )
static

Definition at line 61 of file NetworkPage.cpp.

62 {
63 delete static_cast<HoverPayload*>(data);
64 }

References hover_payload_destroy().

Referenced by hover_payload_destroy().

◆ map_fx_draw()

void anonymous_namespace{NetworkPage.cpp}::map_fx_draw ( GtkDrawingArea * ,
cairo_t * cr,
int width,
int height,
gpointer user_data )
static

Definition at line 160 of file NetworkPage.cpp.

165 {
166 // user_data contiene il NetworkPage*. Se null, non disegniamo nulla
167 // (overlay trasparente).
168 auto* page = static_cast<NetworkPage*>(user_data);
169 if (!page) return;
170 page->drawConnectionArcs(cr, width, height);
171 }
void drawConnectionArcs(cairo_t *cr, int width, int height)

References NetworkPage::drawConnectionArcs(), and map_fx_draw().

Referenced by map_fx_draw().

◆ net_json_escape()

std::string anonymous_namespace{NetworkPage.cpp}::net_json_escape ( const std::string & s)

Definition at line 1139 of file NetworkPage.cpp.

1139 {
1140 std::string out;
1141 out.reserve(s.size());
1142 for (unsigned char c : s) {
1143 switch (c) {
1144 case '"': out += "\\\""; break;
1145 case '\\': out += "\\\\"; break;
1146 case '\n': out += "\\n"; break;
1147 case '\r': out += "\\r"; break;
1148 case '\t': out += "\\t"; break;
1149 default:
1150 if (c < 0x20) {
1151 char b[8];
1152 std::snprintf(b, sizeof(b), "\\u%04x", c);
1153 out += b;
1154 } else {
1155 out += static_cast<char>(c);
1156 }
1157 }
1158 }
1159 return out;
1160 }

References net_json_escape().

Referenced by net_json_escape().

◆ net_json_field_double()

double anonymous_namespace{NetworkPage.cpp}::net_json_field_double ( const std::string & line,
const std::string & key )

Definition at line 1176 of file NetworkPage.cpp.

1177 {
1178 const std::string needle = "\"" + key + "\":";
1179 auto pos = line.find(needle);
1180 if (pos == std::string::npos) return 0.0;
1181 pos += needle.size();
1182 return std::strtod(line.c_str() + pos, nullptr);
1183 }

References net_json_field_double().

Referenced by net_json_field_double().

◆ net_json_field_i64()

int64_t anonymous_namespace{NetworkPage.cpp}::net_json_field_i64 ( const std::string & line,
const std::string & key )

Definition at line 1185 of file NetworkPage.cpp.

1186 {
1187 const std::string needle = "\"" + key + "\":";
1188 auto pos = line.find(needle);
1189 if (pos == std::string::npos) return 0;
1190 pos += needle.size();
1191 return std::strtoll(line.c_str() + pos, nullptr, 10);
1192 }

References net_json_field_i64().

Referenced by net_json_field_i64().

◆ net_json_field_str()

std::string anonymous_namespace{NetworkPage.cpp}::net_json_field_str ( const std::string & line,
const std::string & key )

Definition at line 1165 of file NetworkPage.cpp.

1166 {
1167 const std::string needle = "\"" + key + "\":\"";
1168 auto pos = line.find(needle);
1169 if (pos == std::string::npos) return {};
1170 pos += needle.size();
1171 auto end = line.find('"', pos);
1172 return end == std::string::npos ? std::string{}
1173 : line.substr(pos, end - pos);
1174 }

References net_json_field_str().

Referenced by net_json_field_str().

Variable Documentation

◆ kDefaultLat

double anonymous_namespace{NetworkPage.cpp}::kDefaultLat = 20.0
constexpr

Definition at line 22 of file NetworkPage.cpp.

◆ kDefaultLon

double anonymous_namespace{NetworkPage.cpp}::kDefaultLon = 10.0
constexpr

Definition at line 23 of file NetworkPage.cpp.

◆ kDefaultZoom

double anonymous_namespace{NetworkPage.cpp}::kDefaultZoom = 2.2
constexpr

Definition at line 24 of file NetworkPage.cpp.

◆ kFocusedZoom

double anonymous_namespace{NetworkPage.cpp}::kFocusedZoom = 3.0
constexpr

Definition at line 25 of file NetworkPage.cpp.

◆ kHoverHideDelay

auto anonymous_namespace{NetworkPage.cpp}::kHoverHideDelay = std::chrono::milliseconds(140)
constexpr

Definition at line 28 of file NetworkPage.cpp.

◆ kMaxZoom

double anonymous_namespace{NetworkPage.cpp}::kMaxZoom = 20.0
constexpr

Definition at line 26 of file NetworkPage.cpp.

◆ kMinZoom

double anonymous_namespace{NetworkPage.cpp}::kMinZoom = 1.0
constexpr

Definition at line 27 of file NetworkPage.cpp.

◆ kUserViewportHold

auto anonymous_namespace{NetworkPage.cpp}::kUserViewportHold = std::chrono::seconds(8)
constexpr

Definition at line 29 of file NetworkPage.cpp.