|
Atrinik Client 1.0
|
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 <include.h> 00031 00032 int active_button = -1; 00033 00041 void draw_frame(SDL_Surface *surface, int x, int y, int w, int h) 00042 { 00043 SDL_Rect box; 00044 00045 box.x = x; 00046 box.y = y; 00047 box.h = h; 00048 box.w = 1; 00049 SDL_FillRect(surface, &box, surface == ScreenSurface ? sdl_gray4 : SDL_MapRGB(surface->format, 0x60, 0x60, 0x60)); 00050 box.x = x + w; 00051 box.h++; 00052 SDL_FillRect(surface, &box, surface == ScreenSurface ? sdl_gray3 : SDL_MapRGB(surface->format, 0x55, 0x55, 0x55)); 00053 box.x = x; 00054 box.y+= h; 00055 box.w = w; 00056 box.h = 1; 00057 SDL_FillRect(surface, &box, surface == ScreenSurface ? sdl_gray4 : SDL_MapRGB(surface->format, 0x60, 0x60, 0x60)); 00058 box.x++; 00059 box.y = y; 00060 SDL_FillRect(surface, &box, surface == ScreenSurface ? sdl_gray3 : SDL_MapRGB(surface->format, 0x55, 0x55, 0x55)); 00061 } 00062 00072 void border_create(SDL_Surface *surface, int x, int y, int w, int h, int color, int size) 00073 { 00074 SDL_Rect box; 00075 00076 /* Left border. */ 00077 box.x = x; 00078 box.y = y; 00079 box.h = h; 00080 box.w = size; 00081 SDL_FillRect(surface, &box, color); 00082 00083 /* Right border. */ 00084 box.x = x + w - size; 00085 SDL_FillRect(surface, &box, color); 00086 00087 /* Top border. */ 00088 box.x = x + size; 00089 box.y = y; 00090 box.w = w - size * 2; 00091 box.h = size; 00092 SDL_FillRect(surface, &box, color); 00093 00094 /* Bottom border. */ 00095 box.y = y + h - size; 00096 SDL_FillRect(surface, &box, color); 00097 } 00098 00104 void add_close_button(int x, int y, int menu) 00105 { 00106 int mx, my, mb; 00107 00108 mb = SDL_GetMouseState(&mx, &my) & SDL_BUTTON(SDL_BUTTON_LEFT); 00109 StringBlt(ScreenSurface, &SystemFont, "X", x + 463, y + 28, COLOR_BLACK, NULL, NULL); 00110 00111 if (mx >x + 459 && mx < x + 469 && my > y + 27 && my < y + 39) 00112 { 00113 StringBlt(ScreenSurface, &SystemFont, "X", x + 462, y + 27, COLOR_HGOLD, NULL, NULL); 00114 00115 if (mb && mb_clicked) 00116 { 00117 check_menu_keys(menu, SDLK_ESCAPE); 00118 } 00119 } 00120 else 00121 { 00122 StringBlt(ScreenSurface, &SystemFont, "X", x + 462, y + 27, COLOR_WHITE, NULL, NULL); 00123 } 00124 } 00125 00135 int add_button(int x, int y, int id, int gfxNr, char *text, char *text_h) 00136 { 00137 char *text_sel; 00138 int ret = 0, mx, my, mb; 00139 00140 mb = SDL_GetMouseState(&mx, &my) & SDL_BUTTON(SDL_BUTTON_LEFT); 00141 00142 if (text_h) 00143 { 00144 text_sel = text_h; 00145 } 00146 else 00147 { 00148 text_sel = text; 00149 } 00150 00151 sprite_blt(Bitmaps[gfxNr], x, y, NULL, NULL); 00152 00153 if (mx >x && my >y && mx < x + Bitmaps[gfxNr]->bitmap->w && my < y + Bitmaps[gfxNr]->bitmap->h) 00154 { 00155 if (mb && mb_clicked && active_button < 0) 00156 { 00157 active_button = id; 00158 } 00159 00160 if (active_button == id) 00161 { 00162 sprite_blt(Bitmaps[gfxNr + 1], x, y++, NULL, NULL); 00163 00164 if (!mb) 00165 { 00166 ret = 1; 00167 } 00168 } 00169 00170 StringBlt(ScreenSurface, &SystemFont, text, x + 11, y + 2, COLOR_BLACK, NULL, NULL); 00171 StringBlt(ScreenSurface, &SystemFont, text_sel, x + 10, y + 1, COLOR_HGOLD, NULL, NULL); 00172 } 00173 else 00174 { 00175 StringBlt(ScreenSurface, &SystemFont, text, x + 11, y + 2, COLOR_BLACK, NULL, NULL); 00176 StringBlt(ScreenSurface, &SystemFont, text_sel, x + 10, y + 1, COLOR_WHITE, NULL, NULL); 00177 } 00178 00179 return ret; 00180 } 00181 00191 int add_gr_button(int x, int y, int id, int gfxNr, const char *text, const char *text_h) 00192 { 00193 const char *text_sel; 00194 int ret = 0; 00195 int mx, my, mb; 00196 00197 mb = SDL_GetMouseState(&mx, &my) & SDL_BUTTON(SDL_BUTTON_LEFT); 00198 /* use text_h (=highlighted char for keyboard user) if available. */ 00199 if (text_h) 00200 text_sel = text_h; 00201 else 00202 text_sel = text; 00203 00204 if (id) 00205 sprite_blt(Bitmaps[++gfxNr], x, y++, NULL, NULL); 00206 else 00207 sprite_blt(Bitmaps[gfxNr], x, y, NULL, NULL); 00208 00209 StringBlt(ScreenSurface, &SystemFont, text, x + 11, y + 2, COLOR_BLACK, NULL, NULL); 00210 00211 if (mx >x && my >y && mx < x + Bitmaps[gfxNr]->bitmap->w && my < y + Bitmaps[gfxNr]->bitmap->h) 00212 { 00213 if (mb && mb_clicked) 00214 ret = 1; 00215 00216 StringBlt(ScreenSurface, &SystemFont, text_sel, x + 10, y + 1, COLOR_HGOLD, NULL, NULL); 00217 } 00218 else 00219 StringBlt(ScreenSurface, &SystemFont, text_sel, x + 10, y + 1, COLOR_WHITE, NULL, NULL); 00220 00221 return ret; 00222 } 00223 00231 void add_value(void *value, int type, int offset, int min, int max) 00232 { 00233 int old_value = 0; 00234 00235 switch (type) 00236 { 00237 case VAL_INT: 00238 old_value = *((int *) value); 00239 *((int *) value) += offset; 00240 00241 if (*((int *) value) > max) 00242 { 00243 *((int *) value) = max; 00244 } 00245 00246 if (*((int *) value) < min) 00247 { 00248 *((int *) value) = min; 00249 } 00250 00251 break; 00252 00253 case VAL_U32: 00254 old_value = *((uint32 *) value); 00255 *((uint32 *) value) += offset; 00256 00257 if (*((uint32 *) value) > (uint32) max) 00258 { 00259 *((uint32 *) value) = (uint32) max; 00260 } 00261 00262 if (*((uint32 *) value) < (uint32) min) 00263 { 00264 *((uint32 *) value) = (uint32) min; 00265 } 00266 00267 break; 00268 00269 default: 00270 break; 00271 } 00272 00273 /* Changed map X/Y, send a setup command to tell the server about the 00274 * change. */ 00275 if ((&options.map_size_x == value && options.map_size_x != old_value) || (&options.map_size_y == value && options.map_size_y != old_value)) 00276 { 00277 char buf[MAX_BUF]; 00278 00279 snprintf(buf, sizeof(buf), "setup mapsize %dx%d", options.map_size_x, options.map_size_y); 00280 cs_write_string(buf, strlen(buf)); 00281 } 00282 } 00283 00291 void draw_tabs(const char *tabs[], int *act_tab, const char *head_text, int x, int y) 00292 { 00293 int i = -1; 00294 int mx, my, mb; 00295 static int active = 0; 00296 00297 mb = SDL_GetMouseState(&mx, &my) & SDL_BUTTON(SDL_BUTTON_LEFT); 00298 sprite_blt(Bitmaps[BITMAP_DIALOG_TAB_START], x, y - 10, NULL, NULL); 00299 sprite_blt(Bitmaps[BITMAP_DIALOG_TAB], x, y, NULL, NULL); 00300 StringBlt(ScreenSurface, &SystemFont, head_text, x + 15, y + 4, COLOR_BLACK, NULL, NULL); 00301 StringBlt(ScreenSurface, &SystemFont, head_text, x + 14, y + 3, COLOR_WHITE, NULL, NULL); 00302 y += 17; 00303 sprite_blt(Bitmaps[BITMAP_DIALOG_TAB], x, y, NULL, NULL); 00304 y += 17; 00305 00306 while (tabs[++i]) 00307 { 00308 sprite_blt(Bitmaps[BITMAP_DIALOG_TAB], x, y, NULL, NULL); 00309 00310 if (i == *act_tab) 00311 { 00312 sprite_blt(Bitmaps[BITMAP_DIALOG_TAB_SEL], x, y, NULL, NULL); 00313 } 00314 00315 StringBlt(ScreenSurface, &SystemFont, tabs[i], x + 25, y + 4, COLOR_BLACK, NULL, NULL); 00316 00317 if (mx > x && mx < x + 100 && my > y && my < y + 17) 00318 { 00319 StringBlt(ScreenSurface, &SystemFont, tabs[i], x + 24, y + 3, COLOR_HGOLD, NULL, NULL); 00320 00321 if (mb && mb_clicked) 00322 { 00323 active = 1; 00324 } 00325 00326 if (active) 00327 { 00328 *act_tab = i; 00329 } 00330 } 00331 else 00332 { 00333 StringBlt(ScreenSurface, &SystemFont, tabs[i], x + 24, y + 3, COLOR_WHITE, NULL, NULL); 00334 } 00335 00336 y += 17; 00337 } 00338 00339 sprite_blt(Bitmaps[BITMAP_DIALOG_TAB_STOP], x, y, NULL, NULL); 00340 00341 if (!mb) 00342 { 00343 active = 0; 00344 } 00345 }
1.7.4