SANDAL2
A SDL2 Wrapper in C
Window.h
Go to the documentation of this file.
1 #ifndef FENETRE_BY_KLEVH
2 #define FENETRE_BY_KLEVH
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <string.h>
9 #include <stdlib.h>
10 
11 #include <SDL2/SDL.h>
12 #include <SDL2/SDL_ttf.h>
13 #include <SDL2/SDL_image.h>
14 
15 #ifdef DEBUG_SDL2_NO_VIDEO
16 extern Uint32 currentDisplaied;
17 #endif
18 
28 #define absolu(a) ((a>0)?a:-a)
29 
32 #define PFREE(p){ \
33  if(p){ \
34  free(p); \
35  } \
36  }
37 
38 struct ListElement;
39 struct ListDCElement;
40 
45 typedef struct{
46  void (*action)(void);
48  void (*onClick)(int);
50  void (*unClick)(int);
52  void (*keyPress)(SDL_Keycode c);
54  void (*keyReleased)(SDL_Keycode c);
56  void (*onWheel)(int);
58  void (*onFocus)(void);
60  void (*unFocus)(void);
62  void (*onMouseMotion)(int, int);
65 
70 typedef struct Window{
71  int height;
73  int width;
77  int initWidth;
81  int background[4];
83  int origin[2];
85 #ifndef DEBUG_SDL2_NO_VIDEO
86  SDL_Window *window;
88 #else
89  unsigned id;
90  struct Window * window;
91  int posX;
92  int posY;
93 #endif
94  SDL_Renderer *renderer;
96  struct ListElement * liste;
100  struct Window * next;
102  unsigned toDelete;
104  int close;
112  void * data;
114  int stop;
116  int state;
118  int focused;
120  Uint32 ticks;
122 }Window;
123 
128 typedef struct{
137  unsigned count;
139 }ListWindow;
140 
141 
147 
148 /* -------------------------------------------------------
149  * Window
150  */
157 int resizeWindow(unsigned width,unsigned height);
168 Uint32 initIteratorWindow();
173 Uint32 nextWindow();
180 int getDimensionWindow(int * w,int * h);
186 int getDisplayCodeWindow(int * d);
192 int getColorWindow(int color[4]);
198 int setColorWindow(const int color[4]);
205 int getCoordWindow(int *x,int *y);
212 int setCoordWindow(int x,int y);
219 int getRealDimensionWindow(int *width,int *height);
225 int getIDWindow(Uint32 *ID);
231 int getIDCurrentWindow(Uint32 *ID);
237 int setIconWindow(const char * icon_path);
243 int setActionWindow(void (*action)(void));
249 int setKeyPressedWindow(void (*keyPress)(SDL_Keycode c));
255 int setKeyReleasedWindow(void (*keyReleased)(SDL_Keycode c));
261 int setOnClickWindow(void (*onCLick)(int));
267 int setUnClickWindow(void (*unCLick)(int));
273 int setOnWheelWindow(void (*onWheel)(int));
279 int setOnMouseMotionWindow(void (*onMouseMotion)(int, int));
285 int setOnFocusedWindow(void (*onFocus)(void));
291 int setUnFocusedWindow(void (*unFocus)(void));
298 int getOriginWindow(int * x,int * y);
305 int setOriginWindow(int x,int y);
311 int setXOriginWindow(int x);
317 int setYOriginWindow(int y);
323 int setDataWindow(void * data);
329 int getDataWindow(void ** data);
335 int setDisplayWindow(Uint32 windowID);
336 /* ------------------------------------------------------- */
337 
338 #ifdef __cplusplus
339 }
340 #endif
341 
342 #endif
int setOnWheelWindow(void(*onWheel)(int))
set behavior of window when a wheel event occure
Definition: Window.c:344
int getOriginWindow(int *x, int *y)
get the origin point of the current window
Definition: Window.c:388
int getIDCurrentWindow(Uint32 *ID)
Getter for the current window ID.
Definition: Window.c:260
Window * current
Definition: Window.h:133
int getDataWindow(void **data)
get the data package of a window
Definition: Window.c:429
List (display code) of list (plan) of element.
Definition: Element.h:169
int initWidth
Definition: Window.h:77
int setXOriginWindow(int x)
set the x coordinate of the origin point of the current window
Definition: Window.c:408
EventWindow events
Definition: Window.h:98
int stop
Definition: Window.h:114
Behaviors of a window to events.
Definition: Window.h:45
Uint32 initIteratorWindow()
Initialise the iterator of the windows&#39; list.
Definition: Window.c:134
int close
Definition: Window.h:104
Uint32 ticks
Definition: Window.h:120
int focused
Definition: Window.h:118
struct ListElement * liste
Definition: Window.h:96
int setUnFocusedWindow(void(*unFocus)(void))
set behavior of window when the window lose focus
Definition: Window.c:377
int setDisplayCodeWindow(int displayCode)
Change the display code of the current window.
Definition: Window.c:122
int displayCode
Definition: Window.h:79
struct Window * next
Definition: Window.h:100
int setOnMouseMotionWindow(void(*onMouseMotion)(int, int))
set behavior of window when a wheel event occure
Definition: Window.c:355
List of list (display code) of list (plan) of elements.
Definition: Element.h:184
int getIDWindow(Uint32 *ID)
Getter for the currently displaied window ID.
Definition: Window.c:247
int setDataWindow(void *data)
set the data package of a window
Definition: Window.c:422
int setColorWindow(const int color[4])
Change the background color of the current window.
Definition: Window.c:198
SDL_Window * window
Definition: Window.h:86
int setYOriginWindow(int y)
set the y coordinate of the origin point of the current window
Definition: Window.c:415
SANDAL2 window.
Definition: Window.h:70
int setOriginWindow(int x, int y)
set the origin point of the current window
Definition: Window.c:399
struct ListDCElement * current
Definition: Window.h:110
int setKeyReleasedWindow(void(*keyReleased)(SDL_Keycode c))
set the behaviour of the current window when a key is released
Definition: Window.c:311
unsigned count
Definition: Window.h:137
int setActionWindow(void(*action)(void))
set the continuous behaviour of the current window
Definition: Window.c:289
int state
Definition: Window.h:116
int getDimensionWindow(int *w, int *h)
Put the width of the current window in w (if not NULL) and its height in h (if not NULL) ...
Definition: Window.c:158
int getRealDimensionWindow(int *width, int *height)
Getter for the real dimension of the current window (do not use this function to calculate elements&#39; ...
Definition: Window.c:231
void * data
Definition: Window.h:112
int setDisplayWindow(Uint32 windowID)
set the window to be displaied and the current window
Definition: Window.c:437
int setCoordWindow(int x, int y)
Set for the current window position.
Definition: Window.c:220
int getDisplayCodeWindow(int *d)
Put the display code of the current window in d (if not NULL)
Definition: Window.c:174
int setKeyPressedWindow(void(*keyPress)(SDL_Keycode c))
set the behaviour of the current window when a key is pressed
Definition: Window.c:300
int getCoordWindow(int *x, int *y)
Getter for the current window position.
Definition: Window.c:209
Window * currentDisplay
Definition: Window.h:135
Window * first
Definition: Window.h:129
int setOnFocusedWindow(void(*onFocus)(void))
set behavior of window when the window gain focus
Definition: Window.c:366
unsigned toDelete
Definition: Window.h:102
Window * last
Definition: Window.h:131
int initHeight
Definition: Window.h:75
SDL_Renderer * renderer
Definition: Window.h:94
int setOnClickWindow(void(*onCLick)(int))
set the behaviour of the current window when it is clicked
Definition: Window.c:322
ListWindow * _windows_SANDAL2
list of windows WARNING : do not touch this variable, never ... trust me
Definition: Window.c:3
Uint32 nextWindow()
Go to the next window.
Definition: Window.c:145
int origin[2]
Definition: Window.h:83
int getColorWindow(int color[4])
Put the background color of the current window in color.
Definition: Window.c:187
int resizeWindow(unsigned width, unsigned height)
Resize the current window.
Definition: Window.c:109
int background[4]
Definition: Window.h:81
int width
Definition: Window.h:73
int setUnClickWindow(void(*unCLick)(int))
set the behaviour of the current window when it is unclicked
Definition: Window.c:333
int displayToChange
Definition: Window.h:108
int setIconWindow(const char *icon_path)
Set the current window&#39;s icon.
Definition: Window.c:273
list of windows
Definition: Window.h:128
int height
Definition: Window.h:71
int newDisplayCode
Definition: Window.h:106