Merge branch 'master' of https://bitbucket.org/omigamedev/new_engine
* 'master' of https://bitbucket.org/omigamedev/new_engine: add text input popup
This commit is contained in:
16
src/app.h
16
src/app.h
@@ -33,6 +33,7 @@
|
||||
#endif
|
||||
#include "node_panel_grid.h"
|
||||
#include "node_panel_quick.h"
|
||||
#include "node_input_box.h"
|
||||
|
||||
struct VRController
|
||||
{
|
||||
@@ -159,7 +160,11 @@ public:
|
||||
bool clipboard_set_text(const std::string& s);
|
||||
void pick_image(std::function<void(std::string path)> callback);
|
||||
void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
#if __IOS__
|
||||
void pick_file_save(const std::string& type, std::function<void(std::string path)> writer);
|
||||
#else
|
||||
void pick_file_save(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
#endif
|
||||
void pick_dir(std::function<void(std::string path)> callback);
|
||||
void display_file(std::string path);
|
||||
void share_file(std::string path);
|
||||
@@ -206,7 +211,6 @@ public:
|
||||
bool key_char(char key);
|
||||
void toggle_ui();
|
||||
void set_stylus();
|
||||
std::shared_ptr<NodeMessageBox> message_box(const std::string& title, const std::string& text, bool cancel_button = false);
|
||||
|
||||
void rec_clear();
|
||||
void rec_loop();
|
||||
@@ -241,11 +245,17 @@ public:
|
||||
void cloud_upload();
|
||||
void cloud_upload_all();
|
||||
void cloud_browse();
|
||||
void upload(std::string filename, std::string name = "", std::function<void(float)> progress = nullptr);
|
||||
void download(std::string url, std::string dest_filepath, std::function<void(float)> progress = nullptr);
|
||||
void upload(std::string filename, std::string name = "",
|
||||
std::function<void(float)> progress = nullptr);
|
||||
void download(std::string url, std::string dest_filepath,
|
||||
std::function<void(float)> progress = nullptr);
|
||||
bool check_license();
|
||||
|
||||
std::shared_ptr<NodeProgressBar> show_progress(const std::string& title, int total = 0);
|
||||
std::shared_ptr<NodeMessageBox> message_box(const std::string& title,
|
||||
const std::string& text, bool cancel_button = false);
|
||||
std::shared_ptr<NodeInputBox> input_box(const std::string& title,
|
||||
const std::string& field_name, const std::string& ok_caption = "Ok");
|
||||
|
||||
void brush_update(bool update_color, bool update_brush);
|
||||
void title_update();
|
||||
|
||||
@@ -44,6 +44,21 @@ std::shared_ptr<NodeMessageBox> App::message_box(const std::string &title, const
|
||||
return m;
|
||||
}
|
||||
|
||||
std::shared_ptr<NodeInputBox> App::input_box(const std::string& title,
|
||||
const std::string& field_name, const std::string& ok_caption /*= "Ok"*/)
|
||||
{
|
||||
auto m = std::make_shared<NodeInputBox>();
|
||||
m->m_manager = &layout;
|
||||
m->init();
|
||||
m->create();
|
||||
m->loaded();
|
||||
m->m_title->set_text(title.c_str());
|
||||
m->m_field_name->set_text(field_name.c_str());
|
||||
m->btn_ok->m_text->set_text(ok_caption.c_str());
|
||||
layout[main_id]->add_child(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
void App::dialog_usermanual()
|
||||
{
|
||||
auto dialog = std::make_shared<NodeUserManual>();
|
||||
|
||||
@@ -192,14 +192,32 @@ void App::pick_file(std::vector<std::string> types, std::function<void (std::str
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __IOS__
|
||||
void App::pick_file_save(const std::string& type, std::function<void(std::string)> writer)
|
||||
{
|
||||
redraw = true;
|
||||
std::thread([=]{
|
||||
auto mb = input_box("Insert", "File name");
|
||||
std::string placeholder = "name." + type;
|
||||
mb->m_field_text->set_text(placeholder.c_str());
|
||||
mb->on_submit = [this, writer, type] (Node* target, std::string name) {
|
||||
std::string ext = "." + type;
|
||||
std::string path = data_path + "/" + name;
|
||||
if (name.find(ext) == std::string::npos)
|
||||
path += ext;
|
||||
writer(path);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[ios_view pick_file_save:path];
|
||||
});
|
||||
target->destroy();
|
||||
};
|
||||
}).detach();
|
||||
}
|
||||
#else
|
||||
void App::pick_file_save(std::vector<std::string> types, std::function<void (std::string)> callback)
|
||||
{
|
||||
redraw = true;
|
||||
#ifdef __IOS__
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// [ios_view pick_file_save:callback];
|
||||
// });
|
||||
#elif __OSX__
|
||||
#if __OSX__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//NSArray* fileTypes = [NSArray arrayWithObjects:@"ppi", @"PPI", nil];
|
||||
NSMutableArray<NSString*>* fileTypes = [NSMutableArray arrayWithCapacity:types.size()];
|
||||
@@ -233,6 +251,7 @@ void App::pick_file_save(std::vector<std::string> types, std::function<void (std
|
||||
callback(path);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void App::pick_dir(std::function<void(std::string path)> callback)
|
||||
{
|
||||
|
||||
57
src/node_input_box.cpp
Normal file
57
src/node_input_box.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "node_input_box.h"
|
||||
#include "layout.h"
|
||||
|
||||
Node* NodeInputBox::clone_instantiate() const
|
||||
{
|
||||
return new NodeInputBox();
|
||||
}
|
||||
|
||||
void NodeInputBox::init()
|
||||
{
|
||||
SetPosition(0, 0);
|
||||
SetWidthP(100);
|
||||
SetHeightP(100);
|
||||
SetPositioning(YGPositionTypeAbsolute);
|
||||
auto m_template = (*m_manager)[const_hash("input-box")]->m_children[0]->clone();
|
||||
add_child(m_template);
|
||||
m_title = m_template->find<NodeText>("title");
|
||||
m_field_name = m_template->find<NodeText>("field-name");
|
||||
m_field_text = m_template->find<NodeTextInput>("field-text");
|
||||
btn_ok = m_template->find<NodeButton>("btn-ok");
|
||||
btn_ok->on_click = [&](Node*) {
|
||||
if (on_submit)
|
||||
on_submit(this, m_field_text->m_text->m_text);
|
||||
};
|
||||
btn_cancel = m_template->find<NodeButton>("btn-cancel");
|
||||
btn_cancel->on_click = [&](Node*) { destroy(); };
|
||||
m_capture_children = false; // don't capture children events on mouse_capture
|
||||
}
|
||||
|
||||
kEventResult NodeInputBox::handle_event(Event* e)
|
||||
{
|
||||
Node::handle_event(e);
|
||||
auto ke = (KeyEvent*)e;
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::KeyDown:
|
||||
break;
|
||||
case kEventType::KeyUp:
|
||||
if (ke->m_key == kKey::KeyEnter && on_submit)
|
||||
on_submit(this, m_field_text->m_text->m_text);
|
||||
break;
|
||||
case kEventType::KeyChar:
|
||||
break;
|
||||
default:
|
||||
return kEventResult::Available;
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
|
||||
void NodeInputBox::added(Node* parent)
|
||||
{
|
||||
Node::added(parent);
|
||||
mouse_capture();
|
||||
}
|
||||
19
src/node_input_box.h
Normal file
19
src/node_input_box.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "node.h"
|
||||
#include "node_button.h"
|
||||
#include "node_text_input.h"
|
||||
|
||||
class NodeInputBox : public Node
|
||||
{
|
||||
public:
|
||||
std::function<void(Node*, std::string text)> on_submit = nullptr;
|
||||
NodeButton* btn_ok;
|
||||
NodeButton* btn_cancel;
|
||||
NodeText* m_field_name;
|
||||
NodeTextInput* m_field_text;
|
||||
NodeText* m_title;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void init() override;
|
||||
virtual kEventResult handle_event(Event* e) override;
|
||||
virtual void added(Node* parent) override;
|
||||
};
|
||||
@@ -502,6 +502,11 @@ void NodePanelBrushPreset::init()
|
||||
});
|
||||
break;
|
||||
case 1: // export file
|
||||
#if __IOS__
|
||||
App::I->pick_file_save("ppbr", [this] (std::string path) {
|
||||
export_ppbr(path, {});
|
||||
});
|
||||
#else
|
||||
App::I->pick_file_save({ "ppbr" }, [this] (std::string path) {
|
||||
std::thread([this, path] {
|
||||
BT_SetTerminate();
|
||||
@@ -509,6 +514,7 @@ void NodePanelBrushPreset::init()
|
||||
App::I->message_box("Export PPBR", "Brushes exported to:\n" + path);
|
||||
}).detach();
|
||||
});
|
||||
#endif
|
||||
break;
|
||||
case 2: // download
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user