<?php

require_once 'XmlScreen.php';

class XmlFormattedTextScreen
{

    public function __construct($attributes = array())
    {
        $this->xw = new xmlWriter();
        $this->xw->openMemory();
        $this->xw->setIndent(TRUE);
        $this->xw->startDocument('1.0', 'UTF-8'); // start document

        $this->xw->startElement("FormattedTextScreen");

        foreach ($attributes as $key => $value) {
            $this->xw->writeAttribute($key, $value);
        }
    }

    public function setLine($text, $size = "normal", $align = "left", $color = "black")
    {
        $this->xw->startElement("Line");
        $this->xw->writeAttribute("Size", $size);   //normal/small/double/large
        $this->xw->writeAttribute("Align", $align); //center/left/right
        $this->xw->writeAttribute("Color", $color); //white/black/red/green/brown/blue/magenta/cyan/lightgray /darkgray/lightred/lightgreen/yellow/lightblue/lightmagenta/lightcyan
        $this->xw->text($text);
        $this->xw->endElement();
    }

    public function addButton($index, $label, $URI = "SoftKey:Select")
    {
        $this->xw->startElement("SoftKey");
        $this->xw->writeAttribute("index", $index);
        $this->xw->writeElement("Label", $label);
        $this->xw->writeElement("URI", $URI);
        $this->xw->endElement();
    }

    public function removeDefaultButtons()
    {
        foreach(range(1,4) as $key)
        {
            $this->addButton($key, "", "");
        }
    }
    
    public function printScreen()
    {
        $this->finishDocument();
        echo $this->xw->outputMemory();
    }

    private function finishDocument()
    {
        $this->xw->endElement(); // close node <book>
        $this->xw->endDocument(); // end document
    }
}
