Page 1 of 1

OpenWindowedScreen resizable

Posted: Wed May 08, 2019 9:20 am
by Christophe_fr
thanks to Ollivier from the French forum for the help
OpenWindowedScreen(GadgetID(0), 0, 0, ScreenW, ScreenH)
you can open a screen on a gadget

Code: Select all

#MainWin = 0
#ScreenWin = 1
ScreenW = 2048
ScreenH = 2048
InitSprite()

If OpenWindow(#MainWin, 0, 0, 400, 300, Str(ScreenW) + " x " + Str(ScreenH), #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
  
  MDIGadget(0, 0, 0, WindowWidth(#MainWin), WindowHeight(#MainWin), 0, 0, #PB_MDI_AutoSize | #PB_MDI_BorderLess)

  OpenWindowedScreen(GadgetID(0), 0, 0, ScreenW, ScreenH) ;, 0, 0, 0, #PB_Screen_NoSynchronization) 
  
  CreateSprite(101, ScreenW, ScreenH, #PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(101) )
    For I = 1 To 1000
      x = Random(ScreenW)
      y = Random(ScreenH)
      r = 50 + Random(50)
      c = RGB(Random(255), Random(255), Random(255) )
      Circle(x, y, r, c)
      Circle(x - ScreenW, y, r, c)
      Circle(x + ScreenW, y, r, c)
    Next
    StopDrawing()
  EndIf
  
  x = 0
  Repeat
    DisplaySprite(101, x, 0)
    DisplaySprite(101, ScreenW + x, 0)
    x - 1
    If x <= 0 - ScreenW
      X = 0
    EndIf
    FlipBuffers()
    Delay(3)
  Until WindowEvent() = #PB_Event_CloseWindow
EndIf

Re: OpenWindowedScreen resizable

Posted: Wed May 08, 2019 11:15 am
by RSBasic
Good idea and works fine. 8)

Re: OpenWindowedScreen resizable

Posted: Wed May 08, 2019 11:59 am
by Christophe_fr
Without blocking the animation when resizing or moving

Code: Select all

#MainWin = 0
#ScreenWin = 1
Global ScreenW = 2048
Global ScreenH = 2048

InitSprite()

Procedure UpdateScreen()
  ResizeGadget(0, #PB_Ignore, #PB_Ignore,  WindowWidth(#MainWin), WindowHeight(#MainWin))
EndProcedure

Procedure Scrolling()
  Static x
  
    DisplaySprite(101, x, 0)
    DisplaySprite(101, ScreenW + x, 0)
    x - 1
    If x <= 0 - ScreenW
      X = 0
    EndIf
    FlipBuffers()
 
EndProcedure

If OpenWindow(#MainWin, 0, 0, 400, 300, Str(ScreenW) + " x " + Str(ScreenH), #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
  AddWindowTimer(#MainWin,1,1)
  MDIGadget(0, 0, 0, WindowWidth(#MainWin), WindowHeight(#MainWin), 0, 0, #PB_MDI_BorderLess )

  OpenWindowedScreen(GadgetID(0), 0, 0, ScreenW, ScreenH,0,0,0,#PB_Screen_NoSynchronization) 
  
  CreateSprite(101, ScreenW, ScreenH, #PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(101) )
    For I = 1 To 1000
      x = Random(ScreenW)
      y = Random(ScreenH)
      r = 50 + Random(50)
      c = RGB(Random(255), Random(255), Random(255) )
      Circle(x, y, r, c)
      Circle(x - ScreenW, y, r, c)
      Circle(x + ScreenW, y, r, c)
    Next
    StopDrawing()
  EndIf
  
  x = 0
  DisplaySprite(101, x, 0)
  DisplaySprite(101, ScreenW + x, 0)
  FlipBuffers()
  
  BindEvent(#PB_Event_SizeWindow, @UpdateScreen())
  BindEvent(#PB_Event_Timer,@Scrolling())

  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: OpenWindowedScreen resizable

Posted: Wed May 08, 2019 3:54 pm
by Mijikai
Interesting but the second example does is just black for me.

Re: OpenWindowedScreen resizable

Posted: Wed May 08, 2019 4:57 pm
by Christophe_fr
can be a screen refresh problem
the same but with a thread

Code: Select all

#MainWin = 0
#ScreenWin = 1
Global ScreenW = 2048
Global ScreenH = 2048
Global Thread
Global ThreadSemaphore = CreateSemaphore()

InitSprite()

Procedure UpdateScreen()
  WaitSemaphore(ThreadSemaphore)
  ResizeGadget(0, #PB_Ignore, #PB_Ignore,  WindowWidth(#MainWin), WindowHeight(#MainWin))
  SignalSemaphore(ThreadSemaphore)
EndProcedure

Procedure Scrolling(nul)
 
  Repeat
    WaitSemaphore(ThreadSemaphore)
    TrySemaphore(ThreadSemaphore)
    DisplaySprite(101, x, 0)
    DisplaySprite(101, ScreenW + x, 0)
    x - 1
    If x <= 0 - ScreenW
      X = 0
    EndIf
    FlipBuffers()
    SignalSemaphore(ThreadSemaphore)
    Delay(20)   ; 3
    ForEver

EndProcedure

If OpenWindow(#MainWin, 0, 0, 400, 300, Str(ScreenW) + " x " + Str(ScreenH), #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
 
  MDIGadget(0, 0, 0, WindowWidth(#MainWin), WindowHeight(#MainWin), 0, 0, #PB_MDI_BorderLess )

  OpenWindowedScreen(GadgetID(0), 0, 0, ScreenW, ScreenH)
 
  CreateSprite(101, ScreenW, ScreenH, #PB_Sprite_AlphaBlending)
  If StartDrawing(SpriteOutput(101) )
    For I = 1 To 1000
      x = Random(ScreenW)
      y = Random(ScreenH)
      r = 50 + Random(50)
      c = RGB(Random(255), Random(255), Random(255) )
      Circle(x, y, r, c)
      Circle(x - ScreenW, y, r, c)
      Circle(x + ScreenW, y, r, c)
    Next
    StopDrawing()
  EndIf
 
  x = 0
  DisplaySprite(101, x, 0)
  DisplaySprite(101, ScreenW + x, 0)
  FlipBuffers()
 
   BindEvent(#PB_Event_SizeWindow, @UpdateScreen())
   Thread = CreateThread(@Scrolling(),0)
   SignalSemaphore(ThreadSemaphore)

  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  KillThread(Thread) : FreeSemaphore(ThreadSemaphore)
EndIf

Re: OpenWindowedScreen resizable

Posted: Thu May 09, 2019 11:29 am
by Mijikai
All examples work with PureBasic 5.71b with 5.62 only the first one works? :|