-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
92 lines (73 loc) · 1.94 KB
/
Copy pathmain.cpp
File metadata and controls
92 lines (73 loc) · 1.94 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
#include "export.h"
#include "mainwindow.h"
#include <QApplication>
#include <thread>
#include <chrono>
QApplication* app = nullptr;
MainWindow* win = nullptr;
std::thread th;
// Functions used in C#
extern "C"
{
#ifndef WIN32 // or something like that...
#define __stdcall
#endif
typedef void (__stdcall *ReadyCallback)(void);
EXPORT bool gui_poll_events(PollData* data)
{
if(!win || !app)
return false;
return win->pollEvents(data);
}
EXPORT void gui_log(const char* string)
{
if(!win || !app)
return;
win->log(QString::fromUtf16((const char16_t*)string));
}
EXPORT void gui_set_status(const char* string)
{
if(!win || !app)
return;
win->setStatusTip(QString::fromUtf16((const char16_t*)string));
}
EXPORT void gui_add_ban(const char* name, const char* ip)
{
if(!win || !app)
return;
win->addBan(QString::fromUtf16((const char16_t*)name), (QString::fromUtf16((const char16_t*)ip)));
}
EXPORT void gui_player_state(PlayerData data)
{
if(!win || !app)
return;
win->setPlayerState(data);
}
EXPORT int gui_run(ReadyCallback cb)
{
th = std::thread([=]
{
int argc = 1;
char* argv[] = { (char*)"AppName" };
app = new QApplication(argc, argv);
app->setStyle("fusion");
win = new MainWindow();
win->show();
cb();
while(true)
{
app->processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
});
return true;
}
}
int main(int argc, char *argv[])
{
app = new QApplication(argc, argv);
app->setStyle("fusion");
win = new MainWindow();
win->show();
return app->exec();
}