compile for Android, add initial TextInput support
This commit is contained in:
100
engine/layout.h
100
engine/layout.h
@@ -51,6 +51,7 @@ enum class kWidget : uint16_t
|
||||
Border = const_hash("border"),
|
||||
Shape = const_hash("shape"),
|
||||
Text = const_hash("text"),
|
||||
TextInput = const_hash("text-input"),
|
||||
Image = const_hash("image"),
|
||||
Icon = const_hash("icon"),
|
||||
Button = const_hash("button"),
|
||||
@@ -89,6 +90,7 @@ enum class kEventResult : uint8_t
|
||||
enum class kEventCategory : uint8_t
|
||||
{
|
||||
MouseEvent,
|
||||
KeyEvent,
|
||||
};
|
||||
enum class kEventType : uint8_t
|
||||
{
|
||||
@@ -99,6 +101,9 @@ enum class kEventType : uint8_t
|
||||
MouseUpR,
|
||||
MouseEnter,
|
||||
MouseLeave,
|
||||
KeyDown,
|
||||
KeyUp,
|
||||
KeyChar,
|
||||
};
|
||||
|
||||
class Event
|
||||
@@ -115,6 +120,13 @@ public:
|
||||
glm::vec2 m_pos;
|
||||
};
|
||||
|
||||
class KeyEvent : public Event
|
||||
{
|
||||
public:
|
||||
KeyEvent() { m_cat = kEventCategory::KeyEvent; }
|
||||
int m_key;
|
||||
};
|
||||
|
||||
class LayoutManager
|
||||
{
|
||||
std::map<uint16_t, std::unique_ptr<class Node>> m_layouts;
|
||||
@@ -143,7 +155,9 @@ public:
|
||||
std::string m_nodeID_s;
|
||||
std::vector<std::unique_ptr<Node>> m_children;
|
||||
Node* current_mouse_capture = nullptr;
|
||||
Node* current_key_capture = nullptr;
|
||||
bool m_mouse_captured = false;
|
||||
bool m_key_captured = false;
|
||||
|
||||
glm::mat4 m_proj;
|
||||
glm::mat4 m_mvp;
|
||||
@@ -291,6 +305,8 @@ public:
|
||||
int get_child_index(Node* n);
|
||||
void mouse_capture() { root()->current_mouse_capture = this; m_mouse_captured = true; }
|
||||
void mouse_release() { root()->current_mouse_capture = nullptr; m_mouse_captured = false; }
|
||||
void key_capture() { root()->current_key_capture = this; m_key_captured = true; }
|
||||
void key_release() { root()->current_key_capture = nullptr; m_key_captured = false; }
|
||||
|
||||
// class iterator
|
||||
// {
|
||||
@@ -682,6 +698,60 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class NodeTextInput : public NodeBorder
|
||||
{
|
||||
public:
|
||||
NodeText* m_text;
|
||||
std::string m_string;
|
||||
virtual Node* clone_instantiate() const override { return new NodeTextInput(); }
|
||||
virtual void init() override
|
||||
{
|
||||
init_controls();
|
||||
}
|
||||
void init_controls()
|
||||
{
|
||||
m_text = new NodeText;
|
||||
add_child(m_text);
|
||||
m_text->m_font = "arial";
|
||||
m_text->m_font_size = 11;
|
||||
m_text->m_text = "TextInput";
|
||||
m_text->create();
|
||||
}
|
||||
virtual kEventResult handle_event(Event* e) override
|
||||
{
|
||||
KeyEvent* ke = (KeyEvent*)e;
|
||||
switch (e->m_type)
|
||||
{
|
||||
case kEventType::MouseDownL:
|
||||
break;
|
||||
case kEventType::MouseUpL:
|
||||
key_capture();
|
||||
break;
|
||||
case kEventType::KeyDown:
|
||||
switch (ke->m_key)
|
||||
{
|
||||
case VK_BACK:
|
||||
m_string.erase(m_string.end() - 1);
|
||||
m_text->set_text(m_string.c_str());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case kEventType::KeyChar:
|
||||
if (ke->m_key >= 32 && ke->m_key < 32+96)
|
||||
{
|
||||
m_string += (char)ke->m_key;
|
||||
m_text->set_text(m_string.c_str());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return kEventResult::Consumed;
|
||||
}
|
||||
};
|
||||
|
||||
class NodeMessageBox : public Node
|
||||
{
|
||||
public:
|
||||
@@ -1306,18 +1376,24 @@ public:
|
||||
virtual Node* clone_instantiate() const override { return new NodePanelLayer(); }
|
||||
virtual void init() override
|
||||
{
|
||||
LOG("NodePanelLayer::init");
|
||||
init_template("tpl-panel-layers");
|
||||
LOG("template initted");
|
||||
m_layers_container = find<NodeBorder>("layers-container");
|
||||
LOG("template container found");
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
LOG("add layer");
|
||||
add_layer();
|
||||
}
|
||||
LOG("find components");
|
||||
m_current_layer = m_layers[0];
|
||||
m_layers[0]->m_selected = true;
|
||||
btn_add = find<NodeButtonCustom>("btn-add");
|
||||
btn_remove = find<NodeButtonCustom>("btn-remove");
|
||||
btn_up = find<NodeButtonCustom>("btn-up");
|
||||
btn_down = find<NodeButtonCustom>("btn-down");
|
||||
LOG("attach events");
|
||||
btn_add->on_click = [this](Node*) {
|
||||
add_layer();
|
||||
};
|
||||
@@ -1332,6 +1408,7 @@ public:
|
||||
btn_down->on_click = [this](Node*) {
|
||||
m_layers_container->move_child_offset(m_current_layer, +1);
|
||||
};
|
||||
LOG("done init");
|
||||
}
|
||||
void add_layer()
|
||||
{
|
||||
@@ -1418,13 +1495,13 @@ public:
|
||||
{
|
||||
init_template("tpl-panel-brushes");
|
||||
//m_layers_container = find<NodeBorder>("layers-container");
|
||||
static auto icons = FindAllBrushes("data\\Icons\\");
|
||||
static auto icons = FindAllBrushes("data/Icons/");
|
||||
if (m_container = find<NodeBorder>("brushes"))
|
||||
{
|
||||
int count = 0;
|
||||
for (auto& i : icons)
|
||||
{
|
||||
std::string path = "data\\Icons\\" + i;
|
||||
std::string path = "data/Icons/" + i;
|
||||
NodeButtonBrush* brush = new NodeButtonBrush;
|
||||
m_container->add_child(brush);
|
||||
brush->init();
|
||||
@@ -1452,6 +1529,7 @@ public:
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
std::string search_path = folder + "*.png";
|
||||
#ifdef _WIN32
|
||||
WIN32_FIND_DATAA fd;
|
||||
HANDLE hFind = ::FindFirstFileA(search_path.c_str(), &fd);
|
||||
if (hFind != INVALID_HANDLE_VALUE) {
|
||||
@@ -1464,6 +1542,17 @@ public:
|
||||
} while (::FindNextFileA(hFind, &fd));
|
||||
::FindClose(hFind);
|
||||
}
|
||||
#elif __ANDROID__
|
||||
LOG("listing brushes");
|
||||
AAssetDir* dir = AAssetManager_openDir(Asset::m_am, "data/Icons");
|
||||
while (const char* name = AAssetDir_getNextFileName(dir))
|
||||
{
|
||||
LOG("asset: %s", name);
|
||||
names.push_back(name);
|
||||
}
|
||||
AAssetDir_close(dir);
|
||||
#else
|
||||
#endif
|
||||
return names;
|
||||
}
|
||||
uint16_t get_texture_id(int index) const
|
||||
@@ -1606,7 +1695,7 @@ public:
|
||||
"out vec3 uv;"
|
||||
"void main(){"
|
||||
" uv = vec3(uvs, pos.w);"
|
||||
" gl_Position = mvp * vec4(pos.xyz, 1.f);"
|
||||
" gl_Position = mvp * vec4(pos.xyz, 1.0);"
|
||||
"}";
|
||||
static const char* shader_f =
|
||||
SHADER_VERSION
|
||||
@@ -1616,7 +1705,7 @@ public:
|
||||
"in vec3 uv;"
|
||||
"out vec4 frag;"
|
||||
"void main(){"
|
||||
" float a = (1 - texture(tex, uv.xy).r) * alpha;"
|
||||
" float a = (1.0 - texture(tex, uv.xy).r) * alpha;"
|
||||
" frag = vec4(col.rgb, a);"
|
||||
"}";
|
||||
m_shader.create(shader_v, shader_f);
|
||||
@@ -1732,6 +1821,7 @@ public:
|
||||
NodeSliderH* m_jitter_angle;
|
||||
NodeSliderH* m_jitter_spread;
|
||||
NodeSliderH* m_jitter_flow;
|
||||
std::function<void(Node* target)> on_stroke_change;
|
||||
virtual Node* clone_instantiate() const override { return new NodePanelStroke(); }
|
||||
virtual void clone_finalize(Node* dest) const override
|
||||
{
|
||||
@@ -1766,6 +1856,8 @@ public:
|
||||
{
|
||||
m_canvas->*prop = value;
|
||||
m_canvas->draw_stroke();
|
||||
if (on_stroke_change)
|
||||
on_stroke_change(this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user