added a compose_color_scale interface

This commit is contained in:
Asad M. Zaman 2007-03-28 23:36:45 +00:00
parent c9b1445b7c
commit 1d0789ecde
6 changed files with 77 additions and 2 deletions

View File

@ -53,10 +53,10 @@ public:
virtual bool lower_attrib_can_override() const;
virtual void output(ostream &out) const;
virtual void store_into_slot(AttribSlots *slots) const;
virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
protected:
virtual int compare_to_impl(const RenderAttrib *other) const;
virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
virtual CPT(RenderAttrib) invert_compose_impl(const RenderAttrib *other) const;
virtual RenderAttrib *make_default_impl() const;

View File

@ -1179,6 +1179,16 @@ set_color_scale(float sr, float sg, float sb, float sa, int priority) {
set_color_scale(LVecBase4f(sr, sg, sb, sa), priority);
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::compose_color_scale
// Access: Published
// Description: Sets the color scale component of the transform
////////////////////////////////////////////////////////////////////
INLINE void NodePath::
compose_color_scale(float sr, float sg, float sb, float sa, int priority) {
compose_color_scale(LVecBase4f(sr, sg, sb, sa), priority);
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_sr
// Access: Published

View File

@ -2146,6 +2146,39 @@ clear_color_scale() {
node()->clear_attrib(ColorScaleAttrib::get_class_type());
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::compose_color_scale
// Access: Published
// Description: multiplies the color scale component of the transform,
// with previous color scale leaving translation and
// rotation untouched.
////////////////////////////////////////////////////////////////////
void NodePath::
compose_color_scale(const LVecBase4f &scale, int priority) {
nassertv_always(!is_empty());
const RenderAttrib *attrib =
node()->get_attrib(ColorScaleAttrib::get_class_type());
if (attrib != (const RenderAttrib *)NULL) {
priority = max(priority,
node()->get_state()->get_override(ColorScaleAttrib::get_class_type()));
const ColorScaleAttrib *csa = DCAST(ColorScaleAttrib, attrib);
// Modify the existing ColorScaleAttrib by multiplying with the
// indicated colorScale.
LVecBase4f prev_color_scale = csa->get_scale();
LVecBase4f new_color_scale(prev_color_scale[0]*scale[0],
prev_color_scale[1]*scale[1],
prev_color_scale[2]*scale[2],
prev_color_scale[3]*scale[3]);
node()->set_attrib(csa->set_scale(new_color_scale), priority);
} else {
// Create a new ColorScaleAttrib for this node.
node()->set_attrib(ColorScaleAttrib::make(scale), priority);
}
}
////////////////////////////////////////////////////////////////////
// Function: NodePath::set_color_scale
// Access: Published

View File

@ -512,8 +512,12 @@ PUBLISHED:
int priority = 0);
INLINE void set_color_scale(float sx, float sy, float sz, float sa,
int priority = 0);
void compose_color_scale(const LVecBase4f &scale,
int priority = 0);
INLINE void compose_color_scale(float sx, float sy, float sz, float sa,
int priority = 0);
void set_color_scale_off(int priority = 0);
void set_alpha_scale(float scale, int priority = 0);
void set_all_color_scale(float scale, int priority = 0);
INLINE void set_sr(float sr);

View File

@ -470,6 +470,30 @@ set_color_scale(const Colorf &color, int priority) {
}
}
////////////////////////////////////////////////////////////////////
// Function: NodePathCollection::compose_color_scale
// Access: Published
// Description: Applies color scales to all NodePaths in the collection
////////////////////////////////////////////////////////////////////
void NodePathCollection::
compose_color_scale(float r, float g, float b, float a, int priority) {
for (int i = 0; i < get_num_paths(); i++) {
get_path(i).compose_color_scale(Colorf(r, g, b, a), priority);
}
}
////////////////////////////////////////////////////////////////////
// Function: NodePathCollection::compose_color_scale
// Access: Published
// Description: Applies color scales to all NodePaths in the collection
////////////////////////////////////////////////////////////////////
void NodePathCollection::
compose_color_scale(const Colorf &color, int priority) {
for (int i = 0; i < get_num_paths(); i++) {
get_path(i).compose_color_scale(color, priority);
}
}
////////////////////////////////////////////////////////////////////
// Function: NodePathCollection::output
// Access: Published

View File

@ -76,6 +76,10 @@ PUBLISHED:
int priority = 0);
void set_color_scale(const Colorf &color, int priority = 0);
void compose_color_scale(float r, float g, float b, float a = 1.0,
int priority = 0);
void compose_color_scale(const Colorf &color, int priority = 0);
void output(ostream &out) const;
void write(ostream &out, int indent_level = 0) const;