Page 1 of 1

WindowedScreen question

Posted: Wed Jan 15, 2025 4:15 pm
by Catdaddy
So, the basic idea for this program is to open a borderless window to the dimensions of the current desktop. This is so I don't have to deal with changing resolutions with a full graphic screen. Then, at some point in the bigger program I would like to have a procedure that I could call that creates a WindowedScreen within the window that will bounce a sprite around the screen. Everything works fine except... while the sprite is moving around the screen, the mouse pointer continually spins without disappearing. Also, if I click a mouse button the program crashes. I'm not as familiar with windowed coding as I'd like to be, and the code is really messy, but if anyone could explain what I;m doing wrong I would be grateful. Thank you.

Code: Select all

ExamineDesktops()
InitSprite()
InitKeyboard()


Global Window_0.i


Procedure OutOfService()
	#Font = 0
	#Sprite = 0
	Define Quit.b = #False
	Define ScreenH.i = DesktopHeight(0)
	Define ScreenW.i = DesktopWidth(0)
	Define Text.s = "Out Of Service"
	Define x.i = 1
	Define y.i = 1
	Define xd.i = 1
	Define yd.i = 1
	Define SpriteH.i
	Define SpriteW.i
	Define TWidth.i
	Define THeight.i
	Define TextFont.i = LoadFont(#Font, "Tahoma", 32, #PB_Font_Bold)
	
	
	If OpenWindowedScreen(WindowID(Window_0), 0, 0, ScreenW, ScreenH) = 0
		End
	EndIf
	
	
	ClearScreen(RGB(0,0,0))
	StartDrawing(ScreenOutput()) 
	DrawingMode(#PB_2DDrawing_Transparent)
	DrawingFont(Textfont) 
	DrawText(0, 0, Text, #White, #Black)
	TWidth = TextWidth(Text)
	THeight = TextHeight(Text)
	StopDrawing() 
	
	
	GrabSprite(#Sprite, 0, 0, TWidth, THeight, #PB_Sprite_PixelCollision)
	SpriteH = SpriteHeight(#Sprite)
	SpriteW = SpriteWidth(#Sprite)
	
	
	Repeat
		ClearScreen(RGB(0, 0, 0))
		DisplaySprite(#Sprite, x, y)
		x=x+xd:y=y+yd
		
		If y>ScreenH - SpriteH 
			yd=-1
		EndIf
		
		If x>ScreenW - SpriteW  
			xd=-1	
		EndIf
		
		If y<0
			yd=1
		EndIf
		
		If X<0
			xd=1
		EndIf	
		
		FlipBuffers()
		ExamineKeyboard()
		
		Delay(1)
	Until KeyboardPushed(#PB_Key_Escape)
	
	FreeSprite(#Sprite)
	CloseScreen()
EndProcedure



Width = DesktopWidth(0)
Height = DesktopHeight(0)
Depth = DesktopDepth(0)


; Create borderless window with above measurements and black background.
Window_0 = OpenWindow(#PB_Any, 0, 0, Width, Height, "", #PB_Window_BorderLess)
SetWindowColor(Window_0, RGB(0,0,0))
OutOfService()

Re: WindowedScreen question

Posted: Wed Jan 15, 2025 4:30 pm
by firace
Hi,
Your code is missing a window loop for Window_0.
You need to handle WindowEvent().
See the built-in help for OpenWindowedScreen() for an example:

Code: Select all

   ; It's very important to process all the events remaining in the queue at each frame

Re: WindowedScreen question

Posted: Wed Jan 15, 2025 4:51 pm
by infratec

Code: Select all

  Repeat
    Repeat
      Event = WindowEvent()
    Until Event = 0
  
    ClearScreen(RGB(0, 0, 0))

Re: WindowedScreen question

Posted: Wed Jan 15, 2025 4:55 pm
by AnC
You can also hide the cursor with ShowCursor_(0)

Re: WindowedScreen question

Posted: Wed Jan 15, 2025 11:04 pm
by Catdaddy
firace - In my haste I overlooked this part in the manual. Is it because the events pile up and eventually crash the program?

infratec - Worked like a charm.

AnC - That definitely helped. I'm used to a regular full graphic screen where the cursor automatically goes away.

Thank you to all for your help.

Re: WindowedScreen question

Posted: Thu Jan 16, 2025 12:55 am
by Catdaddy
I may have spoken too soon. ShowCursor_(0) does not seem to work. I've tried ShowCursor_(-1), ShowCursor_(#FALSE). I've even tried SetCursor_(#NULL). Is it not possible to disable the mouse pointer in Windows?

Re: WindowedScreen question

Posted: Thu Jan 16, 2025 1:13 am
by Otrebor
What help me in my program is repeat the line:

Code: Select all

      ShowCursor_(0)
      ShowCursor_(0)

Re: WindowedScreen question

Posted: Thu Jan 16, 2025 1:23 am
by miso
Is it not possible to disable the mouse pointer in Windows?
You can also switch to hardware mouse:

Code: Select all

ExamineDesktops()
InitSprite()
InitKeyboard()
InitMouse()

Global Window_0.i


Procedure OutOfService()
	#Font = 0
	#Sprite = 0
	Define Quit.b = #False
	Define ScreenH.i = DesktopHeight(0)
	Define ScreenW.i = DesktopWidth(0)
	Define Text.s = "Out Of Service"
	Define x.i = 1
	Define y.i = 1
	Define xd.i = 1
	Define yd.i = 1
	Define SpriteH.i
	Define SpriteW.i
	Define TWidth.i
	Define THeight.i
	Define TextFont.i = LoadFont(#Font, "Tahoma", 32, #PB_Font_Bold)
	
	
	If OpenWindowedScreen(WindowID(Window_0), 0, 0, ScreenW, ScreenH) = 0
		End
	EndIf
	
	
	ClearScreen(RGB(0,0,0))
	StartDrawing(ScreenOutput()) 
	DrawingMode(#PB_2DDrawing_Transparent)
	DrawingFont(Textfont) 
	DrawText(0, 0, Text, #White, #Black)
	TWidth = TextWidth(Text)
	THeight = TextHeight(Text)
	StopDrawing() 
	
	
	GrabSprite(#Sprite, 0, 0, TWidth, THeight, #PB_Sprite_PixelCollision)
	SpriteH = SpriteHeight(#Sprite)
	SpriteW = SpriteWidth(#Sprite)
	
	
	Repeat
  	Repeat : Until WindowEvent() = #False
	  ExamineMouse()
		ClearScreen(RGB(0, 0, 0))
		DisplaySprite(#Sprite, x, y)
		x=x+xd:y=y+yd
		
		If y>ScreenH - SpriteH 
			yd=-1
		EndIf
		
		If x>ScreenW - SpriteW  
			xd=-1	
		EndIf
		
		If y<0
			yd=1
		EndIf
		
		If X<0
			xd=1
		EndIf	
		
		FlipBuffers()
		ExamineKeyboard()
		
		Delay(1)
	Until KeyboardPushed(#PB_Key_Escape)
	
	FreeSprite(#Sprite)
	CloseScreen()
EndProcedure



Width = DesktopWidth(0)
Height = DesktopHeight(0)
Depth = DesktopDepth(0)


; Create borderless window with above measurements and black background.
Window_0 = OpenWindow(#PB_Any, 0, 0, Width, Height, "", #PB_Window_BorderLess)
SetWindowColor(Window_0, RGB(0,0,0))
OutOfService()


Re: WindowedScreen question

Posted: Thu Jan 16, 2025 11:35 am
by Catdaddy
That worked. Thank you so much, miso.