Revision: 2606
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2606&view=rev
Author:   ulteq
Date:     2012-05-20 02:14:23 +0000 (Sun, 20 May 2012)
Log Message:
-----------
-Codechange: style++

Modified Paths:
--------------
    trunk/source/main/gui/MapControl.cpp
    trunk/source/main/gui/MapControl.h
    trunk/source/main/gui/MapEntity.cpp
    trunk/source/main/gui/MapEntity.h

Modified: trunk/source/main/gui/MapControl.cpp
===================================================================
--- trunk/source/main/gui/MapControl.cpp        2012-05-20 01:40:52 UTC (rev 
2605)
+++ trunk/source/main/gui/MapControl.cpp        2012-05-20 02:14:23 UTC (rev 
2606)
@@ -23,88 +23,76 @@
 
 #include "BeamData.h"
 #include "MapEntity.h"
+#include "Ogre.h"
 
 using namespace Ogre;
 
 MapControl::MapControl(int mapsizex, int mapsizez) :
-         h(100.0f)
+         mMapWidth(mapsizex)
+       , mMapHeight(mapsizez)
        , mAlpha(1.0f)
-       , mapsizex(mapsizex)
-       , mapsizez(mapsizez)
-       , rWinHeight(1)
-       , rWinWidth(1)
-       , w(100.0f)
-       , x(0.0f)
-       , y(0.0f)
+       , mScale(1.0f)
 {
        initialiseByAttributes(this);
+       setVisibility(false);
 }
 
-MapControl::~MapControl()
+void MapControl::setMapTexture(String name)
 {
+       mMapTexture->setImageTexture(name);
 }
 
-void MapControl::setMapTexture(String _name)
-{
-       mMapTexture->setImageTexture(_name);
-}
-
 void MapControl::setWorldSize(int x, int z)
 {
-       this->mapsizex = x;
-       this->mapsizez = z;
+       mMapWidth = x;
+       mMapHeight = z;
 }
 
 MapEntity *MapControl::createMapEntity(String type)
 {
-       MapEntity *m = new MapEntity(this, type, mMapTexture);
-       mMapEntities.push_back(m);
-       return m;
+       MapEntity *entity = new MapEntity(this, type, mMapTexture);
+       mMapEntities.insert(entity);
+       return entity;
 }
 
 MapEntity *MapControl::createNamedMapEntity(String name, String type)
 {
-       MapEntity *e = createMapEntity(type);
-       mNamedEntities[name] = e;
-       return e;
+       MapEntity *entity = createMapEntity(type);
+       mNamedEntities[name] = entity;
+       return entity;
 }
 
 MapEntity *MapControl::getEntityByName(String name)
 {
        if (mNamedEntities.find(name) != mNamedEntities.end())
+       {
                return mNamedEntities[name];
-
-       return nullptr;
+       }
+       return NULL;
 }
 
 String MapControl::getTypeByDriveable(int driveable)
 {
-       if(driveable == NOT_DRIVEABLE)
+       switch (driveable)
+       {
+       case NOT_DRIVEABLE:
                return "load";
-       else if(driveable == TRUCK)
+       case TRUCK:
                return "truck";
-       else if(driveable == AIRPLANE)
+       case AIRPLANE:
                return "airplane";
-       else if(driveable == BOAT)
+       case BOAT:
                return "boat";
-       else if(driveable == MACHINE)
+       case MACHINE:
                return "machine";
-       return "unknown";
+       default:
+               return "unknown";
+       }
 }
 
-void MapControl::deleteMapEntity(MapEntity *ent)
+void MapControl::deleteMapEntity(MapEntity *entity)
 {
-       std::vector<MapEntity *>::iterator it;
-       for(it=mMapEntities.begin(); it!= mMapEntities.end(); it++)
-       {
-               if((*it) == ent)
-               {
-                       // found it, erase!
-                       delete *it;
-                       mMapEntities.erase(it);
-                       return;
-               }
-       }
+       mMapEntities.erase(entity);
 }
 
 bool MapControl::getVisibility()
@@ -114,7 +102,6 @@
 
 void MapControl::setVisibility(bool value)
 {
-       //if(!value) GUIManager::getSingleton().unfocus();
        mMainWidget->setVisible(value);
 }
 
