Wedge

Package: Libraries.Interface.Controls.Charts.Graphics · Inherits from: Libraries.Interface.Controls.Control, Libraries.Game.Graphics.Drawable, Libraries.Interface.Events.TouchListener, Libraries.Interface.Item, Libraries.Interface.Controls.Charts.ChartItem, Libraries.Interface.Item2D, Libraries.Language.Object, Libraries.Interface.Controls.Charts.Graphics.ChartDrawable, Libraries.Interface.Events.TextureLoadListener, Libraries.Game.Graphics.TextureRegion, Libraries.Game.Disposable

The Wedge class is used to render wedges in a pie chart. Wedges have an outer radius that measures the number of pixels from the origin (the center of a pie chart) to the outer edge of the wedge. They also have an inner radius that measures how many pixels are between the origin and the start of the wedge, allowing for "donut" style charts. A wedge should always be the same size as its parent container. If it doesn't have a parent, the wedge should be large enough to render the whole circle, even if it's only a portion of it.

Example Code

use Libraries.Game.Game
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Color
use Libraries.Interface.Controls.Charts.Graphics.Wedge

class Main is Game
action Main
    StartGame()
end

action CreateGame
    Color color

    Drawable pieChart
    pieChart:LoadFilledRectangle(400, 400, color:White())

    // Put it wedges until we've filled a whole pie chart shape.
    number total = 0
    repeat until total >= 1
        Wedge wedge
        Color newColor
        newColor:SetColor(1 - total, 0.5, total, 1)
        wedge:Load(newColor)

        // The size of the wedge should match the size of its parent container.
        // If it isn't a child of another item, it should be large enough to contain the entire circle, even if it's only a portion of it.
        wedge:SetSize(pieChart:GetWidth(), pieChart:GetHeight())
        wedge:SetOuterRadius(180)
        wedge:SetInnerRadius(25)
        
        number newTotal = total + 0.125

        // Each wedge is positioned according to what percent of a pie chart it begins and ends at.
        // The percentages are stored as values between 0 and 1.
        wedge:SetStartPercentage(total)
        wedge:SetEndPercentage(newTotal)

        total = newTotal
        pieChart:Add(wedge)
    end

    Add(pieChart)
end
end

Variables

  • text WEDGE_SHADER_PROGRAM_NAME

Actions

BeganTouch(Libraries.Interface.Events.TouchEvent event)

Parameters

Contains(number containsX, number containsY)

This action tests if a point in global x,y coordinates is contained inside this Item2D. The global coordinates are considered to be the x and y coordinates of this Item plus its offsetX and offsetY values.

Parameters

  • containsX number
  • containsY number

Returns

boolean: Whether or not the point is contained in this Item.

Example

use Libraries.Interface.Item2D

Item2D item
item:SetPosition(50, 50)
item:SetWidth(100)
item:SetHeight(50)
boolean value = item:Contains(125, 70)

ContinuedTouch(Libraries.Interface.Events.TouchEvent event)

Parameters

CreateGame()

EndedTouch(Libraries.Interface.Events.TouchEvent event)

Parameters

GetCrustColor()

This action sets the distance between the wedge's origin point and the inner edge, in pixels. In other words, this represents how many empty pixels should appear between the origin and the start of this wedge. If this value is 0, the wedge will begin directly from the origin point with no gap.

Returns

Libraries.Game.Graphics.Color

GetCrustThickness()

This action sets the distance (in pixels) from the origin point of the wedge to the outer edge. The origin is determined to be the midpoint of the parent item, if there is one. If the wedge doesn't have a parent item, the origin point will be the midpoint of the wedge item.

Returns

number

GetEndPercentage()

This action determines where the wedge ends along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Returns

number: A value between 0 and 1 indicating where the wedge ends on the circle.

GetInnerRadius()

This action returns the distance between the wedge's origin point and the inner edge, in pixels. In other words, this represents how many empty pixels should appear between the origin and the start of this wedge. If this value is 0, the wedge will begin directly from the origin point with no gap.

Returns

number: The radius from the origin point to the inner edge of the wedge.

GetOuterRadius()

