TextNode optimizations, more pgEntry stuff

This commit is contained in:
David Rose 2007-07-12 17:26:50 +00:00
parent 0a29de84c2
commit 9e150511e1
6 changed files with 48 additions and 47 deletions

View File

@ -715,6 +715,7 @@ update_text() {
_current_text =
_text_render_root.attach_new_node(assembled);
_current_text.set_mat(node->get_transform());
_text_geom_stale = false;
_text_geom_flattened = false;
_cursor_stale = true;

View File

@ -50,13 +50,13 @@ get_usage_hint() const {
// max_rows will be accepted. Text beyond that will be
// truncated.
//
// The return value is true if all the text is accepted,
// or false if some was truncated.
// Setting this will not truncate text immediately. You
// 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) {
_max_rows = max_rows;
return wordwrap_text();
}
////////////////////////////////////////////////////////////////////

View File

@ -55,7 +55,7 @@ PUBLISHED:
INLINE void set_usage_hint(Geom::UsageHint usage_hint);
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 void set_properties(const TextProperties &properties);

View File

@ -47,7 +47,6 @@ get_line_height() const {
INLINE void TextNode::
set_max_rows(int max_rows) {
_max_rows = max_rows;
_assembler.set_max_rows(_max_rows);
invalidate_with_measure();
}
@ -60,7 +59,6 @@ set_max_rows(int max_rows) {
INLINE void TextNode::
clear_max_rows() {
_max_rows = 0;
_assembler.set_max_rows(_max_rows);
invalidate_with_measure();
}
@ -383,18 +381,14 @@ INLINE LVecBase4f TextNode::
get_frame_actual() const {
if (!has_frame()) {
check_measure();
const LVector2f &ul = _assembler.get_ul();
const LVector2f &lr = _assembler.get_lr();
return LVecBase4f(ul[0], lr[0], lr[1], ul[1]);
return LVecBase4f(_text_ul[0], _text_lr[0], _text_lr[1], _text_ul[1]);
} else if (is_frame_as_margin()) {
check_measure();
const LVector2f &ul = _assembler.get_ul();
const LVector2f &lr = _assembler.get_lr();
return LVecBase4f(ul[0] - _frame_ul[0],
lr[0] + _frame_lr[0],
lr[1] - _frame_lr[1],
ul[1] + _frame_ul[1]);
return LVecBase4f(_text_ul[0] - _frame_ul[0],
_text_lr[0] + _frame_lr[0],
_text_lr[1] - _frame_lr[1],
_text_ul[1] + _frame_ul[1]);
} else {
return get_frame_as_set();
}
@ -588,18 +582,14 @@ INLINE LVecBase4f TextNode::
get_card_actual() const {
if (!has_card()) {
check_measure();
const LVector2f &ul = _assembler.get_ul();
const LVector2f &lr = _assembler.get_lr();
return LVecBase4f(ul[0], lr[0], lr[1], ul[1]);
return LVecBase4f(_text_ul[0], _text_lr[0], _text_lr[1], _text_ul[1]);
} else if (is_card_as_margin()) {
check_measure();
const LVector2f &ul = _assembler.get_ul();
const LVector2f &lr = _assembler.get_lr();
return LVecBase4f(ul[0] - _card_ul[0],
lr[0] + _card_lr[0],
lr[1] - _card_lr[1],
ul[1] + _card_ul[1]);
return LVecBase4f(_text_ul[0] - _card_ul[0],
_text_lr[0] + _card_lr[0],
_text_lr[1] - _card_lr[1],
_text_ul[1] + _card_ul[1]);
} else {
return get_card_as_set();
}
@ -679,7 +669,7 @@ get_coordinate_system() const {
////////////////////////////////////////////////////////////////////
INLINE void TextNode::
set_usage_hint(Geom::UsageHint usage_hint) {
_assembler.set_usage_hint(usage_hint);
_usage_hint = usage_hint;
invalidate_no_measure();
}
@ -691,7 +681,7 @@ set_usage_hint(Geom::UsageHint usage_hint) {
////////////////////////////////////////////////////////////////////
INLINE Geom::UsageHint TextNode::
get_usage_hint() const {
return _assembler.get_usage_hint();
return _usage_hint;
}
////////////////////////////////////////////////////////////////////
@ -1246,7 +1236,7 @@ append_wtext(const wstring &wtext) {
INLINE wstring TextNode::
get_wordwrapped_wtext() const {
check_measure();
return _assembler.get_wordwrapped_wtext();
return _wordwrapped_wtext;
}
////////////////////////////////////////////////////////////////////
@ -1259,7 +1249,7 @@ get_wordwrapped_wtext() const {
INLINE float TextNode::
get_left() const {
check_measure();
return _assembler.get_ul()[0];
return _text_ul[0];
}
////////////////////////////////////////////////////////////////////
@ -1272,7 +1262,7 @@ get_left() const {
INLINE float TextNode::
get_right() const {
check_measure();
return _assembler.get_lr()[0];
return _text_lr[0];
}
////////////////////////////////////////////////////////////////////
@ -1285,7 +1275,7 @@ get_right() const {
INLINE float TextNode::
get_bottom() const {
check_measure();
return _assembler.get_lr()[1];
return _text_lr[1];
}
////////////////////////////////////////////////////////////////////
@ -1298,7 +1288,7 @@ get_bottom() const {
INLINE float TextNode::
get_top() const {
check_measure();
return _assembler.get_ul()[1];
return _text_ul[1];
}
////////////////////////////////////////////////////////////////////
@ -1310,7 +1300,7 @@ get_top() const {
INLINE float TextNode::
get_height() const {
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::
get_width() const {
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::
get_num_rows() const {
check_measure();
return _assembler.get_num_rows();
return _num_rows;
}
////////////////////////////////////////////////////////////////////

View File

@ -64,11 +64,12 @@ static PStatCollector text_generate_collector("*:Generate Text");
// Description:
////////////////////////////////////////////////////////////////////
TextNode::
TextNode(const string &name) : PandaNode(name), _assembler(this) {
TextNode(const string &name) : PandaNode(name) {
set_cull_callback();
_flags = 0;
_max_rows = 0;
_usage_hint = GeomEnums::UH_static;
if (text_small_caps) {
set_small_caps(true);
@ -100,8 +101,7 @@ TextNode(const string &name) : PandaNode(name), _assembler(this) {
////////////////////////////////////////////////////////////////////
TextNode::
TextNode(const string &name, const TextProperties &copy) :
PandaNode(name), TextProperties(copy),
_assembler(this)
PandaNode(name), TextProperties(copy)
{
_flags = 0;
_max_rows = 0;
@ -148,8 +148,7 @@ TextNode(const TextNode &copy) :
_transform(copy._transform),
_coordinate_system(copy._coordinate_system),
_ul3d(copy._ul3d),
_lr3d(copy._lr3d),
_assembler(this)
_lr3d(copy._lr3d)
{
invalidate_with_measure();
}
@ -190,7 +189,7 @@ calc_width(int character) const {
return 0.0f;
}
return _assembler.calc_width(character, *this);
return TextAssembler::calc_width(character, *this);
}
////////////////////////////////////////////////////////////////////
@ -302,8 +301,11 @@ generate() {
wstring wtext = get_wtext();
// Assemble the text.
_assembler.set_properties(*this);
bool all_set = _assembler.set_wtext(wtext);
TextAssembler assembler(this);
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) {
// No overflow.
_flags &= ~F_has_overflow;
@ -312,7 +314,11 @@ generate() {
_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.
PT(PandaNode) text = new PandaNode("text");
@ -321,8 +327,8 @@ generate() {
// Save the bounding-box information about the text in a form
// friendly to the user.
const LVector2f &ul = _assembler.get_ul();
const LVector2f &lr = _assembler.get_lr();
const LVector2f &ul = assembler.get_ul();
const LVector2f &lr = assembler.get_lr();
_ul3d.set(ul[0], 0.0f, ul[1]);
_lr3d.set(lr[0], 0.0f, lr[1]);

View File

@ -284,6 +284,7 @@ private:
int _flags;
int _max_rows;
GeomEnums::UsageHint _usage_hint;
float _frame_width;
float _card_border_size;
float _card_border_uv_portion;
@ -296,7 +297,10 @@ private:
LPoint3f _ul3d, _lr3d;
TextAssembler _assembler;
// Returned from TextAssembler:
LVector2f _text_ul, _text_lr;
int _num_rows;
wstring _wordwrapped_wtext;
public:
static TypeHandle get_class_type() {