⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainmodule.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************
	filename: 	CEGUIOgre_TestDriver1.cpp
	created:	16/5/2004
	author:		Paul D Turner
	
	purpose:	Source code for application startup
*************************************************************************/
/*************************************************************************
    Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
    Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*************************************************************************/
/*************************************************************************
	This is a test driver application for CEGUI under Ogre.
*************************************************************************/
#include "OgrePrerequisites.h"
#include "CEGUI.h"
#include "Ogre.h"
#include "OgreStringConverter.h"

#include "renderers/OgreGUIRenderer/ogrerenderer.h"
#include "MainModule.h"

#include "boost/bind.hpp"

#include <cstdlib>

#if OGRE_PLATFORM == PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{
	// Create application object
	CEGUIOgre_TestDriver1 app;

	try {
		app.go();

		// cleanup for the CEGUI bits.
		app.cleanup();
	} catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == PLATFORM_WIN32
        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        std::cerr << "An exception has occured: " <<
            e.getFullDescription().c_str() << std::endl;
#endif
    }

    return 0;
}


/*************************************************************************
	createScene method - initialises CEGUI & adds some controls etc
*************************************************************************/
void CEGUIOgre_TestDriver1::createScene(void)
{
	// setup GUI system
	mGUIRenderer = new CEGUI::OgreRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, false, 3000);
	new CEGUI::System(mGUIRenderer);

	// load some GUI stuff for demo.
	try
	{
		using namespace CEGUI;

		Logger::getSingleton().setLoggingLevel(Informative);

		// load scheme and set up defaults
		SchemeManager::getSingleton().loadScheme((utf8*)"testscheme.xml");
		System::getSingleton().setDefaultMouseCursor((utf8*)"TaharezImagery", (utf8*)"MouseArrow");
		System::getSingleton().setDefaultFont((utf8*)"Tahoma-14");

		Window* sheet = WindowManager::getSingleton().createWindow((utf8*)"DefaultGUISheet", (utf8*)"root_wnd");
		System::getSingleton().setGUISheet(sheet);
		createCrazyPanel();

		// do demo stuff
		mMovieControl = new MovieLogic( mGUIRenderer );
		createDemoWindows();
		initDemoEventWiring();
	}
	// catch to prevent exit (errors will be logged).
	catch(CEGUI::Exception)
	{}

	mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");
}


