Panda3D

pgButton.h

00001 // Filename: pgButton.h
00002 // Created by:  drose (13Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PGBUTTON_H
00016 #define PGBUTTON_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "pgItem.h"
00021 #include "pgButtonNotify.h"
00022 #include "nodePath.h"
00023 #include "pset.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : PGButton
00027 // Description : This is a particular kind of PGItem that is
00028 //               specialized to behave like a normal button object.
00029 //               It keeps track of its own state, and handles mouse
00030 //               events sensibly.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_PANDA_PGUI PGButton : public PGItem {
00033 PUBLISHED:
00034   PGButton(const string &name);
00035   virtual ~PGButton();
00036 
00037 protected:
00038   PGButton(const PGButton &copy);
00039 
00040 public:
00041   virtual PandaNode *make_copy() const;
00042 
00043   virtual void enter_region(const MouseWatcherParameter &param);
00044   virtual void exit_region(const MouseWatcherParameter &param);
00045   virtual void press(const MouseWatcherParameter &param, bool background);
00046   virtual void release(const MouseWatcherParameter &param, bool background);
00047 
00048   virtual void click(const MouseWatcherParameter &param);
00049 
00050   INLINE void set_notify(PGButtonNotify *notify);
00051   INLINE PGButtonNotify *get_notify() const;
00052 
00053 PUBLISHED:
00054   enum State {
00055     S_ready = 0,
00056     S_depressed,
00057     S_rollover,
00058     S_inactive
00059   };
00060 
00061   void setup(const string &label, PN_stdfloat bevel = 0.1f);
00062   INLINE void setup(const NodePath &ready);
00063   INLINE void setup(const NodePath &ready, const NodePath &depressed);
00064   INLINE void setup(const NodePath &ready, const NodePath &depressed, 
00065                     const NodePath &rollover);
00066   void setup(const NodePath &ready, const NodePath &depressed,
00067              const NodePath &rollover, const NodePath &inactive);
00068 
00069   virtual void set_active(bool active);
00070 
00071   bool add_click_button(const ButtonHandle &button);
00072   bool remove_click_button(const ButtonHandle &button);
00073   bool has_click_button(const ButtonHandle &button);
00074 
00075   INLINE bool is_button_down();
00076 
00077   INLINE static string get_click_prefix();
00078   INLINE string get_click_event(const ButtonHandle &button) const;
00079 
00080 private:
00081   typedef pset<ButtonHandle> Buttons;
00082   Buttons _click_buttons;
00083 
00084   bool _button_down;
00085 
00086 public:
00087   static TypeHandle get_class_type() {
00088     return _type_handle;
00089   }
00090   static void init_type() {
00091     PGItem::init_type();
00092     register_type(_type_handle, "PGButton",
00093                   PGItem::get_class_type());
00094   }
00095   virtual TypeHandle get_type() const {
00096     return get_class_type();
00097   }
00098   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00099 
00100 private:
00101   static TypeHandle _type_handle;
00102 
00103 };
00104 
00105 #include "pgButton.I"
00106 
00107 #endif
 All Classes Functions Variables Enumerations