Difference between revisions of "Creating a sub image"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
m (CodeSnippets/CreateSubImage moved to CreateSubImage)
m (Spelling fix)
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Creating a subimage==
+
{{VersionBadge|0.5}} {{VersionBadge|0.6}} {{VersionBadge|0.7}}
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:
+
  
<pre>
+
I found that it might be useful 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 21: Line 22:
  
 
/*this function replaces the image with the new coordinates passed with it, which selects a subimage,
 
/*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 */
+
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));
 
createSubImage("ExampleImageSet","Base",CEGUI::Point(0.0f,0.0f),CEGUI::Size(texture->getWidth()-512,texture->getHeight()-512),CEGUI::Point(0.0f,0.0f));
 
 
Line 35: Line 36:
 
curr_imageset->defineImage(imageName,start,size,offset);
 
curr_imageset->defineImage(imageName,start,size,offset);
 
}
 
}
</pre>
+
</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:HowTo]]

Latest revision as of 23:55, 3 March 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)

I found that it might be useful 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.