Atrinik Client  4.0
label.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
33 #include <global.h>
34 
36 static void widget_draw(widgetdata *widget)
37 {
38  _widget_label *label;
39 
40  label = widget->subwidget;
41 
42  if (label->text) {
43  text_show(ScreenSurface, label->font, label->text, widget->x, widget->y, label->color, TEXT_MARKUP, NULL);
44  }
45 }
46 
48 static void widget_deinit(widgetdata *widget)
49 {
50  _widget_label *label;
51 
52  label = widget->subwidget;
53 
54  if (label->text) {
55  efree(label->text);
56  }
57 
58  font_free(label->font);
59 }
60 
65 {
66  _widget_label *label;
67 
68  label = ecalloc(1, sizeof(*label));
69  label->font = font_get("arial", 10);
70  label->color = COLOR_WHITE;
71 
72  widget->draw_func = widget_draw;
73  widget->deinit_func = widget_deinit;
74  widget->subwidget = label;
75 }
void * subwidget
Definition: widget.h:107
void text_show(SDL_Surface *surface, font_struct *font, const char *text, int x, int y, const char *color_notation, uint64_t flags, SDL_Rect *box)
Definition: text.c:1983
void font_free(font_struct *font)
Definition: text.c:262
font_struct * font_get(const char *name, uint8_t size)
Definition: text.c:216
SDL_Surface * ScreenSurface
Definition: main.c:47
#define TEXT_MARKUP
Definition: text.h:224
font_struct * font
Definition: widget.h:213
static void widget_draw(widgetdata *widget)
Definition: label.c:36
void widget_label_init(widgetdata *widget)
Definition: label.c:64
int x
Definition: widget.h:48
static void widget_deinit(widgetdata *widget)
Definition: label.c:48
const char * color
Definition: widget.h:216
#define COLOR_WHITE
Definition: text.h:289
int y
Definition: widget.h:51
char * text
Definition: widget.h:210