Page 1 of 1
AutoStretch + windowMouse
Posted: Sun Feb 06, 2022 8:21 am
by Ampli
Hello!
When I use AutoStretch in OpenWindowedScreen then my sprite dosen't move with the mouse.
I don't know the formula to calculate it.
Any ideas?
Code: Select all
InitSprite()
winId = OpenWindow(#PB_Any, 0, 0, 640, 480, "Test", #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(winId), 0, 0, 640, 480, #True, 0, 0)
ResizeWindow(winId, 0, 0, 1024, 768)
CreateSprite(1, 32, 32)
StartDrawing(SpriteOutput(1))
Box(0, 0, 32, 32, #White)
StopDrawing()
Repeat
event = WindowEvent()
ClearScreen(0)
mx = WindowMouseX(winId)
my = WindowMouseY(winId)
DisplaySprite(1, mx, my)
Delay(1) : FlipBuffers()
Until event = #PB_Event_CloseWindow
Re: AutoStretch + windowMouse
Posted: Sun Feb 06, 2022 8:49 am
by #NULL
You need to process all events per frame. Does that help?
Code: Select all
InitSprite()
winId = OpenWindow(#PB_Any, 0, 0, 640, 480, "Test", #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(winId), 0, 0, 640, 480, #True, 0, 0)
ResizeWindow(winId, 0, 0, 1024, 768)
CreateSprite(1, 32, 32)
StartDrawing(SpriteOutput(1))
Box(0, 0, 32, 32, #White)
StopDrawing()
quit = false
Repeat
Repeat
event = WindowEvent()
Select event
Case #PB_Event_CloseWindow
quit = true
EndSelect
Until Not event
ClearScreen(0)
mx = WindowMouseX(winId)
my = WindowMouseY(winId)
DisplaySprite(1, mx, my)
Delay(1) : FlipBuffers()
Until quit
Re: AutoStretch + windowMouse
Posted: Sun Feb 06, 2022 8:59 am
by Ampli
Hello, No it won't work.
for 1024x768 = 1.6 ish
Code: Select all
mx = WindowMouseX(winId) / 1.6
my = WindowMouseY(winId) / 1.6
I don't know how I can do it with code to calculate it.
Re: AutoStretch + windowMouse
Posted: Sun Feb 06, 2022 10:36 am
by thyphoon
Don't forget DPI function if you use 4K monitor or monitor with not 100% DPI
Code: Select all
mx = DesktopUnscaledX(WindowMouseX(winId)*ScreenWidth()/WindowWidth(winId))
my = DesktopUnscaledY(WindowMouseY(winId)*ScreenHeight()/WindowHeight(winId))
All the code
Code: Select all
InitSprite()
winId = OpenWindow(#PB_Any, 0, 0, 640, 480, "Test", #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(winId), 0, 0, 640, 480, #True, 0, 0)
ResizeWindow(winId, 0, 0, 1024, 768)
CreateSprite(1, 32, 32)
StartDrawing(SpriteOutput(1))
Box(0, 0, 32, 32, #White)
StopDrawing()
quit = false
Repeat
Repeat
event = WindowEvent()
Select event
Case #PB_Event_CloseWindow
quit = true
EndSelect
Until Not event
ClearScreen(0)
mx = DesktopUnscaledX(WindowMouseX(winId)*ScreenWidth()/WindowWidth(winId))
my = DesktopUnscaledY(WindowMouseY(winId)*ScreenHeight()/WindowHeight(winId))
DisplaySprite(1, mx, my)
Delay(1) : FlipBuffers()
Until quit
Re: AutoStretch + windowMouse
Posted: Sun Feb 06, 2022 10:45 am
by Ampli
Perfect, it works great. Thank you so much.