PGFrameStyle::T_texture_border

This commit is contained in:
David Rose 2009-12-13 07:20:23 +00:00
parent 08a4e29993
commit 5d8b61ca86
5 changed files with 127 additions and 16 deletions

View File

@ -700,6 +700,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
# Widget's frame characteristics # Widget's frame characteristics
('relief', DGG.FLAT, self.setRelief), ('relief', DGG.FLAT, self.setRelief),
('borderWidth', (.1, .1), self.setBorderWidth), ('borderWidth', (.1, .1), self.setBorderWidth),
('borderUvWidth', (.1, .1), self.setBorderUvWidth),
('frameSize', None, self.setFrameSize), ('frameSize', None, self.setFrameSize),
('frameColor', (.8, .8, .8, 1), self.setFrameColor), ('frameColor', (.8, .8, .8, 1), self.setFrameColor),
('frameTexture', None, self.setFrameTexture), ('frameTexture', None, self.setFrameTexture),
@ -1028,6 +1029,12 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
self.frameStyle[i].setWidth(width[0], width[1]) self.frameStyle[i].setWidth(width[0], width[1])
self.updateFrameStyle() self.updateFrameStyle()
def setBorderUvWidth(self):
uvWidth = self['borderUvWidth']
for i in range(self['numStates']):
self.frameStyle[i].setUvWidth(uvWidth[0], uvWidth[1])
self.updateFrameStyle()
def destroy(self): def destroy(self):
if hasattr(self, "frameStyle"): if hasattr(self, "frameStyle"):
if __dev__: if __dev__:

View File

@ -37,9 +37,11 @@ RAISED = PGFrameStyle.TBevelOut
SUNKEN = PGFrameStyle.TBevelIn SUNKEN = PGFrameStyle.TBevelIn
GROOVE = PGFrameStyle.TGroove GROOVE = PGFrameStyle.TGroove
RIDGE = PGFrameStyle.TRidge RIDGE = PGFrameStyle.TRidge
TEXTUREBORDER = PGFrameStyle.TTextureBorder
FrameStyleDict = {'flat': FLAT, 'raised': RAISED, 'sunken': SUNKEN, FrameStyleDict = {'flat': FLAT, 'raised': RAISED, 'sunken': SUNKEN,
'groove': GROOVE, 'ridge': RIDGE 'groove': GROOVE, 'ridge': RIDGE,
'texture_border': TEXTUREBORDER,
} }
# Orientation of DirectSlider and DirectScrollBar # Orientation of DirectSlider and DirectScrollBar

View File

