I needed a routine to return the nearest graphics mode available to my game resolution. The returned mode has to be => than the requested mode. I think this routine is working, but it's been a long night. ;)
Usage:
xres:int=800
yres:int=600
FindNearestGraphicsMode(xres,yres)
If a mode was found, xres/yres will equal the new x/y resolution, otherwise they will equal zero.
Usage:
xres:int=800
yres:int=600
FindNearestGraphicsMode(xres,yres)
If a mode was found, xres/yres will equal the new x/y resolution, otherwise they will equal zero.
Function FindNearestGraphicsMode(modex:Int Var,modey:Int Var) ' Local workx:Int = 0 Local worky:Int = 0 Local match:Int = 0 Local calcx:Int = 30000 Local calcy:Int = 30000 Local mode:TGraphicsMode ' For mode = EachIn GraphicsModes() If match = 0 If mode.width = modex And mode.height = modey modex = mode.width modey = mode.height match = 1 EndIf If match = 0 If mode.width >= modex And mode.height >= modey If (mode.width - modex) < calcx And (mode.height - modey) < calcy calcx = Mode.width - modex calcy = mode.height - modey workx = mode.width worky= mode.height EndIf EndIf EndIf EndIf Next ' If match = 0 If workx > 0 And worky > 0 modex = workx modey = worky Else modex = 0 modey = 0 EndIf EndIf ' End Function