1 /* This file is part of SDL_haa - SDL addon for Hildon Animation Actors
2 * Copyright (C) 2010 Javier S. Pedro
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.
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.
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/>.
23 #include "SDL_video.h"
24 #include "SDL_events.h"
26 /* Set up for C function definitions, even when using C++ */
31 typedef enum HAA_Axis {
37 typedef enum HAA_Gravity {
47 HAA_GRAVITY_CENTER = 9
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
63 /** A Hildon Animation Actor. */
64 typedef struct HAA_Actor {
65 /** The associated SDL surface; you can render to it. */
66 SDL_Surface * surface;
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;
77 /** Invoke after SDL_Init.
78 @param flags reserved for future expansion (pass 0)
79 @return 0 if SDL_haa was initialized correctly.
81 extern DECLSPEC int SDLCALL HAA_Init(Uint32 flags);
83 /** Invoke just before SDL_Quit.
85 extern DECLSPEC void SDLCALL HAA_Quit();
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.
92 extern DECLSPEC int SDLCALL HAA_FilterEvent(const SDL_Event *event);
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.
99 extern DECLSPEC int SDLCALL HAA_SetVideoMode(void);
101 /** Creates both an animation actor and its associated surface.
102 * @param flags reserved (pass 0)
103 * @param width size of the actor surface
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.
109 extern DECLSPEC HAA_Actor* SDLCALL HAA_CreateActor(Uint32 flags,
110 int width, int height, int bitsPerPixel);
112 /** Frees an animation actor and associated surface. */
113 extern DECLSPEC void SDLCALL HAA_FreeActor(HAA_Actor* actor);
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);
120 static inline void HAA_Show
124 actor->pending |= HAA_PENDING_SHOW;
127 static inline void HAA_Hide
131 actor->pending |= HAA_PENDING_SHOW;
134 static inline void HAA_SetOpacity
135 (HAA_Actor* actor, unsigned char opacity)
137 actor->opacity = opacity;
138 actor->pending |= HAA_PENDING_SHOW;
141 static inline void HAA_SetPosition
142 (HAA_Actor* actor, int x, int y)
144 actor->position_x = x;
145 actor->position_y = y;
146 actor->pending |= HAA_PENDING_POSITION;
149 static inline void HAA_SetDepth
150 (HAA_Actor* actor, int depth)
152 actor->depth = depth;
153 actor->pending |= HAA_PENDING_POSITION;
156 static inline void HAA_SetScaleX
157 (HAA_Actor* actor, Sint32 x, Sint32 y)
161 actor->pending |= HAA_PENDING_SCALE;
164 static inline void HAA_SetScale
165 (HAA_Actor* actor, double x, double y)
167 HAA_SetScaleX(actor, x * (1 << 16), y * (1 << 16));
170 static inline void HAA_SetAnchor
171 (HAA_Actor* actor, int x, int y)
173 actor->gravity = HAA_GRAVITY_NONE;
176 actor->pending |= HAA_PENDING_ANCHOR;
179 static inline void HAA_SetGravity
180 (HAA_Actor* actor, HAA_Gravity gravity)
182 actor->gravity = gravity;
185 actor->pending |= HAA_PENDING_ANCHOR;
188 static inline void HAA_SetRotationX
189 (HAA_Actor* actor, HAA_Axis axis, Sint32 degrees, int x, int y, int z)
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;
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;
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;
213 static inline void HAA_SetRotation
214 (HAA_Actor* actor, HAA_Axis axis, double degrees, int x, int y, int z)
216 HAA_SetRotationX(actor, axis, degrees * (1 << 16), x, y, z);
219 /* Ends C function definitions when using C++ */