Panda3D
 All Classes Functions Variables Enumerations
clientDialDevice.I
1 // Filename: clientDialDevice.I
2 // Created by: drose (26Jan01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: ClientDialDevice::DialState::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE ClientDialDevice::DialState::
21 DialState() :
22  _offset(0.0),
23  _known(false)
24 {
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: ClientDialDevice::Constructor
29 // Access: Protected
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 INLINE ClientDialDevice::
33 ClientDialDevice(ClientBase *client, const string &device_name):
34  ClientDevice(client, get_class_type(), device_name)
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: ClientDialDevice::get_num_dials
40 // Access: Public
41 // Description: Returns the number of dial dials known to the
42 // ClientDialDevice. This number may change as
43 // more dials are discovered.
44 ////////////////////////////////////////////////////////////////////
45 INLINE int ClientDialDevice::
46 get_num_dials() const {
47  return _dials.size();
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: ClientDialDevice::push_dial
52 // Access: Public
53 // Description: Marks that the dial has been offset by the indicated
54 // amount. It is the user's responsibility to ensure
55 // that this call is protected within acquire().
56 ////////////////////////////////////////////////////////////////////
57 INLINE void ClientDialDevice::
58 push_dial(int index, double offset) {
59  ensure_dial_index(index);
60  nassertv(index >= 0 && index < (int)_dials.size());
61  _dials[index]._offset += offset;
62  _dials[index]._known = true;
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: ClientDialDevice::read_dial
67 // Access: Public
68 // Description: Returns the number of complete revolutions of the
69 // dial since the last time read_dial() was called.
70 // This is a destructive operation; it is not possible
71 // to read the dial without resetting the counter.
72 //
73 // It is the user's responsibility to ensure that this
74 // call is protected within acquire().
75 ////////////////////////////////////////////////////////////////////
76 INLINE double ClientDialDevice::
77 read_dial(int index) {
78  if (index >= 0 && index < (int)_dials.size()) {
79  double result = _dials[index]._offset;
80  _dials[index]._offset = 0.0;
81  return result;
82  } else {
83  return 0.0;
84  }
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: ClientDialDevice::is_dial_known
89 // Access: Public
90 // Description: Returns true if the state of the indicated dial
91 // dial is known, or false if we have never heard
92 // anything about this particular dial.
93 ////////////////////////////////////////////////////////////////////
94 INLINE bool ClientDialDevice::
95 is_dial_known(int index) const {
96  if (index >= 0 && index < (int)_dials.size()) {
97  return _dials[index]._known;
98  } else {
99  return false;
100  }
101 }
double read_dial(int index)
Returns the number of complete revolutions of the dial since the last time read_dial() was called...
void push_dial(int index, double offset)
Marks that the dial has been offset by the indicated amount.
bool is_dial_known(int index) const
Returns true if the state of the indicated dial dial is known, or false if we have never heard anythi...
An abstract base class for a family of client device interfaces–including trackers, buttons, dials, and other analog inputs.
Definition: clientBase.h:47
int get_num_dials() const
Returns the number of dial dials known to the ClientDialDevice.
Any of a number of different devices that might be attached to a ClientBase, including trackers...
Definition: clientDevice.h:35