TGC Codebase Backup



FindBestMode(Width,Height,Depth) by TinTin

23rd May 2007 9:24
Summary

This Function is used to find the closest matching resolution that the hardware supports to the required on.



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` FindBestMode() Function By Alan Barclay Rev 1.0
If FindBestMode(800,600,32)
 Print Screen Width();"x";Screen Height();"x";Screen Depth()
 MX = Screen Width()/2 : MY = Screen Height()/2 : CV = RGB(255,255,255)
 Box MX-100,MY-100,MX+100,MY+100,CV,CV,CV,CV
 Wait Key
EndIf
End
` FindBestMode(Width,Height,Depth)
Function FindBestMode(W#.H#,D#)
 bRet as boolean
 `Get Windows Desktop Aspect Ratio
 Load Dll "User32.Dll",1
 DW# = Call Dll(1,"GetSystemMetrics",0)
 DH# = Call Dll(1,"GetSystemMetrics",1)
 Delete Dll 1
 Set Camera Aspect DW#/DH#
 `Check If Desired Resolution Exists
 If Check Display Mode(W#,H#,D#)
  Set Display Mode W#,H#,D#
  bRet = 1
 Else
  P#=W#*H# : C#=0 : M=0
  Empty Checklist
  Perform Checklist For Display Modes
  For I = Checklist Quantity() to 1 step -1
   If D#=Checklist Value C(I) and(C#=0 or C#>ABs((Checklist Value A(I)*Checklist Value B(I)-P#)
    M=I : C# = (Checklist Value A(I)*Checklist Value B(I))-P#
   EndIf
  Next
  If M>0 And Check Display Mode (Checklist Value A(M), Checklist Value B(M), Checklist Value C(M))
   Set Display Mode Checklist Value A(M),Checklist Value B(M),Checklist Value C(M)
   bRet = 1
  EndIf
 EndIf
EndFunction bRet
 EndIf
EndFunction