1 /****************************************************************************
3 * SciTech Multi-platform Graphics Library
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
25 * Environment: QNX Photon GUI
27 * Description: QNX fullscreen console implementation for the SciTech
28 * cross platform event library.
30 ****************************************************************************/
32 /*--------------------------- Global variables ----------------------------*/
34 static ushort keyUpMsg[256] = {0};/* Table of key up messages */
36 /*---------------------------- Implementation -----------------------------*/
38 /* These are not used under Linux */
39 #define _EVT_disableInt() 1
40 #define _EVT_restoreInt(flags)
42 /****************************************************************************
44 scanCode - Scan code to test
47 This macro determines if a specified key is currently down at the
48 time that the call is made.
49 ****************************************************************************/
50 static ibool _EVT_isKeyDown(
53 return (KeyState[(scancode & 0xf8) >> 3] & (1 << (scancode & 0x7)) ?
57 /****************************************************************************
59 Retrieves all events from the mouse/keyboard event queue and stuffs them
60 into the MGL event queue for further processing.
61 ****************************************************************************/
62 static void _EVT_pumpMessages(void)
65 uint msg, but_stat, message;
66 uchar evt[sizeof (PhEvent_t) + 1024];
67 PhEvent_t *event = (void *)evt;
69 PhPointerEvent_t *mouse;
73 while (count < EVENTQSIZE) {
74 uint mods = 0, keyp = 0;
76 pid = Creceive(0, &msg, sizeof (msg));
81 if (PhEventRead(pid, event, sizeof (evt)) == Ph_EVENT_MSG) {
82 memset(&evt, 0, sizeof (evt));
83 if (event->type == Ph_EV_KEY) {
84 key = PhGetData(event);
86 if (key->key_flags & KEY_SCAN_VALID) {
88 if (key->key_flags & KEY_DOWN)
89 KeyState[(keyp & 0xf800) >> 11]
90 |= 1 << ((keyp & 0x700) >> 8);
92 KeyState[(keyp & 0xf800) >> 11]
93 &= ~(1 << ((keyp & 0x700) >> 8));
95 if ((key->key_flags & KEY_SYM_VALID) || extended)
98 /* No way to tell left from right... */
99 if (key->key_mods & KEYMOD_SHIFT)
100 mods = (EVT_LEFTSHIFT | EVT_RIGHTSHIFT);
101 if (key->key_mods & KEYMOD_CTRL)
102 mods |= (EVT_CTRLSTATE | EVT_LEFTCTRL);
103 if (key->key_mods & KEYMOD_ALT)
104 mods |= (EVT_ALTSTATE | EVT_LEFTALT);
106 _evt.when = evt->timestamp;
107 if (key->key_flags & KEY_REPEAT) {
108 _evt.what = EVT_KEYREPEAT;
109 _evt.message = 0x10000;
111 else if (key->key_flags & KEY_DOWN)
112 _evt.what = EVT_KEYDOWN;
114 _evt.what = EVT_KEYUP;
115 _evt.modifiers = mods;
116 _evt.message |= keyp;
120 switch(key->key_scan & 0xff00) {
132 else if (event->type & Ph_EV_PTR_ALL) {
133 but_stat = message = 0;
134 mouse = PhGetData(event);
136 if (mouse->button_state & Ph_BUTTON_3)
137 but_stat = EVT_LEFTBUT;
138 if (mouse->buttons & Ph_BUTTON_3)
139 message = EVT_LEFTBMASK;
141 if (mouse->button_state & Ph_BUTTON_1)
142 but_stat |= EVT_RIGHTBUT;
143 if (mouse->buttons & Ph_BUTTON_1)
144 message |= EVT_RIGHTBMASK;
146 _evt.when = evt->timestamp;
147 if (event->type & Ph_EV_PTR_MOTION) {
148 _evt.what = EVT_MOUSEMOVE;
149 _evt.where_x = mouse->pos.x;
150 _evt.where_y = mouse->pos.y;
151 _evt.modifiers = but_stat;
154 if (event->type & Ph_EV_BUT_PRESS)
155 _evt.what = EVT_MOUSEDOWN;
157 _evt.what = EVT_MOUSEUP;
158 _evt.where_x = mouse->pos.x;
159 _evt.where_y = mouse->pos.y;
160 _evt.modifiers = but_stat;
161 _evt.message = message;
170 /****************************************************************************
172 This macro/function is used to converts the scan codes reported by the
173 keyboard to our event libraries normalised format. We only have one scan
174 code for the 'A' key, and use shift modifiers to determine if it is a
175 Ctrl-F1, Alt-F1 etc. The raw scan codes from the keyboard work this way,
176 but the OS gives us 'cooked' scan codes, we have to translate them back
178 ****************************************************************************/
179 #define _EVT_maskKeyCode(evt)
181 /****************************************************************************
183 Safely abort the event module upon catching a fatal error.
184 ****************************************************************************/
191 sprintf(buf,"Terminating on signal %d",signo);
195 /****************************************************************************
197 mouseMove - Callback function to call wheneve the mouse needs to be moved
200 Initiliase the event handling module. Here we install our mouse handling ISR
201 to be called whenever any button's are pressed or released. We also build
202 the free list of events in the event queue.
204 We use handler number 2 of the mouse libraries interrupt handlers for our
205 event handling routines.
206 ****************************************************************************/
207 void EVTAPI EVT_init(
208 _EVT_mouseMoveHandler mouseMove)
212 /* Initialise the event queue */
213 _mouseMove = mouseMove;
215 memset((void *)KeyState, 0, sizeof (KeyState));
217 /* Catch program termination signals so we can clean up properly */
218 signal(SIGABRT, _EVT_abort);
219 signal(SIGFPE, _EVT_abort);
220 signal(SIGINT, _EVT_abort);
223 /****************************************************************************
225 Changes the range of coordinates returned by the mouse functions to the
226 specified range of values. This is used when changing between graphics
227 modes set the range of mouse coordinates for the new display mode.
228 ****************************************************************************/
229 void EVTAPI EVT_setMouseRange(
233 // TODO: Need to call Input to change the coordinates that it returns
234 // for mouse events!!
237 /****************************************************************************
239 Initiailises the internal event handling modules. The EVT_suspend function
240 can be called to suspend event handling (such as when shelling out to DOS),
241 and this function can be used to resume it again later.
242 ****************************************************************************/
243 void EVT_resume(void)
245 // Do nothing for Photon
248 /****************************************************************************
250 Suspends all of our event handling operations. This is also used to
251 de-install the event handling code.
252 ****************************************************************************/
253 void EVT_suspend(void)
255 // Do nothing for Photon
258 /****************************************************************************
260 Exits the event module for program terminatation.
261 ****************************************************************************/
264 /* Restore signal handlers */
265 signal(SIGABRT, SIG_DFL);
266 signal(SIGFPE, SIG_DFL);
267 signal(SIGINT, SIG_DFL);