@@ -124,18 +111,19 @@
        mMainWidget->setAlpha(value);
 }
 
-void MapControl::setPosition(float _x, float _y, float _w, float _h, 
RenderWindow* rw)
+void MapControl::setPosition(float x, float y, float w, float h, RenderWindow* 
rw)
 {
-       mMainWidget->setCoord(_x*rWinWidth, _y*rWinHeight, _w*rWinWidth, 
_h*rWinHeight);
-       myScale = _w;
+       updateRenderMetrics(rw);
+
+       mScale = w;
+       mMainWidget->setCoord(x * rWinWidth, y * rWinHeight, w * rWinWidth, h * 
rWinHeight);
+
        updateEntityPositions();
 }
 
-
 void MapControl::updateEntityPositions()
 {
-       std::vector<MapEntity *>::iterator it;
-       for(it=mMapEntities.begin(); it!=mMapEntities.end(); it++)
+       for (std::set<MapEntity *>::iterator it = mMapEntities.begin(); it != 
mMapEntities.end(); it++)
        {
                (*it)->update();
        }
@@ -143,19 +131,12 @@
 
 void MapControl::setEntitiesVisibility(bool value)
 {
-       std::vector<MapEntity *>::iterator it;
-       for(it=mMapEntities.begin(); it!=mMapEntities.end(); it++)
+       for (std::set<MapEntity *>::iterator it = mMapEntities.begin(); it != 
mMapEntities.end(); it++)
        {
                (*it)->setVisibility(value);
        }
 }
 
-void MapControl::resizeToScreenRatio(RenderWindow* rw)
-{
-       //win->setRealPosition(
-       // TODO
-}
-
 void MapControl::updateRenderMetrics(RenderWindow* win)
 {
        win->getMetrics(rWinWidth, rWinHeight, rWinDepth, rWinLeft, rWinTop);

Modified: trunk/source/main/gui/MapControl.h
===================================================================
--- trunk/source/main/gui/MapControl.h  2012-05-20 01:40:52 UTC (rev 2605)
+++ trunk/source/main/gui/MapControl.h  2012-05-20 02:14:23 UTC (rev 2606)
@@ -18,6 +18,7 @@
 along with Rigs of Rods.  If not, see <http://www.gnu.org/licenses/>.
 */
 #ifdef USE_MYGUI
+
 #ifndef __MAP_CONTROL_H_
 #define __MAP_CONTROL_H_
 
@@ -32,46 +33,44 @@
 public:
 
        MapControl(int mapsizex, int mapsizez);
-       ~MapControl();
 
-       void setMapTexture(Ogre::String _name);
-
-       MapEntity *createNamedMapEntity(Ogre::String name, Ogre::String type);
        MapEntity *createMapEntity(Ogre::String type);
+       MapEntity *createNamedMapEntity(Ogre::String name, Ogre::String type);
+
+       
        MapEntity *getEntityByName(Ogre::String name);
-       void deleteMapEntity(MapEntity *ent);
+       Ogre::Vector2 getMapSize(){ return Ogre::Vector2(mMapWidth, 
mMapHeight); }
        bool getVisibility();
-       void setVisibility(bool value);
-
-       void setPosition(float x, float y, float w, float h, 
Ogre::RenderWindow* rw=0);
-       void setPosition(float x, float y, float w, Ogre::RenderWindow* rw=0);
-       void resizeToScreenRatio(Ogre::RenderWindow* win);
-
-       void updateRenderMetrics(Ogre::RenderWindow* win);
-
-       static Ogre::String getTypeByDriveable(int driveable);
        float getAlpha() { return mAlpha; }
+       float getWindowScale() { return mScale; }
+
        void setAlpha(float value);
        void setEntitiesVisibility(bool value);
+       void setMapTexture(Ogre::String name);
+       void setPosition(float x, float y, float w, float h, 
Ogre::RenderWindow* rw);
+       void setVisibility(bool value);
        void setWorldSize(int x, int z);
-       Ogre::Vector2 getMapSize(){ return Ogre::Vector2(mapsizex, mapsizez); }
-       float getWindowScale() { return myScale; }
 
+       void deleteMapEntity(MapEntity *ent);
+
+       static Ogre::String getTypeByDriveable(int driveable);
+
 protected:
 
        ATTRIBUTE_FIELD_WIDGET_NAME(MapControl, mMapTexture, "mMapTexture");
        MyGUI::StaticImage* mMapTexture;
 
-       std::vector<MapEntity *> mMapEntities;
-       std::map<Ogre::String, MapEntity *> mNamedEntities;
-       int mapsizex, mapsizez;
-       float x,y,w,h, myScale;
-       float mAlpha;
-       unsigned int rWinWidth, rWinHeight, rWinDepth;
+       float mAlpha, mScale;
+       int mMapWidth, mMapHeight;
        int rWinLeft, rWinTop;
+       unsigned int rWinWidth, rWinHeight, rWinDepth;
+       std::map<Ogre::String, MapEntity *> mNamedEntities;
+       std::set<MapEntity *> mMapEntities;
 
        void updateEntityPositions();
+       void updateRenderMetrics(Ogre::RenderWindow* win);
 };
 
 #endif // __MAP_CONTROL_H_
+
 #endif // USE_MYGUI

Modified: trunk/source/main/gui/MapEntity.cpp
===================================================================
--- trunk/source/main/gui/MapEntity.cpp 2012-05-20 01:40:52 UTC (rev 2605)
+++ trunk/source/main/gui/MapEntity.cpp 2012-05-20 02:14:23 UTC (rev 2606)
@@ -22,45 +22,45 @@
 #include "Beam.h"
 #include "MapEntity.h"
 #include "MapControl.h"
+#include "Ogre.h"
 
-Ogre::String MapEntity::entityStates[MaxEntityStates] = {"activated", 
"deactivated", "sleeping", "networked"};
+using namespace Ogre;
 
-MapEntity::MapEntity(MapControl *ctrl, Ogre::String type, 
MyGUI::StaticImagePtr _parent)
+String MapEntity::entityStates[MaxEntityStates] = {"activated", "deactivated", 
"sleeping", "networked"};
+
+MapEntity::MapEntity(MapControl *ctrl, String type, MyGUI::StaticImagePtr 
parent) :
+         mMapControl(ctrl)
+       , mType(type)
+       , mParent(parent)
+       , mRotation(0)
+       , mState(Sleeping)
+       , mX(0)
+       , mZ(0)
 {
-       initialiseByAttributes(this, _parent);
+       initialiseByAttributes(this, parent);
 
-       if (mIcon) mIconRotating = 
mIcon->getSubWidgetMain()->castType<MyGUI::RotatingSkin>(false);
-       else mIconRotating = nullptr;
+       if (mIcon)
+               mIconRotating = 
mIcon->getSubWidgetMain()->castType<MyGUI::RotatingSkin>(false);
+       else
+               mIconRotating = nullptr;
 
-       mMapControl = ctrl;
-       mParent = _parent;
-       mType = type;
-       mX = 0;
-       mZ = 0;
-       mRotation = 0;
-       mState = Sleeping;
        init();
 }
 
-MapEntity::~MapEntity()
-{
-}
-
 void MapEntity::init()
 {
        // check if static only icon
-       Ogre::String imageFile = "icon_" + mType + ".dds";
-       Ogre::String group = 
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
+       String imageFile = "icon_" + mType + ".dds";
+       String group = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
 
-       if(Ogre::ResourceGroupManager::getSingleton().resourceExists(group, 
imageFile))
+       if (ResourceGroupManager::getSingleton().resourceExists(group, 
imageFile))
        {
                //LOG("static map icon found: " + imageFile);
-               mIsStatic=true;
-       }
-       else
+               mIsStatic = true;
+       } else
        {
                LOG("static map icon not found: " + imageFile);
-               mIsStatic=false;
+               mIsStatic = false;
        }
 
        setVisibility(false);
@@ -69,39 +69,41 @@
        update();
 }
 
