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

Pass through events to Blender UI #13

Open
skarndev opened this issue Jan 9, 2020 · 6 comments
Open

Pass through events to Blender UI #13

skarndev opened this issue Jan 9, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@skarndev
Copy link

skarndev commented Jan 9, 2020

I've been experimenting with creating UI with CookieCutter yesterday and I think I found a significant limitation in the way the whole library can be used. It seems to be impossible (just judging from event passing code) to pass any events to Blender UI when a CookieCutter-based operator is running modal.

I see where the limitation is coming from since it was built primarily for Retopoflow and similar tools implementing their own edit modes basically. But since the modal operators in Blender can be run alongside each other it makes it possible to make UI-only operators implementing no real actions (e.g. useful widgets for viewport or something like that, which could stay open when you keep on working using normal Blender features). So, if that functionality is not supported, I propose adding some functionality to have some control over "allowed" areas where events could pass through, making Blender UI functional.

I temporarily changed in the code in cookiecutter.py to pass through all events, and it seems to be not breaking any UI interaction, dragging or whatever. So I suppose, some functionality like that can be added in theory without too much pain?

@patmo141
Copy link

patmo141 commented Jan 9, 2020

Yes absolitely! we have did this before in 2.79 and decided not to push into master until after the 2.8 upgrade I think. https://github.com/CGCookie/addon_common/tree/pass_through

@patmo141
Copy link

patmo141 commented Jan 9, 2020

In this other repository, I have created a "should_pass_through" example (not complete!!) and made alterations to the current cooki_cutter.py

https://github.com/patmo141/cookie_cutter_examples/blob/master/selective_pass_through.py

https://github.com/patmo141/cookie_cutter_examples/blob/master/subtrees/cookiecutter/cookiecutter.py#L157

However I had not thoroughly tested it and wasn't sure exactly where in the cookiecutter modal to insert it. So no merge from me yet. Would love to see what you did.

@skarndev
Copy link
Author

skarndev commented Jan 9, 2020

Thanks for such a quick response! What I did is actually very similar to what you have done in cookiecutter.py with this change, but in a more hacky way. I will test if this change still works properly with action states and if there is no overlapping between events that should pass through.

@patmo141
Copy link

@skarnproject I just pushed my version of should_pass_through to the addon_common repo

@patmo141
Copy link

patmo141 commented Jul 15, 2020

Here is a simple should_pass_through override

def in_region(reg, x, y):
    #first, check outside of area
    if x < reg.x: return False
    if y < reg.y: return False
    if x > reg.x + reg.width: return False
    if y > reg.y + reg.height: return False
     return True
def should_pass_through(self, context, event):
        
 
    if self._hover_ui: return False
    if context.area.type != "VIEW_3D"
        return False

    #first, check outside of area
     outside = False
    if event.mouse_x < context.area.x: outside = True
    if event.mouse_y < context.area.y: outside = True
    if event.mouse_x > context.area.x + context.area.width: outside = True
    if event.mouse_y > context.area.y + context.area.height: outside = True
    
    if outside:
        print('outside the 3DView area')
        return False
     
    #make sure we are in the window region, not the header, tools or UI
    for reg in context.area.regions:
        if in_region(reg, event.mouse_x, event.mouse_y) and reg.type != "WINDOW":
            print('in wrong region')
            return False
        
    return True

@patmo141
Copy link

After a few more tests and examples I think we will be able to close this feature request

@patmo141 patmo141 self-assigned this Jul 27, 2020
@patmo141 patmo141 added the enhancement New feature or request label Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants