[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In the following discussion I will try to explain how to build simple applications using the Crystal Space Windowing System. I hope you will understand enough to start writing your own applications; I also hope you will get a deeper knowledge of CSWS during your development (or lab) sessions. In fact, I highly recommend perusing the CSWS header files (or alternatively at the HTML documentation generated from the header files) as they contain a lot of useful information which is not present here.
The simplest possible application should do the following:
Let's try:
#include "csws/csws.h" int main(int argc, char const* const argv[]) { iObjectRegistry* object_reg = csInitializer::CreateEnvironment (argc, argv); if (!object_reg) return -1; if (!csInitializer::SetupConfigManager (object_reg, "/config/cswstest.cfg")) return -1; if (!csInitializer::RequestPlugins (object_reg, CS_REQUEST_END)) return -1; csApp* app = new csApp(object_reg); if (app.Initialize()) csDefaultRunLoop(object_reg); delete app; csInitializer::DestroyApplication (object_reg); } |
Pretty simple, eh? So the result is simple as well. We got a gray background, a mouse and nothing more. What the program does is:
CreateEnvironment()
.
csInitializer::RequestPlugin()
method). In our case, since we used a configuration file, we do not have to
ask for any additional plugins in the call to RequestPlugin()
, since it
will load all of the ones mentioned by the configuration file.
csApp::Initialize()
. You may want to override
this method to initialize your application here (after calling the parent's
Initialize()
). For instance, create a popup menu, insert it onto the
desktop, add some windows, etc.
Idle()
method to give some time slices to other running
applications. If some window needs redrawing, it is redrawn. After this the
screen is updated and everything starts again from the beginning.
If you observe, the above program allocates the `csApp' object on the
heap, rather than on the stack as an automatic variable. This is done so that
we can manually destroy that object before DestroyApplication()
is
called. This is important, because no Crystal Space or CSWS functionality
should be invoked after DestroyApplication()
has been called. By
destroying csApp
first, we ensure that code in its destructor is invoked
early enough.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |