You are not logged in.

1

Wednesday, July 17th 2013, 9:19pm

Is there a way to autosize the width of hotspot textfield?

Hi,

I need to put tooltip hotspots with background. It seems that I need to write down
width and height for every single tooltip hotspot. Since the width of every tooltip hotspot
is different from one another, it is really a time consuming task for finding out
right size..

I wonder if there is a way to autosize the width of hotspot textfield.
Or is there a way for workaround?

This would be a really convenient feature!

Best Regards,
Hyung

Alexey Tkachenko

Professional

Posts: 750

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

2

Wednesday, July 17th 2013, 10:22pm

Well, I thought on that issue before and just now I've created something like that, I suppose *smile*

Try adding this action

Source code

1
2
3
4
5
6
7
8
9
10
<action name="show_tooltip">
	txtadd(tooltip_width_search, 'get(tooltip)','_countstart');
	indexoftxt(number_of_characters,get(tooltip_width_search),_countstart,0);
	mul(text_width, number_of_characters, 8);
	copy(layer[tooltip].width, text_width);
	copy(layer[tooltip].html, tooltip);
	set(layer[tooltip].visible, true);
	tween(layer[tooltip].alpha, 1.0, 0.5);
	asyncloop(hovering, copy(layer[tooltip].x,mouse.stagex); copy(layer[tooltip].y,mouse.stagey); );
	</action>


to the onover attribute in the style of your hotspots. I've just tested it quickly and it seems to work.

The value "8" in this line

Source code

1
mul(text_width, number_of_characters, 8);


Comes from my thought and my quick practical test that the font Arial 12 has optimal "width" of 8 px. If I set more than 8, the textfield becomes a bit long on the edges, if I state less than 8, textfield sometimes becomes "cut'. So if you are using other fonts, then state some other character width value.

Or maybe is there some connection between font height and font width in lower and upper cases? I don't know that, unfortunately...

P.S. note that there must be tooltip="your_tooltip" attributes in your hotspots for the above action to retrieve these tooltips.
Regards,

Alexey

3

Thursday, July 18th 2013, 11:03am

Brilliant Alexey!

I haven't tried it myself yet but I believe this would work! I was thinking something
similar (getting the size of the tooltip on the fly) but I thought there is no krpano action
that would do this but "indexoftxt" would do the trick.

I will try the code later and share the result :)

Thanks!

Hyung

4

Thursday, July 18th 2013, 9:48pm

This is how I applied based on the code Alexey has provided

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
	<style name="building_tooltip"
		url="%SWFPATH%/plugins/textfield.swf"
		children="false"
		css="text-align:center; color:#FFFFFF; font-family:Arial; font-weight:bold; font-size:12px;"
		vcenter="true"
		backgroundcolor="0x000000" backgroundalpha="0.6" roundedge="5" border="false"
		handcursor="false" capture="false" 
		height="25"
	/>

	<action name="calc_tooltip_width">
		if(hotspot[%1].width == 0, 
			txtadd(tooltip_width_search, get(hotspot[%1].html),'_countstart');
			indexoftxt(number_of_characters,get(tooltip_width_search), '_countstart',0);
			mul(text_width, number_of_characters, 17);
			if(number_of_characters GT 5, sub(text_width, 10));
			copy(hotspot[%1].width, text_width);
			delete(tooltip_width_search, number_of_characters, text_width);
		);
	</action>

	<hotspot name="building_tooltip1" ath="20" atv="0" style="building_tooltip" html="Main Entrance" onloaded="calc_tooltip_width(building_tooltip1);" width="0" />
	<hotspot name="building_tooltip2" ath="-30" atv="-15" style="building_tooltip" html="Second Entrance" onloaded="calc_tooltip_width(building_tooltip2);" width="0" />



I found out that the length of one character is not always the same.. This could be worse
when using non alphabetic language characters. So I set the basic width for one character
and when there are many characters I subtract certain pixels. (In the code above I subtract
10 pixels of width when there are more than 5 characters)

if(number_of_characters GT 5, sub(text_width, 10));

Of course the value would differ depending on the language, font size, font style etc..

And I tried to apply this action to all the tooltips hotspots at one time but I don't know this
could be done with pure krpano actions. So I have added "onloaded" event to each tooltip
hotspot.

