-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialog.cpp
113 lines (97 loc) · 1.62 KB
/
Dialog.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
#include "Dialog.h"
#include "assist.h"
Dialog::Dialog()
{
strcpy(Words,"");
Height = 60;
Width = 300;
cHeight = 20;
count_in_row = 48;
cX = 20;
cY = 10;
num_row = 2;
Surf = NULL;
Font = NULL;
Color = NULL;
X = SCR_W/8;
Y = SCR_H-Height;
num = 0;
}
Dialog::~Dialog()
{
// Words = NULL;
Surf = NULL;
}
short Dialog::is_over()
{
if(Words[num] == '\0') {
return 1;
}
else
return 0;
}
void Dialog::show(SDL_Surface *dest_surf)
{
// static int num = 0;
if(Words[num] == '\0')
return;
SDL_Rect dlg_src, dlg_dest;
dlg_src.x = 0;
dlg_src.y = 0;
dlg_src.w = Width;
dlg_src.h = Height;
dlg_dest.x = X;
dlg_dest.y = Y;
dlg_dest.w = Width;
dlg_dest.h = Height;
SDL_BlitSurface(Surf, &dlg_src, dest_surf, &dlg_dest);
if (!TTF_WasInit()){
printf("Truetype font engine has not been initialized!\n");
exit(1);
}
char temp[100];
short x_print = X+cX;
short y_print = Y+cY;
for(short i = 0; i<num_row; i++)
{
memset(temp, 0, 100);
for(short j=0; j<count_in_row; j++)
{
if (Words[num] == '\0')
{
i = num_row - 1;
break;
}
else if(Words[num] == '@')
{
i = num_row - 1;
num++;
break;
}
else
{
temp[j] = Words[num];
num++;
}
}
SDL_BlitText(temp, dest_surf, x_print, y_print, Font, *Color);
y_print += 20;
}
if(Words[num] == '\0')
{
set_text("");
num = 0;
}
}
void Dialog::set_text(const char * text)
{
memset(Words, 0, 500);
strcpy(Words, text);
}
void Dialog::set_dlg(SDL_Surface *surf, TTF_Font *font,
SDL_Color *color)
{
Surf = surf;
Font = font;
Color =color;
}