src/GUISeparator.cpp

Go to the documentation of this file.
00001 #include "glwx.h"
00002 
00003 GUISeparator::GUISeparator(int orientation_) : GUIRectangle()
00004 {
00005   setOrientation(orientation);
00006   setRatio(1.0f);
00007   widgetType = WT_SEPARATOR;
00008 }
00009 
00010 bool GUISeparator::loadXMLSettings(const TiXmlElement *element)
00011 {
00012   if(!element || !element->Value() || strcmp(element->Value(),  "Separator"))
00013     return Logger::writeErrorLog("Need a <Separator> tag");
00014 
00015   setRatio(XMLArbiter::fillComponents1f(element, "ratio", ratio));
00016   return true;
00017 }
00018 
00019 void  GUISeparator::setRatio(float ratio_)
00020 {
00021   ratio = clamp(ratio_, 0.1f, 1.0f);
00022 } 
00023 
00024 float GUISeparator::getRatio()
00025 {
00026   return ratio;
00027 }
00028 
00029 void GUISeparator::setOrientation(int orientation_)
00030 {
00031   orientation =  orientation_ == OR_HORIZONTAL ? OR_HORIZONTAL : OR_VERTICAL;
00032 }
00033 
00034 int  GUISeparator::getOrientation()
00035 {
00036   return orientation;
00037 }
00038 
00039 void GUISeparator::render(float tick)
00040 {
00041   if(!parent || !((GUIPanel*)parent)->isBGColorOn())
00042     return;
00043 
00044   glColor3fv(((GUIPanel*)parent)->getBordersColor());
00045 
00046   glBegin(GL_LINES);
00047   glVertex2i(windowBounds.x, windowBounds.y);
00048   glVertex2i(windowBounds.z, (orientation == OR_VERTICAL) ? windowBounds.w : windowBounds.y);
00049   glEnd();
00050   glColor3f(1.0f, 1.0f, 1.0f);
00051 }
00052 
00053 void const GUISeparator::computeWindowBounds()
00054 {
00055   const Tuple4i &parentBounds = parent->getWindowBounds();
00056   if(orientation == OR_HORIZONTAL)
00057   {
00058     float offset = (float(parent->getWidth()) - float(ratio*parent->getWidth()))/2.0f;
00059     windowBounds.set(int(parentBounds.x + offset), int(parentBounds.y + position.y),
00060                      int(parentBounds.z - offset), int(parentBounds.y + position.y));
00061   }
00062   else
00063   {
00064     float offset = (float(parent->getHeight()) - float(parent->getHeight())*ratio)/2.0f;
00065     windowBounds.set(int(parentBounds.x + position.x), int(parentBounds.y + offset),
00066                      int(parentBounds.x + position.x), int(parentBounds.w - offset));
00067   }
00068 }
00069 
00070 const Tuple4i &GUISeparator::getWindowBounds()
00071 {
00072   windowBounds.set(0,0,0,1);
00073   return windowBounds;
00074 }
00075 

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