-- events for the logo splash screen



--
-- show parameters


splashes = {
  "logos/logo1.jpg", 
  -- "logos/logo2.jpg", 
  -- NOTE: ADD ADDITIONAL LOGOS HERE !!!

}


-- time (in seconds) how long a single splash is shown
time_single_splash_shown = 2.5;

-- delay between two splashes
delay_between_splashes = 0.5;

-- delay before showing the first splash
intro_delay = 0.5;




--
-- variables

timer = 0;
splash_index = 1;




function OnLoad ()

	-- cache splash graphics
	for i = 1, #splashes do
		NX_GetBitmap (splashes[i]);
	end;
end;



function OnEnter ()

	SetProperty ("/:enter_trans_duration", 0.1);
	SetProperty ("/:leave_trans_duration", 0.1);

	timer = -intro_delay;
	splash_index = 1;
	
end;



function OnLeave ()
	-- release splash graphics manually
	for i = 1, #splashes do
		NX_ReleaseBitmap (splashes[i]);
	end;
end;



function OnClick (name)
	Print ("OnClick " .. name .. "\n");
end;



function clamp01 (value)

	value = math.min (value, 1);
	value = math.max (value, 0);
	return value;
end;



function OnUpdate (tdelta)

	if (tdelta > 0.1) then
		-- make sure we don't skip too much (the app has just been 
		-- started so large time delays may be likely at this point)
		tdelta = 0.1;
	end;
	
	
	timer = timer + tdelta / time_single_splash_shown;

	-- move to the next splash
	if (timer > 1) then
		splash_index = splash_index + 1;
		timer = -delay_between_splashes;
		if (splash_index > #splashes) then
			-- leave after the last splash
			PopScreen ();
		end;
	end;
	
end;



function OnDrawComp (id)

	if (splash_index > #splashes) then
		return;
	end;

	local alpha = clamp01 (2*math.sin (timer*math.pi));

	NX_SetAlpha (alpha);
	NX_SetColor (1,1,1);
	
	NX_DrawBitmap (splashes[splash_index], 0, 0);

end;



function OnDraw ()

end;
