View Single Post
Old 05-19-2016, 03:17 PM   #55
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Code:
Template = {}

function Template:new(x,y,h,w) 

	local temp = {}   
	temp.x, temp.y = x , y
	temp.w, temp.h = w , h

	setmetatable(temp, self)
	self.__index = self
	return temp	

end


function Template:draw()
	
	gfx.rect(self.x, self.y, self.w, self.h)
	
end

function DRAW(tbl)
    for key, btn in pairs(tbl) do btn:draw()  end   
end

w,h = 20,20 
y,x = 10,10

Button = {}
local temp_x = x
for i = 1 , 5 do
	Button[i] = Template:new(temp_x,y,h,w)
	temp_x = temp_x + 30    
end 


function main()
      
    DRAW(Button)
    
    local char = gfx.getchar()
      if char ~= 27 and char ~= -1 then
        reaper.defer(main)
    end     
    
    gfx.update()
	
end

gfx.init("My Window", 640, 480, 0, 200, 200)
main()
I had to increase the value for temp_x to make the individual buttons visible. If your buttons are 20 pixels wide and you only increase x by 10 each time, they just make one big rectangle.

Further reading...
Lua reference manual - Object-oriented programming. There's an explanation of using the : syntax about halfway down
Lua reference manual - Classes
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote