HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Custom Viewport Event Handling

Introduction

Houdini offers custom mouse event hooks that allow you to augment or replace mouse event handling in the Houdini viewport. These hooks, in combination with the custom viewport rendering hooks, provide a great amount of control over the display and functionality of the Houdini viewport.

Mouse event hooks are most commonly used in conjunction with scene render hooks to allow interaction with custom scene elements.

Installing a Mouse Hook

Mouse hooks replace or augument handling of mouse events, such as button presses, button releases, mouse movement, mouse wheel scrolling, double clicks, and RMB menu popups.

To install a mouse hook, derive a class from DM_MouseHook and install it to the DM_EventTable. The DM_MouseHook acts as an object factory for a class derived from DM_MouseEventHook.

{
const int hook_priority = 0; // normal priority
table->registerSceneHook( new DM_CustomMouseHook("greedy",
hook_priority) );
}

There is a simple mouse hook example:

  • HDK_Sample::DM_GreedyMouseHook : Greedily consumes all mouse events, effectively crippling the viewport. A very basic beginner example. (DM_GreedyMouseHook.C)

Working with UI_Event

DM_MouseEventHook has several virtual methods that take a UI_Event object pointer as an argument. This object encapsulates a lot of useful state information about the mouse event. For example, the type of event can be found in UI_Event::reason, a member of type UI_Reason.

Also of interest is UI_Event::state.

bool lmb_down = (event->state.values[W] & UI_LEFT_BUTTON);
bool mmb_down = (event->state.values[W] & UI_MIDDLE_BUTTON);
bool rmb_down = (event->state.values[W] & UI_RIGHT_BUTTON);
int x = event->state.values[X];
int y = event->state.values[Y];
bool alt = (event->state.altFlags & UI_ALT_KEY);
bool shift = (event->state.altFlags & UI_SHIFT_KEY);
bool ctrl = (event->state.altFlags & UI_CTRL_KEY);
bool cmd = (event->state.altFlags & UI_COMMAND_KEY);