-void MapEntity::setPosition(Ogre::Vector3 pos)
+void MapEntity::setPosition(Vector3 pos)
 {
        setPosition(pos.x, pos.z);
 }
 
-void MapEntity::setPosition(float _x, float _z)
+void MapEntity::setPosition(float x, float z)
 {
-       bool needUpdate=false;
-       if(fabs(_x - mX) > 0.00001f || fabs(_z - mZ) > 0.00001f)
-               needUpdate=true;
-       mX = _x;
-       mZ = _z;
-       if(needUpdate)
+       bool needUpdate = false;
+
+       if (fabs(x - mX) > 0.00001f || fabs(z - mZ) > 0.00001f)
+       {
+               needUpdate = true;
+       }
+
+       mX = x;
+       mZ = z;
+
+       if (needUpdate)
+       {
                update();
+       }
 }
 
-void MapEntity::setRotation(Ogre::Quaternion q)
+void MapEntity::setRotation(Quaternion q)
 {
-       mRotation = q.getYaw().valueRadians() - Ogre::Math::PI/2;
+       mRotation = q.getYaw().valueRadians() - Math::PI/2;
        if (mIconRotating) mIconRotating->setAngle(-mRotation);
 }
 
-void MapEntity::setRotation(Ogre::Radian _r)
+void MapEntity::setRotation(Radian _r)
 {
        mRotation = _r.valueRadians();
        if (mIconRotating) mIconRotating->setAngle(-mRotation);
 }
 
