Changeset 1615 for code/branches/hud/src/orxonox/overlays/OverlayGroup.cc
- Timestamp:
- Jun 22, 2008, 12:06:55 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/orxonox/overlays/OverlayGroup.cc
r1614 r1615 30 30 #include "OverlayGroup.h" 31 31 32 #include <assert.h>33 32 #include "core/Debug.h" 34 33 #include "core/ConsoleCommand.h" … … 38 37 namespace orxonox 39 38 { 40 CreateFactory(OverlayGroup);39 CreateFactory(OverlayGroup); 41 40 42 SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User); 43 SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User); 41 SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User); 42 SetConsoleCommand(OverlayGroup, scaleGroup, false).setAccessLevel(AccessLevel::User); 43 SetConsoleCommand(OverlayGroup, scrollGroup, false).setAccessLevel(AccessLevel::User); 44 44 45 using namespace Ogre; 45 OverlayGroup::OverlayGroup() 46 : scale_(1.0, 1.0) 47 { 48 RegisterObject(OverlayGroup); 49 } 46 50 47 OverlayGroup::OverlayGroup() 48 : scale_(1.0, 1.0) 49 { 50 RegisterObject(OverlayGroup); 51 } 51 OverlayGroup::~OverlayGroup() 52 { 53 } 52 54 53 OverlayGroup::~OverlayGroup()54 {55 }55 void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode) 56 { 57 BaseObject::XMLPort(xmlElement, mode); 56 58 57 void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode) 58 { 59 BaseObject::XMLPort(xmlElement, mode); 59 XMLPortParam(OverlayGroup, "scale", setScale, getScale, xmlElement, mode); 60 XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlElement, mode); 61 XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true); 62 } 60 63 61 XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode); 62 XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true); 63 } 64 void OverlayGroup::setScale(const Vector2& scale) 65 { 66 for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) 67 (*it).second->scale(scale / this->scale_); 68 this->scale_ = scale; 69 } 64 70 65 void OverlayGroup::scale(const Vector2& scale)66 {67 for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)68 (*it).second->scale(scale);69 this->scale_ = scale;70 }71 void OverlayGroup::setScroll(const Vector2& scroll) 72 { 73 for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) 74 (*it).second->scroll(scroll - this->scroll_); 75 this->scroll_ = scroll; 76 } 71 77 72 void OverlayGroup::addElement(OrxonoxOverlay* element) 73 { 74 if (hudElements_.find(element->getName()) != hudElements_.end()) 78 void OverlayGroup::addElement(OrxonoxOverlay* element) 75 79 { 76 COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl; 80 if (hudElements_.find(element->getName()) != hudElements_.end()) 81 { 82 COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl; 83 } 84 else 85 hudElements_[element->getName()] = element; 77 86 } 78 else79 hudElements_[element->getName()] = element;80 }81 87 82 OrxonoxOverlay* OverlayGroup::getElement(unsigned int index) 83 { 84 if (index < this->hudElements_.size()) 88 OrxonoxOverlay* OverlayGroup::getElement(unsigned int index) 85 89 { 86 std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin(); 87 for (unsigned int i = 0; i != index; ++it, ++i) 88 ; 89 return (*it).second; 90 if (index < this->hudElements_.size()) 91 { 92 std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin(); 93 for (unsigned int i = 0; i != index; ++it, ++i) 94 ; 95 return (*it).second; 96 } 97 else 98 return 0; 90 99 } 91 else92 return 0;93 }94 100 95 101 96 /*static*/ void OverlayGroup::toggleVisibility(const std::string& name) 97 { 98 for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) 102 /*static*/ void OverlayGroup::toggleVisibility(const std::string& name) 99 103 { 100 if ((*it)->getName() == name) 101 (*it)->setVisibility(!((*it)->isVisible())); 104 for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) 105 { 106 if ((*it)->getName() == name) 107 (*it)->setVisibility(!((*it)->isVisible())); 108 } 102 109 } 103 }104 110 105 /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale) 106 { 107 for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) 111 /*static*/ void OverlayGroup::scaleGroup(const std::string& name, float scale) 108 112 { 109 if ((*it)->getName() == name) 110 (*it)->scale(Vector2(scale, scale)); 113 for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) 114 { 115 if ((*it)->getName() == name) 116 (*it)->scale(Vector2(scale, scale)); 117 } 111 118 } 112 } 119 120 /*static*/ void OverlayGroup::scrollGroup(const std::string& name, const Vector2& scroll) 121 { 122 for (Iterator<OverlayGroup> it = ObjectList<OverlayGroup>::begin(); it; ++it) 123 { 124 if ((*it)->getName() == name) 125 (*it)->scroll(scroll); 126 } 127 } 113 128 }
Note: See TracChangeset
for help on using the changeset viewer.