Panda3D
pgButton.h
1 // Filename: pgButton.h
2 // Created by: drose (13Mar02)
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 #ifndef PGBUTTON_H
16 #define PGBUTTON_H
17 
18 #include "pandabase.h"
19 
20 #include "pgItem.h"
21 #include "pgButtonNotify.h"
22 #include "nodePath.h"
23 #include "pset.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : PGButton
27 // Description : This is a particular kind of PGItem that is
28 // specialized to behave like a normal button object.
29 // It keeps track of its own state, and handles mouse
30 // events sensibly.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_PANDA_PGUI PGButton : public PGItem {
33 PUBLISHED:
34  PGButton(const string &name);
35  virtual ~PGButton();
36 
37 protected:
38  PGButton(const PGButton &copy);
39 
40 public:
41  virtual PandaNode *make_copy() const;
42 
43  virtual void enter_region(const MouseWatcherParameter &param);
44  virtual void exit_region(const MouseWatcherParameter &param);
45  virtual void press(const MouseWatcherParameter &param, bool background);
46  virtual void release(const MouseWatcherParameter &param, bool background);
47 
48  virtual void click(const MouseWatcherParameter &param);
49 
50  INLINE void set_notify(PGButtonNotify *notify);
51  INLINE PGButtonNotify *get_notify() const;
52 
53 PUBLISHED:
54  enum State {
55  S_ready = 0,
56  S_depressed,
57  S_rollover,
58  S_inactive
59  };
60 
61  void setup(const string &label, PN_stdfloat bevel = 0.1f);
62  INLINE void setup(const NodePath &ready);
63  INLINE void setup(const NodePath &ready, const NodePath &depressed);
64  INLINE void setup(const NodePath &ready, const NodePath &depressed,
65  const NodePath &rollover);
66  void setup(const NodePath &ready, const NodePath &depressed,
67  const NodePath &rollover, const NodePath &inactive);
68 
69  virtual void set_active(bool active);
70 
71  bool add_click_button(const ButtonHandle &button);
72  bool remove_click_button(const ButtonHandle &button);
73  bool has_click_button(const ButtonHandle &button);
74 
75  INLINE bool is_button_down();
76 
77  INLINE static string get_click_prefix();
78  INLINE string get_click_event(const ButtonHandle &button) const;
79 
80 private:
82  Buttons _click_buttons;
83 
84  bool _button_down;
85 
86 public:
87  static TypeHandle get_class_type() {
88  return _type_handle;
89  }
90  static void init_type() {
91  PGItem::init_type();
92  register_type(_type_handle, "PGButton",
93  PGItem::get_class_type());
94  }
95  virtual TypeHandle get_type() const {
96  return get_class_type();
97  }
98  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
99 
100 private:
101  static TypeHandle _type_handle;
102 
103 };
104 
105 #include "pgButton.I"
106 
107 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is the base class for all the various kinds of gui widget objects.
Definition: pgItem.h:58
This is a particular kind of PGItem that is specialized to behave like a normal button object...
Definition: pgButton.h:32
virtual void enter_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse enters the region.
Definition: pgItem.cxx:541
Objects that inherit from this class can receive notify messages when a slider bar moves or otherwise...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
PGItemNotify * get_notify() const
Returns the object which will be notified when the PGItem changes, if any.
Definition: pgItem.I:85
virtual void release(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever a mouse or keyboard button previously depressed wit...
Definition: pgItem.cxx:726
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
virtual void exit_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse exits the region.
Definition: pgItem.cxx:568
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition: pgItem.cxx:890
virtual void press(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever a mouse or keyboard button is depressed while the m...
Definition: pgItem.cxx:694
void set_notify(PGItemNotify *notify)
Sets the object which will be notified when the PGItem changes.
Definition: pgItem.I:54