s/TRANSLATORS/Translators/ in xgettext comments
[neverball] / share / state.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERBALL 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.
8  *
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.
13  */
14
15 #include "glext.h"
16 #include "state.h"
17 #include "config.h"
18
19 /*---------------------------------------------------------------------------*/
20
21 static float  state_time;
22 static struct state *state;
23
24 struct state *curr_state(void)
25 {
26     return state;
27 }
28
29 float time_state(void)
30 {
31     return state_time;
32 }
33
34 void init_state(struct state *st)
35 {
36     state = st;
37 }
38
39 int goto_state(struct state *st)
40 {
41     if (state && state->leave)
42         state->leave(state->gui_id);
43
44     state      = st;
45     state_time =  0;
46
47     if (state && state->enter)
48         state->gui_id = state->enter();
49
50     return 1;
51 }
52
53 /*---------------------------------------------------------------------------*/
54
55 void st_paint(float t)
56 {
57     int stereo = config_get_d(CONFIG_STEREO);
58
59     if (state && state->paint)
60     {
61         if (stereo)
62         {
63             glDrawBuffer(GL_BACK_LEFT);
64             config_clear();
65             state->paint(state->gui_id, t);
66
67             glDrawBuffer(GL_BACK_RIGHT);
68             config_clear();
69             state->paint(state->gui_id, t);
70         }
71         else
72         {
73             config_clear();
74             state->paint(state->gui_id, t);
75         }
76     }
77 }
78
79 void st_timer(float dt)
80 {
81     state_time += dt;
82
83     if (state && state->timer)
84         state->timer(state->gui_id, dt);
85 }
86
87 void st_point(int x, int y, int dx, int dy)
88 {
89     if (state && state->point)
90         state->point(state->gui_id, x, y, dx, dy);
91 }
92
93 void st_stick(int a, int k)
94 {
95     if (state && state->stick)
96         state->stick(state->gui_id, a, k);
97 }
98
99 void st_angle(int x, int z)
100 {
101     if (state && state->angle)
102         state->angle(state->gui_id, x, z);
103 }
104
105 /*---------------------------------------------------------------------------*/
106
107 int st_click(int b, int d)
108 {
109     return (state && state->click) ? state->click(b, d) : 1;
110 }
111
112 int st_keybd(int c, int d)
113 {
114     return (state && state->keybd) ? state->keybd(c, d) : 1;
115 }
116
117 int st_buttn(int b, int d)
118 {
119     return (state && state->buttn) ? state->buttn(b, d) : 1;
120 }
121
122 /*---------------------------------------------------------------------------*/