Go to file
Jakub Towarek 130c1722ce
Update README.md with link to SwiftyOLED
2020-01-05 14:26:33 +01:00
Sources [Fix] fixes memory leak when creating and using Text instances 2019-12-22 19:38:17 -06:00
SwiftyGFX.xcodeproj Add xcodeproj 2019-07-02 23:20:17 +02:00
Tests Make Shapes' initializers accessible 2019-09-10 00:58:34 +02:00
.gitignore Add xcodeproj 2019-07-02 23:20:17 +02:00
LICENSE Add LICENSE 2019-07-06 22:04:01 +02:00
Package.swift Edit package 2019-07-02 11:21:21 +02:00
README.md Update README.md with link to SwiftyOLED 2020-01-05 14:26:33 +01:00

README.md

SwiftyGFX

A swift graphics library intended for my SwiftyOLED library. Feel free to design API for it when creating display libraries using swift on arm.

Documentation

Coordinate system

This library uses iOS like coordinate system. The X axis is increasing to the right. The Y axis is increasing downwards.

Primitives

Each of defined primitives conforms to Drawable protocool. The library defines following groups of primitives:

Lines

The Bresenham's was used for drawing oblique lines. Even though you can draw horizontal and vertical lines with ObliqueLine class it is way faster to used either HorizontalLine or VerticalLine class.

    ObliqueLine(from origin: Point, to endPoint: Point)
    HorizontalLine(from origin: Point, to endPoint: Point)
    HorizontalLine(from origin: Point, lenght: UInt)
    VerticalLine(from origin: Point, to endPoint: Point)
    VerticalLine(from origin: Point, lenght: UInt)

If you pass incorret values to HorizontalLine or VerticalLine, that is points with diffrent y coordinates or x coordinates accordingly, library will back up to using y or x of origin.

Rectangles

    Rectangle(at origin: Point = Point(x: 0, y: 0), height: UInt, width: UInt)
    Square(at origin: Point = Point(x: 0, y: 0), sideSize a: UInt)

Ellipses

    Ellipse(at origin: Point = Point(x: 0, y: 0), yRadius: UInt, xRadius: UInt)
    Ellipse(at origin: Point = Point(x: 0, y: 0), height: UInt, width: UInt)
    Circle(at origin: Point = Point(x: 0, y: 0), radius: UInt)
    Circle(at origin: Point = Point(x: 0, y: 0), width: UInt)

Triangles

    Triangle(at origin: Point = Point(x: 0, y: 0), corner1: Point, corner2: Point, corner3: Point)

Text

If you do not specify the pathToFont parameter the library will try to use DejaVuSans font which is embeded into Raspbian. If that fails the library will try to get list of all installed fonts from fontconfig package and use the first one. If that fails library will raise fatalError.

    Text(_ text: String, font pathToFont: String? = nil, at origin: Point = Point(x: 0, y: 0), pixelHeight: UInt32 = 16, pixelWidth: UInt32 = 16)

You can change text size by using one of two methods:

    public func setPixel(height: UInt32, width: UInt32)
    public func setChar(height: Int, width: Int, horizontalResolution: UInt32, verticalResolution: UInt32)

These two are just wrappers around FT_Set_Pixel_Sizes and FT_Set_Char_Size from FreeType 2 library. For more info go to it's documentation.

Filling

The Rectangle, Square, Ellipse, Circle, Triangle types can be filled. This functionality is provided by .fill() and .filled() methods. Only diffrence is that .filled() returns a filled copy of object it's been called on.

Rendering

The Drawable protocool guarantes that for each object you can generate array of tuplets of integer and integer by calling .generatePointsForDrawing(). This effectively is array of points (each having X and Y coordinate). They can be passed to the display library of your choice and therefore be displayed.

Contributing

Feel free to sugest changes, report bugs and issues, create pull requests.