Class: Toybox::Graphics::Dc

Inherits:
Lang::Object show all

Overview

Note:

You should never directly instantiate a Dc object, or attempt to render to the screen outside of an onUpdate call.

This class represents a device context.

It provides methods to perform drawing operations on the device.

Examples:

Draws a blue rectangle using direct pixel parameters.

using Toybox.Graphics;
function onUpdate(dc) {
    dc.setColor(Graphics.COLOR_BLUE, Graphics.COLOR_BLACK);
    dc.fillRectangle(100, 100, 100, 100);
}

Draws a red circle using direct pixel parameters.

using Toybox.Graphics;
function onUpdate(dc) {
    dc.setColor(Graphics.COLOR_RED, Graphics.COLOR_BLACK);
    dc.fillCircle(50, 100, 75);
}

Draws “Hello World” in the center of the screen using calls to the Device Context (dc).

using Toybox.Graphics;
function onUpdate(dc) {
    dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_TRANSPARENT);
    dc.drawText(
        dc.getWidth() / 2,                      // gets the width of the device and divides by 2
        dc.getHeight() / 2,                     // gets the height of the device and divides by 2
        Graphics.FONT_LARGE,                    // sets the font size
        "Hello World",                          // the String to display
        Graphics.TEXT_JUSTIFY_CENTER            // sets the justification for the text
                );
}

Clears the screen of device with background color (Graphics.COLOR_BLACK).

using Toybox.Graphics;
function onUpdate(dc) {
    dc.setColor(Graphics.COLOR_BLACK, Graphics.COLOR_BLACK);
    dc.clear();
}

Since:

  • 1.0.0

Instance Method Summary collapse

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Instance Method Details

clearObject

Erase the screen using the background color.

Starting form version 3.1.0, COLOR_TRANSPARENT will also be honored as background color,
which will cause the value of pixels in the clip region to be replaced by COLOR_TRANSPARENT.
For example, this can be used to clear the transparent overlay layer
so animation background is visible.

Since:

  • 1.0.0


5845
5846
# File 'Monkeybrains.rb', line 5845

def clear()
end

clearClipObject

Reset the drawable area to the full area of the Dc.

Since:

  • 2.3.0


6038
6039
# File 'Monkeybrains.rb', line 6038

def clearClip()
end

drawArc(x, y, r, attr, degreeStart, degreeEnd) ⇒ Object

Draw an arc.

  • 0 degrees: 3 o'clock position.

  • 90 degrees: 12 o'clock position.

  • 180 degrees: 9 o'clock position.

  • 270 degrees: 6 o'clock position.

Parameters:

Since:

  • 1.2.0


6084
6085
# File 'Monkeybrains.rb', line 6084

def drawArc(x, y, r, attr, degreeStart, degreeEnd)
end

drawBitmap(x, y, bitmap) ⇒ Object

Draw a bitmap to the screen.

Parameters:

Raises:

Since:

  • 1.0.0


5908
5909
# File 'Monkeybrains.rb', line 5908

def drawBitmap(x, y, bitmap)
end

drawCircle(x, y, radius) ⇒ Object

Draw a circle around a point.

Parameters:

Since:

  • 1.0.0


5853
5854
# File 'Monkeybrains.rb', line 5853

def drawCircle(x, y, radius)
end

drawEllipse(x, y, a, b) ⇒ Object

Draw an ellipse around a point.

Parameters:

Since:

  • 1.0.0


5864
5865
# File 'Monkeybrains.rb', line 5864

def drawEllipse(x, y, a, b)
end

drawLine(x1, y1, x2, y2) ⇒ Object

Draw a line between two points.

Parameters:

Since:

  • 1.0.0


5917
5918
# File 'Monkeybrains.rb', line 5917

def drawLine(x1, y1, x2, y2)
end

drawPoint(x, y) ⇒ Object

Draw a point on the screen.

Parameters:

Since:

  • 1.0.0


5871
5872
# File 'Monkeybrains.rb', line 5871

def drawPoint(x, y)
end

drawRectangle(x, y, width, height) ⇒ Object

Draw a rectangle.

Parameters:

Since:

  • 1.0.0


5881
5882
# File 'Monkeybrains.rb', line 5881

def drawRectangle(x, y, width, height)
end

drawRoundedRectangle(x, y, width, height, radius) ⇒ Object

Draw a rounded rectangle.

Parameters:

Since:

  • 1.0.0


5892
5893
# File 'Monkeybrains.rb', line 5892

def drawRoundedRectangle(x, y, width, height, radius)
end

drawText(x, y, font, text, justification) ⇒ Object

Draw text at the given location.

