-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgametext.cpp
More file actions
102 lines (91 loc) · 1.79 KB
/
Copy pathgametext.cpp
File metadata and controls
102 lines (91 loc) · 1.79 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
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
#include "gametext.h"
GameText::GameText(QString str, QRect r, int time, QColor col, QObject *parent):
QObject{parent},text(str),rect(r),displayTime(time),color(col)
{
isEnd=0;
isAlphaDecreasing=0;
color.setAlpha(0);
}
void GameText::display(QPainter &painter)
{
int alpha=color.alpha();
if(alpha>=255)
{
if(displayTime>0)
{
displayTime--;
}
else
{
isAlphaDecreasing=true;
}
}
if(isAlphaDecreasing)
{
if(alpha>5) color.setAlpha(alpha-5);
else
{
isEnd=true;
emit end();
}
}
else
{
color.setAlpha(std::min(255,alpha+5));
}
QFont font("黑体", 25);
painter.setFont(font);
painter.setPen(color);
painter.drawText(rect, Qt::AlignCenter | Qt::TextWordWrap, text);
}
TextList::TextList(QRect r, QColor col, QObject *parent):
QObject{parent},currentIndex(0),rect(r),color(col)
{
}
TextList::~TextList()
{
clear();
}
bool TextList::isEnd()
{
if(texts.isEmpty()) return true;
return texts[size()-1]->isEnd;
}
int TextList::size()
{
return texts.size();
}
void TextList::addText(QString str)
{
GameText *gt=new GameText(str,rect,str.length()*4,color,this);
texts.push_back(gt);
}
void TextList::clear()
{
foreach (GameText* gt, texts) {
if(gt!=nullptr)
{
delete gt;
gt=nullptr;
}
}
texts.clear();
}
void TextList::display(QPainter &painter)
{
if(size()<=0) return;
if(isEnd())
{
emit end(); return;
}
if(texts[currentIndex]->isEnd)
{
currentIndex++;
if(currentIndex>=size())
{
emit end();
return;
}
}
texts[currentIndex]->display(painter);
}