1 /**
2 Grimoire
3 Copyright (c) 2017 Enalye
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising
7 from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute
11 it freely, subject to the following restrictions:
12 
13 	1. The origin of this software must not be misrepresented;
14 	   you must not claim that you wrote the original software.
15 	   If you use this software in a product, an acknowledgment
16 	   in the product documentation would be appreciated but
17 	   is not required.
18 
19 	2. Altered source versions must be plainly marked as such,
20 	   and must not be misrepresented as being the original software.
21 
22 	3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 module ui.image;
26 
27 import core.vec2;
28 import render.sprite;
29 import common.all;
30 
31 import ui.widget;
32 
33 class Image: Widget {
34 	private Sprite _sprite;
35 
36 	@property {
37 		Sprite sprite() { return _sprite; }
38 		Sprite sprite(Sprite newSprite) {
39 			_sprite = newSprite;
40 			_size = _sprite.size;
41 			return _sprite;
42 		}
43 	}
44 
45 	this(Sprite newSprite) {
46 		_sprite = newSprite;
47 		_size = _sprite.size;
48 		_angle = _sprite.angle;
49 		_isInteractable = false;
50 	}
51 
52 	override void onEvent(Event event) {}
53 	override void update(float deltaTime) {}
54     
55     override void onAngle() {
56         _sprite.angle = _angle;
57     }
58 
59     override void onSize() {
60         _sprite.size = _size;
61     }
62 
63 	override void draw() {
64 		_sprite.drawUnchecked(anchoredPosition());
65 	}
66 }