Atrinik Client  4.0
mapname.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 
32 #include <global.h>
33 
34 typedef struct widget_mapname_struct {
35  int alpha;
37 
39 static void widget_draw(widgetdata *widget)
40 {
41  widget_mapname_struct *widget_mapname;
42  SDL_Rect box;
43 
44  widget_mapname = widget->subwidget;
45 
46  box.w = widget->w;
47  box.h = 0;
48  text_show_format(ScreenSurface, MAP_NAME_FONT, widget->x, widget->y, COLOR_HGOLD, TEXT_MARKUP, &box, "[alpha=%d]%s[/alpha]", widget_mapname->alpha, MapData.name);
49 }
50 
52 static void widget_background(widgetdata *widget, int draw)
53 {
54  widget_mapname_struct *widget_mapname;
55  int alpha;
56 
57  widget_mapname = widget->subwidget;
58  alpha = widget_mapname->alpha;
59 
60  if (MapData.name_fadeout_start || MapData.name[0] == '\0') {
61  uint32_t time_passed;
62 
63  time_passed = SDL_GetTicks() - MapData.name_fadeout_start;
64 
65  if (time_passed > MAP_NAME_FADEOUT || MapData.name[0] == '\0') {
66  if (MapData.name[0] != '\0') {
67  alpha = MIN(255, 255 * ((double) (time_passed - MAP_NAME_FADEOUT) / MAP_NAME_FADEOUT));
68 
69  if (alpha == 255) {
70  MapData.name_fadeout_start = 0;
71  }
72  }
73 
74  if (MapData.name_new[0] != '\0') {
75  strncpy(MapData.name, MapData.name_new, sizeof(MapData.name) - 1);
76  MapData.name[sizeof(MapData.name) - 1] = '\0';
77 
78  resize_widget(widget, RESIZE_RIGHT, text_get_width(MAP_NAME_FONT, MapData.name, TEXT_MARKUP));
79  resize_widget(widget, RESIZE_BOTTOM, text_get_height(MAP_NAME_FONT, MapData.name, TEXT_MARKUP));
80 
81  MapData.name_new[0] = '\0';
82  widget->redraw = 1;
83  }
84  } else {
85  alpha = 255 * (1.0 - (double) time_passed / MAP_NAME_FADEOUT);
86  }
87  } else if (MapData.name_new[0] != '\0') {
88  if (strcmp(MapData.name_new, MapData.name) != 0) {
89  MapData.name_fadeout_start = SDL_GetTicks();
90  widget->redraw = 1;
91  } else {
92  MapData.name_new[0] = '\0';
93  }
94  }
95 
96  if (alpha != widget_mapname->alpha) {
97  widget_mapname->alpha = alpha;
98  widget->redraw = 1;
99  }
100 }
101 
106 {
107  widget_mapname_struct *widget_mapname;
108 
109  widget_mapname = emalloc(sizeof(*widget_mapname));
110  widget_mapname->alpha = 255;
111 
112  widget->draw_func = widget_draw;
113  widget->background_func = widget_background;
114  widget->subwidget = widget_mapname;
115 
116 }
#define MAP_NAME_FONT
Definition: map.h:275
char name_new[HUGE_BUF]
Definition: map.h:122
static void widget_background(widgetdata *widget, int draw)
Definition: mapname.c:52
void * subwidget
Definition: widget.h:107
#define COLOR_HGOLD
Definition: text.h:319
SDL_Surface * ScreenSurface
Definition: main.c:47
#define TEXT_MARKUP
Definition: text.h:224
_mapdata MapData
Definition: map.c:64
int text_get_height(font_struct *font, const char *text, uint64_t flags)
Definition: text.c:2364
uint8_t redraw
Definition: widget.h:72
int x
Definition: widget.h:48
void widget_mapname_init(widgetdata *widget)
Definition: mapname.c:105
#define MAP_NAME_FADEOUT
Definition: map.h:278
int w
Definition: widget.h:54
int text_get_width(font_struct *font, const char *text, uint64_t flags)
Definition: text.c:2328
void text_show_format(SDL_Surface *surface, font_struct *font, int x, int y, const char *color_notation, uint64_t flags, SDL_Rect *box, const char *format,...)
Definition: text.c:2289
static void widget_draw(widgetdata *widget)
Definition: mapname.c:39
char name[HUGE_BUF]
Definition: map.h:119
int y
Definition: widget.h:51