This is an REFramework plugin that adds a Direct2D scripting API.
Currently suggest building in RelWithDebInfo so that when issues arise you can debug and fix them.
git clone https://github.com/cursey/reframework-d2d.git
cd reframework-d2d
cmake -B build
cmake --build build --config RelWithDebInfo
local font = nil
local image = nil
d2d.register(function()
font = d2d.Font.new("Tahoma", 50)
image = d2d.Image.new("test.png") -- Loads <gamedir>/reframework/images/test.png
end,
function()
d2d.text(font, "Hello World!", 0, 0, 0xFFFFFFFF)
d2d.text(font, "你好世界!", 0, 50, 0xFFFF0000) -- chinese
d2d.text(font, "こんにちは世界!", 0, 100, 0xFF00FF00) -- japanese
d2d.text(font, "안녕하세요, 세계입니다!", 0, 150, 0xFF0000FF) -- korean
d2d.text(font, "Привет мир!", 0, 200, 0xFFFF00FF) -- russian
d2d.text(font, "😁💕😒😘🤣😂😊🤔🥴👈👉🤦♀️", 0, 250, 0xFFFFFF00) -- emoji
local str = "This is only a test"
local w, h = font:measure(str)
d2d.fill_rect(500, 100, w, h, 0xFFFFFFFF)
d2d.text(font, str, 500, 100, 0xFF000000)
d2d.outline_rect(500, 100, w, h, 5, 0xFF00FFFF)
d2d.quad(100, 100, 500, 100, 500, 500, 400, 500, 5, 0xFF00FFFF)
d2d.fill_quad(1100, 1100, 1500, 1100, 1500, 1500, 1400, 1500, 0xFF00FFFF)
local screen_w, screen_h = d2d.surface_size()
local img_w, img_h = image:size()
-- Draw image at the bottom right corner of the screen in its default size.
d2d.image(image, screen_w - img_w, screen_h - img_h)
-- Draw image at the bottom left corner of the screen but scaled to 50x50.
d2d.image(image, 0, screen_h - 50, 50, 50)
-- x, y, width, height, corner round x, corner round y, thickness, color
d2d.rounded_rect(400, 500, 80, 40, 5, 15, 5, 0xFF00FFFF)
-- x, y, width, height, corner round x, corner round y, color
d2d.fill_rounded_rect(400, 500, 80, 40, 5, 15, 0xFF00FFFF)
-- x, y, radius, color
d2d.fill_circle(600, 500, 50, 0xFF00FFFF)
-- x, y, radius x, radius y, color
d2d.fill_oval(700, 500, 50, 80, 0xFF00FFFF)
-- x, y, radius, thickness, color
d2d.circle(800, 500, 50, 5, 0xFF00FFFF)
-- x, y, radius x, radius y, thickness, color
d2d.oval(900, 500, 50, 80, 5, 0xFF00FFFF)
-- x, y, radius, start angle, sweep angle, color
d2d.pie(1000, 500, 50, 0, 240, 0xFF00FFFF)
d2d.pie(1100, 500, 50, 60, 240, 0xFF00FFFF)
-- negative start angle equals +360 degree
d2d.pie(1200, 100, 50, -90, 240, 0xFF00FFFF)
d2d.pie(1200, 200, 50, 270, 240, 0xFF00FFFF)
-- with clockwise=false
d2d.pie(1300, 100, 50, -90, 240, 0xFF00FFFF, false)
-- x, y, outer radius, inner radius, start angle, sweep angle, color
d2d.ring(1200, 500, 50, 30, 0, 240, 0xFF00FFFF)
d2d.ring(1300, 500, 50, 30, 60, 240, 0xFF00FFFF)
-- negative start angle equals +360 degree
d2d.ring(1600, 100, 50, 30, -90, 240, 0xFF00FFFF)
d2d.ring(1600, 200, 50, 30, 270, 240, 0xFF00FFFF)
-- with clockwise=false
d2d.ring(1700, 100, 50, 30, -90, 240, 0xFF00FFFF, false)
end)Registers your script with d2d allowing you to create d2d resources and draw using them.
init_fna function that gets called when your script should create d2d resources (such as fonts viad2d.create_font)draw_fna function that gets called when your script should draw using d2d and the d2d resources you've created in yourinit_fn
This function has been deprecated in favor of d2d.Font.new(...)
Creates a font resource.
namethe font family namesizethe size of the created fontboldan optional boolean value to make the font bolditalicand optional boolean value to make the font italic
You must call this function from the init_fn passed to d2d.register. That's the only valid place to call it.
Draws text on the screen at the position you supply using a font resource you've created.
fontthe font resource you've created in yourinit_fnviad2d.Font.new(...)textthe text to drawxthe horizontal position on the screenythe vertical position on the screencolorthe ARGB color of the text
This function has been deprecated in favor of d2d.Font:measure(...)
Returns the width and height of the rendered text
fontthe font resource you've created in yourinit_fnviad2d.Font.new(...)textthe text to measure
Draws a filled in rectangle
xthe horizontal position on the screenythe vertical position on the screenwthe width of the rectanglehthe height of the rectanglecolorthe ARGB color of the rectangle
Draws the outline of a rectangle
xthe horizontal position on the screenythe vertical position on the screenwthe width of the rectanglehthe height of the rectanglethicknessthe thickness of the outlinecolorthe ARGB color of the rectangle
Draws the outline of a rounded rectangle
xthe horizontal position on the screenythe vertical position on the screenwthe width of the rectanglehthe height of the rectanglerXthe corner radius XrYthe corner radius Ythicknessthe thickness of the outlinecolorthe ARGB color of the rectangle
Draws a filled in a rounded rectangle
xthe horizontal position on the screenythe vertical position on the screenwthe width of the rectanglehthe height of the rectanglerXthe corner radius XrYthe corner radius Ycolorthe ARGB color of the rectangle
Draws the outline of a quad
x1, y1the first coordinatex2, y2the second coordinatex3, y3the third coordinatex4, y4the fourth coordinatethicknessthe thickness of the outlinecolorthe ARGB color of the quad
Draws a filled in a quad
x1, y1the first coordinatex2, y2the second coordinatex3, y3the third coordinatex4, y4the fourth coordinatecolorthe ARGB color of the quad
Draws a line between two points
x1the first horizontal position on the screeny1the first vertical position on the screenx2the second horizontal position on the screeny2the second vertical position on the screenthicknessthe thickness of the linecolorthe ARGB color of the rectangle
Draws the outline of a circle
xthe horizontal center on the screenythe vertical center on the screenrthe radius of the circlethicknessthe thickness of the outlinecolorthe ARGB color of the circle
Draws a filled in a circle
xthe horizontal center on the screenythe vertical center on the screenrthe radius of the circlecolorthe ARGB color of the circle
Draws the outline of a oval
xthe horizontal center on the screenythe vertical center on the screenrXthe horizontal radius of the ovalrYthe vertical radius of the ovalthicknessthe thickness of the outlinecolorthe ARGB color of the oval
Draws a filled in a oval
xthe horizontal center on the screenythe vertical center on the screenrXthe horizontal radius of the ovalrYthe vertical radius of the ovalcolorthe ARGB color of the oval
Draws a filled pie
xthe horizontal center on the screenythe vertical center on the screenstartAnglethe pie start angle, range from -360 to 360.sweepAnglethe pie sweep angle, range from 0 to 360.colorthe ARGB color of the pieclockwiseby default is true, clockwise. Set false to counter clockwise.
Draws a filled ring
xthe horizontal center on the screenythe vertical center on the screenouterRadiusthe ring outer radiusinnerRadiusthe ring inner radiusstartAnglethe pie start angle, range from -360 to 360.sweepAnglethe pie sweep angle, range from 0 to 360.colorthe ARGB color of the pieclockwiseby default is true, clockwise. Set false to counter clockwise.
Draws an image at the specified position, optionally scaled.
imagethe image resource loaded in yourinit_fnviad2d.Image.new(...)xthe horizontal position on the screenythe vertical position on the screenwthe optional width to scale the image byhthe optional height to scale the image by
If the w and h parameters are omitted, the image will be drawn at its natural size.
Returns the width and height of the drawable surface. This is essentially the screen or window size of the game.
Represents a d2d font resource.
Creates a font resource.
namethe font family namesizethe size of the created fontboldan optional boolean value to make the font bolditalicand optional boolean value to make the font italic
You must call this function from the init_fn passed to d2d.register. That's the only valid place to call it.
Returns the width and height of the rendered text.
textthe text to measure
Represents a d2d image resource.
Loads an image resource from <gamedir>\reframework\images\<filepath>.
filepathA file path for the image to load
Returns the width and height of the image in pixels.