Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 8, 2008, 5:46:52 AM (16 years ago)
Author:
landauf
Message:
  • several small changes in most of the HUD classes (code cleanup): removed obsolete variables, privatized all member variables, removed resizing functioncalls from tick, destroying overlayelements, added some const qualifiers.
  • moved calculation functions for RadarObject-position to Math.h and changed the phi/right/radius format to Vector2. the functions are used too by SpaceShipAI.
  • cycleNavigationFocus takes the nearest object if focus was NULL
  • BarOverlayElement works in both directions (left to right and right to left)
  • fixed bug causing SpaceShipAI to not stop shooting when losing target - this also speeds up orxonox a lot, because there are less projectiles

####################################

!! UPDATE YOUR MEDIA REPOSITORY !!

####################################
…or the BarOverlayElement will look strange

File:
1 edited

Legend:

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

    r1505 r1564  
    3131#include <OgreOverlayManager.h>
    3232#include "GraphicsEngine.h"
     33#include "util/Math.h"
    3334
    3435namespace orxonox
     
    3637    using namespace Ogre;
    3738
    38     BarOverlayElement::BarOverlayElement(const String& name):PanelOverlayElement(name){
     39    BarOverlayElement::BarOverlayElement(const String& name) : PanelOverlayElement(name)
     40    {
    3941        name_ = name;
     42        widthratio_ = 100.0f / 800.0f; // calculates the ratio (backgroundwidth - barwidth) / backgroundwidth
    4043    }
    4144
    42     BarOverlayElement::~BarOverlayElement(){}
     45    BarOverlayElement::~BarOverlayElement()
     46    {
     47        OverlayManager::getSingleton().destroyOverlayElement(this->background_);
     48    }
    4349
    4450    void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
    4551        // init some values...
    46         container_ = container;
    47         om = &OverlayManager::getSingleton();
    4852        value_ = 0;
    49         color_ = 2;
    50         autoColor_ = true;
    51         left2Right = false;     // default is right to left progress
     53        colour_ = 2;
     54        autoColour_ = true;
     55        right2Left_ = false; // default is left to right progress
    5256        leftRel_ = leftRel;
    5357        topRel_ = topRel;
     
    5559
    5660        // create background...
    57         background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container"));
     61        background_ = static_cast<OverlayContainer*>(OverlayManager::getSingleton().createOverlayElement("Panel", name_+"container"));
    5862        background_->show();
    59         container_->addChild(background_);
     63        container->addChild(background_);
    6064        background_->setMetricsMode(GMM_PIXELS);
    6165        background_->setMaterialName("Orxonox/BarBackground");
     
    7175
    7276    void BarOverlayElement::resize(){
    73         windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
    74         windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
    7577        // calculate new absolute coordinates...
    76         left_ = (int) (leftRel_ * windowW_);
    77         top_ = (int) (topRel_ * windowH_);
    78         width_ = (int) (dimRel_ * windowW_);
    79         height_ = (int) (0.1*width_);   // the texture has dimensions height:length = 1:10
     78        left_ = (int) (leftRel_ * GraphicsEngine::getSingleton().getWindowWidth());
     79        top_ = (int) (topRel_ * GraphicsEngine::getSingleton().getWindowHeight());
     80        width_ = (int) (dimRel_ * GraphicsEngine::getSingleton().getWindowWidth());
     81        height_ = (int) (0.1 * width_); // the texture has dimensions height:length = 1:10
     82        offset_ = (int) (width_ * widthratio_ * 0.5);
     83        barwidth_ = (int) (width_ * (1.0f - widthratio_));
     84
    8085        // adapt background
    8186        background_->setPosition(left_, top_);
     
    8691
    8792    void BarOverlayElement::setValue(float value){
    88         value_ = value;
    89         // set color, if nescessary
    90         if(autoColor_){
    91             if (value_>0.5) {setColor(BarOverlayElement::GREEN);}
    92             else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);}
    93             else setColor(BarOverlayElement::RED);
     93        value_ = clamp<float>(value, 0, 1);
     94        // set colour, if nescessary
     95        if(autoColour_){
     96            if (value_>0.5) {setColour(BarOverlayElement::GREEN);}
     97            else if (value_>0.25) {setColour(BarOverlayElement::YELLOW);}
     98            else setColour(BarOverlayElement::RED);
    9499        }
     100
    95101        // set value
    96         if(left2Right){ // backward case
    97             setPosition(0+width_-width_*value_, 0);
    98             setDimensions(width_*value_,height_);
     102        if(right2Left_){ // backward case
     103            setPosition(offset_ + barwidth_ * (1 - value_), 0);
     104            setDimensions(barwidth_ * value_, height_);
    99105        }else{          // default case
    100             setPosition(0, 0);
    101             setDimensions(width_*value_,height_);
     106            setPosition(offset_, 0);
     107            setDimensions(barwidth_ * value_, height_);
    102108        }
    103109        if(value_ != 0) setTiling(value_, 1.0);
    104110    }
    105111
    106     void BarOverlayElement::setColor(int color){
    107         color_ = color;
    108         switch(color){
     112    void BarOverlayElement::setColour(int colour){
     113        colour_ = colour;
     114        switch(colour){
    109115        case 0:
    110116            setMaterialName("Orxonox/Red");
     
    117123        }
    118124    }
    119 
    120     float BarOverlayElement::getValue(){
    121         return(value_);
    122     }
    123 
    124     int BarOverlayElement::getBarColor(){
    125         return(color_);
    126     }
    127125}
Note: See TracChangeset for help on using the changeset viewer.