-void MapEntity::onTop()
-{
-//     container->_notifyZOrder(container->getZOrder()+10);
-}
-
 bool MapEntity::getVisibility()
 {
        return mMainWidget->getVisible();
@@ -114,19 +116,28 @@
 
 void MapEntity::setState(int truckstate)
 {
-       if (mIsStatic)
-               return;
+       if (mIsStatic) return;
 
-       EntityStates mapstate;
+       EntityStates mapstate = Sleeping;
+
        switch (truckstate)
        {
-       case ACTIVATED: mapstate = Activated; break;
+       case ACTIVATED:
+               mapstate = Activated;
+               break;
        case DESACTIVATED:
        case MAYSLEEP:
-       case GOSLEEP: mapstate = Deactivated; break;
-       case SLEEPING: mapstate = Sleeping; break;
-       case NETWORKED: mapstate = Networked; break;
-       default: mapstate = Sleeping;
+       case GOSLEEP:
+               mapstate = Deactivated;
+               break;
+       case SLEEPING:
+               mapstate = Sleeping;
+               break;
+       case NETWORKED:
+               mapstate = Networked;
+               break;
+       default:
+               mapstate = Sleeping;
        }
 
        if (mState != mapstate)
@@ -147,7 +158,7 @@
 
        mCaption->setVisible(wscale > 0.5f);
 
-       Ogre::Vector2 s = mMapControl->getMapSize();
+       Vector2 s = mMapControl->getMapSize();
        mMainWidget->setPosition(
                mX / s.x * mParent->getWidth() - mMainWidget->getWidth() / 2,
                mZ / s.y * mParent->getHeight() - mMainWidget->getHeight() / 2
@@ -161,13 +172,13 @@
        mIcon->setVisible(true);
 }
 
-void MapEntity::setDescription(Ogre::String s)
+void MapEntity::setDescription(String s)
 {
        mDescription = s;
        mCaption->setCaption(mDescription);
 }
 
-Ogre::String MapEntity::getDescription()
+String MapEntity::getDescription()
 {
        return mDescription;
 }
@@ -175,21 +186,24 @@
 void MapEntity::updateIcon()
 {
        // check if static only icon
-       Ogre::String imageFile;
-       if(mIsStatic)   imageFile = "icon_" + mType + ".dds";
-       else                    imageFile = "icon_" + mType + "_" + 
entityStates[mState] + ".dds";
+       String imageFile = "icon_" + mType + "_" + entityStates[mState] + 
".dds";
 
+       if (mIsStatic)
+       {
+               imageFile = "icon_" + mType + ".dds";
+       }
+
        // set image texture to load it into memory, so 
TextureManager::getByName will have it loaded if files exist
        mIcon->setImageTexture(imageFile);
 
-       Ogre::TexturePtr texture = 
(Ogre::TexturePtr)(Ogre::TextureManager::getSingleton().getByName(imageFile));
-       if(texture.isNull())
+       TexturePtr texture = 
(TexturePtr)(TextureManager::getSingleton().getByName(imageFile));
+       if (texture.isNull())
        {
                imageFile = "icon_missing.dds";
-               texture = 
(Ogre::TexturePtr)(Ogre::TextureManager::getSingleton().getByName(imageFile));
+               texture = 
(TexturePtr)(TextureManager::getSingleton().getByName(imageFile));
        }
 
-       if(!texture.isNull())
+       if (!texture.isNull())
        {
                mIconSize.width  = (int)texture->getWidth();
                mIconSize.height = (int)texture->getHeight();
@@ -203,4 +217,4 @@
        }
 }
 
-#endif // MYGUI
+#endif // USE_MYGUI

Modified: trunk/source/main/gui/MapEntity.h
===================================================================
--- trunk/source/main/gui/MapEntity.h   2012-05-20 01:40:52 UTC (rev 2605)
+++ trunk/source/main/gui/MapEntity.h   2012-05-20 02:14:23 UTC (rev 2606)
@@ -19,63 +19,63 @@
 */
 #ifdef USE_MYGUI
 
-#ifndef __MAP_ENTITY_H__
-#define __MAP_ENTITY_H__
+#ifndef __MAP_ENTITY_H_
+#define __MAP_ENTITY_H_
 
 #include "RoRPrerequisites.h"
-#include <Ogre.h>
+
 #include "mygui/BaseLayout.h"
 
 ATTRIBUTE_CLASS_LAYOUT(MapEntity, "MapEntity.layout");
-class MapEntity :
-       public wraps::BaseLayout
+
+class MapEntity : public wraps::BaseLayout
 {
 public:
+
        MapEntity(MapControl *ctrl, Ogre::String type, MyGUI::StaticImagePtr 
parent);
-       ~MapEntity();
+
+       Ogre::String getDescription();
+       bool getVisibility();
+       int getState();
+
+       void setDescription(Ogre::String s);
        void setPosition(Ogre::Vector3 pos);
        void setPosition(float x, float z);
        void setRotation(Ogre::Quaternion q);
        void setRotation(Ogre::Radian r);
-       bool getVisibility();
+       void setState(int state);
        void setVisibility(bool value);
-       void onTop();
 
-       void setState(int state);
-       int getState();
-
-       enum EntityStates {Activated = 0, Deactivated, Sleeping, Networked, 
MaxEntityStates};
-       static Ogre::String entityStates[MaxEntityStates];
        void update();
-       void setDescription(Ogre::String s);
-       Ogre::String getDescription();
 
-protected:
-       void updateIcon();
 private:
+
        MyGUI::StaticImagePtr mParent;
 
        ATTRIBUTE_FIELD_WIDGET_NAME(MapEntity, mCaption, "mCaption");
-       MyGUI::StaticText* mCaption;
+       MyGUI::StaticText *mCaption;
 
        ATTRIBUTE_FIELD_WIDGET_NAME(MapEntity, mIcon, "mIcon");
-       MyGUI::StaticImage* mIcon;
+       MyGUI::StaticImage *mIcon;
+       MyGUI::RotatingSkin *mIconRotating;
 
-       MyGUI::RotatingSkin* mIconRotating;
-
-       Ogre::String mType;
-       Ogre::String mDescription;
-       Ogre::Real mX, mZ;
+       enum EntityStates {Activated, Deactivated, Sleeping, Networked, 
MaxEntityStates};
+       
+       EntityStates mState;
+       MapControl *mMapControl;
        MyGUI::IntSize mIconSize;
        Ogre::Real mRotation;
-       MapControl *mMapControl;
-       EntityStates mState;
+       Ogre::Real mX, mZ;
+       Ogre::String mDescription;
+       Ogre::String mType;
        bool mIsStatic;
+
        void init();
+       void updateIcon();
+
+       static Ogre::String entityStates[MaxEntityStates];
 };
 
-#endif // __MAP_ENTITY_H__
+#endif // __MAP_ENTITY_H_
 
-
-#endif //MYGUI
-
+#endif // USE_MYGUI

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to