1 module armos.app.window;
2 
3 import armos.events;
4 import armos.math;
5 import armos.app;
6 import armos.graphics.renderer;
7 
8 /++
9 armosで用いるWindowsの雛形となるinterfaceです.新たにWindowを実装する際はこのinterfaceを継承することでrunnerから実行できます.
10 +/
11 interface Window{
12     public{
13         enum bool hasRenderer = false;
14         /++
15             Windowsが実行するイベントを表すプロパティです.
16         +/
17         // CoreEvents events();
18 
19         /++
20             サイズのプロパティです
21         +/
22         void size(Vector2i size);
23 
24         /++
25             サイズのプロパティです.
26         +/
27         Vector2i size()const;
28 
29         /++
30             サイズのプロパティです.
31         +/
32         Vector2i frameBufferSize()const;
33 
34         /++
35             イベントが発生している場合,登録されたイベントを実行します
36         +/
37         void pollEvents();
38 
39         ///
40         void setup();
41 
42         /++
43             Windowを更新します.
44         +/
45         void update();
46 
47         ///
48         void draw();
49 
50         /++
51             Windowを閉じます.
52         +/
53         void close();
54 
55         /++
56             Windowがフレームの最後に閉じる場合trueになります.
57         +/
58         bool shouldClose();
59 
60         /++
61             Windowのアスペクト比を表します
62         +/
63         float aspect();
64 
65         /++
66             Windowのタイトル文字列のプロパティです.
67         +/
68         string name();
69 
70         /++
71             Windowのタイトル文字列のプロパティです.
72         +/
73         void name(in string str);
74         
75         ///
76         void initEvents(Application);
77 
78         void select();
79 
80         /// VerticalSync
81         void verticalSync(in bool);
82 
83         float pixelScreenCoordScale()const;
84 
85         ///
86         CoreObservables observables();
87 
88         ///
89         Renderer renderer();
90     }//public
91 }
92 
93 mixin template BaseWindow(){
94     public{
95         /++
96         +/
97         bool shouldClose(){return _shouldClose;}
98 
99         /++
100         +/
101         string name(){return _name;}
102 
103         /++
104         +/
105         void name(in string str){_name = str;}
106 
107         /++
108         +/
109         float aspect(){
110             if(size[1]==0){
111                 return 0;
112             }else{
113                 return cast(float)size[0]/cast(float)size[1];
114             }
115 
116         }
117         
118     }//public
119 
120     protected{
121         bool _shouldClose = false;
122         string _name = "";
123         Vector2f _windowSize;
124         
125     }//protected
126 }
127 
128 /++
129     現在のWindowを返す関数です.
130 +/
131 Window currentWindow(){
132     return mainLoop.currentWindow;
133 }
134 
135 /++
136     現在のWindowの大きさを変更する関数です.
137 +/
138 void windowSize(Vector2i size){
139     currentWindow.size(size);
140 }
141 
142 /++
143     現在のWindowの大きさを返す関数です.
144 +/
145 Vector2i windowSize(){
146     return currentWindow.size;
147 }
148 
149 /++
150     現在のWindowのアスペクト比を返す関数です.
151 +/
152 float windowAspect(){
153     return currentWindow.aspect;
154 }
155 
156 /++
157 +/
158 void windowTitle(in string str){
159     currentWindow.name = str;
160 }
161 
162 /++
163 +/
164 string windowTitle(){
165     return currentWindow.name;
166 }
167 
168 ///
169 void verticalSync(in bool f){
170     currentWindow.verticalSync = f;
171 }