From 78205035e1bb9d1d3d4ca03d1f9792e49dce9578 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 5 Jul 2001 21:32:07 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/pgui/pgButton.cxx | 8 ++--- panda/src/pgui/pgFrameStyle.cxx | 41 +++++++++++++++++++++++-- panda/src/pgui/pgFrameStyle.h | 1 + panda/src/pgui/pgItem.cxx | 54 +++++++++++++++++++++++++++++++++ panda/src/pgui/pgItem.h | 1 + 5 files changed, 99 insertions(+), 6 deletions(-) diff --git a/panda/src/pgui/pgButton.cxx b/panda/src/pgui/pgButton.cxx index c46fb9eba1..903a29536c 100644 --- a/panda/src/pgui/pgButton.cxx +++ b/panda/src/pgui/pgButton.cxx @@ -205,8 +205,8 @@ setup(const string &label) { style.set_color(0.9, 0.9, 0.9, 1.0); set_frame_style(S_rollover, style); - ColorTransition *col_trans = new ColorTransition(Colorf(0.8, 0.8, 0.8, 1.0)); - inact->set_transition(col_trans); + ColorTransition *ct = new ColorTransition(Colorf(0.8, 0.8, 0.8, 1.0)); + inact->set_transition(ct); style.set_color(0.6, 0.6, 0.6, 1.0); set_frame_style(S_inactive, style); @@ -214,8 +214,8 @@ setup(const string &label) { style.set_color(0.8, 0.8, 0.8, 1.0); 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); + TransformTransition *tt = new TransformTransition(translate); + down->set_transition(tt); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgui/pgFrameStyle.cxx b/panda/src/pgui/pgFrameStyle.cxx index c9fbb4170f..097f55287d 100644 --- a/panda/src/pgui/pgFrameStyle.cxx +++ b/panda/src/pgui/pgFrameStyle.cxx @@ -54,6 +54,43 @@ output(ostream &out) const { out << _type << " color = " << _color << " width = " << _width; } +//////////////////////////////////////////////////////////////////// +// Function: PGFrameStyle::xform +// Access: Public +// Description: Applies the indicated transform to the FrameStyle. +// The return value is true if the frame style is +// transformed, or false if it was not affected by the +// transform. +//////////////////////////////////////////////////////////////////// +bool PGFrameStyle:: +xform(const LMatrix4f &mat) { + // All we can do is scale the X and Y bevel sizes. + + // Extract the X and Z axes from the matrix. + LVector3f x, z; + mat.get_row3(x, 0); + float x_scale = x.length(); + + mat.get_row3(z, 2); + float z_scale = z.length(); + + _width[0] *= x_scale; + _width[1] *= z_scale; + + switch (_type) { + case T_none: + case T_flat: + return false; + + case T_bevel_out: + case T_bevel_in: + return true; + } + + // Shouldn't get here, but this makes the compiler happy. + return true; +} + //////////////////////////////////////////////////////////////////// // Function: PGFrameStyle::generate_into // Access: Public @@ -106,7 +143,7 @@ generate_into(Node *node, const LVecBase4f &frame) { //////////////////////////////////////////////////////////////////// // Function: PGFrameStyle::generate_flat_geom -// Access: Public +// Access: Private // Description: Generates the GeomNode appropriate to a T_flat // frame. //////////////////////////////////////////////////////////////////// @@ -144,7 +181,7 @@ generate_flat_geom(const LVecBase4f &frame) { //////////////////////////////////////////////////////////////////// // Function: PGFrameStyle::generate_bevel_geom -// Access: Public +// Access: Private // Description: Generates the GeomNode appropriate to a T_bevel_in or // T_bevel_out frame. //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgui/pgFrameStyle.h b/panda/src/pgui/pgFrameStyle.h index 89a55eab9f..f1876cce40 100644 --- a/panda/src/pgui/pgFrameStyle.h +++ b/panda/src/pgui/pgFrameStyle.h @@ -60,6 +60,7 @@ PUBLISHED: void output(ostream &out) const; public: + bool xform(const LMatrix4f &mat); NodeRelation *generate_into(Node *node, const LVecBase4f &frame); private: diff --git a/panda/src/pgui/pgItem.cxx b/panda/src/pgui/pgItem.cxx index e600e27a55..d1dda004a8 100644 --- a/panda/src/pgui/pgItem.cxx +++ b/panda/src/pgui/pgItem.cxx @@ -23,6 +23,8 @@ #include "throw_event.h" #include "string_utils.h" #include "arcChain.h" +#include "transformTransition.h" +#include "sceneGraphReducer.h" TypeHandle PGItem::_type_handle; PT(TextNode) PGItem::_text_node; @@ -96,6 +98,58 @@ make_copy() const { return new PGItem(*this); } +//////////////////////////////////////////////////////////////////// +// Function: PGItem::xform +// Access: Public, Virtual +// Description: Transforms the contents of this node by the indicated +// matrix, if it means anything to do so. For most +// kinds of nodes, this does nothing. +//////////////////////////////////////////////////////////////////// +void PGItem:: +xform(const LMatrix4f &mat) { + // Transform the frame. + LPoint3f ll(_frame[0], 0.0, _frame[2]); + LPoint3f ur(_frame[1], 0.0, _frame[3]); + ll = ll * mat; + ur = ur * mat; + _frame.set(ll[0], ur[0], ll[2], ur[2]); + + // Transform the individual states and their frame styles. + StateDefs::iterator di; + for (di = _state_defs.begin(); di != _state_defs.end(); ++di) { + Node *node = (*di)._node; + if (node != (Node *)NULL) { + // Apply the matrix to the previous transform on all the arcs + // here. + int num_children = node->get_num_children(RenderRelation::get_class_type()); + for (int i = 0; i < num_children; i++) { + NodeRelation *arc = node->get_child(RenderRelation::get_class_type(), i); + if (arc != (*di)._frame_arc) { + LMatrix4f arc_mat; + TransformTransition *tt; + if (!get_transition_into(tt, arc)) { + // No previous transform. + arc_mat = mat; + } else { + arc_mat = tt->get_matrix() * mat; + } + tt = new TransformTransition(arc_mat); + arc->set_transition(tt); + + // Now flatten the transform into the subgraph. + SceneGraphReducer gr; + gr.apply_transitions(arc); + } + } + } + + // Transform the frame style too. + if ((*di)._frame_style.xform(mat)) { + (*di)._frame_stale = true; + } + } +} + //////////////////////////////////////////////////////////////////// // Function: PGItem::activate_region // Access: Public, Virtual diff --git a/panda/src/pgui/pgItem.h b/panda/src/pgui/pgItem.h index dd35c0cea8..ceb243becc 100644 --- a/panda/src/pgui/pgItem.h +++ b/panda/src/pgui/pgItem.h @@ -58,6 +58,7 @@ public: void operator = (const PGItem ©); virtual Node *make_copy() const; + virtual void xform(const LMatrix4f &mat); void activate_region(const LMatrix4f &transform, int sort); INLINE PGMouseWatcherRegion *get_region() const;