1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00
8
Drawing
Robert Beekman edited this page 2017-09-12 14:18:58 +02:00

The Drawing variable lets you draw brushes to the keyboard in different shapes.
To get the Drawing variable you need to subscribe to the DeviceDrawing event, as shown in the examples paired with each funtion.

Overview

Functions

DrawEllipse

Draws an ellipse on the keyboard.

Syntax:

DrawEllipse(brush brush, double x, double y, double height, double width)
Required arguments
  • brush: A brush used to fill the ellipse
  • x: The X-position of the ellipse, from the top-left
  • y: The Y-position of the ellipse, from the top-left
  • height: The width of the ellipse
  • width: The height of the ellipse

Example:

-- Create a brush we want to draw to the keyboard at a later time
local redBrush = Brushes.GetSolidColorBrush(Brushes.GetColor(255, 255, 0, 0))

-- This function will be called after every profile draw.
function drawHandler(profile, eventArgs)
    -- Draw an ellipse (in this case a circle) in the top left 
    eventArgs.Drawing.DrawEllipse(redBrush, 0, 0, 5, 5)
end

-- Subscribe to the event AFTER defining the function which must be subscribed.
Events.DeviceDrawing.add(drawHandler)

Result:

Drawing the ellipse would look like this:
Ellipse


DrawLine

Draws a line on the keyboard.

Syntax:

DrawLine(brush brush, double startX, double startY, double endX, double endY, double thickness)
Required arguments
  • brush: A brush used to fill the line
  • startX: The X-position of the starting point of the line
  • startY: The Y-position of the starting point of the line
  • endX: The X-position of the end point of the line
  • endY: The Y-position of the end point of the line
  • thickness: The thickness of the line

Example:

-- Create a brush we want to draw to the keyboard at a later time
local redBrush = Brushes.GetSolidColorBrush(Brushes.GetColor(255, 255, 0, 0))

-- This function will be called after every profile draw.
function drawHandler(profile, eventArgs)
    -- Draw a line from the top left to the bottom left
    eventArgs.Drawing.DrawLine(redBrush, 0, 0, 5, 5, 1)
end

-- Subscribe to the event AFTER defining the function which must be subscribed.
Events.DeviceDrawing.add(drawHandler)

Result:

Drawing the line would look like this:
Line


DrawRectangle

Draws an rectangle on the keyboard.

Syntax:

DrawRectangle(brush brush, double x, double y, double height, double width)
Required arguments
  • brush: A brush used to fill the rectangle
  • x: The X-position of the rectangle, from the top-left
  • y: The Y-position of the rectangle, from the top-left
  • height: The width of the rectangle
  • width: The height of the rectangle

Example:

-- Create a brush we want to draw to the keyboard at a later time
local redBrush = Brushes.GetSolidColorBrush(Brushes.GetColor(255, 255, 0, 0))

-- This function will be called after every profile draw.
function drawHandler(profile, eventArgs)
    -- Draw an rectangle (in this case a square) in the top left 
    eventArgs.Drawing.DrawRectangle(redBrush, 0, 0, 5, 5)
end

-- Subscribe to the event AFTER defining the function which must be subscribed.
Events.DeviceDrawing.add(drawHandler)

Result:

Drawing the rectangle would look like this:
Rectangle


DrawText

Draws a text string on the keyboard.
Note: Drawing text to the keyboard has very little practical use. Since the keys aren't aligned in a grid it's not very readable. The main reason I've included this function is so that you can use it to draw symbols, such as <, >, ^ etc.

Syntax:

DrawText(brush brush, double x, double y, string text, int fontSize)
Required arguments
  • brush: A brush used to fill the rectangle
  • x: The X-position of the text, from the top-left
  • y: The Y-position of the text, from the top-left
  • text: The text to draw
  • fontSize: The font size of the text to draw.

Note: As you can see in the example, for the best result I use a fontsize of 11, using the entire keyboard's height (on a K95 at least).
To compensate for the margin the font has on the top I'm using a Y-value of -2.4.

Example:

-- Create a brush we want to draw to the keyboard at a later time
local redBrush = Brushes.GetSolidColorBrush(Brushes.GetColor(255, 255, 0, 0))

-- This function will be called after every profile draw.
function drawHandler(profile, eventArgs)
    -- In this example we only want to draw to the keyboard. Each device has it's
    -- own drawing event
    if not (eventArgs.DeviceType == "keyboard") then
        return
    end
    -- Draw the text "hi" on the keyboard.
    eventArgs.Drawing.DrawText(redBrush, 4, -2.4, "hi", 11)    
end

-- Subscribe to the event AFTER defining the function which must be subscribed.
Events.DeviceDrawing.add(drawHandler)

Result:

Drawing the text would look like this:
Text