/*************************************************************************
	create the windows & widgets for this demo
*************************************************************************/
void	CEGUIOgre_TestDriver1::createDemoWindows(void)
{
	using namespace CEGUI;

	WindowManager& winMgr = WindowManager::getSingleton();
	Window* root = winMgr.getWindow((utf8*)"root_wnd");

	FrameWindow* fwnd1 = (FrameWindow*)winMgr.createWindow((utf8*)"Taharez Frame Window", (utf8*)"Demo7/Window1");
	root->addChildWindow(fwnd1);
	fwnd1->setMinimumSize(Size(0.0f, 0.0f));
	fwnd1->setMaximumSize(Size(0.8f, 0.8f));
	fwnd1->setPosition(Point(0.0f, 0.0f));
	fwnd1->setSize(Size(0.5f, 0.5f));
	fwnd1->setText((utf8*)"OGG Player Controller");
	fwnd1->setCloseButtonEnabled(false);

	FrameWindow* fwnd2 = (FrameWindow*)winMgr.createWindow((utf8*)"Taharez Frame Window", (utf8*)"Demo7/Window2");
	root->addChildWindow(fwnd2);
	fwnd2->setMinimumSize(Size(0.2f, 0.0f));
	fwnd2->setMaximumSize(Size(0.8f, 0.8f));
	fwnd2->setPosition(Point(0.5f, 0.0f));
	fwnd2->setSize(Size(0.5f, 0.3f));
	fwnd2->setText((utf8*)"OGG Selections");
	fwnd2->setCloseButtonEnabled(false);

	FrameWindow* fwnd3 = (FrameWindow*)winMgr.createWindow((utf8*)"Taharez Frame Window", (utf8*)"Demo7/Window3");
	root->addChildWindow(fwnd3);
	fwnd3->setMinimumSize(Size(0.2f, 0.2f));
	fwnd3->setMaximumSize(Size(0.8f, 0.8f));
	fwnd3->setPosition(Point(0.25f, 0.5f));
	fwnd3->setSize(Size(0.5f, 0.5f));
	fwnd3->setText((utf8*)"Play Window");
	fwnd3->setCloseButtonEnabled(false);

	PushButton* btn = (PushButton*)winMgr.createWindow((utf8*)"Taharez Button", (utf8*)"Demo7/Window1/Quit");
	fwnd1->addChildWindow(btn);
	btn->setMaximumSize(Size(1.0f, 1.0f));
	btn->setPosition(Point(0.02f, 0.1f));
	btn->setSize(Size(0.25f, 0.1f));
	btn->setText((utf8*)"Exit Player");

	/////Creates three radio buttons for main play/pause/stop
	RadioButton* rbtn = (RadioButton*)winMgr.createWindow((utf8*)"Taharez RadioButton", (utf8*)"Demo7/Window1/Radio1");
	fwnd1->addChildWindow(rbtn);
	rbtn->setMaximumSize(Size(1.0f, 1.0f));
	rbtn->setPosition(Point(0.02f, 0.23f));
	rbtn->setSize(Size(0.25f, 0.075f));
	rbtn->setText((utf8*)"Play");
	rbtn->setID(0);
	rbtn = (RadioButton*)winMgr.createWindow((utf8*)"Taharez RadioButton", (utf8*)"Demo7/Window1/Radio2");
	fwnd1->addChildWindow(rbtn);
	rbtn->setMaximumSize(Size(1.0f, 1.0f));
	rbtn->setPosition(Point(0.02f, 0.306f));
	rbtn->setSize(Size(0.25f, 0.075f));
	rbtn->setText((utf8*)"Pause");
	rbtn->setID(1);
	rbtn = (RadioButton*)winMgr.createWindow((utf8*)"Taharez RadioButton", (utf8*)"Demo7/Window1/Radio3");
	fwnd1->addChildWindow(rbtn);
	rbtn->setMaximumSize(Size(1.0f, 1.0f));
	rbtn->setPosition(Point(0.02f, 0.382f));
	rbtn->setSize(Size(0.25f, 0.075f));
	rbtn->setText((utf8*)"Stop");
	rbtn->setID(2);
	
	//Create a button to hide or show playback window (perhaps make this a fullscree
	//toggle instead
	Checkbox* cbox = (Checkbox*)winMgr.createWindow((utf8*)"Taharez Checkbox", (utf8*)"Demo7/Window1/Checkbox");
	fwnd1->addChildWindow(cbox);
	cbox->setMaximumSize(Size(1.0f, 1.0f));
	cbox->setPosition(Point(0.02f, 0.48f));
	cbox->setSize(Size(0.45f, 0.075f));
	cbox->setText((utf8*)"Show/Hide View Screen");
	cbox->setSelected(true);

	// List box setup
	Listbox* lbox = (Listbox*)winMgr.createWindow((utf8*)"Taharez Listbox", (utf8*)"Demo7/Window2/Listbox");
	fwnd2->addChildWindow(lbox);
	lbox->setMaximumSize(Size(1.0f, 1.0f));
	lbox->setPosition(Point(0.04f, 0.15f));
	lbox->setSize(Size(0.8f, 0.6f));

	mMovieControl->populateListBox( lbox );

	btn = (PushButton*)winMgr.createWindow((utf8*)"Taharez Button", (utf8*)"Demo7/Window2/Play");
	fwnd2->addChildWindow(btn);
	btn->setMaximumSize(Size(1.0f, 1.0f));
	btn->setPosition(Point(0.09f, 0.8f));
	btn->setSize(Size(0.25f, 0.1f));
	btn->setText((utf8*)"Play Selected");
////

}


