• entries
    743
  • comments
    1924
  • views
    580439

Direct3D GUI

Sign in to follow this  

144 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 settings

defaultfont="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.
Sign in to follow this  


2 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now