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