Skip to content

Implement EventDispatcher exclusive mode for higher-level event control#3

Draft
Copilot wants to merge 4 commits intodevel_41_DrawTextfrom
copilot/fix-3dda36e3-fb89-4265-b0ba-363f3dff4d17
Draft

Implement EventDispatcher exclusive mode for higher-level event control#3
Copilot wants to merge 4 commits intodevel_41_DrawTextfrom
copilot/fix-3dda36e3-fb89-4265-b0ba-363f3dff4d17

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 11, 2025

Problem

The existing EventDispatcher system uses hierarchical event propagation (Window → RenderFramework → Scene → SceneNode), but there was no mechanism for a specific EventDispatcher to temporarily operate in exclusive mode at higher levels. This was needed for scenarios like:

  • UI dialogs that need to capture all input events while open
  • Camera controls that need exclusive mouse input for view manipulation
  • Debug interfaces that need to temporarily override normal event handling

Solution

Added comprehensive exclusive mode functionality to the EventDispatcher system that allows any dispatcher to request exclusive control at specified parent levels.

Core Features

EventDispatcher Base Class (inc/hgl/io/event/EventDispatcher.h)

  • SetExclusiveMode(dispatcher) - Set a child dispatcher as exclusive
  • RequestExclusiveAtHigherLevel(levels) - Request exclusive mode at parent levels
  • ReleaseExclusiveAtHigherLevel(levels) - Release exclusive control
  • Proper event dispatch logic that respects exclusive mode

Event Handling Classes

  • WindowEvent - Base window event handling with exclusive mode dispatch
  • MouseEvent - Mouse input handling with coordinate tracking
  • KeyboardEvent - Keyboard input with key state management
  • Window - Basic window abstraction for testing

Usage Examples

UI Dialog Exclusive Mode:

class DialogEventHandler : public io::WindowEvent {
    void OpenDialog() {
        // Capture all events at parent level - game won't receive events
        RequestExclusiveAtHigherLevel(1);
    }
    
    void CloseDialog() {
        ReleaseExclusiveAtHigherLevel(1);
    }
};

Camera Control Exclusive Mode:

class CameraController : public io::MouseEvent {
    void StartCameraControl() {
        // Exclusive mouse control at framework level
        RequestExclusiveAtHigherLevel(2);
    }
};

Implementation Details

  • Uses standard C++ containers (independent of submodules)
  • Maintains backward compatibility with existing EventDispatcher usage
  • Supports multi-level exclusive mode for complex scenarios
  • Type-safe event dispatch using templates and dynamic_cast
  • Comprehensive test coverage with working examples

Testing

Added complete test suite (example/EventDispatcherExclusiveTest.cpp) that demonstrates:

  • Normal event propagation behavior
  • Dialog exclusive mode preventing game event handling
  • Camera control exclusive mouse capture
  • Multi-level exclusive mode interactions

The implementation successfully handles the original requirement for "某一个EventPatcher需要在更高级别处暂时处于独占状态" (allowing an EventPatcher to temporarily be in exclusive state at higher levels).

Files Added

  • Core EventDispatcher system with exclusive mode support
  • Complete example demonstrating all usage scenarios
  • Comprehensive documentation explaining the design
  • Working test program that can be compiled and run immediately

This provides a robust, flexible solution for selective event handling control in the ULRE rendering engine.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits August 11, 2025 05:21
Co-authored-by: hyzboy <1788285+hyzboy@users.noreply.github.com>
Co-authored-by: hyzboy <1788285+hyzboy@users.noreply.github.com>
Copilot AI changed the title [WIP] 我看这个EventPatcher是一级级传递的,但是我有一个需求是某一个EventPatcher需要在更高级别处暂时处于独占状态。请帮我设计一下。 Implement EventDispatcher exclusive mode for higher-level event control Aug 11, 2025
Copilot AI requested a review from hyzboy August 11, 2025 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants