I am currently facing a situation where i have WindowedScreen blitting some pixels data : it all works.
Now, i have a scaling feature with this two options :
- stretch
- scale with aspect ratio
The first case works very good with the autoStretch flag in OpenWindowedScreen().
But how to allow the scaling with aspect ratio ?
I have quickly coded something to let you visualise my problem :
Code: Select all
Global hSprite.l, spr_w.l, spr_h.l
Global hScreen.l
Procedure SizeWindowHandler()
Protected realtime_width.l, realtime_height.l
realtime_width = WindowWidth(main_window_id)
realtime_height = WindowHeight(main_window_id)
;- Scale with stretch feature
TransformSprite(hSprite, 0, 0, DesktopScaledX(realtime_width), 0, DesktopScaledX(realtime_width), DesktopScaledY(realtime_height), 0, DesktopScaledY(realtime_height))
;- TODO
;- Scale with aspect ratio feature (a simple idea coule be)
; ResizeScreen(hSprite, DesktopScaledX(realtime_width), DesktopScaledY(realtime_height), someflags)
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
DisplaySprite(hSprite, 0, 0)
Debug "SizeWindowHandler:: realtime_width = " + Str(realtime_width) + " realtime_height = " + Str(realtime_height) + " spr_w = " + Str(spr_w) + " spr_h = " + Str(spr_h)
EndProcedure
Procedure WindowedScreen_Create(hWnd.l, w, h)
If hScreen
CloseScreen()
hScreen = #Null
EndIf
If hSprite
FreeSprite(hSprite)
hSprite = #Null
EndIf
hScreen = OpenWindowedScreen(WindowID(hWnd), 0, 0, w, h, #False, 0, 0, 0)
If hScreen
hSprite = LoadSprite(#PB_Any, #PB_Compiler_Home + "Examples/Sources/Data/PureBasicLogo.bmp")
spr_w = SpriteWidth(hSprite)
spr_h = SpriteHeight(hSprite)
ResizeWindow(hWnd, #PB_Ignore, #PB_Ignore, spr_w, spr_h)
EndIf
EndProcedure
If InitSprite() = 0
MessageRequester("Error", "Error with InitSprite() !", 0)
End
EndIf
If OpenWindow(0, 0, 0, 220, 160, "Realtime Scale", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
WindowedScreen_Create(0, 320, 240)
EndIf
BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler())
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
DisplaySprite(hSprite, 0, 0)
Delay(1)
ForEver
Thank you for your help



