add scrollbar, improve presets, other small fixes
This commit is contained in:
@@ -136,6 +136,8 @@ void App::cloud_browse()
|
||||
|
||||
dialog->btn_ok->on_click = [this, dialog](Node*)
|
||||
{
|
||||
if (dialog->selected_file.empty())
|
||||
return;
|
||||
dialog->destroy();
|
||||
std::thread([this, dialog] {
|
||||
async_start();
|
||||
|
||||
@@ -170,8 +170,8 @@ void App::initShaders()
|
||||
" if (textureOffset(tex, uv, ivec2(+1, -1)).r == 1.0) zero_count++;\n"
|
||||
" if (textureOffset(tex, uv, ivec2(+1, 0)).r == 1.0) zero_count++;\n"
|
||||
" if (textureOffset(tex, uv, ivec2(+1, +1)).r == 1.0) zero_count++;\n"
|
||||
" float edge = (zero_count > 1 && zero_count < 9) ? 0.75 : 0.0;\n"
|
||||
" frag = vec4(col.rgb, edge * (1.0 - zero_count / 9.f));\n"
|
||||
" mediump float edge = (zero_count > 1 && zero_count < 9) ? 0.75 : 0.0;\n"
|
||||
" frag = vec4(col.rgb, edge * (1.0 - float(zero_count) / 9.f));\n"
|
||||
"}\n";
|
||||
// TEXTURE COMP ERASE
|
||||
static const char* shader_comp_erase_f =
|
||||
|
||||
@@ -1741,6 +1741,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())
|
||||
{
|
||||
std::thread t([=] {
|
||||
@@ -1750,6 +1751,10 @@ void Canvas::project_save(std::string file_path, std::function<void(bool)> on_co
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("no license, no save");
|
||||
}
|
||||
}
|
||||
|
||||
bool Canvas::project_save_thread(std::string file_path)
|
||||
@@ -1758,7 +1763,10 @@ bool Canvas::project_save_thread(std::string file_path)
|
||||
|
||||
// already saved, nothing to do
|
||||
if (!m_unsaved && file_path == App::I.doc_path)
|
||||
{
|
||||
LOG("already saved");
|
||||
return true;
|
||||
}
|
||||
|
||||
// static char name[128];
|
||||
// sprintf(name, "%s/latlong.ppi", data_path.c_str());
|
||||
@@ -1768,11 +1776,15 @@ bool Canvas::project_save_thread(std::string file_path)
|
||||
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";
|
||||
|
||||
LOG("file name %s", file_name.c_str());
|
||||
LOG("tmp path %s", tmp_path.c_str());
|
||||
|
||||
bool use_tmp = false;
|
||||
// check if file already exists
|
||||
if ((fp = fopen(file_path.c_str(), "rb")))
|
||||
{
|
||||
fclose(fp);
|
||||
LOG("use tmp file");
|
||||
// use tmp file for writing
|
||||
use_tmp = true;
|
||||
if (!(fp = fopen(tmp_path.c_str(), "wb")))
|
||||
@@ -1781,6 +1793,8 @@ bool Canvas::project_save_thread(std::string file_path)
|
||||
use_tmp = false;
|
||||
}
|
||||
}
|
||||
|
||||
LOG("save first time");
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#ifdef __APPLE__
|
||||
#define LOG(M,...) { printf(M"\n", ##__VA_ARGS__); LogRemote::I.log(M, ##__VA_ARGS__); }
|
||||
#elif __ANDROID__
|
||||
#define LOG(...) { ((void)__android_log_print(ANDROID_LOG_INFO, "native-engine", __VA_ARGS__)); LogRemote::I.log(__VA_ARGS__); }
|
||||
#define LOG(...) { ((void)__android_log_print(ANDROID_LOG_INFO, "PanoPainterCPP", __VA_ARGS__)); LogRemote::I.log(__VA_ARGS__); }
|
||||
#elif _WIN32
|
||||
#define LOG(M,...) { printf(M"\n", ##__VA_ARGS__); LogRemote::I.log(M, ##__VA_ARGS__); }
|
||||
#define LOGW(M,...) { wprintf(M"\n", ##__VA_ARGS__); LogRemote::I.log(M, ##__VA_ARGS__); }
|
||||
|
||||
@@ -694,8 +694,8 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
float pl = YGNodeLayoutGetPadding(parent->y_node, YGEdgeLeft);
|
||||
glm::vec2 off_p(pl, pt);
|
||||
glm::vec2 off_s(pr, pb);
|
||||
glm::vec4 pclip = { xy(parent->m_clip) + off_p, zw(parent->m_clip) - off_s - off_p};
|
||||
m_clip_uncut = glm::vec4(m_pos, m_size);
|
||||
glm::vec4 pclip = { xy(parent->m_clip) + off_p, zw(parent->m_clip) - (off_s + off_p)};
|
||||
m_clip_uncut = glm::vec4(m_pos - glm::vec2(1), m_size + glm::vec2(2));
|
||||
m_clip = rect_intersection(m_clip_uncut, parent->m_clip);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -240,6 +240,7 @@ public:
|
||||
void move_child_offset(Node* n, int offset);
|
||||
int get_child_index(Node* n);
|
||||
Node* get_child_at(int index);
|
||||
// returns {origin, size} form
|
||||
glm::vec4 get_children_rect() const;
|
||||
bool is_child_recursive(Node* o) const;
|
||||
void mouse_capture();
|
||||
|
||||
@@ -193,13 +193,33 @@ void NodePanelBrushPreset::init()
|
||||
brush->thumb_path = Canvas::I->m_current_brush->m_brush_thumb_path;
|
||||
brush->high_path = Canvas::I->m_current_brush->m_brush_path;
|
||||
brush->m_brush = std::make_shared<Brush>(*Canvas::I->m_current_brush);
|
||||
brush->m_brush->m_tip_size = .05f;
|
||||
//brush->m_brush->m_tip_size = .05f;
|
||||
brush->m_preview->m_brush = brush->m_brush;
|
||||
brush->m_preview->draw_stroke();
|
||||
brush->m_thumb->set_image(brush->m_brush->m_brush_thumb_path);
|
||||
brush->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
|
||||
save();
|
||||
};
|
||||
m_btn_up = find<NodeButtonCustom>("btn-up");
|
||||
m_btn_up->on_click = [this](Node*) {
|
||||
if (m_current)
|
||||
m_container->move_child(m_current, std::max(m_container->get_child_index(m_current) - 1, 0));
|
||||
};
|
||||
m_btn_down = find<NodeButtonCustom>("btn-down");
|
||||
m_btn_down->on_click = [this](Node*) {
|
||||
if (m_current)
|
||||
m_container->move_child(m_current,
|
||||
std::min(m_container->get_child_index(m_current) + 1, (int)m_container->m_children.size() - 1));
|
||||
};
|
||||
m_btn_save = find<NodeButtonCustom>("btn-save");
|
||||
m_btn_save->on_click = [this](Node*) {
|
||||
if (m_current)
|
||||
{
|
||||
*m_current->m_brush = *Canvas::I->m_current_brush;
|
||||
m_current->m_preview->draw_stroke();
|
||||
m_current->m_thumb->set_image(m_current->m_brush->m_brush_thumb_path);
|
||||
}
|
||||
};
|
||||
m_btn_delete = find<NodeButtonCustom>("btn-remove");
|
||||
m_btn_delete->on_click = [this](Node*) {
|
||||
if (!m_current)
|
||||
|
||||
@@ -64,6 +64,7 @@ class NodePanelBrushPreset : public Node
|
||||
NodeButtonCustom* m_btn_up;
|
||||
NodeButtonCustom* m_btn_down;
|
||||
NodeButtonCustom* m_btn_delete;
|
||||
NodeButtonCustom* m_btn_save;
|
||||
struct header_t {
|
||||
char magic[4]{ 'P', 'P', 'P', 'R' };
|
||||
uint16_t version = 0;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "log.h"
|
||||
#include "node_scroll.h"
|
||||
#include "event.h"
|
||||
#include "shader.h"
|
||||
|
||||
NodeScroll::NodeScroll()
|
||||
{
|
||||
@@ -25,6 +26,32 @@ void NodeScroll::fix_scroll()
|
||||
m_pos_offset_childred = m_offset;
|
||||
}
|
||||
|
||||
void NodeScroll::handle_resize(glm::vec2 old_size, glm::vec2 new_size)
|
||||
{
|
||||
Node::handle_resize(old_size, new_size);
|
||||
fix_scroll();
|
||||
}
|
||||
|
||||
void NodeScroll::draw()
|
||||
{
|
||||
NodeBorder::draw();
|
||||
glm::vec4 rect = get_children_rect();
|
||||
if (rect.x == 0 || rect.w < m_size.y)
|
||||
return;
|
||||
float h = m_size.y / rect.w * m_size.y;
|
||||
float offset_percent = m_offset.y / (rect.w - m_size.y);
|
||||
float pr = YGNodeLayoutGetPadding(y_node, YGEdgeRight) - 5;
|
||||
glDisable(GL_BLEND);
|
||||
ShaderManager::use(kShader::Color);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_proj
|
||||
* glm::translate(glm::vec3(m_pos.x + m_size.x - pr, m_pos.y - offset_percent * (m_size.y - h), 0))
|
||||
* glm::scale(glm::vec3(pr, h, 1))
|
||||
* glm::translate(glm::vec3(.5, .5, 0))
|
||||
);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, { .3, .3, .3, 1 });
|
||||
m_plane.draw_fill();
|
||||
}
|
||||
|
||||
kEventResult NodeScroll::handle_event(Event* e)
|
||||
{
|
||||
NodeBorder::handle_event(e);
|
||||
@@ -37,12 +64,14 @@ kEventResult NodeScroll::handle_event(Event* e)
|
||||
m_dragging = true;
|
||||
m_drag_start = me->m_pos;
|
||||
m_offset_start = m_offset;
|
||||
// if click on the scroll area use scrolling direction, otherwise natural
|
||||
m_scroll_dir = me->m_pos.x > (m_size.x - YGNodeLayoutGetPadding(y_node, YGEdgeRight) + 5) ? -1 : 1;
|
||||
mouse_capture();
|
||||
break;
|
||||
case kEventType::MouseMove:
|
||||
if (m_dragging)
|
||||
{
|
||||
m_offset = m_offset_start + (me->m_pos - m_drag_start) * m_mask;
|
||||
m_offset = m_offset_start + (me->m_pos - m_drag_start) * m_mask * m_scroll_dir;
|
||||
fix_scroll();
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
class NodeScroll : public NodeBorder
|
||||
{
|
||||
bool m_dragging = false;
|
||||
float m_scroll_dir = 1.f;
|
||||
glm::vec2 m_drag_start = glm::vec2(0);
|
||||
glm::vec2 m_offset_start = glm::vec2(0);
|
||||
glm::vec2 m_offset = glm::vec2(0);
|
||||
@@ -12,5 +13,7 @@ public:
|
||||
NodeScroll();
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual kEventResult handle_event(Event* e) override;
|
||||
virtual void draw() override;
|
||||
virtual void handle_resize(glm::vec2 old_size, glm::vec2 new_size) override;
|
||||
void fix_scroll();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user