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

« back to all changes in this revision

Viewing changes to src/sxmlgui/GUIAlphaElement.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
GUIAlphaElement::GUIAlphaElement(const std::string &callback) :  GUIRectangle(callback)
 
4
{
 
5
  setColor(225.0f, 225.0f, 225.0f);
 
6
  alphaFadeScale =     1.0f;
 
7
  minAlpha       =     0.6f;
 
8
  color.w        = minAlpha;
 
9
}
 
10
 
 
11
bool GUIAlphaElement::loadXMLSettings(const TiXmlElement *element)
 
12
{
 
13
  if(!element)
 
14
    return false;
 
15
 
 
16
  setAlphaFadeScale(XMLArbiter::fillComponents1f(element, "alphaFadeScale", alphaFadeScale));
 
17
  setMinAlpha(XMLArbiter::fillComponents1f(element, "minAlpha", minAlpha));
 
18
 
 
19
  for(const TiXmlElement *child = element->FirstChildElement(); 
 
20
      child;
 
21
          child = child->NextSiblingElement() )
 
22
  {
 
23
    const char * value = child->Value();
 
24
 
 
25
    if(value)
 
26
    {
 
27
      if(!strcmp(value, "Color"))
 
28
        XMLArbiter::fillComponents4f(child, color);
 
29
 
 
30
      if(!strcmp(value, "Text"))
 
31
        label.loadXMLSettings(child);
 
32
    }
 
33
  }
 
34
 
 
35
  setColor(color.x, color.y, color.z);
 
36
  return   GUIRectangle::loadXMLSettings(element);
 
37
}
 
38
 
 
39
void  GUIAlphaElement::setColor(const Tuple3f& color)
 
40
{
 
41
  setColor(color.x, color.y, color.z);
 
42
}
 
43
 
 
44
void GUIAlphaElement::setColor(float r, float g, float b)
 
45
{
 
46
  color.set(clamp(r, 0.0f, 255.0f),
 
47
            clamp(g, 0.0f, 255.0f),
 
48
            clamp(b, 0.0f, 255.0f),
 
49
            clamp(color.w, 0.0f, 1.0f));
 
50
 
 
51
  color.x /= (color.x > 1.0) ? 255.0f : 1.0f;
 
52
  color.y /= (color.y > 1.0) ? 255.0f : 1.0f;
 
53
  color.z /= (color.z > 1.0) ? 255.0f : 1.0f;
 
54
}
 
55
 
 
56
const Tuple4f &GUIAlphaElement::getColor()
 
57
{
 
58
  return color;
 
59
}
 
60
 
 
61
void  GUIAlphaElement::setLabelString(const std::string &labelArg)
 
62
{
 
63
  label = labelArg;
 
64
}
 
65
 
 
66
GUIText * GUIAlphaElement::getLabel()
 
67
{
 
68
  return &label;
 
69
}
 
70
 
 
71
const std::string &GUIAlphaElement::getLabelString()
 
72
{
 
73
  return label.getString();
 
74
}
 
75
 
 
76
void  GUIAlphaElement::setAlpha(float alphaArg)
 
77
{
 
78
  color.w = clamp(alphaArg, minAlpha, 1.0f);
 
79
}
 
80
 
 
81
float GUIAlphaElement::getAlpha()
 
82
{
 
83
  return color.w;
 
84
}
 
85
 
 
86
void  GUIAlphaElement::setAlphaFadeScale(float duration)
 
87
{
 
88
  alphaFadeScale = clamp(duration, 0.0f, 10.0f);
 
89
}
 
90
 
 
91
float GUIAlphaElement::getAlphaFadeScale()
 
92
{
 
93
  return alphaFadeScale;
 
94
}
 
95
 
 
96
void  GUIAlphaElement::setMinAlpha(float minAlphaArg)
 
97
{
 
98
  minAlpha = clamp(minAlphaArg, 0.2f, 1.0f);
 
99
}
 
100
 
 
101
float GUIAlphaElement::getMinAlpha()
 
102
{
 
103
  return minAlpha;
 
104
}
 
105
 
 
106
void GUIAlphaElement::modifyCurrentAlpha(float clockTick)
 
107
{
 
108
  if(!mouseOver && !pressed)
 
109
    setAlpha(color.w - clockTick * alphaFadeScale);
 
110
  else
 
111
    setAlpha(color.w + clockTick * alphaFadeScale);
 
112
}
 
113
 
 
114