excessive / DOMy

A DOM-like GUI framework for the *awesome* LÖVE framework
Other
32 stars 2 forks source link

Border Radius #24

Closed karai17 closed 9 years ago

karai17 commented 9 years ago

Got this mostly working thats to @Positive07 but this needs to be scaled down so the outside of the polygon is on the border edge, not the inside!

    -- https://gist.github.com/gvx/9072860
    local function get_stencil_clip(x, y, w, h, precision, corners)
        local polygon = {}

        -- true if on x/y, false if on w/h; TL, TR, BR, BL
        local xs = { true, false, false, true  }
        local ys = { true, true,  false, false }

        for i, radius in ipairs(corners) do
            if radius == 0 then
                table.insert(polygon, xs[i] and x or x+w)
                table.insert(polygon, ys[i] and y or y+h)
            else
                for j = 0, precision do
                    local angle = (j / precision + (i - 3)) * math.pi / 2
                    table.insert(polygon, (xs[i] and x or x+w) + radius * math.cos(angle))
                    table.insert(polygon, (ys[i] and y or y+h) + radius * math.sin(angle))
                end
            end
        end

        return polygon
    end
karai17 commented 9 years ago

Whoops, fixed!

table.insert(polygon, (xs[i] and x+radius or x+w-radius) + radius * math.cos(angle))
table.insert(polygon, (ys[i] and y+radius or y+h-radius) + radius * math.sin(angle))
pablomayobre commented 9 years ago

I was just pushing a commit that actually fixed this for your needs hahaha, take x and y in the base function...