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
|
class video_system
{
::HANDLE m_hScreen;
public:
video_system()
: m_hScreen(::CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0))
{
::SetConsoleActiveScreenBuffer(m_hScreen);
}
void play(std::string const& file_name, std::size_t frame_count, std::size_t frame_stop = 8, int play_count = -1)
{
std::vector< std::vector<std::string> > data;
for (std::size_t i(0); i < frame_count; ++i)
{
std::vector<std::string> tmp_obj;
data.push_back(tmp_obj);
read_picture(file_name, i + 1, data.at(data.size() - 1));
}
while (play_count > 0 || play_count == -1)
{
for (std::size_t i(0); i < data.size(); ++i)
{
::HANDLE hBuffer(::CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, 0, CONSOLE_TEXTMODE_BUFFER, 0));
DWORD tmp(0L);
for (std::size_t s(0); s < data[i].size(); ++s) ::WriteConsoleA(hBuffer, data[i][s].c_str(), static_cast<DWORD>(data[i][s].length()), &tmp, 0);
::CONSOLE_SCREEN_BUFFER_INFO info;
::GetConsoleScreenBufferInfo(m_hScreen, &info);
::COORD coord = {0};
unsigned short attr1(0), attr2(0);
char sign1(' '), sign2(' ');
while (coord.X < info.dwSize.X && coord.Y < info.dwSize.Y)
{
::ReadConsoleOutputCharacterA(hBuffer, &sign1, 1, coord, &tmp);
::ReadConsoleOutputAttribute(hBuffer, &attr1, 1, coord, &tmp);
::ReadConsoleOutputCharacterA(m_hScreen, &sign2, 1, coord, &tmp);
::ReadConsoleOutputAttribute(m_hScreen, &attr2, 1, coord, &tmp);
if (attr1 != attr2 || sign1 != sign2)
{
::WriteConsoleOutputCharacterA(m_hScreen, &sign1, 1, coord, &tmp);
::WriteConsoleOutputAttribute(m_hScreen, &attr1, 1, coord, &tmp);
}
if ((++coord.X) >= info.dwSize.X)
{
coord.X =0;
++coord.Y;
}
}
Sleep(static_cast<DWORD>(frame_stop));
}
if (play_count != -1) --play_count;
}
}
private:
void read_picture(std::string const & filename, std::size_t block, std::vector<std::string>& data)
{
std::ifstream file(filename.c_str());
if (!file) throw std::invalid_argument("file does not exist");
data.clear();
std::ostringstream ss;
ss << "// Task_Beginn " << std::setw(2) << std::setfill('0') << block;
const std::string start(ss.str());
ss.str(""); ss.clear();
ss << "// Task_End " << std::setw(2) << std::setfill('0') << block;
std::string line;
bool in_data(false);
while (std::getline(file, line))
{
if (in_data == false && line.find(start) != std::string::npos) in_data = true;
else if (in_data == true)
{
if (line.find(ss.str()) != std::string::npos) in_data = false;
else data.push_back(line);
}
}
}
};
#endif // VIDEO_SYSTEM_HPP_INCLUDED
|