Skip to content

Commit 2917027

Browse files
committed
device: a few InputDevice API tweaks
find_button() and find_axis() should not error since there is no way to find out whether a button/axis exists or not
1 parent 2087d8e commit 2917027

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

panda/src/device/inputDevice.I

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,8 @@ is_button_known(size_t index) const {
250250
*/
251251
INLINE InputDevice::ButtonState InputDevice::
252252
get_button(size_t index) const {
253-
if (index < _buttons.size()) {
254-
return _buttons[index];
255-
} else {
256-
device_cat.error()
257-
<< "Index " << index << " was not found in the axes list\n";
258-
return ButtonState();
259-
}
253+
nassertr_always(index < _buttons.size(), ButtonState());
254+
return _buttons[index];
260255
}
261256

262257
/**
@@ -270,8 +265,6 @@ find_button(ButtonHandle handle) const {
270265
return _buttons[i];
271266
}
272267
}
273-
device_cat.error()
274-
<< "Handle " << handle.get_name() << " was not found in the axes list\n";
275268
return ButtonState();
276269
}
277270

@@ -321,13 +314,8 @@ get_axis_value(size_t index) const {
321314
*/
322315
INLINE InputDevice::AxisState InputDevice::
323316
get_axis(size_t index) const {
324-
if (index < _axes.size()) {
325-
return _axes[index];
326-
} else {
327-
device_cat.error()
328-
<< "Index " << index << " was not found in the axes list\n";
329-
return AxisState();
330-
}
317+
nassertr_always(index < _axes.size(), AxisState());
318+
return _axes[index];
331319
}
332320

333321
/**
@@ -341,8 +329,6 @@ find_axis(InputDevice::Axis axis) const {
341329
return _axes[i];
342330
}
343331
}
344-
device_cat.error()
345-
<< "Axis " << axis << " was not found in the axes list\n";
346332
return AxisState();
347333
}
348334

panda/src/device/inputDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class EXPCL_PANDA_DEVICE InputDevice : public TypedReferenceCount {
142142
ALWAYS_INLINE bool is_pressed() const;
143143

144144
PUBLISHED:
145+
operator bool() { return _state != S_unknown; }
146+
145147
MAKE_PROPERTY(known, is_known);
146148
MAKE_PROPERTY(pressed, is_pressed);
147149

@@ -156,6 +158,8 @@ class EXPCL_PANDA_DEVICE InputDevice : public TypedReferenceCount {
156158
constexpr AxisState() = default;
157159

158160
PUBLISHED:
161+
operator bool() { return known && value != 0.0; }
162+
159163
Axis axis = Axis::none;
160164
double value = 0.0;
161165
bool known = false;
@@ -268,6 +272,8 @@ class EXPCL_PANDA_DEVICE InputDevice : public TypedReferenceCount {
268272
PT(PointerEventList) get_pointer_events();
269273

270274
virtual void output(std::ostream &out) const;
275+
276+
public:
271277
static std::string format_device_class(DeviceClass dc);
272278
static std::string format_axis(Axis axis);
273279

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy