further pgui enhancements

This commit is contained in:
David Rose 2001-07-05 20:19:08 +00:00
parent 2ba3c5fe05
commit 0cba400ac0
17 changed files with 301 additions and 42 deletions

View File

@ -12,6 +12,7 @@
#define SOURCES \
config_pgui.h \
pgButton.I pgButton.h \
pgButtonEvent.I pgButtonEvent.h \
pgFrameStyle.I pgFrameStyle.h \
pgItem.I pgItem.h \
pgMouseWatcherRegion.I pgMouseWatcherRegion.h \
@ -21,6 +22,7 @@
#define SOURCES $[SOURCES] \
config_pgui.cxx \
pgButton.cxx \
pgButtonEvent.cxx \
pgFrameStyle.cxx \
pgItem.cxx \
pgMouseWatcherRegion.cxx \
@ -28,6 +30,7 @@
#define INSTALL_HEADERS \
pgButton.I pgButton.h \
pgButtonEvent.I pgButtonEvent.h \
pgFrameStyle.I pgFrameStyle.h \
pgItem.I pgItem.h \
pgMouseWatcherRegion.I pgMouseWatcherRegion.h \

View File

@ -18,6 +18,7 @@
#include "config_pgui.h"
#include "pgButton.h"
#include "pgButtonEvent.h"
#include "pgItem.h"
#include "pgMouseWatcherRegion.h"
#include "pgTop.h"
@ -29,6 +30,7 @@ NotifyCategoryDef(pgui, "");
ConfigureFn(config_pgui) {
PGButton::init_type();
PGButtonEvent::init_type();
PGItem::init_type();
PGMouseWatcherRegion::init_type();
PGTop::init_type();

View File

@ -20,6 +20,8 @@
#include "throw_event.h"
#include "renderRelation.h"
#include "colorTransition.h"
#include "transformTransition.h"
#include "mouseButton.h"
TypeHandle PGButton::_type_handle;
@ -114,12 +116,16 @@ exit() {
// is within the region.
////////////////////////////////////////////////////////////////////
void PGButton::
button_down(ButtonHandle button) {
button_down(ButtonHandle button, float x, float y) {
if (button == MouseButton::one() ||
button == MouseButton::two() ||
button == MouseButton::three()) {
if (get_active()) {
_button_down = true;
set_state(S_depressed);
}
PGItem::button_down(button);
}
PGItem::button_down(button, x, y);
}
////////////////////////////////////////////////////////////////////
@ -133,7 +139,10 @@ button_down(ButtonHandle button) {
// outside the region.
////////////////////////////////////////////////////////////////////
void PGButton::
button_up(ButtonHandle button, bool is_within) {
button_up(ButtonHandle button, float x, float y, bool is_within) {
if (button == MouseButton::one() ||
button == MouseButton::two() ||
button == MouseButton::three()) {
_button_down = false;
if (get_active()) {
if (is_within) {
@ -143,7 +152,8 @@ button_up(ButtonHandle button, bool is_within) {
set_state(S_ready);
}
}
PGItem::button_up(button, is_within);
}
PGItem::button_up(button, x, y, is_within);
}
////////////////////////////////////////////////////////////////////
@ -168,6 +178,11 @@ click() {
////////////////////////////////////////////////////////////////////
void PGButton::
setup(const string &label) {
clear_state_def(S_ready);
clear_state_def(S_depressed);
clear_state_def(S_rollover);
clear_state_def(S_inactive);
TextNode *text_node = get_text_node();
text_node->set_text(label);
PT_Node geom = text_node->generate();
@ -176,7 +191,7 @@ setup(const string &label) {
set_frame(frame[0] - 0.4, frame[1] + 0.4, frame[2] - 0.15, frame[3] + 0.15);
new RenderRelation(get_state_def(S_ready), geom);
new RenderRelation(get_state_def(S_depressed), geom);
NodeRelation *down = new RenderRelation(get_state_def(S_depressed), geom);
new RenderRelation(get_state_def(S_rollover), geom);
NodeRelation *inact = new RenderRelation(get_state_def(S_inactive), geom);
@ -197,8 +212,10 @@ setup(const string &label) {
style.set_type(PGFrameStyle::T_bevel_in);
style.set_color(0.8, 0.8, 0.8, 1.0);
style.set_width(0.05, 0.05);
set_frame_style(S_depressed, style);
LMatrix4f translate = LMatrix4f::translate_mat(0.05, 0.0, -0.05);
TransformTransition *ttrans = new TransformTransition(translate);
down->set_transition(ttrans);
}
////////////////////////////////////////////////////////////////////
@ -210,6 +227,11 @@ setup(const string &label) {
void PGButton::
setup(const ArcChain &ready, const ArcChain &depressed,
const ArcChain &rollover, const ArcChain &inactive) {
clear_state_def(S_ready);
clear_state_def(S_depressed);
clear_state_def(S_rollover);
clear_state_def(S_inactive);
instance_to_state_def(S_ready, ready);
instance_to_state_def(S_depressed, depressed);
instance_to_state_def(S_rollover, rollover);

View File

@ -44,8 +44,8 @@ public:
virtual void enter();
virtual void exit();
virtual void button_down(ButtonHandle button);
virtual void button_up(ButtonHandle button, bool is_within);
virtual void button_down(ButtonHandle button, float x, float y);
virtual void button_up(ButtonHandle button, float x, float y, bool is_within);
virtual void click();

View File

@ -0,0 +1,94 @@
// Filename: pgButtonEvent.I
// Created by: drose (05Jul01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE PGButtonEvent::
PGButtonEvent() {
}
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE PGButtonEvent::
PGButtonEvent(ButtonHandle button, float mouse_x, float mouse_y) :
_button(button),
_mouse_x(mouse_x),
_mouse_y(mouse_y)
{
}
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::get_button
// Access: Published
// Description: Returns the ButtonHandle of the button involved with
// this event.
////////////////////////////////////////////////////////////////////
INLINE ButtonHandle PGButtonEvent::
get_button() const {
return _button;
}
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::get_button_name
// Access: Published
// Description: Returns the name of the button involved with this
// event. This is just a shorthand way to get to the
// name, since get_button().get_name() will return the
// same thing.
////////////////////////////////////////////////////////////////////
INLINE string PGButtonEvent::
get_button_name() const {
return _button.get_name();
}
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::get_mouse_x
// Access: Published
// Description: Returns the X position of the mouse within the window
// at the time the button event occurred. This is in
// the normalized range [-1 .. 1].
////////////////////////////////////////////////////////////////////
INLINE float PGButtonEvent::
get_mouse_x() const {
return _mouse_x;
}
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::get_mouse_y
// Access: Published
// Description: Returns the Y position of the mouse within the window
// at the time the button event occurred. This is in
// the normalized range [-1 .. 1].
////////////////////////////////////////////////////////////////////
INLINE float PGButtonEvent::
get_mouse_y() const {
return _mouse_y;
}
INLINE ostream &
operator << (ostream &out, const PGButtonEvent &event) {
event.output(out);
return out;
}

View File

@ -0,0 +1,40 @@
// Filename: pgButtonEvent.cxx
// Created by: drose (05Jul01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "pgButtonEvent.h"
TypeHandle PGButtonEvent::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
PGButtonEvent::
~PGButtonEvent() {
}
////////////////////////////////////////////////////////////////////
// Function: PGButtonEvent::output
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
void PGButtonEvent::
output(ostream &out) const {
out << _button << " at (" << _mouse_x << ", " << _mouse_y << ")";
}

View File

@ -0,0 +1,76 @@
// Filename: pgButtonEvent.h
// Created by: drose (05Jul01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef PGBUTTONEVENT_H
#define PGBUTTONEVENT_H
#include "pandabase.h"
#include "typedReferenceCount.h"
#include "buttonHandle.h"
////////////////////////////////////////////////////////////////////
// Class : PGButtonEvent
// Description : This is sent along as a parameter to a button_down or
// button_up event for an item to indicate which button
// was involved, and what the current mouse position
// was.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA PGButtonEvent : public TypedReferenceCount {
public:
INLINE PGButtonEvent();
INLINE PGButtonEvent(ButtonHandle button, float mouse_x, float mouse_y);
virtual ~PGButtonEvent();
PUBLISHED:
INLINE ButtonHandle get_button() const;
INLINE string get_button_name() const;
INLINE float get_mouse_x() const;
INLINE float get_mouse_y() const;
void output(ostream &out) const;
public:
ButtonHandle _button;
float _mouse_x;
float _mouse_y;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
TypedReferenceCount::init_type();
register_type(_type_handle, "PGButtonEvent",
TypedReferenceCount::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
INLINE ostream &operator << (ostream &out, const PGButtonEvent &event);
#include "pgButtonEvent.I"
#endif

View File

@ -193,8 +193,8 @@ get_exit_event() const {
// depressed while the mouse is within the frame.
//
// This event will be thrown with one parameter, which
// will be the name of the button that generated the
// event.
// will be the PGButtonEvent for the button that
// generated the event.
////////////////////////////////////////////////////////////////////
INLINE string PGItem::
get_button_down_event() const {
@ -210,10 +210,11 @@ get_button_down_event() const {
// released.
//
// This event will be thrown with two parameters, the
// first of which will be the name of the button that
// generated the event, and the second of which will be
// a boolean flag indicating true if the mouse was
// within the frame while the button was released.
// first of which will be the PGButtonEvent for the
// button that generated the event, and the second of
// which will be a boolean flag indicating true if the
// mouse was within the frame while the button was
// released.
////////////////////////////////////////////////////////////////////
INLINE string PGItem::
get_button_up_event() const {

View File

@ -17,6 +17,7 @@
////////////////////////////////////////////////////////////////////
#include "pgItem.h"
#include "pgButtonEvent.h"
#include "namedNode.h"
#include "throw_event.h"
@ -142,8 +143,10 @@ exit() {
// is within the region.
////////////////////////////////////////////////////////////////////
void PGItem::
button_down(ButtonHandle button) {
throw_event(get_button_down_event(), button.get_name());
button_down(ButtonHandle button, float x, float y) {
PGButtonEvent *be = new PGButtonEvent(button, x, y);
throw_event(get_button_down_event(),
EventParameter(be));
}
////////////////////////////////////////////////////////////////////
@ -157,9 +160,10 @@ button_down(ButtonHandle button) {
// outside the region.
////////////////////////////////////////////////////////////////////
void PGItem::
button_up(ButtonHandle button, bool is_within) {
button_up(ButtonHandle button, float x, float y, bool is_within) {
PGButtonEvent *be = new PGButtonEvent(button, x, y);
throw_event(get_button_up_event(),
EventParameter(button.get_name()),
EventParameter(be),
EventParameter(is_within));
}

View File

@ -64,8 +64,8 @@ public:
virtual void enter();
virtual void exit();
virtual void button_down(ButtonHandle button);
virtual void button_up(ButtonHandle button, bool is_within);
virtual void button_down(ButtonHandle button, float x, float y);
virtual void button_up(ButtonHandle button, float x, float y, bool is_within);
PUBLISHED:
INLINE void set_frame(float left, float right, float bottom, float top);

View File

@ -82,9 +82,9 @@ exit() {
// is within the region.
////////////////////////////////////////////////////////////////////
void PGMouseWatcherRegion::
button_down(ButtonHandle button) {
button_down(ButtonHandle button, float x, float y) {
if (_item != (PGItem *)NULL) {
_item->button_down(button);
_item->button_down(button, x, y);
}
}
@ -99,8 +99,8 @@ button_down(ButtonHandle button) {
// outside the region.
////////////////////////////////////////////////////////////////////
void PGMouseWatcherRegion::
button_up(ButtonHandle button, bool is_within) {
button_up(ButtonHandle button, float x, float y, bool is_within) {
if (_item != (PGItem *)NULL) {
_item->button_up(button, is_within);
_item->button_up(button, x, y, is_within);
}
}

View File

@ -39,8 +39,8 @@ public:
virtual void enter();
virtual void exit();
virtual void button_down(ButtonHandle button);
virtual void button_up(ButtonHandle button, bool is_within);
virtual void button_down(ButtonHandle button, float x, float y);
virtual void button_up(ButtonHandle button, float x, float y, bool is_within);
private:
PGItem *_item;

View File

@ -92,6 +92,22 @@ get_ascii_equivalent() const {
return has_ascii_equivalent() ? (char)_index : '\0';
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::get_index
// Access: Public
// Description: Returns the integer index associated with this
// ButtonHandle. Each different ButtonHandle will have a
// different index. However, you probably shouldn't be
// using this method; you should just treat the
// ButtonHandles as opaque classes. This is provided
// for the convenience of non-C++ scripting languages to
// build a hashtable of ButtonHandles.
////////////////////////////////////////////////////////////////////
INLINE int ButtonHandle::
get_index() const {
return _index;
}
////////////////////////////////////////////////////////////////////
// Function: ButtonHandle::none
// Access: Public, Static

View File

@ -43,6 +43,7 @@ PUBLISHED:
INLINE bool has_ascii_equivalent() const;
INLINE char get_ascii_equivalent() const;
INLINE int get_index() const;
INLINE static ButtonHandle none();
private:

View File

@ -359,7 +359,7 @@ transmit_data(NodeAttributes &data) {
// both of the button-up events properly.
if (_button_down_region != (MouseWatcherRegion *)NULL) {
bool is_within = (_current_region == _button_down_region);
_button_down_region->button_up(be._button, is_within);
_button_down_region->button_up(be._button, get_mouse_x(), get_mouse_y(), is_within);
throw_event_pattern(_button_up_pattern, _button_down_region,
be._button.get_name());
}
@ -373,7 +373,7 @@ transmit_data(NodeAttributes &data) {
}
_button_down = true;
if (_button_down_region != (MouseWatcherRegion *)NULL) {
_button_down_region->button_down(be._button);
_button_down_region->button_down(be._button, get_mouse_x(), get_mouse_y());
throw_event_pattern(_button_down_pattern, _button_down_region,
be._button.get_name());
}

View File

@ -71,7 +71,7 @@ exit() {
// is within the region.
////////////////////////////////////////////////////////////////////
void MouseWatcherRegion::
button_down(ButtonHandle) {
button_down(ButtonHandle, float, float) {
}
////////////////////////////////////////////////////////////////////
@ -85,5 +85,5 @@ button_down(ButtonHandle) {
// outside the region.
////////////////////////////////////////////////////////////////////
void MouseWatcherRegion::
button_up(ButtonHandle, bool) {
button_up(ButtonHandle, float, float, bool) {
}

View File

@ -59,8 +59,8 @@ public:
virtual void enter();
virtual void exit();
virtual void button_down(ButtonHandle button);
virtual void button_up(ButtonHandle button, bool is_within);
virtual void button_down(ButtonHandle button, float x, float y);
virtual void button_up(ButtonHandle button, float x, float y, bool is_within);
private:
LVecBase4f _frame;