From: <sv...@ww...> - 2004-12-22 01:34:27
|
Author: delta Date: 2004-12-21 17:34:20 -0800 (Tue, 21 Dec 2004) New Revision: 1416 Modified: trunk/CSP/CSPSim/Include/ScreenInfo.h trunk/CSP/CSPSim/Source/ScreenInfo.cpp trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp Log: * Minor change in ScreenInfo: MessageBox has been renamed MessageList. * Small change in the implementation of ScreenInfo. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1416 Modified: trunk/CSP/CSPSim/Include/ScreenInfo.h =================================================================== --- trunk/CSP/CSPSim/Include/ScreenInfo.h 2004-12-19 15:00:01 UTC (rev 1415) +++ trunk/CSP/CSPSim/Include/ScreenInfo.h 2004-12-22 01:34:20 UTC (rev 1416) @@ -26,30 +26,33 @@ #ifndef __SCREENINFO_H__ #define __SCREENINFO_H__ -#include <osg/Geode> - namespace osgText { class Text; } +#include <osg/Geode> +#include <osg/Switch> + #include <SimData/Ref.h> class DynamicObject; - -class ScreenInfo: public osg::Geode + +class ScreenInfo: public osg::Switch +//class ScreenInfo: public osg::Geode { protected: std::string m_TTFPath; int m_FontSize; float m_CharacterSize; - osgText::Text *m_Text; + osg::ref_ptr<osg::Geode> m_InfoGeode; + osg::ref_ptr<osgText::Text> m_Text; osgText::Text *makeText(float pos_x, float pos_y,std::string const &string_text = ""); virtual ~ScreenInfo() {} public: ScreenInfo(float pos_x, float pos_y, std::string const &name, std::string const &text = ""); virtual void update(){} - void setStatus(bool const visible) {if (visible) setNodeMask(0x1); else setNodeMask(0x0);} - bool getStatus() const {return getNodeMask() != 0x0;} + void setStatus(bool const visible) {if (visible) setAllChildrenOn(); else setAllChildrenOff();} + bool getStatus() const {return getValue(0);} }; @@ -93,7 +96,7 @@ }; -class MessageBox: public ScreenInfo +class MessageList: public ScreenInfo { std::vector<osg::ref_ptr<osgText::Text> > m_Messages; int m_Lines; @@ -101,9 +104,9 @@ float m_Alpha; double m_LastUpdate; protected: - ~MessageBox(){} + ~MessageList(){} public: - MessageBox(int posx, int posy, int lines, float delay); + MessageList(int posx, int posy, int lines, float delay); void addLine(std::string const &line); virtual void update(); }; Modified: trunk/CSP/CSPSim/Source/ScreenInfo.cpp =================================================================== --- trunk/CSP/CSPSim/Source/ScreenInfo.cpp 2004-12-19 15:00:01 UTC (rev 1415) +++ trunk/CSP/CSPSim/Source/ScreenInfo.cpp 2004-12-22 01:34:20 UTC (rev 1416) @@ -32,8 +32,8 @@ #include <iomanip> #include <sstream> -#include <osg/Texture2D> -#include <osg/StateSet> +#include <osg/Texture2D> +#include <osg/StateSet> #include <osgText/Text> #include <SimData/Timing.h> @@ -79,8 +79,9 @@ m_FontSize(20), //m_CharacterSize(14), m_CharacterSize(11), - m_Text(makeText(pos_x,pos_y - m_CharacterSize, text)) { - addDrawable(m_Text); + m_Text(makeText(pos_x,pos_y - m_CharacterSize, text)), + m_InfoGeode(new osg::Geode) { + m_InfoGeode->addDrawable(m_Text.get()); setName(name); // HACK to prevent text from disappearing when chunklod multitexture details // are turned on: @@ -88,6 +89,7 @@ ss->setTextureMode(1,GL_TEXTURE_2D,osg::StateAttribute::OFF); //ss->setTextureMode(2,GL_TEXTURE_2D,osg::StateAttribute::OFF); //ss->setTextureMode(3,GL_TEXTURE_2D,osg::StateAttribute::OFF); + addChild(m_InfoGeode.get()); } osgText::Text *ScreenInfo::makeText(float pos_x, float pos_y, std::string const &string_text) { @@ -114,7 +116,7 @@ m_Date(makeText(pos_x, pos_y - 2*m_CharacterSize)) { m_Text->setUseDisplayList(false); m_Date->setUseDisplayList(false); - addDrawable(m_Date); + m_InfoGeode->addDrawable(m_Date); setUpdateCallback(new UpdateCallback); } @@ -156,11 +158,11 @@ m_Text->setUseDisplayList(false); m_Altitude->setUseDisplayList(false); - addDrawable(m_Altitude); + m_InfoGeode->addDrawable(m_Altitude); m_GlobalPosition->setUseDisplayList(false); - addDrawable(m_GlobalPosition); + m_InfoGeode->addDrawable(m_GlobalPosition); m_Velocity->setUseDisplayList(false); - addDrawable(m_Velocity); + m_InfoGeode->addDrawable(m_Velocity); setUpdateCallback(new UpdateCallback); } @@ -199,8 +201,8 @@ : ScreenInfo(posx,posy,"OBJECT STATS"), m_PosX(posx), m_PosY(posy) { m_Skip = static_cast<int>(m_CharacterSize); - if (m_Text) { - removeDrawable(m_Text); + if (m_Text.valid()) { + m_InfoGeode->removeDrawable(m_Text.get()); } if (!getUpdateCallback()) { setUpdateCallback(new UpdateCallback); @@ -216,7 +218,7 @@ short m = stringStats.size(); if (m < n) { for (int i = m; i < n; ++i) { - removeDrawable(m_ObjectStats[i].get()); + m_InfoGeode->removeDrawable(m_ObjectStats[i].get()); } m_ObjectStats.resize(m); } else @@ -224,7 +226,7 @@ m_ObjectStats.resize(m); for (int i = n; i < m; ++i) { m_ObjectStats[i] = makeText(m_PosX, m_PosY+i*m_Skip); - addDrawable(m_ObjectStats[i].get()); + m_InfoGeode->addDrawable(m_ObjectStats[i].get()); } } while (--m >= 0) { @@ -233,24 +235,24 @@ } } -MessageBox::MessageBox(int posx, int posy, int lines, float delay) +MessageList::MessageList(int posx, int posy, int lines, float delay) : ScreenInfo(posx, posy, "MESSAGE BOX"), m_Lines(lines), m_Delay(delay), m_Alpha(1.0), m_LastUpdate(0) { - if (m_Text) { - removeDrawable(m_Text); + if (m_Text.valid()) { + m_InfoGeode->removeDrawable(m_Text.get()); } int stepy = static_cast<int>(m_CharacterSize); for (int i = 0; i < lines; ++i) { osg::ref_ptr<osgText::Text> line = makeText(posx, posy - i * stepy); m_Messages.push_back(line); - addDrawable(line.get()); + m_InfoGeode->addDrawable(line.get()); } if (!getUpdateCallback()) { setUpdateCallback(new UpdateCallback); } } -void MessageBox::addLine(std::string const &line) { +void MessageList::addLine(std::string const &line) { m_LastUpdate = simdata::get_realtime(); for (int i = m_Lines-1; i > 0; --i) { m_Messages[i]->setText(m_Messages[i-1]->getText()); @@ -260,7 +262,7 @@ } } -void MessageBox::update() { +void MessageList::update() { double now = simdata::get_realtime(); float dt = static_cast<float>(now - m_LastUpdate); float old_alpha = m_Alpha; Modified: trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp =================================================================== --- trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp 2004-12-19 15:00:01 UTC (rev 1415) +++ trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp 2004-12-22 01:34:20 UTC (rev 1416) @@ -36,7 +36,7 @@ osg::ref_ptr<ScreenInfo> pause = new ScreenInfo(ScreenWidth-5*offsetpos,ScreenHeight-offsetpos,"PAUSE", "PAUSE"); osg::ref_ptr<ScreenInfo> record = new ScreenInfo(ScreenWidth-15*offsetpos,ScreenHeight-offsetpos,"RECORD", "RECORD"); osg::ref_ptr<GeneralStats> generalStats = new GeneralStats(offsetpos, ScreenHeight / 5); - osg::ref_ptr<MessageBox> messageBox = new MessageBox(offsetpos, ScreenHeight / 2, 4, 4.0); + osg::ref_ptr<MessageList> messageBox = new MessageList(offsetpos, ScreenHeight / 2, 4, 4.0); rootNode->addChild(framerate.get()); rootNode->addChild(pause.get()); @@ -137,7 +137,7 @@ void ScreenInfoManager::addMessage(std::string const &line) { - MessageBox *mbox = dynamic_cast<MessageBox*>(getScreenInfo("MESSAGE BOX")); + MessageList *mbox = dynamic_cast<MessageList*>(getScreenInfo("MESSAGE BOX")); if (mbox) { mbox->addLine(line); } |