OpenWindowedScreen resizable

Share your advanced PureBasic knowledge/code with the community.
Christophe_fr
User
User
Posts: 13
Joined: Thu Dec 13, 2018 9:58 pm
Location: france

OpenWindowedScreen resizable

Post 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
Sorry for my English. My language is French
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: OpenWindowedScreen resizable

Post by RSBasic »

Good idea and works fine. 8)
Image
Image
Christophe_fr
User
User
Posts: 13
Joined: Thu Dec 13, 2018 9:58 pm
Location: france

Re: OpenWindowedScreen resizable

Post 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
Sorry for my English. My language is French
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: OpenWindowedScreen resizable

Post by Mijikai »

Interesting but the second example does is just black for me.
Christophe_fr
User
User
Posts: 13
Joined: Thu Dec 13, 2018 9:58 pm
Location: france

Re: OpenWindowedScreen resizable

Post 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
Sorry for my English. My language is French
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: OpenWindowedScreen resizable

Post by Mijikai »

All examples work with PureBasic 5.71b with 5.62 only the first one works? :|
Post Reply