Page 1 of 1
mouse outside windowed screen?
Posted: Wed Aug 18, 2004 6:04 am
by Dreglor
i was making a simple game
the proablem is that when windowed screen is initalized the mouse is captured and hidden although i can display the mouse it doesn't go outside the screen i want it to be able to interact with the window
i can always use the WindowMouse commands to get mouse x and y inside the screen so thats not a problem
Posted: Wed Aug 18, 2004 7:19 am
by fweil
Dreglor,
I guess having posted this foprmerly, .... this should help you :
Code: Select all
#Window_Main = 0
#Status_Bar = 0
Quit = #FALSE
If InitSprite()
If InitKeyboard()
If InitMouse()
WindowXSize = 800
WindowYSize = 600
If OpenWindow(#Window_Main,0,0,WindowXSize,WindowYSize,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered,"demo")
If CreateGadgetList(WindowID())
EndIf
If CreateStatusBar(#Status_Bar, WindowID())
WindowedScreenBottomMargin + 20
EndIf
hCursor1 = LoadCursor_(0, #IDC_ARROW)
hCursor2 = LoadCursor_(0, #IDC_CROSS)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
WindowedScreenXSize = 640
WindowedScreenYSize = 480
If OpenWindowedScreen(WindowID(),WindowXSize - WindowedScreenXSize, WindowYSize - WindowedScreenYSize - WindowedScreenBottomMargin,WindowedScreenXSize,WindowedScreenYSize,0,0,0)
SetFrameRate(60)
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
Quit = #TRUE
Case #PB_Event_Menu
Select EventMenuID()
Case #PB_Shortcut_Escape
Quit = #TRUE
EndSelect
Case #PB_Event_Gadget
EndSelect
; GetCursorPos_(CursorPosition.POINT) - 20
MouseX = WindowMouseX() ; CursorPosition\x - WindowX()
MouseY = WindowMouseY() + 20 ; CursorPosition\y - WindowY()
If MouseX >= WindowXSize - WindowedScreenXSize And MouseX <= WindowXSize And MouseY >= WindowYSize - WindowedScreenYSize And MouseY <= WindowYSize
SetCursor_(hCursor2)
Else
SetCursor_(hCursor1)
EndIf
FlipBuffers()
ClearScreen($00, $00, $30)
StartDrawing(ScreenOutput())
FrontColor($FF, $FF, $C0)
Locate(10,200)
DrawingMode(1)
DrawText("Mouse X/Y=("+Str(MouseX)+","+Str(MouseY)+")")
If MouseX >= WindowXSize - WindowedScreenXSize And MouseX <= WindowXSize And MouseY >= WindowYSize - WindowedScreenYSize And MouseY <= WindowYSize
Locate(10,220)
DrawText("Cursor in")
Else
Locate(10,220)
DrawText("Cursor out")
EndIf
StopDrawing()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Quit = #TRUE
EndIf
Delay(10)
Until Quit
Else
MessageRequester("Error", "Can't open the main windowedscreen", 0)
EndIf
Else
MessageRequester("Error", "Can't open the main window", 0)
EndIf
Else
MessageRequester("Error", "Can't init mouse", 0)
EndIf
Else
MessageRequester("Error", "Can't init leyboard", 0)
EndIf
Else
MessageRequester("Error", "Can't init sprites", 0)
EndIf
End