@ -23,6 +23,7 @@ PGFrameStyle() {
_type = T_none; _type = T_none;
_color.set(1.0f, 1.0f, 1.0f, 1.0f); _color.set(1.0f, 1.0f, 1.0f, 1.0f);
_width.set(0.1f, 0.1f); _width.set(0.1f, 0.1f);
_uv_width.set(0.1f, 0.1f);
_visible_scale.set(1.0f, 1.0f); _visible_scale.set(1.0f, 1.0f);
} }
@ -37,6 +38,7 @@ PGFrameStyle(const PGFrameStyle &copy) :
_color(copy._color), _color(copy._color),
_texture(copy._texture), _texture(copy._texture),
_width(copy._width), _width(copy._width),
_uv_width(copy._uv_width),
_visible_scale(copy._visible_scale) _visible_scale(copy._visible_scale)
{ {
} }
@ -52,6 +54,7 @@ operator = (const PGFrameStyle &copy) {
_color = copy._color; _color = copy._color;
_texture = copy._texture; _texture = copy._texture;
_width = copy._width; _width = copy._width;
_uv_width = copy._uv_width;
_visible_scale = copy._visible_scale; _visible_scale = copy._visible_scale;
} }
@ -196,6 +199,42 @@ get_width() const {
return _width; return _width;
} }
////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::set_uv_width
// Access: Published
// Description: Sets the uv_width parameter, which indicates the
// amount of the texture that is consumed by the inner
// bevel--the width in texture space of the amount
// indicated by set_width.
////////////////////////////////////////////////////////////////////
INLINE void PGFrameStyle::
set_uv_width(float u, float v) {
set_uv_width(LVecBase2f(u, v));
}
////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::set_uv_width
// Access: Published
// Description: Sets the uv_width parameter, which indicates the
// amount of the texture that is consumed by the inner
// bevel--the width in texture space of the amount
// indicated by set_width.
////////////////////////////////////////////////////////////////////
INLINE void PGFrameStyle::
set_uv_width(const LVecBase2f &uv_width) {
_uv_width = uv_width;
}
////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::get_uv_width
// Access: Published
// Description: See set_uv_width().
////////////////////////////////////////////////////////////////////
INLINE const LVecBase2f &PGFrameStyle::
get_uv_width() const {
return _uv_width;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::set_visible_scale // Function: PGFrameStyle::set_visible_scale
// Access: Published // Access: Published

View File

@ -52,6 +52,9 @@ operator << (ostream &out, PGFrameStyle::Type type) {
case PGFrameStyle::T_ridge: case PGFrameStyle::T_ridge:
return out << "ridge"; return out << "ridge";
case PGFrameStyle::T_texture_border:
return out << "texture_border";
} }
return out << "**unknown(" << (int)type << ")**"; return out << "**unknown(" << (int)type << ")**";
@ -138,6 +141,7 @@ xform(const LMatrix4f &mat) {
case T_bevel_in: case T_bevel_in:
case T_groove: case T_groove:
case T_ridge: case T_ridge:
case T_texture_border:
return true; return true;
} }
@ -177,11 +181,11 @@ generate_into(const NodePath &parent, const LVecBase4f &frame,
break; break;
case T_bevel_out: case T_bevel_out:
new_node = generate_bevel_geom(scaled_frame, false); new_node = generate_bevel_geom(scaled_frame, false, false);
break; break;
case T_bevel_in: case T_bevel_in:
new_node = generate_bevel_geom(scaled_frame, true); new_node = generate_bevel_geom(scaled_frame, true, false);
break; break;
case T_groove: case T_groove:
@ -192,6 +196,10 @@ generate_into(const NodePath &parent, const LVecBase4f &frame,
new_node = generate_groove_geom(scaled_frame, false); new_node = generate_groove_geom(scaled_frame, false);
break; break;
case T_texture_border:
new_node = generate_bevel_geom(scaled_frame, false, true);
break;
default: default:
break; break;
} }
@ -271,11 +279,11 @@ generate_flat_geom(const LVecBase4f &frame) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: PGFrameStyle::generate_bevel_geom // Function: PGFrameStyle::generate_bevel_geom
// Access: Private // Access: Private
// Description: Generates the GeomNode appropriate to a T_bevel_in or // Description: Generates the GeomNode appropriate to a T_bevel_in,
// T_bevel_out frame. // T_bevel_out, or T_texture_border frame.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PT(PandaNode) PGFrameStyle:: PT(PandaNode) PGFrameStyle::
generate_bevel_geom(const LVecBase4f &frame, bool in) { generate_bevel_geom(const LVecBase4f &frame, bool in, bool flat_color) {
// //
// Colors: // Colors:
// //
@ -356,6 +364,12 @@ generate_bevel_geom(const LVecBase4f &frame, bool in) {
top_color_scale = 0.7; top_color_scale = 0.7;
bottom_color_scale = 1.3; bottom_color_scale = 1.3;
} }
if (flat_color) {
left_color_scale = 1.0;
right_color_scale = 1.0;
bottom_color_scale = 1.0;
top_color_scale = 1.0;
}
// Clamp all colors at white, and don't scale the alpha. // Clamp all colors at white, and don't scale the alpha.
Colorf cleft(min(_color[0] * left_color_scale, 1.0f), Colorf cleft(min(_color[0] * left_color_scale, 1.0f),
@ -378,7 +392,13 @@ generate_bevel_geom(const LVecBase4f &frame, bool in) {
min(_color[2] * top_color_scale, 1.0f), min(_color[2] * top_color_scale, 1.0f),
_color[3]); _color[3]);
CPT(GeomVertexFormat) format = GeomVertexFormat::get_v3cp(); CPT(GeomVertexFormat) format;
if (has_texture()) {
format = GeomVertexFormat::get_v3cpt2();
} else {
format = GeomVertexFormat::get_v3cp();
}
PT(GeomVertexData) vdata = new GeomVertexData PT(GeomVertexData) vdata = new GeomVertexData
("PGFrame", format, Geom::UH_static); ("PGFrame", format, Geom::UH_static);
@ -423,18 +443,55 @@ generate_bevel_geom(const LVecBase4f &frame, bool in) {
strip->add_next_vertices(6); strip->add_next_vertices(6);
strip->close_primitive(); strip->close_primitive();
strip->set_shade_model(Geom::SM_flat_last_vertex);
if (!flat_color) {
strip->set_shade_model(Geom::SM_flat_last_vertex);
}
if (has_texture()) {
// Generate UV's.
float left = uv_range[0];
float right = uv_range[1];
float bottom = uv_range[2];
float top = uv_range[3];
float inner_left = left + _uv_width[0];
float inner_right = right - _uv_width[0];
float inner_bottom = bottom + _uv_width[1];
float inner_top = top - _uv_width[1];
GeomVertexWriter texcoord(vdata, InternalName::get_texcoord());
texcoord.add_data2f(right, bottom);
texcoord.add_data2f(inner_right, inner_bottom);
texcoord.add_data2f(left, bottom);
texcoord.add_data2f(inner_left, inner_bottom);
texcoord.add_data2f(left, top);
texcoord.add_data2f(inner_left, inner_top);
texcoord.add_data2f(right, top);
texcoord.add_data2f(inner_right, inner_top);
texcoord.add_data2f(right, bottom);
texcoord.add_data2f(right, top);
texcoord.add_data2f(inner_right, inner_bottom);
texcoord.add_data2f(inner_right, inner_top);
texcoord.add_data2f(inner_left, inner_bottom);
texcoord.add_data2f(inner_left, inner_top);
}
vdata->write(cerr);
PT(Geom) geom = new Geom(vdata); PT(Geom) geom = new Geom(vdata);
geom->add_primitive(strip); geom->add_primitive(strip);
CPT(RenderState) state = RenderState::make(ShadeModelAttrib::make(ShadeModelAttrib::M_flat), CPT(RenderState) state;
ColorAttrib::make_vertex()); if (flat_color) {
state = RenderState::make(ColorAttrib::make_flat(_color));
} else {
state = RenderState::make(ShadeModelAttrib::make(ShadeModelAttrib::M_flat),
ColorAttrib::make_vertex());
}
if (has_texture()) {
state = state->set_attrib(TextureAttrib::make(get_texture()));
}
gnode->add_geom(geom, state); gnode->add_geom(geom, state);
// For now, beveled and grooved geoms don't support textures. Easy
// to add if anyone really wants this.
return gnode.p(); return gnode.p();
} }

View File

@ -42,7 +42,8 @@ PUBLISHED:
T_bevel_out, T_bevel_out,
T_bevel_in, T_bevel_in,
T_groove, T_groove,
T_ridge T_ridge,
T_texture_border
}; };
INLINE void set_type(Type type); INLINE void set_type(Type type);
@ -61,6 +62,10 @@ PUBLISHED:
INLINE void set_width(const LVecBase2f &width); INLINE void set_width(const LVecBase2f &width);
INLINE const LVecBase2f &get_width() const; INLINE const LVecBase2f &get_width() const;
INLINE void set_uv_width(float u, float v);
INLINE void set_uv_width(const LVecBase2f &uv_width);
INLINE const LVecBase2f &get_uv_width() const;
INLINE void set_visible_scale(float x, float y); INLINE void set_visible_scale(float x, float y);
INLINE void set_visible_scale(const LVecBase2f &visible_scale); INLINE void set_visible_scale(const LVecBase2f &visible_scale);
INLINE const LVecBase2f &get_visible_scale() const; INLINE const LVecBase2f &get_visible_scale() const;
@ -76,7 +81,7 @@ public:
private: private:
PT(PandaNode) generate_flat_geom(const LVecBase4f &frame); PT(PandaNode) generate_flat_geom(const LVecBase4f &frame);
PT(PandaNode) generate_bevel_geom(const LVecBase4f &frame, bool in); PT(PandaNode) generate_bevel_geom(const LVecBase4f &frame, bool in, bool flat_color);
PT(PandaNode) generate_groove_geom(const LVecBase4f &frame, bool in); PT(PandaNode) generate_groove_geom(const LVecBase4f &frame, bool in);
private: private:
@ -84,6 +89,7 @@ private:
Colorf _color; Colorf _color;
PT(Texture) _texture; PT(Texture) _texture;
LVecBase2f _width; LVecBase2f _width;
LVecBase2f _uv_width;
LVecBase2f _visible_scale; LVecBase2f _visible_scale;
}; };