David Rose пре 20 година
родитељ
комит
f234ec5e84

+ 3 - 0
panda/src/tform/Sources.pp

@@ -14,6 +14,7 @@
     config_tform.h \
     driveInterface.I driveInterface.h \
     mouseInterfaceNode.I mouseInterfaceNode.h \
+    mouseSubregion.I mouseSubregion.h \
     mouseWatcher.I mouseWatcher.h \
     mouseWatcherGroup.h \
     mouseWatcherParameter.I mouseWatcherParameter.h \
@@ -26,6 +27,7 @@
     config_tform.cxx \
     driveInterface.cxx \
     mouseInterfaceNode.cxx \
+    mouseSubregion.cxx \
     mouseWatcher.cxx \
     mouseWatcherGroup.cxx \
     mouseWatcherParameter.cxx mouseWatcherRegion.cxx  \
@@ -36,6 +38,7 @@
     buttonThrower.I buttonThrower.h \
     driveInterface.I driveInterface.h \
     mouseInterfaceNode.I mouseInterfaceNode.h \
+    mouseSubregion.I mouseSubregion.h \
     mouseWatcher.I mouseWatcher.h \
     mouseWatcherGroup.h \
     mouseWatcherParameter.I mouseWatcherParameter.h \

+ 2 - 0
panda/src/tform/config_tform.cxx

@@ -20,6 +20,7 @@
 
 #include "driveInterface.h"
 #include "buttonThrower.h"
+#include "mouseSubregion.h"
 #include "mouseWatcher.h"
 #include "mouseWatcherGroup.h"
 #include "mouseWatcherRegion.h"
