share/gui: don't use less of widget width for truncation than available
[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 #include "video.h"
19
20 /*---------------------------------------------------------------------------*/
21
22 static float         state_time;
23 static int           state_drawn;
24 static struct state *state;
25
26 struct state *curr_state(void)
27 {
28     return state;
29 }
30
31 float time_state(void)
32 {
33     return state_time;
34 }
35
36 void init_state(struct state *st)
37 {
38     state = st;
39 }
40
41 int goto_state(struct state *st)
42 {
43     if (state && state->leave)
44         state->leave(state->gui_id);
45
46     state       = st;
47     state_time  = 0;
48     state_drawn = 0;
49
50     if (state && state->enter)
51         state->gui_id = state->enter();
52
53     return 1;
54 }
55
56 /*---------------------------------------------------------------------------*/
57
58 void st_paint(float t)
59 {
60     int stereo = config_get_d(CONFIG_STEREO);
61
62     state_drawn = 1;
63
64     if (state && state->paint)
65     {
66         if (stereo)
67         {
68             glDrawBuffer(GL_BACK_LEFT);
69             video_clear();
70             state->paint(state->gui_id, t);
71
72             glDrawBuffer(GL_BACK_RIGHT);
73             video_clear();
74             state->paint(state->gui_id, t);
75         }
76         else
77         {
78             video_clear();
79             state->paint(state->gui_id, t);
80         }
81     }
82 }
83
84 void st_timer(float dt)
85 {
86     if (!state_drawn)
87         return;
88
89     state_time += dt;
90
91     if (state && state->timer)
92         state->timer(state->gui_id, dt);
93 }
94
95 void st_point(int x, int y, int dx, int dy)
96 {
97     if (state && state->point)
98         state->point(state->gui_id, x, y, dx, dy);
99 }
100
101 void st_stick(int a, int k)
102 {
103     if (state && state->stick)
104         state->stick(state->gui_id, a, k);
105 }
106
107 void st_angle(int x, int z)
108 {
109     if (state && state->angle)
110         state->angle(state->gui_id, x, z);
111 }
112
113 /*---------------------------------------------------------------------------*/
114
115 int st_click(int b, int d)
116 {
117     return (state && state->click) ? state->click(b, d) : 1;
118 }
119
120 int st_keybd(int c, int d)
121 {
122     return (state && state->keybd) ? state->keybd(c, d) : 1;
123 }
124
125 int st_buttn(int b, int d)
126 {
127     return (state && state->buttn) ? state->buttn(b, d) : 1;
128 }
129
130 /*---------------------------------------------------------------------------*/