App::I static singleton to pointer
This commit is contained in:
144
src/main.cpp
144
src/main.cpp
@@ -174,24 +174,24 @@ void win32_update_stylus(float dt)
|
||||
{
|
||||
WacomTablet::I.m_stylus = false;
|
||||
WacomTablet::I.m_eraser = false;
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
}
|
||||
if (timer_ink_pen > 0.1 && WacomTablet::I.m_ink_pen)
|
||||
{
|
||||
WacomTablet::I.m_ink_pen = false;
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
}
|
||||
if (timer_ink_touch > 0.1 && WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
WacomTablet::I.m_ink_touch = false;
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
void win32_update_fps(int frames)
|
||||
{
|
||||
static wchar_t title_fps[512];
|
||||
if (App::I.vr_active)
|
||||
if (App::I->vr_active)
|
||||
swprintf_s(title_fps, L"%s - %d fps - %d vr fps", window_title, frames, vr_frames);
|
||||
else
|
||||
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
|
||||
@@ -514,7 +514,7 @@ static void SetupExceptionHandler()
|
||||
// PCTSTR pszLogFileName = BT_GetLogFileName(g_iLogHandle);
|
||||
TCHAR wpath[MAX_PATH];
|
||||
//GetFullPathNameW(L"panopainter-log.txt", 1024, wpath, nullptr);
|
||||
auto log_file = App::I.data_path + "/panopainter-log.txt";
|
||||
auto log_file = App::I->data_path + "/panopainter-log.txt";
|
||||
std::mbstowcs(wpath, log_file.c_str(), log_file.size());
|
||||
BT_AddLogFile(wpath);
|
||||
|
||||
@@ -526,7 +526,7 @@ static void SetupExceptionHandler()
|
||||
std::ostringstream oss;
|
||||
oss << std::put_time(&tm, "%d-%m-%Y %H-%M-%S");
|
||||
|
||||
auto path = App::I.data_path + "/" + App::I.doc_name + "-recovery (" + oss.str() + ").ppi";
|
||||
auto path = App::I->data_path + "/" + App::I->doc_name + "-recovery (" + oss.str() + ").ppi";
|
||||
Canvas::I->project_save_thread(path);
|
||||
static char abspath[MAX_PATH];
|
||||
GetFullPathNameA(path.c_str(), MAX_PATH, abspath, NULL);
|
||||
@@ -570,7 +570,7 @@ bool win32_vr_start()
|
||||
return false;
|
||||
|
||||
vive = new Vive;
|
||||
vive->on_draw = [](const glm::mat4& proj, const glm::mat4& view, const glm::mat4& pose) { App::I.vr_draw(proj, view, pose); };
|
||||
vive->on_draw = [](const glm::mat4& proj, const glm::mat4& view, const glm::mat4& pose) { App::I->vr_draw(proj, view, pose); };
|
||||
if (!vive->Initialize())
|
||||
{
|
||||
delete vive;
|
||||
@@ -585,12 +585,12 @@ bool win32_vr_start()
|
||||
|
||||
BT_SetTerminate();
|
||||
LOG("start hmd render thread");
|
||||
App::I.has_vr = true;
|
||||
App::I->has_vr = true;
|
||||
vr_running = true;
|
||||
|
||||
vive->on_analog_button = std::bind(&App::vr_analog, &App::I, std::placeholders::_1,
|
||||
vive->on_analog_button = std::bind(&App::vr_analog, App::I, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
|
||||
vive->on_button = std::bind(&App::vr_digital, &App::I, std::placeholders::_1,
|
||||
vive->on_button = std::bind(&App::vr_digital, App::I, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
|
||||
|
||||
const float target_tick_rate = 90;
|
||||
@@ -613,10 +613,10 @@ bool win32_vr_start()
|
||||
frames++;
|
||||
|
||||
vive->Update();
|
||||
App::I.vr_active = vive->m_active;
|
||||
App::I.vr_controllers[0] = vive->m_controllers[0];
|
||||
App::I.vr_head = vive->m_pose;
|
||||
App::I.vr_update(dt);
|
||||
App::I->vr_active = vive->m_active;
|
||||
App::I->vr_controllers[0] = vive->m_controllers[0];
|
||||
App::I->vr_head = vive->m_pose;
|
||||
App::I->vr_update(dt);
|
||||
|
||||
if (vr_running && vive->m_active)
|
||||
{
|
||||
@@ -630,8 +630,8 @@ bool win32_vr_start()
|
||||
hmd_render_cv.wait_for(lock, std::chrono::milliseconds(diff));
|
||||
t0 = t1;
|
||||
}
|
||||
App::I.vr_active = false;
|
||||
App::I.has_vr = false;
|
||||
App::I->vr_active = false;
|
||||
App::I->has_vr = false;
|
||||
vr_running = false;
|
||||
if (async_lock_try())
|
||||
{
|
||||
@@ -757,7 +757,7 @@ BOOL UnadjustWindowRectEx(LPRECT prc, DWORD dwStyle, BOOL fMenu, DWORD dwExStyle
|
||||
|
||||
void _pre_call_callback(const char* name, void* funcptr, int len_args, ...)
|
||||
{
|
||||
assert(App::I.is_render_thread());
|
||||
assert(App::I->is_render_thread());
|
||||
}
|
||||
|
||||
void _post_call_callback(const char* name, void* funcptr, int len_args, ...)
|
||||
@@ -776,7 +776,8 @@ int main(int argc, char** argv)
|
||||
WNDCLASS wc;
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
|
||||
App::I.initLog();
|
||||
App::I = new App();
|
||||
App::I->initLog();
|
||||
|
||||
init_shcore_API();
|
||||
init_ink_API();
|
||||
@@ -811,7 +812,7 @@ int main(int argc, char** argv)
|
||||
|
||||
read_WMI_info();
|
||||
|
||||
App::I.create();
|
||||
App::I->create();
|
||||
|
||||
// Inizialize data structures to zero
|
||||
memset(&wc, 0, sizeof(wc));
|
||||
@@ -836,7 +837,7 @@ int main(int argc, char** argv)
|
||||
auto y = unsigned{96};
|
||||
if (GetDpiForMonitor_fn)
|
||||
GetDpiForMonitor_fn(monitor, MDT_EFFECTIVE_DPI, &x, &y);
|
||||
App::I.zoom *= (float)x / 96.f;
|
||||
App::I->zoom *= (float)x / 96.f;
|
||||
|
||||
int show_cmd = SW_NORMAL;
|
||||
Settings::value<Serializer::Integer>("window-show-cmd", show_cmd);
|
||||
@@ -844,13 +845,13 @@ int main(int argc, char** argv)
|
||||
//if (show_cmd == SW_MAXIMIZE)
|
||||
// wnd_style != WS_MAXIMIZE;
|
||||
|
||||
RECT clientRect = { 0, 0, (int)App::I.width * App::I.zoom, (int)App::I.height * App::I.zoom };
|
||||
RECT clientRect = { 0, 0, (int)App::I->width * App::I->zoom, (int)App::I->height * App::I->zoom };
|
||||
POINT clientPos = { CW_USEDEFAULT, CW_USEDEFAULT };
|
||||
if (Settings::has("window-rect"))
|
||||
{
|
||||
auto wnd_rect = Settings::value<Serializer::IVec4>("window-rect");
|
||||
App::I.width = wnd_rect.z - wnd_rect.x;
|
||||
App::I.height = wnd_rect.w - wnd_rect.y;
|
||||
App::I->width = wnd_rect.z - wnd_rect.x;
|
||||
App::I->height = wnd_rect.w - wnd_rect.y;
|
||||
clientRect = { wnd_rect.x, wnd_rect.y, wnd_rect.z, wnd_rect.w };
|
||||
clientPos = { wnd_rect.x, wnd_rect.y };
|
||||
}
|
||||
@@ -952,8 +953,8 @@ int main(int argc, char** argv)
|
||||
switch (const_hash(argv[1]))
|
||||
{
|
||||
case const_hash("convert"):
|
||||
App::I.initShaders();
|
||||
App::I.cmd_convert(argv[2], argv[3]);
|
||||
App::I->initShaders();
|
||||
App::I->cmd_convert(argv[2], argv[3]);
|
||||
return 0;
|
||||
case const_hash("-vrmode"):
|
||||
start_in_vr = true;
|
||||
@@ -972,8 +973,8 @@ int main(int argc, char** argv)
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
|
||||
running = 1;
|
||||
App::I.render_thread_start();
|
||||
App::I.ui_thread_start();
|
||||
App::I->render_thread_start();
|
||||
App::I->ui_thread_start();
|
||||
|
||||
#ifdef _DEBUG
|
||||
glad_set_pre_callback(_pre_call_callback);
|
||||
@@ -994,7 +995,7 @@ int main(int argc, char** argv)
|
||||
SendMessage(hWnd, WM_SETICON, ICON_SMALL,
|
||||
(LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1)));
|
||||
|
||||
App::I.ui_sync();
|
||||
App::I->ui_sync();
|
||||
|
||||
{
|
||||
WINDOWPLACEMENT wp;
|
||||
@@ -1002,12 +1003,12 @@ int main(int argc, char** argv)
|
||||
wp.showCmd = show_cmd;
|
||||
SetWindowPlacement(hWnd, &wp);
|
||||
//GetClientRect(hWnd, &clientRect);
|
||||
//App::I.width = clientRect.right - clientRect.left;
|
||||
//App::I.height = clientRect.bottom - clientRect.top;
|
||||
//App::I->width = clientRect.right - clientRect.left;
|
||||
//App::I->height = clientRect.bottom - clientRect.top;
|
||||
}
|
||||
|
||||
if (start_in_vr)
|
||||
App::I.vr_start();
|
||||
App::I->vr_start();
|
||||
|
||||
LOG("show main window");
|
||||
SetForegroundWindow(hWnd);
|
||||
@@ -1022,7 +1023,7 @@ int main(int argc, char** argv)
|
||||
while (running == 1)
|
||||
{
|
||||
// If there any message in the queue process it
|
||||
auto present = App::I.animate || App::I.redraw ?
|
||||
auto present = App::I->animate || App::I->redraw ?
|
||||
PeekMessage(&msg, 0, 0, 0, PM_REMOVE) : GetMessage(&msg, 0, 0, 0);
|
||||
|
||||
if (msg.message == WM_QUIT)
|
||||
@@ -1075,21 +1076,22 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
running = 0;
|
||||
if (hmd_renderer.joinable())
|
||||
hmd_renderer.join();
|
||||
App::I.ui_thread_stop();
|
||||
App::I.render_thread_stop();
|
||||
App::I.terminate();
|
||||
App::I->ui_thread_stop();
|
||||
App::I->render_thread_stop();
|
||||
App::I->terminate();
|
||||
delete App::I;
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
App::I.redraw = true;
|
||||
App::I->redraw = true;
|
||||
break;
|
||||
case WM_CREATE:
|
||||
BT_SetTerminate();
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
{
|
||||
App::I.ui_task_async([] {
|
||||
if (App::I.request_close())
|
||||
App::I->ui_task_async([] {
|
||||
if (App::I->request_close())
|
||||
{
|
||||
destroy_window();
|
||||
}
|
||||
@@ -1103,17 +1105,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
auto h = (float)HIWORD(lp);
|
||||
if (h != 0 && running == 1)
|
||||
{
|
||||
App::I.ui_task_async([=]
|
||||
App::I->ui_task_async([=]
|
||||
{
|
||||
App::I.resize(w, h);
|
||||
App::I.redraw = true;
|
||||
App::I->resize(w, h);
|
||||
App::I->redraw = true;
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_ACTIVATE:
|
||||
{
|
||||
App::I.ui_task_async([=] {
|
||||
App::I->ui_task_async([=] {
|
||||
int active = GET_WM_ACTIVATE_STATE(wp, lp);
|
||||
WacomTablet::I.set_focus(active);
|
||||
static BYTE keys[256];
|
||||
@@ -1126,10 +1128,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if (alt && k.first == kKey::KeyTab)
|
||||
continue;
|
||||
bool down = keys[k.second] & 0x80;
|
||||
if (App::I.keys[(int)k.first] && !down)
|
||||
App::I.key_up(k.first);
|
||||
else if(!App::I.keys[(int)k.first] && down)
|
||||
App::I.key_down(k.first);
|
||||
if (App::I->keys[(int)k.first] && !down)
|
||||
App::I->key_up(k.first);
|
||||
else if(!App::I->keys[(int)k.first] && down)
|
||||
App::I->key_down(k.first);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1137,16 +1139,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
// case WM_TOUCH:
|
||||
// {
|
||||
// App::I.ui_task_async([=] {
|
||||
// App::I->ui_task_async([=] {
|
||||
// //LOG("touch");
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
case WT_PACKET:
|
||||
{
|
||||
App::I.set_stylus();
|
||||
App::I->set_stylus();
|
||||
timer_stylus = 0;
|
||||
App::I.ui_task_async([=] {
|
||||
App::I->ui_task_async([=] {
|
||||
WacomTablet::I.handle_message(hWnd, msg, wp, lp);
|
||||
});
|
||||
break;
|
||||
@@ -1154,26 +1156,26 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
case WM_SYSKEYDOWN:
|
||||
case WM_KEYDOWN:
|
||||
if ((lp >> 30 & 1) == 0 && // ignore repeated
|
||||
!(wp == VK_TAB && App::I.keys[(int)kKey::KeyAlt])) // ignore alt+tab
|
||||
!(wp == VK_TAB && App::I->keys[(int)kKey::KeyAlt])) // ignore alt+tab
|
||||
{
|
||||
App::I.ui_task_async([wp] {
|
||||
App::I.key_down(convert_key((int)wp));
|
||||
App::I->ui_task_async([wp] {
|
||||
App::I->key_down(convert_key((int)wp));
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_SYSKEYUP:
|
||||
case WM_KEYUP:
|
||||
if (!(wp == VK_TAB && App::I.keys[(int)kKey::KeyAlt])) // ignore alt+tab
|
||||
if (!(wp == VK_TAB && App::I->keys[(int)kKey::KeyAlt])) // ignore alt+tab
|
||||
{
|
||||
App::I.ui_task_async([wp] {
|
||||
App::I.key_up(convert_key((int)wp));
|
||||
App::I->ui_task_async([wp] {
|
||||
App::I->key_up(convert_key((int)wp));
|
||||
});
|
||||
}
|
||||
break;
|
||||
case WM_CHAR:
|
||||
{
|
||||
App::I.ui_task_async([wp]{
|
||||
App::I.key_char((int)wp);
|
||||
App::I->ui_task_async([wp]{
|
||||
App::I->key_char((int)wp);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -1188,7 +1190,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
SetCursorPos(center.x, center.y);
|
||||
|
||||
//glm::vec2 cur = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
|
||||
glm::vec2 sz = { App::I.width, App::I.height };
|
||||
glm::vec2 sz = { App::I->width, App::I->height };
|
||||
glm::vec2 diff = { curpos.x - center.x, curpos.y - center.y };
|
||||
lastPoint = glm::clamp(lastPoint + diff, { 0, 0 }, sz);
|
||||
|
||||
@@ -1196,7 +1198,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
lastPoint = { GET_X_LPARAM(lp), GET_Y_LPARAM(lp) };
|
||||
|
||||
auto pt = lastPoint;
|
||||
App::I.ui_task_async([pt, extra, p = WacomTablet::I.get_pressure()]{
|
||||
App::I->ui_task_async([pt, extra, p = WacomTablet::I.get_pressure()]{
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -1208,7 +1210,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_move((float)pt.x, (float)pt.y, p, pointer_source, WacomTablet::I.m_eraser);
|
||||
App::I->mouse_move((float)pt.x, (float)pt.y, p, pointer_source, WacomTablet::I.m_eraser);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -1216,7 +1218,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
SetCapture(hWnd);
|
||||
auto pt = lastPoint;
|
||||
App::I.ui_task_async([pt, extra, hWnd, p = WacomTablet::I.get_pressure()]{
|
||||
App::I->ui_task_async([pt, extra, hWnd, p = WacomTablet::I.get_pressure()]{
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -1228,7 +1230,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_down(0, (float)pt.x, (float)pt.y, p, pointer_source, WacomTablet::I.m_eraser);
|
||||
App::I->mouse_down(0, (float)pt.x, (float)pt.y, p, pointer_source, WacomTablet::I.m_eraser);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -1236,7 +1238,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
ReleaseCapture();
|
||||
auto pt = lastPoint;
|
||||
App::I.ui_task_async([pt, extra] {
|
||||
App::I->ui_task_async([pt, extra] {
|
||||
WacomTablet::I.reset_pressure();
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
@@ -1249,7 +1251,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_up(0, (float)pt.x, (float)pt.y, pointer_source, WacomTablet::I.m_eraser);
|
||||
App::I->mouse_up(0, (float)pt.x, (float)pt.y, pointer_source, WacomTablet::I.m_eraser);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -1257,7 +1259,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
SetCapture(hWnd);
|
||||
auto pt = lastPoint;
|
||||
App::I.ui_task_async([pt, extra, hWnd] {
|
||||
App::I->ui_task_async([pt, extra, hWnd] {
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -1269,7 +1271,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_down(1, (float)pt.x, (float)pt.y, 1.f, pointer_source, 0);
|
||||
App::I->mouse_down(1, (float)pt.x, (float)pt.y, 1.f, pointer_source, 0);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -1277,7 +1279,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
ReleaseCapture();
|
||||
auto pt = lastPoint;
|
||||
App::I.ui_task_async([pt, extra] {
|
||||
App::I->ui_task_async([pt, extra] {
|
||||
kEventSource pointer_source;
|
||||
if (WacomTablet::I.m_ink_pen || WacomTablet::I.m_ink_touch)
|
||||
{
|
||||
@@ -1289,7 +1291,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
if ((extra & 0xFFFFFF00) == 0xFF515700)
|
||||
pointer_source = kEventSource::Touch;
|
||||
}
|
||||
App::I.mouse_up(1, (float)pt.x, (float)pt.y, pointer_source, 0);
|
||||
App::I->mouse_up(1, (float)pt.x, (float)pt.y, pointer_source, 0);
|
||||
});
|
||||
}
|
||||
break;
|
||||
@@ -1300,8 +1302,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
pt.y = GET_Y_LPARAM(lp);
|
||||
ScreenToClient(hWnd, &pt);
|
||||
{
|
||||
App::I.ui_task_async([pt, wp] {
|
||||
App::I.mouse_scroll((float)pt.x, (float)pt.y,
|
||||
App::I->ui_task_async([pt, wp] {
|
||||
App::I->mouse_scroll((float)pt.x, (float)pt.y,
|
||||
(float)GET_WHEEL_DELTA_WPARAM(wp) / (float)WHEEL_DELTA);
|
||||
});
|
||||
}
|
||||
@@ -1365,7 +1367,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
timer_ink_pen = 0;
|
||||
WacomTablet::I.m_ink_pen = true;
|
||||
WacomTablet::I.m_pen_pres = (float)penInfo.pressure / 1024.f;
|
||||
App::I.set_stylus();
|
||||
App::I->set_stylus();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user