Пример #1
0
TexturePair AssetsManager::createTextureImage(Ogre::TexturePtr texturePtr, const std::string& imageSetName)
{
	// 	if (mOgreCEGUITexture) {
	// 		GUIManager::getSingleton().getGuiRenderer()->destroyTexture(mOgreCEGUITexture);
	// 		mOgreCEGUITexture = 0;
	// 	}


	CEGUI::Imageset* textureImageset;

	if (CEGUI::ImagesetManager::getSingleton().isDefined(imageSetName)) {
		textureImageset = &CEGUI::ImagesetManager::getSingleton().get(imageSetName);
	} else {
		//create a CEGUI texture from our Ogre texture
		S_LOG_VERBOSE("Creating new CEGUI texture from Ogre texture.");
		CEGUI::Texture* ogreCEGUITexture = &GUIManager::getSingleton().getGuiRenderer()->createTexture(texturePtr);

		//we need a imageset in order to create GUI elements from the ceguiTexture
		S_LOG_VERBOSE("Creating new CEGUI imageset with name " << imageSetName);
		textureImageset = &CEGUI::ImagesetManager::getSingleton().create(imageSetName, *ogreCEGUITexture);

		//we only want one element: the whole texture
		textureImageset->defineImage("full_image", CEGUI::Rect(0, 0, texturePtr->getWidth(), texturePtr->getHeight()), CEGUI::Point(0, 0));
	}
	//assign our image element to the StaticImage widget
	const CEGUI::Image* textureImage = &textureImageset->getImage("full_image");

	return TexturePair(texturePtr, textureImage, textureImageset);

}
Пример #2
0
/*!
	Init method, for every button created
*/
void Button2d::init( qreal x, qreal y, const QString &image )
{
	CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
	_ceguiButton = (CEGUI::PushButton*)winMgr.createWindow("AquaLook/ImageButton", "bt_" + QString::number(_counter++).toStdString());

	// Position
	_ceguiButton->setPosition(CEGUI::UVector2(cegui_absdim(x), cegui_absdim(y)));

	// Size
	CEGUI::Imageset *btImageset = createImageSet(image);
	if(btImageset == NULL)
	{
		qWarning() << "[Button2d::init] Imageset is NULL, reseting size to 64x64";
		_ceguiButton->setSize(CEGUI::UVector2(cegui_absdim(64), cegui_absdim(64)));
	}
	else
	{
		CEGUI::Size s = btImageset->getNativeResolution();
		_ceguiButton->setSize(CEGUI::UVector2(cegui_absdim(s.d_width), cegui_absdim(s.d_height)));
	}

	// Uses click to make sure that button down occurred. (ex: problem when opening options after clicking a 3D button)
	_ceguiButton->subscribeEvent(CEGUI::PushButton::EventMouseClick, CEGUI::Event::Subscriber(&Button2d::onMouseClick, this));
	_ceguiButton->subscribeEvent(CEGUI::PushButton::EventMouseEnters, CEGUI::Event::Subscriber(&Button2d::onMouseEnters, this));
//	_ceguiButton->subscribeEvent(CEGUI::PushButton::EventMouseLeaves, CEGUI::Event::Subscriber(&Button2d::onMouseLeaves, this));

//	setCursor(QCursor(Qt::PointingHandCursor));
}
//Constructor sets up a CEGUI window with a 'Game Loading' background
SplashScreen::SplashScreen(Ogre::RenderWindow *window)
{
    mRootWindow = CEGUI::WindowManager::getSingleton().createWindow("DefaultWindow", "_splashscreenRoot");

    // Creating Imageset and define image for window background
    CEGUI::Imageset* imgs = (CEGUI::Imageset*) &CEGUI::ImagesetManager::getSingletonPtr()->createFromImageFile("splashscreenSet","splashscreen.jpg");
    imgs->defineImage("splashscreenImage", CEGUI::Point(0.0,0.0), CEGUI::Size(1920,1080), CEGUI::Point(0.0,0.0));

    //Create new, inner window, set position, size and attach to root.
    //Add background image
    mImageWindow = CEGUI::WindowManager::getSingleton().createWindow("WindowsLook/StaticImage","splashscreenWindow" );
    mImageWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(0.0, 0),CEGUI::UDim(0.0, 0)));
    mImageWindow->setSize(CEGUI::UVector2(CEGUI::UDim(0, window->getWidth()), CEGUI::UDim(0, window->getHeight())));
    mImageWindow->setProperty("Image","set:splashscreenSet image:splashscreenImage");

    mRootWindow->addChildWindow(mImageWindow);
}
	//---------------------------------------------------------------------
	bool CompositorDemo_FrameListener::handleRttSelection(const CEGUI::EventArgs& e)
	{
		if (mDebugRTTListbox->getSelectedCount() > 0)
		{
			// image set is in user data
			CEGUI::Imageset* imgSet = (CEGUI::Imageset*)mDebugRTTListbox->getFirstSelectedItem()->getUserData();

			mDebugRTTStaticImage->setProperty("Image",
                CEGUI::PropertyHelper::imageToString(&imgSet->getImage("RttImage")));

		}
		else
		{
			mDebugRTTStaticImage->setProperty("Image", "");

		}
		return true;
	}
