Difference between revisions of "Creating a sub image"
From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
m (Robot: Adding Category:Uncategorised) |
|||
Line 1: | Line 1: | ||
− | ==Creating a subimage== | + | {{VersionBadge|0.5}} {{VersionBadge|0.6}} {{VersionBadge|0.7}} |
+ | |||
+ | == 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: | 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: | ||
− | < | + | <source lang="cpp"> |
//this function is just called to show the imageloading from a file, and selecting a subpart of the image | //this function is just called to show the imageloading from a file, and selecting a subpart of the image | ||
void GUIHud::createMMap() | void GUIHud::createMMap() | ||
Line 35: | Line 37: | ||
curr_imageset->defineImage(imageName,start,size,offset); | curr_imageset->defineImage(imageName,start,size,offset); | ||
} | } | ||
− | </ | + | </source> |
this code was written with Ogre, but the main lines of it should be clear i think. | this code was written with Ogre, but the main lines of it should be clear i think. | ||
− | [[Category: | + | [[Category:HowTo]] |
Revision as of 12:37, 28 February 2011
Written for CEGUI 0.5
Works with versions 0.5.x (obsolete)
Written for CEGUI 0.6
Works with versions 0.6.x (obsolete)
Written for CEGUI 0.7
Works with versions 0.7.x (obsolete)
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.