Display

About Display

Type: Framework
License: FREE
Supported platforms:

       

Categories:
  • Debug
  • Graphics
  • Text Processing
  • User Interface

Display library extends some of the basic Gideros classes like Sprite, Mesh, etc. with additional functionality.

Provided Classes

• Container [Extends Sprite]
• Image [Extends Container]
• Mesh [Extends original Gideros Mesh with Container methods]
• Shape [Extends Container and implements Gideros Shape]
• Rectangle [Extends Shape]
• Circle [Extends Shape]
• ArcFilled [Extends Shape]
• TTFont [Extends Gideros TTFont]
• Text [Extends Container]
• MLText [Extends Container]

Static Fields

• [boolean] Display.X_STRETCHED
• [boolean] Display.Y_STRETCHED
• [num] Display.ACTUAL_RATIO -> (Total height)/ (Total width)
• [num] Display.LOGICAL_RATIO -> (Project properties height)/ (Project properties width)
• [num] Display.FULL_WIDTH -> Same scale as Gideros coordinate system, but reflects true device width
• [num] Display.FULL_HEIGHT -> Same scale as Gideros coordinate system, but reflects true device height
• [num] Display.WIDTH -> Project properties width
• [num] Display.HALF_WIDTH -> Display.WIDTH/2
• [num] Display.HEIGHT -> Project properties height
• [num] Display.HALF_HEIGHT -> Display.HEIGHT/2
• [num] Display.LEFT -> Absolute screen left edge (Useful for UI positioning)
• [num] Display.RIGHT -> Absolute screen right edge (Useful for UI positioning)
• [num] Display.TOP -> Absolute screen top edge (Useful for UI positioning)
• [num] Display.BOTTOM -> Absolute screen bottom edge (Useful for UI positioning)

Code example:

local group = Container.new()

-- Rectangle with width 100, height 200, parent "group"
local rect = Rectangle.new(100, 200, group)
-- Set center anchor point
rect:setAnchorPoint(0.5, 0.5)
-- Set appearance
rect:setFillColor(255, 0, 0)
print("Fill color: "..rect:getFillColor())
rect:setLineColor(0, 255, 0)
print("Line color: "..rect:getLineColor())
rect:setLineWidth(20)
print("Line width: "..rect:getLineWidth())

-- Circle with radius 50 and parent "group"
local cir = Circle.new(50, group)

-- Arc with radius 65 and parent "group"
local arc = ArcFilled.new(65, 135, group)
arc:setFillColor(0, 0, 255)
arc:setPosition(100, -70)
arc:setLineColor(255, 0, 255)

-- Setting positions and anchor points with free-form polygons
local s = Shape.new()
s:beginPath(Shape.NON_ZERO)
s:setFillColor(125, 100, 56)
s:moveTo(0, 0)
s:lineTo(30, -30*math.sqrt(3))
s:lineTo(60, 0)
s:closePath()
s:endPath()
s:setAnchorPoint(0, 0)
group:addChild(s)

-- Mesh
local mesh  = Mesh.new()
mesh:setVertexArray(0, 0, 150, 0, 150, 150, 0, 150)
mesh:setIndexArray(1, 2, 4, 2, 3, 4)
mesh:setColorArray(0xff0000, 1.0, 0xff0000, 1.0, 0xffff00, 0.5, 0xffff00, 0.5) 
mesh:setAnchorPoint(0.5, 0.5)
mesh:setPosition(Display.HALF_WIDTH, Display.HALF_HEIGHT)
mesh:setRotation(45)
mesh:toBack()
mesh:toFront()
print("Mesh z-index: "..mesh:getZ())
mesh:deltaZ(-1)

-- Font
local font = TTFont.new("Ethnocen.ttf", 25, true)
print("Font size: "..font:getSize())
print("Font cache: "..tostring(font:getCache()))
print("Font name: "..font:getFontname())
print("Font filtered: "..tostring(font:getFiltered()))

-- Text
local txt = Text.new(font, "Text")
txt:setPosition(10, 75)
txt:setFontSize(txt:getFontSize() + 1)
print("Text font size: "..txt:getFontSize())
txt:setTextColor(255, 125, 0)
print("Text color: "..txt:getTextColor())
txt:setLetterSpacing(5)
print("Text letter spacing: "..txt:getLetterSpacing())
group:addChild(txt)

-- MLText
local mltxt = MLText.new(font, "This is just a bunch of text... asdka djalsj daodiw judoiajd asldou")
mltxt:setWidth(300)

local function changeSize(event)
	mltxt:setFontSize(mltxt:getFontSize() + 1)
	mltxt:setWidth(mltxt:getWidth() - 1)
	mltxt:setAlignment(mltxt:getAlignment() + 0.05)
end

local t = Timer.new(500, 10)
t:addEventListener(Event.TIMER, changeSize)
t:start()

-- Change x-coord by +100
group:deltaX(100)
-- Set bottom left anchor point
group:setAnchorPoint(0, 0)
-- Align to top left corner of display (Regardless of device size if using Letterbox scaling!)
group:setPosition(Display.LEFT, Display.TOP)

-- Similar examples
Timer.delayedCall(1000, function(event)
	rect:setLineWidth(nil)
	group:setAnchorPoint(1, 0)
	group:setPosition(Display.RIGHT, Display.TOP)
end)
Timer.delayedCall(2000, function(event)
	rect:setLineWidth(20)
	group:setAnchorPoint(1, 1)
	group:setPosition(Display.RIGHT, Display.BOTTOM)
end)
Timer.delayedCall(3000, function(event)
	rect:setLineWidth(nil)
	group:setAnchorPoint(0, 1)
	group:setPosition(Display.LEFT, Display.BOTTOM)
end)

-- Remove all objects within "group" after 4 seconds
Timer.delayedCall(4000, function(event)
	group:removeSelf()
end)