MultiStopGradient = class(Object, function(o, x, y, w, h, stops)
	o.stops = {}
	Object.init(o, x, y, w, h)
	o.sprite = sprites['tiles']['white.png']
	o.drawType = 'stretched'
	o:setLayer(0)
	for i,v in ipairs(stops) do
		local r,g,b,a = v.c:get()
		local ma = a/255
		r,g,b = r*ma, g*ma, b*ma
		o.stops[i] = {}
		o.stops[i].p = v.p
		o.stops[i].c = bludColor(r,g,b,a)
	end
end)
function MultiStopGradient:draw()
	oy, oh = self.pos.y, self.h
	self.c1 = self.stops[1].c
	for i=2,#self.stops do
		self.pos.y = oy+oh*self.stops[i-1].p
		self.h = oh*self.stops[i].p
		self.c1 = self.stops[i-1].c
		self.c2 = self.stops[i].c
		GradientObject.draw(self)
	end
	self.pos.y, self.h = oy, oh
end

GradientObject = class(Object,function(o, x, y, w, h, c1, c2, ...)
	Object.init(o, x, y, w, h)
	o.sprite = sprites['tiles']['white.png']
	o.drawType = 'stretched'
	o:setLayer(0)
	o.c1 = c1
	o.c2 = c2
end)
function GradientObject:update()
	Object.update(self)
	-- copy the top tint color into the c1
	if self.tintTop then
		self.c1:set(self.tintTop.r, self.tintTop.g, self.tintTop.b, self.tintTop.a)
	end
	if self.tintBottom then
		self.c2:set(self.tintBottom.r, self.tintBottom.g, self.tintBottom.b, self.tintBottom.a)
	end
end
function GradientObject:draw()
	-- print(self)
	local cameras = self.cameras or bludG.cameras
	if not self.cam then
		self.cam = Rectangle(0, 0, bludG.camera.w, bludG.camera.h)
	end
	local flip = 0
	if self.flip then flip = self.flip end

	if self.sprite then
		-- loop through all the cameras
		-- print(bludG.camera.scale)
		for i,camera in pairs(cameras) do
			-- print(camera.scale)
			local px, py, pw, ph = self.pos.x, self.pos.y, self.w, self.h
			self.pos.x, self.pos.y, self.w, self.h = Object.getCameraOffsetZoom(self, camera)
			-- self.pos.x, self.pos.y = self.pos.x*camera.scale, self.pos.y*camera.scale
			-- draw the sprite if it is on the current camera
			local cam = Rectangle(0, 0, camera.w, camera.h)
			if self:doesRectangleTouch(camera) or asLine then
				-- calculate the position on the current camera
				local c = {self.pos.x, self.pos.y, self.w, self.h}
				local tl = {c[1], c[2]}
				local tr = {c[1]+c[3], c[2]}
				local bl = {c[1], c[2]+c[4]}
				local br = {c[1]+c[3], c[2]+c[4]}
				self.sheet:addCornerColorTile(self.sprite, tl[1],tl[2], tr[1],tr[2], bl[1],bl[2], br[1],br[2], self.layer, flip, self.c1, self.c1, self.c2, self.c2)
			end
			self.pos.x, self.pos.y, self.w, self.h = px, py, pw, ph
		end
	end
end

