1 #include "MyInterpreter.hpp"
2 #include "mof/ImageTileWidgetView.hpp"
3 #include "mof/utilities.hpp"
4 #include "mof/LayoutManager.hpp"
5 #include "mof/Deleter.hpp"
6 #include "mof/mofInput.hpp"
7 #include "mof/mofGraphics.hpp"
8 #include <boost/bind.hpp>
9 #include "mof/EventScheduler.hpp"
11 #include "mof/ConsoleIO.hpp"
13 struct MyInterpreter::Impl
15 std::list<boost::weak_ptr<mof::MessageWidget> > inactiveResources;
16 mof::EventScheduler scheduler;
17 std::list<boost::shared_ptr<mof::MessageWidget> > messages;
30 MyInterpreter::MyInterpreter( )
31 : m_pImpl(new Impl() )
36 MyInterpreter::~MyInterpreter()
40 boost::shared_ptr<mof::MessageWidget>
41 MyInterpreter::createMessageWidget(const mof::tstring &title, const mof::tstring &text)
43 mof::LayoutManager* pLayout = new mof::LayoutManager(10 , 35 , mof::LayoutManager::HORIZONTAL , 1);
44 mof::WidgetView* pBackgroundView = new mof::ImageTileWidgetView( _T("image/frame0.png") , title);
46 std::vector<mof::MessageWidget::Page> pages;
48 //foreach(const mof::tstring& text , text)
50 mof::MessageWidget::Page tmp(text , mof::Font(_T("
\94~UI
\83S
\83V
\83b
\83N") , 25) );
54 boost::shared_ptr<mof::MessageWidget> p
56 new mof::MessageWidget
59 pages.front() , pages.back() , mof::Rectangle<int>(70+20 , 300 , 570+20 , 450) , pLayout
63 m_pImpl->messages.push_back(p);
68 void MyInterpreter::inactive( boost::shared_ptr<mof::MessageWidget>& message )
71 mof::Deleter<mof::MessageWidget> del(message);
73 m_pImpl->inactiveResources.push_back(del.getWeak());
74 m_pImpl->scheduler.addEvent( 40 , del );
75 m_pImpl->scheduler.addEvent( 40 , boost::bind( &mof::Interpreter::doNextCommand , this ) );
78 void MyInterpreter::update()
80 m_pImpl->scheduler.update();
81 Interpreter::update();
82 foreach(boost::weak_ptr<mof::MessageWidget>& resource , m_pImpl->inactiveResources)
84 if(resource.lock())resource.lock()->update();
88 void MyInterpreter::draw() const
90 foreach(boost::shared_ptr<mof::MessageWidget>& resource , m_pImpl->messages )
94 foreach(boost::weak_ptr<mof::MessageWidget>& resource , m_pImpl->inactiveResources)
96 if(resource.lock())resource.lock()->draw();