﻿
<krpano>



	//CALLOUT VR

<callout
		 size="10"
		 color="0xffffff"
		 rotate="45"
		 distancepopup="8"
		 min_fov="180"
		 max_fov="0"
		 line_length="60"
		 line_width="2"
		 shape="round"
		 circle_active_width="50"
		 animation="center_screen"
		 text_width="300"
		 callout_bg_border_vr="2"
		 text_x="5"
		 css_title="color:#fff;font-size:20px;font-family:Lato;font-weight:400"
		 css_text="color:#fff;font-size:16px;text-shadow: 3px 3px 8px #000000;"
		 title_background="0x000000"
		 text_background=""
		 title_padding="7"
		 text_padding="10 10 0 0"
		 depth="off"
		 zoomfactor="0.5"
		 minfov="0"
		 maxfov="180"
		 />

<style name="callout" callout="true" type="text" zorder="1" oversampling="2" mipmapping="true" enabled="false" vrscale="true"
	size="calc:callout.size"
	color="calc:callout.color"
	initial_width="calc:callout.size"
	shape="calc:callout.shape"
	bgalpha="1"
	rotate="calc:callout.rotate"
	distancepopup="calc:callout.distancepopup"
	animation="calc:callout.animation"
	minfov="calc:callout.min_fov"
	maxfov="calc:callout.max_fov"
	line_length="calc:callout.line_length"
	line_width="calc:callout.line_width"
	circle_active_width="calc:callout.circle_active_width"
	text_width="calc:callout.text_width"
	callout_bg_border_vr="calc:callout.callout_bg_border_vr"
	text_x="calc:callout.text_x"
	css_title="calc:callout.css_title"
	css_text="calc:callout.css_text"
	title_background="calc:callout.title_background"
	text_background="calc:callout.text_background"
	title_padding="calc:callout.title_padding"
	text_padding="calc:callout.text_padding"
	contentheight="0"
	depth="calc:callout.depth"
	bgborder="2 0xffffff 1"
	scale.mobilevr="calc:callout.zoomfactor"
    pulsescale.mobilevr="calc:callout.zoomfactor"
	onloaded="build_callout();"
	oncallout="animate_callout();"
	oncallin="animate_callin();"
	distorted.mobilevr="true"
	nhs="0"
/>

	<style name="callout_pulse" type="text" bg="false" onloaded="pulsevr()" depth="off" oversampling="2" mipmapping="true" distorted.mobilevr="true" enabled="false" autoalpha="false" vrscale="true"/>
	<style name="callout_line" type="text" width="2" height="0" bgalpha="1" edge="bottom" depth="off" oversampling="2" mipmapping="true" distorted.mobilevr="true" enabled="false" autoalpha="true" vrscale="true"/>
	<style name="callout_line_vertical" type="text" height="0"  depth="off" oversampling="2" mipmapping="true" distorted.mobilevr="true" enabled="false" autoalpha="true" vrscale="true"/>
	<style name="callout_title" type="text" bg="false" edge="topleft" onautosized="add(hotspot[get(hs)].contentheight,height);set(alpha,0);sub(hotspot[get(hs)].nhs,1)" depth="off" oversampling="2" mipmapping="true" distorted.mobilevr="true" enabled="false" autoalpha="true" vrscale="true" bgalpha="0.5"/>
	<style name="callout_text" type="text" bg="false" edge="bottomleft" onautosized="add(hotspot[get(hs)].contentheight,height);set(alpha,0);sub(hotspot[get(hs)].nhs,1)" depth="off" oversampling="2" mipmapping="true" distorted.mobilevr="true" enabled="false" autoalpha="true" vrscale="true"/>
	<style name="callout_img" alpha="0" depth="off" oversampling="2" mipmapping="true" distorted.mobilevr="true" enabled="false" autoalpha="true" vrscale="true"/>

