
paratest.cpp
Demonstrates general usage of the library (widgets, callbacks, ...) #include "paragui.h"
#include "pgapplication.h"
#include "pgbutton.h"
#include "pgwidgetlist.h"
#include "pglabel.h"
#include "pgwindow.h"
#include "pgmaskedit.h"
#include "pgscrollbar.h"
#include "pgprogressbar.h"
#include "pgradiobutton.h"
#include "pgthemewidget.h"
#include "pgcheckbutton.h"
#include "pgslider.h"
#include "pglistbox.h"
#include "pgcolumnitem.h"
#include "pgdropdown.h"
#include "pgpopupmenu.h"
#include "pgspinnerbox.h"
#include "pglog.h"
#include "pgmenubar.h"
#include "pgtheme.h"
#include "pgmultilineedit.h"
#include <iostream>
#define RESX 800
#define RESY 600
void Splash() {
PG_ThemeWidget splash(NULL,
PG_Rect(100,100,600,400),
true);
PG_ThemeWidget splash1(&splash,
PG_Rect(10,10,580,380));
PG_ThemeWidget splash2(&splash1,
PG_Rect(10,10,560,340));
PG_Label l(&splash2,
PG_Rect(10,10,540,320),
"I'm a splash screen");
l.
SetAlignment(PG_Label::CENTER);
splash.
Show();
SDL_Delay(5000);
splash.
Hide();
}
bool handle_popup(
PG_Pointer clientdata) {
PG_PopupMenu* pop = (
PG_PopupMenu*)clientdata;
pop->
trackMenu(10, 10);
return true;
}
bool handle_exit(PG_Pointer clientdata) {
PG_Application* app = (
PG_Application*)clientdata;
app->
Quit();
return true;
}
bool handle_toggle(PG_Pointer clientdata) {
PG_Button* b = (
PG_Button*)clientdata;
if (b->
GetPressed()) {
PG_LogMSG(
"Button pressed");
}
else {
PG_LogMSG(
"Button released");
}
return true;
}
bool hande_slideIndent(
PG_ScrollBar* s,
long pos, PG_Pointer data) {
PG_DropDown* drop = static_cast<PG_DropDown*>(data);
drop->
SetIndent(pos);
return true;
}
class MySliderLabel :
public PG_Label {
public:
MySliderLabel(
PG_Widget* parent,
const PG_Rect& r,
char* text) :
PG_Label(parent,r,text) {
};
bool handler_slider(
long data) {
SetTextFormat(
"%i", (
int)data);
return true;
}
};
class TestWindow :
public PG_Window {
public:
TestWindow(
PG_Widget* parent,
const PG_Rect& r,
char* windowtext);
virtual ~TestWindow() {};
void Dummy() {};
bool handle_show_window() {
Show(
true);
return true;
}
bool handler_slider_btntrans(
long data) {
b->SetTransparency(static_cast<Uint8>(data));
b->Update();
progress->SetTransparency(static_cast<Uint8>(data));
progress->Update();
return true;
}
protected:
bool handleButtonClick(
PG_Button* button);
bool handleScrollPos(
PG_ScrollBar* widget,
long data);
bool handleScrollTrack(
PG_ScrollBar* widget,
long data);
private:
PG_ProgressBar* progress;
PG_WidgetList* WidgetList;
PG_Button* b;
};
TestWindow::TestWindow(
PG_Widget* parent,
const PG_Rect& r,
char* windowtext) :
PG_Window(parent, r, windowtext, DEFAULT)
{
WidgetList =
new PG_WidgetList(
this,
PG_Rect(30, 40, 220, 250));
WidgetList->SetDirtyUpdate(
false);
WidgetList->SetTransparency(0);
WidgetList->SetBackground(
"default/wnd_close.bmp", BKMODE_TILE, 0xFF);
WidgetList->SetBackgroundBlend(0);
WidgetList->EnableScrollBar(
true, PG_ScrollBar::VERTICAL);
WidgetList->EnableScrollBar(
true, PG_ScrollBar::HORIZONTAL);
(
new PG_Button(
this,
PG_Rect(260,130,110,30),
"<< ADD", 100))->sigClick.connect(slot(*
this, &TestWindow::handleButtonClick));
(
new PG_Button(
this,
PG_Rect(260,165,110,30),
">> REMOVE", 101))->sigClick.connect(slot(*
this, &TestWindow::handleButtonClick));
b =
new PG_Button(WidgetList,
PG_Rect(0,0, 400,50),
"YES", PG_Button::YES);
b->SetTransparency(128,128,128);
b->SetFontName(
"qnx/font.ttf");
PG_Slider* s =
new PG_Slider(WidgetList,
PG_Rect(0, 0, 200,20), PG_ScrollBar::HORIZONTAL);
s->
SetRange(0,255);
s->
SetTransparency(200);
s->
SetPosition(50);
s->
sigSlide.connect(slot(*
this, &TestWindow::handler_slider_btntrans));
s->
sigSlideEnd.connect(slot(*
this, &TestWindow::handler_slider_btntrans));
new PG_LineEdit(WidgetList,
PG_Rect(0,0,80,30));
new PG_CheckButton(WidgetList,
PG_Rect(0,0,200,25),
"CheckButton 2");
progress =
new PG_ProgressBar(
this,
PG_Rect(260, 90, 150, 25));
progress->SetTransparency(128);
progress->SetName(
"MyProgressBar");
progress->SetID(1001);
progress->SetFontAlpha(128);
PG_ScrollBar* scroll =
new PG_ScrollBar(
this,
PG_Rect(415,90,20,150));
scroll->
SetID(1);
scroll->
sigScrollPos.connect(slot(*
this, &TestWindow::handleScrollPos));
scroll->
sigScrollTrack.connect(slot(*
this, &TestWindow::handleScrollPos));
scroll->
SetRange(0, 100);
PG_ScrollBar* scroll1 =
new PG_ScrollBar(
this,
PG_Rect(435,90,20,150));
scroll1->
SetID(2);
scroll1->
sigScrollPos.connect(slot(*
this, &TestWindow::handleScrollPos));
scroll1->
sigScrollTrack.connect(slot(*
this, &TestWindow::handleScrollPos));
scroll1->
SetRange(0, 255);
PG_DropDown* drop =
new PG_DropDown(
this,
PG_Rect(260, 60, 200,25));
drop->
SetIndent(5);
drop->
SetAlignment(PG_Label::CENTER);
drop->
AddItem(
"Under construction");
drop->
AddItem(
"Item 1");
drop->
AddItem(
"Item 2");
drop->
AddItem(
"Item 3");
drop->
AddItem(
"Item 4");
drop->
AddItem(
"Item 5");
drop->
AddItem(
"Item 6");
}
bool TestWindow::handleScrollPos(PG_ScrollBar* widget,
long data){
int id = widget->
GetID();
if(
id == 1){
progress->SetProgress(data);
return true;
}
if(
id == 2){
SetTransparency((
unsigned char)data);
Update();
return true;
}
return false;
}
bool TestWindow::handleScrollTrack(PG_ScrollBar* widget,
long data) {
int id = widget->
GetID();
if(
id == 1){
progress->SetProgress(data);
return true;
}
if(
id == 2){
SetTransparency((
unsigned char)data);
Update();
return true;
}
return false;
}
bool TestWindow::handleButtonClick(PG_Button* button) {
static int label=0;
int id = button->
GetID();
PG_Window::handleButtonClick(button);
if(
id == 100) {
PG_Label* l =
new PG_Label(WidgetList,
PG_Rect(0,0,220,25),
"");
l->
SetAlignment(PG_Label::CENTER);
l->
SetTextFormat(
"Label %i", ++label);
return true;
}
if(
id == 101) {
PG_Widget* w = WidgetList->FindWidget(4);
PG_LogDBG(
"FindWidget(4) = %p", w);
if(w != NULL) {
delete w;
}
return true;
}
return false;
}
bool handle_menu_click(
PG_PopupMenu::MenuItem* item, PG_Pointer clientdata) {
std::cout <<
"menu item '" << item->
getId() <<
"' (\""
<< item->
getCaption() <<
"\") clicked" << std::endl;
switch (item->
getId()) {
case 5:
static_cast<TestWindow*>(clientdata)->Show();
break;
case 6:
static_cast<PG_Application*>(clientdata)->Quit();
break;
}
return true;
}
void PrintChildObjects(
PG_RectList *RectList,
char *TabSpace) {
char tab[20];
strcpy(tab, TabSpace);
if (RectList == NULL) {
return;
}
PG_Widget* list = RectList->
first();
const char* name = NULL;
while(list != NULL) {
name = list->
GetName();
PG_LogMSG(
"%s %s",TabSpace,name);
sprintf(tab,
" %s",TabSpace);
PrintChildObjects(list->
GetChildList(), tab);
list = list->
next();
}
}
bool handle_list() {
PG_LogMSG(
" ---- List of objects ----\n");
PrintChildObjects(PG_Widget::GetWidgetList(),
" +");
PG_LogMSG(
" ---- End of list ----\n");
return true;
}
int main(
int argc,
char* argv[]) {
char theme[20];
bool bTestMode =
false;
strcpy(theme,
"default");
Uint32 flags = SDL_SWSURFACE;
int bpp = 0;
int resx = RESX, resy = RESY;
PG_Application app;
for(
int c=1; c<argc; c++) {
if(argv[c][0] !=
'-') {
strcpy(theme, argv[c]);
}
if(strcmp(argv[c],
"-f") == 0) {
flags |= SDL_FULLSCREEN;
}
if(strcmp(argv[c],
"-t") == 0) {
bTestMode =
true;
}
if(strcmp(argv[c],
"-hw") == 0) {
flags |= SDL_HWSURFACE;
flags ^= SDL_SWSURFACE;
}
if(strcmp(argv[c],
"-bpp") == 0) {
bpp = atoi(argv[++c]);
}
if(strcmp(argv[c],
"-x") == 0) {
resx = atoi(argv[++c]);
}
if(strcmp(argv[c],
"-y") == 0) {
resy = atoi(argv[++c]);
}
}
Uint32 start_ticks = SDL_GetTicks();
if(!app.
LoadTheme(theme)) {
PG_LogERR(
"Unable to load theme \"%s\"", theme);
return -1;
}
PG_LogMSG(
"Loaded theme in %i ms", SDL_GetTicks() - start_ticks);
if(!app.
InitScreen(resx, resy, bpp, flags)){
printf(
"Resolution %dx%d not supported\n", resx, resy);
exit(-1);
}
PG_LogMSG(
"screen initialized after %i ms", SDL_GetTicks() - start_ticks);
app.
SetCursor(app.
GetTheme()->
FindSurface(
"Pointer",
"Pointer",
"normal"));
PG_Color color(255,255,255);
PG_LogMSG(
"creating 'wnd' after %i ms", SDL_GetTicks() - start_ticks);
TestWindow wnd(NULL,
PG_Rect(100,100,500,300),
"My first Testwindow");
wnd.SetTransparency(0);
wnd.SetName(
"WindowOne");
wnd.SetID(100);
PG_LogMSG(
"creating 'wnd1' after %i ms", SDL_GetTicks() - start_ticks);
TestWindow wnd1(NULL,
PG_Rect(50,50,500,300),
"My 2nd Testwindow");
wnd1.SetTransparency(0);
wnd1.SetName(
"WindowTwo");
wnd1.SetID(101);
PG_RadioButton radio1(NULL,
PG_Rect(50,0,200,25),
"RadioButton 1");
PG_RadioButton radio2(NULL,
PG_Rect(50,25,200,25),
"RadioButton 2", &radio1);
PG_RadioButton radio3(NULL,
PG_Rect(50,50,200,25),
"RadioButton 3", &radio1);
radio3.
SetSizeByText();
radio1.
SetAlignment(PG_Label::RIGHT);
PG_RadioButton radio4(NULL,
PG_Rect(50,90,200,25),
"RadioButton 4");
PG_RadioButton radio5(NULL,
PG_Rect(50,115,200,25),
"RadioButton 5", &radio4);
PG_RadioButton radio6(NULL,
PG_Rect(50,140,200,25),
"RadioButton 6", &radio4);
PG_CheckButton check1(NULL,
PG_Rect(300,140,180,25),
"CheckButton 1");
PG_PopupMenu popmenu(NULL, 425, 140,
"My Menu");
PG_PopupMenu submenu(NULL, 425, 140,
"My SubMenu");
PG_PopupMenu subsubmenu(NULL, 425, 140,
"");
submenu.
sigSelectMenuItem.connect(slot(handle_menu_click), NULL);
subsubmenu.
sigSelectMenuItem.connect(slot(handle_menu_click), NULL);
subsubmenu.
addMenuItem(
"Mordor", 1).
addMenuItem(
"Minas Morgul", 2).
addMenuItem(
"Orodruin", 3);
submenu.
addMenuItem(
"Grendel", 1).
addMenuItem(
"Beowulf", 2).
addMenuItem(
"Hrothgar", 3).
addMenuItem(
"Long ago", &subsubmenu);
popmenu.
addMenuItem(
"Tasty", 1, slot(handle_menu_click)).
addMenuItem(
"Even tastier", 2, slot(handle_menu_click)).
addMenuItem(
"I'm third here...", 3, slot(handle_menu_click)).
addMenuItem(
"And I'm fourth", 4, slot(handle_menu_click)).
addMenuItem(
"Saga", &submenu).
addSeparator().
addMenuItem(
"Open Window", 5, slot(handle_menu_click), &wnd).
addMenuItem(
"Quit", 6, slot(handle_menu_click), &app);
popmenu.
disableItem(2);
PG_MenuBar menubar(NULL,
PG_Rect(resx-300, 0, 300, 30));
menubar.
Add(
"PopMe 2", &popmenu);
PG_PopupMenu editmenu(NULL, 0 ,0, NULL);
editmenu.
addMenuItem(
"Cut", 1);
editmenu.
addMenuItem(
"Copy", 2);
editmenu.
addMenuItem(
"Paste", 3);
menubar.
Add(
"Edit", &editmenu);
menubar.
Show();
radio1.
Show();
radio2.
Show();
radio3.
Show();
radio4.
Show();
radio5.
Show();
radio6.
Show();
check1.
Show();
PG_ScrollBar scroll(NULL,
PG_Rect(50, 200, 300, 20), PG_ScrollBar::HORIZONTAL );
scroll.
Show();
PG_MaskEdit edit(NULL,
PG_Rect(260,0,200,25));
edit.
SetMask(
"###.###.###.###");
edit.
SetValidKeys(
"1234567890");
edit.
Show();
MySliderLabel slider_label(NULL,
PG_Rect(360, 250, 50,20),
"5");
slider_label.Show();
PG_Slider slider(NULL,
PG_Rect(50, 250, 300,20), PG_ScrollBar::HORIZONTAL);
slider.
SetRange(5,50);
slider.
sigSlide.connect(slot(slider_label, &MySliderLabel::handler_slider));
slider.
sigSlideEnd.connect(slot(slider_label, &MySliderLabel::handler_slider));
slider.
Show();
PG_Button popbtn(NULL,
PG_Rect(430, 250,100,25),
"Pop me");
popbtn.
sigClick.connect(slot(handle_popup), (PG_Pointer)&popmenu);
popbtn.
Show();
PG_SpinnerBox spin(NULL,
PG_Rect(550,250,130,25));
spin.
Show();
PG_DropDown drop(NULL,
PG_Rect(50, 280, 300,25));
drop.
AddItem(
"Under construction");
drop.
AddItem(
"Item 1");
drop.
AddItem(
"Item 2");
drop.
AddItem(
"Item 3");
drop.
AddItem(
"Item 4");
drop.
AddItem(
"Item 5");
drop.
AddItem(
"Item 6");
new PG_ListBoxItem(&drop, 25,
"Item 7");
new PG_ListBoxItem(&drop, 25,
"Item 8");
new PG_ListBoxItem(&drop, 25,
"Item 9");
drop.
SetIndent(5);
slider.
sigSlide.connect(slot(hande_slideIndent), (PG_Pointer)&drop);
slider.
sigSlideEnd.connect(slot(hande_slideIndent), (PG_Pointer)&drop);
drop.
Show();
PG_Button toggle(NULL,
PG_Rect(200, 350, 100, 30),
"Toggle me");
toggle.
sigClick.connect(slot(handle_toggle), (PG_Pointer)&toggle);
toggle.
SetToggle(
true);
toggle.
Show();
PG_Button list(NULL,
PG_Rect(400,450,100,30),
"List", PG_Button::OK);
list.
sigClick.connect(slot(handle_list));
list.
Show();
PG_Button quit(NULL,
PG_Rect(600,450,100,30),
"Quit", PG_Button::CLOSE);
quit.
sigClick.connect(slot(handle_exit), (PG_Pointer)&app);
quit.
Show();
PG_Button show_wnd(NULL,
PG_Rect(500,450,100,30),
"Window", PG_Button::APPLY);
show_wnd.
sigClick.connect(slot(wnd, &TestWindow::handle_show_window));
show_wnd.
Show();
PG_MultiLineEdit text(NULL,
PG_Rect(resx - 300, 35, 300, 150));
text.
SetText(
"Once upon a time, in a galaxy far far away...\n...\n...\n...\n...\n...\n...\nand they lived happily till once upon a time, in a galaxy far far away...\n[INSERT STORY HERE]");
text.
Show();
wnd.Show();
wnd1.Show();
PG_LogMSG(
"app ready after %i ms", SDL_GetTicks() - start_ticks);
app.
ShowCursor(PG_Application::SOFTWARE);
PG_LogMSG(
"testing the widget finding methods");
PG_Widget *tmp;
tmp =
PG_Application::GetWidgetByName(
"WindowOne");
if (tmp)
PG_LogMSG(
"'WindowOne' found by name (id %d)", tmp->
GetID());
tmp =
PG_Application::GetWidgetById(100);
if (tmp)
PG_LogMSG(
"'100' found by ID (name '%s')", tmp->
GetName());
tmp =
PG_Application::GetWidgetById(101);
if (tmp)
PG_LogMSG(
"'101' found by ID (name '%s')", tmp->
GetName());
PG_LogMSG(
"testing the child finding methods");
tmp = wnd.FindChild(
"MyProgressBar");
if (tmp)
PG_LogMSG(
"sought for 'MyProgressBar' and found it (id '%d')",
tmp->
GetID());
tmp = wnd.FindChild(1001);
if (tmp)
PG_LogMSG(
"sought for '1001' and found it (name '%s')",
tmp->
GetName());
if(!bTestMode) {
app.
Run();
return EXIT_SUCCESS;
}
PG_LogMSG(
"Starting benchmark ... Wait");
start_ticks = SDL_GetTicks();
int iter = 500;
for(
int i=0; i<iter; i++) {
PG_Widget::UpdateScreen();
}
int ticks = SDL_GetTicks() - start_ticks;
PG_LogMSG(
"did %i iterations in %i ms", iter, ticks);
PG_LogMSG(
"~%2.2fms per iteration", (
float)ticks/(
float)iter);
return EXIT_SUCCESS;
}
00001
#include "paragui.h"
00002
00003
#include "pgapplication.h"
00004
#include "pgbutton.h"
00005
#include "pgwidgetlist.h"
00006
#include "pglabel.h"
00007
#include "pgwindow.h"
00008
#include "pgmaskedit.h"
00009
#include "pgscrollbar.h"
00010
#include "pgprogressbar.h"
00011
#include "pgradiobutton.h"
00012
#include "pgthemewidget.h"
00013
#include "pgcheckbutton.h"
00014
#include "pgslider.h"
00015
#include "pglistbox.h"
00016
#include "pgcolumnitem.h"
00017
#include "pgdropdown.h"
00018
#include "pgpopupmenu.h"
00019
#include "pgspinnerbox.h"
00020
#include "pglog.h"
00021
#include "pgmenubar.h"
00022
#include "pgtheme.h"
00023
#include "pgmultilineedit.h"
00024
00025
#include <iostream>
00026
00027
#define RESX 800
00028
#define RESY 600
00029
00030
void Splash() {
00031
PG_ThemeWidget splash(NULL,
PG_Rect(100,100,600,400),
true);
00032
PG_ThemeWidget splash1(&splash,
PG_Rect(10,10,580,380));
00033
PG_ThemeWidget splash2(&splash1,
PG_Rect(10,10,560,340));
00034
PG_Label l(&splash2,
PG_Rect(10,10,540,320),
"I'm a splash screen");
00035 l.
SetAlignment(PG_Label::CENTER);
00036
00037 splash.
Show();
00038 SDL_Delay(5000);
00039 splash.
Hide();
00040 }
00041
00042
bool handle_popup(PG_Pointer clientdata) {
00043
PG_PopupMenu* pop = (
PG_PopupMenu*)clientdata;
00044
00045 pop->
trackMenu(10, 10);
00046
00047
return true;
00048 }
00049
00050
bool handle_exit(PG_Pointer clientdata) {
00051
PG_Application* app = (
PG_Application*)clientdata;
00052 app->
Quit();
00053
return true;
00054 }
00055
00056
bool handle_toggle(PG_Pointer clientdata) {
00057 PG_Button* b = (PG_Button*)clientdata;
00058
if (b->
GetPressed()) {
00059
PG_LogMSG(
"Button pressed");
00060 }
00061
else {
00062
PG_LogMSG(
"Button released");
00063 }
00064
return true;
00065 }
00066
00067
00068
bool hande_slideIndent(PG_ScrollBar* s,
long pos, PG_Pointer data) {
00069 PG_DropDown* drop = static_cast<PG_DropDown*>(data);
00070 drop->
SetIndent(pos);
00071
return true;
00072 }
00073
00074
00075
00076
class MySliderLabel :
public PG_Label {
00077
public:
00078 MySliderLabel(
PG_Widget* parent,
const PG_Rect& r,
char* text) :
PG_Label(parent,r,text) {
00079 };
00080
00081
bool handler_slider(
long data) {
00082 SetTextFormat(
"%i", (
int)data);
00083
return true;
00084 }
00085 };
00086
00087
00088
00089
class TestWindow :
public PG_Window {
00090
public:
00091
00092 TestWindow(
PG_Widget* parent,
const PG_Rect& r,
char* windowtext);
00093
virtual ~TestWindow() {};
00094
00095
void Dummy() {};
00096
00098
bool handle_show_window() {
00099
Show(
true);
00100
return true;
00101 }
00102
00104
bool handler_slider_btntrans(
long data) {
00105
00106 b->SetTransparency(static_cast<Uint8>(data));
00107 b->Update();
00108
00109
00110 progress->SetTransparency(static_cast<Uint8>(data));
00111 progress->Update();
00112
return true;
00113 }
00114
00115
protected:
00116
00117
bool handleButtonClick(PG_Button* button);
00118
bool handleScrollPos(PG_ScrollBar* widget,
long data);
00119
bool handleScrollTrack(PG_ScrollBar* widget,
long data);
00120
00121
private:
00122 PG_ProgressBar* progress;
00123 PG_WidgetList* WidgetList;
00124 PG_Button* b;
00125 };
00126
00127
00128 TestWindow::TestWindow(
PG_Widget* parent,
const PG_Rect& r,
char* windowtext) :
00129
PG_Window(parent, r, windowtext, DEFAULT)
00130 {
00131 WidgetList =
new PG_WidgetList(
this,
PG_Rect(30, 40, 220, 250));
00132 WidgetList->SetDirtyUpdate(
false);
00133 WidgetList->SetTransparency(0);
00134 WidgetList->SetBackground(
"default/wnd_close.bmp", BKMODE_TILE, 0xFF);
00135 WidgetList->SetBackgroundBlend(0);
00136
00137 WidgetList->EnableScrollBar(
true, PG_ScrollBar::VERTICAL);
00138 WidgetList->EnableScrollBar(
true, PG_ScrollBar::HORIZONTAL);
00139
00140 (
new PG_Button(
this,
PG_Rect(260,130,110,30),
"<< ADD", 100))->sigClick.connect(slot(*
this, &TestWindow::handleButtonClick));
00141
00142 (
new PG_Button(
this,
PG_Rect(260,165,110,30),
">> REMOVE", 101))->sigClick.connect(slot(*
this, &TestWindow::handleButtonClick));
00143
00144 b =
new PG_Button(WidgetList,
PG_Rect(0,0, 400,50),
"YES", PG_Button::YES);
00145 b->SetTransparency(128,128,128);
00146 b->SetFontName(
"qnx/font.ttf");
00147
00148 PG_Slider* s =
new PG_Slider(WidgetList,
PG_Rect(0, 0, 200,20), PG_ScrollBar::HORIZONTAL);
00149 s->
SetRange(0,255);
00150 s->
SetTransparency(200);
00151 s->
SetPosition(50);
00152
00153 s->
sigSlide.connect(slot(*
this, &TestWindow::handler_slider_btntrans));
00154 s->
sigSlideEnd.connect(slot(*
this, &TestWindow::handler_slider_btntrans));
00155
00156
new PG_LineEdit(WidgetList,
PG_Rect(0,0,80,30));
00157
new PG_CheckButton(WidgetList,
PG_Rect(0,0,200,25),
"CheckButton 2");
00158
00159 progress =
new PG_ProgressBar(
this,
PG_Rect(260, 90, 150, 25));
00160 progress->SetTransparency(128);
00161 progress->SetName(
"MyProgressBar");
00162 progress->SetID(1001);
00163 progress->SetFontAlpha(128);
00164
00165 PG_ScrollBar* scroll =
new PG_ScrollBar(
this,
PG_Rect(415,90,20,150));
00166 scroll->
SetID(1);
00167 scroll->
sigScrollPos.connect(slot(*
this, &TestWindow::handleScrollPos));
00168 scroll->
sigScrollTrack.connect(slot(*
this, &TestWindow::handleScrollPos));
00169 scroll->
SetRange(0, 100);
00170
00171 PG_ScrollBar* scroll1 =
new PG_ScrollBar(
this,
PG_Rect(435,90,20,150));
00172 scroll1->
SetID(2);
00173 scroll1->
sigScrollPos.connect(slot(*
this, &TestWindow::handleScrollPos));
00174 scroll1->
sigScrollTrack.connect(slot(*
this, &TestWindow::handleScrollPos));
00175 scroll1->
SetRange(0, 255);
00176
00177 PG_DropDown* drop =
new PG_DropDown(
this,
PG_Rect(260, 60, 200,25));
00178 drop->
SetIndent(5);
00179 drop->
SetAlignment(PG_Label::CENTER);
00180 drop->
AddItem(
"Under construction");
00181 drop->
AddItem(
"Item 1");
00182 drop->
AddItem(
"Item 2");
00183 drop->
AddItem(
"Item 3");
00184 drop->
AddItem(
"Item 4");
00185 drop->
AddItem(
"Item 5");
00186 drop->
AddItem(
"Item 6");
00187
00188 }
00189
00190
bool TestWindow::handleScrollPos(PG_ScrollBar* widget,
long data){
00191
int id = widget->
GetID();
00192
00193
if(
id == 1){
00194 progress->SetProgress(data);
00195
return true;
00196 }
00197
00198
if(
id == 2){
00199 SetTransparency((
unsigned char)data);
00200
Update();
00201
return true;
00202 }
00203
00204
return false;
00205 }
00206
00207
bool TestWindow::handleScrollTrack(PG_ScrollBar* widget,
long data) {
00208
int id = widget->
GetID();
00209
00210
if(
id == 1){
00211 progress->SetProgress(data);
00212
return true;
00213 }
00214
00215
if(
id == 2){
00216 SetTransparency((
unsigned char)data);
00217
Update();
00218
return true;
00219 }
00220
00221
return false;
00222 }
00223
00224
bool TestWindow::handleButtonClick(PG_Button* button) {
00225
static int label=0;
00226
int id = button->
GetID();
00227
00228
PG_Window::handleButtonClick(button);
00229
00230
if(
id == 100) {
00231
PG_Label* l =
new PG_Label(WidgetList,
PG_Rect(0,0,220,25),
"");
00232 l->
SetAlignment(PG_Label::CENTER);
00233 l->
SetTextFormat(
"Label %i", ++label);
00234
return true;
00235 }
00236
00237
if(
id == 101) {
00238
PG_Widget* w = WidgetList->FindWidget(4);
00239
PG_LogDBG(
"FindWidget(4) = %p", w);
00240
if(w != NULL) {
00241
delete w;
00242 }
00243
00244
return true;
00245 }
00246
00247
return false;
00248 }
00249
00250
bool handle_menu_click(
PG_PopupMenu::MenuItem* item, PG_Pointer clientdata) {
00251 std::cout <<
"menu item '" << item->
getId() <<
"' (\""
00252 << item->
getCaption() <<
"\") clicked" << std::endl;
00253
00254
switch (item->
getId()) {
00255
case 5:
00256 static_cast<TestWindow*>(clientdata)->Show();
00257
break;
00258
00259
case 6:
00260 static_cast<PG_Application*>(clientdata)->Quit();
00261
break;
00262 }
00263
00264
return true;
00265 }
00266
00267
void PrintChildObjects(
PG_RectList *RectList,
char *TabSpace) {
00268
char tab[20];
00269 strcpy(tab, TabSpace);
00270
00271
if (RectList == NULL) {
00272
return;
00273 }
00274
00275
PG_Widget* list = RectList->
first();
00276
const char* name = NULL;
00277
00278
while(list != NULL) {
00279 name = list->
GetName();
00280
00281
PG_LogMSG(
"%s %s",TabSpace,name);
00282
00283 sprintf(tab,
" %s",TabSpace);
00284 PrintChildObjects(list->
GetChildList(), tab);
00285
00286 list = list->
next();
00287 }
00288
00289 }
00290
00291
bool handle_list() {
00292
00293
PG_LogMSG(
" ---- List of objects ----\n");
00294 PrintChildObjects(PG_Widget::GetWidgetList(),
" +");
00295
PG_LogMSG(
" ---- End of list ----\n");
00296
00297
return true;
00298 }
00299
00300
int main(
int argc,
char* argv[]) {
00301
char theme[20];
00302
bool bTestMode =
false;
00303
00304 strcpy(theme,
"default");
00305
00306
00307 Uint32 flags = SDL_SWSURFACE;
00308
int bpp = 0;
00309
00310
int resx = RESX, resy = RESY;
00311
00312
00313
PG_Application app;
00314
00315
for(
int c=1; c<argc; c++) {
00316
00317
if(argv[c][0] !=
'-') {
00318 strcpy(theme, argv[c]);
00319 }
00320
00321
if(strcmp(argv[c],
"-f") == 0) {
00322 flags |= SDL_FULLSCREEN;
00323 }
00324
00325
if(strcmp(argv[c],
"-t") == 0) {
00326 bTestMode =
true;
00327 }
00328
00329
if(strcmp(argv[c],
"-hw") == 0) {
00330 flags |= SDL_HWSURFACE;
00331 flags ^= SDL_SWSURFACE;
00332 }
00333
00334
if(strcmp(argv[c],
"-bpp") == 0) {
00335 bpp = atoi(argv[++c]);
00336 }
00337
00338
if(strcmp(argv[c],
"-x") == 0) {
00339 resx = atoi(argv[++c]);
00340 }
00341
00342
if(strcmp(argv[c],
"-y") == 0) {
00343 resy = atoi(argv[++c]);
00344 }
00345 }
00346
00347 Uint32 start_ticks = SDL_GetTicks();
00348
00349
if(!app.
LoadTheme(theme)) {
00350
PG_LogERR(
"Unable to load theme \"%s\"", theme);
00351
return -1;
00352 }
00353
00354
PG_LogMSG(
"Loaded theme in %i ms", SDL_GetTicks() - start_ticks);
00355
00356
if(!app.
InitScreen(resx, resy, bpp, flags)){
00357 printf(
"Resolution %dx%d not supported\n", resx, resy);
00358 exit(-1);
00359 }
00360
00361
PG_LogMSG(
"screen initialized after %i ms", SDL_GetTicks() - start_ticks);
00362
00363 app.
SetCursor(app.
GetTheme()->
FindSurface(
"Pointer",
"Pointer",
"normal"));
00364
00365
00366
00367
PG_Color color(255,255,255);
00368
00369
PG_LogMSG(
"creating 'wnd' after %i ms", SDL_GetTicks() - start_ticks);
00370
00371
00372 TestWindow wnd(NULL,
PG_Rect(100,100,500,300),
"My first Testwindow");
00373 wnd.SetTransparency(0);
00374 wnd.SetName(
"WindowOne");
00375 wnd.SetID(100);
00376
00377
PG_LogMSG(
"creating 'wnd1' after %i ms", SDL_GetTicks() - start_ticks);
00378
00379 TestWindow wnd1(NULL,
PG_Rect(50,50,500,300),
"My 2nd Testwindow");
00380 wnd1.SetTransparency(0);
00381 wnd1.SetName(
"WindowTwo");
00382 wnd1.SetID(101);
00383
00384
00385
PG_RadioButton radio1(NULL,
PG_Rect(50,0,200,25),
"RadioButton 1");
00386
PG_RadioButton radio2(NULL,
PG_Rect(50,25,200,25),
"RadioButton 2", &radio1);
00387
PG_RadioButton radio3(NULL,
PG_Rect(50,50,200,25),
"RadioButton 3", &radio1);
00388 radio3.
SetSizeByText();
00389 radio1.
SetAlignment(PG_Label::RIGHT);
00390
00391
PG_RadioButton radio4(NULL,
PG_Rect(50,90,200,25),
"RadioButton 4");
00392
PG_RadioButton radio5(NULL,
PG_Rect(50,115,200,25),
"RadioButton 5", &radio4);
00393
PG_RadioButton radio6(NULL,
PG_Rect(50,140,200,25),
"RadioButton 6", &radio4);
00394
00395
PG_CheckButton check1(NULL,
PG_Rect(300,140,180,25),
"CheckButton 1");
00396
PG_PopupMenu popmenu(NULL, 425, 140,
"My Menu");
00397
PG_PopupMenu submenu(NULL, 425, 140,
"My SubMenu");
00398
PG_PopupMenu subsubmenu(NULL, 425, 140,
"");
00399
00400 submenu.
sigSelectMenuItem.connect(slot(handle_menu_click), NULL);
00401 subsubmenu.
sigSelectMenuItem.connect(slot(handle_menu_click), NULL);
00402
00403 subsubmenu.
addMenuItem(
"Mordor", 1).
00404 addMenuItem(
"Minas Morgul", 2).
00405 addMenuItem(
"Orodruin", 3);
00406
00407 submenu.
addMenuItem(
"Grendel", 1).
00408 addMenuItem(
"Beowulf", 2).
00409 addMenuItem(
"Hrothgar", 3).
00410 addMenuItem(
"Long ago", &subsubmenu);
00411
00412 popmenu.
addMenuItem(
"Tasty", 1, slot(handle_menu_click)).
00413 addMenuItem(
"Even tastier", 2, slot(handle_menu_click)).
00414 addMenuItem(
"I'm third here...", 3, slot(handle_menu_click)).
00415 addMenuItem(
"And I'm fourth", 4, slot(handle_menu_click)).
00416 addMenuItem(
"Saga", &submenu).
00417 addSeparator().
00418 addMenuItem(
"Open Window", 5, slot(handle_menu_click), &wnd).
00419 addMenuItem(
"Quit", 6, slot(handle_menu_click), &app);
00420
00421 popmenu.
disableItem(2);
00422
00423
PG_MenuBar menubar(NULL,
PG_Rect(resx-300, 0, 300, 30));
00424 menubar.
Add(
"PopMe 2", &popmenu);
00425
00426
PG_PopupMenu editmenu(NULL, 0 ,0, NULL);
00427 editmenu.
addMenuItem(
"Cut", 1);
00428 editmenu.
addMenuItem(
"Copy", 2);
00429 editmenu.
addMenuItem(
"Paste", 3);
00430 menubar.
Add(
"Edit", &editmenu);
00431
00432 menubar.
Show();
00433
00434 radio1.
Show();
00435 radio2.
Show();
00436 radio3.
Show();
00437
00438 radio4.
Show();
00439 radio5.
Show();
00440 radio6.
Show();
00441
00442 check1.
Show();
00443
00444 PG_ScrollBar scroll(NULL,
PG_Rect(50, 200, 300, 20), PG_ScrollBar::HORIZONTAL );
00445 scroll.
Show();
00446
00447
PG_MaskEdit edit(NULL,
PG_Rect(260,0,200,25));
00448 edit.
SetMask(
"###.###.###.###");
00449 edit.
SetValidKeys(
"1234567890");
00450 edit.
Show();
00451
00452
00453 MySliderLabel slider_label(NULL,
PG_Rect(360, 250, 50,20),
"5");
00454 slider_label.Show();
00455
00456
00457 PG_Slider slider(NULL,
PG_Rect(50, 250, 300,20), PG_ScrollBar::HORIZONTAL);
00458 slider.
SetRange(5,50);
00459
00460
00461 slider.
sigSlide.connect(slot(slider_label, &MySliderLabel::handler_slider));
00462 slider.
sigSlideEnd.connect(slot(slider_label, &MySliderLabel::handler_slider));
00463
00464 slider.
Show();
00465
00466 PG_Button popbtn(NULL,
PG_Rect(430, 250,100,25),
"Pop me");
00467 popbtn.
sigClick.connect(slot(handle_popup), (PG_Pointer)&popmenu);
00468 popbtn.
Show();
00469
00470
PG_SpinnerBox spin(NULL,
PG_Rect(550,250,130,25));
00471 spin.
Show();
00472
00473 PG_DropDown drop(NULL,
PG_Rect(50, 280, 300,25));
00474
00475
00476 drop.
AddItem(
"Under construction");
00477 drop.
AddItem(
"Item 1");
00478 drop.
AddItem(
"Item 2");
00479 drop.
AddItem(
"Item 3");
00480 drop.
AddItem(
"Item 4");
00481 drop.
AddItem(
"Item 5");
00482 drop.
AddItem(
"Item 6");
00483
00484
00485
00486
00487
00488
new PG_ListBoxItem(&drop, 25,
"Item 7");
00489
new PG_ListBoxItem(&drop, 25,
"Item 8");
00490
new PG_ListBoxItem(&drop, 25,
"Item 9");
00491 drop.
SetIndent(5);
00492
00493 slider.
sigSlide.connect(slot(hande_slideIndent), (PG_Pointer)&drop);
00494 slider.
sigSlideEnd.connect(slot(hande_slideIndent), (PG_Pointer)&drop);
00495 drop.
Show();
00496
00497 PG_Button toggle(NULL,
PG_Rect(200, 350, 100, 30),
"Toggle me");
00498 toggle.
sigClick.connect(slot(handle_toggle), (PG_Pointer)&toggle);
00499 toggle.
SetToggle(
true);
00500 toggle.
Show();
00501
00502 PG_Button list(NULL,
PG_Rect(400,450,100,30),
"List", PG_Button::OK);
00503 list.
sigClick.connect(slot(handle_list));
00504 list.
Show();
00505
00506 PG_Button quit(NULL,
PG_Rect(600,450,100,30),
"Quit", PG_Button::CLOSE);
00507 quit.
sigClick.connect(slot(handle_exit), (PG_Pointer)&app);
00508 quit.
Show();
00509
00510 PG_Button show_wnd(NULL,
PG_Rect(500,450,100,30),
"Window", PG_Button::APPLY);
00511 show_wnd.
sigClick.connect(slot(wnd, &TestWindow::handle_show_window));
00512
00513 show_wnd.
Show();
00514
00515
PG_MultiLineEdit text(NULL,
PG_Rect(resx - 300, 35, 300, 150));
00516 text.
SetText(
"Once upon a time, in a galaxy far far away...\n...\n...\n...\n...\n...\n...\nand they lived happily till once upon a time, in a galaxy far far away...\n[INSERT STORY HERE]");
00517 text.
Show();
00518
00519
00520 wnd.Show();
00521 wnd1.Show();
00522
00523
PG_LogMSG(
"app ready after %i ms", SDL_GetTicks() - start_ticks);
00524 app.
ShowCursor(PG_Application::SOFTWARE);
00525
00526
PG_LogMSG(
"testing the widget finding methods");
00527
PG_Widget *tmp;
00528
00529 tmp =
PG_Application::GetWidgetByName(
"WindowOne");
00530
if (tmp)
00531
PG_LogMSG(
"'WindowOne' found by name (id %d)", tmp->
GetID());
00532
00533 tmp =
PG_Application::GetWidgetById(100);
00534
if (tmp)
00535
PG_LogMSG(
"'100' found by ID (name '%s')", tmp->
GetName());
00536
00537 tmp =
PG_Application::GetWidgetById(101);
00538
if (tmp)
00539
PG_LogMSG(
"'101' found by ID (name '%s')", tmp->
GetName());
00540
00541
PG_LogMSG(
"testing the child finding methods");
00542 tmp = wnd.FindChild(
"MyProgressBar");
00543
if (tmp)
00544
PG_LogMSG(
"sought for 'MyProgressBar' and found it (id '%d')",
00545 tmp->
GetID());
00546 tmp = wnd.FindChild(1001);
00547
if (tmp)
00548
PG_LogMSG(
"sought for '1001' and found it (name '%s')",
00549 tmp->
GetName());
00550
00551
if(!bTestMode) {
00552
00553 app.
Run();
00554
return EXIT_SUCCESS;
00555 }
00556
00557
PG_LogMSG(
"Starting benchmark ... Wait");
00558 start_ticks = SDL_GetTicks();
00559
int iter = 500;
00560
00561
for(
int i=0; i<iter; i++) {
00562
PG_Widget::UpdateScreen();
00563 }
00564
00565
int ticks = SDL_GetTicks() - start_ticks;
00566
PG_LogMSG(
"did %i iterations in %i ms", iter, ticks);
00567
PG_LogMSG(
"~%2.2fms per iteration", (
float)ticks/(
float)iter);
00568
00569
return EXIT_SUCCESS;
00570 }
The ParaGUI Project - Alexander Pipelka