~ubuntu-branches/ubuntu/edgy/pouetchess/edgy-updates

« back to all changes in this revision

Viewing changes to src/sxmlgui/GUITexCoordDescriptor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc (mr_pouit)
  • Date: 2006-07-15 15:45:57 UTC
  • Revision ID: james.westby@ubuntu.com-20060715154557-3paxq02hx4od0wm4
Tags: upstream-0.2.0
ImportĀ upstreamĀ versionĀ 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "EasyGL.h"
 
2
 
 
3
Tuple2i textureGUIDimensions(256,256);
 
4
 
 
5
void GUITexCoordDescriptor::setTextureWidth(int width)
 
6
{
 
7
  textureGUIDimensions.x = clamp(width, 8, 1024);
 
8
}
 
9
 
 
10
void GUITexCoordDescriptor::setTextureHeight(int height)
 
11
{  
 
12
  textureGUIDimensions.y = clamp(height, 8, 1024);
 
13
}
 
14
 
 
15
GUITexCoordDescriptor::GUITexCoordDescriptor(int widgetTypeArg)
 
16
{
 
17
  texCoords.set(0.0f,0.0f,1.0f,1.0f);
 
18
  widgetType = widgetTypeArg;
 
19
}
 
20
 
 
21
GUITexCoordDescriptor::GUITexCoordDescriptor(const GUITexCoordDescriptor &copy)
 
22
{
 
23
  this->operator=(copy);
 
24
}
 
25
 
 
26
GUITexCoordDescriptor &GUITexCoordDescriptor::operator =(const GUITexCoordDescriptor &copy)
 
27
{
 
28
 
 
29
  if(this != &copy)
 
30
  {
 
31
    texCoords  = copy.texCoords;
 
32
    widgetType = copy.widgetType;
 
33
  } 
 
34
  return *this;
 
35
}
 
36
 
 
37
void GUITexCoordDescriptor::setType(int type)
 
38
{
 
39
  switch(type)
 
40
  {
 
41
    case WT_SLIDER :
 
42
    case WT_BUTTON:
 
43
    case WT_CHECK_BOX:
 
44
    case WT_CHECK_BOX_MARK:
 
45
    case WT_RADIO_BUTTON:
 
46
    case WT_CHECK_RB_MARK:
 
47
      widgetType = type;
 
48
    break;
 
49
    default: widgetType = WT_UNKNOWN;
 
50
  }
 
51
}
 
52
 
 
53
void GUITexCoordDescriptor::setType(const std::string &type)
 
54
{
 
55
  if(!type.size())
 
56
  {
 
57
    Logger::writeErrorLog("NULL GUITexCoordDescriptor type");
 
58
    return;
 
59
  }
 
60
 
 
61
  if(type == "MATERIAL_SURFACE"){ widgetType = WT_MATERIAL_SURFACE; return; }
 
62
  if(type == "CHECK_BOX_MARK")  { widgetType = WT_CHECK_BOX_MARK;   return; }
 
63
  if(type == "CHECK_RB_MARK")   { widgetType = WT_CHECK_RB_MARK;    return; }
 
64
  if(type == "RADIO_BUTTON")    { widgetType = WT_RADIO_BUTTON;     return; }
 
65
  if(type == "SEPARATOR")       { widgetType = WT_SEPARATOR;        return; }
 
66
  if(type == "CHECK_BOX")       { widgetType = WT_CHECK_BOX;        return; }
 
67
  if(type == "TEXT_AREA")       { widgetType = WT_TEXT_AREA;        return; }
 
68
  if(type == "BUTTON")          { widgetType = WT_BUTTON;           return; }
 
69
  if(type == "SLIDER")          { widgetType = WT_SLIDER;           return; }
 
70
  if(type == "PANEL")           { widgetType = WT_PANEL;            return; }
 
71
  if(type == "LABEL")           { widgetType = WT_LABEL;            return; }
 
72
 
 
73
  Logger::writeErrorLog(std::string("Unknow GUITexCoordDescriptor type -> ") + type);
 
74
  widgetType = WT_UNKNOWN;
 
75
}
 
76
 
 
77
int GUITexCoordDescriptor::getType()
 
78
{
 
79
  return widgetType;
 
80
}
 
81
 
 
82
void GUITexCoordDescriptor::loadXMLSettings(const TiXmlElement *element)
 
83
{
 
84
  if(!XMLArbiter::inspectElementInfo(element, "TexCoordsDesc"))
 
85
    return;
 
86
 
 
87
  std::string name;
 
88
  int         xStart        = 0,
 
89
              yStart        = 0,
 
90
              xEnd          = 0,
 
91
              yEnd          = 0;
 
92
 
 
93
  xStart = XMLArbiter::fillComponents1i(element, "xStart", xStart);
 
94
  yStart = XMLArbiter::fillComponents1i(element, "yStart", yStart);
 
95
 
 
96
  xEnd = XMLArbiter::fillComponents1i(element, "xEnd", xEnd);
 
97
  yEnd = XMLArbiter::fillComponents1i(element, "yEnd", yEnd);
 
98
   
 
99
  setTexCoords(xStart/float(textureGUIDimensions.x), yStart/float(textureGUIDimensions.y),
 
100
               xEnd  /float(textureGUIDimensions.x), yEnd  /float(textureGUIDimensions.y));
 
101
  setType(element->Attribute("type"));
 
102
}
 
103
 
 
104
int GUITexCoordDescriptor::getTextureWidth()
 
105
{
 
106
  return textureGUIDimensions.x;
 
107
}
 
108
 
 
109
int GUITexCoordDescriptor::getTextureHeight()
 
110
{
 
111
  return textureGUIDimensions.y;
 
112
}
 
113
 
 
114
void GUITexCoordDescriptor::setTexCoords(float x, float y, float z, float w)
 
115
{
 
116
  texCoords.set(clamp(x,0.0f, 1.0f), clamp(y,0.0f, 1.0f),
 
117
                clamp(z,0.0f, 1.0f), clamp(w,0.0f, 1.0f));
 
118
}
 
119
 
 
120
void GUITexCoordDescriptor::setTexCoords(const Tuple4f& texCoordsArg)
 
121
{
 
122
  texCoords =  texCoordsArg;
 
123
};
 
124
 
 
125
const Tuple4f &GUITexCoordDescriptor::getTexCoords()
 
126
{
 
127
  return texCoords;
 
128
}