Exemplo n.º 1
0
	ResDB_p LoadStdWidgets( const char * pImagePath, const SurfaceFactory_p& pFactory )
	{
		const int HSLIDER_BTN_OFS 		= 1;
		const int VSLIDER_BTN_OFS 		= HSLIDER_BTN_OFS + 19;
		const int SLIDER_OFS 			= VSLIDER_BTN_OFS + 19;
		const int SLIDER_BACK_OFS		= SLIDER_OFS + 10;
		const int RESIZE_BUTTON_OFS 	= SLIDER_BACK_OFS + 13;
		const int CHECKBOX_OFS 			= RESIZE_BUTTON_OFS + 22;
		const int RADIOBUTTON_OFS 		= CHECKBOX_OFS + 13;
		const int BUTTON_OFS			= RADIOBUTTON_OFS + 13;
		const int PLATE_OFS				= BUTTON_OFS + 10;
		const int SPLITS_AND_FRAME_OFS	= PLATE_OFS + 10;
		const int COMBOBOX_OFS			= SPLITS_AND_FRAME_OFS + 10;
		const int LISTENTRY_OFS			= COMBOBOX_OFS + 35;
		const int SORT_ARROW_OFS		= LISTENTRY_OFS + 9;
		const int SMILEY_OFS			= SORT_ARROW_OFS + 8;
		const int TILES_OFS				= 256+192;

		Surface_p pSurface = loadSurface( pImagePath, pFactory );
		if( !pSurface )
			return 0;

		BlockSkin_p	pHScrollbarBwdButtonSkin = BlockSkin::createClickable( pSurface, Size(17,17), Coord(1,HSLIDER_BTN_OFS), Size(19,0), Border(3) );
		pHScrollbarBwdButtonSkin->setContentPadding(Border(4));

		BlockSkin_p	pHScrollbarFwdButtonSkin = BlockSkin::createClickable( pSurface, Size(17,17), Coord(77,HSLIDER_BTN_OFS), Size(19,0), Border(3) );
		pHScrollbarFwdButtonSkin->setContentPadding(Border(4));

		BlockSkin_p	pVScrollbarBwdButtonSkin = BlockSkin::createClickable( pSurface, Size(17,17), Coord(1,VSLIDER_BTN_OFS), Size(19,0), Border(3) );
		pVScrollbarBwdButtonSkin->setContentPadding(Border(4));

		BlockSkin_p	pVScrollbarFwdButtonSkin = BlockSkin::createClickable( pSurface, Size(17,17), Coord(77,VSLIDER_BTN_OFS), Size(19,0), Border(3) );
		pVScrollbarFwdButtonSkin->setContentPadding(Border(4));

		BlockSkin_p	pScrollbarHandleSkin = BlockSkin::createClickable( pSurface, Size(8,8), Coord(1,SLIDER_OFS), Size(10,0), Border(2) );
		pScrollbarHandleSkin->setContentPadding(Border(3));

		BlockSkin_p	pScrollbarBackSkin = BlockSkin::createStatic( pSurface, Rect(1,SLIDER_BACK_OFS,5,5), Border(2) );
		pScrollbarBackSkin->setContentPadding(Border(2));

//		WgBlocksetPtr pResizeButtonBlocks = WgBlockset::CreateFromRow(pSurface, Rect(1,RESIZE_BUTTON_OFS,86,20), 4, 2, WG_OPAQUE);
//		pResizeButtonBlocks->setFrame(Border(3));

		BlockSkin_p	pCheckboxIconSkin = BlockSkin::createClickSelectableWidget( pSurface, Size(11,11), Coord(1,CHECKBOX_OFS), Size(13,0), Border(2) );
		pCheckboxIconSkin->setContentPadding(Border(3));

		BlockSkin_p	pRadiobuttonIconSkin = BlockSkin::createClickSelectableWidget( pSurface, Size(11,11), Coord(1,RADIOBUTTON_OFS), Size(13,0) );
		pRadiobuttonIconSkin->setContentPadding(Border(3));

		BlockSkin_p pButtonSkin = BlockSkin::createClickable( pSurface, Size(8,8), Coord(1,BUTTON_OFS), Size(10,0), Border(3) );
		pButtonSkin->setContentPadding(Border(4));
		pButtonSkin->setContentShift( StateEnum::Pressed, Coord(2,2) );

		BlockSkin_p pHSplitSkin = BlockSkin::createStatic(pSurface, Rect(1,SPLITS_AND_FRAME_OFS,8,2), Border(0) );

		BlockSkin_p pVSplitBlocks = BlockSkin::createStatic(pSurface, Rect(11,SPLITS_AND_FRAME_OFS,2,8), Border(0) );

		BlockSkin_p pFrameSkin = BlockSkin::createClickable( pSurface, Size(8,8), Coord(1, SPLITS_AND_FRAME_OFS), Size(10,0), Border(2) );
		pFrameSkin->setContentPadding(Border(3));

//		WgBlocksetPtr pComboboxBlocks = WgBlockset::CreateFromRow(pSurface, Rect(1,COMBOBOX_OFS,98,20), 4, 2, WG_OPAQUE);
//		pComboboxBlocks->setFrame(Border(1,1,20,1));
//		pComboboxBlocks->setPadding(Border(2,2,21,2));

		BlockSkin_p pListEntrySkin = BlockSkin::createClickSelectable( pSurface, Size(8,6), Coord(1,LISTENTRY_OFS), Size(10,0), Border(1) );
		pListEntrySkin->setContentPadding(Border(4));

		BlockSkin_p pSortArrowSkin = BlockSkin::createClickSelectable( pSurface, Size(11,6), Coord(1,SORT_ARROW_OFS), Size(13,0), Border(0) );

		BlockSkin_p pSmileyIconSkin = BlockSkin::createClickSelectable( pSurface, Size(12,12), Coord(1, SMILEY_OFS), Size(14,0), Border(0) );


		BlockSkin_p pBgCheckeredGreySkin = BlockSkin::createStatic( pSurface, Rect(0,TILES_OFS,64,64) );
		pBgCheckeredGreySkin->setTiledCenter(true);
		pBgCheckeredGreySkin->optimizeRenderMethods();

		BlockSkin_p pBgBlueGradientSkin = BlockSkin::createStatic( pSurface, Rect(1*64,TILES_OFS,64,64) );
		pBgBlueGradientSkin->optimizeRenderMethods();


//		ColorsetPtr pSelectionColors = Colorset::create( Color(0x0), Color(0x40FFFFFF), Color(0x80FFFFFF), Color(0x40000000), Color(0x0) );

		BlockSkin_p pPlateSkin = BlockSkin::createClickable( pSurface, Size(8,8), Coord(1,PLATE_OFS), Size(10,0), Border(3) );
		pPlateSkin->setContentPadding(Border(4));
		pPlateSkin->optimizeRenderMethods();

		ResDB_p pDB = ResDB::create();

		pDB->addSkin( "listentry", pListEntrySkin );
		pDB->addSkin( "plate", pPlateSkin );
		pDB->addSkin( "sortarrow", pSortArrowSkin );
		pDB->addSkin( "smiley", pSmileyIconSkin );

		// Create standard button

		Button_p pButton = Button::create();
		pButton->setSkin( pButtonSkin );
		pDB->addWidget( "button", pButton );

		// Create standard plate

		Image_p pPlate = Image::create();
		pPlate->setSkin( pPlateSkin );
		pDB->addWidget( "plate", pPlate );

		// Create standard checkbox

		CheckBoxPtr pCheckbox = CheckBox::create();
		pCheckbox->Icon()->set( pCheckboxIconSkin );
		pDB->addWidget( "checkbox", pCheckbox );

		// Create standard radiobutton

		RadioButtonPtr pRadiobutton = RadioButton::create();
		pRadiobutton->Icon()->set( pRadiobuttonIconSkin );
		pDB->addWidget( "radiobutton", pRadiobutton );

		// Create standard horizontal scrollbar

		Scrollbar_p pHScrollbar = Scrollbar::create();
		pHScrollbar->setSkins( pScrollbarBackSkin, pScrollbarHandleSkin, pHScrollbarBwdButtonSkin, pHScrollbarFwdButtonSkin );
		pDB->addWidget( "hscrollbar", pHScrollbar );

		// Create standard vertical scrollbar

		Scrollbar_p pVScrollbar = Scrollbar::create();
		pVScrollbar->setSkins( pScrollbarBackSkin, pScrollbarHandleSkin, pVScrollbarBwdButtonSkin, pVScrollbarFwdButtonSkin );
		pDB->addWidget( "vscrollbar", pVScrollbar );

		// Create standard menubar
/*
		Menubar * pMenubar = new Menubar();
		pMenubar->SetBgSource( pPlateBlocks );
		pDB->addWidget( "menubar", pMenubar );
*/
		// Create Background bitmaps

		Image_p pBgCheckeredGrey = Image::create();
		pBgCheckeredGrey->setSkin( pBgCheckeredGreySkin );
		pDB->addWidget( "bg_checkered_grey", pBgCheckeredGrey );

		Image_p pBgBlueGradient = Image::create();
		pBgBlueGradient->setSkin( pBgBlueGradientSkin );
		pDB->addWidget( "bg_blue_gradient", pBgBlueGradient );

		// Create standard menu

		Menu_p pMenu = Menu::create();
		pMenu->setSkin( pPlateSkin, 16, 16 );
		pMenu->setSeparatorSkin( pHSplitSkin, Border(1) );
		pMenu->setCheckBoxSkin( pCheckboxIconSkin );
		pMenu->setRadioButtonSkin( pRadiobuttonIconSkin );
		pMenu->setScrollbarSkins( pScrollbarBackSkin, pScrollbarHandleSkin, pVScrollbarBwdButtonSkin, pVScrollbarFwdButtonSkin );
		pMenu->setEntrySkin( pPlateSkin );
		pDB->addWidget( "menu", pMenu );

		// Create standard combobox
/*
		Combobox * pCombobox = new Combobox();
		pCombobox->SetSource( pComboboxBlocks );
		pDB->addWidget( "combobox", pCombobox );
*/
		// Create standard view

		{
			ScrollPanel_p pView = ScrollPanel::create();

			Widget_p pHScrollbar = pDB->cloneWidget( "hscrollbar" );
			Widget_p pVScrollbar = pDB->cloneWidget( "vscrollbar" );

			if( pHScrollbar )
			{
				Scrollbar_p pH = Scrollbar::cast(pHScrollbar);
				pView->setHorizontalScrollbar( pH );
			}
			if( pVScrollbar )
			{
				Scrollbar_p pV = Scrollbar::cast(pVScrollbar);
				pView->setVerticalScrollbar( pV );
			}
			pView->setSkin( pBgCheckeredGreySkin );
			pView->setCornerSkin( pPlateSkin );
			pDB->addWidget( "view", pView );
		}

		return pDB;
	}
