Changing appearance of a button

From Sidvind
Jump to: navigation, search

To change the appearance of a button is quite simple once you learned it.

  1. Load the texture containing the images.
  2. Create an imageset and define the images you to use.
  3. Set the button to use custom images and which

I assume you know how to create the texture and the imageset (if not, look in the example and the documentation). In the example below I use two images, one normal and one when hovering/clicking. I think the code speaks for itself.

Code:

  1. CEGUI::Texture* texturePtr = CEGUI::System::getSingletonPtr()->getRenderer()->createTexture("buttons.png","Data/Media/Menu");                          
  2.  
  3. CEGUI::Imageset* ButtonsImageset = CEGUI::ImagesetManager::getSingletonPtr()->createImageset("Buttons",texturePtr);                                    
  4. ButtonsImageset->defineImage("ButtonUp",CEGUI::Point(1,1),CEGUI::Size( 431, 64 ),CEGUI::Point(0.0f,0.0f));
  5. ButtonsImageset->defineImage("ButtonDown",CEGUI::Point(1,256),CEGUI::Size( 431, 64 ),CEGUI::Point(0.0f,0.0f));
  6.  
  7. button->setProperty("UseStandardImagery", "false");                                                                                                
  8. button->setProperty("NormalImage", "set:Buttons image:ButtonUp");                                                                              
  9. button->setProperty("HoverImage", "set:Buttons image:ButtonDown");                                                                              
  10. button->setProperty("PushedImage", "set:Buttons image:ButtonDown");