Atrinik Client  4.0
progress.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 
40 {
41  progress->ticks = SDL_GetTicks();
42  progress->dot = 0;
43  progress->done = 0;
44 }
45 
57 void progress_dots_show(progress_dots *progress, SDL_Surface *surface, int x, int y)
58 {
59  uint8_t i;
60  SDL_Surface *texture;
61 
62  for (i = 0; i < PROGRESS_DOTS_NUM; i++) {
63  texture = TEXTURE_CLIENT(progress->dot == i || progress->done ? "loading_on" : "loading_off");
64  surface_show(surface, x + (texture->w + PROGRESS_DOTS_SPACING) * i, y, NULL, texture);
65  }
66 
67  /* Progress the lit dot. */
68  if (!progress->done && SDL_GetTicks() - progress->ticks > PROGRESS_DOTS_TICKS) {
69  progress->ticks = SDL_GetTicks();
70  progress->dot++;
71 
72  /* More than maximum, back to the first one. */
73  if (progress->dot >= PROGRESS_DOTS_NUM) {
74  progress->dot = 0;
75  }
76  }
77 }
78 
87 {
88  (void) progress;
89 
90  return (TEXTURE_CLIENT("loading_on")->w + PROGRESS_DOTS_SPACING) * PROGRESS_DOTS_NUM - PROGRESS_DOTS_SPACING;
91 }
uint8_t done
Definition: progress.h:44
void progress_dots_create(progress_dots *progress)
Definition: progress.c:39
uint8_t dot
Definition: progress.h:41
int progress_dots_width(progress_dots *progress)
Definition: progress.c:86
#define PROGRESS_DOTS_TICKS
Definition: progress.h:52
uint32_t ticks
Definition: progress.h:38
void surface_show(SDL_Surface *surface, int x, int y, SDL_Rect *srcrect, SDL_Surface *src)
Definition: sprite.c:761
void progress_dots_show(progress_dots *progress, SDL_Surface *surface, int x, int y)
Definition: progress.c:57
static progress_dots progress
Definition: characters.c:49
#define PROGRESS_DOTS_NUM
Definition: progress.h:48
#define PROGRESS_DOTS_SPACING
Definition: progress.h:50