Exemplo n.º 2
0
int main ( int argc, char** argv )
{
	//------------------------------------------------------
	// Init SDL
	//------------------------------------------------------

	SDL_Init(SDL_INIT_VIDEO);

	int posX = 100, posY = 100, width = 320, height = 240;
	SDL_Window * pWin = SDL_CreateWindow("Hello WonderGUI", posX, posY, width, height, 0);

	SDL_Surface * pWinSurf = SDL_GetWindowSurface( pWin );

	IMG_Init( IMG_INIT_JPG | IMG_INIT_PNG );

	//------------------------------------------------------
	// Init WonderGUI
	//------------------------------------------------------

	Base::init();

	InputHandler_p pInput = InputHandler::create();
	pDebug = pInput.rawPtr();
	
	WgPixelType type = WG_PIXEL_UNKNOWN;

	if( pWinSurf->format->BitsPerPixel == 32 )
		type = WG_PIXEL_ARGB_8;
	else if( pWinSurf->format->BitsPerPixel == 24 )
		type = WG_PIXEL_RGB_8;
		
	SoftSurface_p pCanvas = SoftSurface::create( Size(pWinSurf->w,pWinSurf->h), type, (unsigned char*) pWinSurf->pixels, pWinSurf->pitch, 0 );

	SoftGfxDevice_p pGfxDevice = SoftGfxDevice::create( pCanvas );

	RootPanel_p pRoot = RootPanel::create( pGfxDevice );
	Base::msgRouter()->setRoot(pRoot);

	// 
	
	MsgLogger_p pLogger = MsgLogger::create( std::cout );
	pLogger->ignoreAllMsgs();
	pLogger->logMouseMsgs();
	
	Base::msgRouter()->broadcastTo( pLogger );


	// Init font
	
	SDL_Surface * pFontSurf = IMG_Load( "../../../resources/anuvverbubbla_8x8.png" );
	Blob_p pFontSurfBlob = Blob::create( pFontSurf, freeSDLSurfCallback );
	SoftSurface_p pFontImg = SoftSurface::create( Size(pFontSurf->w,pFontSurf->h), WG_PIXEL_ARGB_8, (unsigned char*) pFontSurf->pixels, pFontSurf->pitch, pFontSurfBlob );
		
	char * pFontSpec = (char*) loadFile( "../../../resources/anuvverbubbla_8x8.fnt" );

	BitmapGlyphs_p pGlyphs = BitmapGlyphs::create( pFontImg, pFontSpec );
	Font_p pFont = Font::create( pGlyphs, 8 );

	Textprop prop;
	prop.setFont(pFont);
	prop.setSize(8);
	Textprop_p pProp = prop.reg();

	Base::setDefaultTextprop( pProp );

	TextStyle_p pStyle = TextStyle::create();
	pStyle->setFont(pFont);
	pStyle->setSize(8);
	Base::setDefaultStyle(pStyle);

	// Init skins

	SDL_Surface * pSDLSurf = IMG_Load( "../../../resources/simple_button.bmp" );
	SoftSurface_p pButtonSurface = SoftSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), WG_PIXEL_RGB_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, 0 );
	BlockSkin_p pSimpleButtonSkin = BlockSkin::createClickableFromSurface( pButtonSurface, 0, Border(3) );
	pSimpleButtonSkin->setContentPadding( Border(5) );

	pSDLSurf = IMG_Load( "../../../resources/state_button.bmp" );
	SoftSurface_p pStateButtonSurface = SoftSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), WG_PIXEL_RGB_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, 0 );
	BlockSkin_p pStateButtonSkin = BlockSkin::createClickSelectableFromSurface( pStateButtonSurface, 0, Border(3) );
	pStateButtonSkin->setContentPadding( Border(5) );

	pSDLSurf = IMG_Load( "../../../resources/grey_pressable_plate.bmp" );
	SoftSurface_p pPressablePlateSurface = SoftSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), WG_PIXEL_RGB_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, 0 );
	Skin_p pPressablePlateSkin = BlockSkin::createClickableFromSurface( pPressablePlateSurface, 0, Border(3) );
	
	pSDLSurf = IMG_Load( "../../../resources/list_entry.png" );
	SoftSurface_p pListEntrySurface = SoftSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), WG_PIXEL_RGB_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, 0 );
	Skin_p pListEntrySkin = BlockSkin::createClickableFromSurface( pListEntrySurface, 0, Border(3) );

	//------------------------------------------------------
	// Setup a simple GUI consisting of a filled background and 
	// a button using scaled bitmaps.
	//------------------------------------------------------

	FlexPanel_p pFlexPanel = FlexPanel::create();
	pFlexPanel->setSkin( ColorSkin::create(Color::burlywood));
	pRoot->setWidget(pFlexPanel);


