documentation was wrong
[sdlhildon] / sdlhaa / src / SDL_haa.h
1 /* This file is part of SDL_haa - SDL addon for Hildon Animation Actors
2  * Copyright (C) 2010 Javier S. Pedro
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 3 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA or see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef __SDL_HAA_H
21 #define __SDL_HAA_H
22
23 #include "SDL_video.h"
24 #include "SDL_events.h"
25
26 /* Set up for C function definitions, even when using C++ */
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 typedef enum HAA_Axis {
32         HAA_X_AXIS = 0,
33         HAA_Y_AXIS = 1,
34         HAA_Z_AXIS = 2
35 } HAA_Axis;
36
37 typedef enum HAA_Gravity {
38         HAA_GRAVITY_NONE        = 0,
39         HAA_GRAVITY_N           = 1,
40         HAA_GRAVITY_NE          = 2,
41         HAA_GRAVITY_E           = 3,
42         HAA_GRAVITY_SE          = 4,
43         HAA_GRAVITY_S           = 5,
44         HAA_GRAVITY_SW          = 6,
45         HAA_GRAVITY_W           = 7,
46         HAA_GRAVITY_NW          = 8,
47         HAA_GRAVITY_CENTER      = 9
48 } HAA_Gravity;
49
50 typedef enum HAA_Actor_Pending {
51         HAA_PENDING_NOTHING             = 0,
52         HAA_PENDING_PARENT                      = (1 << 0),
53         HAA_PENDING_SHOW                        = (1 << 1),
54         HAA_PENDING_POSITION            = (1 << 2),
55         HAA_PENDING_SCALE                       = (1 << 3),
56         HAA_PENDING_ANCHOR                      = (1 << 4),
57         HAA_PENDING_ROTATION_X          = (1 << 5),
58         HAA_PENDING_ROTATION_Y          = (1 << 6),
59         HAA_PENDING_ROTATION_Z          = (1 << 7),
60         HAA_PENDING_EVERYTHING          = 0xFFU
61 } HAA_Actor_Pending;
62
63 /** A Hildon Animation Actor. */
64 typedef struct HAA_Actor {
65         /** The associated SDL surface; you can render to it. */
66         SDL_Surface * surface;
67         Uint8 pending;
68         Uint8 visible, opacity, gravity;
69         Sint32 position_x, position_y, depth;
70         Sint32 scale_x, scale_y;
71         Sint32 anchor_x, anchor_y;
72         Sint32 x_rotation_angle, x_rotation_y, x_rotation_z;
73         Sint32 y_rotation_angle, y_rotation_x, y_rotation_z;
74         Sint32 z_rotation_angle, z_rotation_x, z_rotation_y;
75 } HAA_Actor;
76
77 /** Invoke after SDL_Init.
78         @param flags reserved for future expansion (pass 0)
79         @return 0 if SDL_haa was initialized correctly.
80   */
81 extern DECLSPEC int SDLCALL HAA_Init(Uint32 flags);
82
83 /** Invoke just before SDL_Quit.
84   */
85 extern DECLSPEC void SDLCALL HAA_Quit();
86
87 /** 
88   Call before handling any SDL_Event (or use SDL_SetEventFilter).
89   @param event the SDL_Event you were about to handle.
90   @return 0 if the event was filtered and should not be handled by your app.
91 */
92 extern DECLSPEC int SDLCALL HAA_FilterEvent(const SDL_Event *event);
93
94 /** Call after calling SDL_SetVideoMode() if you have any actors created
95   * to ensure they're visible in the new window.
96   * If you have no actors, it does nothing.
97   * @return 0 if everything went OK.
98   */
99 extern DECLSPEC int SDLCALL HAA_SetVideoMode(void);
100
101 /** Creates both an animation actor and its associated surface.
102   * @param flags reserved (pass 0)
103   * @param width size of the actor surface
104   * @param height
105   * @param bitsPerPixel depth of the actor surface
106   *     a 32 bpp surface will have an alpha channel.
107   * @return the created HAA_Actor, or NULL if an error happened.
108   */
109 extern DECLSPEC HAA_Actor* SDLCALL HAA_CreateActor(Uint32 flags,
110         int width, int height, int bitsPerPixel);
111
112 /** Frees an animation actor and associated surface. */
113 extern DECLSPEC void SDLCALL HAA_FreeActor(HAA_Actor* actor);
114
115 /** Flushes any pending position, scale, orientation, etc. changes. */
116 extern DECLSPEC int SDLCALL HAA_Commit(HAA_Actor* actor);
117 /** Puts contents of actor surface to screen. */
118 extern DECLSPEC int SDLCALL HAA_Flip(HAA_Actor* actor);
119
120 static inline void HAA_Show
121 (HAA_Actor* actor)
122 {
123         actor->visible = 1;
124         actor->pending |= HAA_PENDING_SHOW;
125 }
126
127 static inline void HAA_Hide
128 (HAA_Actor* actor)
129 {
130         actor->visible = 0;
131         actor->pending |= HAA_PENDING_SHOW;
132 }
133
134 static inline void HAA_SetOpacity
135 (HAA_Actor* actor, unsigned char opacity)
136 {
137         actor->opacity = opacity;
138         actor->pending |= HAA_PENDING_SHOW;
139 }
140
141 static inline void HAA_SetPosition
142 (HAA_Actor* actor, int x, int y)
143 {
144         actor->position_x = x;
145         actor->position_y = y;
146         actor->pending |= HAA_PENDING_POSITION;
147 }
148
149 static inline void HAA_SetDepth
150 (HAA_Actor* actor, int depth)
151 {
152         actor->depth = depth;
153         actor->pending |= HAA_PENDING_POSITION;
154 }
155
156 static inline void HAA_SetScaleX
157 (HAA_Actor* actor, Sint32 x, Sint32 y)
158 {
159         actor->scale_x = x;
160         actor->scale_y = y;
161         actor->pending |= HAA_PENDING_SCALE;
162 }
163
164 static inline void HAA_SetScale
165 (HAA_Actor* actor, double x, double y)
166 {
167         HAA_SetScaleX(actor, x * (1 << 16), y * (1 << 16));
168 }
169
170 static inline void HAA_SetAnchor
171 (HAA_Actor* actor, int x, int y)
172 {
173         actor->gravity = HAA_GRAVITY_NONE;
174         actor->anchor_x = x;
175         actor->anchor_y = y;
176         actor->pending |= HAA_PENDING_ANCHOR;
177 }
178
179 static inline void HAA_SetGravity
180 (HAA_Actor* actor, HAA_Gravity gravity)
181 {
182         actor->gravity = gravity;
183         actor->anchor_x = 0;
184         actor->anchor_y = 0;
185         actor->pending |= HAA_PENDING_ANCHOR;
186 }
187
188 static inline void HAA_SetRotationX
189 (HAA_Actor* actor, HAA_Axis axis, Sint32 degrees, int x, int y, int z)
190 {
191         switch (axis) {
192                 case HAA_X_AXIS:
193                         actor->x_rotation_angle = degrees;
194                         actor->x_rotation_y = y;
195                         actor->x_rotation_z = z;
196                         actor->pending |= HAA_PENDING_ROTATION_X;
197                         break;
198                 case HAA_Y_AXIS:
199                         actor->y_rotation_angle = degrees;
200                         actor->y_rotation_x = x;
201                         actor->y_rotation_z = z;
202                         actor->pending |= HAA_PENDING_ROTATION_Y;
203                         break;
204                 case HAA_Z_AXIS:
205                         actor->z_rotation_angle = degrees;
206                         actor->z_rotation_x = x;
207                         actor->z_rotation_y = y;
208                         actor->pending |= HAA_PENDING_ROTATION_Z;
209                         break;
210         }
211 }
212
213 static inline void HAA_SetRotation
214 (HAA_Actor* actor, HAA_Axis axis, double degrees, int x, int y, int z)
215 {
216         HAA_SetRotationX(actor, axis, degrees * (1 << 16), x, y, z);
217 }
218
219 /* Ends C function definitions when using C++ */
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif