added PGWaitBar

This commit is contained in:
David Rose 2001-07-12 23:14:32 +00:00
parent 9412acb525
commit 9be3670cf9
9 changed files with 384 additions and 16 deletions

View File

@ -18,7 +18,8 @@
pgFrameStyle.I pgFrameStyle.h \
pgItem.I pgItem.h \
pgMouseWatcherRegion.I pgMouseWatcherRegion.h \
pgTop.I pgTop.h
pgTop.I pgTop.h \
pgWaitBar.I pgWaitBar.h
// #define INCLUDED_SOURCES \
#define SOURCES $[SOURCES] \
@ -30,7 +31,8 @@
pgFrameStyle.cxx \
pgItem.cxx \
pgMouseWatcherRegion.cxx \
pgTop.cxx
pgTop.cxx \
pgWaitBar.cxx
#define INSTALL_HEADERS \
pgButton.I pgButton.h \
@ -40,7 +42,8 @@
pgFrameStyle.I pgFrameStyle.h \
pgItem.I pgItem.h \
pgMouseWatcherRegion.I pgMouseWatcherRegion.h \
pgTop.I pgTop.h
pgTop.I pgTop.h \
pgWaitBar.I pgWaitBar.h
#define IGATESCAN all

View File

@ -24,6 +24,7 @@
#include "pgItem.h"
#include "pgMouseWatcherRegion.h"
#include "pgTop.h"
#include "pgWaitBar.h"
#include "dconfig.h"
@ -38,4 +39,5 @@ ConfigureFn(config_pgui) {
PGItem::init_type();
PGMouseWatcherRegion::init_type();
PGTop::init_type();
PGWaitBar::init_type();
}

View File