/*	Filler_p pBackground = Filler::create();
	pBackground->setSkin( ColorSkin::create(Color::aqua) );
	pFlexPanel->addWidget(pBackground, WG_NORTHWEST, Coord(), WG_SOUTHEAST, Coord());
*/

	Image_p pImage = Image::create();
	pImage->setSkin( pSimpleButtonSkin );
	pFlexPanel->addWidget( pImage, Rect(0,0,80,33), WG_CENTER );


//	pRoot->msgRouter()->AddCallback( MsgFilter::select(), pButton, myButtonClickCallback );


	// Test transparency issue
	
	{
		FlexPanel_p pExtraFlex = FlexPanel::create();
		pExtraFlex->setSkin( ColorSkin::create( Color(0,0,0,128)));

		TextDisplay_p pText = TextDisplay::create();
		pText->text.set( "THIS IS SOME TEST TEXT" );
		
		pExtraFlex->addWidget( pText, Rect( 10,10,100,100) );

		addResizablePanel( pFlexPanel, pExtraFlex, Base::msgRouter() );
	}



/*
	SizeCapsule_p pCapsule = SizeCapsule::create();
	pCapsule->setMaxSize( Size(100,1000));
	pFlexPanel->addWidget( pCapsule );

	StackPanel_p pStack = StackPanel::create();
	pCapsule->setWidget( pStack );


	TextDisplay_p pText = TextDisplay::create();
	pText->text()->set( "THIS IS THE LONG TEXT THAT SHOULD WRAP AND BE FULLY DISPLAYED." );
	pStack->addWidget(pText);
*/
	