<action name="build_callout" scope="local" protect="true">
if(caller.onclick,set(caller.enabled,true));
	if(caller.title,add(caller.nhs,1));
	if(caller.content,add(caller.nhs,1));
	copy(caller.bgcolor,caller.color);
	copy(caller.width,caller.size);
	copy(caller.height,caller.size);
	if(caller.shape == 'round', set(caller.bgroundedge,calc:(caller.size/2) + 2);set(style[callout_pulse].bgroundedge,calc((caller.size / 2)+7)));
	if(caller.shape == 'circle', set(caller.bgroundedge,calc:(caller.size/2) + 2);set(style[callout_pulse].bgroundedge,calc((caller.size / 2)+7)));
	if(caller.shape == 'square', set(caller.bgroundedge,0);set(style[callout_pulse].bgroundedge,0););

	txtadd(callout_pulse,'callout_pulse_',get(caller.name));
	addhotspot(get(callout_pulse));
	copy(caller.callout_pulse,callout_pulse);
	hotspot[get(callout_pulse)].loadstyle(callout_pulse);
	copy(hotspot[get(callout_pulse)].ath,caller.ath);
	copy(hotspot[get(callout_pulse)].atv,caller.atv);
	copy(hotspot[get(callout_pulse)].depth,caller.depth);
	calc(hotspot[get(callout_pulse)].width,caller.size + 10);
	calc(hotspot[get(callout_pulse)].height,caller.size + 10);
	set(hotspot[get(callout_pulse)].bgborder,calc:'3 ' + caller.color + ' 1');
	copy(hotspot[get(callout_pulse)].rotate,caller.rotate);
	copy(hotspot[get(callout_pulse)].scale,caller.scale);
    copy(hotspot[get(callout_pulse)].pulsescale,caller.pulsescale);

	txtadd(callout_line,'callout_line_',get(caller.name));
	addhotspot(get(callout_line));
	copy(caller.callout_line,callout_line);
	hotspot[get(callout_line)].loadstyle(callout_line);
	copy(hotspot[get(callout_line)].ath,caller.ath);
	copy(hotspot[get(callout_line)].atv,caller.atv);
	copy(hotspot[get(callout_line)].depth,caller.depth);
	copy(hotspot[get(callout_line)].bgcolor,caller.color);
	copy(hotspot[get(callout_line)].width,caller.line_width);
	copy(hotspot[get(callout_line)].rotate,caller.rotate);
	copy(hotspot[get(callout_line)].scale,caller.scale);

	txtadd(callout_line_vertical,'callout_line_vertical_',get(caller.name));
	addhotspot(get(callout_line_vertical));
	copy(caller.callout_line_vertical,callout_line_vertical);
	copy(hotspot[get(callout_line_vertical)].hs,caller.name);
	copy(hotspot[get(callout_line_vertical)].width,caller.callout_bg_border_vr);
	copy(hotspot[get(callout_line_vertical)].bgcolor,caller.color);
	hotspot[get(callout_line_vertical)].loadstyle(callout_line_vertical);

	copy(hotspot[get(callout_line_vertical)].ath,caller.ath);
	copy(hotspot[get(callout_line_vertical)].atv,caller.atv);
	copy(hotspot[get(callout_line_vertical)].depth,caller.depth);
	copy(hotspot[get(callout_line_vertical)].scale,caller.scale);

	calc(prout,Math.PI * 2 * caller.rotate / 360);
	calc(pouet,Math.PI * 2 * caller.rotate / 360);
	Math.sin(prout);
	Math.cos(pouet);
	if(caller.shape == 'circle',
		set(distance,calc(caller.line_length + (caller.circle_active_width/2)));
		calc(hotspot[get(caller.callout_line)].oy,-(caller.circle_active_width/2) * caller.scale);
		,
		copy(distance,caller.line_length )
	);
	calc(caller.x_offset,distance * prout * caller.scale);
	calc(caller.y_offset,-(distance * pouet * caller.scale));

	calc(hotspot[get(callout_line_vertical)].ox,caller.x_offset);
	calc(hotspot[get(callout_line_vertical)].oy,caller.y_offset);

	if(caller.title,
	txtadd(callout_title,'callout_title_',get(caller.name));
	addhotspot(get(callout_title));
	copy(caller.callout_title,callout_title);
	copy(hotspot[get(callout_title)].hs,caller.name);
	hotspot[get(callout_title)].loadstyle(callout_title);
	if(caller.title_background != null,copy(hotspot[get(callout_title)].bgcolor,caller.title_background);set(hotspot[get(callout_title)].bg,true););
	if(caller.title_padding,copy(hotspot[get(callout_title)].padding,caller.title_padding););

	copy(hotspot[get(callout_title)].css,caller.css_title);
	if(caller.rotate LT 0 OR caller.rotate GT 180,
		  set(hotspot[get(callout_title)].align,topright);
	);
	copy(hotspot[get(callout_title)].ath,caller.ath);
	copy(hotspot[get(callout_title)].atv,caller.atv);
	copy(hotspot[get(callout_title)].depth,caller.depth);
	calc(hotspot[get(callout_title)].ox,caller.x_offset + (caller.text_x * caller.scale));

	copy(hotspot[get(callout_title)].html,caller.title);
	set(hotspot[get(callout_title)].onclick,callwith(hotspot[get(hs)],onclick));
	copy(hotspot[get(callout_title)].scale,caller.scale);
	callwhen(caller.contentheight AND caller.nhs == 0,
	calc(hotspot[get(caller.callout_title)].oy,caller.y_offset - ((caller.contentheight/2)* caller.scale));
	);
	if(caller.onclick,set(hotspot[get(callout_title)].enabled,true));
	,
	set(caller.callout_title,'');
	);

	if(caller.img,
	txtadd(callout_img,'callout_img_',get(caller.name));
	addhotspot(get(callout_img));
	copy(caller.callout_img,callout_img);
	copy(hotspot[get(callout_img)].hs,caller.name);
	hotspot[get(callout_img)].loadstyle(callout_img);

	if(caller.rotate LT 0 OR caller.rotate GT 180,
		  set(hotspot[get(callout_title)].align,topright);
	);
	copy(hotspot[get(callout_img)].ath,caller.ath);
	copy(hotspot[get(callout_img)].atv,caller.atv);
	copy(hotspot[get(callout_img)].depth,caller.depth);
	calc(hotspot[get(callout_img)].ox,caller.x_offset);
	calc(hotspot[get(callout_img)].oy,caller.y_offset);

	if(caller.solo,
	add(hotspot[get(callout_img)].ox,7);
	sub(hotspot[get(callout_img)].oy,7);
	);

	copy(hotspot[get(callout_img)].url,caller.img);
	set(hotspot[get(callout_img)].onclick,callwith(hotspot[get(hs)],onclick));
	copy(hotspot[get(callout_img)].scale,caller.scale);
	copy(hotspot[get(callout_img)].edge,caller.img_edge);

	if(caller.onclick,set(hotspot[get(callout_img)].enabled,true));
	,
	set(caller.callout_img,'');
	);

	if((caller.rotate LT 0) OR (caller.rotate GT 180),
		  set(hotspot[get(callout_title)].edge,topright);
		  set(hotspot[get(callout_text)].edge,bottomright);
	calc(hotspot[get(callout_title)].ox,hotspot[get(callout_title)].ox - ((caller.text_x* caller.scale) * 2));
	calc(hotspot[get(callout_text)].ox,hotspot[get(callout_text)].ox - ((caller.text_x* caller.scale) * 2));
	);



	if(caller.onclick,set(caller.bgcapture,true);set(hotspot[get(callout_line_vertical)].onclick,callwith(hotspot[get(hs)],onclick));set(hotspot[get(callout_line_vertical)].bgcapture,true););
	if(caller.animation == 'on_over',set(caller.bgcapture,true);set(caller.onover,oncallout);set(caller.onout,oncallin);set(caller.ondown,oncallout);set(caller.onup,oncallin););
	if(caller.animation == 'on_click',set(caller.bgcapture,true);set(caller.onclick,highlight_callout_hotspot(get(name)));set(events[callout_events].onmousedown,hide_callouts));

	set(events[callout_events].onviewchange,test_callout_hotspots_action());
