diff --git a/inc/hgl/type/Size2.h b/inc/hgl/type/Size2.h index b82fdc9..85b8ae6 100644 --- a/inc/hgl/type/Size2.h +++ b/inc/hgl/type/Size2.h @@ -1,13 +1,14 @@ #pragma once #include +#include namespace hgl { /** * 尺寸模板 */ - template struct Size2 + template class Size2 { T width,height; @@ -18,6 +19,13 @@ namespace hgl width=height=0; } + template + Size2(const Size2 &s) + { + width =T(s.Width()); + height=T(s.Height()); + } + Size2(const T &w,const T &h) { Set(w,h); @@ -29,6 +37,26 @@ namespace hgl height=h; } + void SetWidth(const T &w) + { + width=w; + } + + void SetHeight(const T &h) + { + height=h; + } + + const T Width()const{return width;} + const T Height()const{return height;} + + template + void operator = (const Size2 &s) + { + width =T(s.Width()); + height=T(s.Height()); + } + const bool isLandscape()const{return width>height;} ///<是否横的 const bool isPortrait()const{return width Size2 operator op (const N &n) const {return Size2(width op n,height op n);} \ - template Size2 operator op (const Size2 &n) const {return Size2(width op n.Width(),height op n.Height());} + #define SIZE2_OPERATOR_INTERACTIVE(op) template Size2 operator op (const N &n) const {return Size2(width op n,height op n);} \ + template Size2 operator op (const Size2 &n) const {return Size2(width op n.Width(),height op n.Height());} + + SIZE2_OPERATOR_INTERACTIVE(+) + SIZE2_OPERATOR_INTERACTIVE(-) + SIZE2_OPERATOR_INTERACTIVE(*) + SIZE2_OPERATOR_INTERACTIVE(/) + #undef SIZE2_OPERATOR_INTERACTIVE + - SIZE2_OPERATOR_INTERACTIVE(+) - SIZE2_OPERATOR_INTERACTIVE(-) - SIZE2_OPERATOR_INTERACTIVE(*) - SIZE2_OPERATOR_INTERACTIVE(/) - #undef SIZE2_OPERATOR_INTERACTIVE /** * 计算另一个尺寸在当前尺寸内的等比缩放多大可以正好 @@ -103,6 +133,10 @@ namespace hgl return(scale); } + + const T Area()const{return width*height;} ///<面积 + + operator glm::vec<2,T,glm::defaultp>()const{return glm::vec<2,T,glm::defaultp>(width,height);} };//template struct Size2 using Size2i =Size2;