Atrinik Client  4.0
range_buttons.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 
38 static uint32_t ticks = 0;
39 
54 int range_buttons_show(int x, int y, int *val, int advance)
55 {
56  int state, mx, my;
57  SDL_Surface *texture_off, *texture_left, *texture_right;
58 
59  /* Get state of the mouse and the x/y. */
60  state = SDL_GetMouseState(&mx, &my);
61 
62  texture_off = texture_surface(texture_get(TEXTURE_TYPE_CLIENT, "texture_off"));
63  texture_left = texture_surface(texture_get(TEXTURE_TYPE_CLIENT, "texture_left"));
64  texture_right = texture_surface(texture_get(TEXTURE_TYPE_CLIENT, "texture_right"));
65 
66  /* Show the two range buttons. */
67  surface_show(ScreenSurface, x, y, NULL, texture_off);
68 
69  /* Check the Y position. */
70  if (my > y && my < y + texture_off->h && state == SDL_BUTTON(SDL_BUTTON_LEFT) && (!ticks || SDL_GetTicks() - ticks > 125)) {
71  /* If the left range button was clicked, decrease the value. */
72  if (mx > x && mx < x + texture_left->w) {
73  surface_show(ScreenSurface, x, y, NULL, texture_left);
74  *val -= advance;
75  ticks = SDL_GetTicks();
76  return 1;
77  } else if (mx > x + texture_left->w && mx < x + texture_left->w + texture_right->w) {
78  /* Otherwise increase it. */
79  surface_show(ScreenSurface, x + texture_left->w, y, NULL, texture_right);
80  *val += advance;
81  ticks = SDL_GetTicks();
82  return 1;
83  }
84  }
85 
86  return 0;
87 }
static uint32_t ticks
Definition: range_buttons.c:38
SDL_Surface * texture_surface(texture_struct *texture)
Definition: texture.c:303
texture_struct * texture_get(texture_type_t type, const char *name)
Definition: texture.c:279
int range_buttons_show(int x, int y, int *val, int advance)
Definition: range_buttons.c:54
SDL_Surface * ScreenSurface
Definition: main.c:47
void surface_show(SDL_Surface *surface, int x, int y, SDL_Rect *srcrect, SDL_Surface *src)
Definition: sprite.c:761