This the code that makes the gx Graphics Library work. This page will always contain the most up-to-date version.
Just paste this code into the bottom of your program to use the gx Graphics Library:
' ---------------------------------------------------------------------------------------------- '' ------------------------------------ gx GRAPHICS LIBRARY ------------------------------------- '' ---------------------------------------------------------------------------------------------- 'Sub gx.InitMemoryDrawing width, height
' Call this once before attempting to draw in memory using the gx functions.' width and height are the maximum dimensions of the graphics you intend to draw in memory.Struct gxInfo,_
DC AsULong,_ ' Device Context
BmpCache AsULong,_ ' Another Device Context for temporarily storing bitmaps.
Width AsLong,_ ' Area Width
Height AsLong,_ ' Area Height
PenStyle AsLong,_ ' _PS_SOLID _PS_DASH _PS_DOT _PS_DASHDOT
_ ' _PS_DASHDOTDOT _PS_NULL _PS_INSIDEFRAME
PenWidth AsLong,_ ' Line Thickness
PenColor AsLong,_ ' Line Color
BrushStyle AsLong,_ ' _HS_BDIAGONAL _HS_CROSS _HS_DIAGCROSS
_ ' _HS_FDIAGONAL _HS_HORIZONTAL _HS_VERTICAL
FillColor AsLong,_ ' Fill Color
StyleColor AsLong,_ ' Brush Style Color
Font AsLong,_ ' Handle to a font for text rendering.
FontHeight AsLong,_ ' Height of the current font in pixels. Provided for your convenience.
DesktopDPI AsLong,_ ' DPI-Y of the desktop window.
BlitStyle AsLong,_ ' The blit mode for drawing bitmaps
BlitKey AsLong,_ ' The transparent color for drawing bitmaps.
_ ' -1 indicates no transparency.
BlitAngle AsLong,_ ' The angle of rotation for drawing bitmaps in degrees.
BlitFlip$ AsPtr,_ ' If the image is to be flipped around.
BlitOrigin$ AsPtr,_ ' The origin point for blitting.
TextColor AsLong' Text ColorStruct gxGDIBitmap,_
bmType AsLong,_
bmWidth AsLong,_
bmHeight AsLong,_
bmWidthBytes AsLong,_
bmPlanes AsWord,_
bmBitsPixel AsWord,_
bmBits AsLongStruct gxTA, eM11 AsuLong, eM12 AsuLong, eM21 AsuLong,_
eM22 AsuLong, eDx AsuLong, eDy AsuLongStruct gxTB, eM11 AsuLong, eM12 AsuLong, eM21 AsuLong,_
eM22 AsuLong, eDx AsuLong, eDy AsuLongStruct gxPoint, x AsLong, y AsLongStruct gxLocal, R4 AsULong' Needed for TransparentBlt:Open"msimg32.dll"ForDLLAs#msimg32
Open"oleaut32"ForDLLAs#oleaut32
' Get the desktop window:CallDLL#user32,"GetDesktopWindow", desktopWin AsULong' Get the desktop window's device context:CallDLL#user32,"GetDC", desktopWin AsULong, desktopDC AsULong' Make a compatible DC:CallDLL#gdi32,"CreateCompatibleDC", desktopDC AsUlong, gxDC AsULong' Make another one:CallDLL#gdi32,"CreateCompatibleDC", desktopDC AsUlong, BmpCache AsULong' Make a compatible bitmap for drawing on:CallDLL#gdi32,"CreateCompatibleBitmap",_
desktopDC AsULong, width AsLong, height AsLong, bitmap AsULong' Select it into our DC:CallDLL#gdi32,"SelectObject", gxDC AsULong, bitmap AsULong, oldBitmap AsULong' Delete the old bitmap:CallDLL#gdi32,"DeleteObject", oldBitmap AsULong, result AsLong' Release the desktop window's DC:CallDLL#user32,"ReleaseDC", desktopWin AsULong, desktopDC AsULong, result AsLong' Set the text align to work as expected:CallDLL#gdi32,"SetTextAlign", gxDC AsULong,0AsuLong, result AsLong' DPI:CallDLL#gdi32,"GetDeviceCaps", gxDC AsULong, _LOGPIXELSY AsLong, dpi AsLongCallDLL#gdi32,"SetStretchBltMode", gxDC AsULong, _COLORONCOLOR AsLong, result AsLongCallDLL#gdi32,"SetGraphicsMode", gxDC AsULong, _GM_ADVANCED AsLong, result AsLongCallDLL#gdi32,"SetPolyFillMode", gxDC AsULong, _WINDING AsLong, result AsLong
gxInfo.DC.struct= gxDC
gxInfo.BmpCache.struct= BmpCache
gxInfo.Width.struct= width
gxInfo.Height.struct= height
gxInfo.PenStyle.struct= _PS_SOLID
gxInfo.PenWidth.struct=1
gxInfo.PenColor.struct= gx.Color("black")
gxInfo.BrushStyle.struct=-1' Solid. -2 = null brush.
gxInfo.FillColor.struct= gx.Color("darkgray")
gxInfo.StyleColor.struct= gx.Color("lightgray")
gxInfo.Font.struct=0
gxInfo.FontHeight.struct=0
gxInfo.DesktopDPI.struct= dpi
gxInfo.BlitStyle.struct= gx.BlitStyle("normal")
gxInfo.BlitKey.struct=-1' No transparent color.
gxInfo.BlitAngle.struct=0' No rotation in degrees.
gxInfo.BlitFlip$.struct="none"
gxInfo.BlitOrigin$.struct="default"
gxInfo.TextColor.struct= gx.Color("black")EndSubSub gx.StretchTo control, destX, destY, destW, destH, srcX, srcY, srcW, srcH
' control is the hwnd of the control you'd like to render the image in memory to.' destX and destY specify where to place the image on the control.' srX and srcY specify the start point to grab the source image.' srcW and srcH specify the size of the grab area.
gxDC = gxInfo.DC.structIfNot(gxDC)ThenExitSub' Get the control's DC:CallDLL#user32,"GetDC", control AsULong, controlDC AsULong' Render the specified area of the source to the specified location on the destination control.CallDLL#gdi32,"SetStretchBltMode", controlDC AsULong, _COLORONCOLOR AsLong, result AsLongCallDLL#gdi32,"StretchBlt",_
controlDC AsUlong,_ 'destination
destX AsLong,_ 'destination x pos
destY AsLong,_ 'destination y pos
destW AsLong,_ 'destination width desired
destH AsLong,_ 'destination height desired
gxDC AsUlong,_ 'source
srcX AsLong,_ 'x location to start from source
srcY AsLong,_ 'y location to start from source
srcW AsLong,_ 'width desired from source
srcH AsLong,_ 'height desired from source
_SRCCOPY AsULong,_ 'dwRasterOperation
result AsLong' Release the control's DC:CallDLL#user32,"ReleaseDC", control AsULong, controlDC AsULong, result AsLongEndSubSub gx.RenderTo control, destX, destY, srcX, srcY, srcW, srcH
' control is the hwnd of the control you'd like to render the image in memory to.' destX and destY specify where to place the image on the control.' srX and srcY specify the start point to grab the source image.' srcW and srcH specify the size of the grab area.
gxDC = gxInfo.DC.structIfNot(gxDC)ThenExitSub' Get the control's DC:CallDLL#user32,"GetDC", control AsULong, controlDC AsULong' Render the specified area of the source to the specified location on the destination control.CallDLL#gdi32,"SetStretchBltMode", controlDC AsULong, _COLORONCOLOR AsLong, result AsLongCallDLL#gdi32,"StretchBlt",_
controlDC AsUlong,_ 'destination
destX AsLong,_ 'destination x pos
destY AsLong,_ 'destination y pos
srcW AsLong,_ 'destination width desired
srcH AsLong,_ 'destination height desired
gxDC AsUlong,_ 'source
srcX AsLong,_ 'x location to start from source
srcY AsLong,_ 'y location to start from source
srcW AsLong,_ 'width desired from source
srcH AsLong,_ 'height desired from source
_SRCCOPY AsULong,_ 'dwRasterOperation
result AsLong' Release the control's DC:CallDLL#user32,"ReleaseDC", control AsULong, controlDC AsULong, result AsLongEndSubSub gx.Finish
' Call this once at the end of your program after using the gx library.
gxDC = gxInfo.DC.struct
BmpCache = gxInfo.BmpCache.structIfNot(gxDC)ThenExitSubClose#msimg32
Close#oleaut32
' Delete the DC and it's resources.CallDLL#gdi32,"DeleteDC", gxDC AsULong, result AsLongCallDLL#gdi32,"DeleteDC", BmpCache AsULong, result AsLong
gxInfo.DC.struct=0EndSubSub gx.Draw query$
' Call this with your drawing commands in draw$
gxDC = gxInfo.DC.struct
BmpCache = gxInfo.BmpCache.structIfNot(gxDC)ThenExitSub
width = gxInfo.Width.struct
height = gxInfo.Height.struct
penStyle = gxInfo.PenStyle.struct
penWidth = gxInfo.PenWidth.struct
penColor = gxInfo.PenColor.struct
brushStyle = gxInfo.BrushStyle.struct
fillColor = gxInfo.FillColor.struct
styleColor = gxInfo.StyleColor.struct
font = gxInfo.Font.struct
dpi = gxInfo.DesktopDPI.struct
blitStyle = gxInfo.BlitStyle.struct
blitKey = gxInfo.BlitKey.struct
blitAngle = gxInfo.BlitAngle.struct
blitFlip$ =WinString(gxInfo.BlitFlip$.struct)
blitOrigin$ =WinString(gxInfo.BlitOrigin$.struct)
textColor = gxInfo.TextColor.structIfNot(font)Then
fontHeightPx =16: fontWeight =400
fontItalic =0: fontUnderline =0: fontStrikeout =0: fontFace$ ="Arial"GoSub[CreateFont]EndIfGoSub[ResetPen]GoSub[ResetBrush]' Don't parse past the | character if it's in there. That denotes rendering text.
textMaybe =Instr(query$,"|")IfNot(textMaybe)Then textMaybe =Len(query$)Else textMaybe = textMaybe -1text$ =Mid$(query$, textMaybe+2)
query$ =Mid$(query$,1, textMaybe)
i =1:WhileWord$(query$,i,";")<>"": i = i +1:WEnd: queries = i -1For i =1To queries
q$ =Trim$(Word$(query$, i,";"))
key$ =Lower$(Word$(q$,1))' These are used for a lot of things:
x =Int(Val(Word$(q$,2))): y =Int(Val(Word$(q$,3)))
x2 = x +Int(Val(Word$(q$,4))): y2 = y +Int(Val(Word$(q$,5)))' ---------------------------------------------------------------- '
afterKey$ =Trim$(Mid$(q$,Len(key$)+1))SelectCase key$
Case"polygonmode"IfLower$(Word$(q$,2))="winding"Then mode = _WINDING Else mode = _ALTERNATE
CallDLL#gdi32,"SetPolyFillMode", gxDC AsULong, mode AsLong, result AsLongCase"blitstyle"
blitStyle = gx.BlitStyle(Word$(q$,2))Case"blitkey"IfLower$(Word$(q$,2))="none"Then
blitKey =-1Else
blitKey = gx.Color(afterKey$)EndIfCase"blitangle"
blitAngle =Val(Word$(q$,2))Case"blitorigin"IfLower$(Word$(q$,2))="default"Then
blitOrigin$ ="default"Else
blitOrigin$ =Str$(Val(Word$(q$,2)));" ";Str$(Val(Word$(q$,3)))EndIfCase"blitflip"SelectCaseLower$(Word$(q$,2))Case"none","normal"
blitFlip$ ="none"Case"horizontal"
blitFlip$ ="horizontal"Case"vertical"
blitFlip$ ="vertical"Case"both"
blitFlip$ ="both"CaseElse
blitFlip$ ="none"EndSelectCase"pencolor"
penColor = gx.Color(afterKey$):GoSub[ResetPen]Case"penwidth"
penWidth =Val(Word$(q$,2)):GoSub[ResetPen]Case"penstyle"SelectCaseLower$(Word$(q$,2))Case"normal","solid": penStyle = _PS_SOLID
Case"none": penStyle = _PS_NULL
Case"insideframe": penStyle = _PS_INSIDEFRAME
Case"dash": penStyle = _PS_DASH
Case"dot": penStyle = _PS_DOT
Case"dashdot": penStyle = _PS_DASHDOT
Case"dashdotdot": penStyle = _PS_DASHDOTDOT
EndSelectGoSub[ResetPen]Case"fillcolor"
fillColor = gx.Color(afterKey$):GoSub[ResetBrush]Case"brushstyle"SelectCaseLower$(Word$(q$,2))Case"45up": brushStyle = _HS_BDIAGONAL
Case"45down": brushStyle = _HS_FDIAGONAL
Case"45": brushStyle = _HS_DIAGCROSS
Case"cross": brushStyle = _HS_CROSS
Case"horizontal": brushStyle = _HS_HORIZONTAL
Case"vertical": brushStyle = _HS_VERTICAL
Case"solid","normal": brushStyle =-1Case"none": brushStyle =-2EndSelectGoSub[ResetBrush]Case"stylecolor"IfLower$(Word$(q$,2))="none"Then' Set background mode to be transparent:CallDLL#gdi32,"SetBkMode", gxDC AsULong, _TRANSPARENT AsLong, result AsLong
styleColor =-1Else' Set background color to be opaque:CallDLL#gdi32,"SetBkMode", gxDC AsULong, _OPAQUE AsLong, result AsLong
styleColor = gx.Color(afterKey$)' Set the background color:CallDLL#gdi32,"SetBkColor", gxDC AsULong, styleColor AsLong, result AsLongEndIfCase"ellipse"CallDLL#gdi32,"Ellipse", gxDC AsULong,_
x AsLong, y AsLong, x2 AsLong, y2 AsLong, result AsLongCase"box"CallDLL#gdi32,"Rectangle", gxDC AsULong,_
x AsLong, y AsLong, x2 AsLong, y2 AsLong, result AsLongCase"roundbox"
nWidth =Val(Word$(q$,6)): nHeight =Val(Word$(q$,7))IfNot(nWidth)AndNot(nHeight)Then nWidth =10' Default round radius.IfNot(nHeight)Then nHeight = nWidth ' Make it whatever the other is.CallDLL#gdi32,"RoundRect", gxDC AsULong,_
x AsLong, y AsLong, x2 AsLong, y2 AsLong, nWidth AsLong, nHeight AsLong,_
result AsLongCase"line"
x2 =Val(Word$(q$,4)): y2 =Val(Word$(q$,5))CallDLL#gdi32,"MoveToEx", gxDC AsULong, x AsLong, y AsLong,0AsLong, result AsLongCallDLL#gdi32,"LineTo", gxDC AsULong, x2 AsLong, y2 AsLong, result AsLongCase"polygon"
polyArray$ =""
p =1WhileWord$(afterKey$,p)<>"": p = p +1:WEnd
p =Int((p-1)/2)For q =1To p*2 Step 2
x =Int(Val(Word$(afterKey$,q)))
y =Int(Val(Word$(afterKey$,q+1)))
gxPoint.x.struct= x
gxPoint.y.struct= y
polyArray$ = polyArray$; gxPoint.structNext q
CallDLL#gdi32,"Polygon", gxDC AsULong, polyArray$ AsPtr, p AsULong, result AsLongCase"cls"CallDLL#gdi32,"GetStockObject", _WHITE_BRUSH AsLong, whiteBrush AsuLongCallDLL#gdi32,"SelectObject", gxDC AsULong, whiteBrush AsLong, oldBrush AsULongGoSub[NullPen]
x =-2: y =-2: x2 = width+4: y2 = height+4CallDLL#gdi32,"Rectangle", gxDC AsULong,_
x AsLong, y AsLong, x2 AsLong, y2 AsLong, result AsLongGoSub[NonNullPen]CallDLL#gdi32,"SelectObject", gxDC AsULong, oldBrush AsULong, whiteBrush AsULongCase"fill"GoSub[NullPen]
x =-2: y =-2: x2 = width+4: y2 = height+4
oldBrushStyle = brushStyle : oldFillColor = fillColor
brushStyle =-1: fillColor = gx.Color(afterKey$)GoSub[ResetBrush]CallDLL#gdi32,"Rectangle", gxDC AsULong,_
x AsLong, y AsLong, x2 AsLong, y2 AsLong, result AsLong
brushStyle = oldBrushStyle
fillColor = oldBrushColor
GoSub[ResetBrush]GoSub[NonNullPen]Case"fillat"CallDLL#gdi32,"GetPixel", gxDC AsULong, x AsLong, y AsLong, fillAtColor AsLongCallDLL#gdi32,"ExtFloodFill", gxDC AsULong,_
x AsLong, y AsLong, fillAtColor AsLong, _FLOODFILLSURFACE AsLong, result AsLongCase"font"
fontFace$ =Word$(q$,2)
fb$ =""For f =1ToLen(fontFace$)
char$ =Mid$(fontFace$,f,1)If char$="_"Then char$=" "
fb$ = fb$;char$
Next f
fontFace$ = fb$
' Technically, calculating the height of the font should work without the 1.25.' But to get it to be the same as all other programs on my system (JosephE), I had' to add that constant in. For some reason, it works for me.
fontHeightPx =Int(((Val(Word$(q$,3))* dpi*1.25)/72)- .5)
a$ =Trim$(Lower$(Word$(q$,4);" ";Word$(q$,5);" ";Word$(q$,6);" ";Word$(q$,7)))IfInstr(a$,"bold")Then fontWeight =700Else fontWeight =400IfInstr(a$,"underline")Then fontUnderline =1Else fontUnderline =0IfInstr(a$,"strike")Then fontStrikeout =1Else fontStrikeout =0IfInstr(a$,"italic")Then fontItalic =1Else fontItalic =0' Create new font, select it, and destroy any old ones:GoSub[CreateFont]Case"textat"CallDLL#gdi32,"SetBkMode", gxDC AsULong, _TRANSPARENT AsLong, oldBkMode AsLong
textLen =Len(text$)CallDLL#gdi32,"TextOutA", gxDC AsULong,_
x AsLong, y AsLong,text$ AsPtr, textLen AsLong, result AsLongCallDLL#gdi32,"SetBkMode", gxDC AsULong, oldBkMode AsLong, null AsLongCase"textcolor"
textColor = gx.Color(afterKey$)CallDLL#gdi32,"SetTextColor", gxDC AsULong, textColor AsULong, result AsLongCase"blit"
bitmap$ =Word$(q$,2)
bitmap =HBmp(Word$(q$,2))
destX =Val(Word$(q$,3)): destY =Val(Word$(q$,4))
size$ = gx.BitmapSize$(bitmap$)
destW =Val(Word$(size$,1)): destH =Val(Word$(size$,2))
srcW = destW : srcH = destH : srcX =0: srcY =0' Blit the bitmap:GoSub[Blit]Case"blitfield"' blitfield bitmap srcX srcY srcW srcH destX destY destW destH
bitmap =HBmp(Word$(q$,2))
srcX =Val(Word$(q$,3)): srcY =Val(Word$(q$,4))
srcW =Val(Word$(q$,5)): srcH =Val(Word$(q$,6))
destX =Val(Word$(q$,7)): destY =Val(Word$(q$,8))
destW =Val(Word$(q$,9)): destH =Val(Word$(q$,10))' Show the bitmap to custom dimensions:GoSub[Blit]Case"getbmp"' getbmp bmpName x y width height
bitmap$ =Word$(q$,2)
x =Val(Word$(q$,3)): y =Val(Word$(q$,4))
w =Val(Word$(q$,5)): h =Val(Word$(q$,6))' Create a new bitmap. Place it in the bitmap buffer. Draw the portion of the memory bitmap' into it. Unselect it, and give it to the user after LOADBMPing it.CallDLL#user32,"GetDesktopWindow", desktopWin AsULongCallDLL#user32,"GetDC", desktopWin AsULong, desktopDC AsULongCallDLL#gdi32,"CreateCompatibleBitmap",_
desktopDC AsULong, w AsLong, h AsLong, bitmap AsULongCallDLL#gdi32,"SelectObject", BmpCache AsULong, bitmap AsULong, oldBitmap AsULongCallDLL#gdi32,"StretchBlt", BmpCache AsULong,_
0AsLong,0AsLong, w AsLong, h AsLong,_
gxDC AsULong, x AsLong, y AsLong, w AsLong, h AsLong,_
_SRCCOPY AsLong, result AsLongCallDLL#gdi32,"SelectObject", BmpCache AsULong, oldBitmap AsULong, bitmap AsULongLoadBMP bitmap$, bitmap
EndSelectNext i
GoTo[CleanUp][Blit]' See if rotation is necessary:If blitAngle <>0Then' Apply world rotation.
radians = blitAngle /180*acs(-1)
cosine =cos(radians)
sine =sin(radians)If blitOrigin$ ="default"Then
centerX = destX +Int(destW/2)
centerY = destY +Int(destH/2)Else
centerX = destX +Val(Word$(blitOrigin$,1))
centerY = destY +Val(Word$(blitOrigin$,2))EndIf
gxTB.eM11.struct= gx.InternalFloat(cosine)
gxTB.eM12.struct= gx.InternalFloat(sine)
gxTB.eM21.struct= gx.InternalFloat(-1*sine)
gxTB.eM22.struct= gx.InternalFloat(cosine)
gxTB.eDx.struct= gx.InternalFloat(centerX -cos(radians)*centerX +sin(radians)*centerY)
gxTB.eDy.struct= gx.InternalFloat(centerY -cos(radians)*centerY -sin(radians)*centerX)' Get the original transform:CallDLL#gdi32,"GetWorldTransform", gxDC AsULong, gxTA Asstruct, result AsLong' Set it to the new one:CallDLL#gdi32,"SetWorldTransform", gxDC AsULong, gxTB Asstruct, result AsLongEndIfCallDLL#gdi32,"SelectObject", BmpCache AsULong, bitmap AsULong, junkBitmap AsULong' srcX srcY srcW srcHIf blitKey =-1Then' Stretch Blit:If blitFlip$ ="horizontal"Or blitFlip$ ="both"Then
destX = destX + destW
destW =0- destW
EndIfIf blitFlip$ ="vertical"Or blitFlip$ ="both"Then
destY = destY + destH
destH =0- destH
EndIfCallDLL#gdi32,"StretchBlt", gxDC AsULong,_
destX AsLong, destY AsLong, destW AsLong, destH AsLong,_
BmpCache AsULong, srcX AsLong, srcY AsLong, srcW AsLong, srcH AsLong,_
blitStyle AsLong, result AsLongElse' Transparent Blit:CallDLL#msimg32,"TransparentBlt", gxDC AsULong,_
destX AsLong, destY AsLong, destW AsLong, destH AsLong,_
BmpCache AsULong, srcX AsLong, srcY AsLong, srcW AsLong, srcH AsLong,_
blitKey AsULong, result AsLongEndIfCallDLL#gdi32,"SelectObject", BmpCache AsULong, junkBitmap AsULong, bitmap AsULongIf blitAngle <>0Then' Go back to the old transform setting:CallDLL#gdi32,"SetWorldTransform", gxDC AsULong, gxTA Asstruct, result AsLongEndIfReturn[CreateFont]CallDLL#gdi32,"CreateFontA",_
fontHeightPx AsLong,0AsLong,0AsLong,0AsLong, fontWeight AsLong, fontItalic AsLong,_
fontUnderline AsLong, fontStrikeout AsLong,0AsLong,0AsLong,0AsLong,0AsLong,0AsLong,_
fontFace$ AsPtr, font AsLongCallDLL#gdi32,"SelectObject", gxDC AsULong, font AsLong, oldFont AsLongIf oldFont ThenCallDLL#gdi32,"DeleteObject", oldFont AsLong, result AsLongReturn[NullPen]' The transparent pen for non-outlined shapes.CallDll#gdi32,"GetStockObject", _NULL_PEN AsULong, nullPen AsULongCallDLL#gdi32,"SelectObject", gxDC AsULong, nullPen AsULong, oldPen AsULongReturn[NonNullPen]' The other pen that is for outlined shapes.CallDLL#gdi32,"SelectObject", gxDC AsULong, oldPen AsULong, nullPen AsULongReturn[ResetPen]' Recreate the pen and select it.CallDLL#gdi32,"CreatePen", penStyle AsULong, penWidth AsLong, penColor AsULong, pen AsULong' Select the new pen:CallDLL#gdi32,"SelectObject", gxDC AsULong, pen AsULong, oldPen AsULongCallDLL#gdi32,"DeleteObject", oldPen AsULong, result AsLongReturn[ResetBrush]' Recreate the brush and select it.Select brushStyle
Case-1' Solid brush:CallDLL#gdi32,"CreateSolidBrush", fillColor AsLong, brush AsULongCase-2' No brush (invisible/hollow/null) brush:CallDll#gdi32,"GetStockObject", _HOLLOW_BRUSH AsULong, hollowBrush AsULong
brush = hollowBrush
CaseElse' Hatch brush of some kind:CallDLL#gdi32,"CreateHatchBrush",_
brushStyle AsLong, fillColor AsLong, brush AsULongEndSelect' Select the new brush:CallDLL#gdi32,"SelectObject", gxDC AsULong, brush AsULong, oldBrush AsULongCallDLL#gdi32,"DeleteObject", oldBrush AsULong, result AsLongReturn[CleanUp]' Replace the pen with the stock one. Delete the custom pen.CallDll#gdi32,"GetStockObject", _BLACK_PEN AsLong, blackPen AsULongCallDLL#gdi32,"SelectObject", gxDC AsULong, blackPen AsULong, oldPen AsULongCallDLL#gdi32,"DeleteObject", oldPen AsULong, result AsLong' Do the same for the brushies:' Save any changes into gx:
gxInfo.PenStyle.struct= penStyle
gxInfo.PenWidth.struct= penWidth
gxInfo.PenColor.struct= penColor
gxInfo.BrushStyle.struct= brushStyle
gxInfo.FillColor.struct= fillColor
gxInfo.StyleColor.struct= styleColor
gxInfo.Font.struct= font
gxInfo.FontHeight.struct= fontHeightPx
gxInfo.BlitStyle.struct= blitStyle
gxInfo.BlitKey.struct= blitKey
gxInfo.BlitAngle.struct= blitAngle
gxInfo.BlitOrigin$.struct= blitOrigin$
gxInfo.BlitFlip$.struct= blitFlip$
gxInfo.TextColor.struct= textColor
EndSubFunction gx.Color(color$)' Returns the RGB color version of color$.' color$ can be a "### ### ###" (rgb string) or a LB recognized color.' You don't need to use this function. This is for internal use by gxGL.IfWord$(color$,2)<>""Then' Color is a rgb string.
red =Val(Word$(color$,1))
green =Val(Word$(color$,2))
blue =Val(Word$(color$,3))
gx.Color = gx.RGB(red,green,blue)ExitFunction' Return the value.EndIf' Color must be a Liberty BASIC color:' Get the system "buttonface" color just in case:CallDLL#user32,"GetSysColor", _COLOR_BTNFACE AsLong, btnface asULong
color$ =Trim$(Lower$(color$))SelectCase color$
Case"buttonface": rgb = btnface
Case"yellow": rgb = gx.RGB(255,255,0)Case"brown": rgb = gx.RGB(128,128,0)Case"red": rgb = gx.RGB(255,0,0)Case"darkred": rgb = gx.RGB(128,0,0)Case"pink": rgb = gx.RGB(255,0,255)Case"darkpink": rgb = gx.RGB(128,0,128)Case"blue": rgb = gx.RGB(0,0,255)Case"darkblue": rgb = gx.RGB(0,0,128)Case"green": rgb = gx.RGB(0,255,0)Case"darkgreen": rgb = gx.RGB(0,128,0)Case"cyan": rgb = gx.RGB(0,255,255)Case"darkcyan": rgb = gx.RGB(0,128,128)Case"white": rgb = gx.RGB(255,255,255)Case"black": rgb =0Case"lightgray","lightgrey": rgb = gx.RGB(192,192,192)Case"darkgray","darkgrey": rgb = gx.RGB(128,128,128)EndSelect
gx.Color = rgb
EndFunctionFunction gx.RGB(r,g,b)' Returns a single RGB color representation of the given color.
gx.RGB =(b*256*256)+(g*256)+r
EndFunctionFunction gx.InternalFloat(R8)' This is an internal function for use by gxGL.' It converts a 64-bit double to a 32-bit number.' This is necessary for certain GDI functions.' You don't need to use this function.CallDLL#oleaut32,"VarR4FromR8", R8 AsDouble, gxLocal AsStruct, result AsLong
gx.InternalFloat = gxLocal.R4.structEndFunctionFunction gx.BlitStyle(style$)' Returns the GDI raster code for the internal gx blit style style$.' You don't need to use this function.SelectCaseLower$(Trim$(style$))Case"copy","normal": style = _SRCCOPY
Case"and": style = _SRCAND
Case"or": style = _SRCPAINT
Case"xor": style = _SRCINVERT
Case"invert": style = _NOTSRCCOPY
Case"orinvert": style = _NOTSRCERASE
Case"invertormerge": style = _MERGEPAINT
Case"invertfinal": style = _DSTINVERT
Case"invertfinaland": style = _SRCERASE
EndSelect
gx.BlitStyle = style
EndFunctionFunction gx.BitmapSize$(bitmap$)' Returns the dimensions of the bitmap with the name bitmap$.
bitmap =HBmp(bitmap$)
nsize =Len(gxGDIBitmap.struct)CallDLL#gdi32,"GetObjectA",_
bitmap AsULong, nsize AsLong, gxGDIBitmap Asstruct, result AsLong
width = gxGDIBitmap.bmWidth.struct: height = gxGDIBitmap.bmHeight.struct
gx.BitmapSize$ ="";width;" ";height
EndFunction
gx Graphics Library
This the code that makes the gx Graphics Library work. This page will always contain the most up-to-date version.Just paste this code into the bottom of your program to use the gx Graphics Library: