----------------------------------------------------- OLD POST -----------------------------------------------------
Hello,
I would like to share my custom GUI element (dynamic grid). It is the very first version of its source code.
Demo : http://www.youtube.com/watch?v=TlIWHTYHQxw
Demo with visible joints (DEBUG) : http://www.youtube.com/watch?v=Xk5vqG7XcrU
This GUI element is intended to be inserted onto top of the windows of your GUI.
Code: Select all
IGUIDynamicGrid* grid = new CGUIDynamicGrid( env, env->getRootGUIElement() );
//! later...
IGUIWindow* window = env->addWindow( rect<s32>(...), false, L"Your window", grid);
Code: Select all
//! Enumeration for all behaviors of the GUI Dynamic Grid element.
enum EGUI_DYNAMIC_GRID_BEHAVIOR
{
EGDGB_RESET=0, ///< Do nothing. Every child elements move freely.
EGDGB_ATTACH_RUN_ONCE, ///< Try to attach every nearer child elements together (then go to RUN behavior).
EGDGB_ATTACH_FOCUSED, ///< Try to attach the focused child element with the nearer child elements.
EGDGB_RUN, ///< Attached child elements remain attached, others move freely.
EGDGB_DETACH_FOCUSED, ///< Try to dettach the focused child element (it moves freely).
EGDGB_DETACH_ALL ///< Try to dettach every child elements (then go to RUN behavior).
};
Note : Attached joints are shown in green. Unaatached are empty rectangle.
How it works ? Every child elements are viewed as bones. A bone has got 8 joints (1 per corner (4) x 1 per axis (2)). When the distance between two unattached joints is less than 4 (pixels), the joints get attached, then the bones are attached. Draging a child element, will also drags every attached elements.
Limitations :
- You have to reset the behavior of grid when adding/removing child GUI element (you forgot = segfault) (see http://irrlicht.sourceforge.net/forum/v ... =1&t=48285). See the main.cpp, the best way is to save the behavior before adding or removing child, then set successivley the following behaviors : RESET => ATTACH_RUN_ONCE => previous behavior.
- Does not work with modal GUI childs.
Improvements :
- Rename this custom GUI element ! Something likes "GUIMagnetManager" sounds better...
- Snap the managed child elements to the borders and the corners of the viewport while dragging.
Source code download : http://snipplr.com/users/xterminhate/ta ... namicGrid/ (hope this link is public)
I will support the code as long as possible. I will use it in a little RTS game project of my own.
Good Bye,
X.
---edit1 : Once integrated in my own game, I detected a serious bug. I used IGUIElement::isMyChild() in a wrong way, causing segfault. V0.01 fixes the problem.
---edit2 : Improved algorithms. Posted the source code on snipplr.