Author Paul D Turner The purpose of this tutorial is to show you how to create a simple window and get it on screen. Before continuing here, it is very important that you have already read and fully understood the articles 1 - The Beginners Guide to Initialising CEGUI , 2 - The Beginners Guide to resource loading with ResourceProviders and 3 - The Beginners Guide to Data Files and Defaults Initialisation because this tutorial builds upon the basic ideas introduced in those previous tutorials. Introduction to window and widget concepts Before we get to the the meat of this tutorial there are some essential ideas that you must first consider. Every widget within the system is derived from the same Window base class; so for the purposes of this tutorial, whenever I mention a window, the same ideas could just as easily be applied to a push button or scrollbar widget. Many settings are inherited Many of the settings and properties available for windows in CEGUI are passed down the window hierarchy.
|Published (Last):||5 March 2015|
|PDF File Size:||5.8 Mb|
|ePub File Size:||7.7 Mb|
|Price:||Free* [*Free Regsitration Required]|
This is not a hard thing to do. Every frame in an update function a timepulse needs to be injected. This is the time that passed between this frame, and the previous frame: System::getSingleton. This is the element that contains all other controls and windows. Now, the second line is basically the default way of adding things: Create a window, and cast it to a different type.
Another default skin is called "Falagard". The second argument is the "path". In the introduction the "hierarchy" of interfaces was explained. This is where it comes back. Therefore you can have multiple objects with the same name, but not with the same path. Think of it as a directory structure. It is quite the same. An window needs to be retrieved using the same path. And finally the third line of code will add the button as a child to the root window.
This is how it works for nearly every object. Objects have properties as well. These properties determine the position, size, text, etc. This tutorial shows the creation of many GUI objects, including listboxes with columns!
Events Right now we can press as long as we want on the button, but nothing will happen. Creating an event handler does not take too much effort either: WindowManager::getSingleton.
The first argument of the subScribeEvent specifies the type of event that we want to subscribe to. The GUI objects do not share all the same properties.
A slider object has "Slider::EventValueChanged" for example, while the Pushbutton does not have such an event. For a complete list of properties check this page. Which means I assume that the function is in the same class as the above code. As you might see the function has an argument "EventArgs". This argument will be filled with event information. A few pieces of information you can get: Mouse position, which mouse button, which object triggered the event, etc.
Remember when I talked about event bubbling? It will stop at this event. If you returned false, it will continue traversing the hierarchy. For a mouse move event this might be trivial. Event argument Edit As you might have seen in the handleButton code, an argument is given to the function. This argument gives you information about the event. There are various argument types available depending on the event that occurred. A keyboard event returns "KeyEventArgs" which will tell you which key is pressed and which system keys control, shift, alt, A Drag and drop event tells you what dropped.
There are quite some events available, but they all share one single property: The "window" object. This object tells you either what the source was of the event, or the destination the object that received the event One important point regarding the events is casting.
It takes an "EventArgs" argument. This argument does not contain anything about the mouse, so we can cast it to the MouseEventArgs using the above code.
The same applies to all other events. With above code you could use "evMouse. A MouseMove event will not tell you which button is pressed. Be careful with this! Unsubscribing an event You might want to remove events. Removing an event involves two steps: Get the window with the event you subscribed to, and then remove it. We have covered the initializing subscribing , using handlers and the unsubscribing of events. This will allow Lua to communicate directly with your game code.
This chapter deals with the generation of this interface. This is the original version meant for C. You might want to add extra methods to the Lua interface, or remove function. For example: Should it be possible to add objects by script or not? If not, the AddObject function can be removed. CEGUI comes with quite some package files already. Although in the earlier chapters this was addressed before, I do want to say again that the options are endless: Script event handlers, create windows or buttons.
Be creative! Here is a quick example from my own game. Basically there are three steps: Make package file s Compile package file s Include the single generated file in your application. On to the second part. This batch file compiles one single package file. This single package file actually includes all the other files, and therefore a complete file is generated. To create a batch file, simply create a text file in your favorite text editor, put the code below in it, and save it with an extension of ".
This batch file will generate an header file "LuaInterface. The contents of "LuaInterface. Compilation only takes a few seconds. Now you should have a dosbox open. Anything that goes wrong will be shown, and the window will stay open. To use the generated files, simply drag and drop or use Add file Working source code can be downloaded here.
Please follow the "source code" instructions at the end of this tutorial or read the included readme for proper installation of the files. This chapter continues from that point. First, we need to consider what we want to do in this Lua script. In my own project this Lua script is calling about ten other Lua files together I prefer things separated from each other and is loading 3D Models, Textures, Configuration of units - and of course the interface!
Remember the setLuaPath function? Check out the sample source code, and you will find the function. It sets some predefined paths to make file handling a lot easier. Additional filenames are appended using ".. Including files Although this tutorial will not go into detail about the Lua language, knowing how to include Lua files might be a good thing to get used to immediately: dofile App.
So, if you have multiple files which you want to combine in one file you could simply do: dofile App. System:getSingleton Actually, I think that covers nearly all singletons which we will ever use. The names look familiar they should! The above code will simply create a local variable to make it easier for you to access the managers.
That should get you nail biting of excitement already!
Tutorial: CEGUI and SFML
This is not a hard thing to do. Every frame in an update function a timepulse needs to be injected. This is the time that passed between this frame, and the previous frame: System::getSingleton. This is the element that contains all other controls and windows. Now, the second line is basically the default way of adding things: Create a window, and cast it to a different type. Another default skin is called "Falagard". The second argument is the "path".
Crazy Eddies GUI System:Tutorials:Creating a scriptable interface using CEGUI
What do you think? This tutorial builds on the previous beginner tutorials, and it assumes you have already worked through them. Just as a side note: The following two directories are needed. However if you go to your install path the commons folder will not be there.
Also note that the value NoButton is not 0. If you are using Microsoft DirectInput, then our scan codes are the same ones output by that library, in other cases you may be required to perform some translation. At present no automatic key mapping and generation of character codes is performed, also there is no integrated key auto-repeat functionality - though these functions may appear in future releases. If you need key auto-repeat then you will need to either use an input library that offers this function, or implement something directly.