Пример #5
0
void Button2d::init( CEGUI::UDim x, CEGUI::UDim y, const QString &image )
{
	CEGUI::WindowManager& winMgr = CEGUI::WindowManager::getSingleton();
	_ceguiButton = (CEGUI::PushButton*)winMgr.createWindow("AquaLook/ImageButton", "bt_" + QString::number(_counter++).toStdString());

	// Position
	_ceguiButton->setPosition(CEGUI::UVector2(x, y));

	// Size
	CEGUI::Imageset *btImageset = createImageSet(image);
	CEGUI::Size s = btImageset->getNativeResolution();
	_ceguiButton->setSize(CEGUI::UVector2(cegui_absdim(s.d_width), cegui_absdim(s.d_height)));

	_ceguiButton->subscribeEvent(CEGUI::PushButton::EventMouseButtonUp, CEGUI::Event::Subscriber(&Button2d::onMouseClick, this));
	_ceguiButton->subscribeEvent(CEGUI::PushButton::EventMouseEnters, CEGUI::Event::Subscriber(&Button2d::onMouseEnters, this));

//	setCursor(QCursor(Qt::PointingHandCursor));
}
void CSimulatorWindowHandler::init()
{
	CEGUI::WindowManager	&windowMngr = CEGUI::WindowManager::getSingleton();

    m_continueButton			= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/ContinueButton"));
    m_startButton				= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/StartButton"));
    m_zoomButton				= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/ZoomButton"));
    m_formation433Button		= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/433Button"));
    m_formation442Button		= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/442Button"));
    m_frameWindow				= static_cast<CEGUI::FrameWindow*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/FrameWindow"));
    m_view2DButton				= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/2DButton"));
    m_view3DButton				= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/3DButton"));
    m_frameStartButtom			= static_cast<CEGUI::PushButton*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/StartButton"));

    m_logHistoryList            = static_cast<CEGUI::Listbox*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Log"));
    m_logHistoryListShort       = static_cast<CEGUI::Listbox*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/Log"));
    m_teamPlayersList           = static_cast<CEGUI::MultiColumnList*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/TeamPlayersList"));
    m_groundImage               = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Image"));
    m_groundFrameImage          = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/Image"));
    m_teamNames                 = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/TeamNames"));
    m_score                     = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Score"));
    m_frameHomeName             = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/HomeName"));
    m_frameAwayName             = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/AwayName"));
    m_frameHomeScore            = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/HomeScore"));
    m_frameAwayScore            = static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/Frame/AwayScore"));

    // i18n support
    m_continueButton->setText((CEGUI::utf8*)gettext("Continue"));
    m_startButton->setText((CEGUI::utf8*)gettext("Start"));
    m_zoomButton->setText((CEGUI::utf8*)gettext("Zoom"));
    m_frameWindow->setText((CEGUI::utf8*)gettext("Simulation View"));
    m_view2DButton->setText((CEGUI::utf8*)gettext("2D View"));
    m_view3DButton->setText((CEGUI::utf8*)gettext("3D View"));
    m_frameStartButtom->setText((CEGUI::utf8*)gettext("Start"));
    static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/TeamTab"))->setText((CEGUI::utf8*)gettext("Team"));
    static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/FormationTab"))->setText((CEGUI::utf8*)gettext("Formation"));
    static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/LogTab"))->setText((CEGUI::utf8*)gettext("Log"));
    static_cast<CEGUI::Window*>(windowMngr.getWindow((CEGUI::utf8*)"Simulator/StatisticsTab"))->setText((CEGUI::utf8*)gettext("Statistics"));

    // Event handle
    registerEventConnection(m_continueButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::continueButtonClicked, this)));
    registerEventConnection(m_startButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::startButtonClicked, this)));
    registerEventConnection(m_zoomButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::zoomButtonClicked, this)));
    registerEventConnection(m_formation433Button->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::formation433ButtonClicked, this)));
    registerEventConnection(m_formation442Button->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::formation442ButtonClicked, this)));
    registerEventConnection(m_frameWindow->subscribeEvent(CEGUI::FrameWindow::EventCloseClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::frameWindowCloseClicked, this)));
    registerEventConnection(m_view2DButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::view2DButtonClicked, this)));
    registerEventConnection(m_view3DButton->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::view3DButtonClicked, this)));
    registerEventConnection(m_frameStartButtom->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::startButtonClicked, this)));
    registerEventConnection(windowMngr.getWindow("Simulator")->subscribeEvent(CEGUI::Window::EventKeyDown, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::keyDownHandler, this)));
    registerEventConnection(windowMngr.getWindow("Simulator")->subscribeEvent(CEGUI::Window::EventKeyUp, CEGUI::Event::Subscriber(&CSimulatorWindowHandler::keyUpHandler, this)));

    m_direction = Ogre::Vector3::ZERO;
    m_sceneMngr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, SIMULATION_SCENE_MANAGER_NODE_NAME);

    m_cam2D = m_sceneMngr->createCamera("2D_Camera");
    m_cam2D->setNearClipDistance(1);
    int width = 120;
    int height = 90;
    double  right = width/2.0,
            left = -width/2.0,
            top = height/2.0,
            bottom = -height/2.0,
            farZ = 150.0,
            nearZ = 10.0;
    Ogre::Matrix4 projectionMatrix(
            2/(right-left), 0, 0, -(right+left)/(right-left),
            0, 2/(top-bottom), 0, -(top+bottom)/(top-bottom),
            0, 0, -2/(farZ-nearZ), -(farZ+nearZ)/(farZ-nearZ),
            0, 0, 0, 1
            );
    m_cam2D->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
    m_cam2D->setCustomProjectionMatrix(true, projectionMatrix);

    m_cam3D = m_sceneMngr->createCamera("3D_Camera");
    m_cam3D->setProjectionType(Ogre::PT_PERSPECTIVE);
    m_cam3D->setCustomProjectionMatrix(false);
    m_cam3D->setNearClipDistance(5);

    Ogre::TexturePtr texturePtr = Ogre::TextureManager::getSingleton().createManual("RttTex",
                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,
                    (int)m_groundImage->getPixelSize().d_width, (int)m_groundImage->getPixelSize().d_height,
                    0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
    m_renderTexture = texturePtr->getBuffer()->getRenderTarget();

    CEGUI::Texture  *cTex = static_cast<CEGUI::OgreCEGUIRenderer*>(CEGUI::System::getSingleton().getRenderer())->createTexture((CEGUI::utf8*)"RttTex");
    CEGUI::Imageset *imageSet = CEGUI::ImagesetManager::getSingleton().createImageset((CEGUI::utf8*)"RttImageset", cTex);
    imageSet->defineImage((CEGUI::utf8*)"RttImage",
        CEGUI::Point(0.0f, 0.0f),
        CEGUI::Size(cTex->getWidth(), cTex->getHeight()),
        CEGUI::Point(0.0f,0.0f));

    m_groundImage->setProperty(     "Image", CEGUI::PropertyHelper::imageToString(&imageSet->getImage((CEGUI::utf8*)"RttImage")));
    m_groundFrameImage->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet->getImage((CEGUI::utf8*)"RttImage")));
    m_groundFrameImage->disable();

    m_initiated = true;
}
	//---------------------------------------------------------------------
	void CompositorDemo_FrameListener::updateDebugRTTWindow(void)
	{
		// Clear listbox
		mDebugRTTListbox->resetList();
		// Clear imagesets
		mDebugRTTStaticImage->setProperty("Image", "");
		for (ImageSetList::iterator isIt = mDebugRTTImageSets.begin();
			isIt != mDebugRTTImageSets.end(); ++isIt)
		{
			CEGUI::ImagesetManager::getSingleton().destroyImageset(*isIt);
		}
		mDebugRTTImageSets.clear();
		Ogre::set<Ogre::String>::type uniqueTextureNames;
		// Add an entry for each render texture for all active compositors
		Ogre::Viewport* vp = mMain->getRenderWindow()->getViewport(0);
		Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(vp);
		Ogre::CompositorChain::InstanceIterator it = chain->getCompositors();
		while (it.hasMoreElements())
		{
			Ogre::CompositorInstance* inst = it.getNext();
			if (inst->getEnabled())
			{
				Ogre::CompositionTechnique::TextureDefinitionIterator texIt =
					inst->getTechnique()->getTextureDefinitionIterator();
				while (texIt.hasMoreElements())
				{
					Ogre::CompositionTechnique::TextureDefinition* texDef = texIt.getNext();

					// Get instance name of texture (NB only index 0 if MRTs for now)
					const Ogre::String& instName = inst->getTextureInstanceName(texDef->name, 0);
					// Create CEGUI texture from name of OGRE texture
					CEGUI::Texture* tex = mMain->getGuiRenderer()->createTexture(instName.c_str());
					// Create imageset
					// Note that if we use shared textures in compositor, the same texture name
					// will occur more than once, so we have to cater for this
					if (uniqueTextureNames.find(instName) == uniqueTextureNames.end())
					{
						CEGUI::Imageset* imgSet =
							CEGUI::ImagesetManager::getSingleton().createImageset(
								instName.c_str(), tex);
						mDebugRTTImageSets.push_back(imgSet);
						imgSet->defineImage((CEGUI::utf8*)"RttImage",
							CEGUI::Point(0.0f, 0.0f),
							CEGUI::Size(tex->getWidth(), tex->getHeight()),
							CEGUI::Point(0.0f,0.0f));


						CEGUI::ListboxTextItem *item = new CEGUI::ListboxTextItem(texDef->name.c_str(), 0, imgSet);
						item->setSelectionBrushImage("TaharezLook", "ListboxSelectionBrush");
						item->setSelectionColours(CEGUI::colour(0,0,1));
						mDebugRTTListbox->addItem(item);

						uniqueTextureNames.insert(instName);
					}

				}

			}

		}



	}
