#include <util/application.h>
#include <gui/stringview.h>
#include <gui/textview.h>
#include <gui/layoutview.h>
#include <gui/font.h>
#include "fontwin.h"

using namespace os;

FontWin::FontWin( const Rect& cRect )
 : Window( cRect, "FontWin", "Font Example" )
{
    // 1. Create a vertical layout node. This will be our 'root' layout node.

    LayoutNode* pcRootLayout = new VLayoutNode( "pcRootLayout" );

    // 2. Create gadgets for the regions:
    
    TextView*   pcAA = new TextView( Rect(), "pcAA", "Antialiased font!" );
    TextView*   pcNonAA = new TextView( Rect(), "pcNonAA", "Non-antialiased font!" );
    TextView*   pcShear = new TextView( Rect(), "pcShear", "Sheared font!" );
    TextView*   pcRot = new TextView( Rect(), "pcRot", "Rotated font!" );

    os::font_properties fp( "Nimbus Sans L", "Regular", 0, 15.0f, 0.0f, 0.0f );
    fp.m_nFlags |= FPF_SMOOTHED;
    os::Font *f = new os::Font( fp );
    pcAA->SetFont( f );
    f->Release();

    fp.m_nFlags &= ~FPF_SMOOTHED;
    f = new os::Font( fp );
    pcNonAA->SetFont( f );
    f->Release();

    fp.m_nFlags |= FPF_SMOOTHED;
    fp.m_vShear = 16;
    f = new os::Font( fp );
    pcShear->SetFont( f );
    f->Release();

    fp.m_vRotation = 20;
    f = new os::Font( fp );
    pcRot->SetFont( f );
    f->Release();

    // 3. Add them to the LayoutNode:

    pcRootLayout->AddChild( pcAA, 1 );
    pcRootLayout->AddChild( pcNonAA, 1 );
    pcRootLayout->AddChild( pcShear, 1 );
    pcRootLayout->AddChild( pcRot, 1 );

    // 4. Create a LayoutView and attach the root node to it.
    
    LayoutView* pcLayout = new LayoutView( GetBounds(), "pcLayout" );
    pcLayout->SetRoot( pcRootLayout );

    // 5. Finally, add the LayoutView to the Window.

    AddChild( pcLayout ); 
}

FontWin::~FontWin()
{
}
	
bool FontWin::OkToQuit()
{
    Application::GetInstance()->PostMessage( M_QUIT );
    return true;
}
