[C++] GUI Magnet Window Manager for Irrlicht 1.8

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

[C++] GUI Magnet Window Manager for Irrlicht 1.8

Post by xterminhate »

See http://irrlicht.sourceforge.net/forum/v ... =9&t=48327 for the latest release of this class.



----------------------------------------------------- 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);
It acts as a window manager. Once created, you can change the behavior using setBehavior(). Default behavior (RESET) at startup does nothing. You can change its behavior in-game using a toolbar, a context menu, or simply buttons. It is up to the final user.

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).
    };
 
I have modified the Irrlicht Example #05.UserInterface, so you can try it without much effort. You can change the behavior during run time and there is a debug interface that show/hide the child JOINTS.

Image
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. :wink:
---edit2 : Improved algorithms. Posted the source code on snipplr.
Last edited by xterminhate on Wed Mar 13, 2013 8:47 pm, edited 16 times in total.
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Re: GUI Magnet Window Manager for Irrlicht 1.8

Post by Seven »

this is pretty cool stuff!

I am not sure that it fits into my plans, but you did some good work here.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Re: [C++] GUI Magnet Window Manager for Irrlicht 1.8

Post by xterminhate »

Thank you ! :D
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
chronologicaldot
Competition winner
Posts: 685
Joined: Mon Sep 10, 2012 8:51 am

Re: [C++] GUI Magnet Window Manager for Irrlicht 1.8

Post by chronologicaldot »

Nice work!
Can't think of what I'd use it for either at the moment, but thanks for posting!
Post Reply