-
Notifications
You must be signed in to change notification settings - Fork 2
/
rich_text3d.cpp
690 lines (586 loc) · 22.3 KB
/
rich_text3d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#include "engine/richtext/rich_text3d.h"
#include "engine/richtext/rich_batch_text.h"
#include "engine/richtext/rich_batch_image.h"
#include "Urho3D/Core/StringUtils.h"
#include "rich_html_parser.h"
namespace Urho3D
{
namespace
{
inline unsigned find_first_of(const String& str, const String& delimiters, unsigned offset = 0) {
if (offset >= str.Length())
return -1;
for (unsigned i = offset; i < str.Length(); i++) {
for (String::ConstIterator it = delimiters.Begin(); it != delimiters.End(); ++it)
if ((*it) == str.At(i))
return i;
}
return -1;
}
// Characters that split words
static const char splitter_chars[] = " \t,.:;";
// Old code kept for 1:1 compatibility
template <typename T>
inline void splitwords(const String& str, T& tokens, const String& delimiters = " ", bool trimEmpty = false) {
unsigned pos, lastPos = 0;
while(true) {
pos = find_first_of(str, delimiters, lastPos);
if(pos == String::NPOS) {
pos = str.Length();
if(pos != lastPos || !trimEmpty)
tokens.Push(typename T::ValueType(str.CString() + lastPos,
pos - lastPos));
break;
} else {
if(pos != lastPos) {
tokens.Push(typename T::ValueType(str.CString() + lastPos, pos - lastPos));
}
if (!trimEmpty)
tokens.Push(typename T::ValueType(str.CString() + pos, 1 ));
}
lastPos = pos + 1;
}
}
} // namespace
static const char* ticker_types[] =
{
"None",
"Horizontal",
"Vertical",
"Both",
0
};
static const char* ticker_directions[] =
{
"Negative",
"Positive",
0
};
static const char* horizontal_alignments[] =
{
"Left",
"Center",
"Right",
0
};
extern const char* GEOMETRY_CATEGORY;
/// Register object factory. Drawable must be registered first.
void RichText3D::RegisterObject(Context* context) {
context->RegisterFactory<RichText3D>(GEOMETRY_CATEGORY);
//URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Draw Origin", GetDrawOrigin, SetDrawOrigin, Vector3, Vector3::ZERO, AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE("Is Enabled", IsEnabled, SetEnabled, bool, false, AM_FILE);
URHO3D_ACCESSOR_ATTRIBUTE("Text", GetText, SetText, String, String::EMPTY, AM_DEFAULT);
URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Font", GetFontAttr, SetFontAttr, ResourceRef, ResourceRef(Font::GetTypeStatic()), AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE("Font Size", GetFontSizeAttr, SetFontSizeAttr, int, 14, AM_DEFAULT);
URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Color", GetTextColor, SetTextColor, Color, Color::WHITE, AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE("Word Wrap", GetWrapping, SetWrapping, bool, true, AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE("Single Line", GetSingleLine, SetSingleLine, bool, false, AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE("Line Spacing", GetLineSpacing, SetLineSpacing, int, 0, AM_DEFAULT);
URHO3D_ENUM_ACCESSOR_ATTRIBUTE("Text Alignment", GetAlignment, SetAlignment, HorizontalAlignment,
horizontal_alignments, HA_LEFT, AM_DEFAULT);
URHO3D_ENUM_ACCESSOR_ATTRIBUTE("Ticker Type", GetTickerType, SetTickerType, TickerType,
ticker_types, TickerType_None, AM_DEFAULT);
URHO3D_ENUM_ACCESSOR_ATTRIBUTE("Ticker Direction", GetTickerDirection, SetTickerDirection, TickerDirection,
ticker_directions, TickerDirection_Negative, AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE("Ticker Speed", GetTickerSpeed, SetTickerSpeed, float, 120, AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE("Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
URHO3D_COPY_BASE_ATTRIBUTES(RichWidget);
URHO3D_COPY_BASE_ATTRIBUTES(Drawable);
}
RichText3D::RichText3D(Context* context)
: ticker_type_(TickerType_None)
, ticker_direction_(TickerDirection_Negative)
, ticker_speed_(60)
, scroll_origin_(0.0f, 0.0f)
, single_line_(false)
, wrapping_(WRAP_WORD)
, ticker_position_(0.0f)
, line_spacing_(0)
, RichWidget(context)
{
default_format_.color = Color::WHITE;
SetDefaultFont("Fonts/Anonymous Pro.ttf", 32);
// TODO: disable this handler when the component is disabled
SubscribeToEvent(Urho3D::E_SCENEUPDATE, URHO3D_HANDLER(RichText3D, UpdateTickerAnimation));
}
RichText3D::~RichText3D()
{
}
void RichText3D::SetText(const String& text)
{
text_ = text;
SetFlags(WidgetFlags_ContentChanged);
CompileTextLayout();
ResetTicker();
}
const String& RichText3D::GetText() const
{
return text_;
}
void RichText3D::SetTextColor(const Color& color)
{
default_format_.color = color;
SetFlags(WidgetFlags_ContentChanged);
}
void RichText3D::SetAlignment(HorizontalAlignment align)
{
default_format_.align = align;
SetFlags(WidgetFlags_ContentChanged);
}
void RichText3D::SetLineSpacing(int line_spacing) {
line_spacing_ = line_spacing;
SetFlags(WidgetFlags_ContentChanged);
}
void RichText3D::SetTickerType(TickerType type)
{
ticker_type_ = type;
ResetTicker();
}
void RichText3D::SetWrapping(bool wrapping) {
wrapping_ = wrapping ? WRAP_WORD : WRAP_NONE;
SetFlags(WidgetFlags_ContentChanged);
}
TickerType RichText3D::GetTickerType() const
{
return ticker_type_;
}
void RichText3D::SetTickerDirection(TickerDirection direction)
{
ticker_direction_ = direction;
ResetTicker();
}
TickerDirection RichText3D::GetTickerDirection() const
{
return ticker_direction_;
}
void RichText3D::SetTickerSpeed(float pixelspersecond)
{
ticker_speed_ = pixelspersecond;
}
float RichText3D::GetTickerSpeed() const
{
return ticker_speed_;
}
void RichText3D::SetSingleLine(bool single_line)
{
single_line_ = single_line;
SetFlags(WidgetFlags_ContentChanged);
}
void RichText3D::ResetTicker()
{
scroll_origin_ = Vector3::ZERO;
auto content_area = GetActualDrawArea();
if (ticker_type_ == TickerType_Horizontal)
{
if (ticker_direction_ == TickerDirection_Negative)
scroll_origin_ = Vector3(content_area.Right(), 0.0f, 0.0f);
else
scroll_origin_ = Vector3(-content_size_.x_, 0.0f, 0.0f);
}
else if (ticker_type_ == TickerType_Vertical)
{
if (ticker_direction_ == TickerDirection_Negative)
scroll_origin_ = Vector3(0.0f, GetActualDrawArea().Bottom(), 0.0f);
else
scroll_origin_ = Vector3(0.0f, -content_size_.y_, 0.0f);
}
else
{
scroll_origin_ = Vector3::ZERO;
SetDrawOrigin(scroll_origin_);
}
ticker_position_ = 0.0f;
}
float RichText3D::GetTickerPosition() const
{
return ticker_position_;
}
void RichText3D::SetTickerPosition(float tickerPosition)
{
// TODO: implement
}
void RichText3D::SetDefaultFont(const String& face, unsigned size)
{
default_format_.font.face = face;
default_format_.font.size = size;
default_format_.font.bold = false;
default_format_.font.italic = false;
SetFlags(WidgetFlags_ContentChanged);
}
ResourceRef RichText3D::GetFontAttr() const
{
return ResourceRef(Font::GetTypeStatic(), default_format_.font.face);
}
void RichText3D::SetFontAttr(const ResourceRef& value)
{
default_format_.font.face = value.name_;
SetFlags(WidgetFlags_ContentChanged);
}
int RichText3D::GetFontSizeAttr() const
{
return default_format_.font.size;
}
void RichText3D::SetFontSizeAttr(int size)
{
default_format_.font.size = size;
SetFlags(WidgetFlags_ContentChanged);
}
void RichText3D::ArrangeTextBlocks(Vector<TextBlock>& markup_blocks)
{
TextLine line;
if (!single_line_) {
Vector<TextLine> markupLines;
// for every new line in a block, create a new TextLine
for (Vector<TextBlock>::ConstIterator it = markup_blocks.Begin(); it != markup_blocks.End(); ++it) {
size_t posNewLine = 0;
size_t posLast = 0;
if ((posNewLine = it->text.Find("\n", posLast)) != String::NPOS) {
while ((posNewLine = it->text.Find("\n", posLast)) != String::NPOS) {
TextBlock block;
block.text = it->text.Substring(posLast, posNewLine - posLast);
block.format = it->format;
line.blocks.Push(block);
markupLines.Push(line);
posLast = posNewLine + 1;
line.blocks.Clear();
}
if (posLast < it->text.Length() - 1) {
TextBlock block;
block.text = it->text.Substring(posLast, it->text.Length() - posLast);
block.format = it->format;
line.blocks.Push(block);
}
} else {
if (it->is_line_break) {
line.blocks.Push(*it);
markupLines.Push(line);
line.blocks.Clear();
}
line.blocks.Push(*it);
// update line alignment from this block if it is not left
if (it->format.align != HA_LEFT)
line.align = it->format.align;
}
}
// make sure there's at least one line with text
if (!line.blocks.Empty())
markupLines.Push(line);
IntRect actual_clip_region = GetClipRegion();
// do the word wrapping and layout positioning
if (wrapping_ == WRAP_WORD && actual_clip_region.Width()) {
int layout_width = actual_clip_region.Width();
int layout_height = actual_clip_region.Height();
int layout_x = actual_clip_region.left_;
int layout_y = actual_clip_region.top_;
int draw_offset_x = layout_x;
int draw_offset_y = layout_y;
FontState fontstate;
for (Vector<TextLine>::Iterator it = markupLines.Begin(); it != markupLines.End(); ++it) {
TextLine* line = &*it;
TextLine new_line;
new_line.height = 0;
new_line.width = 0;
new_line.offset_x = layout_x;
new_line.offset_y = 0;
new_line.align = line->align;
// reset the x offset of the current line
draw_offset_x = layout_x;
for (Vector<TextBlock>::Iterator bit = line->blocks.Begin(); bit != line->blocks.End(); ++bit) {
TextBlock new_block;
new_block.format = (*bit).format;
if (bit->type == TextBlock::BlockType_Text) {
size_t crpos;
while ((crpos = bit->text.Find("\r")) != String::NPOS)
bit->text.Erase(crpos, 1);
Vector<String> words;
splitwords(bit->text, words, splitter_chars, false);
if (words.Empty())
words.Push(bit->text);
bool new_line_space = false;
// bold-italic flags are passed as third asset name parameter
String bi = String(bit->format.font.bold ? "b" : "") + String(bit->format.font.italic ? "i" : "");
if (!bi.Empty())
bi = String(".") + bi;
// this block's text renderer
String id;
fontstate.face = bit->format.font.face;
fontstate.size = bit->format.font.size;
if (fontstate.face.Empty())
fontstate.face = default_format_.font.face;
if (fontstate.size <= 0)
fontstate.size = default_format_.font.size;
id.AppendWithFormat("%s.%d%s", fontstate.face.CString(), fontstate.size, bi.CString());
RichWidgetText* text_renderer = CacheWidgetBatch<RichWidgetText>(id);
text_renderer->SetFont(fontstate.face, fontstate.size);
// for every word in this block do a check if there's enough space on the current line
// Simple word wrap logic: if the space is enough, put the word on the current line, else go to the next line
String the_word;
for (Vector<String>::ConstIterator wit = words.Begin(); wit != words.End(); ++wit) {
the_word = *wit;
Vector2 wordsize = text_renderer->CalculateTextExtents(the_word);
new_line.height = Max<int>((int)wordsize.y_, new_line.height);
bool needs_new_line = (draw_offset_x + wordsize.x_) > layout_width;
bool is_wider_than_line = wordsize.x_ > layout_width;
// Handle cases where this word can't be fit in a line
while (is_wider_than_line && needs_new_line) {
String fit_word = the_word;
int width_remain = (int)wordsize.x_ - layout_width;
assert(width_remain >= 0);
// remove a char from this word until it can be fit in the current line
Vector2 newwordsize;
while (width_remain > 0 && !the_word.Empty()) {
fit_word.Erase(fit_word.Length() - 1);
newwordsize = text_renderer->CalculateTextExtents(fit_word);
width_remain = (int)newwordsize.x_ - layout_width;
}
// prevent endless loops
if (fit_word.Empty())
break;
// append the fitting part of the word in the current line
// and create a new line
new_block.text.Append(fit_word);
new_line.blocks.Push(new_block);
draw_offset_x += (int)newwordsize.x_;
new_line.width = draw_offset_x;
new_line.offset_y = draw_offset_y;
lines_.Push(new_line);
// create a new empty line
new_line.blocks.Clear();
new_block.text.Clear();
draw_offset_x = layout_x;
draw_offset_y += new_line.height;
the_word = the_word.Substring(fit_word.Length());
wordsize = text_renderer->CalculateTextExtents(the_word);
draw_offset_x += (int)wordsize.x_;
is_wider_than_line = wordsize.x_ > layout_width;
if (!is_wider_than_line) {
needs_new_line = false;
// the leftovers from the_word will be added to the line below
break;
}
}
// carry the whole word on a new line
if (needs_new_line) {
new_line.width = draw_offset_x;
new_line.offset_y = draw_offset_y;
new_line.blocks.Push(new_block);
lines_.Push(new_line);
// create next empty line
new_line.blocks.Clear();
// add current text to a block
new_block.text.Clear();
draw_offset_x = layout_x;
draw_offset_y += new_line.height;
if (the_word == " " || the_word == "\t") {
// mark as space
new_line_space = true;
continue;
}
}
if (new_line_space) {
if (the_word != " " && the_word != "\t")
new_line_space = false;
else
continue;
}
new_block.text.Append(the_word);
draw_offset_x += (int)wordsize.x_;
}
new_line.blocks.Push(new_block);
} else {
// if the block is iconic (image, video, etc)
new_block = (*bit); // copy the block
if (new_block.is_visible) {
RichWidgetImage* image_renderer = CacheWidgetBatch<RichWidgetImage>(new_block.text);
image_renderer->SetImageSource(new_block.text);
if (new_block.image_height == 0) {
float aspect = image_renderer->GetImageAspect();
if (aspect == 0.f)
aspect = 1.0f;
// fit by height
//new_block.image_height = clip_region_.height();
//new_block.image_width = new_block.image_height * aspect;
// fit by width
new_block.image_width = (float)(new_block.image_width > 0 ? new_block.image_width : clip_region_.Width());
new_block.image_height = new_block.image_width / aspect;
}
if (new_block.image_width == 0) {
new_block.image_width = (float)clip_region_.Width();
}
new_line.blocks.Push(new_block);
draw_offset_x += (int)new_block.image_width;
new_line.height = Max((int)new_block.image_height, new_line.height);
}
}
new_line.width = draw_offset_x;
new_line.offset_y = draw_offset_y;
draw_offset_y += new_line.height;
}
lines_.Push(new_line);
new_line.blocks.Clear();
}
} else {
// in case there's no word wrapping or the layout has no width
lines_ = markupLines;
}
} else {
// Single line...
// replace /n/r with empty space
for (auto i = markup_blocks.Begin(); i != markup_blocks.End(); i++) {
size_t crpos;
while ((crpos = find_first_of(i->text, "\n\r")) != String::NPOS) {
i->text.Replace(crpos, 1, " ");
}
// TODO: single line doesn't get images when width or height = 0
line.blocks.Push(*i);
}
lines_.Push(line);
}
}
void RichText3D::DrawTextLines() {
// clear all quads
Clear();
RichWidgetText* text_renderer;
RichWidgetImage* image_renderer;
int xoffset = 0, yoffset = 0;
for (auto lit = lines_.Begin(); lit != lines_.End(); ++lit) {
// adjust the size and offset of every block in a line
TextLine* l = &(*lit);
switch (l->align) {
default:
case HA_LEFT:
xoffset = l->offset_x;
break;
case HA_CENTER:
xoffset = (clip_region_.Width() - l->width) / 2;
break;
case HA_RIGHT:
xoffset = clip_region_.Width() - l->width;
}
FontState fontstate;
int line_max_height = 0;
for (auto it = l->blocks.Begin(); it != l->blocks.End(); ++it) {
if (it->type == TextBlock::BlockType_Image) {
image_renderer = CacheWidgetBatch<RichWidgetImage>(it->text);
//image_renderer->clearQuads();
if (image_renderer->GetImageSource() != it->text)
image_renderer->SetImageSource(it->text);
if (it->image_width == 0)
it->image_width = (float)clip_region_.Width();
if (it->image_height == 0) {
// height should be the line max height
it->image_height = (float)line_max_height;
// width should be auto calculated based on the texture size
float aspect = image_renderer->GetImageAspect();
it->image_width = it->image_height * aspect;
}
image_renderer->AddImage(Vector3((float)xoffset, (float)yoffset, 0.0f), it->image_width, it->image_height);
line_max_height = Max((int)it->image_height, line_max_height);
xoffset += (int)it->image_width;
} else if (it->type == TextBlock::BlockType_Text) {
fontstate = it->format.font;
if (fontstate.face.Empty())
fontstate.face = default_format_.font.face;
if (fontstate.size <= 0)
fontstate.size = default_format_.font.size;
String bi = String(it->format.font.bold ? "b" : "") + String(it->format.font.italic ? "i" : "");
if (!bi.Empty())
bi = String(".") + bi;
String id = fontstate.face + "." + ToString("%d", it->format.font.size) + bi;
id.AppendWithFormat("%s.%d%s", fontstate.face.CString(), fontstate.size, bi.CString());
text_renderer = CacheWidgetBatch<RichWidgetText>(id);
// TODO: turn this back on when we have more fonts
text_renderer->SetFont(fontstate.face, fontstate.size, fontstate.bold, fontstate.italic);
//text_renderer->SetFont(default_font_state_.face, default_font_state_.size);
text_renderer->AddText(it->text, Vector3((float)xoffset, (float)yoffset, 0.0f), it->format.color);
if (text_renderer->GetFontFace()) {
line_max_height = Max<int>((int)text_renderer->GetRowHeight(), line_max_height);
xoffset += (int)text_renderer->CalculateTextExtents(it->text).x_;
}
}
}
yoffset += line_max_height + line_spacing_;
content_size_.x_ = Max<float>(content_size_.x_, xoffset);
content_size_.y_ = (float)yoffset;
}
ResetTicker();
}
void RichText3D::CompileTextLayout() {
lines_.Clear();
content_size_ = Vector2::ZERO;
Vector<TextBlock> markup_blocks;
markup_blocks.Reserve(10);
HTMLParser::Parse(text_, markup_blocks, default_format_);
ArrangeTextBlocks(markup_blocks);
DrawTextLines();
ClearFlags(WidgetFlags_ContentChanged);
SetFlags(WidgetFlags_GeometryDirty);
}
void RichText3D::UpdateTickerAnimation(Urho3D::StringHash eventType, Urho3D::VariantMap& eventData)
{
using namespace RenderUpdate;
float elapsed = eventData[P_TIMESTEP].GetFloat();
if (!IsEnabled())
return;
if (IsFlagged(WidgetFlags_ContentChanged))
{
CompileTextLayout();
ClearFlags(WidgetFlags_ContentChanged);
}
// Update ticker state
if (ticker_type_ != TickerType_None)
{
// ticker direction sign
int vertical_dir = 0, horizontal_dir = 0;
if (ticker_type_ == TickerType_Horizontal)
{
if (ticker_direction_ == TickerDirection_Negative)
horizontal_dir = -1;
else
horizontal_dir = 1;
}
else if (ticker_type_ == TickerType_Vertical)
{
if (ticker_direction_ == TickerDirection_Negative)
vertical_dir = -1;
else
vertical_dir = 1;
}
// move the ticker, cap the time elapsed to 100ms to prevent long jumps
float move_factor = ticker_speed_ * (elapsed < 0.1f ? elapsed : 0.1f);
scroll_origin_.x_ += horizontal_dir * move_factor;
scroll_origin_.y_ += vertical_dir * move_factor;
// move the content
SetDrawOrigin(scroll_origin_);
// check if the text has scrolled out
bool scrolled_out = false;
float ticker_max;
IntRect actual_clip_region = GetClipRegion();
// detect ticker scrolling out of the clip region and update the ticker position
if (ticker_type_ == TickerType_Horizontal)
{
if (clip_to_content_)
ticker_max = (horizontal_dir == -1 ? content_size_.x_ : content_size_.x_ + actual_clip_region.Width());
else
ticker_max = (horizontal_dir == -1 ? content_size_.x_ : content_size_.x_ + clip_region_.Width());
scrolled_out = horizontal_dir * scroll_origin_.x_ > ticker_max;
ticker_position_ = ticker_max != 0 ? ((float)horizontal_dir * scroll_origin_.x_ / ticker_max) : 0;
}
else if (ticker_type_ == TickerType_Vertical)
{
ticker_max = (vertical_dir == -1 ? content_size_.y_ : content_size_.y_ + actual_clip_region.Height());
scrolled_out = vertical_dir * scroll_origin_.y_ > ticker_max;
ticker_position_ = ticker_max != 0 ? ((float)vertical_dir * scroll_origin_.y_ / ticker_max) : 0;
}
if (scrolled_out)
{
using namespace RichTextScrolledOut;
VariantMap& eventData = GetEventDataMap();
eventData[P_TEXT] = this;
SendEvent(E_RICHTEXT_SCROLLED_OUT, eventData);
// TODO: send an event
ResetTicker();
}
}
}
} // namespace Urho3D