Merged branch utf8.
[neverball] / ball / st_shared.c
1 /*
2  * Copyright (C) 2003 Robert Kooima - 2006 Jean Privat
3  * Part of the Neverball Project http://icculus.org/neverball/
4  *
5  * NEVERBALL is  free software; you can redistribute  it and/or modify
6  * it under the  terms of the GNU General  Public License as published
7  * by the Free  Software Foundation; either version 2  of the License,
8  * or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
12  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
13  * General Public License for more details.
14  */
15
16 #include "gui.h"
17 #include "config.h"
18 #include "audio.h"
19 #include "game.h"
20 #include "state.h"
21
22 #include "st_shared.h"
23
24 void shared_leave(int id)
25 {
26     gui_delete(id);
27 }
28
29 void shared_paint(int id, float st)
30 {
31     game_draw(0, st);
32     gui_paint(id);
33 }
34
35 void shared_timer(int id, float dt)
36 {
37     gui_timer(id, dt);
38     audio_timer(dt);
39 }
40
41 /* Pulse, activate and return the active id (if changed)*/
42
43 int shared_point_basic(int id, int x, int y)
44 {
45     int jd = gui_point(id, x, y);
46     if (jd)
47         gui_pulse(jd, 1.2f);
48     return jd;
49 }
50
51 void shared_point(int id, int x, int y, int dx, int dy)
52 {
53     shared_point_basic(id, x, y);
54 }
55
56 int shared_stick_basic(int id, int a, int v)
57 /* Pulse, activate and return the active id (if changed)*/
58 {
59     int jd = 0;
60     if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
61         jd = gui_stick(id, v, 0);
62     else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
63         jd = gui_stick(id, 0, v);
64     if (jd)
65         gui_pulse(jd, 1.2f);
66     return jd;
67 }
68
69 void shared_stick(int id, int a, int v)
70 {
71     shared_stick_basic(id, a, v);
72 }
73
74 int shared_click(int b, int d)
75 {
76     if (b < 0 && d == 1)
77         return st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1);
78     else
79         return 1;
80 }
81