1 //  This may look like C code, but it is really -*- C++ -*-
2 
3 //  ------------------------------------------------------------------
4 //  The Goldware Library
5 //  Copyright (C) 1990-1999 Odinn Sorensen
6 //  ------------------------------------------------------------------
7 //  This library is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU Library General Public
9 //  License as published by the Free Software Foundation; either
10 //  version 2 of the License, or (at your option) any later version.
11 //
12 //  This library is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  Library General Public License for more details.
16 //
17 //  You should have received a copy of the GNU Library General Public
18 //  License along with this program; if not, write to the Free
19 //  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 //  MA 02111-1307, USA
21 //  ------------------------------------------------------------------
22 //  $Id: gmoubase.cpp,v 1.1 2011/02/18 19:46:01 stas_degteff Exp $
23 //  ------------------------------------------------------------------
24 //  GCUI: Golded+ Character-oriented User Interface.
25 //  Mousing: class GMou member functions implementation.
26 //  ------------------------------------------------------------------
27 
28 #include <gmemall.h>
29 #include <gvidall.h>
30 #include <gmoubase.h>
31 
32 
33 //  ------------------------------------------------------------------
34 
35 #ifdef GOLD_MOUSE
36 
37 //  ------------------------------------------------------------------
38 
39 GMou gmou;
40 
41 
42 //  ------------------------------------------------------------------
43 
GMou()44 GMou::GMou() {
45 
46   detected = false;
47   Reset();
48 }
49 
50 
51 //  ------------------------------------------------------------------
52 
~GMou()53 GMou::~GMou() {
54 
55   Reset();
56 }
57 
58 
59 //  ------------------------------------------------------------------
60 
SetLevel(int __level)61 void GMou::SetLevel(int __level) {
62 
63   if(detected) {
64     level = __level;
65     if(level < GMOU_LEVEL_NONE)
66       level = GMOU_LEVEL_NONE;
67     else if(level > GMOU_LEVEL_FULL)
68       level = GMOU_LEVEL_FULL;
69   }
70   else {
71     level = GMOU_LEVEL_NONE;
72   }
73 }
74 
75 
76 //  ------------------------------------------------------------------
77 
Reset()78 void GMou::Reset() {
79 
80   level = GMOU_LEVEL_NONE;
81   hidden = 1;
82   hit.button = 0;
83   hit.count = 0;
84   hit.row = 0;
85   hit.column = 0;
86   if(detected)
87     Init();
88 }
89 
90 
91 //  ------------------------------------------------------------------
92 //  ------------------------------------------------------------------
93 //  DOS MOUSING - BEGIN
94 //  ------------------------------------------------------------------
95 //  ------------------------------------------------------------------
96 
97 #if defined(__MSDOS__)
98 
99 
100 //  ------------------------------------------------------------------
101 
Init()102 void GMou::Init() {
103 
104   i86 cpu;
105   cpu.ax(MSMOUSE_RESET_DRIVER);
106   cpu.genint(MSMOUSE_INT);
107   if(cpu.ax())
108     detected = true;
109 }
110 
111 
112 //  ------------------------------------------------------------------
113 
ClearEvents()114 void GMou::ClearEvents() {
115 
116   if(level) {
117     i86 cpu;
118     cpu.ax(MSMOUSE_GET_BUTTON_PRESS);
119     cpu.bx(GMOU_LEFT_BUTTON);
120     cpu.genint(MSMOUSE_INT);
121     cpu.ax(MSMOUSE_GET_BUTTON_PRESS);
122     cpu.bx(GMOU_RIGHT_BUTTON);
123     cpu.genint(MSMOUSE_INT);
124     cpu.ax(MSMOUSE_GET_BUTTON_RELEASE);
125     cpu.bx(GMOU_LEFT_BUTTON);
126     cpu.genint(MSMOUSE_INT);
127     cpu.ax(MSMOUSE_GET_BUTTON_RELEASE);
128     cpu.bx(GMOU_RIGHT_BUTTON);
129     cpu.genint(MSMOUSE_INT);
130   }
131 }
132 
133 
134 //  ------------------------------------------------------------------
135 
GetStatus()136 void GMou::GetStatus() {
137 
138   if(level) {
139     i86 cpu;
140     cpu.ax(MSMOUSE_GET_BUTTONS_AND_POSITION);
141     cpu.genint(MSMOUSE_INT);
142     hit.button = cpu.bx();
143     hit.count  = 0;
144     hit.column = cpu.cx() / gvid->curr.screen.cwidth;
145     hit.row    = cpu.dx() / gvid->curr.screen.cheight;
146   }
147 }
148 
149 
150 //  ------------------------------------------------------------------
151 
GetPress(int __button)152 void GMou::GetPress(int __button) {
153 
154   if(level) {
155     i86 cpu;
156     cpu.ax(MSMOUSE_GET_BUTTON_PRESS);
157     cpu.bx((word)__button);
158     cpu.genint(MSMOUSE_INT);
159     hit.button = cpu.ax();
160     hit.count  = cpu.bx();
161     hit.column = cpu.cx() / gvid->curr.screen.cwidth;
162     hit.row    = cpu.dx() / gvid->curr.screen.cheight;
163   }
164 }
165 
166 
167 //  ------------------------------------------------------------------
168 
GetRelease(int __button)169 void GMou::GetRelease(int __button) {
170 
171   if(level) {
172     i86 cpu;
173     cpu.ax(MSMOUSE_GET_BUTTON_RELEASE);
174     cpu.bx((word)__button);
175     cpu.genint(MSMOUSE_INT);
176     hit.button = cpu.ax();
177     hit.count  = cpu.bx();
178     hit.column = cpu.cx() / gvid->curr.screen.cwidth;
179     hit.row    = cpu.dx() / gvid->curr.screen.cheight;
180   }
181 }
182 
183 
184 //  ------------------------------------------------------------------
185 
SetCursor(int __curtype,int __smask,int __cmask)186 void GMou::SetCursor(int __curtype, int __smask, int __cmask) {
187 
188   if(level) {
189     i86 cpu;
190     cpu.ax(MSMOUSE_SET_TEXT_CURSOR);
191     cpu.bx((word)__curtype);
192     cpu.cx((word)__smask);
193     cpu.dx((word)__cmask);
194     cpu.genint(MSMOUSE_INT);
195   }
196 }
197 
198 
199 //  ------------------------------------------------------------------
200 
SetPosition(int __row,int __col)201 void GMou::SetPosition(int __row, int __col) {
202 
203   if(level) {
204     i86 cpu;
205     cpu.ax(MSMOUSE_SET_CURSOR_POSITION);
206     cpu.cx((word)(__col * gvid->curr.screen.cwidth));
207     cpu.dx((word)(__row * gvid->curr.screen.cheight));
208     cpu.genint(MSMOUSE_INT);
209   }
210 }
211 
212 
213 //  ------------------------------------------------------------------
214 
HideCursor()215 void GMou::HideCursor() {
216 
217   if(level) {
218     if(not hidden) {
219       i86 cpu;
220       cpu.ax(MSMOUSE_HIDE_CURSOR);
221       cpu.genint(MSMOUSE_INT);
222       hidden = true;
223     }
224   }
225 }
226 
227 
228 //  ------------------------------------------------------------------
229 
ShowCursor()230 void GMou::ShowCursor() {
231 
232   if(level) {
233     i86 cpu;
234     cpu.ax(MSMOUSE_SHOW_CURSOR);
235     cpu.genint(MSMOUSE_INT);
236     hidden = false;
237   }
238 }
239 
240 
241 //  ------------------------------------------------------------------
242 //  ------------------------------------------------------------------
243 //  DOS MOUSING - END
244 //  ------------------------------------------------------------------
245 //  ------------------------------------------------------------------
246 
247 #endif
248 
249 
250 //  ------------------------------------------------------------------
251 //  ------------------------------------------------------------------
252 //  OS/2 MOUSING - BEGIN
253 //  ------------------------------------------------------------------
254 //  ------------------------------------------------------------------
255 
256 #if defined(__OS2__)
257 
258 
259 //  ------------------------------------------------------------------
260 
Init()261 void GMou::Init() {
262 
263   #if 0
264   if(MouOpen(NULL, &hmou) == 0) {
265     USHORT _mask = MOUSE_BN1_DOWN|MOUSE_BN2_DOWN|MOUSE_BN3_DOWN;
266     MouSetEventMask(&_mask, hmou);
267     detected = true;
268   }
269   #endif
270 }
271 
272 
273 //  ------------------------------------------------------------------
274 
ClearEvents()275 void GMou::ClearEvents() {
276 
277   if(level) {
278     MouFlushQue(hmou);
279   }
280 }
281 
282 
283 //  ------------------------------------------------------------------
284 
GetStatus()285 void GMou::GetStatus() {
286 
287   if(level) {
288     PTRLOC _pos;
289     MouGetPtrPos(&_pos, hmou);
290     hit.button = 0;
291     hit.count  = 0;
292     hit.column = _pos.col;
293     hit.row    = _pos.row;
294     MOUEVENTINFO _event;
295     USHORT _wait = MOU_NOWAIT;
296     if(MouReadEventQue(&_event, &_wait, hmou) == 0) {
297       if(_event.fs & (MOUSE_BN1_DOWN|MOUSE_MOTION_WITH_BN1_DOWN))
298         hit.button |= GMOU_LEFT_PRESSED;
299       if(_event.fs & (MOUSE_BN2_DOWN|MOUSE_MOTION_WITH_BN2_DOWN))
300         hit.button |= GMOU_RIGHT_PRESSED;
301       if(_event.fs & (MOUSE_BN3_DOWN|MOUSE_MOTION_WITH_BN3_DOWN))
302         hit.button |= GMOU_MIDDLE_PRESSED;
303     }
304   }
305 }
306 
307 
308 //  ------------------------------------------------------------------
309 
GetPress(int __button)310 void GMou::GetPress(int __button) {
311 
312   NW(__button);
313   #if 0
314   if(level) {
315     hit.button = 0;
316     hit.count  = 0;
317     hit.column = 0;
318     hit.row    = 0;
319     MOUQUEINFO _que;
320     MouGetNumQueEl(&_que, hmou);
321     hit.count = _que.cEvents;
322     if(hit.count) {
323       MOUEVENTINFO _event;
324       USHORT _wait = MOU_WAIT;
325       if(MouReadEventQue(&_event, &_wait, hmou) == 0) {
326         if(_event.fs & (MOUSE_BN1_DOWN|MOUSE_MOTION_WITH_BN1_DOWN))
327           hit.button |= GMOU_LEFT_PRESSED;
328         if(_event.fs & (MOUSE_BN2_DOWN|MOUSE_MOTION_WITH_BN2_DOWN))
329           hit.button |= GMOU_RIGHT_PRESSED;
330         if(_event.fs & (MOUSE_BN3_DOWN|MOUSE_MOTION_WITH_BN3_DOWN))
331           hit.button |= GMOU_MIDDLE_PRESSED;
332         hit.column = _event.col;
333         hit.row = _event.row;
334       }
335     }
336   }
337   #endif
338 }
339 
340 
341 //  ------------------------------------------------------------------
342 
GetRelease(int __button)343 void GMou::GetRelease(int __button) {
344 
345   NW(__button);
346   #if 0
347   if(level) {
348     hit.button = 0;
349     hit.count  = 0;
350     hit.column = 0;
351     hit.row    = 0;
352     MOUQUEINFO _que;
353     MouGetNumQueEl(&_que, hmou);
354     hit.count = _que.cEvents;
355     if(hit.count) {
356       MOUEVENTINFO _event;
357       USHORT _wait = MOU_WAIT;
358       if(MouReadEventQue(&_event, &_wait, hmou) == 0) {
359         if(_event.fs & (MOUSE_BN1_DOWN|MOUSE_MOTION_WITH_BN1_DOWN))
360           hit.button |= GMOU_LEFT_PRESSED;
361         if(_event.fs & (MOUSE_BN2_DOWN|MOUSE_MOTION_WITH_BN2_DOWN))
362           hit.button |= GMOU_RIGHT_PRESSED;
363         if(_event.fs & (MOUSE_BN3_DOWN|MOUSE_MOTION_WITH_BN3_DOWN))
364           hit.button |= GMOU_MIDDLE_PRESSED;
365         hit.column = _event.col;
366         hit.row = _event.row;
367       }
368     }
369   }
370   #endif
371 }
372 
373 
374 //  ------------------------------------------------------------------
375 
SetCursor(int __curtype,int __smask,int __cmask)376 void GMou::SetCursor(int __curtype, int __smask, int __cmask) {
377 
378   if(level) {
379     // Not implemented yet
380     NW(__curtype);
381     NW(__smask);
382     NW(__cmask);
383   }
384 }
385 
386 
387 //  ------------------------------------------------------------------
388 
SetPosition(int __row,int __col)389 void GMou::SetPosition(int __row, int __col) {
390 
391   if(level) {
392     PTRLOC _pos;
393     _pos.row = (USHORT)__row;
394     _pos.col = (USHORT)__col;
395     MouSetPtrPos(&_pos, hmou);
396   }
397 }
398 
399 
400 //  ------------------------------------------------------------------
401 
HideCursor()402 void GMou::HideCursor() {
403 
404   if(level) {
405     if(not hidden) {
406       NOPTRRECT _rect;
407       _rect.row = 0;
408       _rect.col = 0;
409       _rect.cRow = (USHORT)(gvid->curr.screen.rows-1);
410       _rect.cCol = (USHORT)(gvid->curr.screen.columns-1);
411       MouRemovePtr(&_rect, hmou);
412       hidden = true;
413     }
414   }
415 }
416 
417 
418 //  ------------------------------------------------------------------
419 
ShowCursor()420 void GMou::ShowCursor() {
421 
422   if(level) {
423     MouDrawPtr(hmou);
424     hidden = false;
425   }
426 }
427 
428 
429 //  ------------------------------------------------------------------
430 //  ------------------------------------------------------------------
431 //  OS/2 MOUSING - END
432 //  ------------------------------------------------------------------
433 //  ------------------------------------------------------------------
434 
435 #endif
436 
437 
438 //  ------------------------------------------------------------------
439 //  Dummy definitions when mouse support is not defined
440 
Init()441 void GMou::Init() {}
ClearEvents()442 void GMou::ClearEvents() {}
GetStatus()443 void GMou::GetStatus() {}
GetPress(int)444 void GMou::GetPress(int) {}
GetRelease(int)445 void GMou::GetRelease(int) {}
SetCursor(int,int,int)446 void GMou::SetCursor(int, int, int) {}
SetPosition(int,int)447 void GMou::SetPosition(int, int) {}
HideCursor()448 void GMou::HideCursor() {}
ShowCursor()449 void GMou::ShowCursor() {}
450 
451 
452 //  ------------------------------------------------------------------
453 
454 #endif // GOLD_MOUSE
455 
456 //  ------------------------------------------------------------------
457