1 module armos.utils.gui;
2 
3 // import armos.graphics;
4 import armos.types.color;
5 import armos.app;
6 import armos.math;
7 import armos.events;
8 import armos.graphics.bitmapfont;
9 
10 public import armos.utils.gui.style;
11 public import armos.utils.gui.widgets;
12 
13 /++
14 値にアクセスするGuiを表すclassです.
15 
16 Examples:
17 ---
18 class TestApp : ar.BaseApp{
19     ar.Gui gui;
20     float f=128;
21 
22     void setup(){
23         gui = (new ar.Gui)
24             .add(
25                     (new ar.List)
26                     .add(new ar.Partition)
27                     .add(new ar.Label("some text"))
28                     .add(new ar.Partition("*"))
29                 )
30             .add(
31                     (new ar.List)
32                     .add(new ar.Partition)
33                     .add(new ar.Slider!float("slider!float", f, 0, 255))
34                 );
35     }
36 
37     void draw(){
38         f.writeln;
39         gui.draw;
40     }
41 }
42 void main(){ar.run(new TestApp);}
43 ---
44 +/
45 class Gui {
46     public{
47         /++
48         +/
49         this(){
50             _style = new Style;
51             _style.font = new BitmapFont;
52             _style.font.load("data/font.png", 8, 8);
53             _style.colors["font1"] = Color(200.0/255.0, 200.0/255.0, 200.0/255.0);
54             _style.colors["font2"] = Color(105.0/255.0, 105.0/255.0, 105.0/255.0);
55             _style.colors["background"] = Color(40.0/255.0, 40.0/255.0, 40.0/255.0, 200.0/255.0);
56             _style.colors["base1"] = Color(0.25, 0.25, 0.25);
57             _style.colors["base2"] = Color(150.0/255.0, 150.0/255.0, 150.0/255.0);
58             _style.width = 256;
59         }
60 
61         /++
62             Listを自身に追加します.また自身を返すためメソッドチェインが可能です.
63         +/
64         Gui add(List list){
65             _lists ~= list;
66             list.style = _style;
67             return this;
68         };
69 
70         /++
71             Guiの内部のウィジェットを再帰的に描画します.
72         +/
73         void draw(){
74             import armos.graphics.renderer;
75             pushStyle;
76             blendMode(BlendMode.Alpha);
77             disableDepthTest;
78 
79             int currentWidth = 0;
80             foreach (list; _lists) {
81                 pushMatrix;
82                 translate(currentWidth, 0, 0);
83                 list.draw(currentWidth);
84                 popMatrix;
85                 currentWidth += list.width + _style.font.width;
86             }
87             popStyle;
88         }
89 
90     }//public
91 
92     private{
93         List[] _lists;
94         Style _style;
95     }//private
96 }//class Gui
97 
98 
99 /++
100 Guiの構成要素でWidgetを複数格納するclassです.
101 +/
102 
103 
104 class List {
105     public{
106 
107         /++
108             Widgetを追加します.また自身を返すためメソッドチェインが可能です.
109         +/
110         List add(Widget widget){
111             _widgets ~= widget;
112             return this;
113         }
114 
115         /++
116         +/
117         void style(Style stl){
118             foreach (widget; _widgets) {
119                 widget.style = stl;
120             }
121         }
122 
123         /++
124             Widgetを描画します.
125         +/
126         void draw(in int posX){
127             int currentHeight= 0;
128             foreach (widget; _widgets) {
129                 import armos.graphics;
130                 pushMatrix;
131                 translate(0, currentHeight, 0);
132                 widget.position = Vector2i(posX, currentHeight);
133                 widget.draw();
134                 popMatrix;
135                 currentHeight += widget.height;
136             }
137         }
138 
139         /++
140         +/
141         int width()const{
142             return _width;
143         }
144     }//public
145 
146     private{
147         Widget[] _widgets;
148         int _width = 256;
149     }//private
150 }//class List