1 /*
2  * Martian: Motor para creaci�n de videojuegos con SDL y OpenGL
3  * Copyright (C) 2007  Javier P�rez Pacheco
4  *
5  * Este motor tiene licencia Creative Commons y se permite
6  * su modificacion y utilizacion libremente siempre y cuando se
7  * cite al autor original y se comparta con la misma licencia.
8  * No se permite su uso comercial.
9  *
10  * Para mas informacion visite la web:
11  * http://creativecommons.org/licenses/by-nc-sa/2.0/es/
12  *
13  * PROGRAMADOR
14  * Javier P�rez Pacheco
15  * Cadiz (Spain)
16  * javielinux@gmail.com
17  *
18  */
19 
20 #ifndef ELEMENTS_H_
21 #define ELEMENTS_H_
22 
23 #ifdef WIN32
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #endif
27 #if defined(__APPLE__) && defined(__MACH__)
28 #include <OpenGL/gl.h>	// Header File For The OpenGL32 Library
29 #include <OpenGL/glu.h>	// Header File For The GLu32 Library
30 #else
31 #include <GL/gl.h>	// Header File For The OpenGL32 Library
32 #include <GL/glu.h>	// Header File For The GLu32 Library
33 #endif
34 
35 #include <stdlib.h>
36 #include <SDL.h>
37 #include <SDL_image.h>
38 #include <math.h>
39 #include "defines.h"
40 #include "joystick.h"
41 #include "scene.h"
42 #include "world.h"
43 #include <string>
44 #include <cmath>
45 #include <fstream>
46 #include <iostream>
47 #include <vector>
48 #include <map>
49 
50 #include <dirent.h>
51 
52 using namespace std;
53 
54 namespace Martian {
55 
56 	class Joystick;
57 	class World;
58 	class Scene;
59 
60 	typedef struct
61 	{
62 		float x1, y1, x2, y2;
63 	} Bounds;
64 
65 	typedef struct
66 	{
67 		float x, y;
68 	} Position;
69 
70 	typedef struct
71 	{
72 		int w, h;
73 	} Size;
74 
75 	typedef struct
76 	{
77 		int r, g, b;
78 	} Color;
79 
80 	class Converter {
81 	public :
82 		static Converter * GetInstance ();
83 		int ml2cycles(int ml);
84 		int time2cycle(string time);
85 		vector<string> split(string txt, string chunk);
86 		string join(vector<string> txt, string chunk);
87 		string fillZeros(int i);
88 		~Converter ();
89 	private :
90 		Converter ();
91 		static Converter *instance;
92 
93 	};
94 
95 	class WorkingData {
96 	public :
97 		static WorkingData * GetInstance ();
98 		bool validCharacter(string c);
99 		bool existFile(string file);
100 		bool createFile(string file, string text, bool changeSpecialsCharacters);
101 		void createDirectory(string dir);
102 		void deleteDirectory(string dir);
103 		string replace(string chain, string search, string replace);
104 		string getPath(string file);
105 		string getFilename(string file);
106 		string getExtension(string file);
107 		string getToUpper(string str);
108 		string getToLower(string str);
109 		~WorkingData ();
110 	private :
111 		WorkingData ();
112 		static WorkingData *instance;
113 
114 	};
115 
116 	class WorkingSurfaces {
117 	public :
118 		static WorkingSurfaces * GetInstance ();
119 		SDL_Surface* surfaceFromImage(string path);
120 		SDL_Surface* mixSurfaces(SDL_Surface* back, SDL_Surface* front, Bounds *destiny);
121 		Size getSize(string file);
122 		~WorkingSurfaces ();
123 	private :
124 		WorkingSurfaces ();
125 		static WorkingSurfaces *instance;
126 
127 	};
128 
129 	class Primitives {
130 	public :
131 		static Primitives * GetInstance ();
132 		void put_pixel(SDL_Surface *_ima, int x, int y, Uint32 pixel);
133 		SDL_Surface* rectangle(int w, int h, int r, int g, int b);
134 		SDL_Surface* rectangle ( int w, int h, int r, int g, int b, int border, int rb, int gb, int bb );
border(int w,int h,int r,int g,int b,int thickness)135 		SDL_Surface* border ( int w, int h, int r, int g, int b, int thickness ) { return border ( w, h, r, g, b, thickness, 0, false ); }
border(int w,int h,int r,int g,int b,int thickness,int space)136 		SDL_Surface* border ( int w, int h, int r, int g, int b, int thickness, int space ) { return border ( w, h, r, g, b, thickness, space, false ); }
137 		SDL_Surface* border ( int w, int h, int r, int g, int b, int thickness, int space, bool intercaleSpace );
138 		~Primitives ();
139 	private :
140 		Primitives ();
141 		static Primitives *instance;
142 
143 	};
144 
145 	class VectorColors {
146 	public :
addColor(Color c)147 		void addColor(Color c) { colors.push_back(c); }
addColor(int r,int g,int b)148 		void addColor(int r, int g, int b) { Color c; c.r = r; c.g = g; c.b = b; colors.push_back(c); }
clear()149 		void clear() { colors.clear(); }
count()150 		int count() { return (int)colors.size(); }
151 		int getIndexColor(int r, int g, int b);
152 		Color* getColor(int n);
153 
154 		VectorColors ();
155 		~VectorColors ();
156 	private :
157 		vector<Color> colors;
158 
159 	};
160 
161 	class Frame {
162 
163 	public:
164 
165         Frame ();
166 		~Frame();
167 
168 		int w, h;
169 		int w_gl, h_gl;
170 		GLuint texture;
171 		int sizeTexGL(int w, int h);
172 		SDL_RWops* RWFromRar(char *fileRar, char *file);
173 		void load(char *path);
174 		void load(char *path, SDL_Surface *sc);
175 		void loadSurface (SDL_Surface *surface);
176 		void loadGLSurface (SDL_Surface *surface);
177 		//void loadGLSurfaceWithoutAlpha (SDL_Surface *surface);
178 		void loadSurface (SDL_Surface *surface, SDL_Surface *sc);
179 		void loadGL(char *path);
180 		//void loadGLWithoutAlpha(char *path);
181 		SDL_Surface* SurfaceGL(SDL_Surface* sfc);
182 		void loadGLFromRAR (char *fileRar, char *path);
183 		void unLoad();
184 
185 	};
186 
187 	class Animation {
188 
189 	private:
190 		vector<int> frame;
191 		int currentFrame;
192 		bool stopped;
193 		int avFrame;
194 		int typeRotation;
195 		int cyclesBetweenFrames, cycles;
196 
197 		int nextFrame();
hasFrame()198 		bool hasFrame() { if (currentFrame>=0) { return true; } else { return false; } };
199 
200 	public:
201 		string name;
202 		bool isLastFrame;
203 		Animation ();
204 		~Animation();
205 
lastFrame()206 		int lastFrame() { return (int)frame.size()-1; };
207 
getCycleInFrame()208 		int getCycleInFrame() { return cycles%cyclesBetweenFrames; };
209 
210 		/*********************
211 		* PLAYER
212 		**********************/
playing()213 		bool playing() { return !stopped; };
stop()214 		void stop() { stopped = true; };
play()215 		void play() { stopped = false; };
swapPlayStop()216 		void swapPlayStop() { stopped = !stopped; };
start()217 		void start() { cycles = 0; currentFrame = 0; stopped = false; };
218 		/*********************
219 		* CONTROL FRAMES
220 		**********************/
getIndexFrame()221 		int getIndexFrame() { return currentFrame; };
getCurrentFrame()222 		int getCurrentFrame() { return frame[currentFrame]; };
clearFrames()223 		void clearFrames() { frame.clear(); };
addFrame(int f)224 		void addFrame(int f) { frame.push_back(f); currentFrame = 0; };
225 		void addRangeFrame(int begin, int end, int steps);
setCyclesBetweenFrames(int c)226 		void setCyclesBetweenFrames (int c) { cyclesBetweenFrames = c; }
getCyclesBetweenFrames()227 		int getCyclesBetweenFrames() { return cyclesBetweenFrames; }
228 		int getFrame();
229 		/*********************
230 		* OTHERS
231 		**********************/
232 		//void setName(char *n) { strcpy(name, n); };
setName(string n)233 		void setName(string n) { name = n; };
getName()234 		string getName() { return name; };
setTypeRotation(int r)235 		void setTypeRotation(int r) { typeRotation = r; }
236 
237 	};
238 
239 	class Group;
240 	class GroupScene;
241 
242 	class Element {
243 
244 	protected:
245 		GroupScene *groupScene;
246 		Group *group;
247 
248 		float perspectiveX1;
249 		float perspectiveY1;
250 		float perspectiveX2;
251 		float perspectiveY2;
252 		float perspectiveX3;
253 		float perspectiveY3;
254 		float perspectiveX4;
255 		float perspectiveY4;
256 
257 		Element *elmBorder;
258 		bool hasBorder;
259 		bool showBorderElement;
260 
261 		Element *elmBackground;
262 		bool hasBackground;
263 		bool showBackgroundElement;
264 
265 		float factorMaskW, factorMaskH;
266 
267 		float posX, posY, oldX, oldY;
268 		// flexible
269 		float xs, ys;
270 		// direccion
271 		float dx, dy;
272 		// movimiento
273 		float polarCos, polarSen, polarDistance; // direction polar coord
274 		float polarEndX, polarEndY;
275 		int nCyclesMovementNormal, countCyclesMovementNormal;
276 		int dirX, dirY;
277 		// por posicion
278 		float posXNew, posYNew; // direccion por posicion
279 
280 		int typeMovement;
281 		bool isMovement;
282 
283 		bool flip, flop;
284 
285 		bool visible;
286 
287 		int indexz;
288 		// colorizar con OpenGL
289 		int red, green, blue;
290 
291 		// factors
292 
293 		float flexibleData0, flexibleData1;
294 		int smoothData;
295 
296 		// rotar
297 
298 		float rot;
299 		bool forceRotateCenter;
300 		int typeRotate;
301 		float rotX, rotY, rotZ;
302 		float factorRotate;
303 		float endRotate;
304 		bool canRotate;
305 		float sRotate;
306 
307 		int alpha; // factor alpha aplicado al elemento
308 		int cyclesFadeIn, cyclesFadeInTotal;
309 		int cyclesFadeOut, cyclesFadeOutTotal;
310 		int typeElement;
311 		int align, valign;
312 		int cycle;
313 		int blinking, stateBlinking; // variables de control de parpadeo
314 		bool activeBlinking;
315 		int cyclesBlinking;
316 		//int cortinilla, maxCortinilla;
317 
318 		// scale
319 		bool canScale;
320 		int typeScale;
321 		float factorScaleX, factorScaleY;
322 		float currentScaleX, currentScaleY;
323 		float endScaleX, endScaleY;
324 		float xsScale, ysScale;
325 
326 		int cFrame; // frame actual
327 
328 		bool toDoAllEffects;
329 
330 		map<string, string> parameters;
331 
332 	private:
333 		void addFrame (Frame *frame);
334 		void addFrame (string file);
335 		void changeFrame (int position, Frame *frame);
336 		void changeFrame (int position, string file);
337 
338 	public:
339 		vector<Frame*> sprite;
340 		/*********************
341 		* CONSTRUCTORS
342 		**********************/
343 		Element ();
344 		~Element();
345 
346 		/*********************
347 		* BORDER AND BG
348 		**********************/
349 		void createBorder(int r, int g, int b, int border, int padding);
showBorder()350 		void showBorder() { showBorderElement = true; }
hideBorder()351 		void hideBorder() { showBorderElement = false; }
getElmBorder()352 		Element *getElmBorder() { return elmBorder; }
353 
354 		void createBackground(int r, int g, int b, int padding);
showBackground()355 		void showBackground() { showBackgroundElement = true; }
hideBackground()356 		void hideBackground() { showBackgroundElement = false; }
getElmBackground()357 		Element *getElmBackground() { return elmBackground; }
358 
359 		/*********************
360 		* COLORS
361 		**********************/
setRGB(int r,int g,int b)362 		void setRGB(int r, int g, int b) { red = r; green = g; blue = b; }
getRed()363 		int getRed() { return red; }
getGreen()364 		int getGreen() { return green; }
getBlue()365 		int getBlue() { return blue; }
removeRGB()366 		void removeRGB() { red = 255; green = 255; blue = 255; }
367 
368 		/*********************
369 		* PARAMETERS
370 		**********************/
addParameter(string name,string value)371 		void addParameter(string name, string value) { parameters[name] = value; }
getParameter(string name)372 		string getParameter(string name) { return parameters[name]; }
373 		/*********************
374 		* ROTATE
375 		**********************/
setForceRotateCenter(bool f)376 		void setForceRotateCenter(bool f) { forceRotateCenter = f; }
getForceRotateCenter()377 		bool getForceRotateCenter() { return forceRotateCenter; }
setRot(float r)378 		void setRot(float r) { rot = r; }
setRotX(float r)379 		void setRotX(float r) { rotX = r; }
setRotY(float r)380 		void setRotY(float r) { rotY = r; }
setRotZ(float r)381 		void setRotZ(float r) { rotZ = r; }
addRot(float a)382 		void addRot(float a) { rot += a; }
setRot(float r,float x,float y,float z)383 		void setRot(float r, float x, float y, float z) { rot = r; rotX = x; rotY = y; rotZ = z; }
getRot()384 		float getRot() { return rot; }
385 		// movements
removeRotation()386 		void removeRotation() { canRotate= false; setRot(0); typeRotate = NO_ROTATE; }
387 		void setRotationNormal (float degreesEnd, int ml);
388 		void setRotationNormal (float degreesBegin, float degreesEnd, int ml);
389 		void setRotationSmooth (float degreesEnd);
390 		void setRotationFlexible (float degreesEnd);
391 		/*********************
392 		* FRAMES
393 		**********************/
394 		void addFrameFile (string file);
395 		void addFrameFileFromData (string file);
396 		void addFrameFile (string name, string ext, int valueInRange);
397 		void addFrameFileFromData (string name, string ext, int valueInRange);
398 		void addFrameText (string font, string text, int align);
399 		void addFrameText (string font, string text, int align, int width);
400 		void addFrameLanguage (string font, string key, int align);
401 		void addFrameLanguage (string font, string key, int align, int width);
402 		void addFrameSurface (SDL_Surface *sfc);
403 
404 		void changeFrameFile (int pos, string file);
405 		void changeFrameFileFromData (int pos, string file);
406 		void changeFrameFile (int pos, string name, string ext, int valueInRange);
407 		void changeFrameFileFromData (int pos, string name, string ext, int valueInRange);
408 		void changeFrameText (int pos, string font, string text, int align);
409 		void changeFrameText (int pos, string font, string text, int align, int width);
410 		void changeFrameLanguage (int pos, string font, string key, int align);
411 		void changeFrameLanguage (int pos, string font, string key, int align, int width);
412 		void changeFrameSurface (int pos, SDL_Surface *sfc);
413 
414 		void addRangeFrames (string name, string ext, int valBeg, int valEnd);
415 		void addRangeFramesFromData (string name, string ext, int valBeg, int valEnd);
getFrames()416 		int getFrames () { return (int)sprite.size(); }
setCurrentFrame(int c)417 		void setCurrentFrame(int c) { if (c<(int)sprite.size()) cFrame = c; }
getCurrentFrame()418 		int getCurrentFrame() { return cFrame; }
previousFrame()419 		void previousFrame() { int c = cFrame - 1; if (c>=0) { cFrame = c; } else { cFrame = (int)sprite.size()-1; } }
nextFrame()420 		void nextFrame() { int c = cFrame + 1; if (c<(int)sprite.size()) { cFrame = c; } else { cFrame = 0; } }
firstFrame()421 		void firstFrame() { cFrame = 0; }
lastFrame()422 		void lastFrame() { cFrame = (int)sprite.size()-1; }
423 		/*********************
424 		* EFFECTS
425 		**********************/
setMlBlinking(int ml)426 		void setMlBlinking (int ml) { cyclesBlinking = Converter::GetInstance()->ml2cycles(ml); }
setActiveBlinking(bool b)427 		void setActiveBlinking (bool b) { activeBlinking = b; }
setBlinking(int b)428 		void setBlinking (int b) { blinking = b; }
getBlinking()429 		int getBlinking() { return blinking; }
setFadeIn(int ml,int alphaBegin)430 		void setFadeIn (int ml, int alphaBegin) { cyclesFadeOut = 0; cyclesFadeInTotal = Converter::GetInstance()->ml2cycles(ml); cyclesFadeIn = Converter::GetInstance()->ml2cycles(ml); cyclesFadeOut = 0; alpha = alphaBegin; }
setFadeIn(int ml)431 		void setFadeIn (int ml) { setFadeIn (ml, 0); }
getFadeIn()432 		int getFadeIn() { return cyclesFadeIn; }
setFadeOut(int ml,int alphaEnd)433 		void setFadeOut (int ml, int alphaEnd) { cyclesFadeIn = 0; cyclesFadeOutTotal = Converter::GetInstance()->ml2cycles(ml); cyclesFadeOut = Converter::GetInstance()->ml2cycles(ml); cyclesFadeIn = 0; alpha = alphaEnd; }
setFadeOut(int ml)434 		void setFadeOut (int ml) { setFadeOut (ml, 255); }
getFadeOut()435 		int getFadeOut() { return cyclesFadeOut; }
436 		//void setCortinilla (int c) { maxCortinilla = c; cortinilla = c; }
437 		//int getCortinilla() { return cortinilla; }
setAlpha(int a)438 		void setAlpha (int a) { alpha = a; };
addAlpha(int a)439 		void addAlpha (int a) { alpha+=a; };
removeAlpha()440 		void removeAlpha () { alpha = 255; };
getAlpha()441 		int getAlpha () { return alpha; };
442 		/*********************
443 		* LIMITS
444 		**********************/
445 		// l�mites del elemento en la pantalla
446 		// se utilizan para saber cuando un elemento tiene que ser descargado al salir de la pantalla
getLimitTop()447 		int getLimitTop () { return (-getHeight() * 2) -5; }
448 		int getLimitBottom ();
449 		int getLimitRight ();
getLimitLeft()450 		int getLimitLeft () { return -getWidth() * 2 -5; }
451 		bool outLimitScreen ();
452 		/*********************
453 		* ALIGN
454 		**********************/
setAlign(int a)455 		void setAlign (int a) { align = a; }
setVAlign(int a)456 		void setVAlign (int a) { valign = a; }
getAlign()457 		int getAlign () { return align; }
getVAlign()458 		int getVAlign () { return valign; }
459 		/*********************
460 		* SCALE
461 		**********************/
setCurrentScale(float s)462 		void setCurrentScale (float s) { currentScaleX = s; currentScaleY = s; };
setCurrentScaleX(float s)463 		void setCurrentScaleX (float s) { currentScaleX = s; };
getCurrentScaleX()464 		float getCurrentScaleX () { return currentScaleX; };
setCurrentScaleY(float s)465 		void setCurrentScaleY (float s) { currentScaleY = s; };
getCurrentScaleY()466 		float getCurrentScaleY () { return currentScaleY; };
addCurrentScale(float s)467 		void addCurrentScale (float s) { currentScaleX += s; currentScaleY += s; };
addCurrentScaleX(float s)468 		void addCurrentScaleX (float s) { currentScaleX += s; };
addCurrentScaleY(float s)469 		void addCurrentScaleY (float s) { currentScaleY += s; };
470 
471 		void setScale (float w, float h);
setScaleW(float w)472 		void setScaleW (float w) { float h = getHeightOriginal()*w/getWidthOriginal(); setScale(w, h); }
setScaleH(float h)473 		void setScaleH (float h) { float w = getWidthOriginal()*h/getHeightOriginal(); setScale(w, h); }
474 
475 		// movements
removeScale()476 		void removeScale() { canScale = false; setCurrentScale(1); typeScale = NO_SCALE; }
setScaleGL(float s,int mlRoute)477 		void setScaleGL (float s, int mlRoute) { setScale(getWidthOriginal()*s, getHeightOriginal()*s, mlRoute); }
478 		void setScale (float w, float h, int mlRoute);
setScaleW(float w,int mlRoute)479 		void setScaleW (float w, int mlRoute) { float h = getHeightOriginal()*w/getWidthOriginal(); setScale(w, h, mlRoute); }
setScaleH(float h,int mlRoute)480 		void setScaleH (float h, int mlRoute) { float w = getWidthOriginal()*h/getHeightOriginal(); setScale(w, h, mlRoute); }
481 		void setScaleSmooth (float w, float h);
setScaleSmoothW(float w)482 		void setScaleSmoothW (float w) { float h = getHeightOriginal()*w/getWidthOriginal(); setScaleSmooth(w, h); }
setScaleSmoothH(float h)483 		void setScaleSmoothH (float h) { float w = getWidthOriginal()*h/getHeightOriginal(); setScaleSmooth(w, h); }
484 		void setScaleFlexible (float w, float h);
setScaleFlexibleW(float w)485 		void setScaleFlexibleW (float w) { float h = getHeightOriginal()*w/getWidthOriginal(); setScaleFlexible(w, h); }
setScaleFlexibleH(float h)486 		void setScaleFlexibleH (float h) { float w = getWidthOriginal()*h/getHeightOriginal(); setScaleFlexible(w, h); }
487 		/*********************
488 		* MOVEMENTS
489 		**********************/
getIsMovement()490 		bool getIsMovement() { return isMovement; }
removeTypeMovement()491 		void removeTypeMovement () { typeMovement = NO_MOVEMENT; }
setTypeMovement(int c)492 		void setTypeMovement (int c) { typeMovement = c; }
getTypeMovement()493 		int getTypeMovement () { return typeMovement; }
setDPolarCos(float c)494 		void setDPolarCos (float c) { polarCos = c; }
setDPolarSen(float s)495 		void setDPolarSen (float s) { polarSen = s; }
setDPolarDistance(float d)496 		void setDPolarDistance (float d) { polarDistance = d; }
getDPolarCos()497 		float getDPolarCos () { return polarCos; }
getDPolarSen()498 		float getDPolarSen () { return polarSen; }
getDPolarDistance()499 		float getDPolarDistance () { return polarDistance; }
getCountCyclesMovementNormal()500 		float getCountCyclesMovementNormal () { return countCyclesMovementNormal; }
getNCyclesMovementNormal()501 		float getNCyclesMovementNormal () { return nCyclesMovementNormal; }
502 		// normal
503 		void setMovementNormal (float x, float y, int ml);
setMovementNormalX(float x,int ml)504 		void setMovementNormalX (float x, int ml) { setMovementNormal(x, getYWithoutDisplacementByGroups(), ml); }
setMovementNormalY(float y,int ml)505 		void setMovementNormalY (float y, int ml) { setMovementNormal(getXWithoutDisplacementByGroups(), y, ml); }
506 		// smooth
setMovementSmooth(float x,float y)507 		void setMovementSmooth (float x, float y) { posXNew = x; posYNew = y; typeMovement = MOVEMENT_SMOOTH; }
setMovementSmoothX(float x)508 		void setMovementSmoothX (float x) { setMovementSmooth(x, getYWithoutDisplacementByGroups()); }
setMovementSmoothY(float y)509 		void setMovementSmoothY (float y) { setMovementSmooth(getXWithoutDisplacementByGroups(), y); }
510 		// flexible
setMovementFlexible(float x,float y)511 		void setMovementFlexible (float x, float y) { xs= 0.0f; ys= 0.0f; posXNew = x; posYNew = y; typeMovement = MOVEMENT_FLEXIBLE; }
setMovementFlexibleX(float x)512 		void setMovementFlexibleX (float x) { setMovementFlexible(x, getYWithoutDisplacementByGroups()); }
setMovementFlexibleY(float y)513 		void setMovementFlexibleY (float y) { setMovementFlexible(getXWithoutDisplacementByGroups(), y); }
514 		// desplazamiento
setDX(int x)515 		void setDX (int x) { dx = x; }
setDY(int y)516 		void setDY (int y) { dy = y; }
getDX()517 		float getDX () { return dx; }
getDY()518 		float getDY () { return dy; }
519 
addDX()520 		void addDX () { posX += dx; }
addDY()521 		void addDY () { posY += dy; }
522 		/*********************
523 		* POSITION
524 		**********************/
525 		Bounds getBounds();
526 		Position getCenterPosition();
setX(float x)527 		void setX (float x) { oldX = posX; posX = x; }
setY(float y)528 		void setY (float y) { oldY = posY; posY = y; }
setXY(float x,float y)529 		void setXY (float x, float y) { setX(x); setY(y); }
addX(float x)530 		void addX (float x) { oldX = posX; posX += x; }
addY(float y)531 		void addY (float y) { oldY = posY; posY += y; }
addXY(float x,float y)532 		void addXY (float x, float y) { addX(x); addY(y); }
getOldX()533 		float getOldX () { return oldX; }
getOldY()534 		float getOldY () { return oldY; }
535 		float getDisplacementInXByGroups ();
536 		float getDisplacementInYByGroups ();
getXWithoutDisplacementByGroups()537 		float getXWithoutDisplacementByGroups () { return posX; }
getYWithoutDisplacementByGroups()538 		float getYWithoutDisplacementByGroups () { return posY; }
539 		float getX ();
540 		float getY ();
541 		float getValueXPlusGroups (float x);
542 		float getValueYPlusGroups (float y);
setTypeElement(int te)543 		void setTypeElement (int te) { typeElement= te; }
getTypeElement()544 		int getTypeElement () { return typeElement; }
545 		void move ();
546 		void transforms ();
547 		/*********************
548 		* ATRIBUTTES
549 		**********************/
550 		void setPerspective(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
551 		void setPerspectiveRelative(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
552 		void setVelocitySmooth (int t);
553 		void setVelocityFlexible (int t);
getWidth()554 		int getWidth () { return sprite[getCurrentFrame()]->w * currentScaleX; }
getHeight()555 		int getHeight () { return sprite[getCurrentFrame()]->h * currentScaleY; }
getWidthOriginal()556 		int getWidthOriginal () { return sprite[getCurrentFrame()]->w; }
getHeightOriginal()557 		int getHeightOriginal () { return sprite[getCurrentFrame()]->h; }
show()558 		void show () { visible = true; }
hide()559 		void hide () { visible = false; }
isVisible()560 		bool isVisible () { return visible; }
setFlip(bool f)561 		void setFlip (bool f) { flip = f; }
getFlip()562 		bool getFlip () { return flip; }
swapFlip()563 		void swapFlip () { flip = !flip; }
setFlop(bool f)564 		void setFlop (bool f) { flop = f; }
getFlop()565 		bool getFlop () { return flop; }
swapFlop()566 		void swapFlop () { flop = !flop; }
setToDoAllEffects(bool e)567 		void setToDoAllEffects (bool e) { toDoAllEffects = e; }
getToDoAllEffects()568 		bool getToDoAllEffects () { return toDoAllEffects; }
setGroup(Group * g)569 		void setGroup(Group *g) { group = g; }
removeGroup()570 		void removeGroup() { group = NULL; }
getGroup()571 		Group* getGroup() { return group; }
setGroupScene(GroupScene * g)572 		void setGroupScene(GroupScene *g) { groupScene = g; }
removeGroupScene()573 		void removeGroupScene() { groupScene = NULL; }
getGroupScene()574 		GroupScene* getGroupScene() { return groupScene; }
575 		/*********************
576 		* SURFACES
577 		**********************/
setIndexZ(int z)578 		void setIndexZ (int z) { indexz = z; }
getIndexZ()579 		int getIndexZ () { return indexz; }
580 		void draw();
581 		void paintSprite();
582 		void unLoad ();
583 	};
584 
585 	class GroupScene;
586 
587 	class Group {
588 
589 	protected:
590 		vector<Element*> elements;
591 		vector<Group*> groups;
592 		float posX, posY;
593 		float oldX, oldY;
594 		GroupScene *groupScene;
595 		Group *group;
596 
597 		int cycle;
598 
599 		// flexible
600 		float xs, ys;
601 		// direccion
602 		float dx, dy;
603 		// movimiento
604 		float polarCos, polarSen, polarDistance; // direction polar coord
605 		float polarEndX, polarEndY;
606 		int nCyclesMovementNormal, countCyclesMovementNormal;
607 		int dirX, dirY;
608 		// por posicion
609 		float posXNew, posYNew; // direccion por posicion
610 
611 		int typeMovement;
612 		bool isMovement;
613 
614 		int alpha; // factor alpha aplicado al elemento
615 		int cyclesFadeIn, cyclesFadeInTotal;
616 		int cyclesFadeOut, cyclesFadeOutTotal;
617 
618 		int blinking, stateBlinking; // variables de control de parpadeo
619 		int cyclesBlinking;
620 
621 		// factors
622 
623 		float flexibleData0, flexibleData1;
624 		int smoothData;
625 
626 	public:
627 		Group ();
addElement(Element * el)628 		void addElement(Element *el) { elements.push_back(el); el->setGroup(this); }
addGroup(Group * gr)629 		void addGroup(Group *gr) { groups.push_back(gr); gr->setGroup(this); }
630 		void setCurrentScale(float s);
631 
setX(float x)632 		void setX(float x) { oldX = posX; posX = x; }
setY(float y)633 		void setY(float y) { oldY = posY; posY = y; }
setXY(float x,float y)634 		void setXY(float x, float y) { setX(x); setY(y); }
addX(float x)635 		void addX(float x) { oldX = posX; posX += x; }
addY(float y)636 		void addY(float y) { oldY = posY; posY += y; }
addXY(float x,float y)637 		void addXY(float x, float y) { addX(x); addY(y); }
638 		float getX();
639 		float getY();
getXWithoutDisplacementByGroups()640 		float getXWithoutDisplacementByGroups () { return posX; }
getYWithoutDisplacementByGroups()641 		float getYWithoutDisplacementByGroups () { return posY; }
642 
setGroup(Group * g)643 		void setGroup(Group *g) { group = g; }
removeGroup()644 		void removeGroup() { group = NULL; }
getGroup()645 		Group* getGroup() { return group; }
setGroupScene(GroupScene * g)646 		void setGroupScene(GroupScene *g) { groupScene = g; }
removeGroupScene()647 		void removeGroupScene() { groupScene = NULL; }
getGroupScene()648 		GroupScene* getGroupScene() { return groupScene; }
649 
650 		/*********************
651 		* EFFECTS
652 		**********************/
setMlBlinking(int ml)653 		void setMlBlinking (int ml) { cyclesBlinking = Converter::GetInstance()->ml2cycles(ml); }
setBlinking(int b)654 		void setBlinking (int b) { blinking = b; }
getBlinking()655 		int getBlinking() { return blinking; }
setFadeIn(int ml)656 		void setFadeIn (int ml) { cyclesFadeInTotal = Converter::GetInstance()->ml2cycles(ml); cyclesFadeIn = Converter::GetInstance()->ml2cycles(ml); cyclesFadeOut = 0; alpha = 0; }
getFadeIn()657 		int getFadeIn() { return cyclesFadeIn; }
setFadeOut(int ml)658 		void setFadeOut (int ml) { cyclesFadeOutTotal = Converter::GetInstance()->ml2cycles(ml); cyclesFadeOut = Converter::GetInstance()->ml2cycles(ml); cyclesFadeIn = 0; alpha = 255; }
getFadeOut()659 		int getFadeOut() { return cyclesFadeOut; }
setAlpha(int a)660 		void setAlpha (int a) { alpha = a; todoAlpha (); };
addAlpha(int a)661 		void addAlpha (int a) { alpha+=a; todoAlpha (); };
removeAlpha()662 		void removeAlpha () { alpha = 255; todoAlpha (); };
663 		void todoAlpha ();
getAlpha()664 		int getAlpha () { return alpha; };
665 
666 		/*********************
667 		* MOVEMENTS
668 		**********************/
getIsMovement()669 		bool getIsMovement() { return isMovement; }
removeTypeMovement()670 		void removeTypeMovement () { typeMovement = NO_MOVEMENT; }
setTypeMovement(int c)671 		void setTypeMovement (int c) { typeMovement = c; }
getTypeMovement()672 		int getTypeMovement () { return typeMovement; }
setDPolarCos(float c)673 		void setDPolarCos (float c) { polarCos = c; }
setDPolarSen(float s)674 		void setDPolarSen (float s) { polarSen = s; }
setDPolarDistance(float d)675 		void setDPolarDistance (float d) { polarDistance = d; }
getDPolarCos()676 		float getDPolarCos () { return polarCos; }
getDPolarSen()677 		float getDPolarSen () { return polarSen; }
getDPolarDistance()678 		float getDPolarDistance () { return polarDistance; }
getCountCyclesMovementNormal()679 		float getCountCyclesMovementNormal () { return countCyclesMovementNormal; }
getNCyclesMovementNormal()680 		float getNCyclesMovementNormal () { return nCyclesMovementNormal; }
681 		// normal
682 		void setMovementNormal (float x, float y, int ml);
setMovementNormalX(float x,int ml)683 		void setMovementNormalX (float x, int ml) { setMovementNormal(x, posY, ml); }
setMovementNormalY(float y,int ml)684 		void setMovementNormalY (float y, int ml) { setMovementNormal(posX, y, ml); }
685 		// smooth
setMovementSmooth(float x,float y)686 		void setMovementSmooth (float x, float y) { posXNew = x; posYNew = y; typeMovement = MOVEMENT_SMOOTH; }
setMovementSmoothX(float x)687 		void setMovementSmoothX (float x) { setMovementSmooth(x, posY); }
setMovementSmoothY(float y)688 		void setMovementSmoothY (float y) { setMovementSmooth(posX, y); }
689 		// flexible
setMovementFlexible(float x,float y)690 		void setMovementFlexible (float x, float y) { xs= 0.0f; ys= 0.0f; posXNew = x; posYNew = y; typeMovement = MOVEMENT_FLEXIBLE; }
setMovementFlexibleX(float x)691 		void setMovementFlexibleX (float x) { setMovementFlexible(x, posY); }
setMovementFlexibleY(float y)692 		void setMovementFlexibleY (float y) { setMovementFlexible(posX, y); }
693 		// desplazamiento
setDX(int x)694 		void setDX (int x) { dx = x; }
setDY(int y)695 		void setDY (int y) { dy = y; }
getDX()696 		float getDX () { return dx; }
getDY()697 		float getDY () { return dy; }
698 
addDX()699 		void addDX () { posX += dx; }
addDY()700 		void addDY () { posY += dy; }
701 
702 		void setVelocitySmooth (int t);
703 		void setVelocityFlexible (int t);
704 
705 		void move();
706 		void work();
707 		void draw();
708 		void unLoad();
709 
710 	};
711 
712 	class GroupScene : public Group {
713 
714 	public:
715 		GroupScene ();
addElement(Element * el)716 		void addElement(Element *el) { elements.push_back(el); el->setGroupScene(this); }
addGroup(Group * gr)717 		void addGroup(Group *gr) { groups.push_back(gr); gr->setGroupScene(this); }
718 	};
719 
720 	typedef struct
721 	{
722 		int numberOfTimes;
723 		int animation;
724 	} NextAnimation;
725 
726 	class AnimatedElement : public Element {
727 
728 	private:
729 		vector<Animation> animations;
730 		int currentAnimation, defaultAnimation;
731 		vector<NextAnimation> nextsAnimations;
732 		int numberOfTimes;
733 		int countNumberOfTimes;
734 
735 	public:
736 		AnimatedElement ();
737 		~AnimatedElement();
738 
739 		int getCurrentFrame();
740 		int getNextFrame();
741 		/*********************
742 		* ANIMACION
743 		**********************/
744 		void addAnimation (Animation a);
745 		void removeAnimation (string name);
setAnimation(string name)746 		bool setAnimation (string name) { return setAnimation (name, -1); }
747 		bool setAnimation (string name, int nt);
setForceAnimation(string name)748 		bool setForceAnimation (string name) { return setForceAnimation (name, -1); }
749 		bool setForceAnimation (string name, int nt);
750 		bool setDefaultAnimation (string name);
751 		Animation* getAnimation ();
752 		Animation* getAnimation (string name);
753 		bool existAnimation (string name);
754 
stop()755 		void stop() { getAnimation ()->stop(); }
play()756 		void play() { getAnimation ()->play(); }
swapPlayStop()757 		void swapPlayStop() { getAnimation ()->swapPlayStop(); }
start()758 		void start() { getAnimation ()->start(); }
759 
760 		void draw();
761 
762 		void unLoad ();
763 	};
764 
765 	class MarqueeElement : public AnimatedElement {
766 
767 	private:
768         string text;
769         int nLetters;
770 
771 	public:
772 		MarqueeElement ();
773 		~MarqueeElement();
774 
775 		void setText(string font, string t, int nl);
776 
777 	};
778 
779 	class Element_AnimatedGroup : public Element {
780 
781 	private:
782 		float offsetX, offsetY;
783 
784 	public:
785 		Element_AnimatedGroup ();
786 		~Element_AnimatedGroup ();
setOffSetX(float x)787 		void setOffSetX(float x) { offsetX = x; addX(x); }
setOffSetY(float y)788 		void setOffSetY(float y) { offsetY = y; addY(y); }
setOffSetX()789 		void setOffSetX() { addX(offsetX); }
setOffSetY()790 		void setOffSetY() { addY(offsetY); }
getOffSetX()791 		float getOffSetX() { return offsetX; }
getOffSetY()792 		float getOffSetY() { return offsetY; }
793 
794 	};
795 
796 	class AnimatedGroup {
797 
798 	private:
799 		int cols;
800 		int rows;
801 		int width;
802 		int height;
803 		int indexz;
804 		int cycles;
805 
806 		vector<Element_AnimatedGroup*> elements;
807 		float posX, posY;
808 
809 		bool reverse;
810 
811 		bool isMovementNormal;
812 		bool isMovementSmooth;
813 		bool isMovementFlexible;
814 
815 		float xMovement, yMovement;
816 		int mlMovement;
817 
818 		int cyclesChangeElement;
819 		int currentElement;
820 
821 	public:
822 		AnimatedGroup ();
823 		~AnimatedGroup ();
setGrid(int c,int r)824 		void setGrid (int c, int r) { cols = c; rows = r; }
825 		void organizeElements();
826 		void addElement(Element_AnimatedGroup *el);
827 		void setX(float x);
828 		void setY(float y);
829 		float getX();
830 		float getY();
831 
832 		void setVelocitySmooth (int t);
833 		void setVelocityFlexible (int t);
834 
setReverse(bool r)835 	    void setReverse(bool r) { reverse = r; }
getReverse()836 	    bool getReverse() { return reverse; }
837 
838 		//void setSize();
getWidth()839 		int getWidth () { return width; }
getHeight()840 		int getHeight () { return height; }
841 
setIndexZ(int z)842 		void setIndexZ (int z) { indexz = z; }
getIndexZ()843 		int getIndexZ () { return indexz; }
844 		void setText(string text, string font);
845 
846 		void paintSprites();
847 		void draw();
848 
849 		// normal
850 		void setMovementNormal(float x, float y, int ml, int waitMl);
setMovementNormalX(float x,int ml,int waitMl)851 		void setMovementNormalX(float x, int ml, int waitMl) { setMovementNormal(x, posY, ml, waitMl); }
setMovementNormalY(float y,int ml,int waitMl)852 		void setMovementNormalY(float y, int ml, int waitMl) { setMovementNormal(posX, y, ml, waitMl); }
853 
854 		// smooth
855 		void setMovementSmooth (float x, float y, int waitMl);
setMovementSmoothX(float x,int waitMl)856 		void setMovementSmoothX (float x, int waitMl) { setMovementSmooth(x, posY, waitMl); }
setMovementSmoothY(float y,int waitMl)857 		void setMovementSmoothY (float y, int waitMl) { setMovementSmooth(posX, y, waitMl); }
858 		// flexible
859 		void setMovementFlexible (float x, float y, int waitMl);
setMovementFlexibleX(float x,int waitMl)860 		void setMovementFlexibleX (float x, int waitMl) { setMovementFlexible(x, posY, waitMl); }
setMovementFlexibleY(float y,int waitMl)861 		void setMovementFlexibleY (float y, int waitMl) { setMovementFlexible(posX, y, waitMl); }
862 
863 		void unLoad();
864 	};
865 
866 	class Button;
867 
868 
869     class CoverFlow : public Group {
870 
871     private:
872 
873     	vector<Element*> data;
874     	int indexz;
875 
876     	Button *bLeft, *bRight;
877 		int index;
878     	int beginItem;
879     	int itemFadeOut;
880     	int itemSeparate;
881 
882 		int width;
883 		int widthItem;
884 
885     	int separateGrid;
886     	int itemsVisible;
887     	int timeChangeItem;
888     	int cursor;
889 
890     	bool drawButtons;
891 
892    	public:
893         CoverFlow ();
894 		~CoverFlow ();
895 
setIndexZ(int z)896 		void setIndexZ (int z) { indexz = z; }
getIndexZ()897 		int getIndexZ () { return indexz; }
898 
899         //void add(Element* e) { e->addX((((int)data.size())*separateGrid)+(width/2)-(widthItem/2)); this->addElement(e); data.push_back(e); verifySensitiveButtons(); }
add(Element * e)900 		void add(Element* e) { e->setAlign(ALIGN_CENTER); e->setVAlign(VALIGN_CENTER); this->addElement(e); data.push_back(e); verifySensitiveButtons(); }
901 
902 		//void startPosition();
903 
MoveFirst()904 		void MoveFirst() { cursor = 0; }
MoveLast()905     	void MoveLast() { cursor = (int)data.size()-1; }
MovePrevious()906     	void MovePrevious() { cursor--; }
MoveNext()907     	void MoveNext() { cursor++; }
isBOF()908     	bool isBOF() { return (cursor<0)?true:false; }
isEOF()909     	bool isEOF() { return (cursor>((int)data.size()-1))?true:false; }
getData()910     	Element* getData() { return data[cursor]; }
getData(int i)911     	Element* getData(int i) { return data[i]; }
getDataIndex()912     	Element* getDataIndex() { return data[index]; }
isVisible()913         bool isVisible() { if ( (cursor>=firtsItem()) && (cursor<lastItem()) ) { return true; } else { return false; } }
isVisible(int i)914         bool isVisible(int i) { if ( (i>=firtsItem()) && (i<lastItem()) ) { return true; } else { return false; } }
getNItems()915         int getNItems() { return (int)data.size(); }
916 
917 	    void inicialize();
918 
firtsItem()919 	    int firtsItem() { return beginItem; }
920 	    int lastItem();
921 
922         void startPosition();
923 
924 		void setIndex(int i);
getIndex()925         int getIndex() { return index; }
926 
setWidth(int w)927         void setWidth(int w) { width = w; }
getWidth()928         int getWidth() { return width; }
929 
setWidthItem(int w)930 		void setWidthItem(int w) { widthItem = w; }
getWidthItem()931         int getWidthItem() { return widthItem; }
932 
setSeparateGrid(int s)933         void setSeparateGrid(int s) { separateGrid = s; }
getSeparateGrid()934         int getSeparateGrid() { return separateGrid; }
935 
setTimeChangeItem(int t)936         void setTimeChangeItem(int t) { timeChangeItem = t; }
getTimeChangeItem()937         int getTimeChangeItem() { return timeChangeItem; }
938 
setItemsVisible(int i)939         void setItemsVisible(int i) { itemsVisible = i; }
getItemsVisible()940         int getItemsVisible() { return itemsVisible; }
941 
942         void setButtons(Button *buttom_up, Button *buttom_down, int separateX, int separateY);
943 
previousIndex()944     	void previousIndex() { if (index>0) setIndex(index-1); }
nextIndex()945     	void nextIndex() { if (index<(int)data.size()-1) setIndex(index+1); }
946 
947     	void verifySensitiveButtons();
948     	void verifyClickButtons();
949     	void onOver();
950 
951     	void draw();
952 
953     	void unLoad();
954 
955     };
956 
957     class ListImage : public Group {
958 
959     private:
960 
961     	vector<Button*> data;
962 		int indexz;
963 		int cursor;
964 
965 		int rows, cols;
966 
967 		int rowBeginObjects;
968 
969     	Button *bUp, *bDown;
970 
971 		Element *boxImage;
972 		bool drawBoxImage;
973 
974     	int separateGrid;
975 
976     	bool drawButtons;
977 
978     	int currentCategory;
979     	vector<string> categories;
980 
981    	public:
982         ListImage (int r, int c);
983 		~ListImage ();
984 
setIndexZ(int z)985 		void setIndexZ (int z) { indexz = z; }
getIndexZ()986 		int getIndexZ () { return indexz; }
987 
988 		void setBoxImage (Element *box);
989 
990 		int nTotalRowObjects();
991 
addCategory(string c)992         void addCategory(string c) { categories.push_back(c); }
993 
994         void setCategory(string c);
995 
996         void orderElements();
997 
998         void add(Button* b);
999 
1000 		void verifyObjectsToShow();
1001 
MoveFirst()1002     	void MoveFirst() { cursor = 0; }
MoveLast()1003     	void MoveLast() { cursor = (int)data.size()-1; }
MovePrevious()1004     	void MovePrevious() { cursor--; }
MoveNext()1005     	void MoveNext() { cursor++; }
isBOF()1006     	bool isBOF() { return (cursor<0)?true:false; }
isEOF()1007     	bool isEOF() { return (cursor>((int)data.size()-1))?true:false; }
getData()1008     	Button* getData() { return data[cursor]; }
getData(int i)1009     	Button* getData(int i) { return data[i]; }
1010         //bool isVisible() { if ( (cursor>=firtsItem()) && (cursor<lastItem()) ) { return true; } else { return false; } }
1011         //bool isVisible(int i) { if ( (i>=firtsItem()) && (i<lastItem()) ) { return true; } else { return false; } }
1012 
1013 	    void inicialize();
1014 
1015 	    //int firtsItem() { return beginItem; }
1016 	    //int lastItem() { if (beginItem+itemsVisible<(int)data.size()) { return beginItem+itemsVisible; } else { return (int)data.size(); } }
1017 
setSeparateGrid(int s)1018         void setSeparateGrid(int s) { separateGrid = s; }
getSeparateGrid()1019         int getSeparateGrid() { return separateGrid; }
1020 
1021         void setButtons(Button *buttom_up, Button *buttom_down, int xSeparate, int ySeparate);
1022 
1023     	void downItems();
1024     	void upItems();
1025 
1026     	void verifyClickButtons();
1027     	void onOver();
1028 
1029     	void draw();
1030 
1031 		void clear();
1032     	void unLoad();
1033 
1034     };
1035 
1036     class ListView : public Group {
1037 
1038     private:
1039 
1040     	vector<Group*> data;
1041 		int indexz;
1042 
1043 		bool todoMovement; // In first and last element
1044 
1045     	Button *bUp, *bDown;
1046     	int beginItem;
1047     	int itemFadeOut;
1048     	int itemSeparate;
1049 
1050     	int separateGrid;
1051     	int itemsVisible;
1052     	int timeChangeItem;
1053     	int cursor;
1054 
1055     	bool drawButtons;
1056 
1057    	public:
1058         ListView ();
1059 		~ListView ();
1060 
setIndexZ(int z)1061 		void setIndexZ (int z) { indexz = z; }
getIndexZ()1062 		int getIndexZ () { return indexz; }
1063 
1064 		void setBeginItem (int b);
getBeginItem()1065 		int getBeginItem () { return beginItem; }
1066 
add(Group * g)1067         void add(Group* g) { g->addY(((int)data.size())*separateGrid); this->addGroup(g); data.push_back(g); verifySensitiveButtons(); }
1068 
setTodoMovement(bool m)1069 		void setTodoMovement(bool m) { todoMovement = m; }
1070 
MoveFirst()1071     	void MoveFirst() { cursor = 0; }
MoveLast()1072     	void MoveLast() { cursor = (int)data.size()-1; }
MovePrevious()1073     	void MovePrevious() { cursor--; }
MoveNext()1074     	void MoveNext() { cursor++; }
isBOF()1075     	bool isBOF() { return (cursor<0)?true:false; }
isEOF()1076     	bool isEOF() { return (cursor>((int)data.size()-1))?true:false; }
getData()1077     	Group* getData() { return data[cursor]; }
getData(int i)1078     	Group* getData(int i) { return data[i]; }
isVisible()1079         bool isVisible() { if ( (cursor>=firtsItem()) && (cursor<lastItem()) ) { return true; } else { return false; } }
isVisible(int i)1080         bool isVisible(int i) { if ( (i>=firtsItem()) && (i<lastItem()) ) { return true; } else { return false; } }
1081 
getNItems()1082 		int getNItems() { return (int)data.size(); }
1083 
1084 	    void inicialize();
1085 
firtsItem()1086 	    int firtsItem() { return beginItem; }
lastItem()1087 	    int lastItem() { if (beginItem+itemsVisible<(int)data.size()) { return beginItem+itemsVisible; } else { return (int)data.size(); } }
1088 
setSeparateGrid(int s)1089         void setSeparateGrid(int s) { separateGrid = s; }
getSeparateGrid()1090         int getSeparateGrid() { return separateGrid; }
1091 
setTimeChangeItem(int t)1092         void setTimeChangeItem(int t) { timeChangeItem = t; }
getTimeChangeItem()1093         int getTimeChangeItem() { return timeChangeItem; }
1094 
setItemsVisible(int i)1095         void setItemsVisible(int i) { itemsVisible = i; }
getItemsVisible()1096         int getItemsVisible() { return itemsVisible; }
1097 
1098         void setButtons(Button *buttom_up, Button *buttom_down, int xSeparate);
1099 
1100     	void downItems();
1101     	void upItems();
1102 
1103     	void verifySensitiveButtons();
1104     	void verifyClickButtons();
1105     	void onOver();
1106 
1107     	void draw();
1108 
1109     	void unLoad();
1110 
1111     };
1112 
1113 	class Slide : public Element {
1114 
1115 	private:
1116 		int nextFrame;
1117 		int degrees;
1118 		int degreesByFrame;
1119 		int degreesToDoChange;
1120 		bool changingFrame;
1121 		int cyclesNextFrame;
1122 		int typeSlide;
1123 		int mlFade;
1124 
1125 		bool stopped;
1126 
1127 	public:
1128 		Slide ();
1129 		~Slide ();
1130 		void setCurrentFrame(int c);
setPreviousFrame()1131 		void setPreviousFrame() { if (getCurrentFrame() > 0) { setCurrentFrame(getCurrentFrame()-1); } else { setCurrentFrame(getFrames()-1); } }
setNextFrame()1132 		void setNextFrame() { if (getCurrentFrame() < getFrames()-1) { setCurrentFrame(getCurrentFrame()+1); } else { setCurrentFrame(0); } }
1133 
setDegreesByFrame(int d)1134 		void setDegreesByFrame(int d) { degreesByFrame = d; }
getDegreesByFrame()1135 		int getDegreesByFrame() { return degreesByFrame; }
1136 
setDegreesToDoChange(int d)1137 		void setDegreesToDoChange(int d) { degreesToDoChange = d; }
getDegreesToDoChange()1138 		int getDegreesToDoChange() { return degreesToDoChange; }
1139 
setTypeSlide(int t)1140 		void setTypeSlide(int t) { typeSlide = t; }
getTypeSlide()1141 		int getTypeSlide() { return typeSlide; }
1142 
stop()1143 		void stop() { stopped = true; }
play()1144 		void play() { stopped = false; }
playing()1145 		bool playing() { return stopped; }
1146 
setMlFade(int t)1147 		void setMlFade(int t) { mlFade = t; }
getMlFade()1148 		int getMlFade() { return mlFade; }
1149 
setTimeNextFrame(int ml)1150 		void setTimeNextFrame(int ml) { cyclesNextFrame = Converter::GetInstance()->ml2cycles(ml); }
1151 
1152 		void draw();
1153 	};
1154 
1155 	class ChronometerElement : public Group {
1156 
1157     private:
1158     	bool stopped;
1159 
1160     	vector<Group*> data;
1161 		int indexz;
1162 
1163 		string font;
1164 		string name;
1165 
1166 		Slide *minute0, *minute1, *second0, *second1;
1167 		Element *points;
1168 
1169 		int pastSeconds;
1170 
1171    	public:
1172         ChronometerElement (string n, string f);
1173 		~ChronometerElement ();
1174 
setSeconds(int s)1175 		void setSeconds(int s) { pastSeconds = s; setTime(); }
addSecond()1176 		void addSecond() { pastSeconds++; setTime(); }
1177 		void setTime();
getSeconds()1178 		int getSeconds() { return pastSeconds; }
1179 
stop()1180 		void stop() { stopped = true; }
play()1181 		void play() { stopped = false; }
reset()1182 		void reset() { pastSeconds = 0; setTime(); }
1183 
setIndexZ(int z)1184 		void setIndexZ (int z) { indexz = z; }
getIndexZ()1185 		int getIndexZ () { return indexz; }
1186 
1187 		void draw();
1188 		void unLoad();
1189 
1190 	};
1191 
1192 	class ElementDnD : public Element {
1193 
1194 	protected:
1195 		bool toDoDnd;
1196 		bool isDnd;
1197 		bool isRollOver;
1198 		int mouseX, mouseY;
1199 
1200 	public:
1201 		ElementDnD ();
1202 		~ElementDnD ();
setToDoDnd(bool b)1203 		void setToDoDnd (bool b) { toDoDnd = b; }
getToDoDnd()1204 		bool getToDoDnd () { return toDoDnd; }
1205 		void startDrag ();
1206 		void drop ();
1207 
1208 		bool isOnMouseOver();
1209 		void onOver();
1210 
1211 	};
1212 
1213 	class ProgressBar {
1214 	private:
1215 		int status, total, width, height;
1216 		int posBarX, posBarY;
1217 		Element *bar, *bg, *txt, *bg_bar;
1218 		string text;
1219 
1220 	public:
1221 		ProgressBar (int tc, int w, int h, int r, int g, int b);
1222 		~ProgressBar ();
1223 
1224 		void setText (string font, string t);
1225 		void setBg (string file);
1226 		void setBgBar (string file);
setTotal(int t)1227 		void setTotal (int t) { status = 0; total = t; }
getTotal()1228 		int getTotal() { return total; }
addStatus()1229 		void addStatus() { status++; }
1230 		void draw ();
1231 		void setPositionBar(int posX, int posY);
1232 		void unLoad();
1233 	};
1234 
1235 	/*****************************
1236 	**
1237 	** CLASS FORM
1238 	**
1239 	******************************/
1240 
1241 	class Button : public AnimatedElement {
1242 
1243 	private:
1244 		float scaleOut, scaleOn;
1245 		bool sensitive;
1246 		string textAlt;
1247 		int alignAlt;
1248 		int valignAlt;
1249 		string soundOn, soundOut, soundClick;
1250 
1251 	public:
1252 		bool isRollOver;
1253 
setAlt(string text,int align,int valign)1254 		void setAlt(string text, int align, int valign) { textAlt = text; alignAlt = align; valignAlt = valign; }
1255 
setSoundOn(string s)1256 		void setSoundOn(string s) { soundOn = s; }
setSoundOut(string s)1257 		void setSoundOut(string s) { soundOut = s; }
setSoundClick(string s)1258 		void setSoundClick(string s) { soundClick = s; }
getSoundClick()1259 		string getSoundClick() { return soundClick; }
1260 
1261 		void setSensitive(bool s);
getSensitive()1262 		bool getSensitive() { return sensitive; }
1263 
1264 		Button ();
1265 		~Button ();
setScales(float out,float on)1266 		void setScales(float out, float on) { scaleOn = on; scaleOut = out; setCurrentScale(out); }
1267 		bool isOnMouseOver();
1268 		bool onOver();
1269 		void imageOut(SDL_Surface* sfc);
1270 		void imageOn(SDL_Surface* sfc);
1271 		void imageOff(SDL_Surface* sfc);
1272 		void (*OnClick)(Scene*, Button*);
1273 	};
1274 
1275 	class CheckButton : public Group {
1276 
1277 	protected:
1278 
1279 		bool sensitive;
1280 		float scaleOut, scaleOn;
1281 
1282 		string textAlt;
1283 		int alignAlt;
1284 		int valignAlt;
1285 		string soundOn, soundOut, soundClick;
1286 
1287 		map<string, string> parameters;
1288 		Element *elBox, *elText;
1289 		string text;
1290 		float scaleText;
1291 		bool active;
1292 		int indexz;
changeFrame()1293 		void changeFrame() { if (active) { elBox->setCurrentFrame(1); } else { elBox->setCurrentFrame(0); } }
1294 
1295 	public:
1296         bool isRollOver;
1297 
setAlt(string text,int align,int valign)1298 		void setAlt(string text, int align, int valign) { textAlt = text; alignAlt = align; valignAlt = valign; }
1299 
setSoundOn(string s)1300 		void setSoundOn(string s) { soundOn = s; }
setSoundOut(string s)1301 		void setSoundOut(string s) { soundOut = s; }
setSoundClick(string s)1302 		void setSoundClick(string s) { soundClick = s; }
getSoundClick()1303 		string getSoundClick() { return soundClick; }
1304 
1305 		CheckButton ();
1306 		CheckButton (string font, string t);
1307 		~CheckButton ();
1308 
setScales(float out,float on)1309 		void setScales(float out, float on) { scaleOn = on; scaleOut = out; setCurrentScale(out); }
1310 
1311 		void setSensitive(bool s);
getSensitive()1312 		bool getSensitive() { return sensitive; }
1313 
1314 		/*********************
1315 		* PARAMETERS
1316 		**********************/
addParameter(string name,string value)1317 		void addParameter(string name, string value) { parameters[name] = value; }
getParameter(string name)1318 		string getParameter(string name) { return parameters[name]; }
1319 
1320 		/*********************
1321 		* ATRIBUTTES
1322 		**********************/
setScaleText(float s)1323 		void setScaleText (float s) { scaleText = s; if (text!="") elText->setCurrentScale(scaleText); }
getScaleText()1324 		float getScaleText () { return scaleText; }
setActive(bool a)1325 		void setActive (bool a) { active = a; changeFrame(); }
getActive()1326 		bool getActive () { return active; }
swapActive()1327 		void swapActive () { active = !active; changeFrame(); }
1328 
setIndexZ(int z)1329 		void setIndexZ (int z) { indexz = z; }
getIndexZ()1330 		int getIndexZ () { return indexz; }
1331 		void setText (string font, string t);
1332 
1333 		bool isOnMouseOver();
1334 		bool onOver();
1335 		void imageActive(SDL_Surface* sfc);
1336 		void imageInactive(SDL_Surface* sfc);
1337 		void (*OnClick)(Scene*, CheckButton*);
1338 		void draw();
1339 		void unLoad();
1340 	};
1341 
1342 	class RadioButton : public CheckButton {
1343 
1344 	private:
1345 		RadioButton *parent;
1346 
1347 	public:
1348 		RadioButton (RadioButton *p);
1349 		RadioButton (RadioButton *p, string font, string t);
1350 		~RadioButton ();
1351 
1352 		RadioButton* getRadioButtonActive ();
1353 		vector<RadioButton*> childs;
1354 		void addChild(RadioButton *r);
1355 		void setActive (bool a);
1356 		void swapActive ();
1357 		void unLoad();
1358 	};
1359 
1360 	class Entry : public Element {
1361 
1362 	protected:
1363         Element *elmCursor;
1364         int posCursor;
1365 
1366 		Entry *parent;
1367 		bool active;
1368 		bool nospace;
1369 		bool nosigns;
1370 		bool drawBox;
1371 
1372 		int maxLetters;
1373 
1374 		string text, label;
1375 		string font, fontLabel;
1376 
1377 		Button *bg;
1378 		Element *select;
1379 		Element *elmLabel;
1380 		int width;
1381 		int height;
1382 		float padding_top;
1383 		float padding_left;
1384 
1385 		bool multiline;
1386 		int totalRows;
1387 		int currentRow;
1388 
1389 		bool horizontal;
1390 
1391 		/*void introKey(SDLKey key);*/
1392 		void introText(string t);
1393 		void updateText();
1394 
1395 
1396 	public:
1397 		Entry (Entry *p, int w, int h, float pt, float pl);
1398 		~Entry ();
1399 
1400 		void setPosCursor(int p);
1401 
1402 		void setXCursor();
1403 		void upLineCursor();
1404 		void downLineCursor();
1405 		void forwardCursor();
1406 		void backCursor();
1407 
1408 		void setLabel (string l);
1409 
1410 		void setHorizontal (bool h);
1411 
setTotalRows(int t)1412 		void setTotalRows (int t) { totalRows = t; }
getTotalRows()1413 		int getTotalRows () { return totalRows; }
1414 
setMultiline(bool m)1415 		void setMultiline (bool m) { multiline = m; }
getMultiline()1416 		bool getMultiline () { return multiline; }
1417 
setNoSigns(bool n)1418 		void setNoSigns (bool n) { nosigns = n; }
1419 
setNoSpace(bool n)1420 		void setNoSpace (bool n) { nospace = n; }
setMaxLetters(int m)1421 		void setMaxLetters (int m) { maxLetters = m; }
getMaxLetters()1422 		int getMaxLetters () { return maxLetters; }
1423 
setPaddingTop(float pt)1424 		void setPaddingTop (float pt) { padding_top = pt; }
getPaddingTop()1425 		float getPaddingTop () { return padding_top; }
setPaddingLeft(float pl)1426 		void setPaddingLeft (float pl) { padding_left = pl; }
getPaddingLeft()1427 		float getPaddingLeft () { return padding_left; }
1428 
getBackground()1429 		Element* getBackground () { return bg; }
1430 
1431 		void colorBoxNormal (int r, int g, int b, int border, int rb, int gb, int bb);
1432 		void colorBoxOnOver (int r, int g, int b, int border, int rb, int gb, int bb);
1433 		void colorBoxActived (int r, int g, int b, int border, int rb, int gb, int bb);
1434 
1435 		void addFrameBoxNormal (SDL_Surface *sfc);
1436 		void addFrameBoxOnOver (SDL_Surface *sfc);
1437 		void addFrameBoxActived (SDL_Surface *sfc);
1438 
setFont(string f)1439 		void setFont (string f) { font = f; }
setFontLabel(string f)1440 		void setFontLabel (string f) { fontLabel = f; }
1441 
1442 		void insertText (string t);
1443 		bool verifyKey (SDLKey k);
1444 		void insertTextUnicode (SDLKey k, int i);
1445 		void setText (string t);
1446 		/*void setText(SDLKey key);*/
getText()1447 		string getText () { return text; }
1448 
1449 		void setX (float x);
1450 		void setY (float y);
1451 		void setXY (float x, float y);
1452 
1453 		Entry* getEntryActive ();
1454 		Entry* getNextEntry ();
1455 		vector<Entry*> childs;
1456 		void addChild(Entry *e);
1457 		void setActive (bool a);
getActive()1458 		bool getActive () { return active; }
1459 		void swapActive ();
setDrawBox(bool d)1460 		void setDrawBox (bool d) { drawBox = d; }
getDrawBox()1461 		bool getDrawBox () { return drawBox; }
1462 
1463 		void onOver();
1464 		bool isOnMouseOver();
1465 		void draw();
1466 		void unLoad();
1467 
1468 	};
1469 
1470 	class SelectButton : public Group  {
1471 
1472 	private:
1473 		map<string, string> parameters;
1474 		int minSeparateButtons;
1475 		int greaterWidthObject;
1476 		Element *elObjects;
1477 		Button *elArrowLeft, *elArrowRight;
1478 		bool arrows;
1479 		int indexz;
1480 		bool sensitive;
1481 
1482 		string textAlt;
1483 		int alignAlt;
1484 		int valignAlt;
1485 		string soundClick;
1486 
1487 	public:
1488 		bool isRollOver;
1489 
1490 		SelectButton ();
1491 		~SelectButton ();
1492 
1493 		bool onOver();
1494 
1495 		void setSensitive(bool s);
getSensitive()1496 		bool getSensitive() { return sensitive; }
1497 
setAlt(string text,int align,int valign)1498 		void setAlt(string text, int align, int valign) { textAlt = text; alignAlt = align; valignAlt = valign; }
1499 
setSoundClick(string s)1500 		void setSoundClick(string s) { soundClick = s; }
1501 
1502 		/*********************
1503 		* PARAMETERS
1504 		**********************/
addParameter(string name,string value)1505 		void addParameter(string name, string value) { parameters[name] = value; }
getParameter(string name)1506 		string getParameter(string name) { return parameters[name]; }
1507 
1508 		/*********************
1509 		* ATRIBUTTES
1510 		**********************/
1511 
setIndexZ(int z)1512 		void setIndexZ (int z) { indexz = z; }
getIndexZ()1513 		int getIndexZ () { return indexz; }
1514 
setMinSeparateButtons(int m)1515 		void setMinSeparateButtons (int m) { minSeparateButtons = m; }
getMinSeparateButtons()1516 		int getMinSeparateButtons () { return minSeparateButtons; }
1517 
1518 		void setArrows(SDL_Surface* left, SDL_Surface* right);
1519 
previousFrame()1520 		void previousFrame() { elObjects->previousFrame(); }
nextFrame()1521 		void nextFrame() { elObjects->nextFrame(); }
setFrame(int f)1522 		void setFrame(int f) { elObjects->setCurrentFrame(f); }
getIndex()1523 		int getIndex() { return elObjects->getCurrentFrame(); }
1524 		bool isOnMouseOver();
1525 		int getOverBottom();
1526 		void addObject(SDL_Surface* sfc);
1527 		void (*OnClick)(Scene*, SelectButton*);
1528 		void draw();
1529 		void unLoad();
1530 	};
1531 
1532 	/*****************************
1533 	**
1534 	** CLASS PARTICLES
1535 	**
1536 	******************************/
1537 
1538 	class ParticlesSystem;
1539 
1540 
1541 	class Particle : public Element {
1542 
1543 	private:
1544 
1545 		ParticlesSystem *particlesSystem;
1546 
1547         int type;
1548 
1549 		int cyclesLife, currentCyclesLife;
1550 
1551 		float positionX, positionY, positionW, positionH;
1552 
1553 		float displacementX, displacementY;
1554 
1555 		bool changeColor;
1556 
1557 		Color color;
1558 		int currentColor;
1559 
1560 		int state;
1561 		int rot;
1562 		float scale;
1563 
1564 		int factorAlpha;
1565 
1566 		bool returnToBeBorn;
1567 
1568 	public:
1569 		Particle (ParticlesSystem *ps);
1570 		~Particle ();
1571 
setType(int t)1572 		void setType(int t) { type = t; }
getType()1573 		int getType() { return type; }
1574 
setDisplacementX(float d)1575 		void setDisplacementX(float d) { displacementX = d; }
setDisplacementY(float d)1576 		void setDisplacementY(float d) { displacementY = d; }
1577 
setCurrentColor(int c)1578 		void setCurrentColor(int c) { currentColor = c; }
addCurrentColor()1579 		void addCurrentColor() { currentColor++; if (currentColor>11) currentColor = 0; }
getCurrentColor()1580 		int getCurrentColor() { return currentColor; }
1581 
1582 		void setMlLife(int ml);
1583 
setCurrentCyclesLife(int cl)1584 		void setCurrentCyclesLife(int cl) { currentCyclesLife = cl; }
addCurrentCyclesLife()1585 		void addCurrentCyclesLife() { currentCyclesLife++; }
getCurrentCyclesLife()1586 		int getCurrentCyclesLife() { return currentCyclesLife; }
1587 
setState(int st)1588 		void setState(int st) { state = st; }
getState()1589 		int getState() { return state; }
1590 
setRotation(int r)1591 		void setRotation(int r) { rot = r; }
getRotation()1592 		int getRotation() { return rot; }
1593 
setScale(int s)1594 		void setScale(int s) { scale = s; }
getScale()1595 		float getScale() { return scale; }
1596 
setFactorAlpha(int fa)1597 		void setFactorAlpha(int fa) { factorAlpha = fa; }
1598 
setColor(int r,int g,int b)1599 		void setColor(int r, int g, int b) { color.r = r; color.g = g; color.b = b; setRGB(r,g,b); }
setChangeColor(bool cl)1600 		void setChangeColor(bool cl) { changeColor = cl; }
getChangeColor()1601 		bool getChangeColor() { return changeColor; }
1602 
setReturnToBeBorn(bool r)1603 		void setReturnToBeBorn(bool r) { returnToBeBorn = r; }
getReturnToBeBorn()1604 		bool getReturnToBeBorn() { return returnToBeBorn; }
1605 
1606 		void setPositions(float px, float py, float pw, float ph);
1607 
die()1608 		void die() { returnToBeBorn = false; state = PARTICLE_DYING; }
1609 
1610 		void start();
1611 		void change();
1612 
1613 	};
1614 
1615 
1616 	class ParticlesSystem	{
1617 	private:
1618 		Particle *particles[NPARTICLES];
1619 		int nParticles;
1620 		int indexz;
1621         int type;
1622 		float positionX, positionY, positionW, positionH;
1623 
1624 	public:
1625 		VectorColors *colors;
1626 
1627 		ParticlesSystem ();
1628 		ParticlesSystem (int np);
1629 		~ParticlesSystem ();
1630 
1631 		void setType(int t);
getType()1632 		int getType() { return type; }
1633 
1634 		void start();
1635 		bool isVisible();
1636 		void setPositions(float px, float py, float pw, float ph);
1637 
1638 		void setFrame(SDL_Surface* sfc);
1639 		void setFrame(string fr);
1640 
1641 		void setMlLife(int ml);
1642 		void setMlLife(int ml1, int ml2);
1643 
1644 		void setDisplacementX(float b, float e);
1645 		void setDisplacementY(float b, float e);
1646 
1647 		void setRotation(int r);
1648 
1649 		void setScale(int s);
1650 
1651 		void setCurrentScale(float s);
1652 
1653         void setFactorAlpha(float fa);
1654 		void setChangeColor(bool cl);
1655 		void setReturnToBeBorn(bool r);
1656 
setIndexZ(int z)1657 		void setIndexZ (int z) { indexz = z; }
getIndexZ()1658 		int getIndexZ () { return indexz; }
1659 
1660 		void draw();
1661 		void unLoad();
1662 
1663 	};
1664 
1665 }
1666 
1667 #endif /* ELEMENTS_H_ */
1668