</action>

<action name="animate_callout" protect="true" scope="local">
copy(caller.bk_zorder,caller.zorder);
set(caller.zorder,10);
set(hotspot[get(caller.callout_title)].zorder,10);
stoptween(hotspot[get(caller.callout_line_vertical)].height);
stoptween(hotspot[get(caller.callout_line)].height);
stoptween(caller.width);
stoptween(caller.height);
stoptween(caller.bgalpha);
stoptween(caller.bgroundedge);
stoptween(hotspot[get(caller.callout_title)].alpha);

if(caller.shape == 'circle',
	tween(caller.bgalpha,0);
	tween(caller.width|caller.height,calc(caller.circle_active_width));
	tween(caller.bgroundedge,calc((caller.circle_active_width + 2) / 2));
);

tween(hotspot[get(caller.callout_line)].height,calc(caller.line_length),0.2,,
	tween(hotspot[get(caller.callout_line_vertical)].height,calc(caller.contentheight),0.1,,
		tween(hotspot[get(caller.callout_title)].alpha|hotspot[get(caller.callout_img)].alpha,1);
	);
);

set(hotspot[get(caller.callout_pulse)].visible,false);
</action>


<action name="animate_callin" protect="true" scope="local">
copy(caller.zorder,caller.bk_zorder);
copy(hotspot[get(caller.callout_title)].zorder,caller.bk_zorder);
delete(caller.bk_zorder);
stoptween(hotspot[get(caller.callout_line_vertical)].height);
stoptween(hotspot[get(caller.callout_line)].height);
stoptween(caller.width);
stoptween(caller.height);
stoptween(caller.bgalpha);
stoptween(caller.bgroundedge);
stoptween(hotspot[get(caller.callout_title)].alpha);

tween(hotspot[get(caller.callout_title)].alpha,0,0.25,,
		tween(hotspot[get(caller.callout_line_vertical)].height,0,0.15,,
			tween(hotspot[get(caller.callout_line)].height,0,0.2,,
			if(caller.shape == 'circle',
				tween(caller.bgroundedge,calc(caller.initial_width / 2));
				tween(caller.bgalpha,1);
				tween(caller.width|caller.height,get(caller.initial_width))
			);
			);
		);
);
tween(hotspot[get(caller.callout_text)].alpha,0,0.25);
tween(hotspot[get(caller.callout_img)].alpha,0,0.25);
set(hotspot[get(caller.callout_pulse)].visible,true);
</action>



