File source

<?php
/** Home screen
 - shows date, time
 - weather
 - upcoming calendar events
 - garage door status
*/
class HomeScreen extends Screen{

  protected 
$id "home";
  protected 
$weatherSource;
  protected 
$calendarSource;
  protected 
$garageSource;
  protected 
$lastGarageClosed true;

  function 
__construct($weatherSource$calendarSource$garageSource){
    
$this->weatherSource $weatherSource;
    
$this->calendarSource $calendarSource;
    
$this->garageSource $garageSource;
    
$this->touchPush("weather_btn"0,40,160,50);
  }

  function 
renderAppointment($img$top$day$text){
    
$black imagecolorallocate($img000);
    
$white imagecolorallocate($img255255255);
    
imagefilledrectangle($img0$top40$top+28$black);
    
imagettftext($img802$top+10$white"./arial.ttf"$day);
    
imagettftext($img10,045$top+20$black"./arialbd.ttf"$text);
  }

  function 
render(){
    if(
$this->touched("weather_btn")){
      return 
$this->screen("weather", Array("return"=>"home"));
    }
    
$garage false;

    if(
$this->garageSource){
      
$garage $this->garageSource->getData();
      if(! 
$garage["closed"] && $this->lastGarageClosed){
        
$this->lastGarageClosed false;
        return 
$this->screen("garage", Array("return" => "home"));
      }else{
        
$this->lastGarageClosed $garage["closed"];
      }
    }

    
$img screen();
    
$black imagecolorallocate($img000);
    
$white imagecolorallocate($img255255255);
    
// time
    
imagettfcenter($img200160/225$black"./arialbd.ttf"Date("H:i"));
    
// date
    
imagettfcenter($img80160/235$black"./arial.ttf"Date("d.m.Y"));
    
    
//weather
    
$w  $this->weatherSource->getData();
    
imageline($img04016040$black);
    
$icon imagecreatefrompng("icons/".$w["icon"].".png");
    
pasteCenter($img$icon2564);
    
imagedestroy($icon);
    
imagettftext($img2506070$black"./arialbd.ttf"number_format($w["temp"],1)."°C");
    
imagettftext($img806085$black"./arial.ttf"$w["text"]);
    
    
//appointments
    
imageline($img09016090$black);
    
$data $this->calendarSource->getData(2);
    
$top 90;
    foreach(
$data as $app){
      
$this->renderAppointment($img$top$this->calendarSource->getRelativeDate($app["date"]), $app["text"]);  
      
$top+=30;
    }    

    
//garage door
    
if($this->garageSource){
      if(
$garage["closed"]){
        
$icon imagecreatefrompng("icons/closed-small.png");
        
paste($img$icon135,140);
        
imagedestroy($icon);
      }else{
        
$icon imagecreatefrompng("icons/open-small.png");
        
paste($img$icon135,140);
        
imagedestroy($icon);
      }
    }
    return 
$this->image($img);
  }
}