This action returns the distance (in pixels) from the origin point of the wedge to the outer edge. The origin is determined to be the midpoint of the parent item, if there is one. If the wedge doesn't have a parent item, the origin point will be the midpoint of the wedge item.

Returns

number: The radius from the origin point to the outer edge of the wedge.

GetRadialOffset()

This action determines where the wedge ends along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Returns

number

GetShaderProgram()

The origin point is the midpoint of the parent item, or the midpoint of this item if there is no parent.

Returns

Libraries.Game.Graphics.Shaders.Programs.ShaderProgram

GetStartPercentage()

This action determines where the wedge begins along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Returns

number: A value between 0 and 1 indicating where the wedge begins on the circle.

GetUnitX()

This action loads the wedge so it can be rendered. It will be loaded with the provided color, but like other Drawables, its color can be changed later using the SetColor action.

Returns

number

GetUnitY()

Returns

number

Load(Libraries.Game.Graphics.Color color)

This action loads the wedge so it can be rendered. It will be loaded with the provided color, but like other Drawables, its color can be changed later using the SetColor action.

Parameters

SetCrustColor(Libraries.Game.Graphics.Color crustColor)

This action returns the distance (in pixels) from the origin point of the wedge to the outer edge. The origin is determined to be the midpoint of the parent item, if there is one. If the wedge doesn't have a parent item, the origin point will be the midpoint of the wedge item.

Parameters

SetCrustThickness(number crustThickness)

This action determines where the wedge begins along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Parameters

  • crustThickness number

SetEndPercentage(number endPercentage)

This action determines where the wedge ends along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Parameters

  • endPercentage number: A value between 0 and 1 indicating where the wedge ends on the circle.

SetInnerRadius(number innerRadius)

This action sets the distance between the wedge's origin point and the inner edge, in pixels. In other words, this represents how many empty pixels should appear between the origin and the start of this wedge. If this value is 0, the wedge will begin directly from the origin point with no gap.

Parameters

  • innerRadius number: The new radius from the origin point to the inner edge of the wedge.

SetOuterRadius(number outerRadius)

This action sets the distance (in pixels) from the origin point of the wedge to the outer edge. The origin is determined to be the midpoint of the parent item, if there is one. If the wedge doesn't have a parent item, the origin point will be the midpoint of the wedge item.

Parameters

  • outerRadius number: The new radius from the origin point to the outer edge of the wedge.

SetRadialOffset(number radialOffset)

This action tests if a point in global x,y coordinates is contained inside this Item2D. The global coordinates are considered to be the x and y coordinates of this Item plus its offsetX and offsetY values.

Parameters

  • radialOffset number

Example

use Libraries.Interface.Item2D

Item2D item
item:SetPosition(50, 50)
item:SetWidth(100)
item:SetHeight(50)
boolean value = item:Contains(125, 70)

SetStartPercentage(number startPercentage)

This action determines where the wedge begins along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Parameters

  • startPercentage number: A value between 0 and 1 indicating where the wedge begins on the circle.

SetUnitX(number unitX)

This action returns the distance between the wedge's origin point and the inner edge, in pixels. In other words, this represents how many empty pixels should appear between the origin and the start of this wedge. If this value is 0, the wedge will begin directly from the origin point with no gap.

Parameters

  • unitX number

SetUnitY(number unitY)

Parameters

  • unitY number

ShowCrust(boolean showCrust)

This action determines where the wedge ends along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Parameters

  • showCrust boolean

ShowingCrust()

This action determines where the wedge begins along a circle, as a percentage represented between 0 and 1. A value of 0 is placed at the top of the circle, moving clockwise as the value increases. For example, a wedge with a start percentage of 0.25 and an end percentage of 0.5 will start on the right side and end at the bottom, filling the bottom-right quadrant of a circle.

Returns

boolean

Inherited Actions

62 actions from Libraries.Game.Graphics.Drawable
27 actions from Libraries.Game.Graphics.TextureRegion
28 actions from Libraries.Interface.Controls.Charts.ChartItem
49 actions from Libraries.Interface.Controls.Charts.Graphics.ChartDrawable
259 actions from Libraries.Interface.Controls.Control
60 actions from Libraries.Interface.Item
194 actions from Libraries.Interface.Item2D
3 actions from Libraries.Language.Object