FreeBASIC  0.91.0
io_mouse.c
Go to the documentation of this file.
1 /* console mode mouse functions */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 
6 static int inited = -1;
7 static int last_x = 0, last_y = 0, last_z = 0, last_buttons = 0;
8 
9 static void ProcessMouseEvent(const MOUSE_EVENT_RECORD *pEvent)
10 {
11  if( pEvent->dwEventFlags == MOUSE_WHEELED ) {
12  last_z += ( ( pEvent->dwButtonState & 0xFF000000 ) ? -1 : 1 );
13  } else {
14  last_x = pEvent->dwMousePosition.X;
15  last_y = pEvent->dwMousePosition.Y;
16  last_buttons = pEvent->dwButtonState & 0x7;
17  }
18 }
19 
20 int fb_ConsoleGetMouse( int *x, int *y, int *z, int *buttons, int *clip )
21 {
22 #if 0
23  INPUT_RECORD ir;
24  DWORD dwRead;
25 #endif
26 
27  DWORD dwMode;
28 
29  if( inited == -1 ) {
30  inited = GetSystemMetrics( SM_CMOUSEBUTTONS );
31  if( inited ) {
32  GetConsoleMode( __fb_in_handle, &dwMode );
33  dwMode |= ENABLE_MOUSE_INPUT;
34  SetConsoleMode( __fb_in_handle, dwMode );
35 #if 1
37 #endif
38  last_x = last_y = 1;
40  }
41  }
42 
43  if( inited == 0 ) {
44  *x = *y = *z = *buttons = -1;
46  }
47 
48  if( inited > 0) {
49  GetConsoleMode( __fb_in_handle, &dwMode );
50  if( !(dwMode & ENABLE_MOUSE_INPUT) )
51  {
52  dwMode |= ENABLE_MOUSE_INPUT;
53  SetConsoleMode( __fb_in_handle, dwMode );
54  }
55  }
56 
57 #if 0
58  if( PeekConsoleInput( __fb_in_handle, &ir, 1, &dwRead ) ) {
59  if( dwRead > 0 ) {
60  ReadConsoleInput( __fb_in_handle, &ir, 1, &dwRead );
61  if( ir.EventType == MOUSE_EVENT ) {
62  ProcessMouseEvent( &ir.Event.MouseEvent );
63  }
64  }
65  }
66 #else
68 #endif
69 
70  *x = last_x - 1;
71  *y = last_y - 1;
72  *z = last_z;
73  *buttons = last_buttons;
74  *clip = 0;
75 
77 
78  return FB_RTERROR_OK;
79 }
80 
81 int fb_ConsoleSetMouse( int x, int y, int cursor, int clip )
82 {
84 }