Lastly, automatic width calculation action is performed only when there the value of "width"
is 0. First I have removed the width and tried to give condition "when there is no width
specified" in the "calc_tooltip_width" action but I didn't succeed.

I tried something like

if(hotspot[%1].width != null

if(hotspot[%1].width !== null

ifnot(hotspot[%1].width == null

ifnot(hotspot[%1].width === null


if(get(hotspot[%1].width) != null

if(get(hotspot[%1].width) !== null

ifnot(get(hotspot[%1].width) == null

ifnot(get(hotspot[%1].width) === null

but none of them worked. It's probably because the width is NOT null but I don't know
what condition I should do the job.

So if you specify the width value more than 0, then that value will be applied and otherwise
the width will be calculated automatically.

Thanks again to Alexey for giving guides.
Hope this helps others too :)

Best Regards,
Hyung

Alexey Tkachenko

Professional

Posts: 750

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

5

Thursday, July 18th 2013, 10:38pm

Hi!

I'm glad that my thoughts were useful *tongue*

Really can't understand why your code doesn't work unless width="0"... *confused*
Regards,

Alexey

Alexey Tkachenko

Professional

Posts: 750

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

6

Thursday, July 18th 2013, 11:25pm

Just tried your code.

Really, if don't specify "width" of the hotspot, I get both hotspots at 400 px in width.
If I specify some other value other than "0", I got this value as textfield width. *confused*
Regards,

Alexey

Alexey Tkachenko

Professional

Posts: 750

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

7

Thursday, July 18th 2013, 11:44pm

I've had another try just now with this code:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<action name="calc_tooltip_width">
		 
			txtadd(tooltip_width_search, 'get(hotspot[%1].html)','_countstart');
			indexoftxt(number_of_characters,'get(tooltip_width_search)', '_countstart',0);
			mul(text_width, number_of_characters, 17);
			if(number_of_characters GT 5, sub(text_width, 10));
			copy(hotspot[%1].width, text_width);
			delete(tooltip_width_search, number_of_characters, text_width);
			
		
	</action>

	<hotspot name="building_tooltip1" ath="20" atv="0" style="building_tooltip" html="Main Entrance" onloaded="calc_tooltip_width(building_tooltip1);"  />
	<hotspot name="building_tooltip2" ath="-30" atv="-15" style="building_tooltip" html="Second Entrance to the church" onloaded="calc_tooltip_width(building_tooltip2);" />


And it seems to calculate the width of the tooltip, if I increase the tooltip phrase, the tolltip textfield grows in length.

Has anybody else tried this yet?
Regards,

Alexey

8

Friday, July 19th 2013, 10:34am

Just tried your code.

Really, if don't specify "width" of the hotspot, I get both hotspots at 400 px in width.
If I specify some other value other than "0", I got this value as textfield width. *confused*
Yes I also get 400px if I don't specify the width. Seems that 400px is the default width used
inside krpano. Do you still get 400px even give value other than "0"? Strange, because the codes
works for me, which means if I give 100 as width for example, the action is ignored and the
width becomes 100. Maybe it could be different krpano version, or you might want to delete
browser cache and check again.

I have modified the code a bit as below so that in order to differentiate mobile from desktop

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
<action name="calc_tooltip_width">
		if(hotspot[%1].width == 0, 
			txtadd(tooltip_width_search, get(hotspot[%1].html),'_countstart');
			indexoftxt(number_of_characters,get(tooltip_width_search), '_countstart',0);
			mul(text_width, number_of_characters, 18);
			ifnot(device.mobile, 
				if(number_of_characters GT 5, sub(text_width, 10));
				if(number_of_characters GT 10, sub(text_width, 40));
			);
			copy(hotspot[%1].width, text_width);
			delete(tooltip_width_search, number_of_characters, text_width);
		);
	</action>


Again, the right size if the width would depends on the language, font size, style etc..

I believe the code in your last post should work :)

Best Regards,
Hyung

Alexey Tkachenko

Professional

Posts: 750

Location: Sevastopol, Crimea, Russian Federation

Occupation: Interpreting, Building virtual tours

  • Send private message

9

Friday, July 19th 2013, 10:58am

It's just struck me. Is this okay to define hotspot url as "textfield.swf"? Maybe textfield has some default width value which interferes with the action?

*confused*

Just a guess...
Regards,

Alexey