@@ -58,6 +59,7 @@ ConfigureFn(config_tform) {
   DriveInterface::init_type();
   ButtonThrower::init_type();
   MouseInterfaceNode::init_type();
+  MouseSubregion::init_type();
   MouseWatcher::init_type();
   MouseWatcherGroup::init_type();
   MouseWatcherRegion::init_type();

+ 93 - 0
panda/src/tform/mouseSubregion.I

@@ -0,0 +1,93 @@
+// Filename: mouseSubregion.I
+// Created by:  drose (13May05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::get_left
+//       Access: Published
+//  Description: Retrieves the x coordinate of the left edge of the
+//               rectangle within the window.  This number will be in
+//               the range [0..1].
+////////////////////////////////////////////////////////////////////
+float MouseSubregion::
+get_left() const {
+  return _l;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::get_right
+//       Access: Published
+//  Description: Retrieves the x coordinate of the right edge of the
+//               rectangle within the window.  This number will be in
+//               the range [0..1].
+////////////////////////////////////////////////////////////////////
+float MouseSubregion::
+get_right() const {
+  return _r;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::get_bottom
+//       Access: Published
+//  Description: Retrieves the y coordinate of the bottom edge of 
+//               the rectangle within the window.  This number will be
+//               in the range [0..1].
+////////////////////////////////////////////////////////////////////
+float MouseSubregion::
+get_bottom() const {
+  return _b;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::get_top
+//       Access: Published
+//  Description: Retrieves the y coordinate of the top edge of the
+//               rectangle within the window.  This number will be in
+//               the range [0..1].
+////////////////////////////////////////////////////////////////////
+float MouseSubregion::
+get_top() const {
+  return _t;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::set_dimensions
+//       Access: Published
+//  Description: Changes the region of the window in which the mouse
+//               is considered to be active.  The parameters are
+//               identical to those for a DisplayRegion: they range
+//               from 0 to 1, where 0,0 is the lower left corner and
+//               1,1 is the upper right; (0, 1, 0, 1) represents the
+//               whole window.
+////////////////////////////////////////////////////////////////////
+void MouseSubregion::
+set_dimensions(float l, float r, float b, float t) {
+  _l = l;
+  _r = r;
+  _b = b;
+  _t = t;
+
+  _minx = l * 2.0f - 1.0f;
+  _miny = b * 2.0f - 1.0f;
+
+  float maxx = r * 2.0f - 1.0f;
+  float maxy = t * 2.0f - 1.0f;
+
+  _scalex = 2.0f / (maxx - _minx);
+  _scaley = 2.0f / (maxy - _miny);
+}

+ 116 - 0
panda/src/tform/mouseSubregion.cxx

@@ -0,0 +1,116 @@
+// Filename: mouseSubregion.cxx
+// Created by:  drose (13May05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "mouseSubregion.h"
+#include "dataNodeTransmit.h"
+
+TypeHandle MouseSubregion::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+MouseSubregion::
+MouseSubregion(const string &name) :
+  MouseInterfaceNode(name)
+{
+  _pixel_xy_input = define_input("pixel_xy", EventStoreVec2::get_class_type());
+  _pixel_size_input = define_input("pixel_size", EventStoreVec2::get_class_type());
+  _xy_input = define_input("xy", EventStoreVec2::get_class_type());
+  _button_events_input = define_input("button_events", ButtonEventList::get_class_type());
+
+  _pixel_xy_output = define_output("pixel_xy", EventStoreVec2::get_class_type());
+  _pixel_size_output = define_output("pixel_size", EventStoreVec2::get_class_type());
+  _xy_output = define_output("xy", EventStoreVec2::get_class_type());
+  _button_events_output = define_output("button_events", ButtonEventList::get_class_type());
+
+  _pixel_xy = new EventStoreVec2(LPoint2f(0.0f, 0.0f));
+  _xy = new EventStoreVec2(LPoint2f(0.0f, 0.0f));
+  _pixel_size = new EventStoreVec2(LPoint2f(0.0f, 0.0f));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::Destructor
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+MouseSubregion::
+~MouseSubregion() {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MouseSubregion::do_transmit_data
+//       Access: Protected, Virtual
+//  Description: The virtual implementation of transmit_data().  This
+//               function receives an array of input parameters and
+//               should generate an array of output parameters.  The
+//               input parameters may be accessed with the index
+//               numbers returned by the define_input() calls that
+//               were made earlier (presumably in the constructor);
+//               likewise, the output parameters should be set with
+//               the index numbers returned by the define_output()
+//               calls.
+////////////////////////////////////////////////////////////////////
+void MouseSubregion::
+do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) {
+  if (input.has_data(_xy_input)) {
+    const EventStoreVec2 *xy;
+    DCAST_INTO_V(xy, input.get_data(_xy_input).get_ptr());
+    const LVecBase2f &p = xy->get_value();
+
+    // Scale the old value into the new range.
+    LVecBase2f n((p[0] - _minx) * _scalex - 1.0f, (p[1] - _miny) * _scaley - 1.0f);
+
+    // If the mouse is indeed within the display region, pass it down.
+    if (n[0] >= -1.0f && n[0] <= 1.0f &&
+        n[1] >= -1.0f && n[1] <= 1.0f) {
+      _xy->set_value(n);
+      output.set_data(_xy_output, EventParameter(_xy));
+
+      // Also compute the pixel coordinates, based on the supplied
+      // pixel_size.
+      if (input.has_data(_pixel_size_input)) {
+        const EventStoreVec2 *pixel_size;
+        DCAST_INTO_V(pixel_size, input.get_data(_pixel_size_input).get_ptr());
+        const LVecBase2f &s = pixel_size->get_value();
+
+        float xf = (1.0f + n[0]) * 0.5f * s[0];
+        float yf = (1.0f - n[1]) * 0.5f * s[1];
+        
+        _pixel_xy->set_value(LPoint2f(xf, yf));
+        output.set_data(_pixel_xy_output, EventParameter(_pixel_xy));
+      }
+
+      // Only send the button events if the mouse is within the
+      // display region.
+      output.set_data(_button_events_output, input.get_data(_button_events_input));
+    }
+  }
+
+  // Now scale the window size.
+  if (input.has_data(_pixel_size_input)) {
+    const EventStoreVec2 *pixel_size;
+    DCAST_INTO_V(pixel_size, input.get_data(_pixel_size_input).get_ptr());
+    const LVecBase2f &s = pixel_size->get_value();
+
+    LVecBase2f n(s[0] * (_r - _l), s[1] * (_t - _b));
+    _pixel_size->set_value(n);
+    output.set_data(_pixel_size_output, EventParameter(_pixel_size));
+  }
+}

+ 101 - 0
panda/src/tform/mouseSubregion.h

@@ -0,0 +1,101 @@
+// Filename: mouseSubregion.h
+// Created by:  drose (13May05)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef MOUSESUBREGION_H
+#define MOUSESUBREGION_H
+
+#include "pandabase.h"
+
+#include "mouseInterfaceNode.h"
+#include "luse.h"
+
+
+////////////////////////////////////////////////////////////////////
+//       Class : MouseSubregion
+// Description : The MouseSubregion object scales the mouse inputs
+//               from within a rectangular region of the screen, as if
+//               they were the full-screen inputs.
+//
+//               If you choose your MouseSubregion coordinates to
+//               exactly match a DisplayRegion within your window, you
+//               end up with a virtual mouse within your
+//               DisplayRegion.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA MouseSubregion : public MouseInterfaceNode {
+PUBLISHED:
+  MouseSubregion(const string &name);
+  ~MouseSubregion();
+
+  INLINE float get_left() const;
+  INLINE float get_right() const;
+  INLINE float get_bottom() const;
+  INLINE float get_top() const;
+  INLINE void set_dimensions(float l, float r, float b, float t);
+
+protected:
+  // Inherited from DataNode
+  virtual void do_transmit_data(const DataNodeTransmit &input,
+                                DataNodeTransmit &output);
+
+private:
+  float _l;
+  float _r;
+  float _b;
+  float _t;
+
+  float _minx, _miny;
+  float _scalex, _scaley;
+
+private:
+  // inputs
+  int _pixel_xy_input;
+  int _pixel_size_input;
+  int _xy_input;
+  int _button_events_input;
+
+  // outputs
+  int _pixel_xy_output;
+  int _pixel_size_output;
+  int _xy_output;
+  int _button_events_output;
+
+  PT(EventStoreVec2) _pixel_xy;
+  PT(EventStoreVec2) _xy;
+  PT(EventStoreVec2) _pixel_size;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    MouseInterfaceNode::init_type();
+    register_type(_type_handle, "MouseSubregion",
+                  MouseInterfaceNode::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "mouseSubregion.I"
+
+#endif

+ 5 - 0
panda/src/tform/mouseWatcher.cxx

@@ -44,10 +44,12 @@ MouseWatcher(const string &name) :
   DataNode(name) 
 {
   _pixel_xy_input = define_input("pixel_xy", EventStoreVec2::get_class_type());
+  _pixel_size_input = define_input("pixel_size", EventStoreVec2::get_class_type());
   _xy_input = define_input("xy", EventStoreVec2::get_class_type());
   _button_events_input = define_input("button_events", ButtonEventList::get_class_type());
 
   _pixel_xy_output = define_output("pixel_xy", EventStoreVec2::get_class_type());
+  _pixel_size_output = define_output("pixel_size", EventStoreVec2::get_class_type());
   _xy_output = define_output("xy", EventStoreVec2::get_class_type());
   _button_events_output = define_output("button_events", ButtonEventList::get_class_type());
 
@@ -1103,4 +1105,7 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) {
     // Transmit all buttons.
     output.set_data(_button_events_output, input.get_data(_button_events_input));
   }
+
+  // We always pass the pixel_size data through.
+  output.set_data(_pixel_size_output, input.get_data(_pixel_size_input));
 }

+ 2 - 0
panda/src/tform/mouseWatcher.h

@@ -193,11 +193,13 @@ protected:
 private:
   // inputs
   int _pixel_xy_input;
+  int _pixel_size_input;
   int _xy_input;
   int _button_events_input;
 
   // outputs
   int _pixel_xy_output;
+  int _pixel_size_output;
   int _xy_output;
   int _button_events_output;
 

+ 2 - 0
panda/src/tform/tform_composite1.cxx

@@ -2,5 +2,7 @@
 #include "config_tform.cxx"
 #include "driveInterface.cxx"
 #include "mouseInterfaceNode.cxx"
+#include "mouseSubregion.cxx"
+
 
 

+ 0 - 1
panda/src/tform/tform_composite2.cxx

@@ -1,4 +1,3 @@
-
 #include "mouseWatcher.cxx"
 #include "mouseWatcherGroup.cxx"
 #include "mouseWatcherParameter.cxx"