1 /**
2  * ae.demo.drawsprite.main
3  *
4  * License:
5  *   This Source Code Form is subject to the terms of
6  *   the Mozilla Public License, v. 2.0. If a copy of
7  *   the MPL was not distributed with this file, You
8  *   can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * Authors:
11  *   Vladimir Panteleev <vladimir@thecybershadow.net>
12  */
13 
14 module ae.demo.drawsprite.main;
15 
16 import ae.ui.app.application;
17 import ae.ui.app.main;
18 import ae.ui.shell.shell;
19 import ae.ui.shell.sdl2.shell;
20 import ae.ui.video.sdl2.video;
21 import ae.ui.video.renderer;
22 import ae.utils.fps;
23 import ae.utils.graphics.image;
24 
25 final class MyApplication : Application
26 {
27 	override string getName() { return "Demo/DrawSprite"; }
28 	override string getCompanyName() { return "CyberShadow"; }
29 
30 	Shell shell;
31 	FPSCounter fps;
32 	Image!BGRX image;
33 	enum SCALE_BASE = 0x10000;
34 
35 	ImageTextureSource source;
36 
37 	override void render(Renderer s)
38 	{
39 		fps.tick(&shell.setCaption);
40 
41 		//auto canvas = s.lock();
42 		//scope(exit) s.unlock();
43 
44 		int x0 = (s.width  - image.w) / 2;
45 		int y0 = (s.height - image.h) / 2;
46 		//image.blitTo(canvas, x0, y0);
47 		s.draw(x0, y0, source, 0, 0, image.w, image.h);
48 	}
49 
50 	override int run(string[] args)
51 	{
52 		import std.file : read;
53 		image = read("lena.bmp")
54 			.parseBMP!BGR()
55 			.colorMap!(c => BGRX(c.b, c.g, c.r))
56 			.copy();
57 		source = new ImageTextureSource;
58 		source.image = image;
59 
60 		shell = new SDL2Shell(this);
61 		shell.video = new SDL2Video();
62 		shell.run();
63 		shell.video.shutdown();
64 		return 0;
65 	}
66 
67 	override void handleQuit()
68 	{
69 		shell.quit();
70 	}
71 }
72 
73 shared static this()
74 {
75 	createApplication!MyApplication();
76 }