Import from neverball-1.4.0.tar.gz
[neverball-archive.git] / putt / hud.c
blob60772ec8d54ac61cb40053408a86a4391aa8e5d1
1 /*
2 * Copyright (C) 2003 Robert Kooima
4 * NEVERPUTT is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include <SDL.h>
16 #include <math.h>
18 #include "gui.h"
19 #include "hud.h"
20 #include "hole.h"
21 #include "config.h"
23 /*---------------------------------------------------------------------------*/
25 static int Lhud_id;
26 static int Rhud_id;
27 static int fps_id;
29 /*---------------------------------------------------------------------------*/
31 void hud_init(void)
33 static const float *color[5] = {
34 gui_wht,
35 gui_red,
36 gui_grn,
37 gui_blu,
38 gui_yel
40 int i = curr_player();
42 if ((Lhud_id = gui_hstack(0)))
44 gui_label(Lhud_id, curr_scr(), GUI_MED, GUI_NE, color[i], gui_wht);
45 gui_label(Lhud_id, "Score", GUI_SML, 0, gui_wht, gui_wht);
46 gui_layout(Lhud_id, -1, -1);
48 if ((Rhud_id = gui_hstack(0)))
50 gui_label(Rhud_id, curr_par(), GUI_MED, 0, color[i], gui_wht);
51 gui_label(Rhud_id, "Par", GUI_SML, GUI_NW, gui_wht, gui_wht);
52 gui_layout(Rhud_id, +1, -1);
54 if ((fps_id = gui_count(0, 1000, GUI_SML, GUI_SE)))
55 gui_layout(fps_id, -1, +1);
58 void hud_free(void)
60 gui_delete(Lhud_id);
61 gui_delete(Rhud_id);
62 gui_delete(fps_id);
65 /*---------------------------------------------------------------------------*/
67 void hud_paint(void)
69 static int fps = 0;
70 static int then = 0;
71 static int count = 0;
73 int now = SDL_GetTicks();
75 if (now - then > 250)
77 fps = count * 1000 / (now - then);
78 then = now;
79 count = 0;
81 gui_set_count(fps_id, fps);
83 else count++;
85 if (config_get_d(CONFIG_FPS))
86 gui_paint(fps_id);
88 gui_paint(Rhud_id);
89 gui_paint(Lhud_id);
92 /*---------------------------------------------------------------------------*/