From 11000ebc22634c8368317e1301a64e8eda3535f2 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Mon, 24 Jul 2023 14:22:19 +0800 Subject: [PATCH] updated codes of Gradient, added comments, upgrade function name. --- inc/hgl/type/Gradient.h | 74 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/inc/hgl/type/Gradient.h b/inc/hgl/type/Gradient.h index eb25982..4952252 100644 --- a/inc/hgl/type/Gradient.h +++ b/inc/hgl/type/Gradient.h @@ -8,12 +8,12 @@ namespace hgl { template struct GradientStop { - P pos; - T data; + P pos; ///<进度数据 + T data; ///<数据 }; /** - * 渐变类 + * 数据渐变类模板 */ template class Gradient { @@ -44,6 +44,9 @@ namespace hgl dirty=true; } + /** + * 添加一个渐变点 + */ void Add(const P &pos,const T &data) { GS gs; @@ -61,11 +64,14 @@ namespace hgl dirty=true; } - const bool GetLowest(P &pos)const + /** + * 取得最低渐变进度 + */ + const bool GetLowestPosition(P &pos)const { GS gs; - if(stop_list.First(gs)) + if(stop_list.GetFirst(gs)) { pos=gs.pos; return(true); @@ -74,11 +80,14 @@ namespace hgl return false; } - const bool GetHighest(P &pos)const + /** + * 取得最高渐变进度 + */ + const bool GetHighestPosition(P &pos)const { GS gs; - if(stop_list.Last(gs)) + if(stop_list.GetLast(gs)) { pos=gs.pos; return(true); @@ -87,11 +96,48 @@ namespace hgl 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) { result=start+(end-start)*pos; } + /** + * 取得指定进度下的渐变结果 + * @param pos 进度 + * @param result 结果 + */ const void Get(T &result,const P &pos) { 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) + + /* + 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