Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 12, 2008, 10:42:15 PM (16 years ago)
Author:
rgrieder
Message:
  • removed conversion functions in String.h
  • you can use convertToString and convertFromString from Convert.h as shortcuts
  • added "true", "false", "on", "off", "yes" and "no" as boolean values to the Converter
  • Conversion bool —> string newly gives "true" or "false"
  • HUDOverlay can deal with the aspect ratio, e.g. circles stay circles when resizing
  • the rest isn't yet finished: svn save ;)
Location:
code/branches/hud/src/orxonox/hud
Files:
4 edited

Legend:

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

    r1590 r1595  
    4141  HUDOverlay::HUDOverlay()
    4242    : overlay_(0)
     43    , windowAspectRatio_(1.0f)
     44    , bCorrectAspect_(false)
     45    , size_(1.0f)
     46    , sizeCorrection_(1.0f)
    4347  {
    4448    RegisterObject(HUDOverlay);
     
    5458            + convertToString(hudOverlayCounter_s++) + "_" + this->getName());
    5559
    56       this->windowWidth_ = GraphicsEngine::getSingleton().getWindowWidth();
    57       this->windowHeight_ = GraphicsEngine::getSingleton().getWindowHeight();
    58       this->windowAspectRatio_ = windowWidth_/(float)windowHeight_;
     60      this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(),
     61            GraphicsEngine::getSingleton().getWindowHeight());
    5962    }
    6063
    61     XMLPortParam(HUDOverlay, "scale", setScale, getScale, xmlElement, mode);
     64    XMLPortParam(HUDOverlay, "size", setSize, getSize, xmlElement, mode);
     65    XMLPortParam(HUDOverlay, "correctAspect", setAspectCorrection, getAspectCorrection, xmlElement, mode);
    6266    XMLPortParam(HUDOverlay, "scroll", setScroll, getScroll, xmlElement, mode);
    6367    XMLPortParam(HUDOverlay, "rotation", setRotation, getRotation, xmlElement, mode);
     
    6872      if (!this->isVisible())
    6973          this->overlay_->hide();
     74
     75      this->sizeChanged();
    7076    }
    7177  }
     
    7783  void HUDOverlay::changedVisibility()
    7884  {
    79       if (this->overlay_)
    80       {
    81           if (this->isVisible())
    82               overlay_->show();
    83           else
    84               overlay_->hide();
    85       }
     85    if (this->overlay_)
     86    {
     87      if (this->isVisible())
     88        this->overlay_->show();
     89      else
     90        this->overlay_->hide();
     91    }
    8692  }
    8793
    8894  void HUDOverlay::windowResized(int newWidth, int newHeight)
    8995  {
    90     this->windowWidth_ = newWidth;
    91     this->windowHeight_ = newHeight;
    92     this->windowAspectRatio_ = windowWidth_/(float)windowHeight_;
     96    this->windowAspectRatio_ = newWidth/(float)newHeight;
     97
     98    this->setAspectCorrection(this->bCorrectAspect_);
     99  }
     100
     101  void HUDOverlay::setAspectCorrection(bool val)
     102  {
     103    if (val)
     104    {
     105      // note: this is only an approximation that is mostly valid when the
     106      // magnitude of the width is about the magnitude of the height.
     107      // Correctly we would have to take the square root of width*height
     108      this->sizeCorrection_.x = 2.0 / (this->windowAspectRatio_ + 1.0);
     109      this->sizeCorrection_.y = this->windowAspectRatio_ * this->sizeCorrection_.x;
     110    }
     111    else
     112    {
     113      this->sizeCorrection_ = Vector2::UNIT_SCALE;
     114    }
     115
     116    this->bCorrectAspect_ = val;
     117    this->sizeChanged();
     118  }
     119
     120  /**
     121    @remarks
     122      This function can be overriden by any derivative.
     123  */
     124  void HUDOverlay::sizeChanged()
     125  {
     126    this->overlay_->setScale(size_.x * sizeCorrection_.x, size_.x * sizeCorrection_.y);
    93127  }
    94128
  • code/branches/hud/src/orxonox/hud/HUDOverlay.h

    r1590 r1595  
    4747      virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
    4848
    49       virtual void changedVisibility();
     49      void setAspectCorrection(bool val);
     50      bool getAspectCorrection() { return this->bCorrectAspect_; }
    5051
    5152      /** Sets the scrolling factor of this overlay. */
     
    6869
    6970      /** Sets the scaling factor of this overlay. */
    70       void setScale(const Vector2& scale) { overlay_->setScale(scale.x, scale.y); }
     71      void setSize(const Vector2& size) { this->size_ = size; this->sizeChanged(); }
    7172
    72       /** Gets the current scale value */
    73       Vector2 getScale() const { return Vector2(overlay_->getScaleX(), overlay_->getScaleY()); }
     73      /** Gets the current size (not corrected) */
     74      Vector2 getSize() const { return this->size_; }
     75
     76      /** Gets the current size (corrected) */
     77      Vector2 getActualSize() const { return this->size_ * this->sizeCorrection_; }
     78
     79      /** Gets the current size correction */
     80      Vector2 getSizeCorrection() const { return this->sizeCorrection_; }
    7481
    7582      /** Scales the overlay */
    76       void scale(Vector2 scale) { overlay_->setScale(overlay_->getScaleX()*scale.x, overlay_->getScaleY()*scale.y); }
     83      void scale(Vector2 scale) { this->size_ *= scale; this->sizeChanged(); }
    7784
    7885    protected:
    79       virtual void windowResized(int newWidth, int newHeight);
     86      virtual void changedVisibility();
     87      virtual void sizeChanged();
     88      float getWindowAspectRatio() { return windowAspectRatio_; }
    8089
    8190      Ogre::Overlay* overlay_;
    82       float windowAspectRatio_;
    83       int windowWidth_;
    84       int windowHeight_;
    8591
    8692    private:
     93      void windowResized(int newWidth, int newHeight);
     94
     95      float windowAspectRatio_;
     96      bool bCorrectAspect_;
     97      Vector2 size_;
     98      Vector2 sizeCorrection_;
     99
    87100      static unsigned int hudOverlayCounter_s;
    88 
    89101  };
    90102}
  • code/branches/hud/src/orxonox/hud/Navigation.cc

    r1590 r1595  
    5454      , navMarker_(0)
    5555      , aimMarker_(0)
     56      , navText_(0)
    5657      , focus_(0)
    5758    {
     
    8182        {
    8283            // create container
    83             this->container_ = static_cast<OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navContainer"));
    84             this->container_->setMetricsMode(Ogre::GMM_RELATIVE);
    85             this->container_->setLeft(0.0);
    86             this->container_->setTop(0.0);
    87             this->container_->setWidth(1.0);
    88             this->container_->setHeight(1.0);
     84            container_ = static_cast<OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navContainer"));
     85            container_->setMetricsMode(Ogre::GMM_RELATIVE);
     86            container_->setLeft(0.0);
     87            container_->setTop(0.0);
     88            container_->setWidth(1.0);
     89            container_->setHeight(1.0);
    8990
    9091            // create nav text
    91             this->navText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_navText"));
    92             this->navText_->setMetricsMode(Ogre::GMM_RELATIVE);
    93             this->navText_->setPosition(0.0f, 0.0f);
    94             this->navText_->setCharHeight(0.05f);
    95             this->navText_->setFontName("Monofur");
     92            navText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_navText"));
     93            navText_->setMetricsMode(Ogre::GMM_RELATIVE);
     94            navText_->setPosition(0.0f, 0.0f);
     95            navText_->setCharHeight(0.05f);
     96            navText_->setFontName("Monofur");
    9697
    9798            // create nav marker
    9899            navMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navMarker"));
    99100            navMarker_->setMetricsMode(GMM_RELATIVE);
    100             navMarker_->setDimensions(0.05f, 0.05f);
    101101            navMarker_->setMaterialName("Orxonox/NavArrows");
     102            this->navMarkerSize_ = 0.05;
    102103            this->wasOutOfView_ = true; // just a to ensure the material is changed right the first time..
    103104
     
    105106            aimMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_aimMarker"));
    106107            aimMarker_->setMetricsMode(GMM_RELATIVE);
    107             aimMarker_->setDimensions(0.05f, 0.05f);
    108108            aimMarker_->setMaterialName("Orxonox/NavCrosshair");
     109            this->aimMarkerSize_ = 0.04;
    109110           
    110111            container_->addChild(navMarker_);
     
    121122        XMLPortParam(Navigation, "navmarkersize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode);
    122123        XMLPortParam(Navigation, "aimmarkersize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode);
    123     }
    124 
    125     void Navigation::setNavMarkerSize(Vector2 size)
    126     {
    127         if (this->navMarker_ && size.squaredLength() >= 0.0f)
    128             this->navMarker_->setDimensions(size.x, size.y);
    129     }
    130 
    131     Vector2 Navigation::getNavMarkerSize() const
    132     {
    133         if (this->navMarker_)
    134             return Vector2(navMarker_->getWidth(), navMarker_->getHeight());
    135         else
    136             return Vector2::ZERO;
    137     }
    138 
    139     void Navigation::setAimMarkerSize(Vector2 size)
    140     {
    141         if (this->aimMarker_ && size.squaredLength() >= 0.0f)
    142             this->aimMarker_->setDimensions(size.x, size.y);
    143     }
    144 
    145     Vector2 Navigation::getAimMarkerSize() const
    146     {
    147         if (this->aimMarker_)
    148             return Vector2(aimMarker_->getWidth(), aimMarker_->getHeight());
    149         else
    150             return Vector2::ZERO;
     124
     125        if (mode == XMLPort::LoadObject)
     126        {
     127            this->sizeChanged();
     128        }
     129    }
     130
     131    void Navigation::setNavMarkerSize(float size)
     132    {
     133        this->navMarkerSize_ = size;
     134    }
     135
     136    float Navigation::getNavMarkerSize() const
     137    {
     138        return this->navMarkerSize_;
     139    }
     140
     141    void Navigation::setAimMarkerSize(float size)
     142    {
     143        this->aimMarkerSize_ = size;
     144    }
     145
     146    float Navigation::getAimMarkerSize() const
     147    {
     148        return this->aimMarkerSize_;
    151149    }
    152150
     
    208206            pos.x = -pos.x;
    209207            pos.y = -pos.y;
    210             pos.z = -pos.z;
    211208        }
    212209        else
     
    366363    }
    367364
    368     void Navigation::windowResized(int newWidth, int newHeight)
    369     {
    370         HUDOverlay::windowResized(newWidth, newHeight);
    371 
    372         //if (this->navMarker_)
    373         //    navMarker_->setDimensions(0.05, 0.05);
    374 
     365    void Navigation::sizeChanged()
     366    {
     367        float xScale = this->getActualSize().x;
     368        float yScale = this->getActualSize().y;
     369        if (this->navMarker_)
     370            navMarker_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale);
     371        if (this->aimMarker_)
     372            aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale);
     373        if (this->navText_)
     374            navText_->setCharHeight(navText_->getCharHeight() * yScale);
    375375    }
    376376}
  • code/branches/hud/src/orxonox/hud/Navigation.h

    r1590 r1595  
    5858
    5959    protected:
    60       virtual void windowResized(int newWidth, int newHeight);
     60      virtual void sizeChanged();
    6161
    6262      private:
     
    6565        void updateFocus();
    6666
    67         void setNavMarkerSize(Vector2 size);
    68         Vector2 getNavMarkerSize() const;
    69         void setAimMarkerSize(Vector2 size);
    70         Vector2 getAimMarkerSize() const;
     67        void setNavMarkerSize(float size);
     68        float getNavMarkerSize() const;
     69        void setAimMarkerSize(float size);
     70        float getAimMarkerSize() const;
    7171        void setTextSize(float size);
    7272        float getTextSize() const;
     
    7575
    7676        Ogre::OverlayContainer* container_;         //!< Container that holds the navigation elements
    77         Ogre::PanelOverlayElement* navMarker_;      // the panel used to show the arrow
    78         Ogre::PanelOverlayElement* aimMarker_;
    79         Ogre::TextAreaOverlayElement* navText_;     // displaying distance
     77        Ogre::PanelOverlayElement* navMarker_;      //!< the panel used to show the arrow and the target marker
     78        float navMarkerSize_;                       //!< One paramter size of the navigation marker
     79        Ogre::PanelOverlayElement* aimMarker_;      //!< Panel used to show the aim Marker
     80        float aimMarkerSize_;                       //!< One paramter size of the aim marker
     81        Ogre::TextAreaOverlayElement* navText_;     //!< Text overlay to display the target distance
    8082        std::list<RadarObject*>::iterator it_;
    8183        RadarObject* focus_;                        // next pointer of linked list
Note: See TracChangeset for help on using the changeset viewer.