mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
PGFrameStyle::T_texture_border
This commit is contained in:
parent
08a4e29993
commit
5d8b61ca86
@ -700,6 +700,7 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
||||
# Widget's frame characteristics
|
||||
('relief', DGG.FLAT, self.setRelief),
|
||||
('borderWidth', (.1, .1), self.setBorderWidth),
|
||||
('borderUvWidth', (.1, .1), self.setBorderUvWidth),
|
||||
('frameSize', None, self.setFrameSize),
|
||||
('frameColor', (.8, .8, .8, 1), self.setFrameColor),
|
||||
('frameTexture', None, self.setFrameTexture),
|
||||
@ -1028,6 +1029,12 @@ class DirectGuiWidget(DirectGuiBase, NodePath):
|
||||
self.frameStyle[i].setWidth(width[0], width[1])
|
||||
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):
|
||||
if hasattr(self, "frameStyle"):
|
||||
if __dev__:
|
||||
|
@ -37,9 +37,11 @@ RAISED = PGFrameStyle.TBevelOut
|
||||
SUNKEN = PGFrameStyle.TBevelIn
|
||||
GROOVE = PGFrameStyle.TGroove
|
||||
RIDGE = PGFrameStyle.TRidge
|
||||
TEXTUREBORDER = PGFrameStyle.TTextureBorder
|
||||
|
||||
FrameStyleDict = {'flat': FLAT, 'raised': RAISED, 'sunken': SUNKEN,
|
||||
'groove': GROOVE, 'ridge': RIDGE
|
||||
'groove': GROOVE, 'ridge': RIDGE,
|
||||
'texture_border': TEXTUREBORDER,
|
||||
}
|
||||
|
||||
# Orientation of DirectSlider and DirectScrollBar
|
||||
|
@ -23,6 +23,7 @@ PGFrameStyle() {
|
||||
_type = T_none;
|
||||
_color.set(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
_width.set(0.1f, 0.1f);
|
||||
_uv_width.set(0.1f, 0.1f);
|
||||
_visible_scale.set(1.0f, 1.0f);
|
||||
}
|
||||
|
||||
@ -37,6 +38,7 @@ PGFrameStyle(const PGFrameStyle ©) :
|
||||
_color(copy._color),
|
||||
_texture(copy._texture),
|
||||
_width(copy._width),
|
||||
_uv_width(copy._uv_width),
|
||||
_visible_scale(copy._visible_scale)
|
||||
{
|
||||
}
|
||||
@ -52,6 +54,7 @@ operator = (const PGFrameStyle ©) {
|
||||
_color = copy._color;
|
||||
_texture = copy._texture;
|
||||
_width = copy._width;
|
||||
_uv_width = copy._uv_width;
|
||||
_visible_scale = copy._visible_scale;
|
||||
}
|
||||
|
||||
@ -196,6 +199,42 @@ get_width() const {
|
||||
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
|
||||
// Access: Published
|
||||
|
@ -52,6 +52,9 @@ operator << (ostream &out, PGFrameStyle::Type type) {
|
||||
|
||||
case PGFrameStyle::T_ridge:
|
||||
return out << "ridge";
|
||||
|
||||
case PGFrameStyle::T_texture_border:
|
||||
return out << "texture_border";
|
||||
}
|
||||
|
||||
return out << "**unknown(" << (int)type << ")**";
|
||||
@ -138,6 +141,7 @@ xform(const LMatrix4f &mat) {
|
||||
case T_bevel_in:
|
||||
case T_groove:
|
||||
case T_ridge:
|
||||
case T_texture_border:
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -177,11 +181,11 @@ generate_into(const NodePath &parent, const LVecBase4f &frame,
|
||||
break;
|
||||
|
||||
case T_bevel_out:
|
||||
new_node = generate_bevel_geom(scaled_frame, false);
|
||||
new_node = generate_bevel_geom(scaled_frame, false, false);
|
||||
break;
|
||||
|
||||
case T_bevel_in:
|
||||
new_node = generate_bevel_geom(scaled_frame, true);
|
||||
new_node = generate_bevel_geom(scaled_frame, true, false);
|
||||
break;
|
||||
|
||||
case T_groove:
|
||||
@ -192,6 +196,10 @@ generate_into(const NodePath &parent, const LVecBase4f &frame,
|
||||
new_node = generate_groove_geom(scaled_frame, false);
|
||||
break;
|
||||
|
||||
case T_texture_border:
|
||||
new_node = generate_bevel_geom(scaled_frame, false, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -271,11 +279,11 @@ generate_flat_geom(const LVecBase4f &frame) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: PGFrameStyle::generate_bevel_geom
|
||||
// Access: Private
|
||||
// Description: Generates the GeomNode appropriate to a T_bevel_in or
|
||||
// T_bevel_out frame.
|
||||
// Description: Generates the GeomNode appropriate to a T_bevel_in,
|
||||
// T_bevel_out, or T_texture_border frame.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(PandaNode) PGFrameStyle::
|
||||
generate_bevel_geom(const LVecBase4f &frame, bool in) {
|
||||
generate_bevel_geom(const LVecBase4f &frame, bool in, bool flat_color) {
|
||||
//
|
||||
// Colors:
|
||||
//
|
||||
@ -356,6 +364,12 @@ generate_bevel_geom(const LVecBase4f &frame, bool in) {
|
||||
top_color_scale = 0.7;
|
||||
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.
|
||||
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),
|
||||
_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
|
||||
("PGFrame", format, Geom::UH_static);
|
||||
|
||||
@ -423,18 +443,55 @@ generate_bevel_geom(const LVecBase4f &frame, bool in) {
|
||||
|
||||
strip->add_next_vertices(6);
|
||||
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);
|
||||
geom->add_primitive(strip);
|
||||
|
||||
CPT(RenderState) state = RenderState::make(ShadeModelAttrib::make(ShadeModelAttrib::M_flat),
|
||||
ColorAttrib::make_vertex());
|
||||
CPT(RenderState) state;
|
||||
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);
|
||||
|
||||
// For now, beveled and grooved geoms don't support textures. Easy
|
||||
// to add if anyone really wants this.
|
||||
|
||||
return gnode.p();
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,8 @@ PUBLISHED:
|
||||
T_bevel_out,
|
||||
T_bevel_in,
|
||||
T_groove,
|
||||
T_ridge
|
||||
T_ridge,
|
||||
T_texture_border
|
||||
};
|
||||
|
||||
INLINE void set_type(Type type);
|
||||
@ -61,6 +62,10 @@ PUBLISHED:
|
||||
INLINE void set_width(const LVecBase2f &width);
|
||||
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(const LVecBase2f &visible_scale);
|
||||
INLINE const LVecBase2f &get_visible_scale() const;
|
||||
@ -76,7 +81,7 @@ public:
|
||||
|
||||
private:
|
||||
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);
|
||||
|
||||
private:
|
||||
@ -84,6 +89,7 @@ private:
|
||||
Colorf _color;
|
||||
PT(Texture) _texture;
|
||||
LVecBase2f _width;
|
||||
LVecBase2f _uv_width;
|
||||
LVecBase2f _visible_scale;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user