/*************************************************************************
	Perform required event hook-ups for this demo.
*************************************************************************/
void	CEGUIOgre_TestDriver1::initDemoEventWiring(void)
{
	using namespace CEGUI;

	WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window1/Quit")->
		subscribeEvent(PushButton::Clicked, boost::bind(&CEGUIOgre_TestDriver1::handleQuit, this, _1));

	WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window1/Checkbox")->
		subscribeEvent(Checkbox::CheckStateChanged, boost::bind(&CEGUIOgre_TestDriver1::handleCheck, this, _1));

	WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window1/Radio1")->
		subscribeEvent(RadioButton::SelectStateChanged, boost::bind(&CEGUIOgre_TestDriver1::handleRadio, this, _1));

	WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window1/Radio2")->
		subscribeEvent(RadioButton::SelectStateChanged, boost::bind(&CEGUIOgre_TestDriver1::handleRadio, this, _1));

	WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window1/Radio3")->
		subscribeEvent(RadioButton::SelectStateChanged, boost::bind(&CEGUIOgre_TestDriver1::handleRadio, this, _1));

	//Register method for handling play button
	WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window2/Play")->
		subscribeEvent(PushButton::Clicked, boost::bind(&CEGUIOgre_TestDriver1::handlePlayButton, this, _1));
}

/*************************************************************************
	Handle PLay Command Button
*************************************************************************/
void CEGUIOgre_TestDriver1::handlePlayButton(const CEGUI::EventArgs& e)
{
	using namespace CEGUI;
	
	FrameWindow* fwnd3 = (FrameWindow*)WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window3");
	Listbox* lbox = (Listbox*)WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window2/Listbox");
	StaticImage* simg = 0;

	try
	{
		CEGUI::String te = mMovieControl->getTextureName();
		
		fwnd3->removeChildWindow( (utf8*)"Demo7/Window3/Image1" );

		simg = (StaticImage*)WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window3/Image1");
		WindowManager::getSingleton().destroyWindow( simg );

		Imageset *tempimg = ImagesetManager::getSingleton().getImageset( 
			(utf8*)"MyImagesNumber" );
		
		tempimg->undefineImage( te );
		ImagesetManager::getSingleton().destroyImageset( (utf8*)"MyImagesNumber" );
	}
	catch(...) 
	{
		//Tis ok, first time through, set does not exist yet
	}

	const ListboxItem* item = lbox->getFirstSelectedItem();
	Ogre::String str = item->getText().c_str();
	mMovieControl->playMovie( str );

	simg = (StaticImage*)WindowManager::getSingleton().createWindow((utf8*)"Taharez StaticImage", (utf8*)"Demo7/Window3/Image1");
	
	fwnd3->addChildWindow(simg);
	simg->setMaximumSize(Size(1.0f, 1.0f));
	simg->setPosition(Point(0.0f, 0.0f));
	simg->setSize(Size(1.0f, 1.0f));
	simg->setFrameEnabled(false);
	simg->setBackgroundEnabled(false);

	//Now attach Texture to
	if( mMovieControl->getTexture() )
	{
		CEGUI::String temp = "MyImagesNumber";
		CEGUI::String tempName = mMovieControl->getTextureName();

		Imageset *img = ImagesetManager::getSingleton().createImageset( 
				temp, mMovieControl->getTexture() );

		unsigned int width = mMovieControl->getWidth();
		unsigned int height= mMovieControl->getHeight();

		img->defineImage( tempName, Point(0.0f,0.0f), Size( width, height ), Point(0.0f,0.0f));
		simg = (StaticImage*)WindowManager::getSingleton().getWindow((utf8*)"Demo7/Window3/Image1");
		simg->setImage( temp, tempName);
	}
}

/*************************************************************************
	Put up an error box
*************************************************************************/
void	CEGUIOgre_TestDriver1::doErrorBox(const char* text)
{
	using namespace CEGUI;

	WindowManager& winMgr = WindowManager::getSingleton();
	Window* root = winMgr.getWindow((utf8*)"root_wnd");

	FrameWindow* errbox;

	try
	{
		errbox = (FrameWindow*)winMgr.getWindow((utf8*)"ErrorBox");
	}
	catch(UnknownObjectException x)
	{
		// create frame window for box
		FrameWindow* fwnd = (FrameWindow*)winMgr.createWindow((utf8*)"Taharez Frame Window", (utf8*)"ErrorBox");
		root->addChildWindow(fwnd);
		fwnd->setPosition(Point(0.25, 0.25f));
		fwnd->setMaximumSize(Size(1.0f, 1.0f));
		fwnd->setSize(Size(0.5f, 0.5f));
		fwnd->setText((utf8*)"CEGUI Demo - Error!");
		fwnd->setDragMovingEnabled(false);
		fwnd->setSizingEnabled(false);
		fwnd->setAlwaysOnTop(true);
		fwnd->setCloseButtonEnabled(false);

		// create error text message

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -