Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MouseWatcherRegion leave event is duplicated at border shared with DisplayRegion #858

Closed
Epihaius opened this issue Jan 23, 2020 · 1 comment
Closed
Assignees
Labels
bug
Milestone

Comments

@Epihaius
Copy link
Contributor

@Epihaius Epihaius commented Jan 23, 2020

When the mouse is moved (not dragged) out of a MouseWatcherRegion across a side that lies on the border of a DisplayRegion, the leave event appears to be fired twice in succession, which may cause problems for associated code that should be called only once.

The following code should reproduce this:

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase


showbase = ShowBase()


def on_region_enter(*args):

    name = args[0].get_name()

    if name.startswith("region"):
        print("Entered {}".format(name))


def on_region_leave(*args):

    name = args[0].get_name()

    if name.startswith("region"):
        print("Left {}".format(name))


# Create new DisplayRegion with blue background, centered in the window.
dr = showbase.win.make_display_region(.25, .75, .25, .75)
dr.sort = 10
dr.active = True
dr.clear_color = (0., 0., 1., 1.)
dr.set_clear_color_active(True)
render2 = NodePath("render2")
lens = OrthographicLens()
lens.film_size = (2., 2.)
cam2_node = Camera("cam2", lens)
cam2_node.active = True
cam2 = render2.attach_new_node(cam2_node)
cam2.set_y(-1.)
dr.camera = cam2

# Create new MouseWatcher, bound to the new DisplayRegion.
mouse_watcher = MouseWatcher("watcher2")
showbase.mouseWatcher.get_parent().attach_new_node(mouse_watcher)
mouse_watcher.set_display_region(dr)
mouse_watcher.set_enter_pattern("region_enter")
mouse_watcher.set_leave_pattern("region_leave")
showbase.accept("region_enter", on_region_enter)
showbase.accept("region_leave", on_region_leave)

# Create a card as the visualization of a MouseWatcherRegion in the
# top left hand corner of the new DisplayRegion.
r = .5
t = .5
cm = CardMaker("card")
cm.set_frame(-r, r, -t, t)
pos = Point3(-1. + r, 0., 1. - t)
card = render2.attach_new_node(cm.generate())
card.set_pos(pos)
region = MouseWatcherRegion("region_topleft",
    -1., -1. + r * 2., 1. - t * 2., 1.)
mouse_watcher.add_region(region)


showbase.run()

When running the above code, first move the mouse over the white rectangle, then move the mouse away from it, making sure that the mouse pointer crosses either the top or left side of that rectangle. Both of these sides are on the border of a display sub-region (the blue rectangle) that is centered in the window. The MouseWatcherRegion associated with the white rectangle has been added to a MouseWatcher that is bound to this DisplayRegion.
In the command console, the output should read:

Entered region_topleft
Left region_topleft
Left region_topleft

Note that Left region_topleft is printed twice in succession, while it is printed only once when leaving the white rectangle along the right or bottom side.

This issue occurs on Windows 10.

@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Feb 29, 2020

Observed on Linux as well.

@rdb rdb self-assigned this Feb 29, 2020
@rdb rdb added this to the 1.10.6 milestone Feb 29, 2020
@rdb rdb closed this in f98c14c Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.