Hi all, here's the public domain part of the framework in case you are interested. Each function has a brief explanation saying what it does. Some of it is generally pretty useful and some of it has a very specific purpose.
The code either came from posts in threads on Blitzmax.com or code archives and I asked people's permission to use it (publicly or via email), or the code was emailed to me privately or came via my Framework forums (so is not actually public domain). Also some of the code is slightly modified by me.
This code is about 3% of my framework (based on line count)
The code either came from posts in threads on Blitzmax.com or code archives and I asked people's permission to use it (publicly or via email), or the code was emailed to me privately or came via my Framework forums (so is not actually public domain). Also some of the code is slightly modified by me.
This code is about 3% of my framework (based on line count)
'BLITZ MAX *PUBLIC DOMAIN* COMMON CODE (Functions) 'Used in the Grey Alien Blitzmax Game Framework. 'Composition, explanations and some modifications by Jake Birkett (Grey Alien). 'Code credited to authors but is not copyright. 'V1.10 Released 20/01/09 'Note that many of these functions need Windows API calls declared as Extern. 'You'll have to add those yourself if you want to use the functions. 'by Manel Ibáñez for use with ccFastRand() Extern "C" Function crndseed:Int(val:Int) = "srand" Function _crand:Int () = "rand" End Extern 'By Bruce Henderson for use with ccGetSharedUserDataFolder() ?MacOS Extern Function FSFindFolder:Int( vRefNum:Int ,folderType:Int ,createFolder:Int ,foundRef:Byte Ptr ) Function FSRefMakePath:Int( ref:Byte Ptr,path:Byte Ptr, maxPath:Int ) End Extern ? ' ----------------------------------------------------------------------------- ' ccAddLists: Adds one list to another ' By Plash ' ----------------------------------------------------------------------------- Function ccAddLists:Int(dest:TList, from:TList) If dest = Null Or from = Null Or from.Count() = 0 Then Return False For Local obj:Object = EachIn from dest.AddLast(obj) Next Return True End Function ' ----------------------------------------------------------------------------- ' ccCircleHalfWidthAtY: Return half the width of a circle of a specifed radius at a given y coord ' by David Bird (although it's really just a simple formula) ' ----------------------------------------------------------------------------- Function ccCircleHalfWidthAtY:Float( radius:Float, y:Float ) Return Sqr(radius*radius - y*y ) End Function ' ----------------------------------------------------------------------------- ' ccCircleLineIntersect2: Pass in coords for a line and circle and this will tell you if they intersect ' by Oddball (adapted from TomToad's code) modified by Grey Alien ' ----------------------------------------------------------------------------- Function ccCircleLineIntersect2%(x1:Double, y1:Double, x2:Double, y2:Double, px:Double, py:Double, r:Double) 'I upgraded all params and local variables from Floats to Doubles (Grey Alien) Local sx:Double= x2-x1 Local sy:Double= y2-y1 Local q:Double= ((px-x1) * (x2-x1) + (py - y1) * (y2-y1)) / (sx*sx + sy*sy) If q < 0.0 Then q = 0.0 If q > 1.0 Then q = 1.0 Local cx:Double=(1-q)*x1+q*x2 Local cy:Double=(1-q)*y1 + q*y2 If ccPointToPointDist(px,py,cx,cy) < r Return True Else Return False EndIf End Function ' ----------------------------------------------------------------------------- ' ccCopyImage: Creates a copy of a TImage ' by BlackSp1der ' ----------------------------------------------------------------------------- Function ccCopyImage:TImage(image:TImage) Local newimage:TImage=CreateImage(image.width,image.height,image.frames.Length,image.flags) newimage.handle_x=image.handle_x newimage.handle_y=image.handle_y newimage.mask_r=image.mask_r newimage.mask_g=image.mask_g newimage.mask_b=image.mask_b For Local frame:Int=0 Until image.Frames.Length Local pixmap:TPixmap=LockImage(image,frame) 'pixmap copy newimage.SetPixmap(frame,pixmap.Copy()) 'pixmap clone 'newimage.pixmaps[frame]=image.pixmaps[frame] 'newimage.frames[frame]=image.frames[frame] 'newimage.seqs[frame]=image.seqs[frame] UnlockImage(image,frame) Next Return newimage EndFunction ' ----------------------------------------------------------------------------- ' ccCopyImageRect: Copies part of an image onto another image ' by James Chamblin ' ----------------------------------------------------------------------------- Function ccCopyImageRect(Source:TImage,SX:Int,SY:Int,SWidth:Int,SHeight:Int,Dest:TImage,DX:Int,DY:Int) 'get the pixmap for the images Local SourcePix:TPixmap = LockImage(Source) Local DestPix:TPixmap = LockImage(Dest) 'find the dimentions Local SourceWidth:Int = PixmapWidth(SourcePix) Local SourceHeight:Int = PixmapHeight(SourcePix) Local DestWidth:Int = PixmapWidth(DestPix) Local DestHeight:Int = PixmapHeight(DestPix) If SX < SourceWidth And SY < SourceHeight And DX < DestWidth And DY < DestHeight 'make sure rects are on image If SX+SWidth > SourceWidth Then SWidth = SourceWidth - SX 'bound the coordinates to the image area If SY+SHeight > SourceHeight Then SHeight = SourceHeight - SY If DX+SWidth > DestWidth Then SWidth = DestWidth - DX 'Make sure coordinates will fit into the destination If DY+SHeight > DestHeight Then SHeight = DestHeight - DY 'find the pitch Local SourcePitch:Int = PixmapPitch(SourcePix) Local DestPitch:Int = PixmapPitch(DestPix) 'pointers To the first pixel of pixmaps Local SourcePtr:Byte Ptr = PixmapPixelPtr(SourcePix) + SY * SourcePitch + SX * 4 Local DestPtr:Byte Ptr = PixmapPixelPtr(DestPix) + DY * DestPitch + DX * 4 'copy pixels over one line at a time For Local i:Int = 1 To SHeight MemCopy(DestPtr,SourcePtr,SWidth*4) SourcePtr :+ SourcePitch DestPtr :+ DestPitch Next End If 'unlock the buffers UnlockImage(Source) UnlockImage(Dest) End Function ' ----------------------------------------------------------------------------- ' ccCopyImageToImage: Copies one TImage to another with a variety of modes ' by Dave Munsie ' ----------------------------------------------------------------------------- Function ccCopyImageToImage(Source:TImage,SX:Int,SY:Int,SWidth:Int,SHeight:Int,Dest:TImage,DX:Int,DY:Int,flags:Int=0) ' ' flags: 0 = Normal 1 = Mirror 2 = Flip 3 = Mirror and Flip ' Local SourcePix:TPixmap = LockImage(Source) Local DestPix:TPixmap = LockImage(Dest) Local SourceWidth:Int = PixmapWidth(SourcePix) Local SourceHeight:Int = PixmapHeight(SourcePix) Local DestWidth:Int = PixmapWidth(DestPix) Local DestHeight:Int = PixmapHeight(DestPix) If SX < SourceWidth And SY < SourceHeight And DX < DestWidth And DY < DestHeight If SX+SWidth > SourceWidth Then SWidth = SourceWidth - SX If SY+SHeight > SourceHeight Then SHeight = SourceHeight - SY If DX+SWidth > DestWidth Then SWidth = DestWidth - DX If DY+SHeight > DestHeight Then SHeight = DestHeight - DY Select flags Case 0 ' Normal For Local py:Int = 0 To SHeight-1 For Local px:Int = 0 To SWidth- 1 WritePixel(DestPix,DX+px,DY+py,ReadPixel(SourcePix,SX+px,SY+py)) Next Next Case 1 ' Mirror For Local py:Int = 0 To SHeight-1 For Local px:Int = 0 To SWidth- 1 WritePixel(DestPix,DX+px,DY+py,ReadPixel(SourcePix,(SX+(SWidth-1))-px,SY+py)) Next Next Case 2 ' Flip For Local py:Int = 0 To SHeight-1 For Local px:Int = 0 To SWidth- 1 WritePixel(DestPix,DX+px,DY+py,ReadPixel(SourcePix,SX+px,(SY+(SHeight-1))-py)) Next Next Case 3 ' Mirror and Flip For Local py:Int = 0 To SHeight-1 For Local px:Int = 0 To SWidth- 1 WritePixel(DestPix,DX+px,DY+py,ReadPixel(SourcePix,(SX+(SWidth-1))-px,(SY+(SHeight-1))-py)) Next Next End Select EndIf UnlockImage(Source) UnlockImage(Dest) End Function ' ----------------------------------------------------------------------------- ' ccCreateFrames: Caches an Image or Anim Image in VRAM ' by Ian Duff ' ----------------------------------------------------------------------------- Function ccCreateFrames(image:TImage) 'Use this to cache an image or animimage in VRAM for quicker drawing later. For Local c%=0 Until image.frames.length image.Frame(c) Next End Function ' ----------------------------------------------------------------------------- ' ccDrawImageArea: Draws part of an image. (faster?) ' by Ian Duff fixed by Grey Alien ' ----------------------------------------------------------------------------- Function ccDrawImageArea(image:TImage, x#, y#, rx#, ry#, rw#, rh#, theframe%=0) 'Note that this code works fine in DirectX or OpenGL on PCs - it autodetects (Grey Alien). 'Warning: make sure that none of your images have pixels right on the edge otherwise 'when drawing clipped, they may leave smear in the clipped area! (Grey Alien). Local origin_x#, origin_y# ; GetOrigin (origin_x, origin_y) Local tw% = ccDrawImageAreaPow2Size(image.width) Local th% = ccDrawImageAreaPow2Size(image.height) Local rw1# = rx + rw Local rh1# = ry + rh Local x0# = -image.handle_x, x1# = x0 + rw Local y0# = -image.handle_y, y1# = y0 + rh If rw1 > image.width x1 = x0 + rw + image.width - rw1 rw1 = image.width EndIf If rh1 > image.height y1 = y0 + rh + image.height - rh1 rh1 = image.height EndIf ?Win32 If TD3D7ImageFrame(image.frame(theframe)) Local frame:TD3D7ImageFrame = TD3D7ImageFrame(image.frame(theframe)) frame.setUV(rx / tw, ry / th, rw1 / tw, rh1 / th) frame.Draw x0, y0, x1, y1, x + origin_x, y + origin_y frame.setUV(0, 0, image.width / Float(tw), image.height / Float(th)) Else ? Local frameA:TGLImageFrame = TGLImageFrame (image.frame(theframe)) 'Protect against frameA being null due to alt+tab. (Grey Alien) If frameA<>Null Then frameA.u0 = rx / tw frameA.v0 = ry / th frameA.u1 = rw1 / tw frameA.v1 = rh1 / th frameA.Draw x0, y0, x1, y1, x + origin_x, y + origin_y frameA.u0 = 0 frameA.v0 = 0 frameA.u1 = image.width / Float(tw) frameA.v1 = image.height / Float(th) EndIf ?Win32 EndIf ? Function ccDrawImageAreaPow2Size%(n%) Local ry% = 1 While ry < n ry :* 2 Wend Return ry End Function End Function ' ----------------------------------------------------------------------------- ' ccDrawImageRect: Draws part of an image. (slow? See also ccDrawImageArea()) ' by TonyG ' ----------------------------------------------------------------------------- Function ccDrawImageRect(image:TImage,x:Int,y:Int,xs:Int,ys:Int,width:Int,height:Int) DrawImage LoadImage(PixmapWindow(LockImage(image),xs,ys,width,height)),x,y End Function ' ----------------------------------------------------------------------------- ' ccDrawOnPixmap: Allows you to draw an image on a pixmap whilst retaining alpha properties ' By MichaelB ' ----------------------------------------------------------------------------- Function ccDrawOnPixmap(image:TImage, framenr:Int = 0, Pixmap:TPixmap, x:Int, y:Int, alpha:Float = 1.0, light:Float = 1.0) Local TempPix:TPixmap = Null If image = Null Then Throw "image doesnt exist" If framenr = 0 Then TempPix = LockImage(image) If framenr > 0 Then TempPix = LockImage(image, Framenr) For Local i:Int = 0 To ImageWidth(image) - 1 For Local j:Int = 0 To ImageHeight(image) - 1 If x + i < pixmap.width And y + j < pixmap.Height Local sourcepixel:Int = ReadPixel(TempPix, i,j) Local destpixel:Int = ReadPixel(pixmap, x+i,y+j) Local destA:Float = ARGB_Alpha(destpixel) Local sourceA:Float = ARGB_Alpha(sourcepixel) * alpha If sourceA = 255 Then destA = 0 'remove comment to remove unneeded calculations 'but only when light/alpha not used! ' If sourceA <> 255 And sourceA <> 0 Local destR:Float = ARGB_Red(destpixel) Local destG:Float = ARGB_Green(destpixel) Local destB:Float = ARGB_Blue(destpixel) Local SourceR:Float = ARGB_Red(Sourcepixel) Local SourceG:Float = ARGB_Green(Sourcepixel) Local SourceB:Float = ARGB_Blue(Sourcepixel) Local AlphaSum:Int = destA + sourceA sourceR = (sourceR * light * sourceA / AlphaSum) + destA / AlphaSum * (destR * destA / AlphaSum) sourceG = (sourceG * light * sourceA / AlphaSum) + destA / AlphaSum * (destG * destA / AlphaSum) sourceB = (sourceB * light * sourceA / AlphaSum) + destA / AlphaSum * (destB * destA / AlphaSum) If AlphaSum > 255 Then AlphaSum = 255 sourcepixel = ARGB_Color(AlphaSum, SourceR, sourceG, sourceB) ' EndIf If SourceA <> 0 Then WritePixel(Pixmap, x + i, y + j, sourcepixel) EndIf Next Next If framenr = 0 UnlockImage(image) If framenr > 0 UnlockImage(image, framenr) End Function Function ARGB_Alpha:Int(ARGB:Int) Return (argb Shr 24) & $ff End Function Function ARGB_Red:Int(ARGB:Int) Return (argb Shr 16) & $ff End Function Function ARGB_Green:Int(ARGB:Int) Return (argb Shr 8) & $ff End Function Function ARGB_Blue:Int(ARGB:Int) Return (argb & $ff) End Function Function ARGB_Color:Int(alpha:Int,red:Int,green:Int,blue:Int) Return (Int(alpha * $1000000) + Int(RED * $10000) + Int(green * $100) + Int(blue)) End Function ' ----------------------------------------------------------------------------- ' ccDrawTextSpaced: DrawText with a specified space between each character ' By Marius Winkelmann ' ----------------------------------------------------------------------------- Function ccDrawTextSpaced(t$,x#,y#, space:Int=0) 'Same as the built in BMax DrawText except you can specify the space between each char. Function ccDrawTextSpacedDraw(font:TImageFont, text$,x#,y#,ix#,iy#,jx#,jy#, space:Int ) For Local i:Int=0 Until text.length Local n:Int=font.CharToGlyph( text[i] ) If n<0 Continue Local glyph:TImageGlyph=font.LoadGlyph(n) Local image:TImage=glyph._image If image Local frame:TImageFrame=image.Frame(0) If frame Local tx#=glyph._x*ix+glyph._y*iy+(i*space) Local ty#=glyph._x*jx+glyph._y*jy frame.Draw 0,0,image.width,image.height,x+tx,y+ty EndIf EndIf x:+glyph._advance*ix y:+glyph._advance*jx Next EndFunction Local gc:TMax2DGraphics = TMax2DGraphics.Current() ccDrawTextSpacedDraw GetImageFont(), t,.. x+gc.origin_x+gc.handle_x*gc.tform_ix+gc.handle_y*gc.tform_iy,.. y+gc.origin_y+gc.handle_x*gc.tform_jx+gc.handle_y*gc.tform_jy,.. gc.tform_ix,gc.tform_iy,gc.tform_jx,gc.tform_jy, space End Function ' ----------------------------------------------------------------------------- ' ccDrawTextSpacedRounded: DrawText with a specified space between each character. X coord is rounded before drawing each character. ' (By Marius Winkelmann modified by Grey Alien) ' ----------------------------------------------------------------------------- Function ccDrawTextSpacedRounded(t$,x#,y#, space:Int=0) 'Same as the built in BMax DrawText except you can specify the space between each char. 'Rounds the X coord before drawing; good if you are using scaled down fonts. Function ccDrawTextSpacedRoundedLocalDraw(font:TImageFont, text$,x#,y#,ix#,iy#,jx#,jy#, space:Int ) For Local i:Int=0 Until text.length Local n:Int=font.CharToGlyph( text[i] ) If n<0 Continue Local glyph:TImageGlyph=font.LoadGlyph(n) Local image:TImage=glyph._image If image Local frame:TImageFrame=image.Frame(0) If frame Local tx#=glyph._x*ix+glyph._y*iy+(i*space) Local ty#=glyph._x*jx+glyph._y*jy frame.Draw 0,0,image.width,image.height,Floor(x+tx),y+ty EndIf EndIf x:+glyph._advance*ix y:+glyph._advance*jx Next EndFunction Local gc:TMax2DGraphics = TMax2DGraphics.Current() ccDrawTextSpacedRoundedLocalDraw GetImageFont(), t,.. x+gc.origin_x+gc.handle_x*gc.tform_ix+gc.handle_y*gc.tform_iy,.. y+gc.origin_y+gc.handle_x*gc.tform_jx+gc.handle_y*gc.tform_jy,.. gc.tform_ix,gc.tform_iy,gc.tform_jx,gc.tform_jy, space EndFunction ' ----------------------------------------------------------------------------- ' ccEnableMaximize: Uses WindowsAPI call to enable maximize button on window ' Thanks go to Gilzu, Diablo and Zawran ' ----------------------------------------------------------------------------- Function ccEnableMaximize(hWnd:Long) 'Adds the Maximize Button "[]" ?Win32 Local tmp:Int = GetWindowLongA( hWnd, GWL_STYLE ) tmp = tmp | WS_MAXIMIZEBOX SetWindowLongA( hWnd, GWL_STYLE, tmp ) DrawMenuBar( hWnd ) ? End Function ' ----------------------------------------------------------------------------- ' ccEnableMinimize: Uses WindowsAPI call to enable minimize button on window ' Thanks go to Gilzu, Diablo and Zawran ' ----------------------------------------------------------------------------- Function ccEnableMinimize(hWnd:Long) 'Adds the Minimize Button "_" ?Win32 Local tmp:Long = GetWindowLongA( hWnd, GWL_STYLE ) tmp = tmp | WS_MINIMIZEBOX SetWindowLongA( hWnd, GWL_STYLE, tmp ) DrawMenuBar( hWnd ) ? End Function ' ----------------------------------------------------------------------------- ' ccFastRand: Faster than BlitzMax Rand() ' by Manel Ibáñez ' ----------------------------------------------------------------------------- Function ccFastRand:Int (start:Int, ende:Int) Return _crand() Mod (ende-start+1) + start End Function ' ----------------------------------------------------------------------------- ' ccFastRandSeed: Sets the Seed for ccFastRand() ' by Manel Ibáñez ' ----------------------------------------------------------------------------- Function ccFastRandSeed(seed:Int) crndseed(seed) End Function ' ----------------------------------------------------------------------------- ' ccFormatNumber: Pass in a floating point number and it will format it with commas to the specified number of decimal places ' by David Maziarka ' ----------------------------------------------------------------------------- Function ccFormatNumber:String(number:Double, decimal:Int=4, comma:Int=0, padleft:Int=0 ) Assert decimal > -1 And comma > -1 And padleft > -1, "Negative numbers not allowed in Format()" Local str:String = number Local dl:Int = str.Find(".") If decimal = 0 Then decimal = -1 str = str[..dl+decimal+1] If comma While dl>comma str = str[..dl-comma] + "," + str[dl-comma..] dl :- comma Wend EndIf If padleft Local paddedLength:Int = padleft+decimal+1 If paddedLength < str.Length Then str = "Error" str = RSet(str,paddedLength) EndIf Return str End Function ' ----------------------------------------------------------------------------- ' ccGetDirectXVersion: Returns the DirectX version as a string ' By Qube and MichaelB ' ----------------------------------------------------------------------------- Function ccGetDirectXVersion$() Local strVersion:String = "" ?win32 Local hbank:TBank = CreateBank(4) RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\DirectX",BankBuf(hbank)) Local hKey% = PeekInt(hbank,0) Local value_bank:TBank = CreateBank(100) Local value_bank_size:TBank = CreateBank(4) Local type_bank:TBank = CreateBank(4) PokeInt(type_bank,0,0) PokeInt(value_bank_size,0,100) RegQueryValueEx(hKey,"Version",0,BankBuf(type_bank),BankBuf(value_bank),BankBuf(value_bank_size)) Local dx_version:String = "" For Local char%=0 To PeekInt(value_bank_size,0)-1 If PeekByte(value_bank,char)=0 Then Exit dx_version = dx_version + Chr(PeekByte(value_bank,char)) Next RegCloseKey(hKey) Select dx_version Case "4.02.0095" strVersion = "1.0" Case "4.03.00.1096" strVersion = "2.0" Case "4.04.0068" strVersion = "3.0" Case "4.04.0069" strVersion = "3.0" Case "4.05.00.0155" strVersion = "5.0" Case "4.05.01.1721" strVersion = "5.0" Case "4.05.01.1998" strVersion = "5.0" Case "4.06.02.0436" strVersion = "6.0" Case "4.07.00.0700" strVersion = "7.0" Case "4.07.00.0716" strVersion = "7.0a" Case "4.08.00.0400" strVersion = "8.0" Case "4.08.01.0881" strVersion = "8.1" Case "4.08.01.0810" strVersion = "8.1" Case "4.09.0000.0900" strVersion = "9.0" Case "4.09.00.0900" strVersion = "9.0" Case "4.09.0000.0901" strVersion = "9.0a" Case "4.09.00.0901" strVersion = "9.0a" Case "4.09.0000.0902" strVersion = "9.0b" Case "4.09.00.0902" strVersion = "9.0b" Case "4.09.00.0904" strVersion = "9.0c" Case "4.09.0000.0904" strVersion = "9.0c" End Select ? Return strVersion End Function ' ----------------------------------------------------------------------------- ' ccGetEnvVar: Uses Windows API call to return an Environment variable ' by Ian Duff modified by Grey Alien ' ----------------------------------------------------------------------------- Function ccGetEnvVar$(envVar$) Local result$= "" ?Win32 Local buff@[64] Local rtn% = GetEnvironmentVariable(envVar$, buff@, buff.length) If rtn > buff.length buff@ = buff@[..rtn] rtn = GetEnvironmentVariable(envVar$, buff@, buff.length) EndIf Result = String.FromBytes(buff@, rtn) ? Return Result 'Mac safe End Function ' ----------------------------------------------------------------------------- ' ccGetSharedUserDataFolder: Returns a special Mac folder for storing shared user data ' By Bruce Henderson ' ----------------------------------------------------------------------------- Function ccGetSharedUserDataFolder:String() 'Note that it does not have slash on the end! ?MacOS Local buf:Byte[1024],ref:Byte[80] If FSFindFolder( kUserDomain, kSharedUserDataFolderType, False, ref ) Return Null If FSRefMakePath( ref,buf,1024 ) Return Null Return String.FromCString( buf ) ? End Function ' ----------------------------------------------------------------------------- ' ccGetSpecialFolder: Returns a special Windows folder ' By Dave Kirk ' ----------------------------------------------------------------------------- Function ccGetSpecialFolder:String(folder_id%) ?win32 Local idl:TBank = CreateBank (8) Local pathbank:TBank = CreateBank (260) If SHGetSpecialFolderLocation(0,folder_id,BankBuf(idl)) = 0 SHGetPathFromIDList PeekInt( idl,0), BankBuf(pathbank) Return String.FromCString(pathbank.Buf()) + "" EndIf ? Return "" End Function ' ----------------------------------------------------------------------------- ' ccGetVersionString: Returns the Windows version in a string ' By Dave Kirk ' ----------------------------------------------------------------------------- Function ccGetVersionString:String() Const VER_PLATFORM_WIN32s% = 0 Const VER_PLATFORM_WIN32_WINDOWS% = 1 Const VER_PLATFORM_WIN32_NT% = 2 Local versionName:String ?win32 Local VersionInfo:TOSVersionInfoEx=New TOSVersionInfoEx VersionInfo.dwOSVersionInfoSize=SizeOf(VersionInfo) GetVersionExA(VersionInfo) Select versionInfo.dwPlatformID Case VER_PLATFORM_WIN32s; VersionName = "Win32s" Case VER_PLATFORM_WIN32_NT; VersionName = "Windows NT" Select versionInfo.dwVerMajor Case 4; VersionName = "Windows NT" Case 5; Select versionInfo.dwVerMinor Case 0; VersionName = "Windows 2000" Case 1; VersionName = "Windows XP" End Select Case 6; VersionName = "Windows Vista" End Select Case VER_PLATFORM_WIN32_WINDOWS Select versionInfo.dwVerMinor Case 0; VersionName = "Windows 95" Case 90; VersionName = "Windows ME" Case 10; VersionName = "Windows 98" End Select End Select ? Return VersionName End Function ' ----------------------------------------------------------------------------- ' ccPointToPointDist: Returns the distance between two points ' by Oddball modified by Grey Alien. ' ----------------------------------------------------------------------------- Function ccPointToPointDist:Double(x1:Double, y1:Double, x2:Double, y2:Double) 'Upgraded Float params and variables to doubles (Grey Alien) Local dx:Double= x1-x2 Local dy:Double= y1-y2 Return Sqr(dx*dx + dy*dy) End Function ' ----------------------------------------------------------------------------- ' ccPrintGraphicsModes: Outputs all available graphics modes in the Output window ' by xlsior ' ----------------------------------------------------------------------------- Function ccPrintGraphicsModes() Local x%,wid%,hei%,dep%,her% For x=0 To CountGraphicsModes()-1 GetGraphicsMode(x,wid,hei,dep,her) Print x+" Width: "+wid+" Height: "+hei+" Depth: "+dep+" Hertz: "+her Next End Function ' ----------------------------------------------------------------------------- ' ccRound: Gives proper rounding of Float to Integer without bankers rounding ' By Beaker ' ----------------------------------------------------------------------------- Function ccRound%(flot#) Return Floor(flot+0.5) End Function ' ----------------------------------------------------------------------------- ' ccRoundFloat: Allows you to round a float to a certain number of decimal places ' By Dreamora ' ----------------------------------------------------------------------------- Function ccRoundFloat:Float(number:Float,decimals:Int) Local t:Int = 10^decimals Local result:Float = Int(number * t + 0.5) Return result / t End Function ' ----------------------------------------------------------------------------- ' ccVWait: Uses DirectX to wait for a vertical blank ' by Skidracer updated by GreyAlien ' ----------------------------------------------------------------------------- Function ccVWait() 'Only works in DirectX graphics mode. 'This shouldn't really be needed any more as Flip 1 now always waits for VSync 'in Full Screen and Windowed mode. ?Win32 If TD3D7Max2DDriver(_max2dDriver) ' PrimaryDevice.ddraw.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN,0 'no longer works since new DX7 module D3D7GraphicsDriver().DirectDraw7().WaitForVerticalBlank DDWAITVB_BLOCKBEGIN,0 EndIf ? End Function