1 /*
2     Copyright © 2020, Luna Nielsen
3     Distributed under the 2-Clause BSD License, see LICENSE file.
4     
5     Authors: Luna Nielsen
6 */
7 module engine.ui;
8 public import engine.ui.widget;
9 import engine;
10 import bindbc.opengl;
11 import core.memory;
12 
13 /**
14     Initialize UI
15 */
16 void initUI(string uiFont) {
17     UI.changeFont(uiFont);
18 }
19 
20 /**
21     Base stuff for UI rendering
22 */
23 class UI {
24 public:
25     /**
26         The font used within UI
27     */
28     static Font UIFont;
29     
30     /**
31         Safetly changes the UI font
32     */
33     static void changeFont(string font) {
34         if (UIFont !is null) {
35 
36             // Destroy the current font and free it from memory
37             // This will force the texture memory to be freed
38             destroy!false(UIFont);
39             GC.collect();
40         }
41         UIFont = new Font(font, 24);
42     }
43 
44     /**
45         Sets up state for UI rendering
46     */
47     static void begin() {
48         glEnable(GL_SCISSOR_TEST);
49     }
50 
51     /**
52         Set the UI scissor area
53     */
54     static void setScissor(vec4i scissor) {
55         glScissor(scissor.x, (GameWindow.height-scissor.y)-scissor.w, cast(uint)scissor.z, cast(uint)scissor.w);
56     }
57 
58     /**
59         Finishes up UI rendering state
60     */
61     static void end() {
62         glDisable(GL_SCISSOR_TEST);
63     }
64 }