/*
	CheckBoxPtr pCheckbox = CheckBox::create();
	pCheckbox->Label()->set( "CHECKBOX" );
	pCheckbox->Icon()->set( pCheckboxSkin );
*/

/*
	ToggleGroup_p pGroup = ToggleGroup::create();
	

	for( int i = 0 ; i < 4 ; i++ )
	{
		ToggleButton_p pCheckbox = ToggleButton::create();
		pCheckbox->label.set( "CHECKBOX" );
		pCheckbox->setSkin( pStateButtonSkin );
		pFlexPanel->addWidget( pCheckbox, Coord(10,20*i) );
		pGroup->add( pCheckbox );
	}
*/

/*
	TextDisplay_p pText = TextDisplay::create();
	pText->text.set( "THIS IS THE TEXT\nLINE TWO.\nAN EXTRA LONG LONG LONG LINE TO TEST THE CLIPPING AND RAND BEHAVIOURS." );
	pFlexPanel->addWidget( pText, WG_NORTHWEST, WG_EAST );
	

	StandardPresenter_p pPresenter = StandardPresenter::create();
	pPresenter->setAlignment( WG_CENTER );
	pText->text.setPresenter( pPresenter );


	ValueDisplay_p pValue = ValueDisplay::create();
	pValue->value.setFormatter( TimeFormatter::create("%2H:%2M:%2S"));
	pValue->value.set(3600+60+12);
	pValue->value.setPresenter( pPresenter );
	pFlexPanel->addWidget( pValue, WG_WEST, WG_SOUTHEAST );
*/

	//------------------------------------------------------
	// Program Main Loop
	//------------------------------------------------------

	while( !bQuit ) 
	{
		translateEvents( pInput, pRoot );

		SDL_LockSurface(pWinSurf);
		pRoot->render();
		SDL_UnlockSurface(pWinSurf);

		updateWindowRects( pRoot, pWin );

		SDL_Delay(20);
    }

	// Exit WonderGUI

	Base::exit();

	// Exit SDL

	IMG_Quit();
	SDL_Quit();

    return 0;
}
Exemplo n.º 3
0
int main ( int argc, char** argv )
{ 
	//------------------------------------------------------
	// Init SDL
	//------------------------------------------------------

	SDL_Init(SDL_INIT_VIDEO);

	int posX = 100, posY = 100, width = 400, height = 400;
	SDL_Window * pWin = SDL_CreateWindow("Hello WonderGUI", posX, posY, width, height, SDL_WINDOW_OPENGL);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(  SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(  SDL_GL_CONTEXT_MINOR_VERSION, 3);
    SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 0 );
    
    SDL_GLContext context = SDL_GL_CreateContext( pWin );

#ifdef WIN32  
	glewExperimental = GL_TRUE;
	GLenum err = glewInit();
#endif

	IMG_Init( IMG_INIT_JPG | IMG_INIT_PNG );

	//------------------------------------------------------
	// Init WonderGUI
	//------------------------------------------------------

	Base::init();
//	Base::initFreeType();
//	VectorFont::setSurfaceFactory( GlSurfaceFactory::create() );

	InputHandler_p pInput = Base::inputHandler();
	
	pInput->mapKey( SDLK_LEFT, Key::Left );
	pInput->mapKey( SDLK_RIGHT, Key::Right );
	pInput->mapKey( SDLK_UP, Key::Up );
	pInput->mapKey( SDLK_DOWN, Key::Down );
	pInput->mapKey( SDLK_BACKSPACE, Key::Backspace );
	pInput->mapKey( SDLK_DELETE, Key::Delete );
	pInput->mapKey( SDLK_END, Key::End );
	pInput->mapKey( SDLK_ESCAPE, Key::Escape );
	pInput->mapKey( SDLK_HOME, Key::Home );
	pInput->mapKey( SDLK_PAGEDOWN, Key::PageDown );
	pInput->mapKey( SDLK_PAGEUP, Key::PageUp );
	pInput->mapKey( SDLK_RETURN, Key::Return );
	pInput->mapKey( SDLK_SPACE, Key::Space );
	pInput->mapKey( SDLK_TAB, Key::Tab );
	pInput->mapKey( SDLK_F1, Key::F1 );
	pInput->mapKey( SDLK_F2, Key::F2 );
	pInput->mapKey( SDLK_F3, Key::F3 );
	pInput->mapKey( SDLK_F4, Key::F4 );
	pInput->mapKey( SDLK_F5, Key::F5 );
	pInput->mapKey( SDLK_F6, Key::F6 );
	pInput->mapKey( SDLK_F7, Key::F7 );
	pInput->mapKey( SDLK_F8, Key::F8 );
	pInput->mapKey( SDLK_F9, Key::F9 );
	pInput->mapKey( SDLK_F10, Key::F10 );
	pInput->mapKey( SDLK_F11, Key::F11 );
	pInput->mapKey( SDLK_F12, Key::F12 );
	
	
	pInput->mapKey( SDLK_LCTRL, Key::Control );
	pInput->mapKey( SDLK_RCTRL, Key::Control );

	pInput->mapKey( SDLK_LSHIFT, Key::Shift );
	pInput->mapKey( SDLK_RSHIFT, Key::Shift );

	pInput->mapKey( SDLK_LALT, Key::Alt );
	pInput->mapKey( SDLK_RALT, Key::Alt );
	
	pInput->mapKey( SDLK_KP_ENTER, Key::Return );
	
	
	pInput->mapCommand( SDLK_ESCAPE, MODKEY_NONE, EditCmd::Escape );

	pInput->mapCommand( SDLK_x, MODKEY_CTRL, EditCmd::Cut );
	pInput->mapCommand( SDLK_c, MODKEY_CTRL, EditCmd::Copy );
	pInput->mapCommand( SDLK_v, MODKEY_CTRL, EditCmd::Paste );

	pInput->mapCommand( SDLK_a, MODKEY_CTRL, EditCmd::SelectAll );
	
	pInput->mapCommand( SDLK_z, MODKEY_CTRL, EditCmd::Undo );
	pInput->mapCommand( SDLK_z, MODKEY_CTRL_SHIFT, EditCmd::Redo );

	

	GlGfxDevice_p pGfxDevice = GlGfxDevice::create( Size(width,height) );

	RootPanel_p pRoot = RootPanel::create( pGfxDevice );
	
	Base::inputHandler()->setFocusedWindow( pRoot );

	// 
	
	MsgLogger_p pLogger = MsgLogger::create( std::cout );
	pLogger->logAllMsgs();
	pLogger->ignoreMsg( MsgType::Tick );
	
	Base::msgRouter()->broadcastTo( pLogger );


	// Init font

	char * pFontSpec = (char*)loadFile("../resources/anuvverbubbla_8x8.fnt");

    assert( glGetError() == 0 );

    
	SDL_Surface * pFontSurf = IMG_Load( "../resources/anuvverbubbla_8x8.png" );
	GlSurface_p pFontImg = GlSurface::create( Size(pFontSurf->w,pFontSurf->h), PixelType::BGRA_8, (uint8_t*) pFontSurf->pixels, pFontSurf->pitch );
	SDL_FreeSurface( pFontSurf );
    assert( glGetError() == 0 );
	BitmapFont_p pBmpFont = BitmapFont::create( pFontImg, pFontSpec );
    assert( glGetError() == 0 );

//	Blob_p pFontFile = loadBlob("../resources/DroidSans.ttf");
	
//	VectorFont_p pFont = VectorFont::create( pFontFile, 1 );


	TextStyle_p pStyle = TextStyle::create();
	pStyle->setFont(pBmpFont);
	pStyle->setSize(10);
	Base::setDefaultStyle(pStyle);

	// Init skins

	PixelFormat	format;

	SDL_Surface * pSDLSurf = IMG_Load( "../resources/simple_button.bmp" );
	convertSDLFormat( &format, pSDLSurf->format );
	GlSurface_p pButtonSurface = GlSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), PixelType::BGR_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, &format );
	SDL_FreeSurface( pSDLSurf );
	BlockSkin_p pSimpleButtonSkin = BlockSkin::createClickableFromSurface( pButtonSurface, 0, Border(3) );
	pSimpleButtonSkin->setContentPadding( Border(5) );

	pSDLSurf = IMG_Load( "../resources/state_button.bmp" );
	convertSDLFormat( &format, pSDLSurf->format );
	GlSurface_p pStateButtonSurface = GlSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), PixelType::BGR_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, &format );
	SDL_FreeSurface( pSDLSurf );
	BlockSkin_p pStateButtonSkin = BlockSkin::createClickSelectableFromSurface( pStateButtonSurface, 0, Border(3) );
	pStateButtonSkin->setContentPadding( Border(5) );
    
	pSDLSurf = IMG_Load( "../resources/grey_pressable_plate.bmp" );
	convertSDLFormat( &format, pSDLSurf->format );
	GlSurface_p pPressablePlateSurface = GlSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), PixelType::BGR_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, &format );
	SDL_FreeSurface( pSDLSurf );
	BlockSkin_p pPressablePlateSkin = BlockSkin::createClickableFromSurface( pPressablePlateSurface, 0, Border(3) );
	pPressablePlateSkin->setContentPadding( Border(3) );
    
	pSDLSurf = IMG_Load( "../resources/list_entry.png" );
	convertSDLFormat( &format, pSDLSurf->format );
	GlSurface_p pListEntrySurface = GlSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), PixelType::BGR_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, &format );
	SDL_FreeSurface( pSDLSurf );
	Skin_p pListEntrySkin = BlockSkin::createClickableFromSurface( pListEntrySurface, 0, Border(3) );
    
	pSDLSurf = IMG_Load( "../resources/frog.jpg" );
	convertSDLFormat( &format, pSDLSurf->format );
	GlSurface_p pImgSurface = GlSurface::create( Size( pSDLSurf->w, pSDLSurf->h ), PixelType::BGR_8, (unsigned char*) pSDLSurf->pixels, pSDLSurf->pitch, &format );
	SDL_FreeSurface( pSDLSurf );
	BlockSkin_p pImgSkin = BlockSkin::createStaticFromSurface( pImgSurface, Border(3) );

	//------------------------------------------------------
	// Setup a simple GUI consisting of a filled background and 
	// a button using scaled bitmaps.
	//------------------------------------------------------

	FlexPanel_p pFlexPanel = FlexPanel::create();
	pFlexPanel->setSkin( pImgSkin  );
	pRoot->setWidget(pFlexPanel);



	Image_p pImage = Image::create();
	pImage->setSkin( pSimpleButtonSkin );
	pFlexPanel->addWidget( pImage, Rect(0,0,80,33), Origo::Center );


