add pressure control flag on size and flow, change data directory in OSX to Documents

This commit is contained in:
2017-09-24 18:55:15 +01:00
parent 78484c53a4
commit 04841a996b
14 changed files with 80 additions and 46 deletions

View File

@@ -43,6 +43,12 @@ void App::initAssets()
void App::initLog()
{
#if defined(__IOS__) || defined(__OSX__)
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docpath = [paths objectAtIndex:0];
data_path = [docpath cStringUsingEncoding:NSASCIIStringEncoding];
#endif
LogRemote::I.start();
LogRemote::I.file_init();
}
@@ -91,12 +97,6 @@ void App::init()
//zoom = ceilf(width / 2000.f);
//zoom = 2;
#ifdef __IOS__
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docpath = [paths objectAtIndex:0];
data_path = [docpath cStringUsingEncoding:NSASCIIStringEncoding];
#endif
glDisable(GL_DEPTH_TEST);
#if defined(_WIN32) || defined(__OSX__)
glEnable(GL_PROGRAM_POINT_SIZE);

View File

@@ -254,7 +254,7 @@ void App::init_toolbar_draw()
layout[main_id]->find<NodeButton>("btn-line")->set_color(color_button_normal);
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_normal);
layout[main_id]->find<NodeButton>("btn-grid")->set_color(color_button_normal);
layout[main_id]->find<NodeButton>("btn-fill")->set_color(color_button_normal);
//layout[main_id]->find<NodeButton>("btn-fill")->set_color(color_button_normal);
Canvas::set_mode(Canvas::kCanvasMode::Erase);
};
}
@@ -266,7 +266,7 @@ void App::init_toolbar_draw()
layout[main_id]->find<NodeButton>("btn-line")->set_color(color_button_hlight);
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_normal);
layout[main_id]->find<NodeButton>("btn-grid")->set_color(color_button_normal);
layout[main_id]->find<NodeButton>("btn-fill")->set_color(color_button_normal);
//layout[main_id]->find<NodeButton>("btn-fill")->set_color(color_button_normal);
Canvas::set_mode(Canvas::kCanvasMode::Line);
};
}
@@ -278,7 +278,7 @@ void App::init_toolbar_draw()
layout[main_id]->find<NodeButton>("btn-line")->set_color(color_button_normal);
layout[main_id]->find<NodeButton>("btn-cam")->set_color(color_button_hlight);
layout[main_id]->find<NodeButton>("btn-grid")->set_color(color_button_normal);
layout[main_id]->find<NodeButton>("btn-fill")->set_color(color_button_normal);
//layout[main_id]->find<NodeButton>("btn-fill")->set_color(color_button_normal);
Canvas::set_mode(Canvas::kCanvasMode::Camera);
};
}
@@ -395,6 +395,14 @@ void App::init_menu_layer()
popup->destroy();
};
popup->find<NodeButtonCustom>("layer-clear")->on_click = [this](Node*) {
canvas->m_canvas->clear();
};
if (layers->m_current_layer)
popup->find<NodeButtonCustom>("layer-clear")->
find<NodeText>("menu-label")->
set_text(("Clear Layer " + layers->m_current_layer->m_label_text).c_str());
popup->find<NodeButtonCustom>("layer-rename")->on_click = [this](Node*) {
dialog_layer_rename();
};

View File

