OSDN Git Service

fix cmake/Macros.cmake
[moflib/moflib.git] / moflib-1.0 / moflib / moflib / mof / widget / mofml_parser.hpp
1 #pragma once
2 #include <mof/Color.hpp>
3 #include <mof/Rectangle.hpp>
4 #include <memory>
5 #include <boost/variant.hpp>
6 #include <mof/widget/flow_layout.hpp>
7
8 namespace mof
9 {
10 namespace widget
11 {
12         class mofml_parser
13         {
14         public:
15 //{{{ text_node
16                 struct text_node
17                 {
18                         mof::Color4f font_color;
19                         mof::tstring text;
20                         text_node() {}// do nothing
21                 };
22 //}}}
23 //{{{ image_node
24                 struct image_node
25                 {
26                         mof::tstring src;
27                         float width, height;
28                         Rectangle<float> t_rect;
29                         image_node() : width(0), height(0) {}// do nothing
30                 };
31 //}}}
32 //{{{ new_line_node
33                 struct new_line_node{};
34 //}}}
35 //{{{ end_node
36                 struct end_node{};
37 //}}}
38 //{{{ layout_start_node
39                 struct layout_start_node{};
40 //}}}
41 //{{{ layout_end_node
42                 struct layout_end_node
43                 {
44                         size_t width, height;
45                         flow_layout::xalign xalign;
46                         flow_layout::yalign yalign;
47
48                         layout_end_node() 
49                                 : width(0), height(0), 
50                                 xalign(flow_layout::XALIGN_LEFT),
51                                 yalign(flow_layout::YALIGN_TOP)
52                         {}// do nothing
53                 };
54 //}}}
55                 typedef boost::variant<text_node, image_node, new_line_node, end_node, layout_start_node, layout_end_node> node;
56                 enum node_type
57                 {
58                         TEXT = 0, IMAGE, NEW_LINE, END, LAYOUT_START, LAYOUT_END
59                 };
60
61                 mofml_parser();
62                 ~mofml_parser();
63
64                 void set_text(const mof::tstring& text);
65                 node next_node();       
66                 bool has_next_node() const;
67
68         private:
69                 struct impl;
70                 std::unique_ptr<impl> pimpl_;
71         };
72 }// namespace widget
73 }// namespace mof