Feature/hourlyforecast #4

Merged
FlareMicrosystems merged 4 commits from feature/hourlyforecast into master 2024-03-16 06:48:10 +00:00
11 changed files with 433 additions and 57 deletions
Showing only changes of commit fee43c3ee2 - Show all commits

View File

@@ -47,6 +47,8 @@ public class HourlyForecastDisplay implements Display {
DateFormat simpleDateFormat = new SimpleDateFormat("ha"); DateFormat simpleDateFormat = new SimpleDateFormat("ha");
BufferedImage lastBuffer = null;
public HourlyForecastDisplay() { public HourlyForecastDisplay() {
font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf")); font = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000.ttf"));
smallFont = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000 Small.ttf")); smallFont = FontManager.getInstance().getOrCreateFont(Font.TRUETYPE_FONT, this.getClass().getResource("/Star4000 Small.ttf"));
@@ -95,46 +97,6 @@ public class HourlyForecastDisplay implements Display {
@Override @Override
public void drawDisplay(RenderPanel renderer, Graphics2D g2d, long ticks, int iconTicks) { public void drawDisplay(RenderPanel renderer, Graphics2D g2d, long ticks, int iconTicks) {
}
public int minTemp(HourlyForecast[] forecast) {
int min = Integer.MAX_VALUE;
for (int i = 0; i < forecast.length; i++)
{
int currMin;
if (ValueCheck.valueNoData(forecast[i].dewPoint) && ValueCheck.valueNoData(forecast[i].temp))
continue;
else if (ValueCheck.valueNoData(forecast[i].dewPoint))
currMin = forecast[i].temp;
else if (ValueCheck.valueNoData(forecast[i].temp))
currMin = forecast[i].dewPoint;
else currMin = Math.min(forecast[i].temp, forecast[i].dewPoint);
if (currMin < min)
min = currMin;
}
return min;
}
public int maxTemp(HourlyForecast[] forecast) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < forecast.length; i++)
{
int currMax;
if (ValueCheck.valueNoData(forecast[i].dewPoint) && ValueCheck.valueNoData(forecast[i].temp))
continue;
else if (ValueCheck.valueNoData(forecast[i].dewPoint))
currMax = forecast[i].temp;
else if (ValueCheck.valueNoData(forecast[i].temp))
currMax = forecast[i].dewPoint;
else currMax = Math.max(forecast[i].temp, forecast[i].dewPoint);
if (currMax > max)
max = currMax;
}
return max;
}
@Override
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g2d, Rectangle bounds, long ticks, int iconTicks) {
HourlyForecast[] forecast = currentTown.getHourlyForecast(); HourlyForecast[] forecast = currentTown.getHourlyForecast();
if (forecast == null) if (forecast == null)
return; return;
@@ -180,7 +142,6 @@ public class HourlyForecastDisplay implements Display {
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 - fm.stringWidth(maxText), RenderConstants.TOPBAR_HEIGHT + 53, maxText, Color.YELLOW, Color.BLACK, 2); DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 - fm.stringWidth(maxText), RenderConstants.TOPBAR_HEIGHT + 53, maxText, Color.YELLOW, Color.BLACK, 2);
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 - fm.stringWidth(minText), RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 92, minText, Color.YELLOW, Color.BLACK, 2); DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 - fm.stringWidth(minText), RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 92, minText, Color.YELLOW, Color.BLACK, 2);
g2d.setColor(RenderConstants.BG_ORANGE.darker()); g2d.setColor(RenderConstants.BG_ORANGE.darker());
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40, (RenderConstants.TOPBAR_HEIGHT + 50), (RenderConstants.W - RenderConstants.SIDE_OFFSET - 20), (RenderConstants.TOPBAR_HEIGHT + 50)); g2d.drawLine(RenderConstants.SIDE_OFFSET + 40, (RenderConstants.TOPBAR_HEIGHT + 50), (RenderConstants.W - RenderConstants.SIDE_OFFSET - 20), (RenderConstants.TOPBAR_HEIGHT + 50));
@@ -228,79 +189,6 @@ public class HourlyForecastDisplay implements Display {
g2d.setClip(null); g2d.setClip(null);
/*g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.BLACK);
//This is so ugly
for (int i = 0; i < Math.min(12, forecast.length); i++)
{
int nextDewpoint = (RenderConstants.TOPBAR_HEIGHT + 50) + (RenderConstants.MAINBAR_HEIGHT - 144) - (int) (((max - forecast[i].dewPoint) / range) * (RenderConstants.MAINBAR_HEIGHT - 144));
int nextTemperature = (RenderConstants.TOPBAR_HEIGHT + 50) + (RenderConstants.MAINBAR_HEIGHT - 144) - (int) (((max - forecast[i].temp) / range) * (RenderConstants.MAINBAR_HEIGHT - 144));
int nextPercip = (RenderConstants.TOPBAR_HEIGHT + 50) + (RenderConstants.MAINBAR_HEIGHT - 144) - (int) ((forecast[i].percip / 100F) * (RenderConstants.MAINBAR_HEIGHT - 144));
if (i == 0)
{
lastDewpoint = nextDewpoint;
lastTemperature = nextTemperature;
lastPercip = nextPercip;
}
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i - 1)) + 2, lastDewpoint + 2, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) + 2, nextDewpoint + 2);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i - 1)) + 2, lastPercip + 2, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) + 2, nextPercip + 2);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i - 1)) + 2, lastTemperature + 2, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) + 2, nextTemperature + 2);
if (i == Math.min(12, forecast.length) - 1)
{
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i)) + 2, nextDewpoint + 2, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i + 2)) + 2, nextDewpoint + 2);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i)) + 2, nextPercip + 2, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i + 2)) + 2, nextPercip + 2);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i)) + 2, nextTemperature + 2, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i + 2)) + 2, nextTemperature + 2);
}
lastPercip = nextPercip;
lastTemperature = nextTemperature;
lastDewpoint = nextDewpoint;
}
g2d.setClip(null);
for (int i = 0; i < Math.min(12, forecast.length); i++)
{
g2d.setClip(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + 40, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60, RenderConstants.MAINBAR_HEIGHT - 124);
int nextDewpoint = (RenderConstants.TOPBAR_HEIGHT + 50) + (RenderConstants.MAINBAR_HEIGHT - 144) - (int) (((max - forecast[i].dewPoint) / range) * (RenderConstants.MAINBAR_HEIGHT - 144));
int nextTemperature = (RenderConstants.TOPBAR_HEIGHT + 50) + (RenderConstants.MAINBAR_HEIGHT - 144) - (int) (((max - forecast[i].temp) / range) * (RenderConstants.MAINBAR_HEIGHT - 144));
int nextPercip = (RenderConstants.TOPBAR_HEIGHT + 50) + (RenderConstants.MAINBAR_HEIGHT - 144) - (int) ((forecast[i].percip / 100F) * (RenderConstants.MAINBAR_HEIGHT - 144));
if (i == 0)
{
lastDewpoint = nextDewpoint;
lastTemperature = nextTemperature;
lastPercip = nextPercip;
}
g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.WHITE);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i - 1)), lastDewpoint, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i), nextDewpoint);
g2d.setColor(Color.CYAN);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i - 1)), lastPercip, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i), nextPercip);
g2d.setColor(Color.RED);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i - 1)), lastTemperature, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i), nextTemperature);
if (i == Math.min(12, forecast.length) - 1)
{
g2d.setColor(Color.WHITE);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i)), nextDewpoint, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i + 1)), nextDewpoint);
g2d.setColor(Color.CYAN);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i)), nextPercip, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i + 1)), nextPercip);
g2d.setColor(Color.RED);
g2d.drawLine(RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i)), nextTemperature, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * (i + 1)), nextTemperature);
}
g2d.setClip(null);
lastPercip = nextPercip;
lastTemperature = nextTemperature;
lastDewpoint = nextDewpoint;
String timeString = simpleDateFormat.format(forecast[i].hour);
if ((i % 2) == 0)
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 70, timeString, Color.YELLOW, Color.BLACK, 2);
else DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 60, timeString, Color.YELLOW, Color.BLACK, 2);
IconProvider.drawIcon(g2d, IconProvider.INDEXED_ICONS[forecast[i].iconId], RenderConstants.SIDE_OFFSET + 45 + i * slotWidth, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth - 10, iconTicks);
}
*/
g2d.setStroke(new BasicStroke(2)); g2d.setStroke(new BasicStroke(2));
g2d.setColor(Color.BLACK); g2d.setColor(Color.BLACK);
g2d.drawRect(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + 40, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60, RenderConstants.MAINBAR_HEIGHT - 124); g2d.drawRect(RenderConstants.SIDE_OFFSET + 40, RenderConstants.TOPBAR_HEIGHT + 40, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60, RenderConstants.MAINBAR_HEIGHT - 124);
@@ -311,10 +199,63 @@ public class HourlyForecastDisplay implements Display {
if ((i % 2) == 0) if ((i % 2) == 0)
DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 70, timeString, Color.YELLOW, Color.BLACK, 2); DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 70, timeString, Color.YELLOW, Color.BLACK, 2);
else DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 60, timeString, Color.YELLOW, Color.BLACK, 2); else DrawingUtil.drawOutlinedString(g2d, RenderConstants.SIDE_OFFSET + 40 + slotWidth / 2 + (slotWidth * i) - fm.stringWidth(timeString) / 2, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 60, timeString, Color.YELLOW, Color.BLACK, 2);
IconProvider.drawIcon(g2d, IconProvider.INDEXED_ICONS[forecast[i].iconId], RenderConstants.SIDE_OFFSET + 45 + i * slotWidth, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth - 10, iconTicks); IconProvider.drawIcon(g2d, IconProvider.INDEXED_ICONS[forecast[i].iconId], RenderConstants.SIDE_OFFSET + 45 + i * slotWidth, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth - 10, iconTicks);
} }
lastBuffer = renderer.getSnapshot().getSubimage(RenderConstants.SIDE_OFFSET - 1, RenderConstants.TOPBAR_HEIGHT + 19, RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 + 2, RenderConstants.MAINBAR_HEIGHT - 38);
lastBuffer.setAccelerationPriority(1);
}
public int minTemp(HourlyForecast[] forecast) {
int min = Integer.MAX_VALUE;
for (int i = 0; i < forecast.length; i++)
{
int currMin;
if (ValueCheck.valueNoData(forecast[i].dewPoint) && ValueCheck.valueNoData(forecast[i].temp))
continue;
else if (ValueCheck.valueNoData(forecast[i].dewPoint))
currMin = forecast[i].temp;
else if (ValueCheck.valueNoData(forecast[i].temp))
currMin = forecast[i].dewPoint;
else currMin = Math.min(forecast[i].temp, forecast[i].dewPoint);
if (currMin < min)
min = currMin;
}
return min;
}
public int maxTemp(HourlyForecast[] forecast) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < forecast.length; i++)
{
int currMax;
if (ValueCheck.valueNoData(forecast[i].dewPoint) && ValueCheck.valueNoData(forecast[i].temp))
continue;
else if (ValueCheck.valueNoData(forecast[i].dewPoint))
currMax = forecast[i].temp;
else if (ValueCheck.valueNoData(forecast[i].temp))
currMax = forecast[i].dewPoint;
else currMax = Math.max(forecast[i].temp, forecast[i].dewPoint);
if (currMax > max)
max = currMax;
}
return max;
}
@Override
public void drawBoundLimitedDisplay(RenderPanel renderer, Graphics2D g2d, Rectangle bounds, long ticks, int iconTicks) {
HourlyForecast[] forecast = currentTown.getHourlyForecast();
if (forecast == null)
return;
if (this.lastBuffer != null)
{
g2d.drawImage(lastBuffer, RenderConstants.SIDE_OFFSET - 1, RenderConstants.TOPBAR_HEIGHT + 19, renderer);
}
int slotWidth = (RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60) / 12;
for (int i = 0; i < Math.min(12, forecast.length); i++)
{
if (IconProvider.INDEXED_ICONS[forecast[i].iconId].isAnimated())
IconProvider.drawIcon(g2d, IconProvider.INDEXED_ICONS[forecast[i].iconId], RenderConstants.SIDE_OFFSET + 45 + i * slotWidth, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth - 10, iconTicks);
}
} }
public void graphTemp(Graphics2D g2d, byte[] tempVal, int min, int slotWidth, float range, float multiplier) { public void graphTemp(Graphics2D g2d, byte[] tempVal, int min, int slotWidth, float range, float multiplier) {
@@ -375,7 +316,8 @@ public class HourlyForecastDisplay implements Display {
@Override @Override
public void redrawRegionlost(RenderPanel renderer) { public void redrawRegionlost(RenderPanel renderer) {
renderer.addRedrawBound(0, RenderConstants.TOPBAR_HEIGHT, RenderConstants.W, RenderConstants.MAINBAR_HEIGHT); int slotWidth = (RenderConstants.W - RenderConstants.SIDE_OFFSET * 2 - 60) / 12;
renderer.addRedrawBound(RenderConstants.SIDE_OFFSET + 45, RenderConstants.TOPBAR_HEIGHT + MAINBAR_HEIGHT - 55, slotWidth * 12 - 10, slotWidth - 10);
} }
@Override @Override

View File

@@ -1,3 +1,3 @@
#VisualForecast 1000 Properties file. Functional provider must be set for successful boot! #VisualForecast 1000 Properties file. Functional provider must be set for successful boot!
#Sat Mar 09 23:33:26 PST 2024 #Sat Mar 09 23:49:43 PST 2024
forecast-provider-jar=MockForecastProvider.jar forecast-provider-jar=MockForecastProvider.jar