OSDN Git Service

fix cmake/Macros.cmake
[moflib/moflib.git] / saisei-1.0 / src / oldcode / MyInterpreter.cpp~
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"
10 #include <list>
11 #include "mof/ConsoleIO.hpp"
12
13 struct MyInterpreter::Impl
14 {
15     std::list<boost::weak_ptr<mof::MessageWidget> > inactiveResources;
16     mof::EventScheduler scheduler;
17     std::list<boost::shared_ptr<mof::MessageWidget> > messages;
18     
19     Impl()
20     {
21     }
22     
23     ~Impl()
24     {
25     }
26     
27     
28 };
29
30 MyInterpreter::MyInterpreter(  )
31 : m_pImpl(new Impl() )
32 {
33 }
34
35
36 MyInterpreter::~MyInterpreter()
37 {
38 }
39
40 boost::shared_ptr<mof::MessageWidget>
41 MyInterpreter::createMessageWidget(const mof::tstring &title, const mof::tstring &text) 
42 {
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);
45         
46         std::vector<mof::MessageWidget::Page> pages;
47         
48         //foreach(const mof::tstring& text , text)
49         //{
50                 mof::MessageWidget::Page tmp(text , mof::Font(_T("\94~UI\83S\83V\83b\83N") , 25) );
51                 pages.push_back(tmp);
52         //}
53         
54         boost::shared_ptr<mof::MessageWidget> p
55         (
56             new mof::MessageWidget
57             (
58                     pBackgroundView ,
59                     pages.front() , pages.back() , mof::Rectangle<int>(70+20 , 300 , 570+20 , 450) , pLayout
60                 )
61         );
62             
63         m_pImpl->messages.push_back(p);
64         return p;
65         
66 }
67
68 void MyInterpreter::inactive( boost::shared_ptr<mof::MessageWidget>& message ) 
69 {   
70
71         mof::Deleter<mof::MessageWidget> del(message);
72                                 
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 ) );
76 }
77
78 void MyInterpreter::update()
79 {
80     m_pImpl->scheduler.update();
81     Interpreter::update();
82     foreach(boost::weak_ptr<mof::MessageWidget>& resource , m_pImpl->inactiveResources)
83         {
84             if(resource.lock())resource.lock()->update();
85         }
86 }
87   
88 void MyInterpreter::draw() const
89 {
90     foreach(boost::shared_ptr<mof::MessageWidget>& resource , m_pImpl->messages )
91     {
92         resource->draw();
93     }
94     foreach(boost::weak_ptr<mof::MessageWidget>& resource , m_pImpl->inactiveResources)
95         {
96             if(resource.lock())resource.lock()->draw();
97         }
98 }
99