1 #ifndef __R_ELEMENT_H
2 #define __R_ELEMENT_H
3 
4 /*
5 Copyright 2011 Jared Krinke.
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
26 #include <lua.h>
27 
28 #include "r_object_ref.h"
29 #include "r_image_cache.h"
30 #include "r_list.h"
31 
32 typedef enum
33 {
34     R_ELEMENT_TYPE_IMAGE = 0,
35     R_ELEMENT_TYPE_IMAGE_REGION,
36     R_ELEMENT_TYPE_ANIMATION,
37     R_ELEMENT_TYPE_TEXT,
38     R_ELEMENT_TYPE_MAX
39 } r_element_type_t;
40 
41 typedef enum
42 {
43     R_ELEMENT_TEXT_ALIGNMENT_LEFT = 0,
44     R_ELEMENT_TEXT_ALIGNMENT_CENTER,
45     R_ELEMENT_TEXT_ALIGNMENT_RIGHT,
46     R_ELEMENT_TEXT_ALIGNMENT_MAX
47 } r_element_text_alignment_t;
48 
49 typedef struct
50 {
51     r_object_t          object;
52 
53     r_element_type_t    element_type;
54     r_real_t            x;
55     r_real_t            y;
56     r_real_t            z;
57     r_real_t            width;
58     r_real_t            height;
59     r_real_t            angle;
60     r_object_ref_t      image;
61     r_object_ref_t      color; /* TODO: Should color values be stored instead of a reference? That would probably make more sense... */
62 } r_element_t;
63 
64 /* Images and image regions */
65 typedef struct
66 {
67     r_element_t         element;
68 } r_element_image_t;
69 
70 typedef struct
71 {
72     r_element_image_t   image;
73     r_real_t            u1;
74     r_real_t            v1;
75     r_real_t            u2;
76     r_real_t            v2;
77 } r_element_image_region_t;
78 
79 /* Animations */
80 typedef struct
81 {
82     r_object_ref_t  image;
83     r_real_t        ms;
84 } r_animation_frame_t;
85 
86 typedef r_list_t r_animation_frame_list_t;
87 
88 extern r_animation_frame_t *r_animation_frame_list_get_index(r_state_t *rs, const r_animation_frame_list_t *list, unsigned int index);
89 
90 typedef struct
91 {
92     r_object_t                  object;
93     r_boolean_t                 loop;
94     r_boolean_t                 transient;
95     r_animation_frame_list_t    frames;
96 } r_animation_t;
97 
98 typedef struct
99 {
100     r_element_t     element;
101     unsigned int    frame_index;
102     r_real_t        frame_ms;
103 } r_element_animation_t;
104 
105 /* Text */
106 typedef struct
107 {
108     r_element_t                 element;
109     r_element_text_alignment_t  alignment;
110     r_object_ref_t              text;
111     r_object_ref_t              buffer;
112 } r_element_text_t;
113 
114 extern r_status_t r_element_setup(r_state_t *rs);
115 
116 #endif
117 
118