00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PGITEM_H
00020 #define PGITEM_H
00021
00022 #include "pandabase.h"
00023
00024 #include "pgMouseWatcherRegion.h"
00025 #include "pgFrameStyle.h"
00026
00027 #include "pandaNode.h"
00028 #include "nodePath.h"
00029 #include "luse.h"
00030 #include "pointerTo.h"
00031 #include "textNode.h"
00032
00033 #include "pmap.h"
00034
00035 class PGTop;
00036 class MouseWatcherParameter;
00037 class AudioSound;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class EXPCL_PANDA PGItem : public PandaNode {
00054 PUBLISHED:
00055 PGItem(const string &name);
00056 virtual ~PGItem();
00057
00058 protected:
00059 PGItem(const PGItem ©);
00060
00061 virtual PandaNode *make_copy() const;
00062 virtual void xform(const LMatrix4f &mat);
00063 virtual bool has_cull_callback() const;
00064 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00065
00066 virtual BoundingVolume *recompute_internal_bound();
00067
00068 public:
00069 void activate_region(const LMatrix4f &transform, int sort);
00070 INLINE PGMouseWatcherRegion *get_region() const;
00071
00072 virtual void enter(const MouseWatcherParameter ¶m);
00073 virtual void exit(const MouseWatcherParameter ¶m);
00074 virtual void within(const MouseWatcherParameter ¶m);
00075 virtual void without(const MouseWatcherParameter ¶m);
00076 virtual void focus_in();
00077 virtual void focus_out();
00078 virtual void press(const MouseWatcherParameter ¶m, bool background);
00079 virtual void release(const MouseWatcherParameter ¶m, bool background);
00080 virtual void keystroke(const MouseWatcherParameter ¶m, bool background);
00081
00082 static void background_press(const MouseWatcherParameter ¶m);
00083 static void background_release(const MouseWatcherParameter ¶m);
00084 static void background_keystroke(const MouseWatcherParameter ¶m);
00085
00086 PUBLISHED:
00087 INLINE void set_frame(float left, float right, float bottom, float top);
00088 INLINE void set_frame(const LVecBase4f &frame);
00089 INLINE const LVecBase4f &get_frame() const;
00090 INLINE bool has_frame() const;
00091 INLINE void clear_frame();
00092
00093 INLINE void set_state(int state);
00094 INLINE int get_state() const;
00095
00096 virtual void set_active(bool active);
00097 INLINE bool get_active() const;
00098
00099 virtual void set_focus(bool focus);
00100 INLINE bool get_focus() const;
00101
00102 void set_background_focus(bool focus);
00103 INLINE bool get_background_focus() const;
00104
00105 INLINE void set_suppress_flags(int suppress_flags);
00106 INLINE int get_suppress_flags() const;
00107
00108 int get_num_state_defs() const;
00109 void clear_state_def(int state);
00110 bool has_state_def(int state) const;
00111 NodePath &get_state_def(int state);
00112 NodePath instance_to_state_def(int state, const NodePath &path);
00113
00114 PGFrameStyle get_frame_style(int state);
00115 void set_frame_style(int state, const PGFrameStyle &style);
00116
00117 INLINE const string &get_id() const;
00118 INLINE void set_id(const string &id);
00119
00120 INLINE static string get_enter_prefix();
00121 INLINE static string get_exit_prefix();
00122 INLINE static string get_within_prefix();
00123 INLINE static string get_without_prefix();
00124 INLINE static string get_focus_in_prefix();
00125 INLINE static string get_focus_out_prefix();
00126 INLINE static string get_press_prefix();
00127 INLINE static string get_release_prefix();
00128 INLINE static string get_keystroke_prefix();
00129
00130 INLINE string get_enter_event() const;
00131 INLINE string get_exit_event() const;
00132 INLINE string get_within_event() const;
00133 INLINE string get_without_event() const;
00134 INLINE string get_focus_in_event() const;
00135 INLINE string get_focus_out_event() const;
00136 INLINE string get_press_event(const ButtonHandle &button) const;
00137 INLINE string get_release_event(const ButtonHandle &button) const;
00138 INLINE string get_keystroke_event() const;
00139
00140 #ifdef HAVE_AUDIO
00141 void set_sound(const string &event, AudioSound *sound);
00142 void clear_sound(const string &event);
00143 AudioSound *get_sound(const string &event) const;
00144 bool has_sound(const string &event) const;
00145 #endif
00146
00147 static TextNode *get_text_node();
00148 INLINE static void set_text_node(TextNode *node);
00149
00150 INLINE static PGItem *get_focus_item();
00151
00152 protected:
00153 void play_sound(const string &event);
00154
00155 private:
00156 void slot_state_def(int state);
00157 void update_frame(int state);
00158 void mark_frames_stale();
00159
00160 bool _has_frame;
00161 LVecBase4f _frame;
00162 int _state;
00163 enum Flags {
00164 F_active = 0x01,
00165 F_focus = 0x02,
00166 F_background_focus = 0x04,
00167 };
00168 int _flags;
00169
00170 PT(PGMouseWatcherRegion) _region;
00171
00172 class StateDef {
00173 public:
00174 NodePath _root;
00175 PGFrameStyle _frame_style;
00176 NodePath _frame;
00177 bool _frame_stale;
00178 };
00179 typedef pvector<StateDef> StateDefs;
00180 StateDefs _state_defs;
00181
00182 #ifdef HAVE_AUDIO
00183 typedef pmap<string, PT(AudioSound) > Sounds;
00184 Sounds _sounds;
00185 #endif
00186
00187 static PT(TextNode) _text_node;
00188 static PGItem *_focus_item;
00189
00190 typedef pset<PGItem *> BackgroundFocus;
00191 static BackgroundFocus _background_focus;
00192
00193 public:
00194 static TypeHandle get_class_type() {
00195 return _type_handle;
00196 }
00197 static void init_type() {
00198 PandaNode::init_type();
00199 register_type(_type_handle, "PGItem",
00200 PandaNode::get_class_type());
00201 }
00202 virtual TypeHandle get_type() const {
00203 return get_class_type();
00204 }
00205 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00206
00207 private:
00208 static TypeHandle _type_handle;
00209 };
00210
00211 #include "pgItem.I"
00212
00213 #endif