From 186da11f365c28511c2126bbc459ba4aa61899dd Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 24 Jan 2012 15:24:18 +0000 Subject: [PATCH] Trackball::set_control_mode() --- panda/src/tform/trackball.cxx | 55 +++++++++++++++++++++++++++++++++++ panda/src/tform/trackball.h | 12 ++++++++ 2 files changed, 67 insertions(+) diff --git a/panda/src/tform/trackball.cxx b/panda/src/tform/trackball.cxx index bece8d91d1..0f66a8a927 100644 --- a/panda/src/tform/trackball.cxx +++ b/panda/src/tform/trackball.cxx @@ -57,6 +57,7 @@ Trackball(const string &name) : _orig = LMatrix4::ident_mat(); _invert = true; _cs = get_default_coordinate_system(); + _control_mode = CM_default; // We want to track the state of these buttons. watch_button(MouseButton::one()); @@ -336,6 +337,32 @@ get_invert() const { return _invert; } +//////////////////////////////////////////////////////////////////// +// Function: Trackball::set_control_mode +// Access: Published +// Description: Sets the control mode. Normally this is CM_default, +// which means each mouse button serves its normal +// function. When it is CM_truck, CM_pan, CM_dolly, or +// CM_roll, all of the mouse buttons serve the indicated +// function instead of their normal function. This can +// be used in conjunction with some external way of +// changing modes. +//////////////////////////////////////////////////////////////////// +void Trackball:: +set_control_mode(ControlMode control_mode) { + _control_mode = control_mode; +} + +//////////////////////////////////////////////////////////////////// +// Function: Trackball::get_control_mode +// Access: Published +// Description: Returns the control mode. See set_control_mode(). +//////////////////////////////////////////////////////////////////// +Trackball::ControlMode Trackball:: +get_control_mode() const { + return _control_mode; +} + //////////////////////////////////////////////////////////////////// // Function: Trackball::set_rel_to // Access: Published @@ -446,6 +473,34 @@ apply(double x, double y, int button) { // translation to be in those local coordinates. reextract(); } + + if (button == B1_MASK && _control_mode != CM_default) { + // We have a control mode set; this may change the meaning of + // button 1. Remap button to match the current control mode + // setting. + switch (_control_mode) { + case CM_truck: + button = B1_MASK; + break; + + case CM_pan: + button = B2_MASK; + break; + + case CM_dolly: + button = B3_MASK; + break; + + case CM_roll: + button = B2_MASK | B3_MASK; + break; + + case CM_default: + // Not possible due to above logic. + nassertv(false); + } + } + if (button == B1_MASK) { // Button 1: translate in plane parallel to screen. diff --git a/panda/src/tform/trackball.h b/panda/src/tform/trackball.h index 4bc9607b71..0917d1b019 100644 --- a/panda/src/tform/trackball.h +++ b/panda/src/tform/trackball.h @@ -81,6 +81,17 @@ PUBLISHED: /// **** Misc **** + enum ControlMode { + CM_default, + CM_truck, // Normally mouse 1 + CM_pan, // Normally mouse 2 + CM_dolly, // Normally mouse 3 + CM_roll, // Normally mouse 2 + 3 + }; + + void set_control_mode(ControlMode control_mode); + ControlMode get_control_mode() const; + void set_invert(bool flag); bool get_invert() const; @@ -113,6 +124,7 @@ private: bool _invert; NodePath _rel_to; CoordinateSystem _cs; + ControlMode _control_mode; protected: // Inherited from DataNode