File source
<?php
class WeatherScreen extends Screen{
protected $id = "weather";
protected $i = 0;
protected $weather;
function __construct($weatherSource){
$this->weather = $weatherSource;
$this->touchPush("return_btn", 0,0,160,160);
}
function activate($params){
if($params["return"]){
$this->returnTo = $params["return"];
}
}
function renderField($title, $img, $data, $top=0){
$black = imagecolorallocate($img, 0, 0, 0);
$white = imagecolorallocate($img, 255, 255, 255);
$w = $data;
imageline($img, 11, $top+49, 160, $top+49, $black);
$icon = @imagecreatefrompng("icons/".$w["icon"].".png");
if($icon){
pasteCenter($img, $icon, 37, $top+24);
imagedestroy($icon);
}
imagettftext($img, 20, 0, 65, $top+30, $black, "./arialbd.ttf", number_format($w["temp"],1)."°C");
imagettftext($img, 8, 0, 60, $top+45, $black, "./arial.ttf", $w["text"]);
imagefilledrectangle($img, 0, $top+1, 10, $top+49, $black);
imagettfcenter($img, 8, 90, 10, $top+25, $white, "./arial.ttf", $title);
}
function render(){
if($this->touched("return_btn") && $this->returnTo){
return $this->screen($this->returnTo);
}
$data = $this->weather->getData();
$img = screen();
$this->renderField("teraz", $img, $data, 0);
$this->renderField("dnes", $img, $this->weather->getData(0), 50);
$this->renderField("zajtra", $img, $this->weather->getData(1), 100);
return $this->image($img);
}
}