Difference between revisions of "Creating a sub image"
From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
(→Creating a subimage) |
|||
Line 17: | Line 17: | ||
renderTarget->setSize(CEGUI::Size(0.3f, 0.4f)); | renderTarget->setSize(CEGUI::Size(0.3f, 0.4f)); | ||
CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)topElement)->addChildWindow(renderTarget); | CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)topElement)->addChildWindow(renderTarget); | ||
− | + | renderTarget->setPosition(CEGUI::Point(0.6, 0.6)); | |
renderTarget->setImage(&set->getImage((CEGUI::utf8*)"Base")); | renderTarget->setImage(&set->getImage((CEGUI::utf8*)"Base")); | ||
Revision as of 18:04, 28 May 2006
Creating a subimage
I found that it might be usefull to be able to create a subimage from an image. Say for instance u have a minimap created from a file, and you want to be able to zoom it. For this purpose it's best to use a subimage from the map. Basically this code can be used to complete that task:
//this function is just called to show the imageloading from a file, and selecting a subpart of the image void GUIHud::createMMap() { //load in a file, replace with your own file CEGUI::Texture* texture = mGUIRenderer->createTexture("Ground1.bmp"); //create a new imageset with an image that spans the entire texture CEGUI::Imageset* set = CEGUI::ImagesetManager::getSingleton().createImageset((CEGUI::utf8*)"ExampleImageSet",texture); set->defineImage("Base",CEGUI::Point(0.0f,0.0f),CEGUI::Size(texture->getWidth(),texture->getHeight()),CEGUI::Point(0.0f,0.0f)); //create a new window for this stuff and link the created image to it CEGUI::StaticImage* renderTarget = (CEGUI::StaticImage*)CEGUI::WindowManager::getSingleton().createWindow((CEGUI::utf8*)"SEM/StaticImage", (CEGUI::utf8*)"BaseWindow"); renderTarget->setSize(CEGUI::Size(0.3f, 0.4f)); CEGUI::WindowManager::getSingleton().getWindow((CEGUI::utf8*)topElement)->addChildWindow(renderTarget); renderTarget->setPosition(CEGUI::Point(0.6, 0.6)); renderTarget->setImage(&set->getImage((CEGUI::utf8*)"Base")); /*this function replaces the image with the new coordinates passed with it, which selects a subimage, and replaces the given image with the newly created one */ createSubImage("ExampleImageSet","Base",CEGUI::Point(0.0f,0.0f),CEGUI::Size(texture->getWidth()-512,texture->getHeight()-512),CEGUI::Point(0.0f,0.0f)); //should not be necessary, if anything weird appears try redrawing the image //renderTarget->requestRedraw(); } //this function replaces the image in the given imageset with the new coordinates that are passed with this function void GUIHud::createSubImage(CEGUI::String imageSetName,CEGUI::String imageName, CEGUI::Point start, CEGUI::Size size,CEGUI::Point offset) { CEGUI::Imageset* curr_imageset = CEGUI::ImagesetManager::getSingleton().getImageset(imageSetName); CEGUI::Texture* texture = curr_imageset->getTexture(); curr_imageset->undefineImage(imageName); curr_imageset->defineImage(imageName,start,size,offset); }
this code was written with Ogre, but the main lines of it should be clear i think.