fix stroke preview zoom, implement dest pick on ppbr export

This commit is contained in:
2019-09-23 22:31:28 +02:00
parent cfdf428a9b
commit 4806a3e8f6
8 changed files with 38 additions and 14 deletions

View File

@@ -59,14 +59,15 @@
<button id="header-open" text="Open" grow="1" height="100%"/> <button id="header-open" text="Open" grow="1" height="100%"/>
<button id="header-clear" text="Clear" grow="1" height="100%"/> <button id="header-clear" text="Clear" grow="1" height="100%"/>
</node> </node>
<border os="win,mac,android" color=".4" grow="1" pad="5" margin="10 0 0 0" justify="center"> <border os="win,osx,android" color=".4" grow="1" pad="5" margin="10 0 0 0" justify="center">
<node dir="row" align="center"> <node dir="row" align="center">
<checkbox id="export-data" width="30" aspect-ratio="1" margin="0 5 0 0"/> <checkbox id="export-data" width="30" aspect-ratio="1" margin="0 5 0 0"/>
<text text="Export data"/> <text text="Export data"/>
<node grow="1"/> <node grow="1"/>
<button os="mac" id="pick-dest" text="Pick dest." pad="5"/> <button os="osx" id="pick-dest" text="Pick dest." pad="5"/>
</node> </node>
<text color=".7" text-wrap-width="256" text="Save the generated preview images to a separete folder."/> <text color=".7" text-wrap-width="256" text="Save the generated preview images to a separete folder."/>
<text id="dest-path" margin="5 0 0 0" text-wrap-width="256"/>
</border> </border>
</node> </node>
<node grow="1" dir="col"> <node grow="1" dir="col">

View File

@@ -606,6 +606,7 @@ void App::dialog_ppbr_export()
info.email = dialog->txt_email->m_text; info.email = dialog->txt_email->m_text;
info.descr = dialog->txt_descr->m_text; info.descr = dialog->txt_descr->m_text;
info.header_image = dialog->m_header_image; info.header_image = dialog->m_header_image;
info.dest_path = dialog->m_dest_path;
if (dialog->export_check) if (dialog->export_check)
info.export_data = dialog->export_check->checked; info.export_data = dialog->export_check->checked;
#if __IOS__ #if __IOS__

View File

