This commit is contained in:
HarukiToreda
2025-10-19 03:47:02 -04:00
parent 68e739359f
commit 7afc6ef833
@@ -27,48 +27,54 @@ void InkHUD::MapApplet::onRender()
// Add white halo outline first // Add white halo outline first
constexpr int outlinePad = 1; // size of white outline padding constexpr int outlinePad = 1; // size of white outline padding
int boxSize = (m.hasHopsAway && m.hopsAway > config.lora.hop_limit) || !m.hasHopsAway ? 12 : 10; int boxSize = (m.hasHopsAway && m.hopsAway > config.lora.hop_limit) || !m.hasHopsAway ? 12 : 10;
fillRect(x - (boxSize / 2) - outlinePad, y - (boxSize / 2) - outlinePad, fillRect(x - (boxSize / 2) - outlinePad, y - (boxSize / 2) - outlinePad, boxSize + (outlinePad * 2),
boxSize + (outlinePad * 2), boxSize + (outlinePad * 2), WHITE); boxSize + (outlinePad * 2), WHITE);
// Draw actual marker on top // Draw actual marker on top
if (m.hasHopsAway && m.hopsAway > config.lora.hop_limit) { if (m.hasHopsAway && m.hopsAway > config.lora.hop_limit) {
fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK); fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK);
setFont(fontSmall); setTextColor(WHITE); setFont(fontSmall);
setTextColor(WHITE);
printAt(x, y, "X", CENTER, MIDDLE); printAt(x, y, "X", CENTER, MIDDLE);
} } else if (!m.hasHopsAway) {
else if (!m.hasHopsAway) {
fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK); fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK);
setFont(fontSmall); setTextColor(WHITE); setFont(fontSmall);
setTextColor(WHITE);
printAt(x, y, "?", CENTER, MIDDLE); printAt(x, y, "?", CENTER, MIDDLE);
} } else {
else {
fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK); fillRect(x - boxSize / 2, y - boxSize / 2, boxSize, boxSize, BLACK);
char hopStr[4]; snprintf(hopStr, sizeof(hopStr), "%d", m.hopsAway); char hopStr[4];
setFont(fontSmall); setTextColor(WHITE); snprintf(hopStr, sizeof(hopStr), "%d", m.hopsAway);
setFont(fontSmall);
setTextColor(WHITE);
printAt(x, y, hopStr, CENTER, MIDDLE); printAt(x, y, hopStr, CENTER, MIDDLE);
} }
// Restore default font and color (safety for rest of UI) // Restore default font and color (safety for rest of UI)
setFont(fontSmall); setTextColor(BLACK); setFont(fontSmall);
setTextColor(BLACK);
} }
// Dual map scale bars // Dual map scale bars
int16_t horizPx = width() * 0.25f; int16_t horizPx = width() * 0.25f;
int16_t vertPx = height() * 0.25f; int16_t vertPx = height() * 0.25f;
float horizMeters = horizPx / metersToPx; float horizMeters = horizPx / metersToPx;
float vertMeters = vertPx / metersToPx; float vertMeters = vertPx / metersToPx;
auto formatDistance = [&](float meters, char *out, size_t len) { auto formatDistance = [&](float meters, char *out, size_t len) {
if (config.display.units == meshtastic_Config_DisplayConfig_DisplayUnits_IMPERIAL) { if (config.display.units == meshtastic_Config_DisplayConfig_DisplayUnits_IMPERIAL) {
float feet = meters * 3.28084f; float feet = meters * 3.28084f;
if (feet < 528) snprintf(out, len, "%.0f ft", feet); if (feet < 528)
snprintf(out, len, "%.0f ft", feet);
else { else {
float miles = feet / 5280.0f; float miles = feet / 5280.0f;
snprintf(out, len, miles < 10 ? "%.1f mi" : "%.0f mi", miles); snprintf(out, len, miles < 10 ? "%.1f mi" : "%.0f mi", miles);
} }
} else { } else {
if (meters >= 1000) snprintf(out, len, "%.1f km", meters / 1000.0f); if (meters >= 1000)
else snprintf(out, len, "%.0f m", meters); snprintf(out, len, "%.1f km", meters / 1000.0f);
else
snprintf(out, len, "%.0f m", meters);
} }
}; };
@@ -115,12 +121,7 @@ void InkHUD::MapApplet::onRender()
// Draw our node LAST with full white fill + outline // Draw our node LAST with full white fill + outline
meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum()); meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum());
if (ourNode && nodeDB->hasValidPosition(ourNode)) { if (ourNode && nodeDB->hasValidPosition(ourNode)) {
Marker self = calculateMarker( Marker self = calculateMarker(ourNode->position.latitude_i * 1e-7, ourNode->position.longitude_i * 1e-7, false, 0);
ourNode->position.latitude_i * 1e-7,
ourNode->position.longitude_i * 1e-7,
false,
0
);
int16_t centerX = X(0.5) + (self.eastMeters * metersToPx); int16_t centerX = X(0.5) + (self.eastMeters * metersToPx);
int16_t centerY = Y(0.5) - (self.northMeters * metersToPx); int16_t centerY = Y(0.5) - (self.northMeters * metersToPx);
@@ -160,7 +161,8 @@ void InkHUD::MapApplet::getMapCenter(float *lat, float *lng)
// - uses tan to find angles for lat / long degrees // - uses tan to find angles for lat / long degrees
// - longitude: triangle formed by x and y (on plane of the equator) // - longitude: triangle formed by x and y (on plane of the equator)
// - latitude: triangle formed by z (north south), // - latitude: triangle formed by z (north south),
// and the line along plane of equator which stretches from earth's axis to where point xyz intersects planet's surface // and the line along plane of equator which stretches from earth's axis to where point xyz intersects planet's
// surface
// Working totals, averaged after nodeDB processed // Working totals, averaged after nodeDB processed
uint32_t positionCount = 0; uint32_t positionCount = 0;
@@ -422,13 +424,13 @@ void InkHUD::MapApplet::drawLabeledMarker(meshtastic_NodeInfoLite *node)
// Prevent overlap with scale bars and their labels // Prevent overlap with scale bars and their labels
// Define a "safe zone" in the bottom-left where the scale bars and text are drawn // Define a "safe zone" in the bottom-left where the scale bars and text are drawn
constexpr int16_t safeZoneHeight = 28; // adjust based on your label font height constexpr int16_t safeZoneHeight = 28; // adjust based on your label font height
constexpr int16_t safeZoneWidth = 60; // adjust based on horizontal label width zone constexpr int16_t safeZoneWidth = 60; // adjust based on horizontal label width zone
bool overlapsScale = (labelY + labelH > height() - safeZoneHeight) && (labelX < safeZoneWidth); bool overlapsScale = (labelY + labelH > height() - safeZoneHeight) && (labelX < safeZoneWidth);
// If it overlaps, shift label upward slightly above the safe zone // If it overlaps, shift label upward slightly above the safe zone
if (overlapsScale) { if (overlapsScale) {
labelY = height() - safeZoneHeight - labelH - 2; labelY = height() - safeZoneHeight - labelH - 2;
textY = labelY + (labelH / 2); textY = labelY + (labelH / 2);
} }
// Backing box // Backing box