• entries
743
1924
• views
581920

# Direct3D GUI

158 views

Got a bit distracted by writing a Direct3D GUI system. Click the below for a fullsize picture.

Nice, huh? All the windows can be dragged around by their title bar, child windows are automatically clipped and cannot be dragged beyond the bounds of their parent windows and the client areas of windows with title bars are seperate classes, so you can derive a class from GDX::Window, say to represent a list view or a drawing canvas, then create a GDX::Frame, passing a pointer to your custom class.

You automatically get a draggable, title barred and bordered window, but all the OnRender(), OnMouseMove() etc methods of your derived class automatically recieve client translated mouse-coords, clipped rendering space and any actual drawing calls, via the GraphicsDevice passed to OnRender, are automatically translated to the client area behind the scenes.

Here's a little demo if anyone wants to have a play around with it.

Alt-F4 to quit.

If you edit the convex.xcs file with Notepad, you can change the resolution if you want.

Edit gdx.xcs with Notepad and you can mess about with all the GUI colors. The colour strings are in the format "A R G B" (A - alpha).

This is quite a nice example of the usefulness of XCS actually. The gdx.xcs file looks like this:

// Convex 1.0 GDX configuration settingsdefaultfont="gdxfont.spf";colors{	titlebar	{		hi { a="255 0 128 128"; b="255 0 64 64"; }		lo { a="255 100 100 100"; b="255 50 50 50"; }		fonthi="255 255 255 255";		fontlo="255 0 0 0";	}	border	{		hi="255 0 64 64";		lo="255 50 50 50";	}}

It allows for quite nice organising of data in the config file, and reading it at runtime is as simple as, for example:

void GDX::Window::LoadSettings(const std::string &Base,const std::string &Xcs){	xcs::node Root;	xcs::open(Base+Xcs,Root);		if(!DefaultFont.Acquire(Base+Root["defaultfont"].value,256)) throw Exception(101,Base+Root["defaultfont"].value);	Colors["BarHiA"]=ColorFromString(Root["colors"]["titlebar"]["hi"]["a"].value);	Colors["BarHiB"]=ColorFromString(Root["colors"]["titlebar"]["hi"]["b"].value);	Colors["BarLoA"]=ColorFromString(Root["colors"]["titlebar"]["lo"]["a"].value);	Colors["BarLoB"]=ColorFromString(Root["colors"]["titlebar"]["lo"]["b"].value);		Colors["BarFontHi"]=ColorFromString(Root["colors"]["titlebar"]["fonthi"].value);	Colors["BarFontLo"]=ColorFromString(Root["colors"]["titlebar"]["fontlo"].value);	Colors["BorderHi"]=ColorFromString(Root["colors"]["border"]["hi"].value);	Colors["BorderLo"]=ColorFromString(Root["colors"]["border"]["lo"].value);}

Colors is a std::map and ColorFromString() just parses a std::string into a D3DCOLOR_ARGB thingy.

Very nice demo! clean and elegant. Do you plan to add widgets, scrollbars etc.?

Thanks, and yes, I plan to add as many controls as I can.