require "color"
Square = class()
function Square:init(x, y, width, height)
self.x = x
self.y = y
self.width = width
self.height = height
self.color = color.dodgerblue
self.colorBorder = color.navy
self.selected = false
end
function Square:contains(x, y)
return self.x <= x and x <= self.x + self.width and self.y <= y and y <= self.y + self.height
end
function Square:paint(gc)
gc:setColorRGB(self.color)
gc:fillRect(self.x, self.y, self.width, self.height)
if self.selected then
cursor.set("hand closed")
gc:setColorRGB(self.colorBorder)
gc:drawRect(self.x, self.y, self.width, self.height)
gc:drawString("selected", 10, 20)
else
gc:drawString("not selected", 10, 20)
cursor.set("default")
end
end
Sq = Square(100, 50, 120, 120)
function on.mouseDown(x,y)
if Sq:contains(x, y) then
Sq.selected = true
end
platform.window:invalidate()
end
function on.mouseUp()
Sq.selected = false
platform.window:invalidate()
end
function on.paint(gc)
Sq:paint(gc)
end