| 23 | == Spring 2008 == |
| 24 | |
| 25 | Instead defining the whole HUD in a single script, and then linking every object of the script into a C++ file, it is now possible to directly creating the HUD in a single C++ file. In orxonox.cc, only one command is needed: |
| 26 | {{{ |
| 27 | HUD hud = new HUD(int zoom); |
| 28 | }}} |
| 29 | the idea is to create a flexible HUD, which can become bigger or smaller easily. |
| 30 | |
| 31 | A simple element of the HUD can be created as following: |
| 32 | {{{ |
| 33 | Ogre:: OverlayManager& overlayManager = Ogre:: OverlayManager::getSingleton(); |
| 34 | Ogre:: OverlayElement* element = overlayManager.createOverlayElement("Panel",name); |
| 35 | }}} |
| 36 | |
| 37 | In the second step, it is to create few inherited classes to Ogre:: OverlayElement, so more complicated and often used elements can be easily implemented. There is a problem about inheritance: Ogre:: OverlayElement doesnt have a constructor for itself, and Ogre:: OverlayManager::getSingleton().createOverlayElement() only creates an OverlayElement, but not its inherited classes. I could not find out how to inherit Ogre:: OverlayElement, so I wrote classes, which have an OverlayElement as public variable and several functions to change this OverlayElement. |
| 38 | |
| 39 | Class Bar: |
| 40 | {{{ |
| 41 | class _OrxonoxExport Bar |
| 42 | { |
| 43 | |
| 44 | ..... |
| 45 | ..... |
| 46 | |
| 47 | public: |
| 48 | Ogre:: OverlayElement* element; |
| 49 | |
| 50 | Bar(Ogre:: Real left, Ogre:: Real top, Ogre:: Real width, Ogre:: Real height, |
| 51 | int dir, int colour, std::string name); |
| 52 | ~Bar(void); |
| 53 | void reset(int percentage); |
| 54 | void setColour(int colour); |
| 55 | void show(); |
| 56 | void hide(); |
| 57 | }; |
| 58 | }}} |
| 59 | |
| 60 | Single elements cannot be directly put into HUD, they have to be added into a panel at first. The panel will be set into the whole overlay afterwards. |
| 61 | {{{ |
| 62 | Bar* energyCounter; |
| 63 | Ogre::OverlayContainer* energyCounterPanel; |
| 64 | |
| 65 | ... |
| 66 | |
| 67 | Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD"); |
| 68 | orxonoxOverlay->add2D(energyCounterPanel); |
| 69 | orxonoxOverlay->show(); |
| 70 | }}} |
| 71 | |
| 72 | |
| 73 | |