--*********************************************************** --** THE INDIE STONE ** --** Author: turbotutone ** --*********************************************************** require "ISUI/ISPanel" ISSLFrame = ISPanel:derive("ISSLFrame"); function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end local function clerp( _t, _a, _b ) local t2 = (1-math.cos(_t*math.pi))/2; return(_a*(1-t2)+_b*t2); end function ISSLFrame:initialise() ISPanel.initialise(self) end function ISSLFrame:createChildren() --test data local test = {}; table.insert(test,{t=0,i=0}); table.insert(test,{t=0.4,i=0.7}); table.insert(test,{t=1,i=0}); self:addGridData( "test", Color.new(1,1,1,1), test ); --self:setStoryEvent(getSLSoundManager():getStorySoundEvent("warzone")); self:setStoryEvent(nil); self:updateGridRectangle(); self:updateVisualGrid(); end function ISSLFrame:isDragging() return self.dragInside; end function ISSLFrame:onMouseDown(x, y) self.dragInside = true; end --function ISSLFrame:onMouseDownOutside(x, y) --self.dragInside = false; --end function ISSLFrame:onMouseUpOutside(x, y) self:onMouseUp(self:getMouseX(),y); end --function ISSLFrame:onMouseUp(x, y) --self.dragInside = false; --end function ISSLFrame:onMouseMove(x, y) if not self:getIsVisible() then return; end local r = self.gridRectangle; if x>=r.x and x<=r.x2 and y>r.y and y=x-8 and self:getMouseX()<=x+8 and self:getMouseY()>=y-8 and self:getMouseY()<=y+8 then mouseOver = true; i1,o1,i2,o2 = 3,7,4,9; end self:drawRect(x-i1, y-i1, o1, o1, 1.0, 1.0, 1.0, 1.0); self:drawRect(x-i2, y-i2, o2, 1, 1.0, 0.0, 0.0, 0.0); self:drawRect(x-i2, y-i2, 1, o2, 1.0, 0.0, 0.0, 0.0); self:drawRect(x+i2, y-i2, 1, o2, 1.0, 0.0, 0.0, 0.0); self:drawRect(x-i2, y+i2, o2, 1, 1.0, 0.0, 0.0, 0.0); end end end end function ISSLFrame:drawGridData( _x, _y, _t ) for k,v in ipairs(self.eventData) do if v.dataPoints and v.eventSound then local c = v.eventSound:getColor(); for i=0, v.dataPoints:size()-1 do local dataPoint = v.dataPoints:get(i); local next = i+1=dataPoint:getTime() and _t=_t then local t = (_t-dataPoint:getTime())/(next:getTime()-dataPoint:getTime()); local intens = clerp(t,dataPoint:getIntensity(),next:getIntensity()); local _,y = self:dataToGrid(0,intens); --self:drawRect(_x, y, 1, 1, 1.0, c:getRed()/255, c:getGreen()/255, c:getBlue()/255); self:drawRect(_x, y, 1, 1, 1.0, 1.0, 1.0, 1.0); break; end end end end end end function ISSLFrame:updateVisualGrid() local x = 0; end function ISSLFrame:updateGridRectangle() local x,y,w,h = 0, 0, self:getWidth(), self:getHeight(); local p = self.gridPadding; local rect = {}; rect.x = x+p.left; rect.y = y+p.top; rect.w = w-p.left-p.right; rect.h = h-p.top-p.bot; rect.x2 = rect.x+w; rect.y2 = rect.y+h; self.gridRectangle = rect; return rect; end --intensity/time to grid x,y function ISSLFrame:dataToGrid( _t, _i ) local r = self.gridRectangle; local x = r.x + (r.w*_t); local y = r.y + (r.h*(1-_i)); --local y = r.y + (1-(r.h*_i)); return x,y; end function ISSLFrame:gridToData( _x, _y ) --FIXME make sure input are local coordinates (for mouse input related functionallity) local r = self.gridRectangle; if _xr.x+r.w then _x=r.x+r.w end if _yr.y+r.h then _y=r.y+r.h end local t = (_x-r.x)/r.w; local i = 1-((_y-r.y)/r.h); return t,i end function ISSLFrame:setStoryEvent( _event ) self.storyEvent = _event; self.eventData = {}; if self.storyEvent~=nil then local eventSounds = self.storyEvent:getEventSounds(); if eventSounds~=nil and eventSounds:size()>0 then for i=0, eventSounds:size()-1 do local eSound = eventSounds:get(i); local dataPoints = eSound:getDataPoints(); table.insert(self.eventData, {eventSound=eSound, dataPoints= dataPoints}); print(eSound:getColor():getRed().." "..eSound:getColor():getGreen().." "..eSound:getColor():getBlue()); print(eSound:getName()); for i=0, dataPoints:size()-1 do local data = dataPoints:get(i); print("time "..tostring(data:getTime()).." intensity "..tostring(data:getIntensity())) end end end end end function ISSLFrame:addGridData( _name, _col, _t ) local gridData = {}; gridData.name = _name; gridData.color = _col; gridData.dataPoints = _t; --[[ gridData.gridPoints = {}; for k,v in ipairs(_t) do local x,y = self:dataToGrid( v.t, v.i); table.insert(gridData.gridPoints, {x=x, y=y}); end --]] table.insert(self.gridData,gridData); end function ISSLFrame:onResize() ISUIElement.onResize(self); self:updateGridRectangle(); self:updateVisualGrid(); end function ISSLFrame:new (x, y, width, height) local o = ISPanel:new(x, y, width, height); setmetatable(o, self) self.__index = self o.x = x; o.y = y; o.background = true; o.backgroundColor = {r=0, g=0, b=0, a=1}; o.borderColor = {r=0.4, g=0.4, b=0.4, a=1}; o.width = width; o.height = height; o.anchorLeft = true; o.anchorRight = false; o.anchorTop = true; o.anchorBottom = false; o.doGridLines = true; o.gridHorzSpacing = 8; o.gridVertSpacing = 4; o.gridPadding = {top=10,bot=20,left=20,right=10}; o.gridColor = {r=0.2, g=0.2, b=0.2, a=1}; o.visualGrid = {}; o.gridData = {}; o.fontheight = getTextManager():MeasureStringY(UIFont.Small, "AbdfghijklpqtyZ")+2; return o end