



--===================================================
--										GHU Image
--===================================================	

-- Purpose: A object that shows a picture made up from one or more textures
-- The object inherits GHU_Object


function GHU_Image(_parent) 
	local class = GHClass("GHU_Image","GHU_Object")
	
	--=========== Setup ===========
	local parent = _parent;
	local gui;
	local enabled = true;
	local textures,textureFrames = {},{};
	local selected = false;
	local scale = 1;
	
	if not(parent.GetObjectType) then 
		assert(parent.GetGui,"Got parent class which is not a UI frame and without GetGui function",parent);
		gui = CreateFrame("Frame",parent:GetGui());
		gui:SetPoint("BOTTOMLEFT",parent:GetGui(),"BOTTOMLEFT",0,0);
	else
		gui = CreateFrame("Frame",parent);
		gui:SetPoint("BOTTOMLEFT",parent,"BOTTOMLEFT",0,0);
	end
	
	-- marker
	gui.marker = CreateFrame("Frame",gui);
	gui.marker:SetBackdrop( { 
		bgFile = "Interface\\CHATFRAME\\CHATFRAMEBACKGROUND", 
		edgeFile = "edgeFile", tile = false, tileSize = 0, edgeSize = 32, 
		insets = { left = 0, right = 0, top = 0, bottom = 0 }
	});
	
	gui.marker:SetBackdropColor(0,0,0,1);
	gui.marker:SetAllPoints(gui);
	gui.marker:Hide();
	
	
	-- temp for testing
	gui:SetWidth(30);
	
	
	--=========== Local Functions ===========
	local UpdateTextures = function()
	
	end
	
	--=========== Functions req by GHU_Object ===========
	
	-- DeleteSelected()
	class.DeleteSelected = function(self)
		if selected then
			return true,"The image is compeltely selected";
		end	
	end
	-- Disable()
	class.Disable = function(self)
		enabled = false;
		self:Hide();	
	end
	-- Dispose()
	class.Dispose = function(self)
		wipe(gui);
		wipe(self);	
	end
	-- Enable()
	class.Enable = function(self)
		enabled = true;
	end
	-- GetGui()
	class.GetGui = function(self)
		return gui;
	end
	-- GetHeight()
	class.GetHeight = function(self)
		return gui:GetHeight();
	end
	-- GetLength()
	class.GetLength = function(self)
		return 1;	
	end
	-- GetOffset()
	class.GetOffset = function(self) 
		local _,_,_,x = gui:GetPoint(1);
		return x;	
	end
	-- GetPosWidth(pos)
	class.GetPosWidth = function(self,pos)
		assert(type(pos)=="number","Position must be a number");
		
	end
	-- GetSelection()
	class.GetSelection = function(self)
		if selected then
			return 0,1;
		else
			return 0,0;		
		end	
	end
	-- GetWidth()
	class.GetWidth = function(self)
		return gui:GetWidth();	
	end
	-- GetWidthPos(width)
	class.GetWidthPos = function(self,_width)
		if _width > self:GetWidth()/2 then
			return 1;
		else
			return 0;		
		end
	end
	-- Hide()
	class.Hide = function(self)
		gui:Hide();	
	end
	-- IsEnabled()
	class.IsEnabled = function(self)
		return enabled;	
	end
	-- SetOffset(x)
	class.SetOffset = function(self,xOff)
		gui:ClearAllPoints();
		local f = parent;
		if not(f.GetObjectType) then f = parent:GetGui() end
		gui:SetPoint("BOTTOMLEFT",f,"BOTTOMLEFT",xOff,0);
	end
	-- SetSelection(sStart,sEnd)
	class.SetSelection = function(sStart,sEnd)
		if sStart and sEnd and sStart <= 0 and sEnd	>= 1 then
			selected = true;
			gui.marker:Show();
		else
			selected = false;		
			gui.marker:Hide();
		end
	end
	-- Show()
	class.Show = function(self)
		gui:Show();
	end

	
	--=========== Image Functions ===========
	class.RemoveAllTextures = function(self)
		textures = {};
		UpdateTextures();
	end
	class.AddTexture = function(self,texture,row,column)
		assert(type(texture)=="table" and texture.IsClass and texture:IsClass("GHU_Texture"),"The texture are not a GHU_Texture object",texture);
		row = row or 1;
		column = column or 1;
		
		textures[row.."-"..column] = texture;
		UpdateTextures();
	end
	class.GetScale = function(self)
		return scale;	
	end
	class.SetScale = function(self,_scale)
		assert(type(_scale)=="number","Scale must be a number");
		scale = _scale;
		UpdateTextures();
	end
	
	
	return class;		
end




