add SoftDemo examples
add example description for all examples (with word-wrap) add the VoronoiFractureDemo, note that the collision are disabled after breaking constraints. add optional GwenOpenGLTest, to make it easier to see Gwen user interface features.
This commit is contained in:
75
test/GwenOpenGLTest/Button.cpp
Normal file
75
test/GwenOpenGLTest/Button.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "UnitTest.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class Button : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( Button, GUnit )
|
||||
{
|
||||
// Normal button
|
||||
Controls::Button* pButtonA = new Controls::Button( this );
|
||||
pButtonA->SetText( L"Event Tester" );
|
||||
pButtonA->onPress.Add( this, &Button::onButtonA );
|
||||
|
||||
{
|
||||
Controls::Button* pButtonA = new Controls::Button( this );
|
||||
pButtonA->SetBounds( 200, 30, 300, 200 );
|
||||
pButtonA->SetText( L"Event Tester" );
|
||||
pButtonA->onPress.Add( this, &Button::onButtonA );
|
||||
}
|
||||
|
||||
// Unicode test
|
||||
Controls::Button* pButtonB = new Controls::Button( this );
|
||||
pButtonB->SetText( L"\u0417\u0430\u043C\u0435\u0436\u043D\u0430\u044F \u043C\u043E\u0432\u0430" );
|
||||
Gwen::Align::PlaceBelow( pButtonB, pButtonA, 10 );
|
||||
|
||||
// Image with text
|
||||
Controls::Button* pButtonC = new Controls::Button( this );
|
||||
pButtonC->SetText( L"Image Button" );
|
||||
pButtonC->SetImage( L"test16.png" );
|
||||
Gwen::Align::PlaceBelow( pButtonC, pButtonB, 10 );
|
||||
|
||||
// Just image
|
||||
Controls::Button* pButtonD = new Controls::Button( this );
|
||||
pButtonD->SetText( L"" );
|
||||
pButtonD->SetImage( L"test16.png" );
|
||||
pButtonD->SetSize( 20, 20 );
|
||||
Gwen::Align::PlaceBelow( pButtonD, pButtonC, 10 );
|
||||
|
||||
// Toggle button
|
||||
Controls::Button* pButtonE = new Controls::Button( this );
|
||||
pButtonE->SetText( L"Toggle Me" );
|
||||
pButtonE->SetIsToggle( true );
|
||||
pButtonE->onToggle.Add( this, &Button::OnToggle );
|
||||
pButtonE->onToggleOn.Add( this, &Button::OnToggleOn );
|
||||
pButtonE->onToggleOff.Add( this, &Button::OnToggleOff );
|
||||
Gwen::Align::PlaceBelow( pButtonE, pButtonD, 10 );
|
||||
}
|
||||
|
||||
void onButtonA( Controls::Base* pControl )
|
||||
{
|
||||
UnitPrint( L"Button Pressed (using 'OnPress' event)" );
|
||||
}
|
||||
|
||||
void OnToggle( Controls::Base* pControl )
|
||||
{
|
||||
UnitPrint( L"Button Toggled (using 'OnToggle' event)" );
|
||||
}
|
||||
|
||||
void OnToggleOn( Controls::Base* pControl )
|
||||
{
|
||||
UnitPrint( L"Button Toggled ON (using 'OnToggleOn' event)" );
|
||||
}
|
||||
|
||||
void OnToggleOff( Controls::Base* pControl )
|
||||
{
|
||||
UnitPrint( L"Button Toggled Off (using 'OnToggleOff' event)" );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( Button, L"Button" );
|
||||
48
test/GwenOpenGLTest/Checkbox.cpp
Normal file
48
test/GwenOpenGLTest/Checkbox.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/CheckBox.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class Checkbox : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( Checkbox, GUnit )
|
||||
{
|
||||
Gwen::Controls::CheckBox* check = new Gwen::Controls::CheckBox( this );
|
||||
check->SetPos( 10, 10 );
|
||||
check->onChecked.Add( this, &Checkbox::OnChecked );
|
||||
check->onUnChecked.Add( this, &Checkbox::OnUnchecked );
|
||||
check->onCheckChanged.Add( this, &Checkbox::OnCheckChanged );
|
||||
|
||||
|
||||
Gwen::Controls::CheckBoxWithLabel* labeled = new Gwen::Controls::CheckBoxWithLabel( this );
|
||||
labeled->SetPos( 10, 10 );
|
||||
labeled->Label()->SetText( "Labeled CheckBox" );
|
||||
labeled->Checkbox()->onChecked.Add( this, &Checkbox::OnChecked );
|
||||
labeled->Checkbox()->onUnChecked.Add( this, &Checkbox::OnUnchecked );
|
||||
labeled->Checkbox()->onCheckChanged.Add( this, &Checkbox::OnCheckChanged );
|
||||
Gwen::Align::PlaceBelow( labeled, check, 10 );
|
||||
|
||||
}
|
||||
|
||||
void OnChecked( Controls::Base* pControl )
|
||||
{
|
||||
UnitPrint( L"Checkbox Checked (using 'OnChecked' event)" );
|
||||
}
|
||||
|
||||
void OnUnchecked( Controls::Base* pControl )
|
||||
{
|
||||
UnitPrint( L"Checkbox Unchecked (using 'OnUnchecked' event)" );
|
||||
}
|
||||
|
||||
void OnCheckChanged( Controls::Base* pControl )
|
||||
{
|
||||
UnitPrint( L"Checkbox CheckChanged (using 'OnCheckChanged' event)" );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( Checkbox, L"Checkbox" );
|
||||
58
test/GwenOpenGLTest/ComboBox.cpp
Normal file
58
test/GwenOpenGLTest/ComboBox.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/ComboBox.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class ComboBox : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( ComboBox, GUnit )
|
||||
{
|
||||
|
||||
{
|
||||
Gwen::Controls::ComboBox* combo = new Gwen::Controls::ComboBox( this );
|
||||
combo->SetKeyboardInputEnabled(true);
|
||||
combo->SetPos( 50, 50 );
|
||||
combo->SetWidth( 200 );
|
||||
|
||||
|
||||
combo->AddItem( L"Option One", "one" );
|
||||
combo->AddItem( L"Number Two", "two" );
|
||||
combo->AddItem( L"Door Three", "three" );
|
||||
combo->AddItem( L"Four Legs", "four" );
|
||||
combo->AddItem( L"Five Birds", "five" );
|
||||
|
||||
combo->onSelection.Add( this, &ComboBox::OnComboSelect );
|
||||
}
|
||||
|
||||
{
|
||||
// Empty..
|
||||
Gwen::Controls::ComboBox* combo = new Gwen::Controls::ComboBox( this );
|
||||
combo->SetPos( 50, 80 );
|
||||
combo->SetWidth( 200 );
|
||||
}
|
||||
|
||||
{
|
||||
// Empty..
|
||||
Gwen::Controls::ComboBox* combo = new Gwen::Controls::ComboBox( this );
|
||||
combo->SetPos( 50, 110 );
|
||||
combo->SetWidth( 200 );
|
||||
|
||||
for (int i=0; i<500; i++ )
|
||||
combo->AddItem( L"Lots Of Options" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnComboSelect( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::ComboBox* combo = (Gwen::Controls::ComboBox*)pControl;
|
||||
|
||||
UnitPrint( Utility::Format( L"Combo Changed: %s", combo->GetSelectedItem()->GetText().c_str() ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( ComboBox, L"ComboBox" );
|
||||
115
test/GwenOpenGLTest/CrossSplitter.cpp
Normal file
115
test/GwenOpenGLTest/CrossSplitter.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/CrossSplitter.h"
|
||||
#include "Gwen/Controls/StatusBar.h"
|
||||
#include "Gwen/Controls/Button.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class CrossSplitter : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( CrossSplitter, GUnit )
|
||||
{
|
||||
|
||||
m_bSplittersVisible = false;
|
||||
m_iCurZoom = 0;
|
||||
|
||||
m_Splitter = new Gwen::Controls::CrossSplitter( this );
|
||||
m_Splitter->SetPos(0, 0);
|
||||
m_Splitter->Dock( Pos::Fill );
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* testButton = new Gwen::Controls::Button( m_Splitter );
|
||||
testButton->SetText( "TOPLEFT");
|
||||
m_Splitter->SetPanel( 0, testButton );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* testButton = new Gwen::Controls::Button( m_Splitter );
|
||||
testButton->SetText( "TOPRIGHT");
|
||||
m_Splitter->SetPanel( 1, testButton );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* testButton = new Gwen::Controls::Button( m_Splitter );
|
||||
testButton->SetText( "BOTTOMRIGHT");
|
||||
m_Splitter->SetPanel( 2, testButton );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* testButton = new Gwen::Controls::Button( m_Splitter );
|
||||
testButton->SetText( "BOTTOMLEFT");
|
||||
m_Splitter->SetPanel( 3, testButton );
|
||||
}
|
||||
|
||||
|
||||
//Status bar to hold unit testing buttons
|
||||
Gwen::Controls::StatusBar* pStatus = new Gwen::Controls::StatusBar( this );
|
||||
pStatus->Dock( Pos::Bottom );
|
||||
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* pButton = new Gwen::Controls::Button( pStatus );
|
||||
pButton->SetText( "Zoom" );
|
||||
pButton->onPress.Add( this, &CrossSplitter::ZoomTest );
|
||||
pStatus->AddControl( pButton, false );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* pButton = new Gwen::Controls::Button( pStatus );
|
||||
pButton->SetText( "UnZoom" );
|
||||
pButton->onPress.Add( this, &CrossSplitter::UnZoomTest );
|
||||
pStatus->AddControl( pButton, false );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* pButton = new Gwen::Controls::Button( pStatus );
|
||||
pButton->SetText( "CenterPanels" );
|
||||
pButton->onPress.Add( this, &CrossSplitter::CenterPanels );
|
||||
pStatus->AddControl( pButton, true );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* pButton = new Gwen::Controls::Button( pStatus );
|
||||
pButton->SetText( "Splitters" );
|
||||
pButton->onPress.Add( this, &CrossSplitter::ToggleSplitters );
|
||||
pStatus->AddControl( pButton, true );
|
||||
}
|
||||
}
|
||||
|
||||
void ZoomTest( Gwen::Controls::Base* pFromPanel )
|
||||
{
|
||||
m_Splitter->Zoom(m_iCurZoom);
|
||||
m_iCurZoom++;
|
||||
if (m_iCurZoom == 4)
|
||||
m_iCurZoom = 0;
|
||||
}
|
||||
|
||||
void UnZoomTest( Gwen::Controls::Base* pFromPanel )
|
||||
{
|
||||
m_Splitter->UnZoom();
|
||||
}
|
||||
|
||||
void CenterPanels( Gwen::Controls::Base* pFromPanel )
|
||||
{
|
||||
m_Splitter->CenterPanels();
|
||||
m_Splitter->UnZoom();
|
||||
}
|
||||
|
||||
void ToggleSplitters( Gwen::Controls::Base* pFromPanel )
|
||||
{
|
||||
m_Splitter->SetSplittersVisible( !m_bSplittersVisible );
|
||||
m_bSplittersVisible = !m_bSplittersVisible;
|
||||
}
|
||||
|
||||
|
||||
bool m_bSplittersVisible;
|
||||
int m_iCurZoom;
|
||||
Controls::CrossSplitter* m_Splitter;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( CrossSplitter, L"CrossSplitter" );
|
||||
21
test/GwenOpenGLTest/GroupBox.cpp
Normal file
21
test/GwenOpenGLTest/GroupBox.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/GroupBox.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class GroupBox2 : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( GroupBox2, GUnit )
|
||||
{
|
||||
Gwen::Controls::GroupBox* pGroup = new Gwen::Controls::GroupBox( this );
|
||||
pGroup->Dock( Pos::Fill );
|
||||
pGroup->SetText( "Group Box" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( GroupBox2, L"GroupBox" );
|
||||
32
test/GwenOpenGLTest/ImagePanel.cpp
Normal file
32
test/GwenOpenGLTest/ImagePanel.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/ImagePanel.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class ImagePanel : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( ImagePanel, GUnit )
|
||||
{
|
||||
// Normal
|
||||
{
|
||||
Controls::ImagePanel* img = new Controls::ImagePanel( this );
|
||||
img->SetImage( L"gwen.png" );
|
||||
img->SetBounds( 10, 10, 100, 100 );
|
||||
}
|
||||
|
||||
// Missing
|
||||
{
|
||||
Controls::ImagePanel* img = new Controls::ImagePanel( this );
|
||||
img->SetImage( L"missingimage.png" );
|
||||
img->SetBounds( 120, 10, 100, 100 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( ImagePanel, L"ImagePanel" );
|
||||
99
test/GwenOpenGLTest/Label.cpp
Normal file
99
test/GwenOpenGLTest/Label.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/Label.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class Label : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( Label, GUnit )
|
||||
{
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( "Garry's Normal Label" );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 10 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Chinese: \u4E45\u6709\u5F52\u5929\u613F \u7EC8\u8FC7\u9B3C\u95E8\u5173" );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 30 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Japanese: \u751F\u3080\u304E\u3000\u751F\u3054\u3081\u3000\u751F\u305F\u307E\u3054" );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 50 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Korean: \uADF9\uC9C0\uD0D0\uD5D8\u3000\uD611\uD68C\uACB0\uC131\u3000\uCCB4\uACC4\uC801\u3000\uC5F0\uAD6C" );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 70 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Hindi: \u092F\u0947 \u0905\u0928\u0941\u091A\u094D\u091B\u0947\u0926 \u0939\u093F\u0928\u094D\u0926\u0940 \u092E\u0947\u0902 \u0939\u0948\u0964" );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 90 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Arabic: \u0627\u0644\u0622\u0646 \u0644\u062D\u0636\u0648\u0631 \u0627\u0644\u0645\u0624\u062A\u0645\u0631 \u0627\u0644\u062F\u0648\u0644\u064A" );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 110 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Wow, Coloured Text" );
|
||||
label->SetTextColor( Gwen::Color( 0, 0, 255, 255 ) );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 130 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Coloured Text With Alpha" );
|
||||
label->SetTextColor( Gwen::Color( 0, 0, 255, 100 ) );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 150 );
|
||||
}
|
||||
|
||||
{
|
||||
//
|
||||
// Note that when using a custom font, this font object has to stick around
|
||||
// for the lifetime of the label. Rethink, or is that ideal?
|
||||
//
|
||||
m_Font.facename = L"Comic Sans MS";
|
||||
m_Font.size = 25;
|
||||
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Custom Font (Comic Sans 25)" );
|
||||
label->SetFont( &m_Font );
|
||||
label->SizeToContents();
|
||||
label->SetPos( 10, 170 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Label* label = new Gwen::Controls::Label( this );
|
||||
label->SetText( L"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." );
|
||||
label->SizeToContents();
|
||||
label->SetBounds( 300, 10, 150, 500 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Gwen::Font m_Font;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( Label, L"Label" );
|
||||
71
test/GwenOpenGLTest/ListBox.cpp
Normal file
71
test/GwenOpenGLTest/ListBox.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/ListBox.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class ListBox : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( ListBox, GUnit )
|
||||
{
|
||||
{
|
||||
Gwen::Controls::ListBox* ctrl = new Gwen::Controls::ListBox( this );
|
||||
ctrl->SetBounds( 10, 10, 100, 200 );
|
||||
|
||||
ctrl->AddItem( L"First" );
|
||||
ctrl->AddItem( L"Blue" );
|
||||
ctrl->AddItem( L"Yellow" );
|
||||
ctrl->AddItem( L"Orange" );
|
||||
ctrl->AddItem( L"Brown" );
|
||||
ctrl->AddItem( L"Green" );
|
||||
ctrl->AddItem( L"Dog" );
|
||||
ctrl->AddItem( L"Cat" );
|
||||
ctrl->AddItem( L"Shoes" );
|
||||
ctrl->AddItem( L"Chair" );
|
||||
ctrl->AddItem( L"Last" );
|
||||
|
||||
ctrl->onRowSelected.Add( this, &ThisClass::RowSelected );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ListBox* ctrl = new Gwen::Controls::ListBox( this );
|
||||
ctrl->SetBounds( 120, 10, 200, 200 );
|
||||
ctrl->SetColumnCount( 3 );
|
||||
ctrl->SetAllowMultiSelect( true );
|
||||
ctrl->onRowSelected.Add( this, &ThisClass::RowSelected );
|
||||
|
||||
|
||||
{
|
||||
Gwen::Controls::Layout::TableRow* pRow = ctrl->AddItem( L"Baked Beans" );
|
||||
pRow->SetCellText( 1, L"Heinz" );
|
||||
pRow->SetCellText( 2, L"£3.50" );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Layout::TableRow* pRow = ctrl->AddItem( L"Bananas" );
|
||||
pRow->SetCellText( 1, L"Trees" );
|
||||
pRow->SetCellText( 2, L"£1.27" );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Layout::TableRow* pRow = ctrl->AddItem( L"Chicken" );
|
||||
pRow->SetCellText( 1, L"\u5355\u5143\u6D4B\u8BD5" );
|
||||
pRow->SetCellText( 2, L"£8.95" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RowSelected( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::ListBox* ctrl = (Gwen::Controls::ListBox*)pControl;
|
||||
|
||||
UnitPrint( Utility::Format( L"Listbox Item Selected: %s", ctrl->GetSelectedRow()->GetText( 0 ).c_str() ) );
|
||||
}
|
||||
|
||||
Gwen::Font m_Font;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( ListBox, L"ListBox" );
|
||||
105
test/GwenOpenGLTest/MenuStrip.cpp
Normal file
105
test/GwenOpenGLTest/MenuStrip.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/MenuStrip.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class MenuStrip : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( MenuStrip, GUnit )
|
||||
{
|
||||
Gwen::Controls::MenuStrip* menu = new Gwen::Controls::MenuStrip( this );
|
||||
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRoot = menu->AddItem( L"File" );
|
||||
pRoot->GetMenu()->AddItem( L"New", L"test16.png", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Load", L"test16.png", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Save", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Save As..", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"Quit", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRoot = menu->AddItem( L"\u043F\u0438\u0440\u0430\u0442\u0441\u0442\u0432\u043E" );
|
||||
pRoot->GetMenu()->AddItem( L"\u5355\u5143\u6D4B\u8BD5", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
pRoot->GetMenu()->AddItem( L"\u0111\u01A1n v\u1ECB th\u1EED nghi\u1EC7m", L"test16.png", GWEN_MCALL( ThisClass::MenuItemSelect ) );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRoot = menu->AddItem( L"Submenu" );
|
||||
|
||||
pRoot->GetMenu()->AddItem( "One" )->SetCheckable( true );
|
||||
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRootB = pRoot->GetMenu()->AddItem( "Two" );
|
||||
pRootB->GetMenu()->AddItem( "Two.One" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Two" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Three" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Four" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Five" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Six" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Seven" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Eight" );
|
||||
pRootB->GetMenu()->AddItem( "Two.Nine", "test16.png" );
|
||||
}
|
||||
|
||||
pRoot->GetMenu()->AddItem( "Three" );
|
||||
pRoot->GetMenu()->AddItem( "Four" );
|
||||
pRoot->GetMenu()->AddItem( "Five" );
|
||||
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRootB = pRoot->GetMenu()->AddItem( "Six" );
|
||||
pRootB->GetMenu()->AddItem( "Six.One" );
|
||||
pRootB->GetMenu()->AddItem( "Six.Two" );
|
||||
pRootB->GetMenu()->AddItem( "Six.Three" );
|
||||
pRootB->GetMenu()->AddItem( "Six.Four" );
|
||||
pRootB->GetMenu()->AddItem( "Six.Five", "test16.png" );
|
||||
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRootC = pRootB->GetMenu()->AddItem( "Six.Six" );
|
||||
pRootC->GetMenu()->AddItem( "Sheep" );
|
||||
pRootC->GetMenu()->AddItem( "Goose" );
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRootD = pRootC->GetMenu()->AddItem( "Camel" );
|
||||
pRootD->GetMenu()->AddItem( "Eyes" );
|
||||
pRootD->GetMenu()->AddItem( "Nose" );
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRootE = pRootD->GetMenu()->AddItem( "Hair" );
|
||||
pRootE->GetMenu()->AddItem( "Blonde" );
|
||||
pRootE->GetMenu()->AddItem( "Black" );
|
||||
{
|
||||
Gwen::Controls::MenuItem* pRootF = pRootE->GetMenu()->AddItem( "Red" );
|
||||
pRootF->GetMenu()->AddItem( "Light" );
|
||||
pRootF->GetMenu()->AddItem( "Medium" );
|
||||
pRootF->GetMenu()->AddItem( "Dark" );
|
||||
}
|
||||
pRootE->GetMenu()->AddItem( "Brown" );
|
||||
}
|
||||
pRootD->GetMenu()->AddItem( "Ears" );
|
||||
}
|
||||
pRootC->GetMenu()->AddItem( "Duck" );
|
||||
}
|
||||
|
||||
pRootB->GetMenu()->AddItem( "Six.Seven" );
|
||||
pRootB->GetMenu()->AddItem( "Six.Eight" );
|
||||
pRootB->GetMenu()->AddItem( "Six.Nine" );
|
||||
}
|
||||
|
||||
pRoot->GetMenu()->AddItem( "Seven" );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MenuItemSelect( Base* pControl )
|
||||
{
|
||||
Gwen::Controls::MenuItem* pMenuItem = (Gwen::Controls::MenuItem*)pControl;
|
||||
|
||||
UnitPrint( Utility::Format( L"Menu Selected: %s", pMenuItem->GetText().c_str() ) );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( MenuStrip, L"MenuStrip" );
|
||||
31
test/GwenOpenGLTest/Numeric.cpp
Normal file
31
test/GwenOpenGLTest/Numeric.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/NumericUpDown.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class Numeric : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( Numeric, GUnit )
|
||||
{
|
||||
|
||||
Controls::NumericUpDown* pCtrl = new Controls::NumericUpDown( this );
|
||||
pCtrl->SetBounds( 10, 10, 50, 20 );
|
||||
pCtrl->SetValue( 50 );
|
||||
pCtrl->SetMax( 1000 );
|
||||
pCtrl->SetMin( -1000 );
|
||||
|
||||
// pCtrl->onPress.Add( this, &ThisClass::onButtonA );
|
||||
}
|
||||
|
||||
void onButtonA( Controls::Base* pControl )
|
||||
{
|
||||
// UnitPrint( L"Button Pressed (using 'OnPress' event)" );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( Numeric, L"Numeric" );
|
||||
534
test/GwenOpenGLTest/OpenGLSample.cpp
Normal file
534
test/GwenOpenGLTest/OpenGLSample.cpp
Normal file
@@ -0,0 +1,534 @@
|
||||
|
||||
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/Skins/Simple.h"
|
||||
|
||||
#include "UnitTest.h"
|
||||
|
||||
extern unsigned char OpenSansData[];
|
||||
|
||||
#include "Gwen/Renderers/OpenGL_DebugFont.h"
|
||||
#ifdef __APPLE__
|
||||
#include "OpenGLWindow/MacOpenGLWindow.h"
|
||||
#else
|
||||
|
||||
#include "CustomGL/glew.h"
|
||||
#ifdef _WIN32
|
||||
#include "OpenGLWindow/Win32OpenGLWindow.h"
|
||||
#else
|
||||
//let's cross the fingers it is Linux/X11
|
||||
#include "OpenGLWindow/X11OpenGLWindow.h"
|
||||
#endif //_WIN32
|
||||
#endif//__APPLE__
|
||||
|
||||
#include "OpenGLWindow/opengl_fontstashcallbacks.h"
|
||||
|
||||
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
|
||||
#include "OpenGLWindow/GLPrimitiveRenderer.h"
|
||||
#include <assert.h>
|
||||
|
||||
Gwen::Controls::Canvas* pCanvas = NULL;
|
||||
Gwen::Skin::Simple skin;
|
||||
|
||||
void MyMouseMoveCallback( float x, float y)
|
||||
{
|
||||
//b3DefaultMouseCallback(button,state,x,y);
|
||||
|
||||
static int m_lastmousepos[2] = {0,0};
|
||||
static bool isInitialized = false;
|
||||
if (pCanvas)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
m_lastmousepos[0] = x+1;
|
||||
m_lastmousepos[1] = y+1;
|
||||
}
|
||||
bool handled = pCanvas->InputMouseMoved(x,y,m_lastmousepos[0],m_lastmousepos[1]);
|
||||
}
|
||||
}
|
||||
|
||||
void MyMouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
//b3DefaultMouseCallback(button,state,x,y);
|
||||
|
||||
if (pCanvas)
|
||||
{
|
||||
bool handled = pCanvas->InputMouseMoved(x,y,x, y);
|
||||
|
||||
if (button>=0)
|
||||
{
|
||||
handled = pCanvas->InputMouseButton(button,state);
|
||||
if (handled)
|
||||
{
|
||||
if (!state)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int sWidth = 800;//1050;
|
||||
int sHeight = 600;//768;
|
||||
GLPrimitiveRenderer* primRenderer=0;
|
||||
//GwenOpenGL3CoreRenderer* gwenRenderer=0;
|
||||
Gwen::Renderer::Base* gwenRenderer =0;
|
||||
|
||||
static void MyResizeCallback( float width, float height)
|
||||
{
|
||||
sWidth = width;
|
||||
sHeight = height;
|
||||
// printf("resize(%d,%d)\n",sWidth,sHeight);
|
||||
if (primRenderer)
|
||||
{
|
||||
primRenderer->setScreenSize(width,height);
|
||||
}
|
||||
if (gwenRenderer)
|
||||
{
|
||||
gwenRenderer->Resize(width,height);
|
||||
}
|
||||
if (pCanvas)
|
||||
{
|
||||
pCanvas->SetSize( sWidth, sHeight);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int droidRegular;//, droidItalic, droidBold, droidJapanese, dejavu;
|
||||
|
||||
sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
|
||||
{
|
||||
GLint err;
|
||||
|
||||
struct sth_stash* stash = 0;
|
||||
OpenGL2RenderCallbacks* renderCallbacks = new OpenGL2RenderCallbacks(primRenderer);
|
||||
|
||||
stash = sth_create(512,512,renderCallbacks);//256,256);//,1024);//512,512);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
if (!stash)
|
||||
{
|
||||
fprintf(stderr, "Could not create stash.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef LOAD_FONTS_FROM_FILE
|
||||
int datasize;
|
||||
unsigned char* data;
|
||||
float sx,sy,dx,dy,lh;
|
||||
GLuint texture;
|
||||
|
||||
|
||||
|
||||
const char* fontPaths[]={
|
||||
"./",
|
||||
"../../bin/",
|
||||
"../bin/",
|
||||
"bin/"
|
||||
};
|
||||
|
||||
int numPaths=sizeof(fontPaths)/sizeof(char*);
|
||||
|
||||
// Load the first truetype font from memory (just because we can).
|
||||
|
||||
FILE* fp = 0;
|
||||
const char* fontPath ="./";
|
||||
char fullFontFileName[1024];
|
||||
|
||||
for (int i=0;i<numPaths;i++)
|
||||
{
|
||||
|
||||
fontPath = fontPaths[i];
|
||||
//sprintf(fullFontFileName,"%s%s",fontPath,"OpenSans.ttf");//"DroidSerif-Regular.ttf");
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Regular.ttf");//OpenSans.ttf");//"DroidSerif-Regular.ttf");
|
||||
fp = fopen(fullFontFileName, "rb");
|
||||
if (fp)
|
||||
break;
|
||||
}
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
assert(fp);
|
||||
if (fp)
|
||||
{
|
||||
fseek(fp, 0, SEEK_END);
|
||||
datasize = (int)ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
data = (unsigned char*)malloc(datasize);
|
||||
if (data == NULL)
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
fread(data, 1, datasize, fp);
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
}
|
||||
|
||||
if (!(droidRegular = sth_add_font_from_memory(stash, data)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
// Load the remaining truetype fonts directly.
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Italic.ttf");
|
||||
|
||||
if (!(droidItalic = sth_add_font(stash,fullFontFileName)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Bold.ttf");
|
||||
|
||||
if (!(droidBold = sth_add_font(stash,fullFontFileName)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
sprintf(fullFontFileName,"%s%s",fontPath,"DroidSansJapanese.ttf");
|
||||
if (!(droidJapanese = sth_add_font(stash,fullFontFileName)))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
unsigned char* data = OpenSansData;
|
||||
|
||||
if (!(droidRegular = sth_add_font_from_memory(stash, data)))
|
||||
{
|
||||
printf("error!\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
return stash;
|
||||
}
|
||||
|
||||
void keyCallback(int key, int value)
|
||||
{
|
||||
printf("key = %d, value = %d\n", key,value);
|
||||
//pCanvas->InputKey(key,value==1);
|
||||
|
||||
|
||||
int gwenKey = -1;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case B3G_LEFT_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Left;
|
||||
break;
|
||||
}
|
||||
case B3G_RIGHT_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Right;
|
||||
break;
|
||||
}
|
||||
case B3G_UP_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Up;
|
||||
break;
|
||||
}
|
||||
case B3G_DOWN_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Down;
|
||||
break;
|
||||
}
|
||||
case B3G_BACKSPACE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Backspace;
|
||||
break;
|
||||
}
|
||||
case B3G_DELETE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Delete;
|
||||
break;
|
||||
}
|
||||
case B3G_HOME:
|
||||
{
|
||||
gwenKey = Gwen::Key::Home;
|
||||
break;
|
||||
}
|
||||
case B3G_END:
|
||||
{
|
||||
gwenKey = Gwen::Key::End;
|
||||
break;
|
||||
}
|
||||
case B3G_SHIFT:
|
||||
{
|
||||
gwenKey = Gwen::Key::Shift;
|
||||
break;
|
||||
}
|
||||
case B3G_CONTROL:
|
||||
{
|
||||
gwenKey = Gwen::Key::Control;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (gwenKey>=0)
|
||||
{
|
||||
pCanvas->InputKey(gwenKey,value==1);
|
||||
} else
|
||||
{
|
||||
if (key<256 && value)
|
||||
{
|
||||
Gwen::UnicodeChar c = ( Gwen::UnicodeChar ) key;
|
||||
pCanvas->InputCharacter(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int avoidUpdate;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
||||
window->setKeyboardCallback(keyCallback);
|
||||
b3gWindowConstructionInfo wci;
|
||||
wci.m_openglVersion = 2;
|
||||
wci.m_width = sWidth;
|
||||
wci.m_height = sHeight;
|
||||
// wci.m_resizeCallback = MyResizeCallback;
|
||||
|
||||
window->createWindow(wci);
|
||||
window->setResizeCallback(MyResizeCallback);
|
||||
|
||||
|
||||
int majorGlVersion, minorGlVersion;
|
||||
|
||||
if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2)
|
||||
{
|
||||
printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n");
|
||||
exit(0);
|
||||
}
|
||||
char title[1024];
|
||||
if (wci.m_openglVersion>2)
|
||||
{
|
||||
sprintf(title,"Gwen with OpenGL %d.%d\n",majorGlVersion,minorGlVersion);
|
||||
} else
|
||||
{
|
||||
sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion);
|
||||
}
|
||||
window->setWindowTitle(title);
|
||||
|
||||
if (majorGlVersion>=3 && wci.m_openglVersion>=3)
|
||||
{
|
||||
float retinaScale = 1.f;
|
||||
|
||||
#ifndef __APPLE__
|
||||
#ifndef _WIN32
|
||||
//we need glewExperimental on Linux
|
||||
glewExperimental = GL_TRUE;
|
||||
#endif // _WIN32
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
//we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue
|
||||
|
||||
GLuint err = glGetError();
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
retinaScale = window->getRetinaScale();
|
||||
|
||||
primRenderer = new GLPrimitiveRenderer(sWidth,sHeight);
|
||||
|
||||
sth_stash* font = initFont(primRenderer );
|
||||
|
||||
|
||||
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
||||
|
||||
} else
|
||||
{
|
||||
//OpenGL 2.x
|
||||
gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
|
||||
|
||||
skin.SetRender( gwenRenderer );
|
||||
|
||||
|
||||
|
||||
glClearColor(1,0,0,1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Create a GWEN OpenGL Renderer
|
||||
//
|
||||
// Gwen::Renderer::OpenGL_DebugFont * pRenderer = new Gwen::Renderer::OpenGL_DebugFont();
|
||||
|
||||
//
|
||||
// Create a GWEN skin
|
||||
//
|
||||
|
||||
|
||||
#ifdef USE_TEXTURED_SKIN
|
||||
Gwen::Skin::TexturedBase skin;
|
||||
skin.SetRender( pRenderer );
|
||||
skin.Init("DefaultSkin.png");
|
||||
#else
|
||||
skin.SetRender( gwenRenderer );
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Create a Canvas (it's root, on which all other GWEN panels are created)
|
||||
//
|
||||
pCanvas = new Gwen::Controls::Canvas( &skin );
|
||||
pCanvas->SetSize( sWidth, sHeight);
|
||||
pCanvas->SetDrawBackground( true );
|
||||
pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) );
|
||||
|
||||
window->setMouseButtonCallback(MyMouseButtonCallback);
|
||||
window->setMouseMoveCallback(MyMouseMoveCallback);
|
||||
|
||||
|
||||
//
|
||||
// Create our unittest control (which is a Window with controls in it)
|
||||
//
|
||||
UnitTest* pUnit = new UnitTest( pCanvas );
|
||||
pUnit->SetPos( 10, 10 );
|
||||
|
||||
//
|
||||
// Create a Windows Control helper
|
||||
// (Processes Windows MSG's and fires input at GWEN)
|
||||
//
|
||||
//Gwen::Input::Windows GwenInput;
|
||||
//GwenInput.Initialize( pCanvas );
|
||||
|
||||
//
|
||||
// Begin the main game loop
|
||||
//
|
||||
// MSG msg;
|
||||
while( !window->requestedExit() )
|
||||
{
|
||||
if (majorGlVersion<3 || wci.m_openglVersion<3)
|
||||
{
|
||||
saveOpenGLState(sWidth,sHeight);
|
||||
}
|
||||
|
||||
// Skip out if the window is closed
|
||||
//if ( !IsWindowVisible( g_pHWND ) )
|
||||
//break;
|
||||
|
||||
// If we have a message from windows..
|
||||
// if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
|
||||
{
|
||||
|
||||
// .. give it to the input handler to process
|
||||
// GwenInput.ProcessMessage( msg );
|
||||
|
||||
// if it's QUIT then quit..
|
||||
// if ( msg.message == WM_QUIT )
|
||||
// break;
|
||||
|
||||
// Handle the regular window stuff..
|
||||
// TranslateMessage(&msg);
|
||||
// DispatchMessage(&msg);
|
||||
|
||||
}
|
||||
|
||||
window->startRendering();
|
||||
|
||||
// Main OpenGL Render Loop
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
//glColor4ub(255,0,0,255);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
|
||||
pCanvas->RenderCanvas();
|
||||
|
||||
if (avoidUpdate<=0)
|
||||
avoidUpdate++;
|
||||
|
||||
// SwapBuffers( GetDC( g_pHWND ) );
|
||||
}
|
||||
window->endRendering();
|
||||
|
||||
if (majorGlVersion<3 || wci.m_openglVersion<3)
|
||||
{
|
||||
restoreOpenGLState();
|
||||
}
|
||||
}
|
||||
|
||||
window->closeWindow();
|
||||
delete window;
|
||||
|
||||
|
||||
}
|
||||
61
test/GwenOpenGLTest/PanelListPanel.cpp
Normal file
61
test/GwenOpenGLTest/PanelListPanel.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/PanelListPanel.h"
|
||||
#include "Gwen/Controls/StatusBar.h"
|
||||
#include "Gwen/Utility.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class PanelListPanel : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( PanelListPanel, GUnit )
|
||||
{
|
||||
m_PLP = new Gwen::Controls::PanelListPanel( this );
|
||||
m_PLP->Dock( Pos::Fill );
|
||||
m_PLP->SetPadding( Gwen::Padding( 10, 10 ));
|
||||
m_PLP->SetVertical();
|
||||
m_PLP->SetSizeToChildren( false );
|
||||
|
||||
for ( int i = 0; i < 16; i++)
|
||||
{
|
||||
Gwen::String testName = "TEST" + Utility::ToString( i );
|
||||
Gwen::Controls::Button* testButton = new Gwen::Controls::Button( m_PLP );
|
||||
testButton->SetText( testName );
|
||||
}
|
||||
|
||||
Gwen::Controls::StatusBar* pStatus = new Gwen::Controls::StatusBar( this );
|
||||
pStatus->Dock( Pos::Bottom );
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* pButton = new Gwen::Controls::Button( pStatus );
|
||||
pButton->SetText( "Horizontal" );
|
||||
pButton->onPress.Add( this, &PanelListPanel::GoHorizontal );
|
||||
pStatus->AddControl( pButton, false );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Button* pButton = new Gwen::Controls::Button( pStatus );
|
||||
pButton->SetText( "Vertical" );
|
||||
pButton->onPress.Add( this, &PanelListPanel::GoVertical );
|
||||
pStatus->AddControl( pButton, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GoVertical( Gwen::Controls::Base* pFromPanel )
|
||||
{
|
||||
m_PLP->SetVertical();
|
||||
}
|
||||
|
||||
void GoHorizontal( Gwen::Controls::Base* pFromPanel )
|
||||
{
|
||||
m_PLP->SetHorizontal();
|
||||
}
|
||||
|
||||
Gwen::Controls::PanelListPanel* m_PLP;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( PanelListPanel, L"PanelListPanel" );
|
||||
93
test/GwenOpenGLTest/ProgressBar.cpp
Normal file
93
test/GwenOpenGLTest/ProgressBar.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
#include "Gwen/Controls/ProgressBar.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class ProgressBar : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( ProgressBar, GUnit )
|
||||
{
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 110, 20, 200, 20 ) );
|
||||
pb->SetValue( 0.27f );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 110, 50, 200, 20 ) );
|
||||
pb->SetValue( 0.66f );
|
||||
pb->SetAlignment( Pos::Right | Pos::CenterV );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 110, 80, 200, 20 ) );
|
||||
pb->SetValue( 0.88f );
|
||||
pb->SetAlignment( Pos::Left | Pos::CenterV );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 110, 110, 200, 20 ) );
|
||||
pb->SetAutoLabel( false );
|
||||
pb->SetValue( 0.20f );
|
||||
pb->SetAlignment( Pos::Right | Pos::CenterV );
|
||||
pb->SetText( L"40,245 MB" );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 110, 140, 200, 20 ) );
|
||||
pb->SetAutoLabel( false );
|
||||
pb->SetValue( 1.00f );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 110, 170, 200, 20 ) );
|
||||
pb->SetAutoLabel( false );
|
||||
pb->SetValue( 0.00f );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 110, 200, 200, 20 ) );
|
||||
pb->SetAutoLabel( false );
|
||||
pb->SetValue( 0.50f );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 20, 20, 25, 200 ) );
|
||||
pb->SetVertical();
|
||||
pb->SetValue( 0.25f );
|
||||
pb->SetAlignment( Pos::Top | Pos::CenterH );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 50, 20, 25, 200 ) );
|
||||
pb->SetVertical();
|
||||
pb->SetValue( 0.40f );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ProgressBar* pb = new Gwen::Controls::ProgressBar( this );
|
||||
pb->SetBounds( Gwen::Rect( 80, 20, 25, 200 ) );
|
||||
pb->SetVertical();
|
||||
pb->SetAlignment( Pos::Bottom | Pos::CenterH );
|
||||
pb->SetValue( 0.65f );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( ProgressBar, L"ProgressBar" );
|
||||
63
test/GwenOpenGLTest/Properties.cpp
Normal file
63
test/GwenOpenGLTest/Properties.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/Properties.h"
|
||||
#include "Gwen/Controls/PropertyTree.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class Properties2 : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( Properties2, GUnit )
|
||||
{
|
||||
{
|
||||
Gwen::Controls::Properties* props = new Gwen::Controls::Properties( this );
|
||||
|
||||
props->SetBounds( 10, 10, 150, 300 );
|
||||
|
||||
{
|
||||
{
|
||||
Gwen::Controls::PropertyRow* pRow = props->Add( L"First Name" );
|
||||
pRow->onChange.Add( this, &Properties2::OnFirstNameChanged );
|
||||
}
|
||||
|
||||
props->Add( L"Middle Name" );
|
||||
props->Add( L"Last Name" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::PropertyTree* ptree = new Gwen::Controls::PropertyTree( this );
|
||||
ptree->SetBounds( 200, 10, 200, 200 );
|
||||
|
||||
{
|
||||
Gwen::Controls::Properties* props = ptree->Add( L"Item One" );
|
||||
props->Add( L"Middle Name" );
|
||||
props->Add( L"Last Name" );
|
||||
props->Add( L"Four" );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::Properties* props = ptree->Add( L"Item Two" );
|
||||
props->Add( L"More Items" );
|
||||
props->Add( L"To Fill" );
|
||||
props->Add( L"Out Here" );
|
||||
}
|
||||
|
||||
ptree->ExpandAll();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void OnFirstNameChanged( Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::PropertyRow* pRow = (Gwen::Controls::PropertyRow*) pControl;
|
||||
UnitPrint( Utility::Format( L"First Name Changed: %s", pRow->GetProperty()->GetPropertyValue().c_str() ) );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( Properties2, L"Properties" );
|
||||
38
test/GwenOpenGLTest/RadioButton.cpp
Normal file
38
test/GwenOpenGLTest/RadioButton.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class RadioButton2 : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( RadioButton2, GUnit )
|
||||
{
|
||||
|
||||
Gwen::Controls::RadioButtonController* rc = new Gwen::Controls::RadioButtonController( this );
|
||||
|
||||
rc->AddOption( "Option 1" );
|
||||
rc->AddOption( "Option 2" );
|
||||
rc->AddOption( "Option 3" );
|
||||
rc->AddOption( L"\u0627\u0644\u0622\u0646 \u0644\u062D\u0636\u0648\u0631" );
|
||||
|
||||
rc->SetBounds( 30, 30, 200, 200 );
|
||||
|
||||
rc->onSelectionChange.Add( this, &RadioButton2::OnChange );
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnChange( Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::RadioButtonController* rc = (Gwen::Controls::RadioButtonController*) pControl;
|
||||
Gwen::Controls::LabeledRadioButton* pSelected = rc->GetSelected();
|
||||
|
||||
UnitPrint( Utility::Format( L"RadioButton changed (using 'OnChange' event)\n Chosen Item: '%s'", pSelected->GetLabel()->GetText().c_str() ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( RadioButton2, L"RadioButton" );
|
||||
138
test/GwenOpenGLTest/ScrollControl.cpp
Normal file
138
test/GwenOpenGLTest/ScrollControl.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/ScrollControl.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class ScrollControl : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( ScrollControl, GUnit )
|
||||
{
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 10, 10, 100, 100 );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Twice As Big" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 200 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 110, 10, 100, 100 );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Same Size" );
|
||||
pTestButton->SetBounds( 0, 0, 100, 100 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 210, 10, 100, 100 );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Wide" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 50 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 310, 10, 100, 100 );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Tall" );
|
||||
pTestButton->SetBounds( 0, 0, 50, 200 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 410, 10, 100, 100 );
|
||||
pCtrl->SetScroll( false, true );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Vertical" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 200 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 510, 10, 100, 100 );
|
||||
pCtrl->SetScroll( true, false );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Horinzontal" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 200 );
|
||||
}
|
||||
|
||||
// Bottom Row
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 10, 110, 100, 100 );
|
||||
pCtrl->SetAutoHideBars( true );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Twice As Big" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 200 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 110, 110, 100, 100 );
|
||||
pCtrl->SetAutoHideBars( true );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Same Size" );
|
||||
pTestButton->SetBounds( 0, 0, 100, 100 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 210, 110, 100, 100 );
|
||||
pCtrl->SetAutoHideBars( true );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Wide" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 50 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 310, 110, 100, 100 );
|
||||
pCtrl->SetAutoHideBars( true );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Tall" );
|
||||
pTestButton->SetBounds( 0, 0, 50, 200 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 410, 110, 100, 100 );
|
||||
pCtrl->SetAutoHideBars( true );
|
||||
pCtrl->SetScroll( false, true );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Vertical" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 200 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::ScrollControl* pCtrl = new Gwen::Controls::ScrollControl( this );
|
||||
pCtrl->SetBounds( 510, 110, 100, 100 );
|
||||
pCtrl->SetAutoHideBars( true );
|
||||
pCtrl->SetScroll( true, false );
|
||||
|
||||
Controls::Button* pTestButton = new Controls::Button( pCtrl );
|
||||
pTestButton->SetText( L"Horinzontal" );
|
||||
pTestButton->SetBounds( 0, 0, 200, 200 );
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( ScrollControl, L"Scroll" );
|
||||
66
test/GwenOpenGLTest/Slider.cpp
Normal file
66
test/GwenOpenGLTest/Slider.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
#include "Gwen/Controls/VerticalSlider.h"
|
||||
#include "Gwen/Controls/HorizontalSlider.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class Slider : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( Slider, GUnit )
|
||||
{
|
||||
{
|
||||
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider( this );
|
||||
pSlider->SetPos( 10, 10 );
|
||||
pSlider->SetSize( 150, 20 );
|
||||
pSlider->SetRange( 0, 100 );
|
||||
pSlider->SetValue( 25 );
|
||||
pSlider->onValueChanged.Add( this, &Slider::SliderMoved );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider( this );
|
||||
pSlider->SetPos( 10, 40 );
|
||||
pSlider->SetSize( 150, 20 );
|
||||
pSlider->SetRange( 0, 100 );
|
||||
pSlider->SetValue( 25 );
|
||||
pSlider->SetNotchCount( 10 );
|
||||
pSlider->SetClampToNotches( true );
|
||||
pSlider->onValueChanged.Add( this, &Slider::SliderMoved );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::VerticalSlider* pSlider = new Gwen::Controls::VerticalSlider( this );
|
||||
pSlider->SetPos( 160, 10 );
|
||||
pSlider->SetSize( 20, 200 );
|
||||
pSlider->SetRange( 0, 100 );
|
||||
pSlider->SetValue( 25 );
|
||||
pSlider->onValueChanged.Add( this, &Slider::SliderMoved );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::VerticalSlider* pSlider = new Gwen::Controls::VerticalSlider( this );
|
||||
pSlider->SetPos( 190, 10 );
|
||||
pSlider->SetSize( 20, 200 );
|
||||
pSlider->SetRange( 0, 100 );
|
||||
pSlider->SetValue( 25 );
|
||||
pSlider->SetNotchCount( 10 );
|
||||
pSlider->SetClampToNotches( true );
|
||||
pSlider->onValueChanged.Add( this, &Slider::SliderMoved );
|
||||
}
|
||||
}
|
||||
|
||||
void SliderMoved( Base* pControl )
|
||||
{
|
||||
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
|
||||
|
||||
UnitPrint( Utility::Format( L"Slider Value: %.2f", pSlider->GetValue() ) );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( Slider, L"Slider" );
|
||||
28
test/GwenOpenGLTest/StatusBar.cpp
Normal file
28
test/GwenOpenGLTest/StatusBar.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/StatusBar.h"
|
||||
#include "Gwen/Controls/Label.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class StatusBar : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( StatusBar, GUnit )
|
||||
{
|
||||
Gwen::Controls::StatusBar* pStatus = new Gwen::Controls::StatusBar( this );
|
||||
pStatus->Dock( Pos::Bottom );
|
||||
|
||||
Gwen::Controls::Label* pLeft = new Gwen::Controls::Label( pStatus );
|
||||
pLeft->SetText(L"Label Added to left");
|
||||
pStatus->AddControl( pLeft, false );
|
||||
|
||||
Gwen::Controls::Label* pRight = new Gwen::Controls::Label( pStatus );
|
||||
pRight->SetText(L"Label Added to Right");
|
||||
pStatus->AddControl( pRight, true );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( StatusBar, L"StatusBar" );
|
||||
71
test/GwenOpenGLTest/TabControl.cpp
Normal file
71
test/GwenOpenGLTest/TabControl.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/TabControl.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class TabControl2 : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
Controls::TabControl* m_pDockControlLeft;
|
||||
|
||||
GWEN_CONTROL_INLINE( TabControl2, GUnit )
|
||||
{
|
||||
{
|
||||
m_pDockControlLeft = new Controls::TabControl( this );
|
||||
m_pDockControlLeft->SetBounds( 10, 10, 200, 200 );
|
||||
|
||||
{
|
||||
Controls::TabButton* pButton = m_pDockControlLeft->AddPage( L"Controls" );
|
||||
Base* pPage = pButton->GetPage();
|
||||
|
||||
{
|
||||
Controls::RadioButtonController* pRadio = new Controls::RadioButtonController( pPage );
|
||||
pRadio->SetBounds( 10, 10, 100, 100 );
|
||||
|
||||
pRadio->AddOption( "Top" )->Select();
|
||||
pRadio->AddOption( "Bottom" );
|
||||
pRadio->AddOption( "Left" );
|
||||
pRadio->AddOption( "Right" );
|
||||
|
||||
pRadio->onSelectionChange.Add( this, &ThisClass::OnDockChange );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_pDockControlLeft->AddPage( L"Red" );
|
||||
m_pDockControlLeft->AddPage( L"Green" );
|
||||
m_pDockControlLeft->AddPage( L"Blue" );
|
||||
}
|
||||
|
||||
{
|
||||
Controls::TabControl* pDragMe = new Controls::TabControl( this );
|
||||
pDragMe->SetBounds( 220, 10, 200, 200 );
|
||||
|
||||
pDragMe->AddPage( L"You" );
|
||||
pDragMe->AddPage( L"Can" );
|
||||
pDragMe->AddPage( L"Reorder" )->SetImage( L"test16.png" );
|
||||
pDragMe->AddPage( L"These" );
|
||||
pDragMe->AddPage( L"Tabs" );
|
||||
|
||||
pDragMe->SetAllowReorder( true );
|
||||
}
|
||||
}
|
||||
|
||||
void OnDockChange( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::RadioButtonController* rc = (Gwen::Controls::RadioButtonController*) pControl;
|
||||
|
||||
if ( rc->GetSelectedLabel() == L"Top" ) m_pDockControlLeft->SetTabStripPosition( Pos::Top );
|
||||
if ( rc->GetSelectedLabel() == L"Bottom" ) m_pDockControlLeft->SetTabStripPosition( Pos::Bottom );
|
||||
if ( rc->GetSelectedLabel() == L"Left" ) m_pDockControlLeft->SetTabStripPosition( Pos::Left );
|
||||
if ( rc->GetSelectedLabel() == L"Right" ) m_pDockControlLeft->SetTabStripPosition( Pos::Right );
|
||||
}
|
||||
|
||||
Gwen::Font m_Font;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( TabControl2, L"TabControl" );
|
||||
79
test/GwenOpenGLTest/TextBox.cpp
Normal file
79
test/GwenOpenGLTest/TextBox.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/TextBox.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
class TextBox : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( TextBox, GUnit )
|
||||
{
|
||||
{
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
|
||||
label->SetText( "" );
|
||||
label->SetPos( 10, 10 );
|
||||
label->onTextChanged.Add( this, &ThisClass::OnEdit );
|
||||
label->onReturnPressed.Add( this, &ThisClass::OnSubmit );
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
|
||||
label->SetText( "Normal Everyday Label" );
|
||||
label->SetPos( 10, 10 + 25 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
|
||||
label->SetText( "Select All Text On Focus" );
|
||||
label->SetPos( 10, 10 + 25 * 2 );
|
||||
label->SetSelectAllOnFocus( true );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
|
||||
label->SetText( L"Different Coloured Text, for some reason" );
|
||||
label->SetTextColor( Gwen::Color( 255, 0, 255, 255 ) );
|
||||
label->SetPos( 10, 10 + 25 * 3 );
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::TextBoxNumeric* label = new Gwen::Controls::TextBoxNumeric( this );
|
||||
label->SetText( L"2004" );
|
||||
label->SetTextColor( Gwen::Color( 255, 0, 255, 255 ) );
|
||||
label->SetPos( 10, 10 + 25 * 4 );
|
||||
}
|
||||
|
||||
{
|
||||
m_Font.facename = L"Impact";
|
||||
m_Font.size = 50;
|
||||
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
|
||||
label->SetText( L"Different Font" );
|
||||
label->SetPos( 10, 10 + 25 * 5 );
|
||||
label->SetFont( &m_Font );
|
||||
label->SetSize( 200, 55 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnEdit( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::TextBox* textbox = (Gwen::Controls::TextBox*) (pControl);
|
||||
UnitPrint( Utility::Format( L"Textbox Edit: [%s]\n", textbox->GetText().c_str() ) );
|
||||
}
|
||||
|
||||
void OnSubmit( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::TextBox* textbox = (Gwen::Controls::TextBox*) (pControl);
|
||||
UnitPrint( Utility::Format( L"Textbox Submit: [%s]\n", textbox->GetText().c_str() ) );
|
||||
}
|
||||
|
||||
Gwen::Font m_Font;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( TextBox, L"TextBox" );
|
||||
61
test/GwenOpenGLTest/TreeControl.cpp
Normal file
61
test/GwenOpenGLTest/TreeControl.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
using namespace Gwen::Controls;
|
||||
|
||||
|
||||
class TreeControl2 : public GUnit
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( TreeControl2, GUnit )
|
||||
{
|
||||
{
|
||||
Gwen::Controls::TreeControl* ctrl = new Gwen::Controls::TreeControl( this );
|
||||
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
ctrl->AddNode( L"Node One" );
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
pNode->SetSelected(true);
|
||||
|
||||
pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
|
||||
ctrl->AddNode( L"Node Three" );
|
||||
ctrl->Focus();
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
|
||||
ctrl->SetBounds( 30, 30, 200, 200 );
|
||||
ctrl->ExpandAll();
|
||||
}
|
||||
|
||||
{
|
||||
Gwen::Controls::TreeControl* ctrl = new Gwen::Controls::TreeControl( this );
|
||||
|
||||
ctrl->AllowMultiSelect( true );
|
||||
|
||||
ctrl->AddNode( L"Node One" );
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
Gwen::Controls::TreeNode* pNodeTwo = pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" );
|
||||
pNodeTwo->AddNode( L"Brown" );
|
||||
pNodeTwo->AddNode( L"Green" );
|
||||
pNodeTwo->AddNode( L"Slime" );
|
||||
pNodeTwo->AddNode( L"Grass" );
|
||||
pNodeTwo->AddNode( L"Pipe" );
|
||||
|
||||
ctrl->AddNode( L"Node Three" );
|
||||
|
||||
ctrl->SetBounds( 240, 30, 200, 200 );
|
||||
ctrl->ExpandAll();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_UNIT_TEST( TreeControl2, L"TreeControl" );
|
||||
179
test/GwenOpenGLTest/UnitTest.cpp
Normal file
179
test/GwenOpenGLTest/UnitTest.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
GWEN
|
||||
Copyright (c) 2010 Facepunch Studios
|
||||
See license in Gwen.h
|
||||
*/
|
||||
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Platform.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
#define ADD_UNIT_TEST( name )\
|
||||
GUnit* RegisterUnitTest_##name( Gwen::Controls::TabControl* tab );\
|
||||
RegisterUnitTest_##name( m_TabControl )->SetUnitTest( this );
|
||||
|
||||
GWEN_CONTROL_CONSTRUCTOR( UnitTest )
|
||||
{
|
||||
SetTitle( L"GWEN Unit Test" );
|
||||
|
||||
SetSize( 600, 450 );
|
||||
|
||||
|
||||
m_TabControl = new Controls::TabControl( this );
|
||||
m_TabControl->Dock( Pos::Fill );
|
||||
m_TabControl->SetMargin( Margin( 2, 2, 2, 2 ) );
|
||||
|
||||
m_TextOutput = new Controls::ListBox( this );
|
||||
m_TextOutput->Dock( Pos::Bottom );
|
||||
m_TextOutput->SetHeight( 100 );
|
||||
|
||||
|
||||
ADD_UNIT_TEST( ImagePanel );
|
||||
|
||||
//ADD_UNIT_TEST( MenuStrip );
|
||||
|
||||
Gwen::UnicodeString str1(L"testje");
|
||||
Gwen::Controls::TabButton* tab = m_TabControl->AddPage(str1);
|
||||
|
||||
Gwen::Controls::TreeControl* ctrl=0;
|
||||
|
||||
{
|
||||
ctrl = new Gwen::Controls::TreeControl(tab->GetPage());
|
||||
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
ctrl->AddNode( L"Node One" );
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
pNode->SetSelected(true);
|
||||
|
||||
|
||||
pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
|
||||
}
|
||||
ctrl->AddNode( L"Node Three" );
|
||||
ctrl->Focus();
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
|
||||
ctrl->SetBounds( 30, 30, 200, 30+16*10 );
|
||||
//ctrl->ExpandAll();
|
||||
ctrl->ForceUpdateScrollBars();
|
||||
ctrl->OnKeyDown(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//GUnit* u = new TreeControl2(m_TabControl);..Gwen::Controls::TreeControl2( m_TabControl );
|
||||
//GUnit* RegisterUnitTest_TreeControl2( Gwen::Controls::TabControl* tab );\
|
||||
//RegisterUnitTest_TreeControl2( m_TabControl )->SetUnitTest( this );
|
||||
|
||||
|
||||
//#define DEFINE_UNIT_TEST( name, displayname )
|
||||
//GUnit* RegisterUnitTest_TreeControl2( Gwen::Controls::TabControl* tab )
|
||||
//{
|
||||
// GUnit* u = new TreeControl2( tab );
|
||||
// tab->AddPage( displayname, u );
|
||||
// return u;
|
||||
//}
|
||||
|
||||
//ADD_UNIT_TEST( TreeControl2 );
|
||||
|
||||
ADD_UNIT_TEST( Properties2 );
|
||||
|
||||
|
||||
ADD_UNIT_TEST( TabControl2 );
|
||||
ADD_UNIT_TEST( ScrollControl );
|
||||
ADD_UNIT_TEST( MenuStrip );
|
||||
ADD_UNIT_TEST( Numeric );
|
||||
ADD_UNIT_TEST( ComboBox );
|
||||
ADD_UNIT_TEST( TextBox );
|
||||
ADD_UNIT_TEST( ListBox );
|
||||
ADD_UNIT_TEST( Slider );
|
||||
ADD_UNIT_TEST( ProgressBar );
|
||||
ADD_UNIT_TEST( RadioButton2 );
|
||||
|
||||
ADD_UNIT_TEST( Label );
|
||||
ADD_UNIT_TEST( Checkbox );
|
||||
ADD_UNIT_TEST( Button );
|
||||
|
||||
ADD_UNIT_TEST( CrossSplitter );
|
||||
|
||||
ADD_UNIT_TEST( PanelListPanel );
|
||||
ADD_UNIT_TEST( GroupBox2 );
|
||||
|
||||
ADD_UNIT_TEST( StatusBar );
|
||||
|
||||
|
||||
ctrl->Focus();
|
||||
PrintText( L"Unit Test Started.\n" );
|
||||
|
||||
m_fLastSecond = Gwen::Platform::GetTimeInSeconds();
|
||||
m_iFrames = 0;
|
||||
}
|
||||
|
||||
|
||||
void UnitTest::PrintText( const Gwen::UnicodeString& str )
|
||||
{
|
||||
m_TextOutput->AddItem( str );
|
||||
m_TextOutput->Scroller()->ScrollToBottom();
|
||||
}
|
||||
|
||||
void UnitTest::Render( Gwen::Skin::Base* skin )
|
||||
{
|
||||
m_iFrames++;
|
||||
|
||||
if ( m_fLastSecond < Gwen::Platform::GetTimeInSeconds() )
|
||||
{
|
||||
SetTitle( Gwen::Utility::Format( L"GWEN Unit Test - %i fps", m_iFrames ) );
|
||||
|
||||
m_fLastSecond = Gwen::Platform::GetTimeInSeconds() + 1.0f;
|
||||
m_iFrames = 0;
|
||||
}
|
||||
|
||||
BaseClass::Render( skin );
|
||||
|
||||
}
|
||||
|
||||
void GUnit::UnitPrint( const Gwen::UnicodeString& str )
|
||||
{
|
||||
m_pUnitTest->PrintText( str );
|
||||
}
|
||||
|
||||
void GUnit::UnitPrint( const Gwen::String& str )
|
||||
{
|
||||
UnitPrint( Utility::StringToUnicode( str ) );
|
||||
}
|
||||
|
||||
64
test/GwenOpenGLTest/UnitTest.h
Normal file
64
test/GwenOpenGLTest/UnitTest.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
GWEN
|
||||
Copyright (c) 2011 Facepunch Studios
|
||||
See license in Gwen.h
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef GWEN_UNITTEST_UNITTEST_H
|
||||
#define GWEN_UNITTEST_UNITTEST_H
|
||||
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/Align.h"
|
||||
#include "Gwen/Utility.h"
|
||||
#include "Gwen/Controls/WindowControl.h"
|
||||
#include "Gwen/Controls/TabControl.h"
|
||||
#include "Gwen/Controls/ListBox.h"
|
||||
|
||||
class UnitTest;
|
||||
|
||||
|
||||
|
||||
class GUnit : public Gwen::Controls::Base
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL_INLINE( GUnit, Gwen::Controls::Base )
|
||||
{
|
||||
m_pUnitTest = NULL;
|
||||
}
|
||||
|
||||
void SetUnitTest( UnitTest* u ){ m_pUnitTest = u; }
|
||||
|
||||
void UnitPrint( const Gwen::UnicodeString& str );
|
||||
void UnitPrint( const Gwen::String& str );
|
||||
|
||||
|
||||
|
||||
|
||||
UnitTest* m_pUnitTest;
|
||||
};
|
||||
|
||||
class UnitTest : public Gwen::Controls::WindowControl
|
||||
{
|
||||
public:
|
||||
|
||||
GWEN_CONTROL( UnitTest, Gwen::Controls::WindowControl );
|
||||
|
||||
void PrintText( const Gwen::UnicodeString& str );
|
||||
|
||||
void Render( Gwen::Skin::Base* skin );
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Gwen::Controls::TabControl* m_TabControl;
|
||||
Gwen::Controls::ListBox* m_TextOutput;
|
||||
unsigned int m_iFrames;
|
||||
float m_fLastSecond;
|
||||
|
||||
};
|
||||
|
||||
#define DEFINE_UNIT_TEST( name, displayname ) GUnit* RegisterUnitTest_##name( Gwen::Controls::TabControl* tab ){ GUnit* u = new name( tab ); tab->AddPage( displayname, u ); return u; }
|
||||
#endif
|
||||
68
test/GwenOpenGLTest/premake4.lua
Normal file
68
test/GwenOpenGLTest/premake4.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
project "Test_Gwen_OpenGL"
|
||||
|
||||
kind "ConsoleApp"
|
||||
flags {"Unicode"}
|
||||
|
||||
defines { "GWEN_COMPILE_STATIC" , "_HAS_EXCEPTIONS=0", "_STATIC_CPPLIB" }
|
||||
defines { "DONT_USE_GLUT"}
|
||||
|
||||
targetdir "../../bin"
|
||||
|
||||
includedirs
|
||||
{
|
||||
|
||||
"../../examples/ThirdPartLibs/Gwen",
|
||||
".",
|
||||
}
|
||||
|
||||
initOpenGL()
|
||||
initGlew()
|
||||
|
||||
links {
|
||||
"gwen",
|
||||
}
|
||||
|
||||
|
||||
files {
|
||||
"../../examples/OpenGLWindow/OpenSans.cpp",
|
||||
"../../examples/OpenGLWindow/TwFonts.cpp",
|
||||
"../../examples/OpenGLWindow/TwFonts.h",
|
||||
"../../examples/OpenGLWindow/LoadShader.cpp",
|
||||
"../../examples/OpenGLWindow/LoadShader.h",
|
||||
"../../examples/OpenGLWindow/GLPrimitiveRenderer.cpp",
|
||||
"../../examples/OpenGLWindow/GLPrimitiveRenderer.h",
|
||||
"../../examples/OpenGLWindow/GwenOpenGL3CoreRenderer.h",
|
||||
"../../examples/OpenGLWindow/fontstash.cpp",
|
||||
"../../examples/OpenGLWindow/fontstash.h",
|
||||
"../../examples/OpenGLWindow/opengl_fontstashcallbacks.cpp",
|
||||
"../../examples/OpenGLWindow/opengl_fontstashcallbacks.h",
|
||||
"../../examples/Utils/b3Clock.cpp",
|
||||
"../../examples/Utils/b3Clock.h",
|
||||
"**.cpp",
|
||||
"**.h",
|
||||
}
|
||||
if os.is("Windows") then
|
||||
files {
|
||||
"../../examples/OpenGLWindow/Win32OpenGLWindow.cpp",
|
||||
"../../examples/OpenGLWindow/Win32OpenGLWindow.h",
|
||||
"../../examples/OpenGLWindow/Win32Window.cpp",
|
||||
"../../examples/OpenGLWindow/Win32Window.h",
|
||||
}
|
||||
end
|
||||
if os.is("Linux") then
|
||||
initX11()
|
||||
files{
|
||||
"../../examples/OpenGLWindow/X11OpenGLWindow.h",
|
||||
"../../examples/OpenGLWindow/X11OpenGLWindow.cpp"
|
||||
}
|
||||
links{"pthread"}
|
||||
end
|
||||
if os.is("MacOSX") then
|
||||
links{"Cocoa.framework"}
|
||||
print("hello!")
|
||||
files{
|
||||
"../../examples/OpenGLWindow/MacOpenGLWindow.mm",
|
||||
"../../examples/OpenGLWindow/MacOpenGLWindow.h",
|
||||
}
|
||||
end
|
||||
Reference in New Issue
Block a user