-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.h
122 lines (100 loc) · 2.53 KB
/
ui.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*************************************
* QURAN BAHIT
* AUTHOR : alahem monsef
* EMAIL : [email protected]
* VERSION : __
* DATE : 11-may-2019
*
*************************************/
typedef struct rgba_t {
int r;
int g;
int b;
int a;
}rgba_t;
typedef struct text_line_t {
SDL_Surface* sur;
SDL_Texture* tex;
SDL_Rect rec;
}text_line_t;
SDL_Color getpixel(SDL_Surface *surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
// printf("b :%d\n", bpp);
SDL_Color PixelColor2 = {p[0],p[1],p[2],p[3]};
return PixelColor2;
}
void SetPixelColor(SDL_Surface* pSurface, int X, int Y, Uint32 Pixel)
{
Uint32* pPixels = (Uint32*)pSurface->pixels;
pPixels[(Y * pSurface->w) + X] = Pixel;
}
void change_pixel(SDL_Surface *sur,char r,char g,char b,char a)
{
int i;
int j;
const int SurfaceWidth = sur->w;
const int SurfaceHeight = sur->h;
// Loop through the second surface' pixel data
for(i = 0; i < SurfaceHeight; i++)
{
for(j = 0; j < SurfaceWidth; j++)
{
SDL_Color pxc = getpixel(sur, j, i);
Uint32 NewPixelValue;
//char val = 250;
//white
/* if (pxc.r > val && pxc.g > val && pxc.b > val && pxc.a > 250) {
pxc.r = 0;
pxc.g = 0;
pxc.b = 0;
pxc.a = 0;
}*/
//green
if (pxc.r > 4 && pxc.g > 4 && pxc.b > 4) {
pxc.r = r;
pxc.g = g;
pxc.b = b;
pxc.a = a;
}
NewPixelValue = SDL_MapRGBA(sur->format, pxc.r, pxc.g, pxc.b, pxc.a);
if(SDL_MUSTLOCK(sur))
SDL_LockSurface(sur);
SetPixelColor(sur, j, i, NewPixelValue);
// printf("g :%d\n", pxc.r);
// printf("g :%d\n", pxc.g);
// printf("b :%d\n", pxc.b);
if(SDL_MUSTLOCK(sur))
SDL_UnlockSurface(sur);
}
}
}
#include "input_box.h"
#include "quiz_box.h"
#include "hud.h"
void init_ui()
{
init_input_box();
init_quiz_box();
init_hud();
}
void update_ui()
{
update_input_box();
update_quiz_box();
update_hud();
}
void draw_ui()
{
draw_input_box();
draw_quiz_box();
draw_hud();
}
int free_ui()
{
free_input_box();
free_quiz_box();
free_hud();
}