Panda3D
|
This is a particular kind of PGItem that is specialized to behave like a normal button object. More...
#include "pgButton.h"
Public Types | |
enum | State { S_ready = 0, S_depressed, S_rollover, S_inactive } |
Public Member Functions | |
PGButton (const string &name) | |
bool | add_click_button (const ButtonHandle &button) |
Adds the indicated button to the set of buttons that can effectively "click" the PGButton. | |
virtual void | click (const MouseWatcherParameter ¶m) |
This is a callback hook function, called whenever the button is clicked down-and-up by the user normally. | |
virtual void | enter_region (const MouseWatcherParameter ¶m) |
This is a callback hook function, called whenever the mouse enters the region. | |
virtual void | exit_region (const MouseWatcherParameter ¶m) |
This is a callback hook function, called whenever the mouse exits the region. | |
virtual TypeHandle | force_init_type () |
string | get_click_event (const ButtonHandle &button) const |
Returns the event name that will be thrown when the button is clicked normally. | |
PGButtonNotify * | get_notify () const |
Returns the object which will be notified when the PGButton changes, if any. | |
virtual TypeHandle | get_type () const |
bool | has_click_button (const ButtonHandle &button) |
Returns true if the indicated button is on the set of buttons that can effectively "click" the PGButton. | |
bool | is_button_down () |
Returns true if the user is currently holding the mouse button down on the button, false otherwise. | |
virtual PandaNode * | make_copy () const |
Returns a newly-allocated Node that is a shallow copy of this one. | |
virtual void | press (const MouseWatcherParameter ¶m, bool background) |
This is a callback hook function, called whenever a mouse or keyboard button is depressed while the mouse is within the region. | |
virtual void | release (const MouseWatcherParameter ¶m, bool background) |
This is a callback hook function, called whenever a mouse or keyboard button previously depressed with press() is released. | |
bool | remove_click_button (const ButtonHandle &button) |
Removes the indicated button from the set of buttons that can effectively "click" the PGButton. | |
virtual void | set_active (bool active) |
Toggles the active/inactive state of the button. | |
void | set_notify (PGButtonNotify *notify) |
Sets the object which will be notified when the PGButton changes. | |
void | setup (const NodePath &ready) |
Sets up the button using the indicated NodePath as arbitrary geometry. | |
void | setup (const NodePath &ready, const NodePath &depressed, const NodePath &rollover, const NodePath &inactive) |
Sets up the button using the indicated NodePath as arbitrary geometry. | |
void | setup (const string &label, PN_stdfloat bevel=0.1f) |
Sets up the button as a default text button using the indicated label string. | |
void | setup (const NodePath &ready, const NodePath &depressed, const NodePath &rollover) |
Sets up the button using the indicated NodePath as arbitrary geometry. | |
void | setup (const NodePath &ready, const NodePath &depressed) |
Sets up the button using the indicated NodePath as arbitrary geometry. | |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static string | get_click_prefix () |
Returns the prefix that is used to define the click event for all PGButtons. | |
static void | init_type () |
Protected Member Functions | |
PGButton (const PGButton ©) |
This is a particular kind of PGItem that is specialized to behave like a normal button object.
It keeps track of its own state, and handles mouse events sensibly.
Definition at line 32 of file pgButton.h.
bool PGButton::add_click_button | ( | const ButtonHandle & | button | ) |
Adds the indicated button to the set of buttons that can effectively "click" the PGButton.
Normally, this is just MouseButton::one(). Returns true if the button was added, or false if it was already there.
Definition at line 279 of file pgButton.cxx.
void PGButton::click | ( | const MouseWatcherParameter & | param | ) | [virtual] |
This is a callback hook function, called whenever the button is clicked down-and-up by the user normally.
Definition at line 156 of file pgButton.cxx.
References PGButtonNotify::button_click(), MouseWatcherParameter::get_button(), get_click_event(), get_notify(), PGItem::has_notify(), and PGItem::play_sound().
Referenced by release().
void PGButton::enter_region | ( | const MouseWatcherParameter & | param | ) | [virtual] |
This is a callback hook function, called whenever the mouse enters the region.
Reimplemented from PGItem.
Definition at line 83 of file pgButton.cxx.
References PGItem::get_active(), and PGItem::set_state().
void PGButton::exit_region | ( | const MouseWatcherParameter & | param | ) | [virtual] |
This is a callback hook function, called whenever the mouse exits the region.
Reimplemented from PGItem.
Definition at line 98 of file pgButton.cxx.
References PGItem::get_active(), and PGItem::set_state().
string PGButton::get_click_event | ( | const ButtonHandle & | button | ) | const [inline] |
Returns the event name that will be thrown when the button is clicked normally.
Definition at line 95 of file pgButton.I.
References get_click_prefix(), PGItem::get_id(), and ButtonHandle::get_name().
Referenced by click().
string PGButton::get_click_prefix | ( | ) | [inline, static] |
Returns the prefix that is used to define the click event for all PGButtons.
The click event is the concatenation of this string followed by get_id().
Definition at line 84 of file pgButton.I.
Referenced by get_click_event().
PGButtonNotify * PGButton::get_notify | ( | ) | const [inline] |
Returns the object which will be notified when the PGButton changes, if any.
Returns NULL if there is no such object configured.
Reimplemented from PGItem.
Definition at line 38 of file pgButton.I.
Referenced by click().
bool PGButton::has_click_button | ( | const ButtonHandle & | button | ) |
Returns true if the indicated button is on the set of buttons that can effectively "click" the PGButton.
Normally, this is just MouseButton::one().
Definition at line 307 of file pgButton.cxx.
bool PGButton::is_button_down | ( | ) | [inline] |
Returns true if the user is currently holding the mouse button down on the button, false otherwise.
Definition at line 107 of file pgButton.I.
PandaNode * PGButton::make_copy | ( | ) | const [virtual] |
void PGButton::press | ( | const MouseWatcherParameter & | param, |
bool | background | ||
) | [virtual] |
This is a callback hook function, called whenever a mouse or keyboard button is depressed while the mouse is within the region.
Reimplemented from PGItem.
Definition at line 114 of file pgButton.cxx.
References PGItem::get_active(), MouseWatcherParameter::get_button(), has_click_button(), and PGItem::set_state().
void PGButton::release | ( | const MouseWatcherParameter & | param, |
bool | background | ||
) | [virtual] |
This is a callback hook function, called whenever a mouse or keyboard button previously depressed with press() is released.
Reimplemented from PGItem.
Definition at line 133 of file pgButton.cxx.
References click(), PGItem::get_active(), MouseWatcherParameter::get_button(), has_click_button(), MouseWatcherParameter::is_outside(), and PGItem::set_state().
bool PGButton::remove_click_button | ( | const ButtonHandle & | button | ) |
Removes the indicated button from the set of buttons that can effectively "click" the PGButton.
Normally, this is just MouseButton::one(). Returns true if the button was removed, or false if it was not in the set.
Definition at line 294 of file pgButton.cxx.
void PGButton::set_active | ( | bool | active | ) | [virtual] |
Toggles the active/inactive state of the button.
In the case of a PGButton, this also changes its visual appearance.
Reimplemented from PGItem.
Definition at line 262 of file pgButton.cxx.
References PGItem::get_active(), and PGItem::set_state().
void PGButton::set_notify | ( | PGButtonNotify * | notify | ) | [inline] |
Sets the object which will be notified when the PGButton changes.
Set this to NULL to disable this effect. The PGButton does not retain ownership of the pointer; it is your responsibility to ensure that the notify object does not destruct.
Definition at line 26 of file pgButton.I.
Referenced by PGSliderBar::set_left_button(), PGSliderBar::set_right_button(), and PGSliderBar::set_thumb_button().
void PGButton::setup | ( | const NodePath & | ready, |
const NodePath & | depressed, | ||
const NodePath & | rollover, | ||
const NodePath & | inactive | ||
) |
Sets up the button using the indicated NodePath as arbitrary geometry.
Definition at line 234 of file pgButton.cxx.
References NodePath::calc_tight_bounds(), PGItem::clear_state_def(), PGItem::instance_to_state_def(), and PGItem::set_frame().
Sets up the button using the indicated NodePath as arbitrary geometry.
Definition at line 60 of file pgButton.I.
References setup().
void PGButton::setup | ( | const NodePath & | ready, |
const NodePath & | depressed, | ||
const NodePath & | rollover | ||
) | [inline] |
Sets up the button using the indicated NodePath as arbitrary geometry.
Definition at line 71 of file pgButton.I.
References setup().
void PGButton::setup | ( | const NodePath & | ready | ) | [inline] |
Sets up the button using the indicated NodePath as arbitrary geometry.
Definition at line 49 of file pgButton.I.
References setup().
void PGButton::setup | ( | const string & | label, |
PN_stdfloat | bevel = 0.1f |
||
) |
Sets up the button as a default text button using the indicated label string.
The TextNode defined by PGItem::get_text_node() will be used to create the label geometry. This automatically sets up the frame according to the size of the text.
Definition at line 178 of file pgButton.cxx.
References NodePath::attach_new_node(), PGItem::clear_state_def(), TextNode::get_card_actual(), PGItem::get_state_def(), PGItem::get_text_node(), PGFrameStyle::set_color(), PGItem::set_frame(), PGItem::set_frame_style(), TextNode::set_text(), PGFrameStyle::set_type(), and PGFrameStyle::set_width().
Referenced by setup().