Trackball::set_control_mode()

This commit is contained in:
David Rose 2012-01-24 15:24:18 +00:00
parent c8e3c72b3a
commit 186da11f36
2 changed files with 67 additions and 0 deletions

View File

@ -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.

View File

@ -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