mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
add underscore property
This commit is contained in:
parent
1f0c2980bb
commit
48a840be75
@ -26,6 +26,11 @@
|
||||
#include "textPropertiesManager.h"
|
||||
#include "textEncoder.h"
|
||||
#include "config_text.h"
|
||||
#include "geomVertexWriter.h"
|
||||
#include "geomLines.h"
|
||||
#include "geomVertexFormat.h"
|
||||
#include "geomVertexData.h"
|
||||
#include "geom.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
@ -1154,6 +1159,10 @@ assemble_row(TextAssembler::TextRow &row,
|
||||
float xpos = 0.0f;
|
||||
align = TextProperties::A_left;
|
||||
|
||||
bool underscore = false;
|
||||
float underscore_start = 0.0f;
|
||||
const TextProperties *underscore_properties = NULL;
|
||||
|
||||
TextString::const_iterator si;
|
||||
for (si = row._string.begin(); si != row._string.end(); ++si) {
|
||||
const TextCharacter &tch = (*si);
|
||||
@ -1161,6 +1170,19 @@ assemble_row(TextAssembler::TextRow &row,
|
||||
const TextGraphic *graphic = tch._graphic;
|
||||
const TextProperties *properties = &(tch._cprops->_properties);
|
||||
|
||||
if (properties->get_underscore() != underscore ||
|
||||
(underscore && (properties->get_text_color() != underscore_properties->get_text_color() ||
|
||||
properties->get_underscore_height() != underscore_properties->get_underscore_height()))) {
|
||||
// Change the underscore status.
|
||||
if (underscore && underscore_start != xpos) {
|
||||
draw_underscore(row_placed_glyphs, underscore_start, xpos,
|
||||
underscore_properties);
|
||||
}
|
||||
underscore = properties->get_underscore();
|
||||
underscore_start = xpos;
|
||||
underscore_properties = properties;
|
||||
}
|
||||
|
||||
TextFont *font = properties->get_font();
|
||||
nassertv(font != (TextFont *)NULL);
|
||||
|
||||
@ -1330,6 +1352,11 @@ assemble_row(TextAssembler::TextRow &row,
|
||||
}
|
||||
}
|
||||
|
||||
if (underscore && underscore_start != xpos) {
|
||||
draw_underscore(row_placed_glyphs, underscore_start, xpos,
|
||||
underscore_properties);
|
||||
}
|
||||
|
||||
row_width = xpos;
|
||||
|
||||
if (row._eol_cprops != (ComputedProperties *)NULL) {
|
||||
@ -1346,6 +1373,41 @@ assemble_row(TextAssembler::TextRow &row,
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextAssembler::draw_underscore
|
||||
// Access: Private, Static
|
||||
// Description: Creates the geometry to render the underscore line
|
||||
// for the indicated range of glyphs in this row.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void TextAssembler::
|
||||
draw_underscore(TextAssembler::PlacedGlyphs &row_placed_glyphs,
|
||||
float underscore_start, float underscore_end,
|
||||
const TextProperties *underscore_properties) {
|
||||
CPT(GeomVertexFormat) format = GeomVertexFormat::get_v3cp();
|
||||
PT(GeomVertexData) vdata =
|
||||
new GeomVertexData("text", format, Geom::UH_static);
|
||||
GeomVertexWriter vertex(vdata, InternalName::get_vertex());
|
||||
GeomVertexWriter color(vdata, InternalName::get_color());
|
||||
float y = underscore_properties->get_underscore_height();
|
||||
vertex.add_data3f(underscore_start, 0.0f, y);
|
||||
color.add_data4f(underscore_properties->get_text_color());
|
||||
vertex.add_data3f(underscore_end, 0.0f, y);
|
||||
color.add_data4f(underscore_properties->get_text_color());
|
||||
|
||||
PT(GeomLines) lines = new GeomLines(Geom::UH_static);
|
||||
lines->add_vertices(0, 1);
|
||||
lines->close_primitive();
|
||||
|
||||
PT(Geom) geom = new Geom(vdata);
|
||||
geom->add_primitive(lines);
|
||||
|
||||
GlyphPlacement *placement = new GlyphPlacement;
|
||||
placement->add_piece(geom, RenderState::make_empty());
|
||||
placement->_xform = LMatrix4f::ident_mat();
|
||||
placement->_properties = underscore_properties;
|
||||
|
||||
row_placed_glyphs.push_back(placement);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextAssembler::get_character_glyphs
|
||||
|
@ -230,6 +230,11 @@ private:
|
||||
CT_tiny_rotate_270,
|
||||
};
|
||||
|
||||
static void
|
||||
draw_underscore(TextAssembler::PlacedGlyphs &row_placed_glyphs,
|
||||
float underscore_start, float underscore_end,
|
||||
const TextProperties *underscore_properties);
|
||||
|
||||
static void
|
||||
get_character_glyphs(int character, const TextProperties *properties,
|
||||
bool &got_glyph, const TextGlyph *&glyph,
|
||||
|
@ -262,6 +262,97 @@ get_slant() const {
|
||||
return _slant;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::set_underscore
|
||||
// Access: Published
|
||||
// Description: Sets the underscore flag. When this is set,
|
||||
// the text is underscored with a one-pixel line the
|
||||
// same color as the text foreground, drawn at the
|
||||
// baseline.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void TextProperties::
|
||||
set_underscore(bool underscore) {
|
||||
_underscore = underscore;
|
||||
_specified |= F_has_underscore;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::clear_underscore
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void TextProperties::
|
||||
clear_underscore() {
|
||||
_underscore = false;
|
||||
_specified &= ~F_has_underscore;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::has_underscore
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool TextProperties::
|
||||
has_underscore() const {
|
||||
return (_specified & F_has_underscore) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::get_underscore
|
||||
// Access: Published
|
||||
// Description: Returns the underscore flag. See set_underscore().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool TextProperties::
|
||||
get_underscore() const {
|
||||
return _underscore;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::set_underscore_height
|
||||
// Access: Published
|
||||
// Description: Specifies the vertical height of the underscore,
|
||||
// relative to the text baseline. This only has meaning
|
||||
// if the underscore mode is enabled with
|
||||
// set_underscore().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void TextProperties::
|
||||
set_underscore_height(float underscore_height) {
|
||||
_underscore_height = underscore_height;
|
||||
_specified |= F_has_underscore_height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::clear_underscore_height
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void TextProperties::
|
||||
clear_underscore_height() {
|
||||
_underscore_height = 0.0f;
|
||||
_specified &= ~F_has_underscore_height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::has_underscore_height
|
||||
// Access: Published
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool TextProperties::
|
||||
has_underscore_height() const {
|
||||
return (_specified & F_has_underscore_height) != 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::get_underscore_height
|
||||
// Access: Published
|
||||
// Description: Returns the vertical height of the underscore; see
|
||||
// set_underscore_height().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE float TextProperties::
|
||||
get_underscore_height() const {
|
||||
return _underscore_height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextProperties::set_align
|
||||
// Access: Published
|
||||
|
@ -41,6 +41,8 @@ TextProperties() {
|
||||
_small_caps = text_small_caps;
|
||||
_small_caps_scale = text_small_caps_scale;
|
||||
_slant = 0.0f;
|
||||
_underscore = false;
|
||||
_underscore_height = 0.0f;
|
||||
_align = A_left;
|
||||
_indent_width = 0.0f;
|
||||
_wordwrap_width = 0.0f;
|
||||
@ -77,6 +79,8 @@ operator = (const TextProperties ©) {
|
||||
_small_caps = copy._small_caps;
|
||||
_small_caps_scale = copy._small_caps_scale;
|
||||
_slant = copy._slant;
|
||||
_underscore = copy._underscore;
|
||||
_underscore_height = copy._underscore_height;
|
||||
_align = copy._align;
|
||||
_indent_width = copy._indent_width;
|
||||
_wordwrap_width = copy._wordwrap_width;
|
||||
@ -114,6 +118,12 @@ operator == (const TextProperties &other) const {
|
||||
if ((_specified & F_has_slant) && _slant != other._slant) {
|
||||
return false;
|
||||
}
|
||||
if ((_specified & F_has_underscore) && _underscore != other._underscore) {
|
||||
return false;
|
||||
}
|
||||
if ((_specified & F_has_underscore_height) && _underscore_height != other._underscore_height) {
|
||||
return false;
|
||||
}
|
||||
if ((_specified & F_has_align) && _align != other._align) {
|
||||
return false;
|
||||
}
|
||||
@ -187,6 +197,12 @@ add_properties(const TextProperties &other) {
|
||||
if (other.has_slant()) {
|
||||
set_slant(other.get_slant());
|
||||
}
|
||||
if (other.has_underscore()) {
|
||||
set_underscore(other.get_underscore());
|
||||
}
|
||||
if (other.has_underscore_height()) {
|
||||
set_underscore_height(other.get_underscore_height());
|
||||
}
|
||||
if (other.has_align()) {
|
||||
set_align(other.get_align());
|
||||
}
|
||||
@ -259,6 +275,14 @@ write(ostream &out, int indent_level) const {
|
||||
indent(out, indent_level)
|
||||
<< "slant = " << get_slant() << "\n";
|
||||
}
|
||||
if (has_underscore()) {
|
||||
indent(out, indent_level)
|
||||
<< "underscore = " << get_underscore() << "\n";
|
||||
}
|
||||
if (has_underscore_height()) {
|
||||
indent(out, indent_level)
|
||||
<< "underscore_height = " << get_underscore_height() << "\n";
|
||||
}
|
||||
|
||||
if (has_align()) {
|
||||
indent(out, indent_level)
|
||||
|
@ -88,6 +88,16 @@ PUBLISHED:
|
||||
INLINE bool has_slant() const;
|
||||
INLINE float get_slant() const;
|
||||
|
||||
INLINE void set_underscore(bool underscore);
|
||||
INLINE void clear_underscore();
|
||||
INLINE bool has_underscore() const;
|
||||
INLINE bool get_underscore() const;
|
||||
|
||||
INLINE void set_underscore_height(float underscore_height);
|
||||
INLINE void clear_underscore_height();
|
||||
INLINE bool has_underscore_height() const;
|
||||
INLINE float get_underscore_height() const;
|
||||
|
||||
INLINE void set_align(Alignment align_type);
|
||||
INLINE void clear_align();
|
||||
INLINE bool has_align() const;
|
||||
@ -159,22 +169,24 @@ private:
|
||||
static void load_default_font();
|
||||
|
||||
enum Flags {
|
||||
F_has_font = 0x0001,
|
||||
F_has_small_caps = 0x0002,
|
||||
F_has_small_caps_scale = 0x0004,
|
||||
F_has_slant = 0x0008,
|
||||
F_has_align = 0x0010,
|
||||
F_has_indent = 0x0020,
|
||||
F_has_wordwrap = 0x0040,
|
||||
F_has_preserve_trailing_whitespace = 0x0080,
|
||||
F_has_text_color = 0x0100,
|
||||
F_has_shadow_color = 0x0200,
|
||||
F_has_shadow = 0x0400,
|
||||
F_has_bin = 0x0800,
|
||||
F_has_draw_order = 0x1000,
|
||||
F_has_tab_width = 0x2000,
|
||||
F_has_glyph_scale = 0x4000,
|
||||
F_has_glyph_shift = 0x8000,
|
||||
F_has_font = 0x00000001,
|
||||
F_has_small_caps = 0x00000002,
|
||||
F_has_small_caps_scale = 0x00000004,
|
||||
F_has_slant = 0x00000008,
|
||||
F_has_align = 0x00000010,
|
||||
F_has_indent = 0x00000020,
|
||||
F_has_wordwrap = 0x00000040,
|
||||
F_has_preserve_trailing_whitespace = 0x00000080,
|
||||
F_has_text_color = 0x00000100,
|
||||
F_has_shadow_color = 0x00000200,
|
||||
F_has_shadow = 0x00000400,
|
||||
F_has_bin = 0x00000800,
|
||||
F_has_draw_order = 0x00001000,
|
||||
F_has_tab_width = 0x00002000,
|
||||
F_has_glyph_scale = 0x00004000,
|
||||
F_has_glyph_shift = 0x00008000,
|
||||
F_has_underscore = 0x00010000,
|
||||
F_has_underscore_height = 0x00020000,
|
||||
};
|
||||
|
||||
int _specified;
|
||||
@ -183,6 +195,8 @@ private:
|
||||
bool _small_caps;
|
||||
float _small_caps_scale;
|
||||
float _slant;
|
||||
bool _underscore;
|
||||
float _underscore_height;
|
||||
Alignment _align;
|
||||
float _indent_width;
|
||||
float _wordwrap_width;
|
||||
|
Loading…
x
Reference in New Issue
Block a user