@@ -161,12 +161,15 @@ ui::StrokeSample ui::Stroke::randomize_sample(const glm::vec2& pos, float pressu
auto rnd_rad = [&] { return float((double)prng() / (double)prng.max() * M_PI * 2.0); }; // normalized [0, 2pi]
auto rnd_vec = [&] { float rad = rnd_rad(); return glm::vec2(cosf(rad), sinf(rad)); }; // normalized direction vector
float size_dyn = m_brush.m_tip_size_pressure ? pressure : 1.f;
float flow_dyn = m_brush.m_tip_flow_pressure ? pressure : 1.f;
StrokeSample s;
s.origin = pos;
s.angle = -curve_angle + (m_brush.m_tip_angle + rnd_nor() * m_brush.m_jitter_angle) * (float)(M_PI * 2.0);
s.pos = pos + (rnd_vec() * m_brush.m_jitter_spread * 100.f);
s.size = 800.f * glm::pow(m_brush.m_tip_size, 3.f) * (1.f - rnd_nor() * m_brush.m_jitter_scale);
s.flow = glm::pow(m_brush.m_tip_flow, 2.f) * (1.f - rnd_nor() * m_brush.m_jitter_flow) * pressure;
s.size = 800.f * glm::pow(m_brush.m_tip_size, 3.f) * (1.f - rnd_nor() * m_brush.m_jitter_scale) * size_dyn;
s.flow = glm::pow(m_brush.m_tip_flow, 2.f) * (1.f - rnd_nor() * m_brush.m_jitter_flow) * flow_dyn;
return s;
}
std::vector<ui::StrokeSample> ui::Stroke::compute_samples()
@@ -219,6 +222,12 @@ void ui::Stroke::reset(bool clear_keypoints /*= false*/)
}
void ui::Stroke::add_point(glm::vec2 pos, float pressure)
{
m_curve = glm::min(m_curve + 0.1f, 1.f);
pressure = pressure * glm::pow(m_curve, 2.f);
if (m_brush.m_tip_size_pressure)
m_step = glm::max(m_brush.m_tip_spacing * m_brush.m_tip_size * 100 * pressure, 1.f);
float dist = m_keypoints.empty() ? 0.f :
m_keypoints.back().dist + glm::distance(m_keypoints.back().pos, pos);
if (m_keypoints.empty())
@@ -231,6 +240,7 @@ void ui::Stroke::add_point(glm::vec2 pos, float pressure)
}
void ui::Stroke::start(const ui::Brush& brush)
{
m_curve = 0.f;
m_curve_angles.clear();
m_last_kp = 0;
m_dist = 0.f;

View File

@@ -17,6 +17,8 @@ public:
float m_tip_opacity;
float m_tip_angle;
bool m_tip_angle_follow = false;
bool m_tip_flow_pressure = false;
bool m_tip_size_pressure = false;
float m_jitter_scale;
float m_jitter_angle;
float m_jitter_spread;
@@ -62,6 +64,7 @@ public:
float fov;
};
int m_layer;
float m_curve;
float m_dist;
float m_step;
Camera m_camera;

View File

@@ -1,5 +1,6 @@
#include "pch.h"
#include "log.h"
#include "app.h"
LogRemote LogRemote::I;
@@ -71,7 +72,7 @@ void LogRemote::net_close()
void LogRemote::file_init()
{
if (!m_logfile.is_open())
m_logfile.open("log.txt");
m_logfile.open(App::I.data_path + "/panopainter-log.txt");
}
void LogRemote::file_close()
{
@@ -130,4 +131,4 @@ LogRemote::~LogRemote()
m_mq.UnlockGetters();
if (m_thread.joinable())
m_thread.join();
}
}

View File

@@ -2,7 +2,7 @@
#include "log.h"
#include "node_canvas.h"
#define RES 1024
#define RES 2048
Node* NodeCanvas::clone_instantiate() const
{

View File

@@ -34,6 +34,8 @@ void NodePanelStroke::init_controls()
init_slider(m_jitter_flow, "jitter-flow", &ui::Brush::m_jitter_flow);
init_checkbox(m_tip_angle_follow, "tip-angle-follow", &ui::Brush::m_tip_angle_follow);
init_checkbox(m_tip_flow_pressure, "tip-flow-pressure", &ui::Brush::m_tip_flow_pressure);
init_checkbox(m_tip_size_pressure, "tip-size-pressure", &ui::Brush::m_tip_size_pressure);
//m_canvas->draw_stroke();
}

View File

@@ -19,6 +19,8 @@ public:
NodeSliderH* m_jitter_spread;
NodeSliderH* m_jitter_flow;
NodeCheckBox* m_tip_angle_follow;
NodeCheckBox* m_tip_flow_pressure;
NodeCheckBox* m_tip_size_pressure;
std::function<void(Node* target)> on_stroke_change;
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;