fix shaders for ios, add separator for combobox

This commit is contained in:
2017-11-16 09:54:57 +00:00
parent c7523310d5
commit d44434a458
5 changed files with 55 additions and 30 deletions

View File

@@ -159,7 +159,7 @@
</node>
<border dir="col" align="center" grow="1" width="1" flood-events="1">
<node height="30" pad="1" width="100%" dir="row">
<combobox id="blend-mode" text="Normal" width="100%" height="30" combo-list="Normal,Multiply,Screen,Color Dodge,Overlay" default="0"/>
<combobox id="blend-mode" text="Normal" width="100%" height="30" combo-list="Normal,-,Multiply,Screen,-,Color Dodge,Overlay" default="0"/>
</node>
<node height="20" pad="1" width="100%" dir="row">
<slider-h id="tip-size" width="1" grow="1" value=".25"/>

View File

@@ -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"

View File

@@ -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);

View File

@@ -12,7 +12,7 @@ void NodeComboBox::clone_copy(Node* dest) const
{
NodeButton::clone_copy(dest);
NodeComboBox* n = static_cast<NodeComboBox*>(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<NodeBorder>();
n->SetHeight(5.f);
n->SetWidthP(100.f);
n->m_color = {0, 0, 0, 1};
}
else
{
auto btn = popup->add_child<NodeButton>();
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:

View File

@@ -5,8 +5,10 @@ class NodeComboBox : public NodeButton
{
public:
std::function<void(Node* target, int index)> on_select;
std::vector<std::string> labels;
std::vector<std::string> m_data;
std::vector<std::string> 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;