Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
ButtonHandle Class Referencefinal

A ButtonHandle represents a single button from any device, including keyboard buttons and mouse buttons (but see KeyboardButton and MouseButton). More...

#include "buttonHandle.h"

Public Member Functions

 ButtonHandle (const std::string &name)
 Constructs a ButtonHandle with the corresponding name, which is looked up in the ButtonRegistry.
 
constexpr ButtonHandle (int index)
 Constructs a ButtonHandle with the corresponding index number, which may have been returned by an earlier call to ButtonHandle::get_index().
 
int compare_to (const ButtonHandle &other) const
 Sorts ButtonHandles arbitrarily (according to <, >, etc.).
 
ButtonHandle get_alias () const
 
char get_ascii_equivalent () const
 
size_t get_hash () const
 Returns a hash code suitable for phash_map.
 
constexpr int get_index () const
 
std::string get_name () const
 
bool has_ascii_equivalent () const
 
bool matches (const ButtonHandle &other) const
 Returns true if this ButtonHandle is the same as the other one, or if the other one is an alias for this one.
 
 operator bool () const
 ButtonHandle::none() evaluates to false, everything else evaluates to true.
 
bool operator!= (const ButtonHandle &other) const
 
bool operator< (const ButtonHandle &other) const
 
bool operator<= (const ButtonHandle &other) const
 
bool operator== (const ButtonHandle &other) const
 
bool operator> (const ButtonHandle &other) const
 
bool operator>= (const ButtonHandle &other) const
 
void output (std::ostream &out) const
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 
static constexpr ButtonHandle none ()
 

Public Attributes

 get_alias
 Returns the alias (alternate name) associated with the button, if any, or ButtonHandle::none() if the button has no alias.
 
 get_ascii_equivalent
 Returns the character code associated with the button, or '\0' if no ASCII code was associated.
 
 get_index
 Returns the integer index associated with this ButtonHandle.
 
 get_name
 Returns the name of the button.
 
 has_ascii_equivalent
 Returns true if the button was created with an ASCII equivalent code (e.g.
 

Friends

class ButtonRegistry
 

Detailed Description

A ButtonHandle represents a single button from any device, including keyboard buttons and mouse buttons (but see KeyboardButton and MouseButton).

Definition at line 26 of file buttonHandle.h.

Constructor & Destructor Documentation

◆ ButtonHandle() [1/2]

constexpr ButtonHandle::ButtonHandle ( int index)
constexpr

Constructs a ButtonHandle with the corresponding index number, which may have been returned by an earlier call to ButtonHandle::get_index().

Definition at line 18 of file buttonHandle.I.

◆ ButtonHandle() [2/2]

ButtonHandle::ButtonHandle ( const std::string & name)

Constructs a ButtonHandle with the corresponding name, which is looked up in the ButtonRegistry.

This exists for the purpose of being able to automatically coerce a string into a ButtonHandle; for most purposes, you should use either the static KeyboardButton/MouseButton getters or ButtonRegistry::register_button().

Definition at line 26 of file buttonHandle.cxx.

References ButtonRegistry::get_button(), and ButtonRegistry::ptr().

Member Function Documentation

◆ compare_to()

int ButtonHandle::compare_to ( const ButtonHandle & other) const
inline

Sorts ButtonHandles arbitrarily (according to <, >, etc.).

Returns a number less than 0 if this type sorts before the other one, greater than zero if it sorts after, 0 if they are equivalent.

Definition at line 75 of file buttonHandle.I.

◆ get_class_type()

static TypeHandle ButtonHandle::get_class_type ( )
inlinestatic

Definition at line 70 of file buttonHandle.h.

◆ get_hash()

size_t ButtonHandle::get_hash ( ) const
inline

Returns a hash code suitable for phash_map.

Definition at line 83 of file buttonHandle.I.

◆ init_type()

static void ButtonHandle::init_type ( )
inlinestatic

Definition at line 73 of file buttonHandle.h.

◆ matches()

bool ButtonHandle::matches ( const ButtonHandle & other) const
inline

Returns true if this ButtonHandle is the same as the other one, or if the other one is an alias for this one.

(Does not return true if this button is an alias for the other one, however.)

This is a more general comparison than operator ==.

Definition at line 113 of file buttonHandle.I.

References get_alias.

Referenced by ModifierButtons::button_down(), ModifierButtons::button_up(), ModifierButtons::has_button(), and ModifierButtons::is_down().

◆ none()

static constexpr ButtonHandle ButtonHandle::none ( )
inlinestaticconstexpr

Definition at line 56 of file buttonHandle.h.

◆ operator bool()

ButtonHandle::operator bool ( ) const
inline

ButtonHandle::none() evaluates to false, everything else evaluates to true.

Definition at line 143 of file buttonHandle.I.

◆ operator!=()

bool ButtonHandle::operator!= ( const ButtonHandle & other) const
inline

Definition at line 33 of file buttonHandle.I.

◆ operator<()

bool ButtonHandle::operator< ( const ButtonHandle & other) const
inline

Definition at line 41 of file buttonHandle.I.

◆ operator<=()

bool ButtonHandle::operator<= ( const ButtonHandle & other) const
inline

Definition at line 49 of file buttonHandle.I.

◆ operator==()

bool ButtonHandle::operator== ( const ButtonHandle & other) const
inline

Definition at line 25 of file buttonHandle.I.

◆ operator>()

bool ButtonHandle::operator> ( const ButtonHandle & other) const
inline

Definition at line 57 of file buttonHandle.I.

◆ operator>=()

bool ButtonHandle::operator>= ( const ButtonHandle & other) const
inline

Definition at line 65 of file buttonHandle.I.

◆ output()

void ButtonHandle::output ( std::ostream & out) const
inline

Definition at line 135 of file buttonHandle.I.

Friends And Related Symbol Documentation

◆ ButtonRegistry

friend class ButtonRegistry
friend

Definition at line 80 of file buttonHandle.h.

Member Data Documentation

◆ get_alias

ButtonHandle ButtonHandle::get_alias

Returns the alias (alternate name) associated with the button, if any, or ButtonHandle::none() if the button has no alias.

Each button is allowed to have one alias, and multiple different buttons can refer to the same alias. The alias should be the more general name for the button, for instance, shift is an alias for lshift, but not vice-versa.

Definition at line 64 of file buttonHandle.h.

Referenced by matches().

◆ get_ascii_equivalent

char ButtonHandle::get_ascii_equivalent
inline

Returns the character code associated with the button, or '\0' if no ASCII code was associated.

Definition at line 63 of file buttonHandle.h.

◆ get_index

constexpr int ButtonHandle::get_index
constexpr

Returns the integer index associated with this ButtonHandle.

Each different ButtonHandle will have a different index. However, you probably shouldn't be using this method; you should just treat the ButtonHandles as opaque classes. This is provided for the convenience of non-C++ scripting languages to build a hashtable of ButtonHandles.

Definition at line 60 of file buttonHandle.h.

Referenced by ButtonMap::get_mapped_button(), ButtonMap::get_mapped_button_label(), RocketInputHandler::get_rocket_key(), MouseWatcher::is_button_down(), and ButtonMap::map_button().

◆ get_name

std::string ButtonHandle::get_name

◆ has_ascii_equivalent

bool ButtonHandle::has_ascii_equivalent
inline

Returns true if the button was created with an ASCII equivalent code (e.g.

for a standard keyboard button).

Definition at line 63 of file buttonHandle.h.


The documentation for this class was generated from the following files: