General inheritance and specific example / Vererbung im allgemeinen und konkretes Beispiel

  • Hello dear Panoheads,

    im trying to understand the following:

    How is the style that a hotspot calls related to the hotspot, I believe the style becomes part of it.
    If the style contains an action, how does it behave, will the action be a child of the hotspot ?
    If the action wants to call an attribute of the hotspot, must it reference its parents attribute or is it nested deeper and if so how to reference attributes through 'nested inheritance'.

    In this particular case:

    I have been trying to add always visible captions to hotspots, where the function is part of the style of the hotspot (so it needs writing and refering to only once) and the text to be displayed is set as a parameter of the hotspot element. I found a very useful code snipped by KR. Now the code looks like this:

    Now my wish is that from a hotspot like this:

    Code
    <hotspot name="spot1" style="skin_hotspotstyle" ath="0.000" atv="0.000" distorted="false" zoom="false" linkedscene="scene_2"/>

    I would be able to grab the name="spot1" attribute and have the tooltip display it. I can directly set 'html' in the function and have all tooltips read the same but I am failing to declare the source for copy(plugin[get(tooltipname)].html, source); to reference 'name' from 'hotspot'.

    I did believe the content of the style referenced by the hotspot would be basically copied into each hotspot that refers to it at runtime. As such I would have believed that when calling

    Code
    plugin[get(tooltipname)].parent.name

    inside the function it should return the 'name' of the actions parent (the hotspot that is) but it does not. Maybe I am failing to understand how 'nested inheritance' works and its more than just adding dots, but I tried a few things and so far no luck.

    Thank you very much everyone who can share some wisdom.

  • Hi, you have replaced the native hotspot style and the "tooltip" value is empty.
    You wrote your code in "onloaded", and in the native one, this attribute was used to set the scene signature in "tooltip"

    Working code example

    Code
    <action name="atttooltip">  
        txtadd(tooltipname, 'tooltip_', get(name));  
        addlayer(get(tooltipname));
    	copy(txt,layer[get(tooltipname)]);
        txtadd(txt.parent,'hotspot[', get(name), ']');
        set(txt,type='text', align=bottom, edge=top, enabled=false, y=-10, width=200, autoheight=true, bg=false, css='text-align:center; color:#FFFFFF; font-family:Arial; font-weight:bold; font-size:28px;', txtshadow='2 2 6 0x000000'    ); 
        copy(layer[get(tooltipname)].html, scene[get(linkedscene)].title);     
    </action>
  • when the xml is parsed
    the styles get applied to the hotspots / layers etc
    all attributes of the style that are not set in the hotspot / layer will be copied over.
    like this you can overwrite (or ignore) a style attribute by setting it in the hotspot / layer.

    after this process the style gets irrelevant,
    eg changing a style dynamically will not update the hotspots / layers!

    but you can also dynamically assign a style
    https://krpano.com/docu/actions/#assignstyle
    so, to simplify your atttooltip() you could add a style "tooltipstyle" for your tooltips and do
    assignstyle(layer[get(tooltipname)], "tooltipstyle");
    (or use the set() syntax like in San7 suggested)

    actions like onclick will executed in the scope of the layer / hotspot
    <hotspot name="test" onclick="trace(name);" /> will trace "test"

  • Hi, you have replaced the native hotspot style and the "tooltip" value is empty.
    You wrote your code in "onloaded", and in the native one, this attribute was used to set the scene signature in "tooltip"

    Working code example

    Code
    copy(layer[get(tooltipname)].html, scene[get(linkedscene)].title);     
    </action>


    Thank you so far, I see part of what failed here, but wouldn't the last line of your example fetch the title of the scene the hotspot points to and use it as the permanently visible tooltip ? So the question for me remains, how I, out of that scope, fetch the hotspots attributes like its name ? Just hotspot.name from the scope of the action ?

    Zitat

    when the xml is parsed
    the styles get applied to the hotspots / layers etc
    all attributes of the style that are not set in the hotspot / layer will be copied over.
    like this you can overwrite (or ignore) a style attribute by setting it in the hotspot / layer.

    after this process the style gets irrelevant,
    eg changing a style dynamically will not update the hotspots / layers!

    This is what I believed, the problem should lie here, as I dont think anything happens dynamically. The scene gets loaded, with it the hotspots with its attributes, the referenced style gets looked up and values copied, including the action and the action, when called, which is after loading, should be performed, where it will fetch the relevant values from the hotspot it is part of. The action should (?) run in the scope of its hotspot and thus there should not be a problem with several actions of the same name being performed with different parameters in one scene (?).

    Zitat

    but you can also dynamically assign a style
    https://krpano.com/docu/actions/#assignstyle
    so, to simplify your atttooltip() you could add a style "tooltipstyle" for your tooltips and do
    assignstyle(layer[get(tooltipname)], "tooltipstyle");
    (or use the set() syntax like in San7 suggested)

    actions like onclick will executed in the scope of the layer / hotspot
    <hotspot name="test" onclick="trace(name);" /> will trace "test"

    Much like assumed, so

    <scene name ="scene1">
    <hotspot name="hotspot1" onclick="action1" onloaded="action2" />
    <hotspot name="hotspot2" onclick="action1" onloaded="action2" />
    </scene>

    should be able to perform 2 actions of the action1 and action2 type, despite running in the same scene, because they are running in their hotspot, meaning if they took "hotspot1" and "hotspot2" as arguments they would produce different results, isn't it ?

    EDIT:

    It was simpler than I thought. From the action, despite it having a

    Code
    name="atttooltip"

    attribute I could fetch the hotspots name attribute by merely using

    Code
    name

    .

    Code
    <action name="atttooltip">
    ... 
    copy(layer[get(tooltipname)].html, name);
    </action>

    The same works when I give the hotspot a custom parameter and call it. I have no idea why. But it works for now.

    3 Mal editiert, zuletzt von _Matthias_ (22. Juni 2021 um 12:07) aus folgendem Grund: Solved it

  • Zitat

    This is what I believed, the problem should lie here, as I dont think anything happens dynamically. The scene gets loaded, with it the hotspots with its attributes, the referenced style gets looked up and values copied, including the action and the action, when called, which is after loading, should be performed, where it will fetch the relevant values from the hotspot it is part of. The action should (?) run in the scope of its hotspot and thus there should not be a problem with several actions of the same name being performed with different parameters in one scene (?).


    yes, thats how it works...
    <hotspot name="a"customattribute="1" onclick="myaction" />
    <hotspot name="b" ustomattribute="2" onclick="myaction" />
    <action name="myaction">trace(name, customattribute);</action>
    --> will trace "a1" and "b2" for the hotspots

    you could also create a local scope action (which is better anyway)
    to make it a bit clearer and to not spill the global scope with variables
    <action name="myaction" scope="local">trace(caller.name,caller.customattribute);</action>
    https://krpano.com/docu/xml/#action.scope

  • Thank you very much. This would leave me with only one question: In the above example, where the <action> is defined in the <style> and as such when loading the action becomes part of the <hotspot>... how would one, inside the action, call the actions name, if as observed simply calling 'name' returns the hotspots name ?

  • Thank you very much. This would leave me with only one question: In the above example, where the <action> is defined in the <style> and as such when loading the action becomes part of the <hotspot>... how would one, inside the action, call the actions name, if as observed simply calling 'name' returns the hotspots name ?

    if you define onclick like
    <style name="test" onclick="trace(name);" />
    <hotspot name="a" style="test" />

    then you could trigger the action with
    hotspot[a].onclick(); (at least i think so *whistling*)
    but such functions are normally triggered by events and not by the user

    you could also define the action separately
    <style name="test" onclick="tracename();" />
    <action name="tracename">trace(name);</action>
    <hotspot name="a" style="test" />

    now you can do
    callwith(hotspot[a], tracename);
    https://krpano.com/docu/actions/#callwith

    or ofc just tracename();
    if the action doesnt depend on the hotspot scope

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!