This is how I applied based on the code Alexey has provided
|
Quellcode
|
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