diff options
author | Martin Schirrmacher <vdr.skinflatplus@schirrmacher.eu> | 2014-11-16 19:24:54 +0100 |
---|---|---|
committer | Martin Schirrmacher <vdr.skinflatplus@schirrmacher.eu> | 2014-11-16 19:24:54 +0100 |
commit | f997e3c12313a74339ffa81e7488217f2ec6c06d (patch) | |
tree | 2353862891d10a99e01e6418a3d63268f03eed5f | |
parent | e2ab40154d2adfe5549e6aba7fe067173bd9c54a (diff) | |
download | skin-flatplus-f997e3c12313a74339ffa81e7488217f2ec6c06d.tar.gz skin-flatplus-f997e3c12313a74339ffa81e7488217f2ec6c06d.tar.bz2 |
update weather widget
-rw-r--r-- | baserender.c | 49 | ||||
-rw-r--r-- | icons/default/widgets/rain.png | bin | 6021 -> 6000 bytes | |||
-rw-r--r-- | icons/default/widgets/sleet.png | bin | 5681 -> 6021 bytes | |||
-rw-r--r-- | widgets/weather/update_weather.config | 2 | ||||
-rw-r--r-- | widgets/weather/update_weather.php | 7 |
5 files changed, 43 insertions, 15 deletions
diff --git a/baserender.c b/baserender.c index 7a094e43..db8edbfa 100644 --- a/baserender.c +++ b/baserender.c @@ -1486,7 +1486,7 @@ int cFlatBaseRender::GetFontAscender(const char *Name, int CharHeight, int CharW void cFlatBaseRender::DrawWidgetWeather(void) { cFont *fontTempSml = cFont::CreateFont(Setup.FontOsd, Setup.FontOsdSize/2.0 ); - std::string tempToday = ""; + std::string tempToday = "", tempTodaySign = ""; std::string iconToday, iconTomorrow; std::string tempMaxToday, tempMaxTomorrow; std::string tempMinToday, tempMinTomorrow; @@ -1500,49 +1500,61 @@ void cFlatBaseRender::DrawWidgetWeather(void) { if( file.is_open() ) { std::getline(file, tempToday); file.close(); - } + std::size_t found = tempToday.find("°"); + if( found != std::string::npos) { + tempTodaySign = tempToday.substr(found); + tempToday = tempToday.substr(0, found); + } + } else + return; filename = cString::sprintf("%s/widgets/weather/weather.0.icon", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) ); file.open(*filename, std::ifstream::in); if( file.is_open() ) { std::getline(file, iconToday); file.close(); - } + } else + return; filename = cString::sprintf("%s/widgets/weather/weather.1.icon", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) ); file.open(*filename, std::ifstream::in); if( file.is_open() ) { std::getline(file, iconTomorrow); file.close(); - } + } else + return; filename = cString::sprintf("%s/widgets/weather/weather.0.tempMax", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) ); file.open(*filename, std::ifstream::in); if( file.is_open() ) { std::getline(file, tempMaxToday); file.close(); - } + } else + return; filename = cString::sprintf("%s/widgets/weather/weather.1.tempMax", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) ); file.open(*filename, std::ifstream::in); if( file.is_open() ) { std::getline(file, tempMaxTomorrow); file.close(); - } + } else + return; filename = cString::sprintf("%s/widgets/weather/weather.0.tempMin", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) ); file.open(*filename, std::ifstream::in); if( file.is_open() ) { std::getline(file, tempMinToday); file.close(); - } + } else + return; filename = cString::sprintf("%s/widgets/weather/weather.1.tempMin", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) ); file.open(*filename, std::ifstream::in); if( file.is_open() ) { std::getline(file, tempMinTomorrow); file.close(); - } + } else + return; double p = 0.0; filename = cString::sprintf("%s/widgets/weather/weather.0.precipitation", cPlugin::ConfigDirectory(PLUGIN_NAME_I18N) ); @@ -1573,7 +1585,7 @@ void cFlatBaseRender::DrawWidgetWeather(void) { int widthTempTomorrow = max(fontTempSml->Width(tempMaxTomorrow.c_str()), fontTempSml->Width(tempMinTomorrow.c_str()) ); int wTop = topBarHeight + Config.decorBorderTopBarSize*2 + 20 + Config.decorBorderChannelEPGSize; - int wWidth = marginItem + font->Width(tempToday.c_str()) + marginItem*2 + fontHeight + marginItem \ + int wWidth = marginItem + font->Width(tempToday.c_str()) + fontTempSml->Width(tempTodaySign.c_str()) + marginItem*2 + fontHeight + marginItem \ + widthTempToday + marginItem + fontHeight - marginItem*2 \ + fontTempSml->Width(precToday.c_str()) + marginItem*4 + fontHeight + marginItem \ + widthTempTomorrow + marginItem + fontHeight - marginItem*2 \ @@ -1583,11 +1595,18 @@ void cFlatBaseRender::DrawWidgetWeather(void) { weatherWidget.Clear(); weatherWidget.SetOsd(osd); weatherWidget.SetPosition(cRect(wLeft, wTop, wWidth, fontHeight)); - weatherWidget.SetBGColor(Config.decorBorderChannelBg); + weatherWidget.SetBGColor(Theme.Color(clrItemCurrentBg)); weatherWidget.SetScrollingActive(false); - weatherWidget.AddText(tempToday.c_str(), false, cRect(left, 0, 0, 0), Theme.Color(clrChannelFontEpg), Config.decorBorderChannelBg, font); - left += font->Width(tempToday.c_str()) + marginItem*2; + weatherWidget.AddText(tempToday.c_str(), false, cRect(left, 0, 0, 0), Theme.Color(clrChannelFontEpg), Theme.Color(clrItemCurrentBg), font); + left += font->Width(tempToday.c_str()); + + int fontAscender = GetFontAscender(Setup.FontOsd, Setup.FontOsdSize); + int fontAscender2 = GetFontAscender(Setup.FontOsd, Setup.FontOsdSize / 2.0); + int t = (fontHeight - fontAscender) - (fontTempSml->Height() - fontAscender2); + + weatherWidget.AddText(tempTodaySign.c_str(), false, cRect(left, t, 0, 0), Theme.Color(clrChannelFontEpg), Theme.Color(clrItemCurrentBg), fontTempSml); + left += fontTempSml->Width(tempTodaySign.c_str()) + marginItem*2; cString weatherIcon = cString::sprintf("widgets/%s", iconToday.c_str()); cImage *img = imgLoader.LoadIcon(*weatherIcon, fontHeight, fontHeight - marginItem*2); @@ -1595,8 +1614,8 @@ void cFlatBaseRender::DrawWidgetWeather(void) { weatherWidget.AddImage(img, cRect(left, 0 + marginItem, fontHeight, fontHeight)); left += fontHeight + marginItem; } - weatherWidget.AddText(tempMaxToday.c_str(), false, cRect(left, 0, 0, 0), Theme.Color(clrChannelFontEpg), Config.decorBorderChannelBg, fontTempSml); - weatherWidget.AddText(tempMinToday.c_str(), false, cRect(left, 0 + fontTempSml->Height(), 0, 0), Theme.Color(clrChannelFontEpg), Config.decorBorderChannelBg, fontTempSml); + weatherWidget.AddText(tempMaxToday.c_str(), false, cRect(left, 0, 0, 0), Theme.Color(clrChannelFontEpg), Theme.Color(clrItemCurrentBg), fontTempSml); + weatherWidget.AddText(tempMinToday.c_str(), false, cRect(left, 0 + fontTempSml->Height(), 0, 0), Theme.Color(clrChannelFontEpg), Theme.Color(clrItemCurrentBg), fontTempSml); left += widthTempToday + marginItem; img = imgLoader.LoadIcon("widgets/umbrella", fontHeight, fontHeight - marginItem*2); @@ -1604,7 +1623,7 @@ void cFlatBaseRender::DrawWidgetWeather(void) { weatherWidget.AddImage(img, cRect(left, 0 + marginItem, fontHeight, fontHeight)); left += fontHeight - marginItem*2; } - weatherWidget.AddText(precToday.c_str(), false, cRect(left, 0 + (fontHeight/2 - fontTempSml->Height()/2), 0, 0), Theme.Color(clrChannelFontEpg), Config.decorBorderChannelBg, fontTempSml); + weatherWidget.AddText(precToday.c_str(), false, cRect(left, 0 + (fontHeight/2 - fontTempSml->Height()/2), 0, 0), Theme.Color(clrChannelFontEpg), Theme.Color(clrItemCurrentBg), fontTempSml); left += fontTempSml->Width(precToday.c_str()) + marginItem*4; weatherWidget.AddRect(cRect(left - marginItem*2, 0, wWidth - left + marginItem*2, fontHeight), Theme.Color(clrChannelBg)); diff --git a/icons/default/widgets/rain.png b/icons/default/widgets/rain.png Binary files differindex 1d99ae00..82750032 100644 --- a/icons/default/widgets/rain.png +++ b/icons/default/widgets/rain.png diff --git a/icons/default/widgets/sleet.png b/icons/default/widgets/sleet.png Binary files differindex de3761bc..1d99ae00 100644 --- a/icons/default/widgets/sleet.png +++ b/icons/default/widgets/sleet.png diff --git a/widgets/weather/update_weather.config b/widgets/weather/update_weather.config index 4a749212..f799c6d3 100644 --- a/widgets/weather/update_weather.config +++ b/widgets/weather/update_weather.config @@ -9,6 +9,8 @@ Units = "si" DegreeSign = "°C" # Can be set to 'en', 'de', 'pl', 'es', 'fr', 'it', 'tet' or 'x-pig-latin' (see forecast.io API); default is 'en' Lang = "de" +# convert . to , for german format +ConvertPoint2Comma = 1 # We have only 1000 api calls per day, so please only do one update per day! # Or request an own key for free at forecast.io ApiKey = "137f2d85a1f1db5762e5e073103541d2" diff --git a/widgets/weather/update_weather.php b/widgets/weather/update_weather.php index 800f3f7b..a35e89f4 100644 --- a/widgets/weather/update_weather.php +++ b/widgets/weather/update_weather.php @@ -8,6 +8,7 @@ $locationSkin = $ini_array['LocationSkin']; $units = $ini_array['Units']; $degree_sign = $ini_array['DegreeSign']; $lang = $ini_array['Lang']; +$convertPoint = $ini_array['ConvertPoint2Comma']; $api_key = $ini_array['ApiKey']; include('lib/forecast.io.php'); @@ -24,6 +25,8 @@ if( !$handle = fopen("weather.0.temp", "w") ) { continue; } $temp = round($condition->getTemperature(), 1); +if( $convertPoint == 1 ) + $temp = str_replace(".", ",", $temp); fwrite($handle, $temp); fwrite($handle, $degree_sign); fclose($handle); @@ -57,6 +60,8 @@ foreach($conditions_week as $conditions) { } // we only have min & max so we must calc $temp = round($conditions->getMinTemperature(), 1); + if( $convertPoint == 1 ) + $temp = str_replace(".", ",", $temp); fwrite($handle, $temp); fwrite($handle, $degree_sign); fclose($handle); @@ -66,6 +71,8 @@ foreach($conditions_week as $conditions) { continue; } // we only have min & max so we must calc + if( $convertPoint == 1 ) + $temp = str_replace(".", ",", $temp); $temp = round($conditions->getMaxTemperature(), 1); fwrite($handle, $temp); fwrite($handle, $degree_sign); |