diff --git a/engine/app.cpp b/engine/app.cpp index 7f9ab2b..32ac0b4 100644 --- a/engine/app.cpp +++ b/engine/app.cpp @@ -367,6 +367,10 @@ void App::initLayout() layers->on_layer_change = [this](Node*, int old_idx, int new_idx) { canvas->m_canvas->m_current_layer_idx = new_idx; }; + + layers->on_layer_order = [this](Node*, int old_idx, int new_idx) { + canvas->m_canvas->layer_order(old_idx, new_idx); + }; layers->on_layer_opacity_changed = [this](Node*, int idx, float value) { canvas->m_canvas->m_layers[idx].m_opacity = value; diff --git a/engine/canvas.cpp b/engine/canvas.cpp index 40f2081..1e58fe9 100644 --- a/engine/canvas.cpp +++ b/engine/canvas.cpp @@ -211,8 +211,14 @@ void ui::Canvas::stroke_start(glm::vec2 point, float pressure, const ui::Brush& } void ui::Canvas::layer_add(std::string name) { + int idx = (int)m_layers.size(); m_layers.emplace_back(); m_layers.back().create(m_width, m_height, name); + m_order.push_back(idx); +} +void ui::Canvas::layer_order(int idx, int pos) +{ + std::swap(m_order[idx], m_order[pos]); } void ui::Canvas::resize(int width, int height) { diff --git a/engine/canvas.h b/engine/canvas.h index 225a9a3..ac4c6f5 100644 --- a/engine/canvas.h +++ b/engine/canvas.h @@ -23,8 +23,8 @@ public: bool m_show_tmp = false; std::vector m_layers; std::vector m_strokes; + std::vector m_order; RTT m_tmp; - //RTT m_fb; Texture2D m_tex; Texture2D m_tex2; Sampler m_sampler; @@ -33,6 +33,7 @@ public: bool create(int width, int height); void resize(int width, int height); void layer_add(std::string name); + void layer_order(int idx, int pos); void stroke_start(glm::vec2 point, float pressure, const ui::Brush& brush); void stroke_update(glm::vec2 point, float pressure); void stroke_draw(); diff --git a/engine/layout.h b/engine/layout.h index d87d165..7d9c677 100644 --- a/engine/layout.h +++ b/engine/layout.h @@ -1383,6 +1383,7 @@ public: std::function on_layer_opacity_changed; std::function on_layer_delete; std::function on_layer_add; + std::function on_layer_order; NodeLayer* m_current_layer = nullptr; std::vector m_layers; NodeBorder* m_layers_container; @@ -1415,11 +1416,23 @@ public: return; // dont' delete the last layer remove_layer(m_current_layer); }; - btn_up->on_click = [this](Node*) { + btn_up->on_click = [this](Node*) { + int old_idx = m_layers_container->get_child_index(m_current_layer); m_layers_container->move_child_offset(m_current_layer, -1); + int new_idx = m_layers_container->get_child_index(m_current_layer); + if (on_layer_order && old_idx != new_idx) + { + on_layer_order(this, old_idx, new_idx); + } }; btn_down->on_click = [this](Node*) { - m_layers_container->move_child_offset(m_current_layer, +1); + int old_idx = m_layers_container->get_child_index(m_current_layer); + m_layers_container->move_child_offset(m_current_layer, +1); + int new_idx = m_layers_container->get_child_index(m_current_layer); + if (on_layer_order && old_idx != new_idx) + { + on_layer_order(this, old_idx, new_idx); + } }; LOG("done init"); } @@ -1945,7 +1958,7 @@ public: auto blend = glIsEnabled(GL_BLEND); glEnable(GL_BLEND); - for (int i = 0; i < m_canvas->m_layers.size(); i++) + for (auto i : m_canvas->m_order) { if (!(m_canvas->m_erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == i)) { diff --git a/engine/log.cpp b/engine/log.cpp index cd1cb23..3cb7644 100644 --- a/engine/log.cpp +++ b/engine/log.cpp @@ -36,6 +36,7 @@ void LogRemote::net_init() curl_easy_setopt(curl, CURLOPT_WRITEDATA, &this->readBuffer); //curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, data_handler); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L); } std::string LogRemote::net_request(std::string cmd, std::string data /*= ""*/) { @@ -45,6 +46,8 @@ std::string LogRemote::net_request(std::string cmd, std::string data /*= ""*/) auto url = m_url + cmd; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); res = curl_easy_perform(curl); + if (res != CURLcode::CURLE_OK) + m_running = false; return readBuffer; } void LogRemote::net_close() diff --git a/engine/main.cpp b/engine/main.cpp index bef828b..895ebbd 100644 --- a/engine/main.cpp +++ b/engine/main.cpp @@ -61,8 +61,10 @@ CVDisplayLinkStart(dl); CGLEnable([self.openGLContext CGLContextObj], kCGLCECrashOnRemovedFunctions); - + + CGLLockContext([[self openGLContext] CGLContextObj]); App::I.init(); + CGLUnlockContext([[self openGLContext] CGLContextObj]); } // This is the renderer output callback function @@ -91,6 +93,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime // thread. Add a mutex around to avoid the threads accessing the context // simultaneously when resizing CGLLockContext([[self openGLContext] CGLContextObj]); + App::I.clear(); App::I.update(now - _prevTime); //[[self openGLContext] flushBuffer]; @@ -200,6 +203,13 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime App::I.mouse_down(0, mouseLoc.x, App::I.height - mouseLoc.y - 1); CGLUnlockContext([[self openGLContext] CGLContextObj]); } +- (void)rightMouseDown:(NSEvent *)theEvent +{ + CGLLockContext([[self openGLContext] CGLContextObj]); + auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + App::I.mouse_down(1, mouseLoc.x, App::I.height - mouseLoc.y - 1); + CGLUnlockContext([[self openGLContext] CGLContextObj]); +} - (void)mouseUp:(NSEvent *)theEvent { CGLLockContext([[self openGLContext] CGLContextObj]); @@ -207,6 +217,13 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime App::I.mouse_up(0, mouseLoc.x, App::I.height - mouseLoc.y - 1); CGLUnlockContext([[self openGLContext] CGLContextObj]); } +- (void)rightMouseUp:(NSEvent *)theEvent +{ + CGLLockContext([[self openGLContext] CGLContextObj]); + auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + App::I.mouse_up(1, mouseLoc.x, App::I.height - mouseLoc.y - 1); + CGLUnlockContext([[self openGLContext] CGLContextObj]); +} - (void)mouseMoved:(NSEvent *)theEvent { CGLLockContext([[self openGLContext] CGLContextObj]); @@ -221,6 +238,20 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1); CGLUnlockContext([[self openGLContext] CGLContextObj]); } +- (void)rightMouseDragged:(NSEvent *)theEvent +{ + CGLLockContext([[self openGLContext] CGLContextObj]); + auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1); + CGLUnlockContext([[self openGLContext] CGLContextObj]); +} +- (void)scrollWheel:(NSEvent *)theEvent +{ + CGLLockContext([[self openGLContext] CGLContextObj]); + auto mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + App::I.mouse_scroll(mouseLoc.x, App::I.height - mouseLoc.y - 1, [theEvent deltaY]); + CGLUnlockContext([[self openGLContext] CGLContextObj]); +} @end @interface Window : NSWindow diff --git a/engine/rtt.cpp b/engine/rtt.cpp index 212e2d4..6d5273a 100644 --- a/engine/rtt.cpp +++ b/engine/rtt.cpp @@ -111,7 +111,9 @@ void RTT::bindFramebuffer() if (bound) { LOG("framebuffer bound twice!"); +#ifdef _WIN32 __debugbreak(); +#endif } #endif // _DEBUG bound = true;