1 /** 
2  * Copyright: Enalye
3  * License: Zlib
4  * Authors: Enalye
5  */
6 module atelier.render.font.glyph;
7 
8 import atelier.core;
9 import atelier.render.drawable, atelier.render.window;
10 
11 /// Information about a single character
12 struct Glyph {
13     @property {
14         /// Is the character defined ?
15         bool exists() const {
16             return _exists;
17         }
18         /// Width to advance cursor from previous position.
19         int advance() const {
20             return _advance;
21         }
22         /// Offset
23         int offsetX() const {
24             return _offsetX;
25         }
26         /// Ditto
27         int offsetY() const {
28             return _offsetY;
29         }
30         /// Character size
31         int width() const {
32             return _width;
33         }
34         /// Ditto
35         int height() const {
36             return _height;
37         }
38     }
39 
40     private {
41         bool _exists;
42         /// Width to advance cursor from previous position.
43         int _advance;
44         /// Offset
45         int _offsetX, _offsetY;
46         /// Character size
47         int _width, _height;
48         /// Coordinates in drawable
49         int _packX, _packY, _packWidth, _packHeight;
50         /// Drawable
51         Drawable _drawable;
52     }
53 
54     /// Render glyph
55     void draw(Vec2f position, int scale, Color color, float alpha) {
56         const Vec2f finalSize = Vec2f(_width, _height) * scale * transformScale();
57         _drawable.color = color;
58         _drawable.blend = Blend.alpha;
59         _drawable.alpha = alpha;
60         _drawable.draw(transformRenderSpace(position), finalSize, Vec4i(_packX,
61                 _packY, _packWidth, _packHeight), Vec2f.zero);
62     }
63 
64     /// Ditto
65     void draw(Vec2f position, float scale, Color color, float alpha) {
66         const Vec2f finalSize = Vec2f(_width, _height) * scale * transformScale();
67         _drawable.color = color;
68         _drawable.blend = Blend.alpha;
69         _drawable.alpha = alpha;
70         _drawable.draw(transformRenderSpace(position), finalSize, Vec4i(_packX,
71                 _packY, _packWidth, _packHeight), Vec2f.zero);
72     }
73 }