Panda3D
pgButton.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pgButton.h
10  * @author drose
11  * @date 2002-03-13
12  */
13 
14 #ifndef PGBUTTON_H
15 #define PGBUTTON_H
16 
17 #include "pandabase.h"
18 
19 #include "pgItem.h"
20 #include "pgButtonNotify.h"
21 #include "nodePath.h"
22 #include "pset.h"
23 
24 /**
25  * This is a particular kind of PGItem that is specialized to behave like a
26  * normal button object. It keeps track of its own state, and handles mouse
27  * events sensibly.
28  */
29 class EXPCL_PANDA_PGUI PGButton : public PGItem {
30 PUBLISHED:
31  explicit PGButton(const std::string &name);
32  virtual ~PGButton();
33 
34 protected:
35  PGButton(const PGButton &copy);
36 
37 public:
38  virtual PandaNode *make_copy() const;
39 
40  virtual void enter_region(const MouseWatcherParameter &param);
41  virtual void exit_region(const MouseWatcherParameter &param);
42  virtual void press(const MouseWatcherParameter &param, bool background);
43  virtual void release(const MouseWatcherParameter &param, bool background);
44 
45  virtual void click(const MouseWatcherParameter &param);
46 
47  INLINE void set_notify(PGButtonNotify *notify);
48  INLINE PGButtonNotify *get_notify() const;
49 
50 PUBLISHED:
51  enum State {
52  S_ready = 0,
53  S_depressed,
54  S_rollover,
55  S_inactive
56  };
57 
58  void setup(const std::string &label, PN_stdfloat bevel = 0.1f);
59  INLINE void setup(const NodePath &ready);
60  INLINE void setup(const NodePath &ready, const NodePath &depressed);
61  INLINE void setup(const NodePath &ready, const NodePath &depressed,
62  const NodePath &rollover);
63  void setup(const NodePath &ready, const NodePath &depressed,
64  const NodePath &rollover, const NodePath &inactive);
65 
66  virtual void set_active(bool active);
67 
68  bool add_click_button(const ButtonHandle &button);
69  bool remove_click_button(const ButtonHandle &button);
70  bool has_click_button(const ButtonHandle &button);
71 
72  INLINE bool is_button_down();
73 
74  INLINE static std::string get_click_prefix();
75  INLINE std::string get_click_event(const ButtonHandle &button) const;
76  MAKE_PROPERTY(click_prefix, get_click_prefix);
77 
78 private:
80  Buttons _click_buttons;
81 
82  bool _button_down;
83 
84 public:
85  static TypeHandle get_class_type() {
86  return _type_handle;
87  }
88  static void init_type() {
89  PGItem::init_type();
90  register_type(_type_handle, "PGButton",
91  PGItem::get_class_type());
92  }
93  virtual TypeHandle get_type() const {
94  return get_class_type();
95  }
96  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
97 
98 private:
99  static TypeHandle _type_handle;
100 
101 };
102 
103 #include "pgButton.I"
104 
105 #endif
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
Objects that inherit from this class can receive notify messages when a slider bar moves or otherwise...
This is a particular kind of PGItem that is specialized to behave like a normal button object.
Definition: pgButton.h:29
This is the base class for all the various kinds of gui widget objects.
Definition: pgItem.h:53
void set_notify(PGItemNotify *notify)
Sets the object which will be notified when the PGItem changes.
Definition: pgItem.I:43
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:674
PGItemNotify * get_notify() const
Returns the object which will be notified when the PGItem changes, if any.
Definition: pgItem.I:69
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:703
virtual void exit_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse exits the region.
Definition: pgItem.cxx:562
virtual void enter_region(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the mouse enters the region.
Definition: pgItem.cxx:538
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition: pgItem.cxx:837
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22