@ -214,17 +214,6 @@ get_accept_prefix() {
return "accept-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_event
// Access: Published
// Description: Returns the event name that will be thrown when the
// entry is accepted normally.
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_event(const ButtonHandle &button) const {
return "accept-" + button.get_name() + "-" + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_overflow_prefix
// Access: Published, Static
@ -237,6 +226,17 @@ get_overflow_prefix() {
return "overflow-";
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_accept_event
// Access: Published
// Description: Returns the event name that will be thrown when the
// entry is accepted normally.
////////////////////////////////////////////////////////////////////
INLINE string PGEntry::
get_accept_event(const ButtonHandle &button) const {
return "accept-" + button.get_name() + "-" + get_id();
}
////////////////////////////////////////////////////////////////////
// Function: PGEntry::get_overflow_event
// Access: Published

View File

@ -98,6 +98,7 @@ PGEntry(const PGEntry &copy) :
////////////////////////////////////////////////////////////////////
void PGEntry::
operator = (const PGEntry &copy) {
PGItem::operator = (copy);
_text = copy._text;
_cursor_position = copy._cursor_position;
_max_chars = copy._max_chars;

View File

@ -88,8 +88,9 @@ PUBLISHED:
virtual void set_focus(bool focus);
INLINE static string get_accept_prefix();
INLINE string get_accept_event(const ButtonHandle &button) const;
INLINE static string get_overflow_prefix();
INLINE string get_accept_event(const ButtonHandle &button) const;
INLINE string get_overflow_event() const;
private:

View File

@ -633,8 +633,8 @@ update_frame(int state) {
if (old_arc != (NodeRelation *)NULL) {
if (old_arc->is_attached()) {
remove_arc(old_arc);
_state_defs[state]._frame_arc = (NodeRelation *)NULL;
}
_state_defs[state]._frame_arc = (NodeRelation *)NULL;
}
}

View File

@ -0,0 +1,94 @@
// Filename: pgWaitBar.I
// Created by: drose (12Jul01)
//
////////////////////////////////////////////////////////////////////
//
// 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: PGWaitBar::set_range
// Access: Published
// Description: Sets the value at which the WaitBar indicates 100%.
////////////////////////////////////////////////////////////////////
INLINE void PGWaitBar::
set_range(float range) {
_range = range;
_bar_state = -1;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::get_range
// Access: Published
// Description: Returns the value at which the WaitBar indicates 100%.
////////////////////////////////////////////////////////////////////
INLINE float PGWaitBar::
get_range() const {
return _range;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::set_value
// Access: Published
// Description: Sets the current value of the bar. This should range
// between 0 and get_range().
////////////////////////////////////////////////////////////////////
INLINE void PGWaitBar::
set_value(float value) {
_value = value;
_bar_state = -1;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::get_value
// Access: Published
// Description: Returns the current value of the bar.
////////////////////////////////////////////////////////////////////
INLINE float PGWaitBar::
get_value() const {
return _value;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::get_percent
// Access: Published
// Description: Returns the percentage complete.
////////////////////////////////////////////////////////////////////
INLINE float PGWaitBar::
get_percent() const {
return _value / _range * 100.0;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::set_bar_style
// Access: Published
// Description: Sets the kind of frame that is drawn on top of the
// WaitBar to represent the amount completed.
////////////////////////////////////////////////////////////////////
INLINE void PGWaitBar::
set_bar_style(const PGFrameStyle &style) {
_bar_style = style;
_bar_state = -1;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::get_bar_style
// Access: Published
// Description: Returns the kind of frame that is drawn on top of the
// WaitBar to represent the amount completed.
////////////////////////////////////////////////////////////////////
INLINE PGFrameStyle PGWaitBar::
get_bar_style() const {
return _bar_style;
}

View File

@ -0,0 +1,178 @@
// Filename: pgWaitBar.cxx
// Created by: drose (12Jul01)
//
////////////////////////////////////////////////////////////////////
//
// 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 "pgWaitBar.h"
#include "pgMouseWatcherParameter.h"
#include "throw_event.h"
TypeHandle PGWaitBar::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::Constructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
PGWaitBar::
PGWaitBar(const string &name) : PGItem(name)
{
_range = 100.0;
_value = 0.0;
_bar_state = -1;
_bar_arc = (NodeRelation *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::Destructor
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
PGWaitBar::
~PGWaitBar() {
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::Copy Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
PGWaitBar::
PGWaitBar(const PGWaitBar &copy) :
PGItem(copy),
_range(copy._range),
_value(copy._value)
{
_bar_state = -1;
_bar_arc = (NodeRelation *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::Copy Assignment Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void PGWaitBar::
operator = (const PGWaitBar &copy) {
PGItem::operator = (copy);
_range = copy._range;
_value = copy._value;
_bar_state = -1;
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::make_copy
// Access: Public, Virtual
// Description: Returns a newly-allocated Node that is a shallow copy
// of this one. It will be a different Node pointer,
// but its internal data may or may not be shared with
// that of the original Node.
////////////////////////////////////////////////////////////////////
Node *PGWaitBar::
make_copy() const {
return new PGWaitBar(*this);
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::draw_item
// Access: Public, Virtual
// Description: Called by the PGTop's traversal to draw this
// particular item.
////////////////////////////////////////////////////////////////////
void PGWaitBar::
draw_item(PGTop *top, GraphicsStateGuardian *gsg,
const AllAttributesWrapper &attrib) {
update();
PGItem::draw_item(top, gsg, attrib);
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::setup
// Access: Public
// Description: Creates a PGWaitBar with the indicated dimensions,
// with the indicated maximum range.
////////////////////////////////////////////////////////////////////
void PGWaitBar::
setup(float width, float height, float range) {
set_state(0);
clear_state_def(0);
set_frame(-0.5 * width, 0.5 * width, -0.5 * height, 0.5 * height);
PGFrameStyle style;
style.set_width(0.05, 0.05);
style.set_color(0.6, 0.6, 0.6, 1.0);
style.set_type(PGFrameStyle::T_bevel_in);
set_frame_style(0, style);
style.set_color(0.8, 0.8, 0.8, 1.0);
style.set_type(PGFrameStyle::T_bevel_out);
set_bar_style(style);
}
////////////////////////////////////////////////////////////////////
// Function: PGWaitBar::update
// Access: Private
// Description: Computes the appropriate size of the bar frame
// according to the percentage completed.
////////////////////////////////////////////////////////////////////
void PGWaitBar::
update() {
int state = get_state();
// If the bar was last drawn in this state and is still current, we
// don't have to draw it again.
if (_bar_state == state) {
return;
}
// Remove the old bar geometry, if any.
if (_bar_arc != (NodeRelation *)NULL) {
if (_bar_arc->is_attached()) {
remove_arc(_bar_arc);
}
_bar_arc = (NodeRelation *)NULL;
}
// Now create new bar geometry.
if (_value != 0.0 && _range != 0.0) {
Node *node = get_state_def(state);
nassertv(node != (Node *)NULL);
PGFrameStyle style = get_frame_style(state);
const LVecBase4f &frame = get_frame();
const LVecBase2f &width = style.get_width();
// Put the bar within the item's frame's border.
LVecBase4f bar_frame(frame[0] + width[0],
frame[1] - width[0],
frame[2] + width[1],
frame[3] - width[1]);
// And scale the bar according to our value.
float frac = _value / _range;
frac = max(min(frac, 1.0f), 0.0f);
bar_frame[1] = bar_frame[0] + frac * (bar_frame[1] - bar_frame[0]);
_bar_arc = _bar_style.generate_into(node, bar_frame);
}
// Indicate that the bar is current for this state.
_bar_state = state;
}

View File

@ -0,0 +1,89 @@
// Filename: pgWaitBar.h
// Created by: drose (12Jul01)
//
////////////////////////////////////////////////////////////////////
//
// 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 PGWAITBAR_H
#define PGWAITBAR_H
#include "pandabase.h"
#include "pgItem.h"
////////////////////////////////////////////////////////////////////
// Class : PGWaitBar
// Description : This is a particular kind of PGItem that draws a
// little bar that fills from left to right to indicate
// a slow process gradually completing, like a
// traditional "wait, loading" bar.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA PGWaitBar : public PGItem {
PUBLISHED:
PGWaitBar(const string &name = "");
virtual ~PGWaitBar();
public:
PGWaitBar(const PGWaitBar &copy);
void operator = (const PGWaitBar &copy);
virtual Node *make_copy() const;
virtual void draw_item(PGTop *top, GraphicsStateGuardian *gsg,
const AllAttributesWrapper &attrib);
PUBLISHED:
void setup(float width, float height, float range);
INLINE void set_range(float range);
INLINE float get_range() const;
INLINE void set_value(float value);
INLINE float get_value() const;
INLINE float get_percent() const;
INLINE void set_bar_style(const PGFrameStyle &style);
INLINE PGFrameStyle get_bar_style() const;
private:
void update();
float _range, _value;
int _bar_state;
PGFrameStyle _bar_style;
PT_NodeRelation _bar_arc;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
PGItem::init_type();
register_type(_type_handle, "PGWaitBar",
PGItem::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;
};
#include "pgWaitBar.I"
#endif