Initial Commit
This commit is contained in:
		
						commit
						0ce34bd35c
					
				
					 3 changed files with 70 additions and 0 deletions
				
			
		
							
								
								
									
										17
									
								
								bordered_window.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								bordered_window.lua
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
local window = require("window")
 | 
			
		||||
 | 
			
		||||
local w = {}
 | 
			
		||||
 | 
			
		||||
function w.new(inner, x, y, w, h)
 | 
			
		||||
    local mt = { __index = inner }
 | 
			
		||||
    local a = {}
 | 
			
		||||
    setmetatable(a, mt)
 | 
			
		||||
 | 
			
		||||
    function a:draw()
 | 
			
		||||
        inner:draw()
 | 
			
		||||
        love.graphics.rectangle("line", 0, 0, w, h)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    local r = window.new(a, x, y, h, w)
 | 
			
		||||
    return r
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										20
									
								
								main.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								main.lua
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,20 @@
 | 
			
		|||
local window = require("window")
 | 
			
		||||
local bwindow = require("bordered_window")
 | 
			
		||||
--local button = require("button")
 | 
			
		||||
 | 
			
		||||
function love.load()
 | 
			
		||||
    b = {}
 | 
			
		||||
    function b.draw()
 | 
			
		||||
        love.graphics.print("A", 10, 10)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    ba = bwindow.new(b, 200, 200, 50, 50)
 | 
			
		||||
    -- canvas = love.graphics.newCanvas()
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function love.update(dt)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function love.draw()
 | 
			
		||||
    ba:draw()
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										33
									
								
								window.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								window.lua
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
local w = {}
 | 
			
		||||
 | 
			
		||||
function w.new(inner, x, y, w, h)
 | 
			
		||||
    local r = {
 | 
			
		||||
        transform = love.math.newTransform(x, y),
 | 
			
		||||
        width = w,
 | 
			
		||||
        height = h
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function r:transformPoint(x, y)
 | 
			
		||||
        local x, y = transform:transformPoint(x, y)
 | 
			
		||||
        if 0 <= x and x <= width and 0 <= y and y <= height then
 | 
			
		||||
            return x, y
 | 
			
		||||
        else
 | 
			
		||||
            return nil
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    function r:mousepressed(m, x, y)
 | 
			
		||||
        return inner:mousepressed(m, x, y)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    function r:draw()
 | 
			
		||||
        love.graphics.push()
 | 
			
		||||
        love.graphics.setTransform(self.transform)
 | 
			
		||||
        inner:draw()
 | 
			
		||||
        love.graphics.pop()
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    return r
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
return w
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue