Atrinik Client 2.5
toolkit/range_buttons.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #include <global.h>
00031 
00035 static uint32 ticks = 0;
00036 
00045 int range_buttons_show(int x, int y, int *val, int advance)
00046 {
00047     int state, mx, my;
00048 
00049     /* Get state of the mouse and the x/y. */
00050     state = SDL_GetMouseState(&mx, &my);
00051 
00052     /* Show the two range buttons. */
00053     sprite_blt(Bitmaps[BITMAP_RANGE_BUTTONS_OFF], x, y, NULL, NULL);
00054 
00055     /* Check the Y position. */
00056     if (my > y && my < y + Bitmaps[BITMAP_RANGE_BUTTONS_OFF]->bitmap->h && state == SDL_BUTTON(SDL_BUTTON_LEFT) && (!ticks || SDL_GetTicks() - ticks > 125))
00057     {
00058         /* If the left range button was clicked, decrease the value. */
00059         if (mx > x && mx < x + Bitmaps[BITMAP_RANGE_BUTTONS_LEFT]->bitmap->w)
00060         {
00061             sprite_blt(Bitmaps[BITMAP_RANGE_BUTTONS_LEFT], x, y, NULL, NULL);
00062             *val -= advance;
00063             ticks = SDL_GetTicks();
00064             return 1;
00065         }
00066         /* Otherwise increase it. */
00067         else if (mx > x + Bitmaps[BITMAP_RANGE_BUTTONS_LEFT]->bitmap->w && mx < x + Bitmaps[BITMAP_RANGE_BUTTONS_LEFT]->bitmap->w + Bitmaps[BITMAP_RANGE_BUTTONS_LEFT]->bitmap->w)
00068         {
00069             sprite_blt(Bitmaps[BITMAP_RANGE_BUTTONS_RIGHT], x + Bitmaps[BITMAP_RANGE_BUTTONS_LEFT]->bitmap->w, y, NULL, NULL);
00070             *val += advance;
00071             ticks = SDL_GetTicks();
00072             return 1;
00073         }
00074     }
00075 
00076     return 0;
00077 }