forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBoxRoll.cpp
More file actions
61 lines (57 loc) · 1.13 KB
/
TextBoxRoll.cpp
File metadata and controls
61 lines (57 loc) · 1.13 KB
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
#include "TextBoxRoll.h"
#include "Font.h"
#include "GameUtil.h"
TextBoxRoll::TextBoxRoll()
{
}
TextBoxRoll::~TextBoxRoll()
{
}
void TextBoxRoll::draw()
{
int x = x_, y = y_;
int i = -1, line_count = 0; //初值
for (auto& line : texts_)
{
i++;
if (i < begin_line_)
{
continue;
}
if (roll_line_ > 0 && line_count >= roll_line_)
{
break;
}
for (auto& color_text : line)
{
Font::getInstance()->draw(color_text.second, font_size_, x, y, color_text.first, color_text.first.a);
x += font_size_ / 2 * color_text.second.length();
}
line_count++;
x = x_;
y += font_size_;
}
}
void TextBoxRoll::dealEvent(BP_Event& e)
{
if (roll_line_ <= 0)
{
return;
}
switch (e.type)
{
case BP_MOUSEWHEEL:
if (e.wheel.y < 0)
{
begin_line_++;
}
else
{
begin_line_--;
}
break;
default:
break;
}
begin_line_ = GameUtil::limit(begin_line_, 0, int(texts_.size() - roll_line_));
}