Table of Contents
| About | News | Mde's GUI | Features | Ideas | Platforms | Building | Utility Programs | Forum | Trac Wiki Help |
Interacting with the GUI: programming
Creating a widget manager
The widget manager is a class sitting between the GUI's widgets and input/output code. The current widget manager is split into two parts: AWidgetManager, which handles loading & saving the GUI using mergetag (mde's file IO library) and some special functionality required by widgets (through IWidgetManager and IParentWidget interfaces), and WMScreen, which uses mde's Screen class (an SDL wrapper) as the output device (and to get resize events) and mde's Input class (an SDL wrapper providing extra configuration) for keyboard/mouse input.
Creating and setting up a WMScreen instance is simple:
// Create an instance and bind it to the screen and input classes for draw, resize and input callbacks: // Also specify the file-name (mde.setup.paths is used to find the file; it ends up being "conf/guiDemo.mtt" from "data" or another directory) scope WMScreen gui = new WMScreen ("guiDemo"); // Load the gui and create widgets: gui.loadDesign(); // Save any changes to dimensions and widgets (although editing widgets isn't supported yet): scope(exit) gui.save;
Other stuff needs initialising to get other parts of mde running though; mostly mde.setup.Init does this. See guiDemo.d for a working program.
There's no limit to only one widget manager. For example, a second window manager using some mouse input adjustment and a renderer rendering to a texture could be used to put a gui on a virtual screen in a 3D world.
Making content accessible by the GUI
The widget manager is the only part of the GUI code intended for use outside the GUI package; for other interaction the mde.content package is used.
The following code creates a menu:
ContentList menu; /// Root menu for imde EventContent quit; /// A content triggering mde to halt static this () { auto quit = new EventContent("menus.main.quit"); quit.addCallback ((Content){ debug logger.trace ("Quit (from menu)"); run = false; }); }
The menu structure is created from the config files, using the addContent function to connect a widget to a content (e.g. specifying the string "menus.main.quit" will get the quit content directly; specifying "menus" will get the menu structure).
Contents with a value are also easy to use:
DoubleContent e; EnumContent lr; void someFunc () { e = new DoubleContent ("someContext.e", 2.7); lr = new EnumContent ("someContext.lr", ["left", "right", "neither"]); lr.addCallback ((Content lr) { logger.info ("{} is now {} ({})", lr.stringof(1), // translated name of lr lr.stringof(0), // translated name of current enumeration value lr() /* numerical value */); } }
