first of all I'd like to say that I'm really impressed by how powerful and handy this engine is
Writing some starts for an item/inventory system, I encountered a possible flaw (idk what's your opinion on this one) when centering a window inside another one using the following code:
Code: Select all
m_IconDragContainer->setPosition((CDragDropIconContainer::Size - CDragDropIcon::Size) / CEGUI::UVector2(CEGUI::UDim(0,2),CEGUI::UDim(0,2)));
m_IconDragContainer is a CEGUI::Window* and CDragDropIconContainer::Size and CDragDropIcon::Size are CEGUI::UVector2 that only have fixed dimensions (as I want items to be 32x32 pixel always).
What I was trying to do is dividing the total border area size by two to get the offset to center the item icon.
Looking at
Code: Select all
UVector2 operator/(const UVector2& other) const { return UVector2(d_x / other.d_x, d_y / other.d_y); }
and
Code: Select all
UDim operator/(const UDim& other) const { return UDim(d_scale / other.d_scale, d_offset / other.d_offset); }
in CEGUIUDim.h, one can easily see what is going to happen at this part:
Code: Select all
d_scale / other.d_scale
of course there are several workarounds to this like just setting other.d_scale to something else as this->d_scale is zero anyway:
Code: Select all
m_IconDragContainer->setPosition((CDragDropIconContainer::Size - CDragDropIcon::Size) / CEGUI::UVector2(CEGUI::UDim(1,2),CEGUI::UDim(1,2)));
or doing the division manually
Code: Select all
CEGUI::UVector2 diff = CDragDropIconContainer::Size - CDragDropIcon::Size;
m_IconDragContainer->setPosition(CEGUI::UVector2(cegui_absdim(diff.d_x.d_offset / 2),cegui_absdim(diff.d_y.d_offset /2)));
but all of them are quite nasty
I'd suppose either checking for zero in the division routines or adding custom division functions like CEGUI::UVector2::divAbs and CEGUI::UVector2::divRel or something similar
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
another feature I'd like to request in this context is overloaded operators of UVector2 and UDim like Ogre3D has it for their Vector classes:
Code: Select all
UVector2 operator+(const UDim& other) const;
UVector2 operator-(const UDim& other) const;
UVector2 operator/(const UDim& other) const;
UVector2 operator*(const UDim& other) const;
and so on, which divide both, x and y, by other. Would come in quite handy to shorten my initial code to
Code: Select all
m_IconDragContainer->setPosition((CDragDropIconContainer::Size - CDragDropIcon::Size) / cegui_absdim(2));
or something similar
Thanks for your time and again thanks for that great engine
-BigG