//	pRoot->msgRouter()->AddCallback( MsgFilter::select(), pButton, myButtonClickCallback );


	// Test transparency issue



	{
		PackPanel_p pVert = PackPanel::create();
		PackPanel_p pHorr = PackPanel::create();
		
		Filler_p pFillerEast = Filler::create();
		Filler_p pFillerSouth = Filler::create();
		
		pFillerEast->setSkin( pPressablePlateSkin );
		pFillerSouth->setSkin( pPressablePlateSkin );
		
		pVert->setOrientation( Orientation::Vertical );
		
		pVert->addWidget( pHorr );
		pVert->addWidget( pFillerSouth );

		TextEditor_p pText = TextEditor::create();
		pText->setSkin( ColorSkin::create( Color::Black ) );
		
		
		TextStyle_p pBig = TextStyle::create();
		pBig->setSize( 16 );
		
		TextStyle_p pRed = TextStyle::create();
		pRed->setColor( Color::Red );
		pRed->setSize( 25 );

		TextStyle_p pAnuv = TextStyle::create();
		pAnuv->setFont( pBmpFont );

		TextStyle_p pLink = TextStyle::create();
		pLink->setColor(Color::Green );
		pLink->setLink( TextLink::create( "www.somewhere.net" ) );

		pText->text.set( "This is a\npiece of TEXT with LINK" );
		pText->text.setCharStyle( pBig, 5, 2 );
		pText->text.setCharStyle( pRed, 10, 3 );
		pText->text.setCharStyle( pAnuv, 19, 4 );
		pText->text.setCharStyle( pLink, 29, 4 );


		pHorr->addWidget( pText );
		pHorr->addWidget( pFillerEast );

		
//		pFlexPanel->addWidget( pVert, Origo::NorthWest, Origo::SouthEast );
	
		pText->grabFocus();
    }


	{
		Image_p pImage = Image::create();
		pImage->setImage( generateTestSurface() );
        pFlexPanel->addWidget( pImage, Origo::NorthWest, Origo::SouthEast, Border(20) );
	}


