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 typedef struct HAA_Actor {
64 SDL_Surface * surface;
66 Uint8 visible, opacity, gravity;
67 Sint32 position_x, position_y, depth;
68 Sint32 scale_x, scale_y;
69 Sint32 anchor_x, anchor_y;
70 Sint32 x_rotation_angle, x_rotation_y, x_rotation_z;
71 Sint32 y_rotation_angle, y_rotation_x, y_rotation_z;
72 Sint32 z_rotation_angle, z_rotation_x, z_rotation_y;
75 /** Invoke after SDL_Init.
76 @param flags SDL_FULLSCREEN if you will set a fullscreen video mode.
77 @return 0 if SDL_haa was initialized correctly.
79 extern DECLSPEC int SDLCALL HAA_Init(Uint32 flags);
81 /** Invoke just before SDL_Quit.
83 extern DECLSPEC void SDLCALL HAA_Quit();
86 Call before handling any SDL_Event (or use SDL_SetEventFilter).
87 @param event the SDL_Event you were about to handle.
88 @return 1 if the event was filtered and should not be handled by your app.
90 extern DECLSPEC int SDLCALL HAA_FilterEvent(const SDL_Event *event);
92 extern DECLSPEC HAA_Actor* SDLCALL HAA_CreateActor(Uint32 flags,
93 int width, int height, int bitsPerPixel);
95 extern DECLSPEC void SDLCALL HAA_FreeActor(HAA_Actor* actor);
97 /** Flushes any pending position, scale, orientation, etc. changes. */
98 extern DECLSPEC int SDLCALL HAA_Commit(HAA_Actor* actor);
99 /** Puts contents of actor surface to screen. */
100 extern DECLSPEC int SDLCALL HAA_Flip(HAA_Actor* actor);
102 static inline void HAA_Show
106 actor->pending |= HAA_PENDING_SHOW;
109 static inline void HAA_Hide
113 actor->pending |= HAA_PENDING_SHOW;
116 static inline void HAA_SetOpacity
117 (HAA_Actor* actor, unsigned char opacity)
119 actor->opacity = opacity;
120 actor->pending |= HAA_PENDING_SHOW;
123 static inline void HAA_SetPosition
124 (HAA_Actor* actor, int x, int y)
126 actor->position_x = x;
127 actor->position_y = y;
128 actor->pending |= HAA_PENDING_POSITION;
131 static inline void HAA_SetDepth
132 (HAA_Actor* actor, int depth)
134 actor->depth = depth;
135 actor->pending |= HAA_PENDING_POSITION;
138 static inline void HAA_SetScaleX
139 (HAA_Actor* actor, Sint32 x, Sint32 y)
143 actor->pending |= HAA_PENDING_SCALE;
146 static inline void HAA_SetScale
147 (HAA_Actor* actor, double x, double y)
149 HAA_SetScaleX(actor, x * (1 << 16), y * (1 << 16));
152 static inline void HAA_SetAnchor
153 (HAA_Actor* actor, int x, int y)
155 actor->gravity = HAA_GRAVITY_NONE;
158 actor->pending |= HAA_PENDING_ANCHOR;
161 static inline void HAA_SetGravity
162 (HAA_Actor* actor, HAA_Gravity gravity)
164 actor->gravity = gravity;
167 actor->pending |= HAA_PENDING_ANCHOR;
170 static inline void HAA_SetRotationX
171 (HAA_Actor* actor, HAA_Axis axis, Sint32 degrees, int x, int y, int z)
175 actor->x_rotation_angle = degrees;
176 actor->x_rotation_y = y;
177 actor->x_rotation_z = z;
178 actor->pending |= HAA_PENDING_ROTATION_X;
181 actor->y_rotation_angle = degrees;
182 actor->y_rotation_x = x;
183 actor->y_rotation_z = z;
184 actor->pending |= HAA_PENDING_ROTATION_Y;
187 actor->z_rotation_angle = degrees;
188 actor->z_rotation_x = x;
189 actor->z_rotation_y = y;
190 actor->pending |= HAA_PENDING_ROTATION_Z;
195 static inline void HAA_SetRotation
196 (HAA_Actor* actor, HAA_Axis axis, double degrees, int x, int y, int z)
198 HAA_SetRotationX(actor, axis, degrees * (1 << 16), x, y, z);
201 /* Ends C function definitions when using C++ */