From d44434a458117636ccce6849559e0deea5c1e3ce Mon Sep 17 00:00:00 2001 From: omigamedev Date: Thu, 16 Nov 2017 09:54:57 +0000 Subject: [PATCH] fix shaders for ios, add separator for combobox --- data/layout.xml | 2 +- engine/app_shaders.cpp | 14 +++++----- engine/canvas.cpp | 10 ++++++++ engine/node_combobox.cpp | 55 +++++++++++++++++++++++++--------------- engine/node_combobox.h | 4 ++- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/data/layout.xml b/data/layout.xml index dcbe2b9..3ac5fe8 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -159,7 +159,7 @@ - + diff --git a/engine/app_shaders.cpp b/engine/app_shaders.cpp index 615feb3..37ff329 100644 --- a/engine/app_shaders.cpp +++ b/engine/app_shaders.cpp @@ -101,12 +101,12 @@ void App::initShaders() " sum += textureOffset(t, uv, ivec2( 1, 1));\n" " return sum / vec4(9.0);\n" "}\n" - "vec3 blend_normal(vec4 base, vec4 stroke, float alpha_tot) { return mix(base.rgb, stroke.rgb, stroke.a/alpha_tot); }\n" - "vec3 blend_multiply(vec4 base, vec4 stroke, float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, base.rgb*stroke.rgb, stroke.a/alpha_tot), base.a/alpha_tot); }\n" - "vec3 blend_screen(vec4 base, vec4 stroke, float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, 1.0-(1.0-base.rgb)*(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }\n" - "vec3 blend_colorDodge(vec4 base, vec4 stroke, float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, base.rgb/(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }\n" - "vec3 blend_overlay(vec4 base, vec4 stroke, float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, mix(2.0*base.rgb*stroke.rgb, 1.0-2.0*(1.0-base.rgb)*(1.0-stroke.rgb), floor(base.rgb*2.0)), stroke.a/alpha_tot), base.a/alpha_tot); }\n" - "vec3 blend(vec4 base, vec4 stroke, float alpha_tot, int mode) { switch(mode){\n" + "mediump vec3 blend_normal(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot) { return mix(base.rgb, stroke.rgb, stroke.a/alpha_tot); }\n" + "mediump vec3 blend_multiply(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, base.rgb*stroke.rgb, stroke.a/alpha_tot), base.a/alpha_tot); }\n" + "mediump vec3 blend_screen(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, 1.0-(1.0-base.rgb)*(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }\n" + "mediump vec3 blend_colorDodge(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, base.rgb/(1.0-stroke.rgb), stroke.a/alpha_tot), base.a/alpha_tot); }\n" + "mediump vec3 blend_overlay(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot) { return mix(stroke.rgb, mix(base.rgb, mix(2.0*base.rgb*stroke.rgb, 1.0-2.0*(1.0-base.rgb)*(1.0-stroke.rgb), floor(base.rgb*2.0)), stroke.a/alpha_tot), base.a/alpha_tot); }\n" + "mediump vec3 blend(mediump vec4 base, mediump vec4 stroke, mediump float alpha_tot, int mode) { switch(mode){\n" " case 0: return blend_normal(base, stroke, alpha_tot);" " case 1: return blend_multiply(base, stroke, alpha_tot);" " case 2: return blend_screen(base, stroke, alpha_tot);" @@ -269,7 +269,7 @@ void App::initShaders() #else "out mediump vec4 frag;\n" #endif - "mediump float rand(vec2 co) { return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); }\n" + "mediump float rand(mediump vec2 co) { return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); }\n" "void main(){\n" " mediump vec2 uv2 = gl_FragCoord.st / resolution;\n" " mediump float stencil = 1.0 - (texture(tex_stencil, (uv2+stencil_offset) * 2.0).r * 0.9) * stencil_alpha;\n" diff --git a/engine/canvas.cpp b/engine/canvas.cpp index 6ae0ed7..74c1dac 100644 --- a/engine/canvas.cpp +++ b/engine/canvas.cpp @@ -719,8 +719,13 @@ void ui::Canvas::resize(int width, int height) m_height = height; for (int i = 0; i < 6; i++) { +#if __IOS__ + m_tmp[i].create(width, height, -1, GL_RGBA8); + m_tex[i].create(width, height, GL_RGBA8); +#else m_tmp[i].create(width, height, -1, GL_RGBA32F); m_tex[i].create(width, height, GL_RGBA32F); +#endif m_tex2[i].create(width, height, GL_RGBA8); } for (auto& l : m_layers) @@ -734,8 +739,13 @@ bool ui::Canvas::create(int width, int height) m_height = height; for (int i = 0; i < 6; i++) { +#if __IOS__ + m_tmp[i].create(width, height, -1, GL_RGBA8); + m_tex[i].create(width, height, GL_RGBA8); +#else m_tmp[i].create(width, height, -1, GL_RGBA32F); m_tex[i].create(width, height, GL_RGBA32F); +#endif m_tex2[i].create(width, height, GL_RGBA8); // TODO: destroy before recreating } m_sampler.create(GL_NEAREST); diff --git a/engine/node_combobox.cpp b/engine/node_combobox.cpp index a1923d6..8aa7480 100644 --- a/engine/node_combobox.cpp +++ b/engine/node_combobox.cpp @@ -12,7 +12,7 @@ void NodeComboBox::clone_copy(Node* dest) const { NodeButton::clone_copy(dest); NodeComboBox* n = static_cast(dest); - n->labels = labels; + n->m_data = m_data; n->m_current_index = m_current_index; } @@ -25,27 +25,40 @@ void NodeComboBox::loaded() popup->create(); popup->loaded(); root()->add_child(popup); - for (int i = 0; i < labels.size(); i++) + m_items.clear(); + for (int i = 0; i < m_data.size(); i++) { - NodeButton* btn = new NodeButton; - btn->init(); - btn->create(); - btn->loaded(); - popup->add_child(btn); - btn->m_text->set_text(labels[i].c_str()); - btn->m_border->SetWidthP(100.f); - btn->m_border->SetHeight(30.f); - btn->on_click = [this,popup,btn](Node* target) { - int index = popup->get_child_index(target); - m_current_index = index; - m_text->set_text(labels[index].c_str()); - popup->mouse_release(); - popup->destroy(); - if (on_select) - on_select(btn, index); - }; + if (m_data[i] == "-") + { + auto n = popup->add_child(); + n->SetHeight(5.f); + n->SetWidthP(100.f); + n->m_color = {0, 0, 0, 1}; + } + else + { + auto btn = popup->add_child(); + btn->m_text->set_text(m_data[i].c_str()); + btn->m_border->SetWidthP(100.f); + btn->m_border->SetHeight(30.f); + int index = (int)m_items.size(); + m_items.push_back(m_data[i]); + btn->on_click = [this,popup,btn,index](Node* target) { + m_current_index = index; + m_selected_child_index = popup->get_child_index(target); + m_text->set_text(m_items[index].c_str()); + popup->mouse_release(); + popup->destroy(); + if (on_select) + on_select(btn, index); + }; + } } - glm::vec2 pos = m_pos + glm::vec2(0, m_size.y - (m_current_index+1) * 30.f); + float offset = 0; + for (int i = 0; i <= m_selected_child_index; i++) + offset += (m_data[i] == "-") ? 5.f : 30.f; + + glm::vec2 pos = m_pos + glm::vec2(0, m_size.y - offset); popup->SetPositioning(YGPositionTypeAbsolute); popup->SetPosition(pos.x, pos.y); popup->SetSize(m_size.x, YGUndefined); @@ -66,7 +79,7 @@ void NodeComboBox::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* { case kAttribute::ComboList: { - labels = split(attr->Value(), ','); + m_data = split(attr->Value(), ','); break; } case kAttribute::Default: diff --git a/engine/node_combobox.h b/engine/node_combobox.h index ad6c85c..a505a90 100644 --- a/engine/node_combobox.h +++ b/engine/node_combobox.h @@ -5,8 +5,10 @@ class NodeComboBox : public NodeButton { public: std::function on_select; - std::vector labels; + std::vector m_data; + std::vector m_items; int m_current_index = 0; + int m_selected_child_index = 0; virtual Node* clone_instantiate() const override; virtual void clone_copy(Node* dest) const override; virtual void loaded() override;