added aclSize in Size2<>
This commit is contained in:
parent
50e754aba2
commit
b43c236894
@ -19,6 +19,11 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
Size2(const T &w,const T &h)
|
Size2(const T &w,const T &h)
|
||||||
|
{
|
||||||
|
Set(w,h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Set(const T &w,const T &h)
|
||||||
{
|
{
|
||||||
width=w;
|
width=w;
|
||||||
height=h;
|
height=h;
|
||||||
@ -72,6 +77,30 @@ namespace hgl
|
|||||||
SIZE2_OPERATOR_INTERACTIVE(/)
|
SIZE2_OPERATOR_INTERACTIVE(/)
|
||||||
#undef SIZE2_OPERATOR_INTERACTIVE
|
#undef SIZE2_OPERATOR_INTERACTIVE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算另一个尺寸在当前尺寸内的等比缩放多大可以正好
|
||||||
|
* @param allow_over 允许超出
|
||||||
|
*/
|
||||||
|
const float alcScale(const Size2<T> &s,const bool allow_over) const
|
||||||
|
{
|
||||||
|
if(width<=0||height<=0)return(0);
|
||||||
|
if(s.width<=0||s.height<=0)return(0);
|
||||||
|
|
||||||
|
float scale=float(width)/float(s.width);
|
||||||
|
|
||||||
|
if(allow_over)
|
||||||
|
{
|
||||||
|
if(scale*float(s.height)<float(height))
|
||||||
|
scale=float(height)/float(s.height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(scale*float(s.height)>float(height))
|
||||||
|
scale=float(height)/float(s.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(scale);
|
||||||
|
}
|
||||||
};//template<typename T> struct Size2
|
};//template<typename T> struct Size2
|
||||||
|
|
||||||
using Size2i =Size2<int>;
|
using Size2i =Size2<int>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user