home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / Samples / FirstWindow / src / Sample_FirstWindow.cpp next >
Encoding:
C/C++ Source or Header  |  2005-08-19  |  8.7 KB  |  174 lines

  1. /************************************************************************
  2.     filename:   Sample_FirstWindow.cpp
  3.     created:    10/3/2005
  4.     author:     Paul D Turner
  5. *************************************************************************/
  6. /*************************************************************************
  7.     Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
  8.     Copyright (C)2004 - 2005 Paul D Turner (crayzed@users.sourceforge.net)
  9.  
  10.     This library is free software; you can redistribute it and/or
  11.     modify it under the terms of the GNU Lesser General Public
  12.     License as published by the Free Software Foundation; either
  13.     version 2.1 of the License, or (at your option) any later version.
  14.  
  15.     This library is distributed in the hope that it will be useful,
  16.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.     Lesser General Public License for more details.
  19.  
  20.     You should have received a copy of the GNU Lesser General Public
  21.     License along with this library; if not, write to the Free Software
  22.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23. *************************************************************************/
  24. #include "Sample_FirstWindow.h"
  25. #include "CEGUI.h"
  26.  
  27. #if defined( __WIN32__ ) || defined( _WIN32 )
  28. #define WIN32_LEAN_AND_MEAN
  29. #include "windows.h"
  30.  
  31. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
  32. #else
  33. int main(int argc, char *argv[])
  34. #endif
  35. {
  36.     // This is a basic start-up for the sample application which is
  37.     // object orientated in nature, so we just need an instance of
  38.     // the CEGuiSample based object and then tell that sample application
  39.     // to run.  All of the samples will use code similar to this in the
  40.     // main/WinMain function.
  41.     FirstWindowSample app;
  42.     return app.run();
  43. }
  44.  
  45. /*************************************************************************
  46.     Sample specific initialisation goes here.
  47. *************************************************************************/
  48. bool FirstWindowSample::initialiseSample()
  49. {
  50.     using namespace CEGUI;
  51.  
  52.     // CEGUI relies on various systems being set-up, so this is what we do
  53.     // here first.
  54.     //
  55.     // Note that is is possible, and even usual, for most of these steps to
  56.     // be done automatically via a "scheme" definition, or even from the
  57.     // cegui.conf configuration file, however for completeness, and as an
  58.     // example, virtually everything is being done manually in this example
  59.     // code.
  60.  
  61.     // Imagesets area a collection of named areas within a texture or image
  62.     // file.  Each area becomes an Image, and has a unique name by which it
  63.     // can be referenced.  This sample is using the TaharezLook widgets, and
  64.     // these rely upon the TaharezLook Imageset; so we must load this in
  65.     // before doing anything else.  Note that the Imageset would normally be
  66.     // specified as part of a scheme file, although as this example is
  67.     // demonstrating, it is not a requirement.
  68.     //
  69.     // Load TaharezLook imageset by making use of the ImagesetManager singleton.
  70.     Imageset* taharezImages = ImagesetManager::getSingleton().createImageset("../datafiles/imagesets/TaharezLook.imageset");
  71.  
  72.     // The next thing we do is to set a default mouse cursor image.  This is
  73.     // not strictly essential, although it is nice to always have a visible
  74.     // cursor if a window or widget does not explicitly set one of its own.
  75.     //
  76.     // The TaharezLook Imageset contains an Image named "MouseArrow" which is
  77.     // the ideal thing to have as a defult mouse cursor image.
  78.     System::getSingleton().setDefaultMouseCursor(&taharezImages->getImage("MouseArrow"));
  79.  
  80.     // Now we have the gui imagery side of thigs set up, we should load in a font.
  81.     // You should always load in at least one font, this is to ensure that there
  82.     // is a default available for any gui element which needs to draw text.
  83.     // The first font you load is automatically set as the initial default font,
  84.     // although you can change the default later on if so desired.  Again, it is
  85.     // possible to list fonts to be automatically loaded as part of a scheme, so
  86.     // this step may not usually be performed explicitly.
  87.     //
  88.     // Fonts are loaded via the FontManager singleton.
  89.     FontManager::getSingleton().createFont("../datafiles/fonts/Commonwealth-10.font");
  90.  
  91.     // The final step of basic initialisation that is usually peformed is
  92.     // registering some widgets with the system via a scheme file.  The scheme
  93.     // basically states the name of a dynamically loaded module that contains the
  94.     // concrete widget classes that we wish to use, and the names of the widgets
  95.     // that are to be registed.  As stated previously, a scheme can actually
  96.     // conatin much more information, though for the sake of this first example, we
  97.     // load a scheme which only contains what is required to register some widgets.
  98.     //
  99.     // Use the SchemeManager singleton to load in a scheme that registers widgets
  100.     // for TaharezLook.
  101.     SchemeManager::getSingleton().loadScheme("../datafiles/schemes/TaharezLookWidgets.scheme");
  102.  
  103.     // Now the system is initialised, we can actually create some UI elements, for
  104.     // this first example, a full-screen 'root' window is set as the active GUI
  105.     // sheet, and then a simple frame window will be created and attached to it.
  106.  
  107.     // All windows and widgets are created via the WindowManager singleton.
  108.     WindowManager& winMgr = WindowManager::getSingleton();
  109.  
  110.     // Here we create a "DeafultWindow".  This is a native type, that is, it does
  111.     // not have to be loaded via a scheme, it is always available.  One common use
  112.     // for the DefaultWindow is as a generic container for other windows.  Its
  113.     // size defaults to 1.0f x 1.0f using the Relative metrics mode, which means
  114.     // when it is set as the root GUI sheet window, it will cover the entire display.
  115.     // The DefaultWindow does not perform any rendering of its own, so is invisible.
  116.     //
  117.     // Create a DefaultWindow called 'Root'.
  118.     DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
  119.  
  120.     // set the GUI root window (also known as the GUI "sheet"), so the gui we set up
  121.     // will be visible.
  122.     System::getSingleton().setGUISheet(root);
  123.  
  124.     // A FrameWindow is a window with a frame and a titlebar which may be moved around
  125.     // and resized.
  126.     //
  127.     // Create a FrameWindow in the TaharezLook style, and name it 'Demo Window'
  128.     FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window");
  129.  
  130.     // Here we attach the newly created FrameWindow to the previously created
  131.     // DefaultWindow which we will be using as the root of the displayed gui.
  132.     root->addChildWindow(wnd);
  133.  
  134.     // Windows are in Relative metrics mode by default.  This means that we can
  135.     // specify sizes and positions without having to know the exact pixel size
  136.     // of the elements in advance.  The relative metrics mode co-ordinates are
  137.     // relative to the parent of the window where the co-ordinates are being set.
  138.     // This means that if 0.5f is specified as the width for a window, that window
  139.     // will be half as its parent window.
  140.     //
  141.     // Here we set the FrameWindow so that it is half the size of the display,
  142.     // and centered within the display.
  143.     wnd->setPosition(Point(0.25f, 0.25f));
  144.     wnd->setSize(Size(0.5f, 0.5f));
  145.  
  146.     // now we set the maximum and minum sizes for the new window.  These are
  147.     // specified using relative co-ordinates, but the important thing to note
  148.     // is that these settings are aways relative to the display rather than the
  149.     // parent window.
  150.     //
  151.     // here we set a maximum size for the FrameWindow which is equal to the size
  152.     // of the display, and a minimum size of one tenth of the display.
  153.     wnd->setMaximumSize(Size(1.0f, 1.0f));
  154.     wnd->setMinimumSize(Size(0.1f, 0.1f));
  155.  
  156.     // As a final step in the initialisation of our sample window, we set the window's
  157.     // text to "Hello World!", so that this text will appear as the caption in the
  158.     // FrameWindow's titlebar.
  159.     wnd->setText("Hello World!");
  160.  
  161.     // return true so that the samples framework knows that initialisation was a
  162.     // success, and that it should now run the sample.
  163.     return true;
  164. }
  165.  
  166.  
  167. /*************************************************************************
  168.     Cleans up resources allocated in the initialiseSample call.
  169. *************************************************************************/
  170. void FirstWindowSample::cleanupSample()
  171. {
  172.     // nothing to do here!
  173. }
  174.