From: <sv...@ww...> - 2004-12-18 10:19:43
|
Author: mkrose Date: 2004-12-18 02:19:27 -0800 (Sat, 18 Dec 2004) New Revision: 1398 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Include/ScreenInfo.h trunk/CSP/CSPSim/Include/ScreenInfoManager.h trunk/CSP/CSPSim/Source/ScreenInfo.cpp trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp Log: Add a message box to the onscreen display that displays/scrolls several lines of text, and fades out when unchanged for several seconds. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1398 Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-12-18 10:14:34 UTC (rev 1397) +++ trunk/CSP/CSPSim/CHANGES.current 2004-12-18 10:19:27 UTC (rev 1398) @@ -1,22 +1,26 @@ Version 0.4.0 (in progress) =========================== +2004-12-17: onsight + * Add a message box to the onscreen display that displays/scrolls several + lines of text, and fades out when unchanged for several seconds. + 2004-12-17: delta * Updated FlightModel and m2k xml related files. - + ==> ALL USERS: run RebuildData.py. - + 2004-12-17: Lologramme * Add hangar - + 2004-12-16: Lologramme * add control tower - + 2004-12-15: delta * Lologramme checked in the runway for a new airbase. - + * Added a new version of balkanMapElev.7-7.bmp to be used with this new airbase (Data/Images). - + * Moved the aircraft to be on the runway at start up. 2004-12-15: onsight @@ -33,20 +37,20 @@ * Rename the runway model file to all lowercase (wasn't found under linux). ==> Run ComplileData.py after updating to pick up the changes. - + 2004-12-14: onsight * Minor fix for the engine cutoff function under linux. - + 2004-12-13: Lologramme * Replace Runway by New runway with taxi and roads - + 2004-12-14: delta * Minor anti-warnings changes in SimCore/Battlefield/LocalBattlefield.cpp. - + * Slighty flatten the joystick inputs. * Other minor changes. - + 2004-12-13: delta * Updated Data/XML/vehicles/aircraft/m2k/thrust.xml with more accurate m2k data. Modified: trunk/CSP/CSPSim/Include/ScreenInfo.h =================================================================== --- trunk/CSP/CSPSim/Include/ScreenInfo.h 2004-12-18 10:14:34 UTC (rev 1397) +++ trunk/CSP/CSPSim/Include/ScreenInfo.h 2004-12-18 10:19:27 UTC (rev 1398) @@ -1,17 +1,17 @@ // Combat Simulator Project - FlightSim Demo // Copyright (C) 2002 The Combat Simulator Project // http://csp.sourceforge.net -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -36,7 +36,7 @@ class DynamicObject; -class ScreenInfo: public osg::Geode +class ScreenInfo: public osg::Geode { protected: std::string m_TTFPath; @@ -53,7 +53,7 @@ }; -class Framerate: public ScreenInfo +class Framerate: public ScreenInfo { float m_MinFps, m_MaxFps, m_Cumul; osgText::Text* m_Date; @@ -65,7 +65,7 @@ }; -class GeneralStats: public ScreenInfo +class GeneralStats: public ScreenInfo { osgText::Text* m_Altitude; osgText::Text* m_GlobalPosition; @@ -78,7 +78,7 @@ }; -class ObjectStats: public ScreenInfo +class ObjectStats: public ScreenInfo { // input device informations std::vector<osg::ref_ptr<osgText::Text> > m_ObjectStats; @@ -93,6 +93,20 @@ }; +class MessageBox: public ScreenInfo +{ + std::vector<osg::ref_ptr<osgText::Text> > m_Messages; + int m_Lines; + float m_Delay; + float m_Alpha; + double m_LastUpdate; +protected: + ~MessageBox(){} +public: + MessageBox(int posx, int posy, int lines, float delay); + void addLine(std::string const &line); + virtual void update(); +}; #endif // __SCREENINFO_H__ Modified: trunk/CSP/CSPSim/Include/ScreenInfoManager.h =================================================================== --- trunk/CSP/CSPSim/Include/ScreenInfoManager.h 2004-12-18 10:14:34 UTC (rev 1397) +++ trunk/CSP/CSPSim/Include/ScreenInfoManager.h 2004-12-18 10:19:27 UTC (rev 1398) @@ -37,6 +37,7 @@ void setStatus(std::string const & name, bool bvisible); bool getStatus(std::string const & name); void changeObjectStats(int ScreenWidth, int ScreenHeight,simdata::Ref<DynamicObject> const& activeObject); + void addMessage(std::string const &line); private: osg::MatrixTransform* m_modelview_abs; ScreenInfo* getScreenInfo(std::string const & name); Modified: trunk/CSP/CSPSim/Source/ScreenInfo.cpp =================================================================== --- trunk/CSP/CSPSim/Source/ScreenInfo.cpp 2004-12-18 10:14:34 UTC (rev 1397) +++ trunk/CSP/CSPSim/Source/ScreenInfo.cpp 2004-12-18 10:19:27 UTC (rev 1398) @@ -33,8 +33,11 @@ #include <sstream> #include <osg/Texture2D> +#include <osg/StateSet> #include <osgText/Text> +#include <SimData/Timing.h> + using std::max; using std::min; using std::setprecision; @@ -226,3 +229,48 @@ } } +MessageBox::MessageBox(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); + } + 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()); + } + if (!getUpdateCallback()) { + setUpdateCallback(new UpdateCallback); + } +} + +void MessageBox::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()); + } + if (m_Lines > 0) { + m_Messages[0]->setText(line); + } +} + +void MessageBox::update() { + double now = simdata::get_realtime(); + float dt = static_cast<float>(now - m_LastUpdate); + float old_alpha = m_Alpha; + if (dt > m_Delay) { + m_Alpha = std::max<float>(0, 1.0 - (dt - m_Delay)); + } else { + m_Alpha = 1.0; + } + if (m_Alpha != old_alpha) { + for (int i = 0; i < m_Lines; ++i) { + m_Messages[i]->setColor(osg::Vec4(1, 1, 1, m_Alpha)); + if (m_Alpha == 0.0) { + m_Messages[i]->setText(""); + } + } + } +} Modified: trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp =================================================================== --- trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp 2004-12-18 10:14:34 UTC (rev 1397) +++ trunk/CSP/CSPSim/Source/ScreenInfoManager.cpp 2004-12-18 10:19:27 UTC (rev 1398) @@ -36,11 +36,13 @@ 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); rootNode->addChild(framerate.get()); rootNode->addChild(pause.get()); rootNode->addChild(record.get()); rootNode->addChild(generalStats.get()); + rootNode->addChild(messageBox.get()); osg::StateSet *rootState = rootNode->getOrCreateStateSet(); rootState->setMode(GL_LIGHTING,osg::StateAttribute::OFF); @@ -129,3 +131,10 @@ } } +void ScreenInfoManager::addMessage(std::string const &line) +{ + MessageBox *mbox = dynamic_cast<MessageBox*>(getScreenInfo("MESSAGE BOX")); + if (mbox) { + mbox->addLine(line); + } +} |