src/GUIFrame.cpp

Go to the documentation of this file.
00001 #include "glwx.h"
00002 
00003 GUIFrame::GUIFrame() : GUIPanel("GUI MAIN PANEL")
00004 {
00005   listener = NULL;
00006   update   = true;
00007 }
00008 
00009 bool GUIFrame::loadXMLSettings(const TiXmlElement *element) 
00010 {
00011   if(!XMLArbiter::inspectElementInfo(element, "Panel"))
00012     return Logger::writeErrorLog("Need a Panel node in the xml file");
00013 
00014   bool defaultFont = true;
00015 
00016   for(const TiXmlElement *child = element->FirstChildElement(); 
00017       child;
00018           child = child->NextSiblingElement() )
00019   {
00020     std::string elementName  = child->Value();
00021 
00022     if(!elementName.size())
00023       continue;
00024     
00025     if(elementName == "Font")
00026     {
00027       int fontIndex = GUIFontManager::addFont(child);
00028       if(defaultFont && fontIndex >= 0)
00029       {
00030         GUIFontManager::setDefaultFont(fontIndex);
00031         defaultFont = false;
00032       }
00033       continue;
00034     }
00035  
00036     if(elementName == "Texture")
00037     {
00038       if(elementsTexture.loadXMLSettings(child))
00039       {
00040         GUITexCoordDescriptor::setTextureHeight(elementsTexture.getHeight());
00041         GUITexCoordDescriptor::setTextureWidth(elementsTexture.getWidth());
00042       }
00043       continue;
00044     }
00045 
00046     if(elementName == "TexCoordsDesc")
00047     {
00048       GUITexCoordDescriptor descriptor;
00049       descriptor.loadXMLSettings(child);
00050       addOrReplaceTexCoordsInfo(descriptor);
00051       continue;
00052     }
00053   }
00054   return   GUIPanel::loadXMLSettings(element);
00055 }
00056 
00057 void  GUIFrame::render(float tick)
00058 {
00059   if(!visible)
00060     return;
00061 
00062   size_t t = 0;
00063 
00064   while(updateCount)
00065   {
00066     for(t = 0; t < elements.size(); t++)
00067       elements[t]->forceUpdate(true);
00068     updateCount--;
00069   }
00070 
00071   for(t = 0; t < elements.size(); t++)
00072     elements[t]->render(tick);
00073 }
00074 
00075 void GUIFrame::addOrReplaceTexCoordsInfo(GUITexCoordDescriptor &info)
00076 {
00077   for(size_t t = 0; t < texCoords.size(); t++)
00078     if(texCoords[t].getType() == info.getType())
00079     {
00080       texCoords[t].setTexCoords(info.getTexCoords());
00081       return;
00082     }
00083   texCoords.push_back(info);
00084 }
00085 
00086 GUITexCoordDescriptor *GUIFrame::getTexCoordsInfo(int type)
00087 {
00088   for(size_t t = 0; t < texCoords.size(); t++)
00089     if(texCoords[t].getType() == type)
00090       return &texCoords[t];
00091   return NULL;
00092 }
00093 
00094 void  GUIFrame::setGUIEventListener(GUIEventListener *listener_)
00095 {
00096   listener = listener_;
00097 }
00098 
00099 GUIEventListener *GUIFrame::getEventsListener()
00100 {
00101   return listener;
00102 }
00103 
00104 void  GUIFrame::setElementsTexture(const char* texturePath)
00105 {
00106   elementsTexture.load2D(texturePath);
00107 }
00108 
00109 void  GUIFrame::setElementsTexture(const Texture &texture)
00110 {
00111   elementsTexture = texture;
00112 }
00113 
00114 Texture *GUIFrame::getElementsTexture()
00115 {
00116   return !elementsTexture.getID() ? NULL : &elementsTexture;
00117 }
00118 
00119 void  GUIFrame::enableGUITexture()
00120 {
00121   if(elementsTexture.getID())
00122     elementsTexture.activate();
00123 }
00124 
00125 void  GUIFrame::disableGUITexture()
00126 {
00127   elementsTexture.deactivate();
00128 }
00129 
00130 void GUIFrame::forceUpdate(bool update)
00131 {
00132   updateCount = update ? getTreeHeight() + 1 : 0;
00133 }
00134 
00135 void GUIFrame::clear()
00136 {
00137   elementsTexture.destroy();
00138   texCoords.clear();
00139   GUIPanel::clear();
00140 }
00141 
00142 const Tuple4i &GUIFrame::getWindowBounds()
00143 {
00144   windowBounds.set(0, 0, int(dimensions.x), int(dimensions.y));
00145   return windowBounds;
00146 }
00147 
00148 GUIFrame::~GUIFrame()
00149 {
00150   clear();
00151 }
00152 

Generated on Wed Dec 5 20:32:03 2007 for GLWX by  doxygen 1.5.3