Пример #8
0
HCURSOR	CUIIconsManager::CreateAsWinCursor(LPCTSTR szIconName)
{
	try{
	//-------------------------------------------------------
	//CEGUI Image
	const CEGUI::Image* pIconImage = GetIcon(szIconName);
	if(!pIconImage) return NULL;

	//-------------------------------------------------------
	//CEGUI ImageSet
	CEGUI::Imageset* pImageset = CEGUI::ImagesetManager::getSingleton().getImageset(pIconImage->getImagesetName());
	if(!pImageset) return NULL;

	//-------------------------------------------------------
	//CEGUI Ogre Texture
	CEGUI::OgreCEGUITexture* pCEGUIOgreTexture = (CEGUI::OgreCEGUITexture*)(pImageset->getTexture());
	if(!pCEGUIOgreTexture) return NULL;

	//-------------------------------------------------------
	//Ogre Texture
	Ogre::Texture* pOgreTexture = pCEGUIOgreTexture->getOgreTexture().get();
	if(!pOgreTexture) return NULL;

	//-------------------------------------------------------
	//Ogre HardwarePixelBuffer
	Ogre::HardwarePixelBuffer* pOgreHardPixBuf = pOgreTexture->getBuffer().get();
	if(!pOgreHardPixBuf) return NULL;

	//-------------------------------------------------------
	//Blt to Ogre PixelBox
	const static INT s_CursorWidth  = 32;
	const static INT s_CursorHeight = 32;

	CEGUI::Rect rectAtImage = pIconImage->getSourceTextureArea();
	const Ogre::PixelBox thePixBox(s_CursorWidth, s_CursorHeight, 1, Ogre::PF_R8G8B8A8, new char[s_CursorWidth*s_CursorHeight*Ogre::PixelUtil::getNumElemBytes(Ogre::PF_R8G8B8A8)]);
	pOgreHardPixBuf->blitToMemory(
		Ogre::Image::Box((INT)rectAtImage.d_left, (INT)rectAtImage.d_top, (INT)rectAtImage.d_right, (INT)rectAtImage.d_bottom), thePixBox);

	//-------------------------------------------------------
	//Create Windows Bitmap as XOR Mask

	HDC hMainDC			= ::GetDC(NULL);
	HDC hXorMaskDC		= ::CreateCompatibleDC(hMainDC); 
	HBITMAP hXorMask	= ::CreateCompatibleBitmap(hMainDC, s_CursorWidth, s_CursorHeight);
	::SelectObject(hXorMaskDC, hXorMask);

	//-------------------------------------------------------
	//Get per Pixel Color to XOR Mask
	for(register INT x=0; x<s_CursorWidth; x++)
	{
		for(register INT y=0; y<s_CursorHeight; y++)
		{
			Ogre::ColourValue col;
			VOID* pColData = (thePixBox.rowPitch*y + x)* Ogre::PixelUtil::getNumElemBytes(thePixBox.format) + 
							 (unsigned char*)thePixBox.data;

			Ogre::PixelUtil::unpackColour( &col, thePixBox.format, pColData);

			::SetPixel(hXorMaskDC, x, y, RGB(col.r*255, col.g*255, col.b*255));
		}
	}
	delete[] thePixBox.data;
	::DeleteDC(hXorMaskDC); hXorMaskDC = NULL;

	//-------------------------------------------------------
	//Create AND Mask
	HDC hAndMaskDC	= ::CreateCompatibleDC(hMainDC); 
	HBITMAP hAndMask	= ::CreateCompatibleBitmap(hMainDC, s_CursorWidth, s_CursorHeight);
	::SelectObject(hAndMaskDC, hAndMask);

	RECT rect;
	::SetRect(&rect, 0, 0, s_CursorWidth, s_CursorHeight);
	::FillRect(hAndMaskDC, &rect, (HBRUSH)::GetStockObject(BLACK_BRUSH));

	::DeleteDC(hAndMaskDC); hAndMaskDC = NULL;

	//-------------------------------------------------------
	//Create Crusor
	ICONINFO iconinfo = {0};
	iconinfo.fIcon		= FALSE;
	iconinfo.xHotspot	= 0;
	iconinfo.yHotspot	= 0;
	iconinfo.hbmMask	= hAndMask;
	iconinfo.hbmColor	= hXorMask;

	HCURSOR hRetCursor = ::CreateIconIndirect(&iconinfo);

	//-------------------------------------------------------
	//Release
	::DeleteObject(hAndMask);
	::DeleteObject(hXorMask);
	::ReleaseDC(NULL,hMainDC);

	return hRetCursor;
	
	}catch(...)
	{
		return 0;
	}
}