📄 sample_demo7.cpp
字号:
/***********************************************************************
filename: Sample_Demo7.cpp
created: 20/8/2005
author: Paul D Turner
*************************************************************************/
/***************************************************************************
* Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#include "Sample_Demo7.h"
#include "CEGUI.h"
#include "CEGuiBaseApplication.h"
#include <cstdlib>
int main(int argc, char *argv[])
{
// This is a basic start-up for the sample application which is
// object orientated in nature, so we just need an instance of
// the CEGuiSample based object and then tell that sample application
// to run. All of the samples will use code similar to this in the
// main/WinMain function.
Demo7Sample app;
return app.run();
}
/*************************************************************************
Sample specific initialisation goes here.
*************************************************************************/
bool Demo7Sample::initialiseSample()
{
using namespace CEGUI;
// we will use of the WindowManager.
WindowManager& winMgr = WindowManager::getSingleton();
// load scheme and set up defaults
SchemeManager::getSingleton().loadScheme("TaharezLook.scheme");
System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
FontManager::getSingleton().createFont("Commonwealth-10.font");
// load an image to use as a background
ImagesetManager::getSingleton().createImagesetFromImageFile("BackgroundImage", "GPN-2000-001437.tga");
// here we will use a StaticImage as the root, then we can use it to place a background image
Window* background = winMgr.createWindow("TaharezLook/StaticImage", "background_wnd");
// set position and size
background->setPosition(UVector2(cegui_reldim(0), cegui_reldim( 0)));
background->setSize(UVector2(cegui_reldim(1), cegui_reldim( 1)));
// disable frame and standard background
background->setProperty("FrameEnabled", "false");
background->setProperty("BackgroundEnabled", "false");
// set the background image
background->setProperty("Image", "set:BackgroundImage image:full_image");
// install this as the root GUI sheet
System::getSingleton().setGUISheet(background);
// now we create a DefaultWindow which we will attach all the widgets to. We could
// have attached them to the background StaticImage, though we want to be a bit tricky
// since we do not wish the background to be faded by the slider - so we create this
// container window so we can affect all the other widgets, but leave the background
// unchanged.
Window* sheet = winMgr.createWindow("DefaultWindow", "root_wnd");
// attach this to the 'real' root
background->addChildWindow(sheet);
// do demo stuff
createDemoWindows();
initDemoEventWiring();
// success!
return true;
}
/*************************************************************************
Cleans up resources allocated in the initialiseSample call.
*************************************************************************/
void Demo7Sample::cleanupSample()
{
// nothing to do here!
}
/*************************************************************************
create the windows & widgets for this demo
*************************************************************************/
void Demo7Sample::createDemoWindows(void)
{
using namespace CEGUI;
WindowManager& winMgr = WindowManager::getSingleton();
Window* root = winMgr.getWindow("root_wnd");
// Create first frame window
FrameWindow* fwnd1 = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "Demo7/Window1"));
root->addChildWindow(fwnd1);
fwnd1->setMinSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
fwnd1->setMaxSize(UVector2(cegui_reldim(0.8f), cegui_reldim( 0.8f)));
fwnd1->setPosition(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
fwnd1->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
fwnd1->setText("Demo 7 - Window 1");
fwnd1->setCloseButtonEnabled(false);
// create second frame window
FrameWindow* fwnd2 = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "Demo7/Window2"));
root->addChildWindow(fwnd2);
fwnd2->setMinSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
fwnd2->setMaxSize(UVector2(cegui_reldim(0.8f), cegui_reldim( 0.8f)));
fwnd2->setPosition(UVector2(cegui_reldim(0.4f), cegui_reldim( 0.1f)));
fwnd2->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.6f)));
fwnd2->setText("Demo 7 - Window 2");
fwnd2->setCloseButtonEnabled(false);
// create third and final frame window.
FrameWindow* fwnd3 = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "Demo7/Window3"));
root->addChildWindow(fwnd3);
fwnd3->setMinSize(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
fwnd3->setMaxSize(UVector2(cegui_reldim(0.8f), cegui_reldim( 0.8f)));
fwnd3->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.4f)));
fwnd3->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
fwnd3->setText("Demo 7 - Window 3");
fwnd3->setCloseButtonEnabled(false);
// create quit button
PushButton* btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "Demo7/Window1/Quit"));
fwnd1->addChildWindow(btn);
btn->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
btn->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.1f)));
btn->setSize(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.1f)));
btn->setText("Exit Demo");
// create first radio-button for StaticImage image selection
RadioButton* rbtn = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton", "Demo7/Window1/Radio1"));
fwnd1->addChildWindow(rbtn);
rbtn->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
rbtn->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.23f)));
rbtn->setSize(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.075f)));
rbtn->setText("Option 1");
rbtn->setID(0);
// create second radio-button for StaticImage image selection
rbtn = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton", "Demo7/Window1/Radio2"));
fwnd1->addChildWindow(rbtn);
rbtn->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
rbtn->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.306f)));
rbtn->setSize(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.075f)));
rbtn->setText("Option 2");
rbtn->setID(1);
// create third radio-button for StaticImage image selection
rbtn = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton", "Demo7/Window1/Radio3"));
fwnd1->addChildWindow(rbtn);
rbtn->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
rbtn->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.382f)));
rbtn->setSize(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.075f)));
rbtn->setText("Option 3");
rbtn->setID(2);
// create checkbox to show / hide frame window 3 (with the multi-line editbox in it)
Checkbox* cbox = static_cast<Checkbox*>(winMgr.createWindow("TaharezLook/Checkbox", "Demo7/Window1/Checkbox"));
fwnd1->addChildWindow(cbox);
cbox->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
cbox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.48f)));
cbox->setSize(UVector2(cegui_reldim(0.45f), cegui_reldim( 0.075f)));
cbox->setText("Enable some option");
cbox->setSelected(true);
// create a static text with some information in.
Window* stxt = winMgr.createWindow("TaharezLook/StaticText", "Demo7/Window1/Text1");
fwnd1->addChildWindow(stxt);
stxt->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
stxt->setPosition(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.1f)));
stxt->setSize(UVector2(cegui_reldim(0.45f), cegui_reldim( 0.5f)));
stxt->setText("This is a re-creation of the original \"Demo7\" preview application, it shows many of the CEGUI widgets.");
stxt->setProperty("FrameEnabled", "false");
stxt->setProperty("BackgroundEnabled", "false");
stxt->setProperty("HorzFormatting", "WordWrapCentred");
// single line edit box widget
Editbox* ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "Demo7/Window1/Editbox"));
fwnd1->addChildWindow(ebox);
ebox->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
ebox->setPosition(UVector2(cegui_reldim(0.2f), cegui_reldim( 0.6f)));
ebox->setSize(UVector2(cegui_reldim(0.6f), cegui_reldim( 0.1f)));
ebox->setText("Single-line editbox");
// large vertical 'Taharez' scrollbar
Scrollbar* sbar = static_cast<Scrollbar*>(winMgr.createWindow("TaharezLook/LargeVerticalScrollbar", "Demo7/Window1/Scrollbar1"));
fwnd1->addChildWindow(sbar);
sbar->setMinSize(UVector2(cegui_reldim(0.01f), cegui_reldim( 0.1f)));
sbar->setMaxSize(UVector2(cegui_reldim(0.03f), cegui_reldim( 1.0f)));
sbar->setPosition(UVector2(cegui_reldim(0.06f), cegui_reldim( 0.6f)));
sbar->setSize(UVector2(cegui_reldim(0.06f), cegui_reldim( 0.38f)));
// Slider to affect display alpha and progress bars
Slider* sldr = static_cast<Slider*>(winMgr.createWindow("TaharezLook/Slider", "Demo7/Window1/Slider1"));
fwnd1->addChildWindow(sldr);
sldr->setMinSize(UVector2(cegui_reldim(0.01f), cegui_reldim( 0.1f)));
sldr->setMaxSize(UVector2(cegui_reldim(0.03f), cegui_reldim( 1.0f)));
sldr->setPosition(UVector2(cegui_reldim(0.9f), cegui_reldim( 0.625f)));
sldr->setSize(UVector2(cegui_reldim(0.03f), cegui_reldim( 0.28f)));
sldr->setCurrentValue(1.0f);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -