ResizeScreen()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

ResizeScreen()

Post by GPI »

A small example, what i want. I render the screen on a Containergadget, so i can "resize" the screen-size while autostretch is activated. I do this, because i want the correct aspect ration, so a circle is stll a circle and not a ellipse for exaple.

(windos directx only)

Code: Select all

#screenw=320
#screenh=200
#win_main=0

#gadget_screen=1

Procedure ResizeContainer()
  menuheight=MenuHeight()
  w= WindowWidth(#win_main)
  h= WindowHeight(#win_main) - MenuHeight
 
  If Int(#ScreenW * h/#ScreenH) <= w
    sw=Int(#ScreenW * h/#ScreenH)
    sh=h
  Else
    sw=w
    sh=Int(#ScreenH * w/#ScreenW)
  EndIf
  sx=Int(w-sw)/2
  sy=Int(h-sh)/2+MenuHeight()
 
  ResizeGadget(#gadget_screen,sx,sy,sw,sh)
EndProcedure

 

If InitSprite() = 0
    MessageRequester("Error", "Can't open screen & sprite enviroment!", 0)
    End
  EndIf
 
 
 
  If OpenWindow(#win_main, 0, 0, 320, 200, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    ;CreateStatusBar(0, WindowID(0))
    ;  AddStatusBarField(320)
    ContainerGadget(1, 0, 0, 320, 200 ,#PB_Container_BorderLess )

    ;StatusBarText(0, 0, "Automatically zoomed screen area when changing window size...")
   
    If OpenWindowedScreen(GadgetID(1), 0, 0, 320, 200, 1, 0, 00)
 
      CreateSprite(0, 50, 50) ; Erstellt ein leeres Sprites, dies wird komplett schwarz sein
       
      Repeat
        ; Es ist sehr wichtig, alle im Queue befindlichen Ereignisse während jedes Frames abzuarbeiten
        ;
        Repeat
          Event = WindowEvent():Delay(0)
          If event=#PB_Event_SizeWindow
            ResizeContainer()
          ElseIf Event = #PB_Event_CloseWindow
            End
          EndIf
        Until Event = 0
       
        FlipBuffers()
        ClearScreen(RGB(0, 0, 200)) ; Ein blauer Hintergrund
       
        DisplaySprite(0, 10, 10)  ; Darstellung unserer schwarzen Box in der linken oberen Ecke
        DisplaySprite(0, 260, 10) ; Darstellung unserer schwarzen Box in der rechten oberen Ecke
      ForEver
     
    Else
      MessageRequester("Error", "Can't open windowed screen!", 0)
    EndIf
  EndIf
it would be easier with a

resizeWindowedScreen(top,left,bottom,right)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ResizeScreen()

Post by netmaestro »

Good request, I'd like it too.

Just bear in mind that if you place a WindowedScreen in a container you will lose the capacity to use InitMouse() and all the mouse commands it provides. Keyboard should still be OK and API mouse control is always available.
BERESHEIT
Post Reply