/*
    {
        TestWidget_p pTest = TestWidget::create();
        pFlexPanel->addWidget( pTest, Origo::NorthWest, Origo::SouthEast, Border(20) );
        pTest->start();
    }
*/

/*	
	{
		FlexPanel_p pExtraFlex = FlexPanel::create();
		pExtraFlex->setSkin( ColorSkin::create( Color(0,0,0,128)));

		TextEditor_p pText = TextEditor::create();
		
		TextStyle_p pBig = TextStyle::create();
		pBig->setSize( 16 );
		
		TextStyle_p pRed = TextStyle::create();
		pRed->setColor( Color::Red );
		pRed->setSize( 25 );

		TextStyle_p pAnuv = TextStyle::create();
		pAnuv->setFont( pBmpFont );

		pText->text.set( "This is a\npiece of TEXT" );
		pText->text.setCharStyle( pBig, 5, 2 );
		pText->text.setCharStyle( pRed, 10, 3 );
		pText->text.setCharStyle( pAnuv, 19, 20 );
		
		pExtraFlex->addWidget( pText, Rect( 10,10,100,100) );

		addResizablePanel( pFlexPanel, pExtraFlex, Base::msgRouter() );

		pText->grabFocus();

		translateEvents( pInput, pRoot );

		pText->text.caretTextBegin();
		pText->text.caretLineEnd();
	}
*/
/*
	{
		VolumeMeter_p p = VolumeMeter::create();
		
		p->setSkin( pPressablePlateSkin );
		
		addResizablePanel( pFlexPanel, p, Base::msgRouter() );
	}
*/


