Modal property in windows and frames.

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
vital1970
Newbie
Posts: 7
Joined: Sat May 30, 2020 9:38 pm
Contact:

Modal property in windows and frames.

#1 Post by vital1970 »

Hello. I tried to apply the modal property with the called function in buttons.
I used three buttons with different position properties as an experiment.
I checked the value of arguments with variables.
The x argument passed the mouse position on the x axis.
The y argument should pass the mouse position on the y axis, but that's not true.
I checked it with the renpy.get_mouse_pos() function.
The w and h arguments are passed to the size of the displayed object, in this example a button.
And when I use the area property, I get integers.
When I use xysize, maximum, minimum properties I get floating point numbers.
I have a question why the mouse position on x-axis is always the same, but never on y-axis.
And also on the position properties, why with some properties the values of arguments are integers in other floating point numbers.
Is it an error or I'm doing something wrong?
Here is an example in which I made a check.

Code: Select all

init python:

            def modal_function(ev, x, y, w, h):
                import pygame_sdl2 as mypygame_sdl2 # import pygame_sdl2 module
                store.mouse_pos = renpy.get_mouse_pos()
                store.mod_1 = ev #renpy.pygame_sdl2.event.event_name(ev)
                store.ev_type = type(ev)
                store.mod_2 = x
                store.mod_3 = y
                store.mod_4 = w
                store.mod_5 = h

                if ev is not None:
                    if ev.type == mypygame_sdl2.MOUSEBUTTONUP: # event when the mouse button is released
                        return True                           
                    else:
                        return False
            screen modal_screen_2():
            tag myscreen
            #modal True
            frame:
                background 'bg meadow'
                hbox:
                    spacing 2
                    vbox:
                        spacing 2
                        pos (-4,-4)
                        text 'Экран my_screen'
                        button id "button_1":
                            background "textbutton_[prefix_]"
                            maximum (180, 60) 
                            minimum (180, 60) 
                            modal modal_function 
                            action Call("enter_label") 
                        button:
                            background "textbutton_[prefix_]"
                            area (0,0,180,60)
                            modal modal_function
                            action ShowTransient("enter_screen", transition=dissolve) 
                        button:
                            background "textbutton_[prefix_]"
                            xysize (180,60)
                            modal modal_function
                            action Return()

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Modal property in windows and frames.

#2 Post by PyTom »

> The y argument should pass the mouse position on the y axis, but that's not true.

That's because the positions are relative to the button, not the screen.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

vital1970
Newbie
Posts: 7
Joined: Sat May 30, 2020 9:38 pm
Contact:

Re: Modal property in windows and frames.

#3 Post by vital1970 »

Thank you for your reply. I understand what you are talking about. In case we apply the button to the whole screen, the x and y positions will coincide with the positions of the mouse cursor and will be integers.
Example.

Code: Select all

init python:

        def modal_function(ev, x, y, w, h):
            import pygame_sdl2 as mypygame_sdl2 # import pygame_sdl2 module
            store.mouse_pos = renpy.get_mouse_pos()
            store.ev_type = type(ev)
            store.mod_1 = ev #renpy.pygame_sdl2.event.event_name(ev)
            store.mod_2 = x
            store.mod_3 = y
            store.mod_4 = w
            store.mod_5 = h

            if ev is not None:
                if ev.type == mypygame_sdl2.MOUSEBUTTONUP: # event when the mouse button is released
                    return True                            
                else:
                    return False
            else:
                pass

        
    # TODO modal_screen_1
    screen modal_screen_1():
        tag myscreen
        frame:
            background "setka"
            button:
            # imagebutton:
            #     idle "background" # imagebutton
                background 'background' # button
                xysize (1280,720) # button
                pos (-4,-4)
                modal modal_function 
                action Return() 
But if I apply a more complicated variant, then with values on positions x and y incomprehensible phenomena will happen.
1. The x-axis position coincides with the mouse position and will be an integer, the y-axis position does not coincide and will be a floating-point number.
2. The x-axis position does not coincide with the mouse position and is a floating point number, the y-axis position coincides and is an integer.
3. The x-axis and y-axis positions do not coincide with the mouse positions and will be a floating point number.
4. The x- and y-axis positions coincide with the mouse positions and will be integers.
This is what I encountered in this example. Different buttons had different values.

Code: Select all

screen modal_screen_2():
        tag myscreen
        frame:
            background 'background'
            hbox:
                spacing 2
                vbox:
                    spacing 2
                    pos (-4,-4)
                    # button:
                    #     background "textbutton_[prefix_]"
                    #     xysize (180,60) 
                    imagebutton:
                        idle "button background_1" # imagebutton
                        xysize (180,60) # imagebutton
                        modal modal_function 
                        action Return() 
                    # button:
                    #     background "textbutton_[prefix_]"
                    #     area (0,0,180,60)
                    imagebutton:
                        idle "button background_1" # imagebutton
                        xysize (180,60) # imagebutton
                        modal modal_function
                        action Return() 
                    # button:
                    #     background "textbutton_[prefix_]"
                    #     maximum (180, 60)
                    #     minimum (180, 60)
                    imagebutton:
                        idle "button background_1" # imagebutton
                        xysize (180,60) # imagebutton
                        modal modal_function
                        action Return()
                vbox:
                    spacing 2
                    pos (-4,-4)
                    # button:
                    #     background "textbutton_[prefix_]"
                    #     xysize (180,60)
                    imagebutton:
                        idle "button background_2" # imagebutton
                        xysize (180,60) # imagebutton
                        modal modal_function 
                        action Return() 
                    # button:
                    #     background "textbutton_[prefix_]"
                    #     xysize (180,60)
                    imagebutton:
                        idle "button background_2" # imagebutton
                        xysize (180,60) # imagebutton
                        modal modal_function 
                        action Return()
                    # button:
                    #     background "textbutton_[prefix_]"
                    #     xysize (180,60)
                    imagebutton:
                        idle "button background_2" # imagebutton
                        xysize (180,60) # imagebutton
                        modal modal_function 
                        action Return()

vital1970
Newbie
Posts: 7
Joined: Sat May 30, 2020 9:38 pm
Contact:

Re: Modal property in windows and frames.

#4 Post by vital1970 »

Hello. I think this topic can be closed. Just confused by the results of the differences, I mean integer and floating point number on the arguments x and y.
Thank you for your answers on this issue.

_____________________________________________________________________________________________________________________________________

I create video tutorials for working with the visual novel engine Ren'Py.
Link to the channel.
https://www.youtube.com/channel/UClZBAe ... Y4IH9TfNEA

Post Reply

Who is online

Users browsing this forum: No registered users