|
1 /* |
|
2 Copyright (c) 2023 MCL Software |
|
3 |
|
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), |
|
5 to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
6 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|
7 |
|
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
|
9 |
|
10 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
11 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
12 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
13 */ |
|
14 |
|
15 #include "common.h" |
|
16 |
|
17 Uint8 alpha; |
|
18 bool fadeInProgress = 0; |
|
19 SDL_TimerID fadeTimer = 0; |
|
20 |
|
21 Uint32 fadeIn(Uint32 interval) |
|
22 { |
|
23 alpha -= 1; |
|
24 SDL_SetRenderDrawColor(renderer, 0, 0, 0, alpha); |
|
25 |
|
26 if(alpha == 0) |
|
27 { |
|
28 SDL_RemoveTimer(fadeTimer); |
|
29 return 0; |
|
30 } |
|
31 |
|
32 return interval; |
|
33 } |
|
34 |
|
35 Uint32 fadeOut(Uint32 interval) |
|
36 { |
|
37 alpha += 1; |
|
38 SDL_SetRenderDrawColor(renderer, 0, 0, 0, alpha); |
|
39 |
|
40 if(alpha == 255) |
|
41 { |
|
42 SDL_RemoveTimer(fadeTimer); |
|
43 return 0; |
|
44 } |
|
45 |
|
46 return interval; |
|
47 } |
|
48 |
|
49 bool ISOL_FadeIn(int interval) |
|
50 { |
|
51 if(fadeInProgress && alpha > 0) |
|
52 { |
|
53 SDL_RenderFillRect(renderer, &(SDL_Rect){0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}); |
|
54 //SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); |
|
55 return 0; |
|
56 } |
|
57 |
|
58 else if(fadeInProgress) |
|
59 { |
|
60 fadeInProgress = 0; |
|
61 return 1; |
|
62 } |
|
63 |
|
64 else |
|
65 { |
|
66 fadeInProgress = 1; |
|
67 alpha = 255; |
|
68 fadeTimer = SDL_AddTimer(interval, fadeIn, 0); |
|
69 return 0; |
|
70 } |
|
71 } |
|
72 |
|
73 bool ISOL_FadeOut(int interval) |
|
74 { |
|
75 if(fadeInProgress && alpha < 255) |
|
76 { |
|
77 SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); |
|
78 SDL_RenderFillRect(renderer, &(SDL_Rect){0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}); |
|
79 return 0; |
|
80 } |
|
81 |
|
82 else if(fadeInProgress) |
|
83 { |
|
84 fadeInProgress = 0; |
|
85 return 1; |
|
86 } |
|
87 |
|
88 else |
|
89 { |
|
90 fadeInProgress = 1; |
|
91 alpha = 0; |
|
92 fadeTimer = SDL_AddTimer(interval, fadeOut, 0); |
|
93 return 0; |
|
94 } |
|
95 } |