*
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#ifndef GUIWidgetSkin_h__
|
||||
#define GUIWidgetSkin_h__
|
||||
|
||||
#include "LString.h"
|
||||
#include <map>
|
||||
#include "math/LifeMath.h"
|
||||
#include "Types.h"
|
||||
|
||||
|
||||
namespace LifeGUI
|
||||
{
|
||||
class GUISkinElement;
|
||||
class GUISkinState;
|
||||
class GUIWidgetSkin;
|
||||
|
||||
class GUISkinElement
|
||||
{
|
||||
public:
|
||||
LifeMath::Vec4i Coord;
|
||||
LifeMath::float4 Mapping;
|
||||
GUISkinElement(const LifeMath::Vec4i& pixCoords, const LifeMath::float4& texCoords)
|
||||
{
|
||||
Coord = pixCoords;
|
||||
Mapping = texCoords;
|
||||
}
|
||||
};
|
||||
class GUISkinState
|
||||
{
|
||||
private:
|
||||
std::map<String, GUISkinElement*> elements;
|
||||
LifeMath::Vec2i texSize;
|
||||
LifeMath::float4 ComputeTC(const LifeMath::Vec4i& coord)
|
||||
{
|
||||
float x, y, z, w;
|
||||
LifeMath::Vec4i pixCoord = coord + LifeMath::Vec4i(0,0,1,1);
|
||||
|
||||
x = (float)pixCoord.X / (float)texSize.X;
|
||||
y = (float)pixCoord.Y / (float)texSize.Y;
|
||||
z = (float)pixCoord.Z / (float)texSize.X;
|
||||
w = (float)pixCoord.W / (float)texSize.Y;
|
||||
|
||||
return LifeMath::float4(x, y, z-x, w-y);
|
||||
}
|
||||
public:
|
||||
GUISkinState(const LifeMath::Vec2i& texDim)
|
||||
{
|
||||
texSize = texDim;
|
||||
}
|
||||
~GUISkinState()
|
||||
{
|
||||
}
|
||||
void AddElement(const String& name, const LifeMath::Vec4i& data)
|
||||
{
|
||||
GUISkinElement* element = new GUISkinElement(data, ComputeTC(data));
|
||||
elements[name] = element;
|
||||
}
|
||||
GUISkinElement* GetElement(const String& name)
|
||||
{
|
||||
return elements[name];
|
||||
}
|
||||
};
|
||||
class GUIWidgetSkin
|
||||
{
|
||||
public:
|
||||
IImage* texture;
|
||||
std::map<String, GUISkinState*> states;
|
||||
|
||||
GUIWidgetSkin(IImage* skinTex)
|
||||
{
|
||||
texture = skinTex;
|
||||
}
|
||||
GUISkinState* AddState(const String& name)
|
||||
{
|
||||
GUISkinState* state = new GUISkinState(LifeMath::Vec2i(texture->GetWidth(), texture->GetHeight()));
|
||||
states[name] = state;
|
||||
return state;
|
||||
}
|
||||
GUISkinState* GetState(const String& name)
|
||||
{
|
||||
if(states.find(name) == states.end())
|
||||
{
|
||||
if(states.find(STR("Normal")) != states.end())
|
||||
{
|
||||
return states[STR("Normal")];
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
return states[name];
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // GUIWidgetSkin_h__
|
||||
Reference in New Issue
Block a user