mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
TextNode optimizations, more pgEntry stuff
This commit is contained in:
parent
0a29de84c2
commit
9e150511e1
@ -715,6 +715,7 @@ update_text() {
|
|||||||
|
|
||||||
_current_text =
|
_current_text =
|
||||||
_text_render_root.attach_new_node(assembled);
|
_text_render_root.attach_new_node(assembled);
|
||||||
|
_current_text.set_mat(node->get_transform());
|
||||||
_text_geom_stale = false;
|
_text_geom_stale = false;
|
||||||
_text_geom_flattened = false;
|
_text_geom_flattened = false;
|
||||||
_cursor_stale = true;
|
_cursor_stale = true;
|
||||||
|
@ -50,13 +50,13 @@ get_usage_hint() const {
|
|||||||
// max_rows will be accepted. Text beyond that will be
|
// max_rows will be accepted. Text beyond that will be
|
||||||
// truncated.
|
// truncated.
|
||||||
//
|
//
|
||||||
// The return value is true if all the text is accepted,
|
// Setting this will not truncate text immediately. You
|
||||||
// or false if some was truncated.
|
// must follow this up with a call to set_wtext() to
|
||||||
|
// truncate the existing text.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE bool TextAssembler::
|
INLINE void TextAssembler::
|
||||||
set_max_rows(int max_rows) {
|
set_max_rows(int max_rows) {
|
||||||
_max_rows = max_rows;
|
_max_rows = max_rows;
|
||||||
return wordwrap_text();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -55,7 +55,7 @@ PUBLISHED:
|
|||||||
INLINE void set_usage_hint(Geom::UsageHint usage_hint);
|
INLINE void set_usage_hint(Geom::UsageHint usage_hint);
|
||||||
INLINE Geom::UsageHint get_usage_hint() const;
|
INLINE Geom::UsageHint get_usage_hint() const;
|
||||||
|
|
||||||
INLINE bool set_max_rows(int max_rows);
|
INLINE void set_max_rows(int max_rows);
|
||||||
INLINE int get_max_rows() const;
|
INLINE int get_max_rows() const;
|
||||||
|
|
||||||
INLINE void set_properties(const TextProperties &properties);
|
INLINE void set_properties(const TextProperties &properties);
|
||||||
|
@ -47,7 +47,6 @@ get_line_height() const {
|
|||||||
INLINE void TextNode::
|
INLINE void TextNode::
|
||||||
set_max_rows(int max_rows) {
|
set_max_rows(int max_rows) {
|
||||||
_max_rows = max_rows;
|
_max_rows = max_rows;
|
||||||
_assembler.set_max_rows(_max_rows);
|
|
||||||
invalidate_with_measure();
|
invalidate_with_measure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +59,6 @@ set_max_rows(int max_rows) {
|
|||||||
INLINE void TextNode::
|
INLINE void TextNode::
|
||||||
clear_max_rows() {
|
clear_max_rows() {
|
||||||
_max_rows = 0;
|
_max_rows = 0;
|
||||||
_assembler.set_max_rows(_max_rows);
|
|
||||||
invalidate_with_measure();
|
invalidate_with_measure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,18 +381,14 @@ INLINE LVecBase4f TextNode::
|
|||||||
get_frame_actual() const {
|
get_frame_actual() const {
|
||||||
if (!has_frame()) {
|
if (!has_frame()) {
|
||||||
check_measure();
|
check_measure();
|
||||||
const LVector2f &ul = _assembler.get_ul();
|
return LVecBase4f(_text_ul[0], _text_lr[0], _text_lr[1], _text_ul[1]);
|
||||||
const LVector2f &lr = _assembler.get_lr();
|
|
||||||
return LVecBase4f(ul[0], lr[0], lr[1], ul[1]);
|
|
||||||
|
|
||||||
} else if (is_frame_as_margin()) {
|
} else if (is_frame_as_margin()) {
|
||||||
check_measure();
|
check_measure();
|
||||||
const LVector2f &ul = _assembler.get_ul();
|
return LVecBase4f(_text_ul[0] - _frame_ul[0],
|
||||||
const LVector2f &lr = _assembler.get_lr();
|
_text_lr[0] + _frame_lr[0],
|
||||||
return LVecBase4f(ul[0] - _frame_ul[0],
|
_text_lr[1] - _frame_lr[1],
|
||||||
lr[0] + _frame_lr[0],
|
_text_ul[1] + _frame_ul[1]);
|
||||||
lr[1] - _frame_lr[1],
|
|
||||||
ul[1] + _frame_ul[1]);
|
|
||||||
} else {
|
} else {
|
||||||
return get_frame_as_set();
|
return get_frame_as_set();
|
||||||
}
|
}
|
||||||
@ -588,18 +582,14 @@ INLINE LVecBase4f TextNode::
|
|||||||
get_card_actual() const {
|
get_card_actual() const {
|
||||||
if (!has_card()) {
|
if (!has_card()) {
|
||||||
check_measure();
|
check_measure();
|
||||||
const LVector2f &ul = _assembler.get_ul();
|
return LVecBase4f(_text_ul[0], _text_lr[0], _text_lr[1], _text_ul[1]);
|
||||||
const LVector2f &lr = _assembler.get_lr();
|
|
||||||
return LVecBase4f(ul[0], lr[0], lr[1], ul[1]);
|
|
||||||
|
|
||||||
} else if (is_card_as_margin()) {
|
} else if (is_card_as_margin()) {
|
||||||
check_measure();
|
check_measure();
|
||||||
const LVector2f &ul = _assembler.get_ul();
|
return LVecBase4f(_text_ul[0] - _card_ul[0],
|
||||||
const LVector2f &lr = _assembler.get_lr();
|
_text_lr[0] + _card_lr[0],
|
||||||
return LVecBase4f(ul[0] - _card_ul[0],
|
_text_lr[1] - _card_lr[1],
|
||||||
lr[0] + _card_lr[0],
|
_text_ul[1] + _card_ul[1]);
|
||||||
lr[1] - _card_lr[1],
|
|
||||||
ul[1] + _card_ul[1]);
|
|
||||||
} else {
|
} else {
|
||||||
return get_card_as_set();
|
return get_card_as_set();
|
||||||
}
|
}
|
||||||
@ -679,7 +669,7 @@ get_coordinate_system() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void TextNode::
|
INLINE void TextNode::
|
||||||
set_usage_hint(Geom::UsageHint usage_hint) {
|
set_usage_hint(Geom::UsageHint usage_hint) {
|
||||||
_assembler.set_usage_hint(usage_hint);
|
_usage_hint = usage_hint;
|
||||||
invalidate_no_measure();
|
invalidate_no_measure();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,7 +681,7 @@ set_usage_hint(Geom::UsageHint usage_hint) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE Geom::UsageHint TextNode::
|
INLINE Geom::UsageHint TextNode::
|
||||||
get_usage_hint() const {
|
get_usage_hint() const {
|
||||||
return _assembler.get_usage_hint();
|
return _usage_hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1246,7 +1236,7 @@ append_wtext(const wstring &wtext) {
|
|||||||
INLINE wstring TextNode::
|
INLINE wstring TextNode::
|
||||||
get_wordwrapped_wtext() const {
|
get_wordwrapped_wtext() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_wordwrapped_wtext();
|
return _wordwrapped_wtext;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1259,7 +1249,7 @@ get_wordwrapped_wtext() const {
|
|||||||
INLINE float TextNode::
|
INLINE float TextNode::
|
||||||
get_left() const {
|
get_left() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_ul()[0];
|
return _text_ul[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1272,7 +1262,7 @@ get_left() const {
|
|||||||
INLINE float TextNode::
|
INLINE float TextNode::
|
||||||
get_right() const {
|
get_right() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_lr()[0];
|
return _text_lr[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1285,7 +1275,7 @@ get_right() const {
|
|||||||
INLINE float TextNode::
|
INLINE float TextNode::
|
||||||
get_bottom() const {
|
get_bottom() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_lr()[1];
|
return _text_lr[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1298,7 +1288,7 @@ get_bottom() const {
|
|||||||
INLINE float TextNode::
|
INLINE float TextNode::
|
||||||
get_top() const {
|
get_top() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_ul()[1];
|
return _text_ul[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1310,7 +1300,7 @@ get_top() const {
|
|||||||
INLINE float TextNode::
|
INLINE float TextNode::
|
||||||
get_height() const {
|
get_height() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_ul()[1] - _assembler.get_lr()[1];
|
return _text_ul[1] - _text_lr[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1322,7 +1312,7 @@ get_height() const {
|
|||||||
INLINE float TextNode::
|
INLINE float TextNode::
|
||||||
get_width() const {
|
get_width() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_lr()[0] - _assembler.get_ul()[0];
|
return _text_lr[0] - _text_ul[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1361,7 +1351,7 @@ get_lower_right_3d() const {
|
|||||||
INLINE int TextNode::
|
INLINE int TextNode::
|
||||||
get_num_rows() const {
|
get_num_rows() const {
|
||||||
check_measure();
|
check_measure();
|
||||||
return _assembler.get_num_rows();
|
return _num_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -64,11 +64,12 @@ static PStatCollector text_generate_collector("*:Generate Text");
|
|||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
TextNode::
|
TextNode::
|
||||||
TextNode(const string &name) : PandaNode(name), _assembler(this) {
|
TextNode(const string &name) : PandaNode(name) {
|
||||||
set_cull_callback();
|
set_cull_callback();
|
||||||
|
|
||||||
_flags = 0;
|
_flags = 0;
|
||||||
_max_rows = 0;
|
_max_rows = 0;
|
||||||
|
_usage_hint = GeomEnums::UH_static;
|
||||||
|
|
||||||
if (text_small_caps) {
|
if (text_small_caps) {
|
||||||
set_small_caps(true);
|
set_small_caps(true);
|
||||||
@ -100,8 +101,7 @@ TextNode(const string &name) : PandaNode(name), _assembler(this) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
TextNode::
|
TextNode::
|
||||||
TextNode(const string &name, const TextProperties ©) :
|
TextNode(const string &name, const TextProperties ©) :
|
||||||
PandaNode(name), TextProperties(copy),
|
PandaNode(name), TextProperties(copy)
|
||||||
_assembler(this)
|
|
||||||
{
|
{
|
||||||
_flags = 0;
|
_flags = 0;
|
||||||
_max_rows = 0;
|
_max_rows = 0;
|
||||||
@ -148,8 +148,7 @@ TextNode(const TextNode ©) :
|
|||||||
_transform(copy._transform),
|
_transform(copy._transform),
|
||||||
_coordinate_system(copy._coordinate_system),
|
_coordinate_system(copy._coordinate_system),
|
||||||
_ul3d(copy._ul3d),
|
_ul3d(copy._ul3d),
|
||||||
_lr3d(copy._lr3d),
|
_lr3d(copy._lr3d)
|
||||||
_assembler(this)
|
|
||||||
{
|
{
|
||||||
invalidate_with_measure();
|
invalidate_with_measure();
|
||||||
}
|
}
|
||||||
@ -190,7 +189,7 @@ calc_width(int character) const {
|
|||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _assembler.calc_width(character, *this);
|
return TextAssembler::calc_width(character, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -302,8 +301,11 @@ generate() {
|
|||||||
wstring wtext = get_wtext();
|
wstring wtext = get_wtext();
|
||||||
|
|
||||||
// Assemble the text.
|
// Assemble the text.
|
||||||
_assembler.set_properties(*this);
|
TextAssembler assembler(this);
|
||||||
bool all_set = _assembler.set_wtext(wtext);
|
assembler.set_properties(*this);
|
||||||
|
assembler.set_max_rows(_max_rows);
|
||||||
|
assembler.set_usage_hint(_usage_hint);
|
||||||
|
bool all_set = assembler.set_wtext(wtext);
|
||||||
if (all_set) {
|
if (all_set) {
|
||||||
// No overflow.
|
// No overflow.
|
||||||
_flags &= ~F_has_overflow;
|
_flags &= ~F_has_overflow;
|
||||||
@ -312,7 +314,11 @@ generate() {
|
|||||||
_flags |= F_has_overflow;
|
_flags |= F_has_overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
PT(PandaNode) text_root = _assembler.assemble_text();
|
PT(PandaNode) text_root = assembler.assemble_text();
|
||||||
|
_text_ul = assembler.get_ul();
|
||||||
|
_text_lr = assembler.get_lr();
|
||||||
|
_num_rows = assembler.get_num_rows();
|
||||||
|
_wordwrapped_wtext = assembler.get_wordwrapped_wtext();
|
||||||
|
|
||||||
// Parent the text in.
|
// Parent the text in.
|
||||||
PT(PandaNode) text = new PandaNode("text");
|
PT(PandaNode) text = new PandaNode("text");
|
||||||
@ -321,8 +327,8 @@ generate() {
|
|||||||
|
|
||||||
// Save the bounding-box information about the text in a form
|
// Save the bounding-box information about the text in a form
|
||||||
// friendly to the user.
|
// friendly to the user.
|
||||||
const LVector2f &ul = _assembler.get_ul();
|
const LVector2f &ul = assembler.get_ul();
|
||||||
const LVector2f &lr = _assembler.get_lr();
|
const LVector2f &lr = assembler.get_lr();
|
||||||
_ul3d.set(ul[0], 0.0f, ul[1]);
|
_ul3d.set(ul[0], 0.0f, ul[1]);
|
||||||
_lr3d.set(lr[0], 0.0f, lr[1]);
|
_lr3d.set(lr[0], 0.0f, lr[1]);
|
||||||
|
|
||||||
|
@ -284,6 +284,7 @@ private:
|
|||||||
|
|
||||||
int _flags;
|
int _flags;
|
||||||
int _max_rows;
|
int _max_rows;
|
||||||
|
GeomEnums::UsageHint _usage_hint;
|
||||||
float _frame_width;
|
float _frame_width;
|
||||||
float _card_border_size;
|
float _card_border_size;
|
||||||
float _card_border_uv_portion;
|
float _card_border_uv_portion;
|
||||||
@ -296,7 +297,10 @@ private:
|
|||||||
|
|
||||||
LPoint3f _ul3d, _lr3d;
|
LPoint3f _ul3d, _lr3d;
|
||||||
|
|
||||||
TextAssembler _assembler;
|
// Returned from TextAssembler:
|
||||||
|
LVector2f _text_ul, _text_lr;
|
||||||
|
int _num_rows;
|
||||||
|
wstring _wordwrapped_wtext;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static TypeHandle get_class_type() {
|
static TypeHandle get_class_type() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user