add scrollbar, improve presets, other small fixes
This commit is contained in:
@@ -114,7 +114,7 @@ target_link_libraries(
|
||||
native-lib
|
||||
android
|
||||
app-glue
|
||||
${CMAKE_SOURCE_DIR}/../libs/curl-android-ios/android/armeabi-v7a/libcurl.a
|
||||
${CMAKE_SOURCE_DIR}/../libs/curl-android-ios/android/${ANDROID_ABI}/libcurl.a
|
||||
EGL
|
||||
GLESv3
|
||||
log
|
||||
|
||||
@@ -269,6 +269,7 @@ JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickExternalCal
|
||||
|
||||
LOG("data_path %s", file_path.c_str());
|
||||
App::I.data_path = file_path;
|
||||
App::I.work_path = file_path;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,22 +33,22 @@ public class MainActivity extends NativeActivity {
|
||||
|
||||
public void setRootPath()
|
||||
{
|
||||
Log.v("MainActivity", "permission granted");
|
||||
Log.v("PanoPainterJava", "permission granted");
|
||||
File d = Environment.getExternalStorageDirectory();
|
||||
File pano_dir = new File(d, "PanoPainter");
|
||||
|
||||
if (!pano_dir.exists())
|
||||
{
|
||||
if (pano_dir.mkdirs())
|
||||
Log.v("MainActivity", "create path " + pano_dir.getAbsolutePath());
|
||||
Log.v("PanoPainterJava", "create path " + pano_dir.getAbsolutePath());
|
||||
else
|
||||
Log.v("MainActivity", "create path failed");
|
||||
Log.v("PanoPainterJava", "create path failed");
|
||||
|
||||
}
|
||||
pickExternalCallback(pano_dir.getAbsolutePath());
|
||||
}
|
||||
public void checkPermissionReadStorage(){
|
||||
Log.v("MainActivity", "permission checking");
|
||||
Log.v("PanoPainterJava", "permission checking");
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
|
||||
setRootPath();
|
||||
} else {
|
||||
@@ -68,14 +68,14 @@ public class MainActivity extends NativeActivity {
|
||||
// No explanation needed, we can request the permission.
|
||||
|
||||
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
||||
Log.v("MainActivity", "permission request");
|
||||
Log.v("PanoPainterJava", "permission request");
|
||||
|
||||
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
|
||||
// app-defined int constant. The callback method gets the
|
||||
// result of the request.
|
||||
// }
|
||||
} else {
|
||||
Log.v("MainActivity", "permission already granted");
|
||||
Log.v("PanoPainterJava", "permission already granted");
|
||||
setRootPath();
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class MainActivity extends NativeActivity {
|
||||
// contacts-related task you need to do.
|
||||
setRootPath();
|
||||
} else {
|
||||
Log.v("MainActivity", "permission denied");
|
||||
Log.v("PanoPainterJava", "permission denied");
|
||||
|
||||
// permission denied, boo! Disable the
|
||||
// functionality that depends on this permission.
|
||||
@@ -123,7 +123,7 @@ public class MainActivity extends NativeActivity {
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("*/*");
|
||||
startActivityForResult(Intent.createChooser(intent, "Select a file"), 1);
|
||||
Log.v("PICK", "start");
|
||||
Log.v("PanoPainterJava", "pick start");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,7 +136,7 @@ public class MainActivity extends NativeActivity {
|
||||
String path = null;
|
||||
try {
|
||||
path = PathUtil.getPath(this, uri);
|
||||
Log.v("PICK", "selected " + path);
|
||||
Log.v("PanoPainterJava", "pick selected " + path);
|
||||
pickFileCallback(path);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -98,6 +98,9 @@
|
||||
<button-custom id="btn-down" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 0">
|
||||
<icon width="30" icon="bullet_arrow_down"/>
|
||||
</button-custom>
|
||||
<button-custom id="btn-save" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 0">
|
||||
<icon width="30" icon="bullet_disk"/>
|
||||
</button-custom>
|
||||
<node grow="1"></node>
|
||||
<button-custom id="btn-remove" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 10 0 0">
|
||||
<icon width="30" icon="bin_closed"/>
|
||||
@@ -513,8 +516,8 @@
|
||||
<scroll id="files-list" dir="row" wrap="1" flood-events="1" grow="1" height="100%" margin="0 0 0 0" pad="0 20 0 0" color=".2 .2 .2 1">
|
||||
</scroll>
|
||||
</border>
|
||||
<node id="footer" height="40" dir="row" align="flex-end" justify="flex-end" pad="10">
|
||||
<node grow="1" os="win,osx"><button id="btn-path" text="Set destination dir" width="120" height="30" margin="0 10 0 0"/></node>
|
||||
<node id="footer" height="50" dir="row" align="flex-end" justify="flex-end" pad="10">
|
||||
<node grow="1" os="win,osx"><button id="btn-path" text="Set destination dir" width="130" height="30" margin="0 10 0 0"/></node>
|
||||
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
|
||||
<button id="btn-cancel" text="Cancel" width="60" height="30"/>
|
||||
</node>
|
||||
@@ -1128,7 +1131,7 @@ Here's a list of what's available in this release.
|
||||
<button-custom id="btn-stroke" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2">
|
||||
<image path="data/ui/stroke.png" width="100%" height="100%" align="center" justify="flex-end"/>
|
||||
</button-custom>
|
||||
<button id="btn-brush-preset" width="50" height="50" margin="0 0 5 0" text="Preset" thickness="1" border-color=".1" pad="2"/>
|
||||
<!--<button id="btn-brush-preset" width="50" height="50" margin="0 0 5 0" text="Preset" thickness="1" border-color=".1" pad="2"/>-->
|
||||
<!--
|
||||
<button-custom id="btn-brush" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2">
|
||||
<image path="data/ui/brushes.png" width="100%" height="100%" align="center" justify="flex-end"/>
|
||||
|
||||
@@ -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