Can I set the ypos of a textbox as equal to ypos of an imagebutton?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#1 Post by Aureus »

Greetings! I tried many different things, but I don't know how to properly use the engine's tools. (I assume there's an answer in "renpy.get_placement()", but I don't see any examples of how to use it.
screenshot0016.png
As shown on the example - I want to point at an imagebutton that doesn't have a fixed position (it will change its placement in different contexts) and by hovering, draw a tooltip box that has a) fixed xpos and b) flexible ypos that references the ypos of the imagebutton, locking it in place. Alternatively, I could also reference the hbox to which this imagebutton belongs.

I was hoping to use something similar to "pos renpy.get_mouse_pos()", but I have no clue how to accomplish this.
Last edited by Aureus on Wed Jul 21, 2021 1:30 am, edited 1 time in total.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3784
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#2 Post by Imperf3kt »

There is this, a tool tip that follows the mouse.
viewtopic.php?f=51&t=47205#p472810

For adding images and styling the text, you can see an example in the first reply.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#3 Post by Aureus »

Thank you and I'm sorry for being confusing in my post.
My goal is not to draw a box depending on the position of the mouse, but rather on the position of a hbox / imagebutton that's a part of a larger screen.
The way it works now the box moves up and down to follow the movement of the mouse. Instead, I want to point at an imabutton, and make the textbox "lock" itself to the "top" position of the hbox / imagebutton so it stays in one place.
Last edited by Aureus on Wed Jul 21, 2021 1:30 am, edited 1 time in total.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

philat
Eileen-Class Veteran
Posts: 1895
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#4 Post by philat »

I can't think of a very good way to do this off the top of my head, but a quick workaround that comes to mind is using an hbox with a null image.

Code: Select all


hbox:
    $ tt = GetTooltip()
    
    if tt:
        # add the actual tooltip here
    else:
        null width 200 # 200 is a placeholder - the width should be the width of the tooltip to ensure that even if there is no tooltip, the rest of the box doesn't move to the left
    hbox:
        # the actual buttons you're going to hover which would of course be at the same ypos as the tooltip because they're all in an hbox

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#5 Post by Aureus »

Thank you, I even gave it a shot just to be sure I properly understand why it wouldn't work:
Since the hbox is a part of the game's NVL screen, the tooltip isn't able to squeeze in next to it. If there's an option to force the textbox to show up ABOVE the other boxes, it would indeed be a good option - I just don't know such an option. That's why I try to draw the textbox outside of the hbox and outside of the NVL box.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

philat
Eileen-Class Veteran
Posts: 1895
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#6 Post by philat »

You could fiddle with zorder and such to make it work, I imagine, but perhaps someone else will have a better idea.

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#7 Post by Aureus »

My temporal solution turned out to be completely rebuilding the NVL screen so it's now a grid of hboxes and vboxes with one side filled with nothing, but which gets altered when a tooltip is called.
However, if anyone has a better solution, I'll be happy to take a step back.
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

philat
Eileen-Class Veteran
Posts: 1895
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#8 Post by philat »

This is a late necro, but I was looking through my old posts looking for something and came across this. I'd forgotten about renpy.focus_coordinates() like an idiot, but here's an update if you want to switch away from the grid.

Code: Select all

screen test():
    vbox:
        xpos 300
        ypos 300
        textbutton "test1":
            action NullAction()
            tooltip "Tooltip1"
        textbutton "test2":
            action NullAction()
            tooltip "Tooltip2"

    $ tt = GetTooltip()

    if tt:
        $ tt_pos = renpy.focus_coordinates() # returns (x, y, w, h) of focused displayable https://www.renpy.org/doc/html/other.html#renpy.focus_coordinates
        $ tt_y = int(tt_pos[1]) # the coordinates are returned as a float for whatever reason so force to int
        text tt xpos 500 ypos tt_y

label start:
    call screen test

User avatar
Aureus
Veteran
Posts: 278
Joined: Sun Aug 06, 2017 4:49 am
Completed: The Tavern, Tales From Windy Meadow
Projects: Roadwarden
Organization: Moral Anxiety Studio
itch: moral-anxiety
Location: Breslau, Poland
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#9 Post by Aureus »

While it may be too late for me, I am grateful that you decided to give it another shot. : ) Thank you, I'm sure I'll need renpy.focus_coordinates() on another day!
Tales From Windy Meadow - slice of life, pixel art Visual Novel set in a fantasy village. now available on Steam.

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: Can I set the ypos of a textbox as equal to ypos of an imagebutton?

#10 Post by henvu50 »

The renpy.focus_coordinates() turned out to be very useful! Thanks for responding with that info.

Is it also possible to get the ID of the displayable, in addition to the focus coordinates?

Code: Select all

# pseudo code
$ rfc = renpy.focus_coordinates(alsoReturnDisplayableID=True)
# result
# (343,142,832,443, "main_menu_load_button")
Anyway to return the ID of the button?

Post Reply

Who is online

Users browsing this forum: Google [Bot]