-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlabel.c
47 lines (33 loc) · 1.08 KB
/
label.c
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
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "game.h"
#include "widget.h"
#include "label.h"
TTF_Font* FontInit(const char* fontpath, int ptsize){
TTF_Font *font = TTF_OpenFont(fontpath, ptsize);
if(NULL == font){
printf("ERROR : Failed to load font. %s\n", TTF_GetError());
return NULL;
}
return font;
}
int InitLabel(Label *self, Game *mainGm){
printf("INITING LABEL\n");
initWidget(&(self->base));
printf("INITING WIDGETS\n");
self->base.draw = &DrawLabel;
//self->font = FontInit("/usr/share/fonts/TTF/DejaVuSerifCondensed.ttf", 18);
//if(NULL == self->font){
//return 0;
//}
return 1;
}
void SetText(Label *self, const char *text){
self->text = text;
}
int DrawLabel(Widget *base, SDL_Renderer *rend){
Label *self = (Label*)base;
SDL_Surface* surface = SDL_CreateRGBSurface(0, base->srcRect.w, base->srcRect.h, DEFAULT_COLOR_DEPTH, 0, 0, 0, 0);
SDL_FillRect(surface, &base->srcRect, SDL_MapRGB(surface->format, self->background.r, self->background.g, self->background.b));
return 0;
}