@@ -28,6 +28,8 @@ void NodeDialogExportPPBR::init()
void NodeDialogExportPPBR::init_controls() void NodeDialogExportPPBR::init_controls()
{ {
m_title = find<NodeText>("title"); m_title = find<NodeText>("title");
m_dest_path_txt = find<NodeText>("dest-path");
m_dest_path_txt->SetVisibility(false);
btn_ok = find<NodeButton>("btn-ok"); btn_ok = find<NodeButton>("btn-ok");
btn_cancel = find<NodeButton>("btn-cancel"); btn_cancel = find<NodeButton>("btn-cancel");
btn_cancel->on_click = [this](Node*) { btn_cancel->on_click = [this](Node*) {
@@ -47,6 +49,15 @@ void NodeDialogExportPPBR::init_controls()
btn_header_gen->on_click = [this] (Node*) { btn_header_gen->on_click = [this] (Node*) {
App::I->message_box("WIP", "This feature is not yet implemented."); App::I->message_box("WIP", "This feature is not yet implemented.");
}; };
btn_pick_dest = find<NodeButton>("pick-dest");
btn_pick_dest->on_click = [this] (Node*) {
App::I->pick_dir([this](std::string path){
m_dest_path = path;
m_dest_path_txt->set_text(("Dest: " + path).c_str());
m_dest_path_txt->SetVisibility(true);
export_check->set_value(true);
});
};
img_header = find<NodeImageTexture>("header-tex"); img_header = find<NodeImageTexture>("header-tex");
txt_header_descr = find<NodeText>("header-descr"); txt_header_descr = find<NodeText>("header-descr");
txt_author = find<NodeTextInput>("info-author"); txt_author = find<NodeTextInput>("info-author");

View File

@@ -15,7 +15,9 @@ public:
NodeButton* btn_header_open; NodeButton* btn_header_open;
NodeButton* btn_header_clear; NodeButton* btn_header_clear;
NodeButton* btn_header_gen; NodeButton* btn_header_gen;
NodeButton* btn_pick_dest;
NodeText* m_title; NodeText* m_title;
NodeText* m_dest_path_txt;
NodeImageTexture* img_header; NodeImageTexture* img_header;
std::shared_ptr<Image> m_header_image; std::shared_ptr<Image> m_header_image;
NodeText* txt_header_descr; NodeText* txt_header_descr;
@@ -24,6 +26,7 @@ public:
NodeTextInput* txt_url; NodeTextInput* txt_url;
NodeTextInput* txt_email; NodeTextInput* txt_email;
NodeCheckBox* export_check; NodeCheckBox* export_check;
std::string m_dest_path;
virtual Node* clone_instantiate() const override; virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override; virtual void clone_finalize(Node* dest) const override;
virtual void init() override; virtual void init() override;

View File

@@ -698,9 +698,14 @@ bool NodePanelBrushPreset::export_ppbr(const std::string& path_in, const PPBRInf
auto base = m[1].str(); auto base = m[1].str();
auto name = m[2].str(); auto name = m[2].str();
auto ext = m[3].str(); auto ext = m[3].str();
std::string out_path = base + "/" + name + "_data";
bool path_created = info_data.export_data ? Asset::create_dir(out_path) : false; #if __OSX__
std::string out_path = info_data.dest_path + "/" + name + "_data";
#else
std::string out_path = base + "/" + name + "_data";
#endif
bool path_created = info_data.export_data && !out_path.empty() ? Asset::create_dir(out_path) : false;
std::ofstream f(path, std::ios::binary); std::ofstream f(path, std::ios::binary);
if (f.good()) if (f.good())

View File

@@ -96,6 +96,7 @@ public:
std::string descr; std::string descr;
std::shared_ptr<Image> header_image; std::shared_ptr<Image> header_image;
bool export_data; bool export_data;
std::string dest_path;
}; };
Node* m_container; Node* m_container;

View File

@@ -192,7 +192,7 @@ glm::vec4 NodeStrokePreview::stroke_draw_samples(std::array<vertex_t, 4>& P, Tex
return glm::vec4(tex_pos, tex_pos + tex_sz); return glm::vec4(tex_pos, tex_pos + tex_sz);
} }
std::vector<NodeStrokePreview::StrokeFrame> NodeStrokePreview::stroke_draw_compute(Stroke& stroke) const std::vector<NodeStrokePreview::StrokeFrame> NodeStrokePreview::stroke_draw_compute(Stroke& stroke, float zoom) const
{ {
std::vector<StrokeFrame> ret; std::vector<StrokeFrame> ret;
StrokeSample prev = stroke.m_prev_sample; StrokeSample prev = stroke.m_prev_sample;
@@ -232,11 +232,11 @@ std::vector<NodeStrokePreview::StrokeFrame> NodeStrokePreview::stroke_draw_compu
glm::vec2 mixer_bb_max(0, 0); glm::vec2 mixer_bb_max(0, 0);
for (int j = 0; j < 4; j++) 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) + 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_min = glm::max({ 0, 0 }, glm::min(mixer_bb_min, p));
mixer_bb_max = glm::min(mixer_sz, glm::max(mixer_bb_max, 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) + zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
B[j].uvs2 = p / mixer_sz; B[j].uvs2 = p / mixer_sz;
} }
@@ -260,6 +260,8 @@ void NodeStrokePreview::draw_stroke_immediate()
GLfloat cc[4]; GLfloat cc[4];
glGetIntegerv(GL_VIEWPORT, vp); glGetIntegerv(GL_VIEWPORT, vp);
glGetFloatv(GL_COLOR_CLEAR_VALUE, cc); glGetFloatv(GL_COLOR_CLEAR_VALUE, cc);
float zoom = root()->m_zoom;
glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() }; glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() };
glm::mat4 ortho_proj = glm::ortho<float>(0, size.x, 0, size.y, -1, 1); glm::mat4 ortho_proj = glm::ortho<float>(0, size.x, 0, size.y, -1, 1);
@@ -315,13 +317,13 @@ void NodeStrokePreview::draw_stroke_immediate()
{ {
float min_pad = size.x * 0.05f; 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)) * zoom;
if (b->m_tip_size_pressure) if (b->m_tip_size_pressure)
pad = min_pad * App::I->zoom; pad = min_pad * zoom;
if (!glm::isnan(m_pad_override)) if (!glm::isnan(m_pad_override))
pad = m_pad_override; pad = m_pad_override;
float w = m_size.x * App::I->zoom; float w = m_size.x * zoom;
float h = m_size.y * App::I->zoom; float h = m_size.y * zoom;
std::vector<glm::vec2> kp = { std::vector<glm::vec2> kp = {
{ pad, h / 2.f }, { pad, h / 2.f },
{ w / 2.f, 0 }, { w / 2.f, 0 },
@@ -374,7 +376,7 @@ void NodeStrokePreview::draw_stroke_immediate()
dual_brush->m_tip_texture ? dual_brush->m_tip_texture ?
dual_brush->m_tip_texture->bind() : dual_brush->m_tip_texture->bind() :
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
auto frames_dual = stroke_draw_compute(m_dual_stroke); auto frames_dual = stroke_draw_compute(m_dual_stroke, zoom);
for (auto& f : frames_dual) for (auto& f : frames_dual)
{ {
ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 }); ShaderManager::u_vec4(kShaderUniform::Col, { 0, 0, 0, 1 });
@@ -407,7 +409,7 @@ void NodeStrokePreview::draw_stroke_immediate()
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE3);
m_rtt_mixer.bindTexture(); m_rtt_mixer.bindTexture();
auto frames = stroke_draw_compute(m_stroke); auto frames = stroke_draw_compute(m_stroke, zoom);
m_rtt.clear(); m_rtt.clear();
for (auto& f : frames) for (auto& f : frames)
{ {

View File

@@ -50,7 +50,7 @@ public:
void stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz); void stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz);
// return rect {origin, size} // return rect {origin, size}
glm::vec4 stroke_draw_samples(std::array<vertex_t, 4>& P, Texture2D& blend_tex); glm::vec4 stroke_draw_samples(std::array<vertex_t, 4>& P, Texture2D& blend_tex);
std::vector<StrokeFrame> stroke_draw_compute(Stroke& stroke) const; std::vector<StrokeFrame> stroke_draw_compute(Stroke& stroke, float zoom) const;
void draw_stroke(); void draw_stroke();
void draw_stroke_immediate(); void draw_stroke_immediate();
Image render_to_image(); Image render_to_image();