1 /** DGui project file.
2 
3 Copyright: Trogu Antonio Davide 2011-2013
4 
5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
6 
7 Authors: Trogu Antonio Davide
8 */
9 module dgui.resources;
10 
11 import dgui.core.charset;
12 import dgui.core.winapi;
13 import dgui.core.geometry;
14 import dgui.core.utils;
15 import dgui.core.exception;
16 import dgui.canvas;
17 
18 final class Resources
19 {
20 	private static Resources _rsrc;
21 
22 	private this()
23 	{
24 
25 	}
26 
27 	public Icon getIcon(ushort id)
28 	{
29 		return getIcon(id, nullSize);
30 	}
31 
32 	public Icon getIcon(ushort id, Size sz)
33 	{
34 		HICON hIcon = loadImage(getHInstance(), cast(wchar*)id, IMAGE_ICON, sz.width, sz.height, LR_LOADTRANSPARENT | (sz == nullSize ? LR_DEFAULTSIZE : 0));
35 
36 		if(!hIcon)
37 		{
38 			throwException!(GDIException)("Cannot load Icon: '%d'", id);
39 		}
40 
41 		return Icon.fromHICON(hIcon);
42 	}
43 
44 	public Bitmap getBitmap(ushort id)
45 	{
46 		HBITMAP hBitmap = loadImage(getHInstance(), cast(wchar*)id, IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT | LR_DEFAULTSIZE);
47 
48 		if(!hBitmap)
49 		{
50 			throwException!(GDIException)("Cannot load Bitmap: '%d'", id);
51 		}
52 
53 		return Bitmap.fromHBITMAP(hBitmap);
54 	}
55 
56 	public T* getRaw(T)(ushort id, char* rt)
57 	{
58 		HRSRC hRsrc = FindResourceW(null, MAKEINTRESOURCEW(id), rt);
59 
60 		if(!hRsrc)
61 		{
62 			throwException!(GDIException)("Cannot load Custom Resource: '%d'", id);
63 		}
64 
65 		return cast(T*)LockResource(LoadResource(null, hRsrc));
66 	}
67 
68 	@property public static Resources instance()
69 	{
70 		if(!_rsrc)
71 		{
72 			_rsrc = new Resources();
73 		}
74 
75 		return _rsrc;
76 	}
77 }