AutoStretch + windowMouse

Just starting out? Need help? Post your questions and find answers here.
Ampli
User
User
Posts: 54
Joined: Sun Jul 29, 2007 7:05 pm
Location: Sweden

AutoStretch + windowMouse

Post 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
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: AutoStretch + windowMouse

Post 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
Ampli
User
User
Posts: 54
Joined: Sun Jul 29, 2007 7:05 pm
Location: Sweden

Re: AutoStretch + windowMouse

Post 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.
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 345
Joined: Sat Dec 25, 2004 2:37 pm

Re: AutoStretch + windowMouse

Post 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
Ampli
User
User
Posts: 54
Joined: Sun Jul 29, 2007 7:05 pm
Location: Sweden

Re: AutoStretch + windowMouse

Post by Ampli »

Perfect, it works great. Thank you so much.
Post Reply