App::I static singleton to pointer

This commit is contained in:
2019-07-11 18:08:17 +02:00
parent 92dd00d910
commit b89274e7a6
33 changed files with 417 additions and 412 deletions

View File

@@ -255,19 +255,21 @@ JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickExternalCal
env->ReleaseStringUTFChars(path, path_utf);
LOG("data_path %s", file_path.c_str());
App::I.data_path = file_path;
App::I.work_path = file_path;
App::I.rec_path = file_path + "/frames";
App::I->data_path = file_path;
App::I->work_path = file_path;
App::I->rec_path = file_path + "/frames";
App::I->initLog();
}
JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_contentRectChanged(JNIEnv *end, jobject,
jint wnd_w, jint wnd_h, jint rect_left, jint rect_top, jint rect_right, jint rect_bottom)
{
#ifndef __QUEST__
LOG("resize wnd [%d %d] rect [%d %d %d %d]", wnd_w, wnd_h, rect_left, rect_top, rect_right, rect_bottom);
App::I.width = wnd_w;
App::I.height = (rect_bottom - rect_top);
App::I.off_x = 0;
App::I.off_y = wnd_h - (rect_bottom - rect_top);
App::I->width = wnd_w;
App::I->height = (rect_bottom - rect_top);
App::I->off_x = 0;
App::I->off_y = wnd_h - (rect_bottom - rect_top);
#endif
}
}
@@ -315,7 +317,6 @@ std::string get_data_path(android_app* mApplication)
*/
static int engine_init_display(struct engine* engine) {
// initialize OpenGL ES and EGL
App::I.initLog();
/*
* Here specify the attributes of the desired configuration.
@@ -499,7 +500,7 @@ static int engine_init_display(struct engine* engine) {
if (resuming_context)
{
LOG("RESUME APP");
App::I.and_app = engine->app;
App::I->and_app = engine->app;
return 0;
}
@@ -593,42 +594,42 @@ static int engine_init_display(struct engine* engine) {
LOG("PROP Mode: %s", os_props["ro.product.model"].c_str());
Asset::m_am = engine->app->activity->assetManager;
App::I.and_app = engine->app;
App::I.and_engine = engine;
App::I->and_app = engine->app;
App::I->and_engine = engine;
//std::string base_path = engine->app->activity->externalDataPath ?
// engine->app->activity->externalDataPath : get_data_path(engine->app);
if (App::I.data_path.empty() || App::I.data_path == ".")
App::I.data_path = get_data_path(engine->app);
LOG("data_path %s", App::I.data_path.c_str());
if (App::I->data_path.empty() || App::I->data_path == ".")
App::I->data_path = get_data_path(engine->app);
LOG("data_path %s", App::I->data_path.c_str());
#ifdef __QUEST__
App::I.zoom = 1.f;
App::I.width = 1024;
App::I.height = 1024;
App::I.redraw = true;
App::I.init();
App::I.resize(1024, 1024);
App::I.vr_active = true;
App::I.has_vr = true;
App::I.vr_only = true;
App::I->zoom = 1.f;
App::I->width = 1024;
App::I->height = 1024;
App::I->redraw = true;
App::I->init();
App::I->resize(1024, 1024);
App::I->vr_active = true;
App::I->has_vr = true;
App::I->vr_only = true;
#else
float density = get_display_density(engine->app);
LOG("density %f", density);
App::I.zoom = density;// / 1.5;
App::I.width = w;
App::I.height = h;
App::I.redraw = true;
App::I->zoom = density;// / 1.5;
App::I->width = w;
App::I->height = h;
App::I->redraw = true;
// give control to the render thread
LOG("release egl context");
eglMakeCurrent(engine->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
LOG("start render threads");
App::I.render_thread_start();
App::I->render_thread_start();
LOG("start ui thread");
App::I.ui_thread_start();
App::I->ui_thread_start();
#endif
return 0;
}
@@ -652,7 +653,7 @@ static void engine_draw_frame(struct engine* engine) {
start = now;
elapsed += dt.count();
elapsed_1s += dt.count();
App::I.tick(dt.count());
App::I->tick(dt.count());
if (elapsed_1s > 1.f)
{
@@ -668,14 +669,14 @@ static void engine_draw_frame(struct engine* engine) {
rendered_frames++;
#ifdef __QUEST__
App::I.update(elapsed);
App::I->update(elapsed);
oculus_draw(dt.count());
#else
if (!(App::I.redraw || App::I.animate))
if (!(App::I->redraw || App::I->animate))
return;
App::I.clear();
App::I.update(elapsed);
App::I->clear();
App::I->update(elapsed);
eglSwapBuffers(engine->display, engine->surface);
#endif
@@ -714,7 +715,7 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
//LOG("event type: %d", eventType);
//locker _locker{engine};
App::I.redraw = true;
App::I->redraw = true;
switch (eventType) {
case AINPUT_EVENT_TYPE_MOTION:
@@ -763,8 +764,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
float pressure = AMotionEvent_getPressure(event, 0);
kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ?
kEventSource::Stylus : kEventSource::Touch;
App::I.ui_task_async([=]{
App::I.mouse_down(0, x, y, pressure, source, 0);
App::I->ui_task_async([=]{
App::I->mouse_down(0, x, y, pressure, source, 0);
});
tracked = 1;
//LOG("first down");
@@ -783,10 +784,10 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
p0.pos.x = AMotionEvent_getX(event, 0);
p0.pos.y = AMotionEvent_getY(event, 0);
//LOG("second down");
App::I.ui_task_async([=] {
App::I->ui_task_async([=] {
if (tracked == 1)
App::I.mouse_cancel(0);
App::I.gesture_start(p0.pos, p1.pos);
App::I->mouse_cancel(0);
App::I->gesture_start(p0.pos, p1.pos);
});
tracked = 2;
}
@@ -804,8 +805,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
kEventSource::Stylus : kEventSource::Touch;
if (tracked == 1)
{
App::I.ui_task_async([=] {
App::I.mouse_up(0, x, y, source, 0);
App::I->ui_task_async([=] {
App::I->mouse_up(0, x, y, source, 0);
});
}
tracked = 0;
@@ -817,8 +818,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
{
p1.id = -1;
//LOG("second up");
App::I.ui_task_async([=] {
App::I.gesture_end();
App::I->ui_task_async([=] {
App::I->gesture_end();
});
}
return 1;
@@ -826,8 +827,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
{
float y = AMotionEvent_getY(event, 0);
float x = AMotionEvent_getX(event, 0);
App::I.ui_task_async([=] {
App::I.mouse_move(x, y, 0, kEventSource::Stylus, 0);
App::I->ui_task_async([=] {
App::I->mouse_move(x, y, 0, kEventSource::Stylus, 0);
});
//LOG("single move");
return 1;
@@ -841,8 +842,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
float pressure = AMotionEvent_getPressure(event, 0);
kEventSource source = tool_type == AMOTION_EVENT_TOOL_TYPE_STYLUS ?
kEventSource::Stylus : kEventSource::Touch;
App::I.ui_task_async([=] {
App::I.mouse_move(x, y, pressure, source, 0);
App::I->ui_task_async([=] {
App::I->mouse_move(x, y, pressure, source, 0);
});
//LOG("single move");
}
@@ -864,8 +865,8 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
float y = AMotionEvent_getY(event, 1);
p1.pos = {x, y};
}
App::I.ui_task_async([=] {
App::I.gesture_move(p0.pos, p1.pos);
App::I->ui_task_async([=] {
App::I->gesture_move(p0.pos, p1.pos);
});
}
return 1;
@@ -889,22 +890,22 @@ static int32_t engine_handle_input(struct android_app* app, AInputEvent* event)
case AKEY_EVENT_ACTION_MULTIPLE:
LOG("Received key multi event: %d\n", key_val);
if (uniValue > 32 && uniValue < 127) //printable ascii range
App::I.ui_task_async([=] {
App::I.key_char(uniValue);
App::I->ui_task_async([=] {
App::I->key_char(uniValue);
});
break;
case AKEY_EVENT_ACTION_DOWN:
LOG("Received key down event: %d\n", key_val);
App::I.ui_task_async([=] {
App::I.key_down(convert_key(key_val));
App::I->ui_task_async([=] {
App::I->key_down(convert_key(key_val));
});
break;
case AKEY_EVENT_ACTION_UP:
LOG("Received key up event: %d\n", key_val);
App::I.ui_task_async([=] {
App::I.key_up(convert_key(key_val));
App::I->ui_task_async([=] {
App::I->key_up(convert_key(key_val));
if (uniValue > 32 && uniValue < 127) //printable ascii range
App::I.key_char(uniValue);
App::I->key_char(uniValue);
});
break;
}
@@ -922,7 +923,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
switch (cmd) {
case APP_CMD_RESUME:
LOG("APP_CMD_RESUME");
App::I.redraw = true;
App::I->redraw = true;
ALooper_wake(engine->app->looper);
break;
case APP_CMD_SAVE_STATE:
@@ -941,7 +942,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
break;
case APP_CMD_TERM_WINDOW:
// The window is being hidden or closed, clean it up.
//App::I.terminate();
//App::I->terminate();
engine_term_display(engine);
//exit(0);
break;
@@ -974,20 +975,20 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
break;
case APP_CMD_WINDOW_REDRAW_NEEDED:
LOG("APP_CMD_WINDOW_REDRAW_NEEDED");
App::I.redraw = true;
App::I->redraw = true;
ALooper_wake(engine->app->looper);
break;
case APP_CMD_WINDOW_RESIZED:
LOG("APP_CMD_WINDOW_RESIZED");
App::I.redraw = true;
App::I->redraw = true;
ALooper_wake(engine->app->looper);
break;
case APP_CMD_CONTENT_RECT_CHANGED:
LOG("APP_CMD_CONTENT_RECT_CHANGED");
//App::I.width = engine->app->contentRect.right - engine->app->contentRect.left;
//App::I.height = engine->app->contentRect.bottom - engine->app->contentRect.top;
//LOG("content rect %f %f", App::I.width, App::I.height);
App::I.redraw = true;
//App::I->width = engine->app->contentRect.right - engine->app->contentRect.left;
//App::I->height = engine->app->contentRect.bottom - engine->app->contentRect.top;
//LOG("content rect %f %f", App::I->width, App::I->height);
App::I->redraw = true;
ALooper_wake(engine->app->looper);
break;
}
@@ -1003,6 +1004,8 @@ void android_main(struct android_app* state) {
// DON'T REMOVE, even if the compiler say it's deprecated
app_dummy();
App::I = new App;
memset(&g_engine, 0, sizeof(g_engine));
state->userData = &g_engine;
state->onAppCmd = engine_handle_cmd;
@@ -1036,8 +1039,8 @@ void android_main(struct android_app* state) {
g_engine.state = *(struct saved_state*)state->savedState;
}
//App::I.create();
App::I.redraw = true;
//App::I->create();
App::I->redraw = true;
// loop waiting for stuff to do.
@@ -1079,7 +1082,7 @@ void android_main(struct android_app* state) {
continue;
if (ident == ALOOPER_POLL_TIMEOUT){
App::I.redraw = true;
App::I->redraw = true;
engine_draw_frame(&g_engine);
}

View File

@@ -11,7 +11,7 @@ void ActionManager::add(Action *action)
I.m_actions.emplace(action);
I.m_memory += action->memory();
//LOG("History: %.2f KB", I.m_memory / 1024.f);
App::I.update_memory_usage(I.m_memory);
App::I->update_memory_usage(I.m_memory);
}
void ActionManager::undo()
@@ -27,8 +27,8 @@ void ActionManager::undo()
Canvas::I->m_unsaved = !I.m_actions.top()->was_saved;
I.m_actions.pop();
//LOG("History: %.2f KB", I.m_memory / 1024.f);
App::I.update_memory_usage(I.m_memory);
App::I.title_update();
App::I->update_memory_usage(I.m_memory);
App::I->title_update();
}
void ActionManager::redo()
@@ -44,8 +44,8 @@ void ActionManager::redo()
Canvas::I->m_unsaved = !I.m_redos.top()->was_saved;
I.m_redos.pop();
//LOG("History: %.2f KB", I.m_memory / 1024.f);
App::I.update_memory_usage(I.m_memory);
App::I.title_update();
App::I->update_memory_usage(I.m_memory);
App::I->title_update();
}
void ActionManager::clear()
@@ -56,5 +56,5 @@ void ActionManager::clear()
I.m_redos.pop();
I.m_memory = 0;
//LOG("History: %.2f KB", I.m_memory / 1024.f);
App::I.update_memory_usage(I.m_memory);
App::I->update_memory_usage(I.m_memory);
}

View File

@@ -22,7 +22,7 @@ void async_unlock();
void destroy_window();
#endif
App App::I; // singleton
App* App::I = nullptr; // singleton
void App::create()
{

View File

@@ -63,7 +63,7 @@ struct VRController
class App
{
public:
static App I;
static App* I;
std::string data_path{ "." };
std::string work_path{ "." };
std::string rec_path{ "." };

View File

@@ -87,7 +87,7 @@ void App::dialog_newdoc()
layout[main_id]->add_child(dialog);
layout[main_id]->update();
App::I.showKeyboard();
App::I->showKeyboard();
dialog->btn_ok->on_click = [this, dialog](Node*)
{
@@ -121,7 +121,7 @@ void App::dialog_newdoc()
title_update();
dialog->destroy();
App::I.hideKeyboard();
App::I->hideKeyboard();
};
if (Asset::exist(path))
@@ -147,7 +147,7 @@ void App::dialog_newdoc()
dialog->btn_cancel->on_click = [this, dialog](Node*)
{
dialog->destroy();
App::I.hideKeyboard();
App::I->hideKeyboard();
};
};
@@ -355,7 +355,7 @@ void App::dialog_save()
dialog->loaded();
dialog->input->set_text(doc_name);
App::I.showKeyboard();
App::I->showKeyboard();
dialog->btn_ok->on_click = [this, dialog](Node*)
{
@@ -375,7 +375,7 @@ void App::dialog_save()
doc_dir = work_path;
title_update();
dialog->destroy();
App::I.hideKeyboard();
App::I->hideKeyboard();
};
if (Asset::exist(path))
@@ -400,7 +400,7 @@ void App::dialog_save()
dialog->btn_cancel->on_click = [this, dialog](Node*)
{
dialog->destroy();
App::I.hideKeyboard();
App::I->hideKeyboard();
};
layout[main_id]->add_child(dialog);
@@ -496,7 +496,7 @@ void App::dialog_resize()
int res = dialog->get_resolution();
if (canvas)
canvas->m_canvas->resize(res, res);
App::I.title_update();
App::I->title_update();
ActionManager::clear();
dialog->destroy();
};
@@ -519,7 +519,7 @@ void App::dialog_layer_rename()
dialog->loaded();
dialog->input->set_text(layers->m_current_layer->m_label_text);
App::I.showKeyboard();
App::I->showKeyboard();
layout[main_id]->add_child(dialog);
layout[main_id]->update();
@@ -553,11 +553,11 @@ void App::dialog_layer_rename()
layer_node->set_name(dialog->get_name().c_str());
layer->m_name = dialog->get_name();
dialog->destroy();
App::I.hideKeyboard();
App::I->hideKeyboard();
};
dialog->btn_cancel->on_click = [this, dialog](Node*)
{
dialog->destroy();
App::I.hideKeyboard();
App::I->hideKeyboard();
};
}

View File

@@ -323,7 +323,7 @@ void App::vr_draw(const glm::mat4& proj, const glm::mat4& camera, const glm::mat
}
}
App::I.grid->draw_heightmap(proj, camera, false);
App::I->grid->draw_heightmap(proj, camera, false);
float tan_fov = glm::tan(glm::radians(canvas->m_canvas->m_cam_fov / 2.f));
glm::vec3 aspect = { (float)uirtt.getWidth() / (float)uirtt.getHeight(), 1.f, 1.f };

View File

@@ -167,7 +167,7 @@ void Stroke::add_point(glm::vec3 pos, float pressure)
float aspect_width = glm::min(1.f, glm::clamp(m_brush->m_tip_aspect, .1f, .9f) * 2.f);
float raw_size = glm::clamp(m_brush->m_tip_size / glm::tan(glm::radians(m_camera.fov * 0.5f)), 1.f, m_max_size);
float size = aspect_width * glm::min(m_brush->m_tip_scale.x, m_brush->m_tip_scale.y) * raw_size;
m_step = glm::max(0.5f, m_brush->m_tip_spacing * size * App::I.zoom * pressure);
m_step = glm::max(0.5f, m_brush->m_tip_spacing * size * App::I->zoom * pressure);
}
float dist = m_keypoints.empty() ? m_step :
@@ -200,7 +200,7 @@ void Stroke::start(const std::shared_ptr<Brush>& brush)
float aspect_width = glm::min(1.f, glm::clamp(m_brush->m_tip_aspect, .1f, .9f) * 2.f);
float raw_size = glm::clamp(m_brush->m_tip_size / glm::tan(glm::radians(m_camera.fov * 0.5f)), 1.f, m_max_size);
float size = aspect_width * glm::min(m_brush->m_tip_scale.x, m_brush->m_tip_scale.y) * raw_size;
m_step = glm::max(0.5f, m_brush->m_tip_spacing * size * App::I.zoom);
m_step = glm::max(0.5f, m_brush->m_tip_spacing * size * App::I->zoom);
auto hsv = convert_rgb2hsv(m_brush->m_tip_color);
if (!m_brush->m_jitter_hsv_eachsample)
@@ -371,17 +371,17 @@ bool Brush::read(BinaryStreamReader& r)
r >> d;
d.value<Serializer::CString>("m_name", m_name);
d.value<Serializer::CString>("m_brush_path", m_brush_path);
m_brush_path = str_replace(m_brush_path, "{data_path}", App::I.data_path);
m_brush_path = str_replace(m_brush_path, "{data_path}", App::I->data_path);
d.value<Serializer::CString>("m_brush_thumb_path", m_brush_thumb_path);
m_brush_thumb_path = str_replace(m_brush_thumb_path, "{data_path}", App::I.data_path);
m_brush_thumb_path = str_replace(m_brush_thumb_path, "{data_path}", App::I->data_path);
d.value<Serializer::CString>("m_dual_path", m_dual_path);
m_dual_path = str_replace(m_dual_path, "{data_path}", App::I.data_path);
m_dual_path = str_replace(m_dual_path, "{data_path}", App::I->data_path);
d.value<Serializer::CString>("m_dual_thumb_path", m_dual_thumb_path);
m_dual_thumb_path = str_replace(m_dual_thumb_path, "{data_path}", App::I.data_path);
m_dual_thumb_path = str_replace(m_dual_thumb_path, "{data_path}", App::I->data_path);
d.value<Serializer::CString>("m_pattern_path", m_pattern_path);
m_pattern_path = str_replace(m_pattern_path, "{data_path}", App::I.data_path);
m_pattern_path = str_replace(m_pattern_path, "{data_path}", App::I->data_path);
d.value<Serializer::CString>("m_pattern_thumb_path", m_pattern_thumb_path);
m_pattern_thumb_path = str_replace(m_pattern_thumb_path, "{data_path}", App::I.data_path);
m_pattern_thumb_path = str_replace(m_pattern_thumb_path, "{data_path}", App::I->data_path);
d.value<Serializer::Vec4>("m_tip_color", m_tip_color);
d.value<Serializer::Vec2>("m_tip_scale", m_tip_scale);
@@ -463,17 +463,17 @@ void Brush::write(BinaryStreamWriter& w) const
d.name = L"Brush class";
d.props["m_name"] = std::make_shared<Serializer::CString>(m_name);
d.props["m_brush_path"] = std::make_shared<Serializer::CString>(
str_replace(m_brush_path, App::I.data_path, "{data_path}"));
str_replace(m_brush_path, App::I->data_path, "{data_path}"));
d.props["m_brush_thumb_path"] = std::make_shared<Serializer::CString>(
str_replace(m_brush_thumb_path, App::I.data_path, "{data_path}"));
str_replace(m_brush_thumb_path, App::I->data_path, "{data_path}"));
d.props["m_dual_path"] = std::make_shared<Serializer::CString>(
str_replace(m_dual_path, App::I.data_path, "{data_path}"));
str_replace(m_dual_path, App::I->data_path, "{data_path}"));
d.props["m_dual_thumb_path"] = std::make_shared<Serializer::CString>(
str_replace(m_dual_thumb_path, App::I.data_path, "{data_path}"));
str_replace(m_dual_thumb_path, App::I->data_path, "{data_path}"));
d.props["m_pattern_path"] = std::make_shared<Serializer::CString>(
str_replace(m_pattern_path, App::I.data_path, "{data_path}"));
str_replace(m_pattern_path, App::I->data_path, "{data_path}"));
d.props["m_pattern_thumb_path"] = std::make_shared<Serializer::CString>(
str_replace(m_pattern_thumb_path, App::I.data_path, "{data_path}"));
str_replace(m_pattern_thumb_path, App::I->data_path, "{data_path}"));
d.props["m_tip_color"] = std::make_shared<Serializer::Vec4>(m_tip_color);
d.props["m_tip_scale"] = std::make_shared<Serializer::Vec2>(m_tip_scale);

View File

@@ -291,7 +291,7 @@ std::array<std::vector<vertex_t>, 6> Canvas::stroke_draw_project(std::array<vert
{
glm::vec4 plane_local = plane_camera * glm::vec4(hit, 1);
//P[j].uvs2 = xy(P[j].pos) / glm::vec2(App::I.width, App::I.height);
//P[j].uvs2 = xy(P[j].pos) / glm::vec2(App::I->width, App::I->height);
vertex_t v;
v.pos.x = -(plane_local.x * 0.5f - 0.5f) * m_width;
v.pos.y = (plane_local.y * 0.5f + 0.5f) * m_height;
@@ -411,18 +411,18 @@ std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute(Stroke& stroke) con
+dx - dy, // D - bottom-right
};
glm::vec2 mixer_sz(App::I.width, App::I.height);
glm::vec2 mixer_sz(App::I->width, App::I->height);
glm::vec2 mixer_bb_min(mixer_sz);
glm::vec2 mixer_bb_max(0, 0);
for (int j = 0; j < 4; j++)
{
auto p = (xy(prev.pos) + App::I.zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle));
auto p = (xy(prev.pos) + App::I->zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle));
mixer_bb_min = glm::max({ 0, 0 }, glm::min(mixer_bb_min, p));
mixer_bb_max = glm::min(mixer_sz, glm::max(mixer_bb_max, p));
if (s.pos.z == 0.f)
{
B[j].pos = glm::vec4(xy(s.pos) + App::I.zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
B[j].pos = glm::vec4(xy(s.pos) + App::I->zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
}
else
{
@@ -433,7 +433,7 @@ std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute(Stroke& stroke) con
B[j].uvs2 = p / mixer_sz;
}
f.m_mixer_rect = glm::vec4(glm::floor(mixer_bb_min), glm::ceil(mixer_bb_max - mixer_bb_min)) / App::I.zoom;
f.m_mixer_rect = glm::vec4(glm::floor(mixer_bb_min), glm::ceil(mixer_bb_max - mixer_bb_min)) / App::I->zoom;
f.col = glm::vec4(s.col, 1);
f.flow = s.flow;
f.opacity = s.opacity;
@@ -695,7 +695,7 @@ void Canvas::stroke_commit()
m_dirty = false;
m_dirty_stroke = true; // new stroke ready for timelapse capture
App::I.redraw = true;
App::I->redraw = true;
// save viewport and clear color states
GLint vp[4];
@@ -709,7 +709,7 @@ void Canvas::stroke_commit()
action->was_saved = !m_unsaved;
m_unsaved = true;
App::I.title_update();
App::I->title_update();
// prepare common states
glViewport(0, 0, m_width, m_height);
@@ -1217,7 +1217,7 @@ void Canvas::layer_merge(int source_idx, int dest_idx) // m_layer index
{
m_dirty = false;
App::I.render_task([&]
App::I->render_task([&]
{
// prepare common states
glViewport(0, 0, m_width, m_height);
@@ -1438,7 +1438,7 @@ void Canvas::FloodData::apply()
if (!dirty[plane])
continue;
auto& rtt = layer->m_rtt[plane];
App::I.render_task([&]
App::I->render_task([&]
{
rtt.bindTexture();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rtt.getWidth(), rtt.getHeight(),
@@ -1575,7 +1575,7 @@ void Canvas::clear_context()
void Canvas::import_equirectangular(std::string file_path, std::shared_ptr<Layer> layer /*= nullptr*/)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -1657,7 +1657,7 @@ void Canvas::import_equirectangular_thread(std::string file_path, std::shared_pt
void Canvas::export_equirectangular(std::string file_path, std::function<void()> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -1672,16 +1672,16 @@ void Canvas::export_equirectangular(std::string file_path, std::function<void()>
void Canvas::export_equirectangular_thread(std::string file_path)
{
std::shared_ptr<NodeProgressBar> pb;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Export Pano Image");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
}
RTT m_latlong;
@@ -1697,7 +1697,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // bottom
};
App::I.render_task([&]
App::I->render_task([&]
{
glGenTextures(1, &cube_id);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
@@ -1716,7 +1716,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
for (int i = 0; i < 6; i++)
{
App::I.render_task([&]
App::I->render_task([&]
{
// prepare common states
glViewport(0, 0, m_width, m_height);
@@ -1795,7 +1795,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
@@ -1813,7 +1813,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
// int ret = stbi_write_png(name, m_tmp[i].getWidth(), m_tmp[i].getHeight(), 4, data.get(), m_tmp[i].stride());
//}
App::I.render_task([&]
App::I->render_task([&]
{
glDisable(GL_BLEND);
glViewport(0, 0, m_latlong.getWidth(), m_latlong.getHeight());
@@ -1836,7 +1836,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
progress++;
LOG("progress: %f", (float)progress / total * 100.f);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP((float)progress / total * 100.f);
}
@@ -1855,7 +1855,7 @@ void Canvas::export_equirectangular_thread(std::string file_path)
progress++;
LOG("progress: %f", (float)progress / total * 100.f);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP((float)progress / total * 100.f);
}
@@ -1876,13 +1876,13 @@ void Canvas::export_equirectangular_thread(std::string file_path)
}];
#endif
App::I.render_task_async([id=cube_id]
App::I->render_task_async([id=cube_id]
{
glDeleteTextures(1, &id);
});
m_latlong.destroy();
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->destroy();
}
@@ -1938,7 +1938,7 @@ void Canvas::inject_xmp(std::string jpg_path)
void Canvas::export_depth(std::string file_name, std::function<void()> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
export_depth_thread(file_name);
@@ -1957,7 +1957,7 @@ void Canvas::export_depth_thread(std::string file_name)
glm::mat4 proj = glm::perspective(glm::radians(m_cam_fov), (float)rtt.getWidth() / (float)rtt.getHeight(), 0.1f, 100.f);
glm::mat4 camera = m_cam_rot;
App::I.render_task([&]
App::I->render_task([&]
{
draw_merge();
@@ -1999,11 +1999,11 @@ void Canvas::export_depth_thread(std::string file_name)
uint8_t* rgba_data = rtt.readTextureData();
stbi_flip_vertically_on_write(true);
std::string path_rgba = App::I.work_path + "/" + file_name + ".png";
std::string path_rgba = App::I->work_path + "/" + file_name + ".png";
stbi_write_jpg(path_rgba.c_str(), rtt.getWidth(), rtt.getHeight(), 4, rgba_data, 100);
delete rgba_data;
App::I.render_task([&]
App::I->render_task([&]
{
rtt.bindFramebuffer();
rtt.clear({ 0, 0, 0, 1 });
@@ -2041,7 +2041,7 @@ void Canvas::export_depth_thread(std::string file_name)
});
uint8_t* depth_data = rtt.readTextureData();
std::string path_depth = App::I.work_path + "/" + file_name + "_depth.png";
std::string path_depth = App::I->work_path + "/" + file_name + "_depth.png";
stbi_write_jpg(path_depth.c_str(), rtt.getWidth(), rtt.getHeight(), 4, depth_data, 100);
delete depth_data;
stbi_flip_vertically_on_write(false);
@@ -2051,7 +2051,7 @@ void Canvas::export_depth_thread(std::string file_name)
void Canvas::export_layers(std::string file_name, std::function<void()> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -2066,16 +2066,16 @@ void Canvas::export_layers(std::string file_name, std::function<void()> on_compl
void Canvas::export_layers_thread(std::string file_name)
{
std::shared_ptr<NodeProgressBar> pb;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Export Pano Layers");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
}
int progress = 0;
int total = (int)(m_layers.size() + 1) * 6;
@@ -2092,7 +2092,7 @@ void Canvas::export_layers_thread(std::string file_name)
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, // top
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, // bottom
};
App::I.render_task([&]
App::I->render_task([&]
{
glGenTextures(1, &cube_id);
glBindTexture(GL_TEXTURE_CUBE_MAP, cube_id);
@@ -2105,7 +2105,7 @@ void Canvas::export_layers_thread(std::string file_name)
{
for (int i = 0; i < 6; i++)
{
App::I.render_task([&]
App::I->render_task([&]
{
glEnable(GL_BLEND);
glViewport(0, 0, m_width, m_height);
@@ -2150,13 +2150,13 @@ void Canvas::export_layers_thread(std::string file_name)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
}
App::I.render_task([&]
App::I->render_task([&]
{
glViewport(0, 0, m_latlong.getWidth(), m_latlong.getHeight());
glActiveTexture(GL_TEXTURE0);
@@ -2178,7 +2178,7 @@ void Canvas::export_layers_thread(std::string file_name)
auto latlong_data = std::make_unique<uint8_t[]>(m_latlong.bytes());
m_latlong.readTextureData(latlong_data.get());
static char name[128];
sprintf(name, "%s/%s-layer-%02d.png", App::I.work_path.c_str(), file_name.c_str(), seq);
sprintf(name, "%s/%s-layer-%02d.png", App::I->work_path.c_str(), file_name.c_str(), seq);
seq++;
LOG("writing %s", name);
int ret = stbi_write_png(name, m_latlong.getWidth(), m_latlong.getHeight(), 4, latlong_data.get(), m_latlong.stride());
@@ -2188,19 +2188,19 @@ void Canvas::export_layers_thread(std::string file_name)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
}
App::I.render_task([&]
App::I->render_task([&]
{
glDeleteTextures(1, &cube_id);
m_latlong.destroy();
});
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->destroy();
}
@@ -2208,7 +2208,7 @@ void Canvas::export_layers_thread(std::string file_name)
void Canvas::export_cubes()
{
if (!App::I.check_license())
if (!App::I->check_license())
return;
#ifdef __OBJC__
NSMutableArray* files = [NSMutableArray array];
@@ -2255,7 +2255,7 @@ void Canvas::export_cubes()
}
static char name[128];
sprintf(name, "%s-%02d-%d.png", App::I.work_path.c_str(), layer, plane);
sprintf(name, "%s-%02d-%d.png", App::I->work_path.c_str(), layer, plane);
int ret = stbi_write_png(name, m_width, m_height, 4, buffer.get(), 0);
@@ -2280,7 +2280,7 @@ void Canvas::export_cubes()
}
#ifdef __OBJC__
static char name[128];
sprintf(name, "%s.zip", App::I.work_path.c_str());
sprintf(name, "%s.zip", App::I->work_path.c_str());
auto zip_path = [NSString stringWithUTF8String : name];
//[SSZipArchive createZipFileAtPath:zip_path withFilesAtPaths:files];
for (NSString* f : files)
@@ -2290,11 +2290,11 @@ void Canvas::export_cubes()
void Canvas::project_save(std::function<void(bool)> on_complete)
{
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
bool ret = project_save_thread(App::I.doc_path);
bool ret = project_save_thread(App::I->doc_path);
if (on_complete)
on_complete(ret);
});
@@ -2305,7 +2305,7 @@ void Canvas::project_save(std::function<void(bool)> on_complete)
void Canvas::project_save(std::string file_path, std::function<void(bool)> on_complete)
{
LOG("saving %s", file_path.c_str());
if (App::I.check_license())
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
@@ -2324,7 +2324,7 @@ void Canvas::project_save(std::string file_path, std::function<void(bool)> on_co
bool Canvas::project_save_thread(std::string file_path)
{
// already saved, nothing to do
if (!m_unsaved && file_path == App::I.doc_path)
if (!m_unsaved && file_path == App::I->doc_path)
{
LOG("already saved");
return true;
@@ -2336,7 +2336,7 @@ bool Canvas::project_save_thread(std::string file_path)
auto start = file_path.rfind('/') + 1;
std::string file_name = file_path.substr(start, file_path.length() - start - strlen(".ppi"));
std::string tmp_path = App::I.data_path + '/' + file_name + ".tmp.ppi";
std::string tmp_path = App::I->data_path + '/' + file_name + ".tmp.ppi";
LOG("file name %s", file_name.c_str());
LOG("tmp path %s", tmp_path.c_str());
@@ -2375,13 +2375,13 @@ bool Canvas::project_save_thread(std::string file_path)
// load thumbnail
Image thumb = thumbnail_generate(ppi_header.thumb_header.width, ppi_header.thumb_header.height);
auto pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Saving Pano Project");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
thumb.flip();
fwrite(thumb.data(), thumb.size(), 1, fp);
@@ -2484,7 +2484,7 @@ bool Canvas::project_save_thread(std::string file_path)
}
pb->destroy();
App::I.title_update();
App::I->title_update();
return success;
}
@@ -2519,16 +2519,16 @@ bool Canvas::project_open_thread(std::string file_path)
}
std::shared_ptr<NodeProgressBar> pb;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb = std::make_shared<NodeProgressBar>();
pb->m_manager = &App::I.layout;
pb->m_manager = &App::I->layout;
pb->init();
pb->create();
pb->loaded();
pb->m_progress->SetWidthP(0);
pb->m_title->set_text("Opening Pano Project");
App::I.layout[App::I.main_id]->add_child(pb);
App::I->layout[App::I->main_id]->add_child(pb);
}
// skip thumbnail
@@ -2615,7 +2615,7 @@ bool Canvas::project_open_thread(std::string file_path)
float p = (float)progress / total * 100.f;
LOG("progress: %f", p);
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->m_progress->SetWidthP(p);
}
@@ -2643,10 +2643,10 @@ bool Canvas::project_open_thread(std::string file_path)
memset(m_pick_ready, 0, sizeof(bool) * 6);
m_unsaved = false;
m_newdoc = false;
if (App::I.layout.m_loaded)
if (App::I->layout.m_loaded)
{
pb->destroy();
App::I.title_update();
App::I->title_update();
}
return true;
}
@@ -2656,7 +2656,7 @@ Image Canvas::thumbnail_generate(int w, int h)
Image image;
image.create(w, h);
App::I.render_task([this, w, h, &image]
App::I->render_task([this, w, h, &image]
{
// save viewport and clear color states
GLint vp[4];
@@ -2795,7 +2795,7 @@ Image Canvas::thumbnail_read(std::string file_path)
void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer)
{
App::I.render_task([&]
App::I->render_task([&]
{
// save viewport and clear color states
GLint vp[4];
@@ -2842,7 +2842,7 @@ void Canvas::draw_objects_direct(std::function<void(const glm::mat4& camera, con
void Canvas::draw_objects(std::function<void(const glm::mat4& camera, const glm::mat4& proj, int i)> observer, Layer& layer)
{
App::I.render_task([&]
App::I->render_task([&]
{
// save viewport and clear color states
GLint vp[4];
@@ -3105,7 +3105,7 @@ void Layer::restore(const Snapshot& snap)
// it's just a quick fix DON'T SHIP!!
//m_rtt[i].recreate();
App::I.render_task_async([this,i,&snap]
App::I->render_task_async([this,i,&snap]
{
m_rtt[i].bindTexture();
glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]);
@@ -3118,7 +3118,7 @@ void Layer::restore(const Snapshot& snap)
(int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
});
}
App::I.render_sync();
App::I->render_sync();
}
Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6> * dirty_box /*= nullptr*/, std::array<bool, 6> * dirty_face /*= nullptr*/)
@@ -3136,7 +3136,7 @@ Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6> * dirty_box /*= nullptr
snap.image[i] = std::make_unique<uint8_t[]>(m_rtt[i].bytes());
App::I.render_task_async([this,i,&snap]
App::I->render_task_async([this,i,&snap]
{
m_rtt[i].bindFramebuffer();
glm::vec2 box_sz = zw(snap.m_dirty_box[i]) - xy(snap.m_dirty_box[i]);
@@ -3145,13 +3145,13 @@ Layer::Snapshot Layer::snapshot(std::array<glm::vec4, 6> * dirty_box /*= nullptr
m_rtt[i].unbindFramebuffer();
});
}
App::I.render_sync();
App::I->render_sync();
return snap;
}
void Layer::clear(const glm::vec4& c)
{
App::I.render_task([&]
App::I->render_task([&]
{
// push clear color state
GLfloat cc[4];
@@ -3188,7 +3188,7 @@ bool Layer::create(int width, int height, std::string name)
m_name = name;
w = width;
h = height;
App::I.render_task([&]
App::I->render_task([&]
{
for (int i = 0; i < 6; i++)
{

View File

@@ -34,7 +34,7 @@ void ActionStroke::undo()
glm::vec2 box_sz = zw(m_box[i]) - xy(m_box[i]);
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= m_canvas->m_layers[m_layer_idx]->w && box_sz.y <= m_canvas->m_layers[m_layer_idx]->h)
{
App::I.render_task([&]
App::I->render_task([&]
{
m_canvas->m_layers[m_layer_idx]->m_rtt[i].bindTexture();
glTexSubImage2D(GL_TEXTURE_2D, 0, (int)m_box[i].x, (int)m_box[i].y, (int)box_sz.x, (int)box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, m_image[i].get());
@@ -77,7 +77,7 @@ Action* ActionStroke::get_redo()
if (box_sz.x > 0 && box_sz.y > 0 && box_sz.x <= layer->w && box_sz.y <= layer->h)
{
action->m_image[i] = std::make_unique<uint8_t[]>(box_sz.x * box_sz.y * 4);
App::I.render_task([&]
App::I->render_task([&]
{
layer->m_rtt[i].bindFramebuffer();
glReadPixels(box_or.x, box_or.y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, action->m_image[i].get());

View File

@@ -31,9 +31,9 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
// }
break;
case kEventType::MouseDownR:
if (App::I.keys[(int)kKey::KeyAlt])
if (App::I->keys[(int)kKey::KeyAlt])
break;
m_zooming = App::I.keys[(int)kKey::KeyCtrl];
m_zooming = App::I->keys[(int)kKey::KeyCtrl];
m_draggingR = true;
m_dragR_start = me->m_pos;
m_pan_start = Canvas::I->m_pan;
@@ -53,7 +53,7 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
}
else
{
auto dir = (App::I.has_vr && App::I.vr_active) ? glm::vec2(1, 1) : glm::vec2(-1, -1);
auto dir = (App::I->has_vr && App::I->vr_active) ? glm::vec2(1, 1) : glm::vec2(-1, -1);
Canvas::I->m_pan = m_pan_start + (me->m_pos - m_dragR_start) * dir * (Canvas::I->m_cam_fov / 85.f);
auto angle = Canvas::I->m_pan * 0.003f;
Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
@@ -63,7 +63,7 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
case kEventType::MouseScroll:
m_zoom_canvas += me->m_scroll_delta * 0.1f;
Canvas::I->m_cam_fov -= me->m_scroll_delta * 2.0f;
App::I.brush_update();
App::I->brush_update();
break;
case kEventType::MouseCancel:
m_draggingR = false;
@@ -89,7 +89,7 @@ void CanvasModeBasicCamera::on_GestureEvent(GestureEvent* ge)
Canvas::I->m_cam_fov = m_camera_fov - ge->m_distance_delta * .05f;
auto angle = Canvas::I->m_pan * 0.003f;
Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
App::I.brush_update();
App::I->brush_update();
break;
}
default:
@@ -125,17 +125,17 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
switch (me->m_type)
{
case kEventType::MouseDownL:
if (App::I.keys[(int)kKey::KeyAlt] || m_picking)
if (App::I->keys[(int)kKey::KeyAlt] || m_picking)
{
m_picking = true;
Canvas::I->pick_start();
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I.brush_update();
App::I->brush_update();
}
else
{
App::I.render_task_async([loc, pr=me->m_pressure]
App::I->render_task_async([loc, pr=me->m_pressure]
{
Canvas::I->stroke_start({ loc, 0 }, pr);
});
@@ -147,7 +147,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
if (m_dragging && !m_picking)
{
node->mouse_release();
App::I.render_task_async([]
App::I->render_task_async([]
{
Canvas::I->stroke_end();
});
@@ -157,19 +157,19 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
node->mouse_release();
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I.brush_update();
App::I->brush_update();
Canvas::I->pick_end();
}
m_dragging = false;
m_picking = false;
break;
case kEventType::MouseDownR:
if (App::I.keys[(int)kKey::KeyAlt])
if (App::I->keys[(int)kKey::KeyAlt])
{
m_resizing = true;
m_dragging = true;
m_size_pos_start = m_cur_pos;
auto curve = App::I.stroke->m_curves[App::I.stroke->m_tip_size];
auto curve = App::I->stroke->m_curves[App::I->stroke->m_tip_size];
m_size_value_start = curve.to_slider(Canvas::I->m_current_brush->m_tip_size);
node->mouse_capture();
}
@@ -185,7 +185,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
case kEventType::MouseMove:
if (m_dragging && !m_picking && !m_resizing)
{
App::I.render_task_async([loc, pr=me->m_pressure]
App::I->render_task_async([loc, pr=me->m_pressure]
{
Canvas::I->stroke_update({ loc, 0 }, pr);
});
@@ -194,21 +194,21 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I.brush_update();
App::I->brush_update();
}
if (m_dragging && m_resizing)
{
auto diff = m_cur_pos - m_size_pos_start;
auto curve = App::I.stroke->m_curves[App::I.stroke->m_tip_size];
auto curve = App::I->stroke->m_curves[App::I->stroke->m_tip_size];
Canvas::I->m_current_brush->m_tip_size = glm::max(curve.to_value(m_size_value_start + diff.x * 0.001f), 0.001f);
App::I.brush_update();
App::I->brush_update();
}
m_cur_pos = loc;
break;
case kEventType::MouseCancel:
if (m_dragging)
{
App::I.render_task_async([]
App::I->render_task_async([]
{
Canvas::I->stroke_cancel();
});
@@ -231,14 +231,14 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const
{
const auto& brush = Canvas::I->m_current_brush;
auto pos = m_resizing ? m_size_pos_start : m_cur_pos;
//if (App::I.keys[(int)kKey::KeyAlt] && !m_resizing)
//if (App::I->keys[(int)kKey::KeyAlt] && !m_resizing)
// pos.x = pos.x - brush->m_tip_size * .5f;
ShaderManager::use(kShader::StrokePreview);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_float(kShaderUniform::Alpha, brush->m_tip_flow * brush->m_tip_opacity);
float tip_scale_fix = 1.f / glm::tan(glm::radians(Canvas::I->m_cam_fov * 0.5f));
float tip_angle = brush->m_tip_angle * (float)(M_PI * 2.0);
glm::vec2 tip_scale = App::I.zoom * brush->m_tip_scale *
glm::vec2 tip_scale = App::I->zoom * brush->m_tip_scale *
glm::vec2(brush->m_tip_size * tip_scale_fix) *
glm::vec2(brush->m_tip_flipx ? -1 : 1, brush->m_tip_flipy ? -1.f : 1.f) *
glm::vec2((brush->m_tip_aspect <= 0.5 ? brush->m_tip_aspect * 2.f : 1.f),
@@ -250,14 +250,14 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const
const auto& s = Canvas::I->m_current_stroke->m_prev_sample;
if (s.size > 0.f)
{
tip_scale = App::I.zoom * (brush->m_tip_size * tip_scale_fix) * s.scale;
tip_scale = App::I->zoom * (brush->m_tip_size * tip_scale_fix) * s.scale;
tip_angle = s.angle;
tip_offset = s.pos - s.origin;
tip_color = glm::vec4(s.col, s.flow);
}
}
glm::u8vec4 pixel;
glReadPixels(pos.x / App::I.zoom, (App::I.height - pos.y - 1) / App::I.zoom, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
glReadPixels(pos.x / App::I->zoom, (App::I->height - pos.y - 1) / App::I->zoom, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
bool outline = glm::min(tip_scale.x, tip_scale.y) < 20 || m_resizing ? false : m_draw_outline;
ShaderManager::u_int(kShaderUniform::DrawOutline, outline);
ShaderManager::u_vec4(kShaderUniform::Col, outline ? glm::vec4(1.f - glm::vec3(pixel) / 255.f, 1.f) : tip_color);
@@ -312,7 +312,7 @@ void CanvasModeLine::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
node->mouse_release();
if (m_dragging)
{
App::I.render_task_async([=]
App::I->render_task_async([=]
{
Canvas::I->stroke_start({ m_drag_start, 0 }, 1.f);
Canvas::I->stroke_update({ m_drag_pos, 0 }, 1.f);
@@ -359,7 +359,7 @@ void CanvasModeLine::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, cons
ShaderManager::u_float(kShaderUniform::Alpha, brush->m_tip_flow * brush->m_tip_opacity);
float tip_scale_fix = 1.f / glm::tan(glm::radians(Canvas::I->m_cam_fov * 0.5f));
float tip_angle = brush->m_tip_angle * (float)(M_PI * 2.0);
glm::vec2 tip_scale = App::I.zoom * brush->m_tip_scale *
glm::vec2 tip_scale = App::I->zoom * brush->m_tip_scale *
glm::vec2(brush->m_tip_size * tip_scale_fix) *
glm::vec2(brush->m_tip_flipx ? -1 : 1, brush->m_tip_flipy ? -1.f : 1.f) *
glm::vec2((brush->m_tip_aspect <= 0.5 ? brush->m_tip_aspect * 2.f : 1.f),
@@ -653,7 +653,7 @@ void CanvasModeMaskFree::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
m_points2d.push_back(loc);
m_points.push_back(vert);
m_points.push_back(vert);
if (!(App::I.keys[(int)kKey::KeyShift] || App::I.keys[(int)kKey::KeyCtrl]))
if (!(App::I->keys[(int)kKey::KeyShift] || App::I->keys[(int)kKey::KeyCtrl]))
Canvas::I->m_smask.clear({0, 0, 0, 0});
Canvas::I->m_smask_active = true;
Canvas::I->m_smask_mode = 1;
@@ -674,7 +674,7 @@ void CanvasModeMaskFree::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
ShaderManager::use(kShader::Color);
ShaderManager::u_mat4(kShaderUniform::MVP, proj * camera);
ShaderManager::u_vec4(kShaderUniform::Col,
App::I.keys[(int)kKey::KeyCtrl] ? glm::vec4(0, 0, 0, 1) : glm::vec4(1, 1, 1, 1));
App::I->keys[(int)kKey::KeyCtrl] ? glm::vec4(0, 0, 0, 1) : glm::vec4(1, 1, 1, 1));
m_shape.draw_fill();
};
// use m_shape to render the mask polygon
@@ -1072,7 +1072,7 @@ void CanvasModeTransform::enter(kCanvasMode prev)
}
auto center = zw(Canvas::I->m_box) * 0.5f;
glm::vec2 bb_sz = glm::vec2(aspect, 1.f) * 100.f * App::I.zoom;
glm::vec2 bb_sz = glm::vec2(aspect, 1.f) * 100.f * App::I->zoom;
glm::vec2 bb_min = center - bb_sz * 0.5f;
glm::vec2 bb_max = center + bb_sz * 0.5f;
glm::vec2 midpoint = (bb_min + bb_max) * 0.5f;
@@ -1207,7 +1207,7 @@ void CanvasModeTransform::enter(kCanvasMode prev)
auto shape3d = triangulate(m_points_face[plane]);
App::I.render_task([&]
App::I->render_task([&]
{
m_shape[plane].update_vertices(shape3d.data(), (int)shape3d.size());
Canvas::I->m_layers[Canvas::I->m_current_layer_idx]->m_rtt[plane].bindFramebuffer();
@@ -1269,7 +1269,7 @@ void CanvasModeTransform::enter(kCanvasMode prev)
glm::max(zw(layer->m_dirty_box[i]), bb_max),
};
App::I.render_task([&]
App::I->render_task([&]
{
glViewport(0, 0, layer->w, layer->h);
glDisable(GL_DEPTH_TEST);
@@ -1367,7 +1367,7 @@ void CanvasModeTransform::leave(kCanvasMode next)
glm::max(zw(layer->m_dirty_box[i]), bb_max),
};
App::I.render_task([&]
App::I->render_task([&]
{
layer->m_rtt[i].bindFramebuffer();
@@ -1451,7 +1451,7 @@ void CanvasModeTransform::on_Draw(const glm::mat4& ortho, const glm::mat4& proj,
auto c2d = (xy(c3d) * 0.5f + 0.5f) * zw(Canvas::I->m_box);
ShaderManager::u_mat4(kShaderUniform::MVP,
ortho * glm::translate(glm::vec3(c2d, 0)) * glm::scale(glm::vec3(20.f) * App::I.zoom));
ortho * glm::translate(glm::vec3(c2d, 0)) * glm::scale(glm::vec3(20.f) * App::I->zoom));
// draw inside
ShaderManager::u_vec4(kShaderUniform::Col, { 1, 1, 1, i == corner_hl ? 1.f : .1f });
@@ -1488,7 +1488,7 @@ void CanvasModeTransform::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
auto c = m2d * glm::vec4(corners[i], 1);
corners2d[i] = ((xy(c) / c.z) * 0.5f + 0.5f) * zw(Canvas::I->m_box);
float d = glm::distance(corners2d[i], loc);
if (d < 20.f * App::I.zoom)
if (d < 20.f * App::I->zoom)
corner_hl = i;
}
if (corner_hl != -1)
@@ -1514,7 +1514,7 @@ void CanvasModeTransform::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
auto c = m2d * glm::vec4(corners[i], 1);
corners2d[i] = ((xy(c) / c.z) * 0.5f + 0.5f) * zw(Canvas::I->m_box);
float d = glm::distance(corners2d[i], loc);
if (d < 20.f * App::I.zoom)
if (d < 20.f * App::I->zoom)
corner_hl = i;
}
if (m_dragging)
@@ -1683,7 +1683,7 @@ void CanvasModeFloodFill::on_Draw(const glm::mat4& ortho, const glm::mat4& proj,
void CanvasModeFloodFill::enter(kCanvasMode prev)
{
auto tools = App::I.layout[App::I.main_id]->find("tools-container");
auto tools = App::I->layout[App::I->main_id]->find("tools-container");
m_tool = tools->add_child<NodeToolBucket>();
}

View File

@@ -60,7 +60,7 @@ const Font& FontManager::get(kFont id)
bool TextMesh::create()
{
App::I.render_task([this]
App::I->render_task([this]
{
glGenBuffers(2, font_buffers);
#if USE_VBO
@@ -125,7 +125,7 @@ void TextMesh::update(kFont id, const char* text)
vi -= glm::vec4(bbmin, 0, 0);
bb = bbmax - bbmin;
font_array_count = (int)idx.size();
App::I.render_task([&]
App::I->render_task([&]
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, font_buffers[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx.size() * sizeof(GLushort), idx.data(), GL_STATIC_DRAW);

View File

@@ -75,7 +75,7 @@ void LogRemote::net_close()
void LogRemote::file_init()
{
if (!m_logfile.is_open())
m_logfile.open(App::I.data_path + "/panopainter-log.txt");
m_logfile.open(App::I->data_path + "/panopainter-log.txt");
}
void LogRemote::file_close()
{

View File

@@ -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:

View File

@@ -39,8 +39,8 @@
void Node::app_redraw()
{
App::I.redraw = true;
App::I.ui_cv.notify_all();
App::I->redraw = true;
App::I->ui_cv.notify_all();
}
void Node::watch(std::function<bool(Node*)> observer)
@@ -303,7 +303,7 @@ void Node::removed(Node* parent)
const Node* Node::init_template(const char* id)
{
Node* m_template = nullptr;
App::I.ui_task([&]
App::I->ui_task([&]
{
auto hid = const_hash(id);
Node* top = m_manager->get(hid);
@@ -324,7 +324,7 @@ const Node* Node::init_template(const char* id)
void Node::add_child(Node* n)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
if (n->m_parent)
n->m_parent->remove_child(n);
@@ -339,7 +339,7 @@ void Node::add_child(Node* n)
void Node::add_child(Node* n, int index)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
if (n->m_parent)
n->m_parent->remove_child(n);
@@ -354,7 +354,7 @@ void Node::add_child(Node* n, int index)
void Node::add_child(std::shared_ptr<Node> n)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
if (n->m_parent)
n->m_parent->remove_child(n.get());
@@ -369,7 +369,7 @@ void Node::add_child(std::shared_ptr<Node> n)
void Node::add_child(std::shared_ptr<Node> n, int index)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
if (n->m_parent)
n->m_parent->remove_child(n.get());
@@ -393,7 +393,7 @@ void Node::remove_child(Node* n)
auto i = std::find_if(m_children.begin(), m_children.end(), [=](auto& ptr) { return ptr.get() == n; });
if (i != m_children.end())
{
App::I.ui_task([&]
App::I->ui_task([&]
{
n->removed(this);
n->m_parent = nullptr;
@@ -408,7 +408,7 @@ void Node::remove_child(Node* n)
void Node::remove_all_children()
{
App::I.ui_task([&]
App::I->ui_task([&]
{
for (auto& n : m_children)
{
@@ -424,7 +424,7 @@ void Node::remove_all_children()
void Node::move_child(Node* n, int index)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
YGNodeRemoveChild(y_node, n->y_node);
YGNodeInsertChild(y_node, n->y_node, index);
@@ -438,7 +438,7 @@ void Node::move_child(Node* n, int index)
void Node::move_child_front(Node* n)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
int count = YGNodeGetChildCount(y_node);
move_child(n, count - 1);
@@ -447,7 +447,7 @@ void Node::move_child_front(Node* n)
void Node::move_child_offset(Node* n, int offset)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
int count = YGNodeGetChildCount(y_node);
for (int i = 0; i < count; i++)
@@ -879,7 +879,7 @@ void Node::SetRTL(YGDirection dir)
void Node::SetVisibility(bool visible)
{
App::I.ui_task([&]
App::I->ui_task([&]
{
if (m_display && !visible)
{

View File

@@ -121,7 +121,7 @@ void NodeCanvas::draw()
{
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(c.x + App::I.off_x, c.y + App::I.off_y, c.z, c.w);
glViewport(c.x + App::I->off_x, c.y + App::I->off_y, c.z, c.w);
}
// NOTE: draw_merge has been disabled for worst performance
@@ -481,7 +481,7 @@ void NodeCanvas::draw()
for (auto& mode : Canvas::modes[(int)kCanvasMode::Grid])
mode->on_Draw(ortho_proj, proj, camera);
App::I.grid->draw_heightmap(proj, camera, false);
App::I->grid->draw_heightmap(proj, camera, false);
for (auto& mode : *m_canvas->m_mode)
mode->on_Draw(ortho_proj, proj, camera);
@@ -492,7 +492,7 @@ void NodeCanvas::draw()
glClearColor(1, 1, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(c.x + App::I.off_x, c.y + App::I.off_y, c.z, c.w);
glViewport(c.x + App::I->off_x, c.y + App::I->off_y, c.z, c.w);
// draw the canvas
m_sampler_nearest.bind(0);
@@ -567,12 +567,12 @@ kEventResult NodeCanvas::handle_event(Event* e)
break;
case kEventType::MouseUnfocus:
(*m_canvas->m_mode)[0]->m_draw_tip = false;
App::I.show_cursor();
App::I->show_cursor();
break;
case kEventType::MouseFocus:
(*m_canvas->m_mode)[0]->hide_curor &&
!App::I.keys[(int)kKey::KeyAlt] ?
App::I.hide_cursor() : App::I.show_cursor();
!App::I->keys[(int)kKey::KeyAlt] ?
App::I->hide_cursor() : App::I->show_cursor();
break;
case kEventType::KeyDown:
if (ke->m_key == kKey::KeyE)
@@ -581,40 +581,40 @@ kEventResult NodeCanvas::handle_event(Event* e)
if (!ActionManager::empty())
ActionManager::undo();
if (ke->m_key == kKey::KeyAlt && m_mouse_focus)
App::I.show_cursor();
App::I->show_cursor();
for (auto& mode : *m_canvas->m_mode)
mode->on_KeyEvent(ke);
break;
case kEventType::KeyUp:
if (ke->m_key == kKey::KeyAlt && m_mouse_focus)
(*m_canvas->m_mode)[0]->hide_curor ?
App::I.hide_cursor() : App::I.show_cursor();
App::I->hide_cursor() : App::I->show_cursor();
if (ke->m_key == kKey::KeyE)
Canvas::set_mode(kCanvasMode::Draw);
if (ke->m_key == kKey::KeyTab)
App::I.toggle_ui();
if (ke->m_key == kKey::KeyZ && App::I.keys[(int)kKey::KeyCtrl])
App::I.keys[(int)kKey::KeyShift] ? ActionManager::redo() : ActionManager::undo();
if (ke->m_key == kKey::KeyS && App::I.keys[(int)kKey::KeyCtrl] && !App::I.keys[(int)kKey::KeyShift])
App::I->toggle_ui();
if (ke->m_key == kKey::KeyZ && App::I->keys[(int)kKey::KeyCtrl])
App::I->keys[(int)kKey::KeyShift] ? ActionManager::redo() : ActionManager::undo();
if (ke->m_key == kKey::KeyS && App::I->keys[(int)kKey::KeyCtrl] && !App::I->keys[(int)kKey::KeyShift])
{
if (Canvas::I->m_newdoc)
{
App::I.dialog_save();
App::I->dialog_save();
}
else if (Canvas::I->m_unsaved)
{
Canvas::I->project_save();
}
}
if (ke->m_key == kKey::KeyS && App::I.keys[(int)kKey::KeyCtrl] && App::I.keys[(int)kKey::KeyShift])
if (ke->m_key == kKey::KeyS && App::I->keys[(int)kKey::KeyCtrl] && App::I->keys[(int)kKey::KeyShift])
{
if (Canvas::I->m_newdoc)
{
App::I.dialog_save();
App::I->dialog_save();
}
else if (Canvas::I->m_unsaved)
{
App::I.dialog_save_ver();
App::I->dialog_save_ver();
}
}
for (auto& mode : *m_canvas->m_mode)

View File

@@ -43,7 +43,7 @@ void NodeColorWheel::loaded()
vertices.push_back({{glm::cos(2.f/3.f*glm::pi<float>())*l,glm::sin(2.f/3.f*glm::pi<float>())*l,0,1},{0,0},{0,0,0,1}});
vertices.push_back({{l,0,0,1},{1,1},{1,0,0,1}});
App::I.render_task([&]
App::I->render_task([&]
{
glGenBuffers(1, &buffers);
glBindBuffer(GL_ARRAY_BUFFER, buffers);

View File

@@ -78,9 +78,9 @@ void NodeDialogBrowse::init_controls()
static char path_buffer[256];
btn_path = find<NodeButton>("btn-path");
btn_path->on_click = [this](Node*){
App::I.pick_dir([this](std::string path){
App::I->pick_dir([this](std::string path){
LOG("change working path to %s", path.c_str());
App::I.work_path = path;
App::I->work_path = path;
#ifdef _WIN32
GetFullPathNameA(path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
@@ -94,9 +94,9 @@ void NodeDialogBrowse::init_controls()
};
working_path = find<NodeText>("path");
#ifdef _WIN32
GetFullPathNameA(App::I.work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
GetFullPathNameA(App::I->work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(App::I.work_path.c_str(), path_buffer);
realpath(App::I->work_path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
#endif

View File

@@ -93,7 +93,7 @@ void NodeDialogCloud::load_thumbs_thread()
node->m_manager = m_manager;
node->init();
node->m_text->set_text(n.c_str());
node->m_path = App::I.work_path + "/" + n;
node->m_path = App::I->work_path + "/" + n;
node->m_file_name = n;
container->add_child(node);
node->on_selected = [&](NodeDialogCloudItem* target) {

View File

@@ -69,14 +69,14 @@ void NodeDialogOpen::init_controls()
root()->update();
};
container = find<Node>("files-list");
auto names = Asset::list_files(App::I.work_path, ".*\\.ppi");
auto names = Asset::list_files(App::I->work_path, ".*\\.ppi");
for (const auto& n : names)
{
auto node = new NodeDialogOpenItem;
node->m_manager = m_manager;
node->init();
node->m_text->set_text(n.c_str());
node->m_path = App::I.work_path + "/" + n;
node->m_path = App::I->work_path + "/" + n;
node->m_file_name = n;
node->on_selected = [&](NodeDialogOpenItem* target) {
if (target == current)
@@ -198,9 +198,9 @@ void NodeDialogSave::init_controls()
static char path_buffer[256];
btn_path = find<NodeButton>("btn-path");
btn_path->on_click = [this](Node*){
App::I.pick_dir([this](std::string path){
App::I->pick_dir([this](std::string path){
LOG("change working path to %s", path.c_str());
App::I.work_path = path;
App::I->work_path = path;
#ifdef _WIN32
GetFullPathNameA(path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
@@ -211,9 +211,9 @@ void NodeDialogSave::init_controls()
};
working_path = find<NodeText>("path");
#ifdef _WIN32
GetFullPathNameA(App::I.work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
GetFullPathNameA(App::I->work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(App::I.work_path.c_str(), path_buffer);
realpath(App::I->work_path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
#endif
@@ -259,9 +259,9 @@ void NodeDialogNewDoc::init_controls()
static char path_buffer[256];
btn_path = find<NodeButton>("btn-path");
btn_path->on_click = [this](Node*){
App::I.pick_dir([this](std::string path){
App::I->pick_dir([this](std::string path){
LOG("change working path to %s", path.c_str());
App::I.work_path = path;
App::I->work_path = path;
#ifdef _WIN32
GetFullPathNameA(path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
@@ -272,9 +272,9 @@ void NodeDialogNewDoc::init_controls()
};
working_path = find<NodeText>("path");
#ifdef _WIN32
GetFullPathNameA(App::I.work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
GetFullPathNameA(App::I->work_path.c_str(), sizeof(path_buffer), path_buffer, nullptr);
#else
realpath(App::I.work_path.c_str(), path_buffer);
realpath(App::I->work_path.c_str(), path_buffer);
#endif
working_path->set_text_format("Working dir: %s", path_buffer);
#endif

View File

@@ -92,7 +92,7 @@ void NodeColorPicker::init_controls()
m_btn_paste->on_click = [this](Node*)
{
std::string s = App::I.clipboard_get_text();
std::string s = App::I->clipboard_get_text();
std::regex r("#([\\dabcdefABCDEF]{6})");
std::smatch m;
if (std::regex_search(s, m, r))
@@ -108,7 +108,7 @@ void NodeColorPicker::init_controls()
m_btn_copy->on_click = [this](Node*)
{
App::I.clipboard_set_text(m_txt_hex->m_text);
App::I->clipboard_set_text(m_txt_hex->m_text);
};
m_wheel->on_value_changed = [this](Node*, glm::vec3 hsv)

View File

@@ -34,7 +34,7 @@ void NodeDialogResize::init_controls()
text = find<NodeText>("current-res");
resolution = Canvas::I->m_width;
static char txt[128];
sprintf(txt, "Current: %s", App::I.res_to_string(resolution).c_str());
sprintf(txt, "Current: %s", App::I->res_to_string(resolution).c_str());
text->set_text(txt);
btn_cancel->on_click = [this](Node*) {
destroy();
@@ -50,5 +50,5 @@ void NodeDialogResize::loaded()
int NodeDialogResize::get_resolution()
{
return combo ? App::I.res_from_index(combo->m_current_index) : 512;
return combo ? App::I->res_from_index(combo->m_current_index) : 512;
}

View File

@@ -48,8 +48,8 @@ bool NodeButtonBrush::read(BinaryStreamReader& r)
d.value<Serializer::CString>("high_path", high_path);
d.value<Serializer::CString>("thumb_path", thumb_path);
d.value<Serializer::Boolean>("m_user_brush", m_user_brush);
high_path = str_replace(high_path, "{data_path}", App::I.data_path);
thumb_path = str_replace(thumb_path, "{data_path}", App::I.data_path);
high_path = str_replace(high_path, "{data_path}", App::I->data_path);
thumb_path = str_replace(thumb_path, "{data_path}", App::I->data_path);
return true;
}
@@ -60,9 +60,9 @@ void NodeButtonBrush::write(BinaryStreamWriter& w) const
d.name = L"Brush class";
d.props["brush_name"] = std::make_shared<Serializer::CString>(brush_name);
d.props["high_path"] = std::make_shared<Serializer::CString>(
str_replace(high_path, App::I.data_path, "{data_path}"));
str_replace(high_path, App::I->data_path, "{data_path}"));
d.props["thumb_path"] = std::make_shared<Serializer::CString>(
str_replace(thumb_path, App::I.data_path, "{data_path}"));
str_replace(thumb_path, App::I->data_path, "{data_path}"));
d.props["m_user_brush"] = std::make_shared<Serializer::Boolean>(m_user_brush);
w << d;
}
@@ -78,7 +78,7 @@ void NodePanelBrush::init()
m_btn_add = find<NodeButtonCustom>("btn-add");
m_btn_add->on_click = [this](Node*) {
App::I.pick_file({ "JPG", "PNG" }, [this](std::string path) {
App::I->pick_file({ "JPG", "PNG" }, [this](std::string path) {
std::string name, base, ext;
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
std::smatch m;
@@ -90,8 +90,8 @@ void NodePanelBrush::init()
Image img;
if (!m_dir_name.empty() && img.load_file(path))
{
std::string path_high = App::I.data_path + "/" + m_dir_name + "/" + name + ".png";
std::string path_thumb = App::I.data_path + "/" + m_dir_name + "/thumbs/" + name + ".png";
std::string path_high = App::I->data_path + "/" + m_dir_name + "/" + name + ".png";
std::string path_thumb = App::I->data_path + "/" + m_dir_name + "/thumbs/" + name + ".png";
//img = img.resize_squared(glm::u8vec4(255));
if (m_dir_name == "brushes")
@@ -170,11 +170,11 @@ void NodePanelBrush::init()
m_container = find<NodeScroll>("brushes");
if (Asset::exist(App::I.data_path + "/settings/" + m_dir_name + ".bin") && !restore())
if (Asset::exist(App::I->data_path + "/settings/" + m_dir_name + ".bin") && !restore())
{
auto mb = App::I.message_box("Brushes", "Could not read brush textures file, it will be deleted.", true);
auto mb = App::I->message_box("Brushes", "Could not read brush textures file, it will be deleted.", true);
mb->btn_ok->on_click = [this, mb](Node*) {
Asset::delete_file(App::I.data_path + "/settings/" + m_dir_name + ".bin");
Asset::delete_file(App::I->data_path + "/settings/" + m_dir_name + ".bin");
mb->destroy();
};
mb->btn_cancel->on_click = [mb](Node*) {
@@ -202,11 +202,11 @@ void NodePanelBrush::init()
brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1);
}
auto custom_icons = Asset::list_files(App::I.data_path + "/" + m_dir_name, ".*\\.png$");
auto custom_icons = Asset::list_files(App::I->data_path + "/" + m_dir_name, ".*\\.png$");
for (auto& i : custom_icons)
{
std::string path_thumb = App::I.data_path + "/" + m_dir_name + "/thumbs/" + i;
std::string path_high = App::I.data_path + "/" + m_dir_name + "/" + i;
std::string path_thumb = App::I->data_path + "/" + m_dir_name + "/thumbs/" + i;
std::string path_high = App::I->data_path + "/" + m_dir_name + "/" + i;
NodeButtonBrush* brush = new NodeButtonBrush;
m_container->add_child(brush);
brush->init();
@@ -287,7 +287,7 @@ std::string NodePanelBrush::get_thumb_path(int index) const
bool NodePanelBrush::save()
{
std::ofstream f(App::I.data_path + "/settings/" + m_dir_name + ".bin", std::ios::binary);
std::ofstream f(App::I->data_path + "/settings/" + m_dir_name + ".bin", std::ios::binary);
if (f.good())
{
BinaryStreamWriter sw;
@@ -310,7 +310,7 @@ bool NodePanelBrush::save()
bool NodePanelBrush::restore()
{
Asset f;
auto path = App::I.data_path + "/settings/" + m_dir_name + ".bin";
auto path = App::I->data_path + "/settings/" + m_dir_name + ".bin";
if (f.open(path.c_str()))
{
f.read_all();
@@ -457,11 +457,11 @@ void NodePanelBrushPreset::init()
save();
};
if (Asset::exist(App::I.data_path + "/settings/presets.bin") && !restore())
if (Asset::exist(App::I->data_path + "/settings/presets.bin") && !restore())
{
auto mb = App::I.message_box("Presets", "Could not read brush presets file, it will be deleted.", true);
auto mb = App::I->message_box("Presets", "Could not read brush presets file, it will be deleted.", true);
mb->btn_ok->on_click = [mb](Node*) {
Asset::delete_file(App::I.data_path + "/settings/presets.bin");
Asset::delete_file(App::I->data_path + "/settings/presets.bin");
mb->destroy();
};
mb->btn_cancel->on_click = [mb](Node*) {
@@ -509,7 +509,7 @@ void NodePanelBrushPreset::handle_click(Node* target)
bool NodePanelBrushPreset::save()
{
std::ofstream f(App::I.data_path + "/settings/presets.bin", std::ios::binary);
std::ofstream f(App::I->data_path + "/settings/presets.bin", std::ios::binary);
if (f.good())
{
BinaryStreamWriter sw;
@@ -532,7 +532,7 @@ bool NodePanelBrushPreset::save()
bool NodePanelBrushPreset::restore()
{
Asset f;
auto path = App::I.data_path + "/settings/presets.bin";
auto path = App::I->data_path + "/settings/presets.bin";
if (f.open(path.c_str()))
{
f.read_all();

View File

@@ -76,7 +76,7 @@ void NodePanelGrid::init_controls()
};
m_hm_load->on_click = [this](Node*) {
App::I.pick_image([this](std::string path) {
App::I->pick_image([this](std::string path) {
Image img;
if (img.load_file(path))
{
@@ -150,7 +150,7 @@ void NodePanelGrid::init_controls()
// get the texture data and resize it
Image img;
img.create(m_texture.size().x, m_texture.size().y);
App::I.render_task([&]
App::I->render_task([&]
{
m_texture.bind();
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.m_data.get());
@@ -465,7 +465,7 @@ void NodePanelGrid::bake_uvs()
//stbi_write_jpg("bake-out.jpg", fb.getWidth(), fb.getHeight(), 4, data_out.get(), 75);
m_texture.update(data_out.get());
m_texture.create_mipmaps();
App::I.async_redraw();
App::I->async_redraw();
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -119,8 +119,8 @@ void NodePanelQuick::init_controls()
m_slider_size = find<NodeSliderV>("quick-size");
m_slider_size->on_value_changed = [this](Node* target, float value) {
float off = App::I.ui_rtl ? -100.f : 100.f;
auto newpos = (m_slider_flow->m_pos + glm::vec2(off, m_slider_flow->m_size.y / 2.f)) * App::I.zoom;
float off = App::I->ui_rtl ? -100.f : 100.f;
auto newpos = (m_slider_flow->m_pos + glm::vec2(off, m_slider_flow->m_size.y / 2.f)) * App::I->zoom;
if (auto m = dynamic_cast<CanvasModePen*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
{
m->m_cur_pos = newpos;
@@ -138,8 +138,8 @@ void NodePanelQuick::init_controls()
};
m_slider_flow = find<NodeSliderV>("quick-flow");
m_slider_flow->on_value_changed = [this](Node* target, float value) {
float off = App::I.ui_rtl ? -100.f : 100.f;
auto newpos = (m_slider_flow->m_pos + glm::vec2(off, m_slider_flow->m_size.y / 2.f)) * App::I.zoom;
float off = App::I->ui_rtl ? -100.f : 100.f;
auto newpos = (m_slider_flow->m_pos + glm::vec2(off, m_slider_flow->m_size.y / 2.f)) * App::I->zoom;
if (auto m = dynamic_cast<CanvasModePen*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
{
m->m_cur_pos = newpos;
@@ -205,7 +205,7 @@ void NodePanelQuick::handle_button_brush_click(Node* button)
// if the box is already selected show the popup
auto popup = App::I.presets;
auto popup = App::I->presets;
auto screen = root()->m_size;
glm::vec2 tick_sz = { 16, 32 };
glm::vec2 tick_pos = button->m_pos + glm::vec2(button->m_size.x, 0);
@@ -287,7 +287,7 @@ void NodePanelQuick::handle_button_color_click(Node* target)
tick->set_image("data/ui/popup-tick.png");
tick->m_scale = { 1, 1 };
//float hh = popup->m_container->m_children.size() > 10 ? (screen.y / App::I.zoom - 90.f) : 400.f;
//float hh = popup->m_container->m_children.size() > 10 ? (screen.y / App::I->zoom - 90.f) : 400.f;
//popup->SetHeight(glm::max(hh, 400.f));
popup->SetPositioning(YGPositionTypeAbsolute);
popup->SetPosition(popup_pos);

View File

@@ -42,7 +42,7 @@ bool NodePanelStroke::import_abr(const std::string& path)
if (!str_iequals(ext, "abr") || !Asset::exist(path))
return false;
auto pb = App::I.show_progress("Importing ABR");
auto pb = App::I->show_progress("Importing ABR");
abr.open(path);
@@ -55,8 +55,8 @@ bool NodePanelStroke::import_abr(const std::string& path)
auto ii = abr.m_samples.begin();
std::advance(ii, i);
const auto& samp = *ii;
std::string path_high = App::I.data_path + "/brushes/" + samp.first + ".png";
std::string path_thumb = App::I.data_path + "/brushes/thumbs/" + samp.first + ".png";
std::string path_high = App::I->data_path + "/brushes/" + samp.first + ".png";
std::string path_thumb = App::I->data_path + "/brushes/thumbs/" + samp.first + ".png";
auto padded = samp.second->resize_squared(glm::u8vec4(255));
//auto high = padded.resize_power2();
//high.save(path_high);
@@ -87,8 +87,8 @@ bool NodePanelStroke::import_abr(const std::string& path)
auto ii = abr.m_patterns.begin();
std::advance(ii, i);
const auto& patt = *ii;
std::string path_high = App::I.data_path + "/patterns/" + patt.first + ".png";
std::string path_thumb = App::I.data_path + "/patterns/thumbs/" + patt.first + ".png";
std::string path_high = App::I->data_path + "/patterns/" + patt.first + ".png";
std::string path_thumb = App::I->data_path + "/patterns/thumbs/" + patt.first + ".png";
patt.second->save(path_high);
auto thumb = patt.second->resize(64, 64);
thumb.save(path_thumb);
@@ -110,20 +110,20 @@ bool NodePanelStroke::import_abr(const std::string& path)
});
m_pattern_popup->save();
auto brushes = abr.compute_brushes(App::I.data_path);
auto brushes = abr.compute_brushes(App::I->data_path);
for (const auto& pr : brushes)
{
if (pr->valid())
{
LOG("add preset %s", pr->m_name.c_str());
App::I.presets->add_brush(pr);
App::I->presets->add_brush(pr);
}
count++;
float prog = (float)count / (float)tot;
pb->m_progress->SetWidthP(prog * 100.f);
}
App::I.presets->save();
App::I->presets->save();
pb->destroy();
//save();
@@ -281,32 +281,32 @@ void NodePanelStroke::init_controls()
m_preset_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_preset_button->m_pos + glm::vec2(m_preset_button->m_size.x, 0);
root()->add_child(App::I.presets);
root()->add_child(App::I->presets);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (m_preset_button->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
float hh = App::I.presets->m_container->m_children.size() > 10 ? App::I.height / App::I.zoom * .75f : 400.f;
App::I.presets->SetHeight(glm::max(hh, 400.f));
float hh = App::I->presets->m_container->m_children.size() > 10 ? App::I->height / App::I->zoom * .75f : 400.f;
App::I->presets->SetHeight(glm::max(hh, 400.f));
root()->update();
if ((pos.y + App::I.presets->m_size.y) > screen.y)
pos.y = screen.y - App::I.presets->m_size.y;
if ((pos.y + App::I->presets->m_size.y) > screen.y)
pos.y = screen.y - App::I->presets->m_size.y;
if (pos.y < 0)
pos.y = 0;
App::I.presets->SetPosition(pos.x + 16, pos.y);
App::I.presets->SetPositioning(YGPositionTypeAbsolute);
App::I.presets->m_mouse_ignore = false;
App::I.presets->m_flood_events = true;
App::I.presets->m_capture_children = false;
App::I.presets->mouse_capture();
App::I->presets->SetPosition(pos.x + 16, pos.y);
App::I->presets->SetPositioning(YGPositionTypeAbsolute);
App::I->presets->m_mouse_ignore = false;
App::I->presets->m_flood_events = true;
App::I->presets->m_capture_children = false;
App::I->presets->mouse_capture();
root()->update();
App::I.presets->on_popup_close = [this, tick](Node*) {
App::I->presets->on_popup_close = [this, tick](Node*) {
tick->destroy();
};
App::I.presets->on_brush_changed = [this](Node* target, std::shared_ptr<Brush>& b) {
App::I->presets->on_brush_changed = [this](Node* target, std::shared_ptr<Brush>& b) {
// don't change some params
//b->m_tip_size = Canvas::I->m_current_brush->m_tip_size;
auto old_color = Canvas::I->m_current_brush->m_tip_color;
@@ -629,7 +629,7 @@ void NodePanelStroke::init_controls()
b->m_tip_opacity = 1.f;
Canvas::I->m_current_brush = b;
update_controls();
App::I.brush_update();
App::I->brush_update();
};
update_controls();

View File

@@ -231,11 +231,11 @@ std::vector<NodeStrokePreview::StrokeFrame> NodeStrokePreview::stroke_draw_compu
glm::vec2 mixer_bb_max(0, 0);
for (int j = 0; j < 4; j++)
{
auto p = (xy(prev.pos) + App::I.zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle));
auto p = (xy(prev.pos) + App::I->zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle));
mixer_bb_min = glm::max({ 0, 0 }, glm::min(mixer_bb_min, p));
mixer_bb_max = glm::min(mixer_sz, glm::max(mixer_bb_max, p));
B[j].pos = glm::vec4(xy(s.pos) + App::I.zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
B[j].pos = glm::vec4(xy(s.pos) + App::I->zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
B[j].uvs2 = p / mixer_sz;
}
@@ -314,13 +314,13 @@ void NodeStrokePreview::draw_stroke_immediate()
{
float min_pad = size.x * 0.05f;
float pad = (5.f + glm::max(glm::min(m_stroke.m_max_size, m_brush->m_tip_size) / 2.f, min_pad)) * App::I.zoom;
float pad = (5.f + glm::max(glm::min(m_stroke.m_max_size, m_brush->m_tip_size) / 2.f, min_pad)) * App::I->zoom;
if (b->m_tip_size_pressure)
pad = min_pad * App::I.zoom;
pad = min_pad * App::I->zoom;
if (!glm::isnan(m_pad_override))
pad = m_pad_override;
float w = m_size.x * App::I.zoom;
float h = m_size.y * App::I.zoom;
float w = m_size.x * App::I->zoom;
float h = m_size.y * App::I->zoom;
std::vector<glm::vec2> kp = {
{ pad, h / 2.f },
{ w / 2.f, 0 },
@@ -529,7 +529,7 @@ void NodeStrokePreview::draw_stroke()
bool to_unload = (node->m_brush->m_tip_texture == nullptr);
node->m_brush->preload();
App::I.render_task([node, to_unload]
App::I->render_task([node, to_unload]
{
gl_state gl;
gl.save();

View File

@@ -63,7 +63,7 @@ kEventResult NodeTextInput::handle_event(Event* e)
switch (e->m_type)
{
case kEventType::MouseDownL:
App::I.showKeyboard();
App::I->showKeyboard();
break;
case kEventType::MouseUpL:
key_capture();

View File

@@ -18,7 +18,7 @@ void NodeViewport::draw()
glClear(GL_COLOR_BUFFER_BIT);
auto box = m_clip * root()->m_zoom;
glm::ivec4 c = (glm::ivec4)glm::vec4(box.x, (int)(vp[3] - box.y - box.w), box.z, box.w);
glViewport(c.x + App::I.off_x, c.y + App::I.off_y, c.z, c.w);
glViewport(c.x + App::I->off_x, c.y + App::I->off_y, c.z, c.w);
TextureManager::get(m_tex_id).bind();
m_sampler->bind(0);
glEnable(GL_BLEND);

View File

@@ -39,7 +39,7 @@ void RTT::resize(int width, int height)
{
RTT new_rtt;
App::I.render_task([&]
App::I->render_task([&]
{
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
@@ -68,7 +68,7 @@ void RTT::resize(int width, int height)
void RTT::destroy()
{
App::I.render_task_async([rboID=rboID, texID=texID, fboID=fboID]
App::I->render_task_async([rboID=rboID, texID=texID, fboID=fboID]
{
if (rboID)
{
@@ -96,7 +96,7 @@ void RTT::destroy()
void RTT::copy(const RTT & source)
{
App::I.render_task([&]
App::I->render_task([&]
{
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
@@ -113,7 +113,7 @@ void RTT::copy(const RTT & source)
bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format, bool depth_buffer /*= false*/)
{
GLenum status = 0;
App::I.render_task([&]
App::I->render_task([&]
{
// Destroy any previously created object
destroy();
@@ -254,7 +254,7 @@ uint8_t* RTT::readTextureData(uint8_t* buffer)
{
if (!buffer)
buffer = createBuffer();
App::I.render_task([&]
App::I->render_task([&]
{
GLint old;
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old);
@@ -269,7 +269,7 @@ float* RTT::readTextureDataFloat(float* buffer)
{
if (!buffer)
buffer = createBufferFloat();
App::I.render_task([&]
App::I->render_task([&]
{
GLint old;
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old);

View File

@@ -6,7 +6,7 @@ Settings Settings::I;
bool Settings::load()
{
auto path = App::I.data_path + "/settings/pref.bin";
auto path = App::I->data_path + "/settings/pref.bin";
BinaryStreamReader sr;
if (sr.load(path))
{
@@ -18,7 +18,7 @@ bool Settings::load()
bool Settings::save()
{
auto path = App::I.data_path + "/settings/pref.bin";
auto path = App::I->data_path + "/settings/pref.bin";
BinaryStreamWriter sw;
sw.init();
I.write(sw);

View File

@@ -155,7 +155,7 @@ bool Shader::reload()
bool Shader::create(const char* vertex, const char* fragment)
{
bool ret = true;
App::I.render_task([&]
App::I->render_task([&]
{
GLint status;
static char infolog[4096];
@@ -278,7 +278,7 @@ void Shader::destroy()
{
if (prog)
{
App::I.render_task_async([prog=prog]
App::I->render_task_async([prog=prog]
{
glUseProgram(0);
glDeleteProgram(prog);

View File

@@ -22,7 +22,7 @@ bool Shape::create_buffers_imp(GLvoid* idx, GLvoid* vertices, int isize, int vsi
use_idx = true;
bool ret = false;
App::I.render_task([&]
App::I->render_task([&]
{
destroy();
@@ -71,7 +71,7 @@ bool Shape::create_buffers(GLvoid* vertices, int vsize)
use_idx = false;
bool ret = false;
App::I.render_task([&]
App::I->render_task([&]
{
destroy();
@@ -124,7 +124,7 @@ void Shape::draw_fill() const
type = GL_POINTS;
if (count[0] == 2)
type = GL_LINES;
App::I.render_task([=]
App::I->render_task([=]
{
#if USE_VBO
glBindVertexArray(arrays[0]);
@@ -160,7 +160,7 @@ void Shape::draw_stroke() const
GLenum type = GL_LINES;
if (count[1] == 1)
type = GL_POINTS;
App::I.render_task([=]
App::I->render_task([=]
{
#if USE_VBO
glBindVertexArray(arrays[1]);
@@ -193,7 +193,7 @@ void Shape::draw_stroke() const
void Shape::destroy()
{
App::I.render_task_async([b1=buffers[0],b2=buffers[1],a1=arrays[0],a2=arrays[1]]
App::I->render_task_async([b1=buffers[0],b2=buffers[1],a1=arrays[0],a2=arrays[1]]
{
if (b1 || b2)
{
@@ -490,7 +490,7 @@ void Plane::update_vertices(const glm::vec4* data, const glm::vec2* uvs, const g
vertices[i].pos.z = q;
}
App::I.render_task([this]
App::I->render_task([this]
{
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -760,7 +760,7 @@ void Sphere::create_impl(int rings, int sectors, float radius,
}
void LineSegment::update_vertices(const glm::vec4 data[2])
{
App::I.render_task([&]
App::I->render_task([&]
{
static vertex_t vertices[2];
vertices[0] = { data[0], { 0, 0 } }; // A
@@ -772,7 +772,7 @@ void LineSegment::update_vertices(const glm::vec4 data[2])
}
void DynamicShape::update_vertices(vertex_t* vertices, int vcount)
{
App::I.render_task([&]
App::I->render_task([&]
{
count[0] = vcount;
count[1] = vcount;

View File

@@ -41,7 +41,7 @@ void TextureManager::invalidate()
bool Texture2D::create(int width, int height, GLint internal_format, GLint format, const uint8_t* data)
{
App::I.render_task([=]
App::I->render_task([=]
{
destroy();
m_width = width;
@@ -68,7 +68,7 @@ bool Texture2D::create(const Image& img)
void Texture2D::create_mipmaps()
{
App::I.render_task([this]
App::I->render_task([this]
{
bind();
glGenerateMipmap(GL_TEXTURE_2D);
@@ -108,7 +108,7 @@ void Texture2D::destroy()
{
if (m_tex)
{
App::I.render_task_async([id = m_tex]
App::I->render_task_async([id = m_tex]
{
glDeleteTextures(1, &id);
});
@@ -128,7 +128,7 @@ void Texture2D::unbind() const
void Texture2D::update(const uint8_t* data)
{
App::I.render_task([this, data]
App::I->render_task([this, data]
{
bind();
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, m_format, GL_UNSIGNED_BYTE, data);
@@ -152,7 +152,7 @@ Texture2D::~Texture2D()
bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
{
bool ret = false;
App::I.render_task([this, &ret, filter, wrap]
App::I->render_task([this, &ret, filter, wrap]
{
#if USE_SAMPLER
glGenSamplers(1, &id);
@@ -169,7 +169,7 @@ bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_ED
}
void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/)
{
App::I.render_task([=]
App::I->render_task([=]
{
#if USE_SAMPLER
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, wrap);
@@ -182,7 +182,7 @@ void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*
}
void Sampler::set_filter(GLint filter_min, GLint filter_mag)
{
App::I.render_task([=]
App::I->render_task([=]
{
#if USE_SAMPLER
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, filter_min);
@@ -192,7 +192,7 @@ void Sampler::set_filter(GLint filter_min, GLint filter_mag)
}
void Sampler::set_border(glm::vec4 rgba)
{
App::I.render_task([this, rgba]
App::I->render_task([this, rgba]
{
#if USE_SAMPLER && !defined(__IOS__) && !defined(__ANDROID__)
glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(rgba));
@@ -201,7 +201,7 @@ void Sampler::set_border(glm::vec4 rgba)
}
void Sampler::bind(int unit) const
{
App::I.render_task([=]
App::I->render_task([=]
{
current_unit = unit;
#if USE_SAMPLER
@@ -211,7 +211,7 @@ void Sampler::bind(int unit) const
}
void Sampler::unbind()
{
App::I.render_task([=]
App::I->render_task([=]
{
#if USE_SAMPLER
glBindSampler(current_unit, 0);