1 module test3.app;
2 
3 import pixelperfectengine.graphics.outputscreen;
4 import pixelperfectengine.graphics.layers;
5 import pixelperfectengine.graphics.raster;
6 import pixelperfectengine.concrete.window;
7 import pixelperfectengine.system.input;
8 import pixelperfectengine.system.systemutility;
9 import pixelperfectengine.system.file;
10 import pixelperfectengine.system.common;
11 import pixelperfectengine.system.timer;
12 
13 import core.thread;
14 import std.conv;
15 
16 /** 
17  * Tests GUI elements by displaying them.
18  */
19 int main() {
20     initialzeSDL();
21     INIT_CONCRETE();
22     TestElements te = new TestElements();
23     te.whereTheMagicHappens();
24     return 0;
25 }
26 
27 public class TestElements : InputListener, SystemEventListener {
28     Raster				mainRaster;
29 	OutputScreen		outScrn;
30     SpriteLayer			sprtL;
31     WindowHandler		wh;
32     InputHandler        ih;
33     bool                isRunning, flipScreen;
34 
35     public this() {
36         sprtL = new SpriteLayer(RenderingMode.Copy);
37 		outScrn = new OutputScreen("Test nr. 3",1696,960);
38 		mainRaster = new Raster(848,480,outScrn,0,1);
39 		mainRaster.addLayer(sprtL,0);
40         mainRaster.loadPalette(loadPaletteFromFile("../system/concreteGUIE1.tga"));
41         wh = new WindowHandler(1696,960,848,480,sprtL);
42         ih = new InputHandler();
43         ih.inputListener = this;
44         ih.systemEventListener = this;
45         ih.mouseListener = wh;
46         WindowElement.onDraw = &rasterRefresh;
47         Window.onDrawUpdate = &rasterRefresh;
48         isRunning = true;
49         wh.addWindow(new TestWindow());
50     }
51     protected void rasterRefresh() {
52         flipScreen = true;
53     }
54     public void whereTheMagicHappens() {
55         mainRaster.refresh();
56         while(isRunning) {
57             if (flipScreen) {
58                 flipScreen = false;
59                 mainRaster.refresh();
60             }
61             //mainRaster.refresh();
62             ih.test();
63             Thread.sleep(dur!"msecs"(10));
64             timer.test();
65         }
66     }
67 
68     public void keyEvent(uint id, BindingCode code, uint timestamp, bool isPressed) {
69 
70     }
71 
72     public void axisEvent(uint id, BindingCode code, uint timestamp, float value) {
73 
74     }
75 
76     public void onQuit() {
77         isRunning = false;
78     }
79 
80     public void controllerAdded(uint id) {
81 
82     }
83 
84     public void controllerRemoved(uint id) {
85 
86     }
87 }
88 
89 public class TestWindow : Window {
90     CheckBox            modeToggle;
91     Panel               panelTest;
92     RadioButton[]       radioButtonTest;
93     RadioButtonGroup    radioButtonTestGr;
94     ListView            listViewTest;
95     Button              buttonTest0, buttonTest1;
96     VertScrollBar       vScrollBarTest;
97     public this() {
98         super(Box.bySize(0, 0, 848, 480), "Test");
99         panelTest = new Panel("Selections", "", Box(5, 20, 200, 200));
100         addElement(panelTest);
101         for (int i ; i < 7 ; i++) {
102             RadioButton rb = new RadioButton
103                     ("Option "d ~ i.to!dstring(), "", Box(10, 40 + i * 20, 195, 40 + i * 20 + 16));
104             panelTest.addElement(rb);
105             radioButtonTest ~= rb;
106         }
107         radioButtonTestGr = new RadioButtonGroup(radioButtonTest);
108 
109         listViewTest = new ListView(new ListViewHeader(16, [50, 50], ["Column 1", "Column 2"]), [
110             new ListViewItem(16, ["First", "000000000000000000000"]),
111             new ListViewItem(16, ["Second", "000000000000000000000"]),
112             new ListViewItem(16, ["Third", "000000000000000000000"]),
113             new ListViewItem(16, ["Fourth", "000000000000000000000"]),
114             new ListViewItem(16, ["Last", "000000000000000000000"]),
115         ], "", Box(5, 220, 105, 313));
116         addElement(listViewTest);
117 
118         vScrollBarTest = new VertScrollBar(1000, "", Box.bySize(110, 220, 16, 120));
119         addElement(vScrollBarTest);
120 
121         buttonTest0 = new Button("A", "", Box(205, 20, 205 + 39, 20 + 39));
122         addElement(buttonTest0);
123         buttonTest0.state = ElementState.Disabled;
124         
125     }
126 
127 }