This method is not supported for anti-aliased fonts (including most built in fonts) for a BufferedBitmap that has a palette.

Parameters:

  • x (Toybox::Lang::Number)

    The x location of the text

  • y (Toybox::Lang::Number)

    The y location of the text

  • font (Toybox::WatchUi::FontResource)

    The font to use. This can be a custom font loaded from resources or a Graphics.FONT_* value

  • text (Toybox::Lang::String)

    The String to render. This can be a String loaded from resources or a hard coded String

  • justification

    Mask of Graphics.TEXT_JUSTIFY_* constants. This may either be a single Graphics.TEXT_JUSTIFY_* contant, or a combination of one vertical and one horizontal justification value as a bit mask (e.g., Graphics.TEXT_JUSTIFY_CENTER | Graphics.TEXT_JUSTIFY_VCENTER).

Raises:

Since:

  • 1.0.0


5987
5988
# File 'Monkeybrains.rb', line 5987

def drawText(x, y, font, text, justification)
end

fillCircle(x, y, radius) ⇒ Object

Fill a circle with the foreground color.

Parameters:

Since:

  • 1.0.0


5925
5926
# File 'Monkeybrains.rb', line 5925

def fillCircle(x, y, radius)
end

fillEllipse(x, y, a, b) ⇒ Object

Fill an ellipse with the foreground color.

Parameters:

Since:

  • 1.0.0


5936
5937
# File 'Monkeybrains.rb', line 5936

def fillEllipse(x, y, a, b)
end

fillPolygon(pts) ⇒ Object

Fill a polygon with the foreground color.

Parameters:

Since:

  • 1.0.0


5943
5944
# File 'Monkeybrains.rb', line 5943

def fillPolygon(pts)
end

fillRectangle(x, y, width, height) ⇒ Object

Fill a rectangle with the foreground color.

Parameters:

Since:

  • 1.0.0


5953
5954
# File 'Monkeybrains.rb', line 5953

def fillRectangle(x, y, width, height)
end

fillRoundedRectangle(x, y, width, height, radius) ⇒ Object

Fill a rounded rectangle with the foreground color.

Parameters:

Since:

  • 1.0.0


5964
5965
# File 'Monkeybrains.rb', line 5964

def fillRoundedRectangle(x, y, width, height, radius)
end

getFontHeight(font) ⇒ Toybox::Lang::Number

Get the height of a font.

Parameters:

Returns:

Since:

  • 1.0.0


6066
6067
# File 'Monkeybrains.rb', line 6066

def getFontHeight(font)
end

getHeightToybox::Lang::Number

Get the height of the display region that is available to the app.

Returns:

Since:

  • 1.0.0


6050
6051
# File 'Monkeybrains.rb', line 6050

def getHeight()
end

getTextDimensions(text, font) ⇒ Toybox::Lang::Array

Get the width and height of a String.

This takes new lines into account when determining the height. The width is the maximum width for a given line of the String. If a String has two newline characters (\n) in it, the height would be for three lines and the width would be the width of the longest String.

Parameters:

Returns:

Since:

  • 1.0.0


6003
6004
# File 'Monkeybrains.rb', line 6003

def getTextDimensions(text, font)
end

getTextWidthInPixels(text, font) ⇒ Toybox::Lang::Number

Get the width of a String.

Parameters:

Returns:

Since:

  • 1.0.0


6059
6060
# File 'Monkeybrains.rb', line 6059

def getTextWidthInPixels(text, font)
end

getWidthToybox::Lang::Number

Get the width of the display region that is available to the app.

Returns:

Since:

  • 1.0.0


6044
6045
# File 'Monkeybrains.rb', line 6044

def getWidth()
end

setClip(x, y, width, height) ⇒ Object

Apply a clipping region to the Dc.

Pixels outside of the region will not be affected by any operations.

Parameters:

Since:

  • 2.3.0


6033
6034
# File 'Monkeybrains.rb', line 6033

def setClip(x, y, width, height)
end

setColor(foreground, background) ⇒ Object

Set the current foreground and background colors.

Parameters:

  • foreground (Toybox::Lang::Number)

    Graphics.COLOR_* constant or 24-bit integer of the form 0xRRGGBB.

  • background (Toybox::Lang::Number)

    Graphics.COLOR_* constant or 24-bit integer of the form 0xRRGGBB.

Since:

  • 1.0.0


6012
6013
# File 'Monkeybrains.rb', line 6012

def setColor(foreground, background)
end

setPenWidth(width) ⇒ Object

Set the width of a line.

Parameters:

Since:

  • 1.0.0


6018
6019
# File 'Monkeybrains.rb', line 6018

def setPenWidth(width)
end