Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1329


Ignore:
Timestamp:
May 19, 2008, 10:51:53 PM (16 years ago)
Author:
FelixSchulthess
Message:

progress bars now resize automatically and have a new look

Location:
code/branches/hud3/src/orxonox/hud
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud3/src/orxonox/hud/BarOverlayElement.cc

    r1328 r1329  
    4949        color_ = 2;
    5050        autoColor_ = true;
    51         dir_ = BarOverlayElement::RIGHT;
     51        left2Right = false; // default: right to left progress
    5252
    5353        // get window data...
     
    6666
    6767        // create background...
    68         bar_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", name_+"Bar"));
    69         bar_->show();
    70         container_->addChild(bar_);
    71         bar_->setPosition(left_, top_);
    72         bar_->setDimensions(width_, height_);
    73         bar_->setMetricsMode(Ogre::GMM_PIXELS);
    74         bar_->setMaterialName("Orxonox/Green");
     68        background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
     69        background_->show();
     70        container_->addChild(background_);
     71        background_->setMetricsMode(Ogre::GMM_PIXELS);
     72        background_->setMaterialName("Orxonox/BarBackground");
    7573
    76         setPosition(left_,top_);
    77         setDimensions(width_,height_);
     74        show();
     75        background_->addChild(this);
    7876        setMetricsMode(Ogre::GMM_PIXELS);
    79         setMaterialName("Orxonox/BarBackground");
     77        setMaterialName("Orxonox/Green");
     78        resize();
     79    }
     80
     81    void BarOverlayElement::resize(){
     82        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
     83        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
     84        // cálculate new absolute coordinates...
     85        left_ = leftRel_ * windowW_;
     86        top_ = topRel_ * windowH_;
     87        width_ = widthRel_ * windowW_;
     88        height_ = heightRel_ * windowH_;
     89        // adapt background
     90        background_->setPosition(left_, top_);
     91        background_->setDimensions(width_, height_);
     92        // adapt bar
    8093        setValue(value_);
    8194    }
    8295
    83 
    84    void BarOverlayElement::setValue(float value){
     96    void BarOverlayElement::setValue(float value){
    8597        value_ = value;
    8698        // set color, if nescessary
     
    91103        }
    92104        // set value
    93         switch(dir_){
    94         case BarOverlayElement::DOWN:
    95             bar_->setPosition(left_,top_);
    96             bar_->setDimensions(width_,height_*value_);
    97             break;
    98         case BarOverlayElement::LEFT:
    99             bar_->setPosition(left_+width_-width_*value_,top_);
    100             bar_->setDimensions(width_*value_,height_);
    101             break;
    102         case BarOverlayElement::UP:
    103             bar_->setPosition(left_,top_+height_-height_*value_);
    104             bar_->setDimensions(width_,height_*value_);
    105             break;
    106         default:
    107             bar_->setPosition(left_,top_);
    108             bar_->setDimensions(width_*value_,height_);
    109             break;
     105        if(left2Right){ // backward case
     106            setPosition(0+width_-width_*value_, 0);
     107            setDimensions(width_*value_,height_);
     108        }else{          // default case
     109            setPosition(0, 0);
     110            setDimensions(width_*value_,height_);
    110111        }
    111     }
    112 
    113     void BarOverlayElement::setDir(int dir){
     112        if(value_ != 0) setTiling(value_, 1.0);
    114113    }
    115114
     
    118117        switch(color){
    119118        case 0:
    120             bar_->setMaterialName("Orxonox/Red");
     119            setMaterialName("Orxonox/Red");
    121120            break;
    122121        case 1:
    123             bar_->setMaterialName("Orxonox/Yellow");
     122            setMaterialName("Orxonox/Yellow");
    124123            break;
    125124        case 2:
    126             bar_->setMaterialName("Orxonox/Green");
     125            setMaterialName("Orxonox/Green");
    127126        }
    128127    }
  • code/branches/hud3/src/orxonox/hud/BarOverlayElement.h

    r1328 r1329  
    4444  {
    4545    private:
    46 
    47     bool autoColor_;                    // whether bar changes color automatically
    48     float value_;                       // progress of bar
    49     int dir_;                           // direction of progress
    50     int color_;
    51     int left_;
    52     int top_;
    53     int width_;
    54     int height_;
    55     int windowW_, windowH_;
    56     Ogre::Real leftRel_;
    57     Ogre::Real topRel_;
    58     Ogre::Real widthRel_;
    59     Ogre::Real heightRel_;
    60     Ogre::PanelOverlayElement* bar_;    // the actual bar
    61     Ogre::OverlayManager* om;           // our overlay manager
    62     Ogre::OverlayContainer* container_; // our parent container to attach to
    63     Ogre::String name_;
     46        bool autoColor_;                    // whether bar changes color automatically
     47        float value_;                       // progress of bar
     48        int color_;
     49        int left_;
     50        int top_;
     51        int width_;
     52        int height_;
     53        int windowW_, windowH_;
     54        Ogre::Real leftRel_;
     55        Ogre::Real topRel_;
     56        Ogre::Real widthRel_;
     57        Ogre::Real heightRel_;
     58        Ogre::OverlayManager* om;           // our overlay manager
     59        Ogre::OverlayContainer* container_; // our parent container to attach to
     60        Ogre::OverlayContainer* background_;
     61        Ogre::String name_;
    6462
    6563    public:
    66         // directions
    67         static const int RIGHT = 0;
    68         static const int UP = 1;
    69         static const int LEFT = 2;
    70         static const int DOWN = 3;
    71         // predefined colors
    72         static const int RED = 0;
     64        bool left2Right;
     65        static const int RED = 0;           // predefined colors
    7366        static const int YELLOW = 1;
    7467        static const int GREEN = 2;
     
    7669        BarOverlayElement(const Ogre::String& name);
    7770        virtual ~BarOverlayElement();
    78 
    7971        void init(Real leftRel, Real topRel, Real widthRel, Real heightRel, Ogre::OverlayContainer* container);
    80         void setDir(int dir);
     72        void resize();
    8173        void setValue(float value);
    8274        void setColor(int color);
    83 
    8475        float getValue();
    8576        int getBarColor();
  • code/branches/hud3/src/orxonox/hud/HUD.cc

    r1328 r1329  
    6666    radar->show();
    6767
    68     container->addChild(energyCounter);
    69     container->addChild(speedo);
    70     container->addChild(radar);
    7168    container->show();
    7269    orxonoxHUD->add2D(container);
     
    7875    container->setMetricsMode(Ogre::GMM_RELATIVE);
    7976
    80     energyCounter->init(0.01, 0.01, 0.2, 0.02, container);
     77    energyCounter->init(0.01, 0.95, 0.4, 0.04, container);
    8178    energyCounter->setValue(1);
    8279
    83     speedo->init(0.01, 0.04, 0.2, 0.02, container);
     80    speedo->init(0.01, 0.90, 0.4, 0.04, container);
    8481
    8582    radar->init(0.5, 0.9, 0.2, container);
     
    8885  void HUD::tick(float dt)
    8986  {
     87      energyCounter->resize();
     88
    9089      float v = SpaceShip::instance_s->getVelocity().length();
    9190      float vmax = SpaceShip::instance_s->getMaxSpeed();
    9291      speedo->setValue(v/vmax);
     92      speedo->resize();
     93
     94      radar->resize();
    9395      radar->update();
    9496  }
  • code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc

    r1328 r1329  
    7878        point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point"));
    7979        point->show();
     80        container->addChild(this);
    8081        container->addChild(point);
    8182        point->setMaterialName("Orxonox/RedDot");
     
    9798
    9899    void RadarOverlayElement::update() {
    99         resize();
    100100        shipPos_ = SpaceShip::instance_s->getPosition();
    101101        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
  • code/branches/hud3/src/orxonox/hud/RadarOverlayElement.h

    r1328 r1329  
    4141namespace orxonox
    4242{
     43    class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement
     44    {
     45        private:
     46            Ogre::PanelOverlayElement* point;
     47            Ogre::OverlayContainer* container_;
     48            Ogre::OverlayManager* om;               // pointer to the one and only overlay manager
     49            Vector3 initialDir_;                        // direction of nose
     50            Vector3 currentDir_;
     51            Vector3 initialOrth_;                   // direction of normal
     52            Vector3 currentOrth_;
     53            Vector3 targetPos_;                     // position of target
     54            Vector3 shipPos_;                       // position of ship
    4355
    44   class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement
    45   {
    46   private:
     56            Ogre::Real radius_;                     // radius on the radar
     57            Ogre::Real phi_;                        // angle on the radar
     58            bool right_;                            // checks whether the object is on the right side (since cos is not bijective)
     59            Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
     60            int left_, top_, dim_;                  // absolute position/dimension
     61            int windowW_, windowH_;                   // absolute window dimensions
     62            int count_;
    4763
    48     Ogre::PanelOverlayElement* point;
    49     Ogre::OverlayContainer* container_;
    50     Ogre::OverlayManager* om;               // pointer to the one and only overlay manager
    51     Vector3 initialDir_;                        // direction of nose
    52     Vector3 currentDir_;
    53     Vector3 initialOrth_;                   // direction of normal
    54     Vector3 currentOrth_;
    55     Vector3 targetPos_;                     // position of target
    56     Vector3 shipPos_;                       // position of ship
    57 
    58     Ogre::Real radius_;                     // radius on the radar
    59     Ogre::Real phi_;                        // angle on the radar
    60     bool right_;                            // checks whether the object is on the right side (since cos is not bijective)
    61     Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
    62     int left_, top_, dim_;                  // absolute position/dimension
    63     int windowW_, windowH_;                   // absolute window dimensions
    64     int count_;
    65 
    66     void resize();
    67 
    68   public:
    69 
    70     RadarOverlayElement(const Ogre::String& name);
    71     virtual ~RadarOverlayElement();
    72     virtual void initialise();
    73     void update();
    74     void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
    75     void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ);
    76     int newShip(int X, int Y, int Z);
    77 
    78     void resetShip(int shipID, int Y, int Z);
    79   };
     64        public:
     65            RadarOverlayElement(const Ogre::String& name);
     66            virtual ~RadarOverlayElement();
     67            virtual void initialise();
     68            void update();
     69            void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
     70            void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ);
     71            int newShip(int X, int Y, int Z);
     72            void resize();
     73            void resetShip(int shipID, int Y, int Z);
     74    };
    8075}
    8176
Note: See TracChangeset for help on using the changeset viewer.