Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1595 for code/branches


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
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud/bin/hud/hud.oxh

    r1590 r1595  
    11<HUD name="OrxonoxHUD">
    2   <HUDSpeedBar name ="SpeedBar1" scale=0.35,0.2 scroll=-0.6,-1.0 value=0 />
    3   <HUDFPSText name="FPSText" scale = 0.043,0.043 scroll=-0.93,0.9 font="Monofur" caption="Frames per second: " />
    4   <HUDRTRText name="RTRText" scale = 0.043,0.043 scroll=-0.93,0.8 font="Monofur" caption="Render time ratio: " />
    5   <Navigation name="Navigation" font="Monofur" navmarkersize=0.03,0.03 />
     2  <HUDSpeedBar name ="SpeedBar1" size=0.35,0.2 scroll=-0.6,-1.0 value=0 />
     3  <HUDFPSText name="FPSText" size = 0.043,0.043 scroll=-0.93,0.9 font="Monofur" caption="Frames per second: " />
     4  <HUDRTRText name="RTRText" size = 0.043,0.043 scroll=-0.93,0.8 font="Monofur" caption="Render time ratio: " />
     5  <Navigation name="Navigation" correctAspect=true font="Monofur" navmarkersize=0.03,0.03 />
    66</HUD>
  • code/branches/hud/src/core/Executor.cc

    r1505 r1595  
    3030#include "Executor.h"
    3131#include "util/Math.h"
     32#include "util/Convert.h"
    3233#include "Language.h"
    3334
     
    136137            {
    137138                std::string paramnumber;
    138                 if (!Convert::ToString(&paramnumber, param))
     139                if (!convertValue(&paramnumber, param))
    139140                    return (*this);
    140141
  • code/branches/hud/src/core/TclThreadManager.h

    r1535 r1595  
    4545namespace orxonox
    4646{
    47     class boost::thread;
    48 
    4947    struct _CoreExport TclInterpreterBundle
    5048    {
  • 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
  • code/branches/hud/src/util/Convert.h

    r1588 r1595  
    4343#include "SubString.h"
    4444#include "MultiTypeMath.h"
     45#include "String.h"
    4546
    4647// disable annoying warning about forcing value to boolean
     
    320321    }
    321322};
     323
     324// convert from string Shortcut
     325template <class ToType>
     326ToType convertFromString(std::string str)
     327{
     328  return getConvertedValue<std::string, ToType>(str);
     329}
    322330
    323331
     
    411419////////////////////
    412420
     421// bool to std::string
     422template <>
     423struct ConverterSpecialized<bool, std::string, _Explicit_>
     424{
     425    enum { specialized = true };
     426    static bool convert(std::string* output, const bool& input)
     427    {
     428        if (input)
     429          *output = "true";
     430        else
     431          *output = "false";
     432        return false;
     433    }
     434};
     435
    413436// Vector2 to std::string
    414437template <>
     
    501524////////////////////
    502525
     526// std::string to bool
     527template <>
     528struct ConverterSpecialized<std::string, bool, _Explicit_>
     529{
     530    enum { specialized = true };
     531    static bool convert(bool* output, const std::string& input)
     532    {
     533        std::string stripped = getLowercase(removeTrailingWhitespaces(input));
     534        if (stripped == "true" || stripped == "on" || stripped == "yes")
     535        {
     536          *output = true;
     537          return true;
     538        }
     539        else if (stripped == "false" || stripped == "off" || stripped == "no")
     540        {
     541          *output = false;
     542          return true;
     543        }
     544
     545        std::istringstream iss(input);
     546        if (iss >> (*output))
     547            return true;
     548        else
     549            return false;
     550    }
     551};
     552
    503553// std::string to Vector2
    504554template <>
  • code/branches/hud/src/util/String.h

    r1505 r1595  
    7070_UtilExport unsigned int getNextCommentPosition(const std::string& str, unsigned int start = 0);
    7171
    72 //! The Convert class has some static member functions to convert strings to values and values to strings.
    73 class _UtilExport Convert
    74 {
    75     public:
    76         /**
    77             @brief Converts a value of any type to a string.
    78             @param output The string to write the result in
    79             @param input The variable to convert
    80             @return True if the conversion succeded
    81 
    82             @example
    83             float f = 3.14;
    84             std::string output;
    85             bool success = Convert::ToString(&output, f);
    86         */
    87         template <typename T>
    88         static bool ToString(std::string* output, T input)
    89         {
    90             std::ostringstream oss;
    91             if (oss << input)
    92             {
    93                 (*output) = oss.str();
    94                 return true;
    95             }
    96 
    97             return false;
    98         }
    99 
    100         /**
    101             @brief Converts a value of any type to a string and assigns a defaultvalue if the conversion fails.
    102             @param output The string to write the result in
    103             @param input The variable to convert
    104             @param fallbackString The assigned string if the conversion fails.
    105             @return True if the conversion succeeded
    106 
    107             @example
    108             float f = 3.14;
    109             std::string output;
    110             bool success = Convert::ToString(&output, f, "0.000000");
    111         */
    112         template <typename T>
    113         static bool ToString(std::string* output, T input, const std::string& fallbackString)
    114         {
    115             if (Convert::ToString(output, input))
    116                 return true;
    117 
    118             (*output) = fallbackString;
    119             return false;
    120         }
    121 
    122         /**
    123             @brief Converts a string to a value of any type.
    124             @param output The variable to assign the result to
    125             @param input The string to convert
    126             @return True if the conversion succeeded
    127 
    128             @example
    129             std::string input = "3.14";
    130             float f;
    131             bool success = string2Number(&f, input);
    132         */
    133         template <typename T>
    134         static bool FromString(T* output, const std::string& input)
    135         {
    136             std::istringstream iss(input);
    137             if (iss >> (*output))
    138                 return true;
    139 
    140             return false;
    141         }
    142 
    143         /**
    144             @brief Converts a string to a value of any type.
    145             @param output The variable to assign the result to
    146             @param input The string to convert
    147             @param fallbackValue The assigned value if the conversion fails
    148             @return True if the conversion succeeded
    149 
    150             @example
    151             std::string input = "3.14";
    152             float f;
    153             bool success = string2Number(&f, input, 0.000000);
    154         */
    155         template <typename T>
    156         static bool FromString(T* output, const std::string& input, T fallbackValue)
    157         {
    158             if (Convert::FromString(output, input))
    159                 return true;
    160 
    161             (*output) = fallbackValue;
    162             return false;
    163         }
    164 };
    165 
    16672#endif /* _Util_String_H__ */
Note: See TracChangeset for help on using the changeset viewer.