2017-08-28 08:17:54 +00:00
|
|
|
import graphics from love
|
|
|
|
|
|
|
|
element = require "#{(...)\sub 1, -11}/element"
|
|
|
|
|
|
|
|
recursiveDraw = (children, x, y) ->
|
2017-08-28 08:49:12 +00:00
|
|
|
for i = 1, #children
|
|
|
|
child = children[i]
|
|
|
|
local drawChildren
|
|
|
|
if child.draw
|
|
|
|
child.data.x -= x
|
|
|
|
child.data.y -= y
|
|
|
|
drawChildren = child\draw!
|
|
|
|
child.data.x += x
|
|
|
|
child.data.y += y
|
|
|
|
if drawChildren != false
|
|
|
|
recursiveDraw child.child, x, y
|
2017-08-28 08:17:54 +00:00
|
|
|
|
|
|
|
local canvasDraw
|
|
|
|
major, minor = love.getVersion!
|
|
|
|
|
|
|
|
if major == 0 and minor == 10
|
2017-08-28 08:49:12 +00:00
|
|
|
canvasDraw = (canvas, x, y) ->
|
|
|
|
graphics.draw canvas, x, y
|
2017-08-28 08:17:54 +00:00
|
|
|
else
|
2017-08-28 08:49:12 +00:00
|
|
|
canvasDraw = (canvas, x, y) ->
|
|
|
|
mode, alpha = graphics.getBlendMode!
|
|
|
|
graphics.setBlendMode "alpha", "premultiplied"
|
|
|
|
graphics.draw canvas, x, y
|
|
|
|
graphics.setBlendMode mode, alpha
|
2017-08-28 08:17:54 +00:00
|
|
|
|
|
|
|
-- canvasDraw = (canvas, x, y) ->
|
2017-08-28 08:49:12 +00:00
|
|
|
-- graphics.draw canvas, x, y
|
2017-08-28 08:17:54 +00:00
|
|
|
|
|
|
|
class clipRegion extends element
|
2017-08-28 08:49:12 +00:00
|
|
|
new: (@parent, @data={}) =>
|
|
|
|
super @parent, @data
|
|
|
|
|
|
|
|
@data.type = "clipRegion" if @data.type == "element"
|
|
|
|
@canvas = graphics.newCanvas @data.w, @data.h
|
|
|
|
|
|
|
|
draw: =>
|
|
|
|
graphics.setCanvas @canvas
|
|
|
|
graphics.clear!
|
|
|
|
recursiveDraw @child, @data.x, @data.y
|
|
|
|
graphics.setCanvas!
|
|
|
|
graphics.setColor 255, 255, 255, 255
|
|
|
|
canvasDraw @canvas, @data.x, @data.y
|
|
|
|
return false
|