curl timeout, reorder layers, handle right click osx

This commit is contained in:
2017-04-15 18:55:27 +02:00
parent d230bc7a99
commit 163a435e6e
7 changed files with 65 additions and 5 deletions

View File

@@ -368,6 +368,10 @@ void App::initLayout()
canvas->m_canvas->m_current_layer_idx = 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) { layers->on_layer_opacity_changed = [this](Node*, int idx, float value) {
canvas->m_canvas->m_layers[idx].m_opacity = value; canvas->m_canvas->m_layers[idx].m_opacity = value;
}; };

View File

@@ -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) void ui::Canvas::layer_add(std::string name)
{ {
int idx = (int)m_layers.size();
m_layers.emplace_back(); m_layers.emplace_back();
m_layers.back().create(m_width, m_height, name); 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) void ui::Canvas::resize(int width, int height)
{ {

View File

@@ -23,8 +23,8 @@ public:
bool m_show_tmp = false; bool m_show_tmp = false;
std::vector<Layer> m_layers; std::vector<Layer> m_layers;
std::vector<Stroke> m_strokes; std::vector<Stroke> m_strokes;
std::vector<int> m_order;
RTT m_tmp; RTT m_tmp;
//RTT m_fb;
Texture2D m_tex; Texture2D m_tex;
Texture2D m_tex2; Texture2D m_tex2;
Sampler m_sampler; Sampler m_sampler;
@@ -33,6 +33,7 @@ public:
bool create(int width, int height); bool create(int width, int height);
void resize(int width, int height); void resize(int width, int height);
void layer_add(std::string name); 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_start(glm::vec2 point, float pressure, const ui::Brush& brush);
void stroke_update(glm::vec2 point, float pressure); void stroke_update(glm::vec2 point, float pressure);
void stroke_draw(); void stroke_draw();

View File

@@ -1383,6 +1383,7 @@ public:
std::function<void(Node* target, int idx, float value)> on_layer_opacity_changed; std::function<void(Node* target, int idx, float value)> on_layer_opacity_changed;
std::function<void(Node* target, int index)> on_layer_delete; std::function<void(Node* target, int index)> on_layer_delete;
std::function<void(Node* target)> on_layer_add; std::function<void(Node* target)> on_layer_add;
std::function<void(Node* target, int old_idx, int new_idx)> on_layer_order;
NodeLayer* m_current_layer = nullptr; NodeLayer* m_current_layer = nullptr;
std::vector<NodeLayer*> m_layers; std::vector<NodeLayer*> m_layers;
NodeBorder* m_layers_container; NodeBorder* m_layers_container;
@@ -1416,10 +1417,22 @@ public:
remove_layer(m_current_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); 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*) { btn_down->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); 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"); LOG("done init");
} }
@@ -1945,7 +1958,7 @@ public:
auto blend = glIsEnabled(GL_BLEND); auto blend = glIsEnabled(GL_BLEND);
glEnable(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)) if (!(m_canvas->m_erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == i))
{ {

View File

@@ -36,6 +36,7 @@ void LogRemote::net_init()
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &this->readBuffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &this->readBuffer);
//curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); //curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, data_handler); 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 /*= ""*/) 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; auto url = m_url + cmd;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (res != CURLcode::CURLE_OK)
m_running = false;
return readBuffer; return readBuffer;
} }
void LogRemote::net_close() void LogRemote::net_close()

View File

@@ -62,7 +62,9 @@
CGLEnable([self.openGLContext CGLContextObj], kCGLCECrashOnRemovedFunctions); CGLEnable([self.openGLContext CGLContextObj], kCGLCECrashOnRemovedFunctions);
CGLLockContext([[self openGLContext] CGLContextObj]);
App::I.init(); App::I.init();
CGLUnlockContext([[self openGLContext] CGLContextObj]);
} }
// This is the renderer output callback function // 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 // thread. Add a mutex around to avoid the threads accessing the context
// simultaneously when resizing // simultaneously when resizing
CGLLockContext([[self openGLContext] CGLContextObj]); CGLLockContext([[self openGLContext] CGLContextObj]);
App::I.clear();
App::I.update(now - _prevTime); App::I.update(now - _prevTime);
//[[self openGLContext] flushBuffer]; //[[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); App::I.mouse_down(0, mouseLoc.x, App::I.height - mouseLoc.y - 1);
CGLUnlockContext([[self openGLContext] CGLContextObj]); 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 - (void)mouseUp:(NSEvent *)theEvent
{ {
CGLLockContext([[self openGLContext] CGLContextObj]); 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); App::I.mouse_up(0, mouseLoc.x, App::I.height - mouseLoc.y - 1);
CGLUnlockContext([[self openGLContext] CGLContextObj]); 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 - (void)mouseMoved:(NSEvent *)theEvent
{ {
CGLLockContext([[self openGLContext] CGLContextObj]); 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); App::I.mouse_move(mouseLoc.x, App::I.height - mouseLoc.y - 1);
CGLUnlockContext([[self openGLContext] CGLContextObj]); 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 @end
@interface Window : NSWindow @interface Window : NSWindow

View File

@@ -111,7 +111,9 @@ void RTT::bindFramebuffer()
if (bound) if (bound)
{ {
LOG("framebuffer bound twice!"); LOG("framebuffer bound twice!");
#ifdef _WIN32
__debugbreak(); __debugbreak();
#endif
} }
#endif // _DEBUG #endif // _DEBUG
bound = true; bound = true;