Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6441 in orxonox.OLD


Ignore:
Timestamp:
Jan 8, 2006, 4:02:30 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: the Hud now scales the Widgets itself

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/graphics_engine.cc

    r6222 r6441  
    1919#include "resource_manager.h"
    2020#include "event_handler.h"
     21#include "state.h"
    2122
    2223#include "world_entity.h"
     
    298299  this->resolutionY = height;
    299300  this->bitsPerPixel = bpp;
     301  State::setResolution( width, height);
    300302
    301303  if (this->screen != NULL)
  • trunk/src/util/hud.cc

    r6440 r6441  
    1818#include "hud.h"
    1919
     20#include "state.h"
     21
    2022using namespace std;
    2123
     
    2931  this->setClassID(CL_HUD, "Hud");
    3032
    31 
     33  //this->setSize2D(
    3234  this->energyWidget = NULL;
    3335  this->shieldWidget = NULL;
    3436  this->armorWidget = NULL;
     37  this->resX = 1;
     38  this->resY = 1;
    3539}
    3640
     
    6771  {
    6872    this->energyWidget->show();
    69     this->energyWidget->setAbsCoor2D(10,80);
    70     this->energyWidget->setSize2D(20,300);
    7173  }
    7274
    73 
     75  this->updateResolution();
    7476}
    7577
     
    9496}
    9597
    96 void setResolution(unsigned int resX, unsigned int resY);
     98void Hud::updateResolution()
     99{
     100  this->resX = State::resX();
     101  this->resY = State::resY();
     102  if (this->energyWidget != NULL)
     103  {
     104    this->energyWidget->setAbsCoor2D(.02 * this->resX, .4 * this->resY);
     105    this->energyWidget->setSize2D(.05 * this->resX, .55 * this->resY);
     106  }
     107}
     108
     109
     110void Hud::tick(float dt)
     111{
     112  if (this->resY != State::resY() || this->resX != State::resY())
     113    this->updateResolution();
     114}
     115
     116void Hud::draw() const
     117{
     118  GLGuiWidget::draw();
     119}
     120
     121
  • trunk/src/util/hud.h

    r6438 r6441  
    1515
    1616//! A class that renders a HUD.
    17 class Hud : private GLGuiWidget
     17class Hud : public GLGuiWidget
    1818{
    1919
     
    2121  Hud();
    2222  virtual ~Hud();
     23
    2324
    2425  void loadParams(const TiXmlElement* root);
     
    3233  void removeWeaponWidget(GLGuiWidget* widget);
    3334
    34   void setResolution(unsigned int resX, unsigned int resY);
     35  void tick(float dt);
     36  void draw() const;
    3537
     38  private:
     39    void updateResolution();
    3640private:
    37   unsigned int             resX;          //!< The X-Resolution needed for resizing the Hud.
    38   unsigned int             resY;          //!< The Y-Resolution needed for resizing the Hud.
     41  unsigned int             resX;
     42  unsigned int             resY;
    3943
    4044  GLGuiWidget*             energyWidget;
  • trunk/src/util/state.cc

    r6222 r6441  
    3131ObjectManager* State::objectManager = NULL;
    3232
     33unsigned int State::_resX = 1;
     34unsigned int State::_resY = 1;
     35
    3336/**
    3437 *  sets camera and target of the current Camera
  • trunk/src/util/state.h

    r6222 r6441  
    3939  static inline ObjectManager* getObjectManager() { return State::objectManager; };
    4040
     41  static inline void setResolution(unsigned int resX, unsigned int resY) { State::_resX = resX; State::_resY = resY; };
     42  static inline unsigned int resX() { return State::_resX; };
     43  static inline unsigned int resY() { return State::_resY; };
     44
    4145  /////////////////////////
    4246  /// WORLD_ENTITY_LIST ///
     
    5155  static ObjectManager*         objectManager;      //!< A referenct to the current ObjectManager
    5256
     57  static unsigned int           _resX;              //!< The X Resolution of the screen.
     58  static unsigned int           _resY;              //!< The Y Resolution of the screen.
    5359};
    5460
  • trunk/src/world_entities/player.cc

    r6440 r6441  
    3838
    3939  this->controllable = NULL;
    40   this->hud = new Hud();
     40  this->hud.show();
    4141
    4242  EventHandler::getInstance()->subscribe(this, ES_GAME, SDLK_l);
     
    4949Player::~Player ()
    5050{
    51   delete this->hud;
    5251
    5352}
     
    5958  {
    6059      this->controllable = controllable;
    61       this->hud->setEnergyWidget(this->controllable->getEnergyWidget());
     60      this->hud.setEnergyWidget(this->controllable->getEnergyWidget());
    6261      return true;
    6362  }
     
    7372   {
    7473     this->controllable = NULL;
    75      this->hud->setEnergyWidget(NULL);
     74     this->hud.setEnergyWidget(NULL);
    7675     return true;
    7776   }
  • trunk/src/world_entities/player.h

    r6440 r6441  
    99#include "event_listener.h"
    1010
     11#include "util/hud.h"
     12
    1113/* Forward Declaration */
    1214class Playable;
    13 class Hud;
     15
    1416
    1517//! Basic controllable WorldEntity
     
    3638  private:
    3739    Playable*         controllable;                  //!< The one we controll or NULL if none
    38     Hud*              hud;                           //!< The HUD to be displayed.
     40    Hud               hud;                           //!< The HUD to be displayed for this Player.
    3941};
    4042
Note: See TracChangeset for help on using the changeset viewer.