1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.quake;
18
19// Wrapper for native quake application
20
21public class QuakeLib {
22
23    public static final int KEY_PRESS = 1;
24    public static final int KEY_RELEASE = 0;
25
26    public static final int MOTION_DOWN = 0;
27    public static final int MOTION_UP = 1;
28    public static final int MOTION_MOVE = 2;
29    public static final int MOTION_CANCEL = 3;
30
31    // copied from Quake keys.h
32    // these are the key numbers that should be passed to Key_Event
33    //
34    //
35    // these are the key numbers that should be passed to Key_Event
36    //
37     public static final int K_TAB           = 9;
38     public static final int K_ENTER         = 13;
39     public static final int K_ESCAPE        = 27;
40     public static final int K_SPACE         = 32;
41
42     // normal keys should be passed as lowercased ascii
43
44     public static final int K_BACKSPACE     = 127;
45     public static final int K_UPARROW       = 128;
46     public static final int K_DOWNARROW     = 129;
47     public static final int K_LEFTARROW     = 130;
48     public static final int K_RIGHTARROW    = 131;
49
50     public static final int K_ALT           = 132;
51     public static final int K_CTRL          = 133;
52     public static final int K_SHIFT         = 134;
53     public static final int K_F1            = 135;
54     public static final int K_F2            = 136;
55     public static final int K_F3            = 137;
56     public static final int K_F4            = 138;
57     public static final int K_F5            = 139;
58     public static final int K_F6            = 140;
59     public static final int K_F7            = 141;
60     public static final int K_F8            = 142;
61     public static final int K_F9            = 143;
62     public static final int K_F10           = 144;
63     public static final int K_F11           = 145;
64     public static final int K_F12           = 146;
65     public static final int K_INS           = 147;
66     public static final int K_DEL           = 148;
67     public static final int K_PGDN          = 149;
68     public static final int K_PGUP          = 150;
69     public static final int K_HOME          = 151;
70     public static final int K_END           = 152;
71
72     public static final int K_PAUSE         = 255;
73
74     //
75     // mouse buttons generate virtual keys
76     //
77     public static final int K_MOUSE1        = 200;
78     public static final int K_MOUSE2        = 201;
79     public static final int K_MOUSE3        = 202;
80
81     //
82     // joystick buttons
83     //
84     public static final int K_JOY1          = 203;
85     public static final int K_JOY2          = 204;
86     public static final int K_JOY3          = 205;
87     public static final int K_JOY4          = 206;
88
89     //
90     // aux keys are for multi-buttoned joysticks to generate so they can use
91     // the normal binding process
92     //
93     public static final int K_AUX1          = 207;
94     public static final int K_AUX2          = 208;
95     public static final int K_AUX3          = 209;
96     public static final int K_AUX4          = 210;
97     public static final int K_AUX5          = 211;
98     public static final int K_AUX6          = 212;
99     public static final int K_AUX7          = 213;
100     public static final int K_AUX8          = 214;
101     public static final int K_AUX9          = 215;
102     public static final int K_AUX10         = 216;
103     public static final int K_AUX11         = 217;
104     public static final int K_AUX12         = 218;
105     public static final int K_AUX13         = 219;
106     public static final int K_AUX14         = 220;
107     public static final int K_AUX15         = 221;
108     public static final int K_AUX16         = 222;
109     public static final int K_AUX17         = 223;
110     public static final int K_AUX18         = 224;
111     public static final int K_AUX19         = 225;
112     public static final int K_AUX20         = 226;
113     public static final int K_AUX21         = 227;
114     public static final int K_AUX22         = 228;
115     public static final int K_AUX23         = 229;
116     public static final int K_AUX24         = 230;
117     public static final int K_AUX25         = 231;
118     public static final int K_AUX26         = 232;
119     public static final int K_AUX27         = 233;
120     public static final int K_AUX28         = 234;
121     public static final int K_AUX29         = 235;
122     public static final int K_AUX30         = 236;
123     public static final int K_AUX31         = 237;
124     public static final int K_AUX32         = 238;
125
126     // JACK: Intellimouse(c) Mouse Wheel Support
127
128     public static final int K_MWHEELUP      = 239;
129     public static final int K_MWHEELDOWN    = 240;
130
131     static {
132         System.loadLibrary("quake");
133     }
134
135     public QuakeLib() {
136     }
137
138     public native boolean init();
139
140    /**
141     * Used to report key events
142     * @param type KEY_PRESS or KEY_RELEASE
143     * @param value the key code.
144     * @return true if the event was handled.
145     */
146     public native boolean event(int type, int value);
147
148    /**
149     * Used to report touch-screen events
150     * @param eventTime the time the event happened
151     * @param action the kind of action being performed -- one of either
152     * {@link #MOTION_DOWN}, {@link #MOTION_MOVE}, {@link #MOTION_UP},
153     * or {@link #MOTION_CANCEL}
154     * @param x the x coordinate in pixels
155     * @param y the y coordinate in pixels
156     * @param pressure the pressure 0..1, can be more than 1 sometimes
157     * @param size the size of the area pressed (radius in X or Y)
158     * @param deviceId the id of the device generating the events
159     * @return true if the event was handled.
160     */
161     public native boolean motionEvent(long eventTime, int action,
162            float x, float y, float pressure, float size, int deviceId);
163
164     /**
165      * Used to report trackball events
166      * @param eventTime the time the event happened
167      * @param action the kind of action being performed -- one of either
168      * {@link #MOTION_DOWN}, {@link #MOTION_MOVE}, {@link #MOTION_UP},
169      * or {@link #MOTION_CANCEL}
170      * @param x the x motion in pixels
171      * @param y the y motion in pixels
172      * @return true if the event was handled.
173      */
174     public native boolean trackballEvent(long eventTime, int action,
175             float x, float y);
176    /**
177     * @param width the current view width
178     * @param height the current view height
179     * @return true if quake is in "game" mode, false if it is in "menu" or
180     * "typing" mode.
181     */
182     public native boolean step(int width, int height);
183
184     /**
185      * Tell Quake to quit. It will write out its config files and so forth.
186      */
187     public native void quit();
188}
189