function OnCreateContent()
-- comicScreen
	
    CreateGraphics();
end

function OnFreeContent()
end

function OnUpdate(dt)
end

function GetScreenLeftIndent()
	return 80.0;
end
------------------------------------------------------------------------------


--// auxiliary functions -----------------------------------------------------
function CreateGraphics()
	local bg = CreateSprite();
	bg:AttachTo(comicScreen);
	bg:SetName('ComicScreenBackground(Dummy)');
	bg:SetSprite('DummyTexture');
	bg:SetColor('0x00FFFFFF');
	bg:SetXY(SCREEN_WIDTH/2.0, SCREEN_HEIGHT/2.0);
	bg:SetVisible(true);

	CreateWindowShade(bg, -1, '0x50FFFFFF');
	local back = bg;
--	local back = CreateSprite(); 
--	back:AttachTo(bg);
--	back:SetSprite('ComicBackgroundTexture');
--	back:SetColor('0xFFFFFFFF');
--	back:SetXY(0.0, 0.0);
--	back:SetZ(0.0);
--	back:SetVisible(true);

	local textbox = CreateSprite();
	textbox:SetName('ComicScreenTextFrame');
	textbox:AttachTo(back);
	textbox:SetSprite('ComicTextboxFrameTexture');
	textbox:SetColor('0xFFFFFFFF');
	textbox:SetXY(GetScreenLeftIndent() + 0.0, (SCREEN_HEIGHT - textbox:GetTextureRect().y2)/2.0 + 2.0);
	textbox:SetZ(1.0);
	textbox:SetVisible(false);

	local text = CreateTextEntity('ComicsTextFont', '');
	text:SetName('ComicScreenText');
	text:SetTextAlignment(HGETEXT_LEFT + HGETEXT_TOP);
   	text:AttachTo(textbox);
	text:SetZ(0.1); 

   	local frameWidthFactor = 0.8;
    local frameHeightFactor = 0.7;

comicText = text;   --// (!) global variable for text frame object
comicText.maxwidth = frameWidthFactor * textbox:GetTextureRect().x2;
comicText.tracking = text:GetTracking(); --//-8.0;

textFrame = textbox; --// (!) global variable for text message attached to the tet frame object
textFrame.text = comicText;

	text:SetXY(- frameWidthFactor * textbox:GetTextureRect().x2/2.0 - 10.0,
               - frameHeightFactor * textbox:GetTextureRect().y2/2.0 + 35.0);
end

function SetComicText(text, textColor)
    if (textColor == nil) then
        textColor = '0xFF000000';
    end
    assert(textFrame and comicText and comicText.maxwidth and comicText.tracking);

	local processedText = AddNewLineMarkersByWidth('ComicsTextFont', comicText.tracking, text, comicText.maxwidth);
	comicText:SetColor(textColor);
	comicText:SetText(processedText);
	if (textFrame:IsVisible() == false or textFrame:GetOpacity() == 0.0 or processedText == '') then
	    textFrame:SetOpacity(0.0);
	    textFrame:SetVisible(true);
	    
	    local duration = 0.15;
	    local eff = CreateAnimationEffector();
	    eff:AttachTo(textFrame);
	    eff:SetKey(_TRACK_O, 0.0, 	   (processedText == '' and 1.0 or 0.0));
	    eff:SetKey(_TRACK_O, duration, (processedText == '' and 0.0 or 1.0));
	    eff:Play();
	end
end
