|
1 |
| -//BEGIN HEAD |
2 |
| -//BEGIN DESCRIPTION |
| 1 | +#pragma GCC diagnostic ignored "-Wunknown-pragmas" |
| 2 | +#pragma region HEAD |
| 3 | +#pragma region DESCRIPTION |
3 | 4 |
|
4 | 5 | /* light SDL2 template
|
5 | 6 | * DeCasteljau Subdivision
|
|
10 | 11 | * connect 4 points with 3 lines
|
11 | 12 | *
|
12 | 13 | */
|
13 |
| -//END DESCRIPTION |
| 14 | +#pragma endregion DESCRIPTION |
14 | 15 |
|
15 |
| -//BEGIN INCLUDES |
| 16 | +#pragma region INCLUDES |
16 | 17 | //system headers
|
17 | 18 | #include <math.h>
|
18 | 19 | //local headers
|
19 | 20 | #include "helper.h"
|
20 | 21 | #include <SDL2/SDL2_gfxPrimitives.h>
|
21 | 22 |
|
22 |
| -//END INCLUDES |
| 23 | +#pragma endregion INCLUDES |
23 | 24 |
|
24 |
| -//BEGIN CPP DEFINITIONS |
25 |
| -#define WHITE 255,255,255,255 |
26 |
| -#define BLACK 0,0,0,255 |
27 |
| -#define RED 255,0,0,255 |
| 25 | +#pragma region CPP DEFINITIONS |
| 26 | +#define WHITE 255, 255, 255, 255 |
| 27 | +#define BLACK 0, 0, 0, 255 |
| 28 | +#define RED 255, 0, 0, 255 |
28 | 29 | #define WW 550
|
29 |
| -#define WH (WW/16)*12 |
| 30 | +#define WH (WW / 16) * 12 |
30 | 31 | #define POINTS 4
|
31 |
| -//END CPP DEFINITIONS |
| 32 | +#pragma endregion CPP DEFINITIONS |
32 | 33 |
|
33 |
| -//BEGIN DATASTRUCTURES |
| 34 | +#pragma region DATASTRUCTURES |
34 | 35 | SDL_Point points[POINTS];
|
35 | 36 |
|
36 |
| -//END DATASTRUCTURES |
| 37 | +#pragma endregion DATASTRUCTURES |
37 | 38 |
|
38 |
| -//BEGIN GLOBALS |
39 |
| -int ww=WW; |
40 |
| -int wh=WH; |
| 39 | +#pragma region GLOBALS |
| 40 | +int ww = WW; |
| 41 | +int wh = WH; |
41 | 42 |
|
42 |
| -//BEGIN VISIBLES |
43 |
| -SDL_Surface *temp_surface = NULL; |
| 43 | +#pragma region VISIBLES |
| 44 | +SDL_Surface *temp_surface = NULL; |
44 | 45 |
|
45 |
| -SDL_Texture *logo = NULL; |
46 |
| -SDL_Rect logo_dst; |
47 |
| -//END VISIBLES |
| 46 | +SDL_Texture *logo = NULL; |
| 47 | +SDL_Rect logo_dst; |
| 48 | +#pragma endregion VISIBLES |
48 | 49 |
|
49 |
| -SDL_Point mouse; |
| 50 | +SDL_Point mouse; |
50 | 51 |
|
51 |
| -//END GLOBALS |
| 52 | +#pragma endregion GLOBALS |
52 | 53 |
|
53 |
| -//BEGIN FUNCTION PROTOTYPES |
54 |
| -void assets_in (void); |
55 |
| -void assets_out (void); |
56 |
| -//END FUNCTION PROTOTYPES |
| 54 | +#pragma region FUNCTION PROTOTYPES |
| 55 | +void assets_in(void); |
| 56 | +void assets_out(void); |
| 57 | +#pragma endregion FUNCTION PROTOTYPES |
| 58 | +#pragma endregion HEAD |
57 | 59 |
|
58 |
| -//END HEAD |
59 |
| - |
60 |
| -//BEGIN MAIN FUNCTION |
| 60 | +#pragma region MAIN FUNCTION |
61 | 61 | int main(int argc, char *argv[])
|
62 | 62 | {
|
63 | 63 |
|
64 |
| -(void)argc; |
65 |
| -(void)argv; |
66 |
| - |
67 |
| -//BEGIN INIT |
68 |
| -init(); |
69 |
| -assets_in(); |
70 |
| - |
71 |
| -//BEGIN WINDOW |
72 |
| -SDL_SetWindowPosition(Window,0,0); |
73 |
| -SDL_SetWindowSize(Window,ww,wh); |
74 |
| -SDL_SetWindowTitle(Window, "SDL2 Template"); |
75 |
| -SDL_ShowWindow(Window); |
76 |
| -//END WINDOW |
77 |
| - |
78 |
| -int r=255,g=0,b=0,a=255; |
79 |
| -points[0].x=40; |
80 |
| -points[0].y=WH/2; |
81 |
| - |
82 |
| -points[1].x=142; |
83 |
| -points[1].y=55; |
84 |
| -points[2].x=372; |
85 |
| -points[2].y=334; |
86 |
| -points[3].x=WW-40; |
87 |
| -points[3].y=160; |
88 |
| - |
89 |
| -SDL_Event event; |
90 |
| -int running = 1; |
91 |
| -//END INIT |
92 |
| - |
93 |
| -//BEGIN MAIN LOOP |
94 |
| -while(running){ |
95 |
| - |
96 |
| - //BEGIN EVENT LOOP |
97 |
| - SDL_GetMouseState(&mouse.x, &mouse.y); |
98 |
| - while(SDL_PollEvent(&event)){ |
99 |
| - if(event.type == SDL_QUIT){ |
100 |
| - running =0; |
101 |
| - } |
102 |
| - if(event.type == SDL_MOUSEMOTION){ |
103 |
| - SDL_Log("x:%d y:%d",mouse.x, mouse.y); |
104 |
| - } |
105 |
| - if(event.type == SDL_MOUSEBUTTONDOWN){ |
106 |
| - if(event.button.button == SDL_BUTTON_RIGHT){ |
107 |
| - ; |
| 64 | + (void)argc; |
| 65 | + (void)argv; |
| 66 | + |
| 67 | +#pragma region INIT |
| 68 | + init(); |
| 69 | + assets_in(); |
| 70 | + |
| 71 | +#pragma region WINDOW |
| 72 | + SDL_SetWindowPosition(Window, 0, 0); |
| 73 | + SDL_SetWindowSize(Window, ww, wh); |
| 74 | + SDL_SetWindowTitle(Window, "SDL2 Template"); |
| 75 | + SDL_ShowWindow(Window); |
| 76 | +#pragma endregion WINDOW |
| 77 | + |
| 78 | + int r = 255, g = 0, b = 0, a = 255; |
| 79 | + points[0].x = 40; |
| 80 | + points[0].y = WH / 2; |
| 81 | + |
| 82 | + points[1].x = 142; |
| 83 | + points[1].y = 55; |
| 84 | + points[2].x = 372; |
| 85 | + points[2].y = 334; |
| 86 | + points[3].x = WW - 40; |
| 87 | + points[3].y = 160; |
| 88 | + |
| 89 | + SDL_Event event; |
| 90 | + int running = 1; |
| 91 | +#pragma endregion INIT |
| 92 | + |
| 93 | +#pragma region MAIN LOOP |
| 94 | + while (running) |
| 95 | + { |
| 96 | + |
| 97 | +#pragma region EVENT LOOP |
| 98 | + SDL_GetMouseState(&mouse.x, &mouse.y); |
| 99 | + while (SDL_PollEvent(&event)) |
| 100 | + { |
| 101 | + if (event.type == SDL_QUIT) |
| 102 | + { |
| 103 | + running = 0; |
108 | 104 | }
|
109 |
| - if(event.button.button == SDL_BUTTON_MIDDLE){ |
110 |
| - ; |
| 105 | + if (event.type == SDL_MOUSEMOTION) |
| 106 | + { |
| 107 | + SDL_Log("x:%d y:%d", mouse.x, mouse.y); |
111 | 108 | }
|
112 |
| - if(event.button.button==SDL_BUTTON_LEFT){ |
113 |
| - ; |
| 109 | + if (event.type == SDL_MOUSEBUTTONDOWN) |
| 110 | + { |
| 111 | + if (event.button.button == SDL_BUTTON_RIGHT) |
| 112 | + { |
| 113 | + ; |
| 114 | + } |
| 115 | + if (event.button.button == SDL_BUTTON_MIDDLE) |
| 116 | + { |
| 117 | + ; |
| 118 | + } |
| 119 | + if (event.button.button == SDL_BUTTON_LEFT) |
| 120 | + { |
| 121 | + ; |
| 122 | + } |
114 | 123 | }
|
115 |
| - } |
116 |
| - if(event.type == SDL_KEYDOWN ){ |
117 |
| - switch(event.key.keysym.sym ){ |
| 124 | + if (event.type == SDL_KEYDOWN) |
| 125 | + { |
| 126 | + switch (event.key.keysym.sym) |
| 127 | + { |
118 | 128 | case SDLK_ESCAPE:
|
119 |
| - running =0; |
| 129 | + running = 0; |
120 | 130 | break;
|
121 | 131 |
|
122 | 132 | case SDLK_r:
|
123 | 133 | case SDLK_BACKSPACE:
|
124 | 134 | break;
|
125 | 135 |
|
126 |
| - case SDLK_p: |
| 136 | + case SDLK_p: |
127 | 137 | case SDLK_SPACE:
|
128 | 138 | break;
|
129 |
| - |
| 139 | + |
130 | 140 | default:
|
131 | 141 | break;
|
| 142 | + } |
132 | 143 | }
|
133 | 144 | }
|
134 |
| - } |
135 |
| - //END EVENT LOOP |
136 |
| - //BEGIN RENDERING |
137 |
| - SDL_SetRenderDrawColor(Renderer, WHITE); |
138 |
| - SDL_RenderClear(Renderer); |
139 |
| - |
140 |
| - SDL_RenderCopy(Renderer, logo, NULL, &logo_dst); |
141 |
| - |
142 |
| - for ( int i=0; i<POINTS; i++){ |
143 |
| - aacircleRGBA(Renderer, points[i].x, points[i].y, 4, r,g,b,a); |
144 |
| - if (i<POINTS-1) |
145 |
| - aalineRGBA(Renderer, points[i].x, points[i].y, |
146 |
| - points[i+1].x, points[i+1].y, r,g,b,a); |
147 |
| - } |
148 |
| - |
149 |
| - |
150 |
| - |
151 |
| - SDL_RenderPresent(Renderer); |
152 |
| - //END RENDERING |
153 |
| -} |
154 |
| -//END MAIN LOOP |
| 145 | +#pragma endregion EVENT LOOP |
| 146 | +#pragma region RENDERING |
| 147 | + SDL_SetRenderDrawColor(Renderer, WHITE); |
| 148 | + SDL_RenderClear(Renderer); |
| 149 | + |
| 150 | + SDL_RenderCopy(Renderer, logo, NULL, &logo_dst); |
| 151 | + |
| 152 | + for (int i = 0; i < POINTS; i++) |
| 153 | + { |
| 154 | + aacircleRGBA(Renderer, points[i].x, points[i].y, 4, r, g, b, a); |
| 155 | + if (i < POINTS - 1) |
| 156 | + aalineRGBA(Renderer, points[i].x, points[i].y, |
| 157 | + points[i + 1].x, points[i + 1].y, r, g, b, a); |
| 158 | + } |
155 | 159 |
|
156 |
| -assets_out(); |
157 |
| -exit_(); |
158 |
| -return EXIT_SUCCESS; |
| 160 | + SDL_RenderPresent(Renderer); |
| 161 | +#pragma endregion RENDERING |
| 162 | + } |
| 163 | +#pragma endregion MAIN LOOP |
159 | 164 |
|
| 165 | + assets_out(); |
| 166 | + exit_(); |
| 167 | + return EXIT_SUCCESS; |
160 | 168 | }
|
161 |
| -//END MAIN FUNCTION |
| 169 | +#pragma endregion MAIN FUNCTION |
162 | 170 |
|
163 |
| -//BEGIN FUNCTIONS |
| 171 | +#pragma region FUNCTIONS |
164 | 172 | void assets_in(void)
|
165 | 173 | {
|
166 | 174 |
|
167 |
| - //BEGIN LOGO |
| 175 | +#pragma region LOGO |
168 | 176 | temp_surface = IMG_Load("./assets/gfx/logo.png");
|
169 | 177 | logo = SDL_CreateTextureFromSurface(Renderer, temp_surface);
|
170 | 178 | SDL_QueryTexture(logo, NULL, NULL, &logo_dst.w, &logo_dst.h);
|
171 |
| - logo_dst.x=(ww/2)-(logo_dst.w/2); |
172 |
| - logo_dst.y=(wh/2)-(logo_dst.h/2); |
173 |
| - //END LOGO |
174 |
| - |
| 179 | + logo_dst.x = (ww / 2) - (logo_dst.w / 2); |
| 180 | + logo_dst.y = (wh / 2) - (logo_dst.h / 2); |
| 181 | +#pragma endregion LOGO |
175 | 182 | }
|
176 | 183 |
|
177 | 184 | void assets_out(void)
|
178 | 185 | {
|
179 | 186 | SDL_DestroyTexture(logo);
|
180 | 187 | }
|
181 | 188 |
|
182 |
| -//END FUNCTIONS |
| 189 | +#pragma endregion FUNCTIONS |
0 commit comments