updated codes of Gradient, added comments, upgrade function name.

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-07-24 14:22:19 +08:00
parent b0d404bb11
commit 11000ebc22

View File

@ -8,12 +8,12 @@ namespace hgl
{ {
template<typename P,typename T> struct GradientStop template<typename P,typename T> struct GradientStop
{ {
P pos; P pos; ///<进度数据
T data; T data; ///<数据
}; };
/** /**
* *
*/ */
template<typename P,typename T> class Gradient template<typename P,typename T> class Gradient
{ {
@ -44,6 +44,9 @@ namespace hgl
dirty=true; dirty=true;
} }
/**
*
*/
void Add(const P &pos,const T &data) void Add(const P &pos,const T &data)
{ {
GS gs; GS gs;
@ -61,11 +64,14 @@ namespace hgl
dirty=true; dirty=true;
} }
const bool GetLowest(P &pos)const /**
*
*/
const bool GetLowestPosition(P &pos)const
{ {
GS gs; GS gs;
if(stop_list.First(gs)) if(stop_list.GetFirst(gs))
{ {
pos=gs.pos; pos=gs.pos;
return(true); return(true);
@ -74,11 +80,14 @@ namespace hgl
return false; return false;
} }
const bool GetHighest(P &pos)const /**
*
*/
const bool GetHighestPosition(P &pos)const
{ {
GS gs; GS gs;
if(stop_list.Last(gs)) if(stop_list.GetLast(gs))
{ {
pos=gs.pos; pos=gs.pos;
return(true); return(true);
@ -87,11 +96,48 @@ namespace hgl
return false; return false;
} }
/**
*
*/
const bool GetLowestData(T &data)const
{
GS gs;
if(stop_list.GetFirst(gs))
{
data=gs.data;
return(true);
}
return false;
}
/**
*
*/
const bool GetHighestData(T &data)const
{
GS gs;
if(stop_list.GetLast(gs))
{
data=gs.data;
return(true);
}
return false;
}
virtual void Get(T &reuslt,const T &start,const T &end,const float &pos) virtual void Get(T &reuslt,const T &start,const T &end,const float &pos)
{ {
result=start+(end-start)*pos; result=start+(end-start)*pos;
} }
/**
*
* @param pos
* @param result
*/
const void Get(T &result,const P &pos) const void Get(T &result,const P &pos)
{ {
const uint count=stop_list.GetCount(); const uint count=stop_list.GetCount();
@ -141,4 +187,18 @@ namespace hgl
} \ } \
\ \
template<> void name::Get(T &result,const T &start,const T &end,const float &pos) template<> void name::Get(T &result,const T &start,const T &end,const float &pos)
/*
HGL_GRADIENT_DEFINE(GradientColor3f,float,Lum)
{
result=start+(end-start)*pos;
}
HGL_GRADIENT_DEFINE(GradientColor3u8,uint,Color3b)
{
result.r=start.r+float(end.r-start.r)*pos;
result.g=start.g+float(end.g-start.g)*pos;
result.b=start.b+float(end.b-start.b)*pos;
}
*/
}//namespace hgl }//namespace hgl