/*
	SizeCapsule_p pCapsule = SizeCapsule::create();
	pCapsule->setMaxSize( Size(100,1000));
	pFlexPanel->addWidget( pCapsule );

	StackPanel_p pStack = StackPanel::create();
	pCapsule->setWidget( pStack );


	TextDisplay_p pText = TextDisplay::create();
	pText->text()->set( "THIS IS THE LONG TEXT THAT SHOULD WRAP AND BE FULLY DISPLAYED." );
	pStack->addWidget(pText);
*/
	
/*
	CheckBoxPtr pCheckbox = CheckBox::create();
	pCheckbox->Label()->set( "CHECKBOX" );
	pCheckbox->Icon()->set( pCheckboxSkin );
*/

/*
	ToggleGroup_p pGroup = ToggleGroup::create();
	

	for( int i = 0 ; i < 4 ; i++ )
	{
		ToggleButton_p pCheckbox = ToggleButton::create();
		pCheckbox->label.set( "CHECKBOX" );
		pCheckbox->setSkin( pStateButtonSkin );
		pFlexPanel->addWidget( pCheckbox, Coord(10,20*i) );
		pGroup->add( pCheckbox );
	}
*/

/*
	TextDisplay_p pText = TextDisplay::create();
	pText->text.set( "THIS IS THE TEXT\nLINE TWO.\nAN EXTRA LONG LONG LONG LINE TO TEST THE CLIPPING AND RAND BEHAVIOURS." );
	pFlexPanel->addWidget( pText, WG_NORTHWEST, WG_EAST );
	

	StandardPrinter_p pPrinter = StandardPrinter::create();
	pPrinter->setAlignment( WG_CENTER );
	pText->text.setPrinter( pPrinter );


	ValueDisplay_p pValue = ValueDisplay::create();
	pValue->value.setFormatter( TimeFormatter::create("%2H:%2M:%2S"));
	pValue->value.set(3600+60+12);
	pValue->value.setPrinter( pPrinter );
	pFlexPanel->addWidget( pValue, WG_WEST, WG_SOUTHEAST );
*/

