1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#include "simpleDisplay.h"
const static char YES = '.';
const static int gapY = 2;
const static int gapX = 5;
const static int lineHeight = 2;
cSimpleWeatherOsd::cSimpleWeatherOsd(cUpdate *metarReader) {
osd = NULL;
color = clrRed;
this->metarReader = metarReader;
}
cSimpleWeatherOsd::~cSimpleWeatherOsd() {
delete osd;
}
void cSimpleWeatherOsd::Show(void) {
osd = cOsdProvider::NewOsd(50, 50);
const cFont *font = cFont::GetFont((eDvbFont)0);
if (osd) {
tArea Area = {0, 240, 611, 489, 4};
osd->SetAreas(&Area, 1);
osd->DrawRectangle(0, 240, 611, 489, clrGray50);
if (metarReader->isDataAvailable()) {
Decoded_METAR *decodedMetar = metarReader->getDecodedMetar();
this->printMetar(osd, decodedMetar, 10, 250);
} else {
osd->DrawText(10, 250, tr("No Data available"),clrWhite, clrTransparent, font);
}
osd->Flush();
}
}
eOSState cSimpleWeatherOsd::ProcessKey(eKeys Key) {
eOSState state = cOsdObject::ProcessKey(Key);
if (state == osUnknown) {
switch (Key & ~k_Repeat) {
case kOk: return osEnd;
case kBack: return osEnd;
default: return state;
}
state = osContinue;
}
return state;
}
void cSimpleWeatherOsd::printMetar (cOsd *osd, Decoded_METAR *Mptr, int x, int y) {
const cFont *font = cFont::GetFont((eDvbFont)0);
drawData(osd, Mptr, 0, font, x, y);
}
int cSimpleWeatherOsd::calculateMaxDescriptionFontWidth(measurement measurements[], int size, const cFont *font) {
int maxSize = 0;
int strSize = 0;
for (int i = 0; i< size; i++) {
strSize = font->Width(measurements[i].description);
if (strSize > maxSize) {
maxSize = strSize;
}
}
return maxSize;
}
int cSimpleWeatherOsd::calculateMaxValueFontWidth(measurement measurements[], int size, const cFont *font) {
int maxSize = 0;
int strSize = 0;
for (int i = 0; i< size; i++) {
strSize = font->Width(measurements[i].value);
if (strSize > maxSize) {
maxSize = strSize;
}
}
return maxSize;
}
void cSimpleWeatherOsd::drawData(cOsd *osd, Decoded_METAR *Mptr, int cy, const cFont *font, int x, int y) {
measurement measurements[10];
for(int i=0; i<10; i++) {
*measurements[i].description = 0;
*measurements[i].value = 0;
}
if ( Mptr->stnid[0] != '\0' ) {
sprintf(measurements[cy].description, "%s", Mptr->stnid);
}
if ( Mptr->ob_hour != MAXINT && Mptr->ob_minute != MAXINT ) {
sprintf(measurements[cy].description, "%s, %d:%d", measurements[cy].description, Mptr->ob_hour, Mptr->ob_minute);
}
cy++;
sprintf(measurements[cy].description, "%s", tr("Temperature"));
if ( Mptr->temp != MAXINT ) {
sprintf(measurements[cy].value, "%d C", Mptr->temp);
} else {
sprintf(measurements[cy].value, "%s", tr("No Data"));
}
cy++;
sprintf(measurements[cy].description, "%s", tr("Windchill"));
if (Mptr->temp != MAXINT && Mptr->winData.windSpeed != MAXINT) {
sprintf(measurements[cy].value, "%d C", cWeatherUtil::calculateWindChill(Mptr->temp, Mptr->winData.windSpeed));
} else {
sprintf(measurements[cy].value, "%s", tr("No Data"));
}
cy++;
sprintf(measurements[cy].description, "%s", tr("Dew point"));
if ( Mptr->dew_pt_temp != MAXINT ) {
sprintf(measurements[cy].value, "%d C", Mptr->dew_pt_temp);
} else {
sprintf(measurements[cy].value, "%s", tr("No Data"));
}
cy++;
sprintf(measurements[cy].description, "%s", tr("Wind speed"));
if ( Mptr->winData.windSpeed != MAXINT && Mptr->winData.windUnits[0] != '\0') {
sprintf(measurements[cy].value, "%d %s",Mptr->winData.windSpeed, Mptr->winData.windUnits);
} else {
sprintf(measurements[cy].value, "%s", tr("No Data"));
}
cy++;
sprintf(measurements[cy].description, "%s", tr("Wind direction"));
if (Mptr->winData.windDir != MAXINT) {
sprintf(measurements[cy].value, "%d (%s)",Mptr->winData.windDir, cWeatherUtil::calculateWindDirectionString(Mptr->winData.windDir));
} else {
sprintf(measurements[cy].value, "%s", tr("No Data"));
}
cy++;
sprintf(measurements[cy].description, "%s", tr("Humidity"));
if ( Mptr->temp != MAXINT && Mptr->dew_pt_temp != MAXINT) {
int hum = cWeatherUtil::calculateHumidity(Mptr->temp, Mptr->dew_pt_temp);
sprintf(measurements[cy].value, "%i %%", hum);
} else {
sprintf(measurements[cy].value, "%s", tr("No Data"));
}
cy++;
sprintf(measurements[cy].description, "%s", tr("Altimeter"));
if ( Mptr->A_altstng ) {
sprintf(measurements[cy].value, "%.2f inch", Mptr->inches_altstng );
} else if ( Mptr->Q_altstng ) {
sprintf(measurements[cy].value, "%d hPa", Mptr->hectoPasc_altstng );
} else{
sprintf(measurements[cy].value, "%s", tr("No Data"));
}
int maxSize = x + calculateMaxDescriptionFontWidth(measurements, cy, font) + gapX;
osd->DrawText(maxSize-font->Width(measurements[0].description)-gapX, y,
measurements[0].description, clrWhite, clrTransparent, font);
y += font->Height(measurements[0].description) + gapY;
int lineY = y;
osd->DrawRectangle(x, y, maxSize+gapX, y+lineHeight, clrBlue);
y += lineHeight+gapY;
for (int i=1; i<=cy; i++) {
osd->DrawText(maxSize-font->Width(measurements[i].description)-gapX, y,
measurements[i].description, clrWhite, clrTransparent, font);
osd->DrawText(maxSize+lineHeight+gapX+gapX, y, measurements[i].value,
clrWhite, clrTransparent, font);
osd->DrawRectangle(maxSize, y+(font->Height(measurements[0].description)/2), maxSize+gapX, y+(font->Height(measurements[0].description)/2)+lineHeight, clrBlue);
y += font->Height(measurements[0].description) + gapY;
}
osd->DrawRectangle(maxSize+gapX, lineY, maxSize+gapX+lineHeight, y, clrBlue);
}
|