<action name="pulsevr" protect="true" scope="local">
tween(caller.scale|caller.alpha,calc(caller.pulsescale * 1.3 +'|0.0'),2,,set(caller.scale,0.5);set(caller.alpha,1);callwith(hotspot[get(caller.name)],onloaded));

</action>


<events name="callout_events" onloadcomplete="set(letspopup,true)" onremovepano="set(letspopup,false)" keep="true"/>

<action name="test_callout_hotspots_action">
if(stagewidth GT 800,test_callout_hotspots(),test_callout_hotspots_smallscreen());
</action>


<action name="test_callout_hotspots" protect="true">
	if(letspopup AND !vrmenuisactive,
    for(set(i,0), i LT hotspot.count, inc(i),
		if(hotspot[get(i)].animation == center_screen,
			if(view.fov LT hotspot[get(i)].minfov AND view.fov GT hotspot[get(i)].maxfov,
        		getlooktodistance(d, hotspot[get(i)].ath, hotspot[get(i)].atv);
        			if(d LT calc(view.fov / hotspot[get(i)].distancepopup),
           				highlight_callout_hotspot(get(i));
          				,
           				background_callout_hotspot(get(i));
          				);
			  ,
			  background_callout_hotspot(get(i));
			  );
		  );
		if(hotspot[get(i)].animation == keep_opened,
			if(view.fov LT hotspot[get(i)].minfov AND view.fov GT hotspot[get(i)].maxfov,
        		getlooktodistance(d, hotspot[get(i)].ath, hotspot[get(i)].atv);
        			if(d LT calc(view.fov / hotspot[get(i)].distancepopup),
           				highlight_callout_hotspot(get(i));
          				);
			  );
		  );
	  );
	);
</action>

<action name="test_callout_hotspots_smallscreen">
if(letspopup,
set(nearest_hs_i,-1);
set(nearest_hs_d,10000);

for(set(i,0), i LT hotspot.count, inc(i),
	if(hotspot[get(i)].animation == center_screen,
		if(view.fov LT hotspot[get(i)].minfov AND view.fov GT hotspot[get(i)].maxfov,
        	getlooktodistance(temp_d, hotspot[get(i)].ath, hotspot[get(i)].atv);

			if(temp_d LT nearest_hs_d,
				copy(nearest_hs_i,i);
				copy(nearest_hs_d,temp_d);
			);

			if(hotspot[get(i)].ishighlighted AND hotspot[get(i)].name != hotspot[get(nearest_hs_i)].name,background_callout_hotspot(get(hotspot[get(i)].name)));
		);
    );
);

if(nearest_hs_i GE 0 AND nearest_hs_d LT calc(view.fov / hotspot[get(nearest_hs_i)].distancepopup),
    highlight_callout_hotspot(get(hotspot[get(nearest_hs_i)].name));
	,
	 background_callout_hotspot(get(hotspot[get(nearest_hs_i)].name));
);
);
</action>

<action name="hide_callouts" protect="true">
for(set(i,0), i LT hotspot.count, inc(i),
	if(hotspot[get(i)].animation == on_click,
		background_callout_hotspot(get(i));
	);
);
</action>

<action name="highlight_callout_hotspot" protect="true">
    if(!hotspot[%1].ishighlighted,
		callwith(hotspot[%1],oncallout);
		set(hotspot[%1].ishighlighted, true);
     );
</action>

<action name="background_callout_hotspot" protect="true">
	if(hotspot[%1].ishighlighted,
    	callwith(hotspot[%1],oncallin);
		set(hotspot[%1].ishighlighted, false);
	);
</action>

	<action name="check_for_web_fonts_loading" autorun="preinit" type="Javascript" devices="html5"><![CDATA[
    function new_fonts_loaded()
    {
        var layers = krpano.get("layer").getArray();
        var hotspots = krpano.get("hotspot").getArray();

        var i;

        for (i=0; i < layers.length; i++)
        {
            if (layers[i]._istextfield)
            {
                // force an update by changing the vcenter setting two times
                layers[i].vcenter = !layers[i].vcenter;
                layers[i].vcenter = !layers[i].vcenter;
            }
        }

        for (i=0; i < hotspots.length; i++)
        {
            if (hotspots[i]._istextfield)
            {
                // force an update by changing the vcenter setting two times
                hotspots[i].vcenter = !hotspots[i].vcenter;
                hotspots[i].vcenter = !hotspots[i].vcenter;
            }
        }
    }

    if (document.fonts)
    {
        document.fonts.addEventListener("loadingdone", new_fonts_loaded, true);
    }
]]></action>
</krpano>