/*
	FpsDisplay_p pFps = FpsDisplay::create();
	pFps->setSkin( pPressablePlateSkin );
	pFlexPanel->addWidget( pFps, Coord(0,0), Origo::SouthWest );
*/	

	//------------------------------------------------------
	// Program Main Loop
	//------------------------------------------------------

    int tick = 0;

	/*
		I need the following crap on my Windows dev machine to
		make something that resembles single buffering work :(

		Apparently single buffering in SDL2/Windows doesn't work on my dev machine, 
		so I get double buffering although I specify single buffering when initializing.
		(don't know if it is SDL's, Windows' or crappy device drivers fault, 
		it works fine in SDL2/Linux on same hardware)

		So I render to the front buffer instead, but apparently nothing will be displayed
		until the rendering pipeline has been filled and flushed twice... so we just clear the
		color buffer and flush() to make sure that everything is displayed on first render call.
	*/

	glDrawBuffer(GL_FRONT);
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT );
	glFlush();


	while( !bQuit ) 
	{
		translateEvents( pInput, pRoot );

		pRoot->render();

//		updateWindowRects( pRoot, pWin );

 //       glClearColor(0.1f, 0.3f, 0.3f, 1.0f );
 //       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//		glFlush();

         pGfxDevice->beginRender();

//        pGfxDevice->setTintColor(Color::Red );
        
//        pGfxDevice->fill( Rect(1,1,320-2,400-2), Color::Aquamarine);

        
//       pGfxDevice->wg::GfxDevice::blit( pButtonSurface, 50, 50 );
//        pGfxDevice->wg::GfxDevice::stretchBlit(pButtonSurface, Rect(50,50,160,40));

        

        Color plotColors[400];
        Coord plotCoords[400];
        
        for( int i = 0 ; i < 400 ; i++ )
        {
            plotColors[i] = Color::Red;
            plotCoords[i] = Coord(i,i);
        }
        
        
//       pGfxDevice->clipPlotPixels( Rect(0,0,width,height), 100, plotCoords, plotColors);

        
//        for(int x = 0 ; x < 200 ; x++ )
//        {
//            pGfxDevice->clipDrawVertLine(Rect(0,0,width,height), Coord(x*2,x), 40, Color::Aquamarine);
//        }

        
//        pGfxDevice->clipDrawHorrLine(Rect(10,10,width-20,height-20), Coord(0,20), 800, Color::Aquamarine);
//        pGfxDevice->clipDrawVertLine(Rect(10,10,width-20,height-20), Coord(20,0), 800, Color::Aquamarine);

        
        
//        pGfxDevice->drawLine( Coord(10,10), Coord(200,40), Color::Red, 3.f );
        
//        pGfxDevice->fill(Rect(21, 21, 100, 100 ), Color::AntiqueWhite );
//        pGfxDevice->fillSubPixel(RectF(21.8f, 21.5f, 0.4f, 0.4f ), Color::AntiqueWhite );
        
        pGfxDevice->endRender();
        
		SDL_Delay(20);
        tick++;
    }

	// Exit WonderGUI

	Base::exit();

	// Exit SDL

	IMG_Quit();
	SDL_Quit();

    return 0;
}