Skip to content

Commit

Permalink
Timeline panel support edit color #1259
Browse files Browse the repository at this point in the history
  • Loading branch information
timi-liuliang committed May 15, 2023
1 parent e99efb8 commit aed8a68
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 50 deletions.
10 changes: 5 additions & 5 deletions editor/echo/Editor/UI/MainWindow/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace Studio
EchoSafeDelete(m_shaderEditorPanel, ShaderEditor);
EchoSafeDelete(m_documentPanel, DocumentPanel);
EchoSafeDelete(m_debuggerPanel, DebuggerPanel);
EchoSafeDelete(m_scenePanel, NodeTreePanel);
EchoSafeDelete(m_nodeTreePanel, NodeTreePanel);
EchoSafeDelete(m_resPanel, ResPanel);
EchoSafeDelete(m_renderPanel, QDockWidget);
}
Expand All @@ -135,7 +135,7 @@ namespace Studio

m_renderPanel = EchoNew(QDockWidget(this));
m_resPanel = EchoNew(ResPanel(this));
m_scenePanel = EchoNew(NodeTreePanel(this));
m_nodeTreePanel = EchoNew(NodeTreePanel(this));
m_scriptEditorMdiArea = EchoNew(TextEditorArea);
m_shaderEditorPanel = EchoNew(ShaderEditor(this));
m_logPanel = AStudio::instance()->getLogPanel();
Expand All @@ -158,7 +158,7 @@ namespace Studio
this->addDockWidget(Qt::TopDockWidgetArea, m_shaderEditorPanel);
this->addDockWidget(Qt::TopDockWidgetArea, m_renderPanel);
this->addDockWidget(Qt::LeftDockWidgetArea, m_resPanel);
this->addDockWidget(Qt::RightDockWidgetArea, m_scenePanel);
this->addDockWidget(Qt::RightDockWidgetArea, m_nodeTreePanel);
this->addDockWidget(Qt::BottomDockWidgetArea, m_logPanel);
this->addDockWidget(Qt::BottomDockWidgetArea, m_documentPanel);
this->addDockWidget(Qt::BottomDockWidgetArea, m_debuggerPanel);
Expand Down Expand Up @@ -299,7 +299,7 @@ namespace Studio
void MainWindow::onNewScene()
{
onSaveProject();
m_scenePanel->clear();
m_nodeTreePanel->clear();
EchoEngine::instance()->newEditNodeTree();

updateRenderWindowTitle();
Expand Down Expand Up @@ -474,7 +474,7 @@ namespace Studio
EchoEngine::instance()->saveCurrentEditNodeTree();

// save current edit res
m_scenePanel->saveCurrentEditRes();
m_nodeTreePanel->saveCurrentEditRes();

// refresh respanel display
m_resPanel->reslectCurrentDir();
Expand Down
2 changes: 1 addition & 1 deletion editor/echo/Editor/UI/MainWindow/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace Studio
QTimer m_timer;
QDockWidget* m_renderPanel = nullptr;
ResPanel* m_resPanel = nullptr;
NodeTreePanel* m_scenePanel = nullptr;
NodeTreePanel* m_nodeTreePanel = nullptr;
TextEditorArea* m_scriptEditorMdiArea = nullptr;
ShaderEditor* m_shaderEditorPanel = nullptr;
QDockWidgets m_centerPanels;
Expand Down
16 changes: 0 additions & 16 deletions engine/modules/ui/base/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ namespace Echo
CLASS_BIND_METHOD(UiImage, setAnchor);
CLASS_BIND_METHOD(UiImage, getTextureRes);
CLASS_BIND_METHOD(UiImage, setTextureRes);
CLASS_BIND_METHOD(UiImage, getColor);
CLASS_BIND_METHOD(UiImage, setColor);
CLASS_BIND_METHOD(UiImage, getMaterial);
CLASS_BIND_METHOD(UiImage, setMaterial);

CLASS_REGISTER_PROPERTY(UiImage, "Width", Variant::Type::Int, getWidth, setWidth);
CLASS_REGISTER_PROPERTY(UiImage, "Height", Variant::Type::Int, getHeight, setHeight);
CLASS_REGISTER_PROPERTY(UiImage, "Anchor", Variant::Type::Vector2, getAnchor, setAnchor);
CLASS_REGISTER_PROPERTY(UiImage, "Texture", Variant::Type::ResourcePath, getTextureRes, setTextureRes);
CLASS_REGISTER_PROPERTY(UiImage, "Color", Variant::Type::Color, getColor, setColor);
CLASS_REGISTER_PROPERTY(UiImage, "Material", Variant::Type::Object, getMaterial, setMaterial);
CLASS_REGISTER_PROPERTY_HINT(UiImage, "Material", PropertyHintType::ObjectType, "Material");
}
Expand Down Expand Up @@ -80,16 +77,6 @@ namespace Echo
}
}

void UiImage::setColor(const Color& color)
{
if (m_color != color)
{
m_color = color;

clearRenderable();
}
}

void UiImage::setMaterial(Object* material)
{
if (m_material != material)
Expand All @@ -114,9 +101,6 @@ namespace Echo

if (!m_textureRes.getPath().empty() && m_material && m_material->isUniformExist("BaseTexture"))
m_material->setUniformTexture("BaseTexture", m_textureRes.getPath());

if (m_material && m_material->isUniformExist("BaseColor"))
m_material->setUniformValue("BaseColor", &m_color);

// Mesh
Ui::VertexArray vertices;
Expand Down
5 changes: 0 additions & 5 deletions engine/modules/ui/base/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ namespace Echo
// Texture res path
void setTextureRes(const ResourcePath& path);
const ResourcePath& getTextureRes() { return m_textureRes; }

// Tint color
const Color& getColor() const { return m_color; }
void setColor(const Color& color);

// Width
i32 getWidth() const { return m_width; }
Expand Down Expand Up @@ -59,7 +55,6 @@ namespace Echo

private:
ResourcePath m_textureRes = ResourcePath("", ".png|.rt");
Color m_color = Color::WHITE;
MeshPtr m_mesh;
MaterialPtr m_material;
RenderProxyPtr m_renderable;
Expand Down
18 changes: 13 additions & 5 deletions engine/modules/ui/base/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ namespace Echo

void UiRender::bindMethods()
{
CLASS_BIND_METHOD(UiRender, getAlpha);
CLASS_BIND_METHOD(UiRender, setAlpha);
CLASS_BIND_METHOD(UiRender, getColor);
CLASS_BIND_METHOD(UiRender, setColor);

CLASS_REGISTER_PROPERTY(UiRender, "Alpha", Variant::Type::Real, getAlpha, setAlpha);
CLASS_REGISTER_PROPERTY(UiRender, "Color", Variant::Type::Color, getColor, setColor);
}

void UiRender::setColor(const Color& color)
{
if (m_color != color)
{
m_color = color;
}
}

void* UiRender::getGlobalUniformValue(const String& name)
Expand All @@ -30,8 +38,8 @@ namespace Echo
if (value)
return value;

if (name == "u_Alpha")
return (void*)(&m_alpha);
if (name == "BaseColor")
return (void*)(&m_color);

return nullptr;
}
Expand Down
8 changes: 4 additions & 4 deletions engine/modules/ui/base/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ namespace Echo
UiRender();
virtual ~UiRender();

// alpha
float getAlpha() const { return m_alpha; }
void setAlpha(float alpha) { m_alpha = alpha; }
// Tint color
const Color& getColor() const { return m_color; }
void setColor(const Color& color);

protected:
// get global uniforms
virtual void* getGlobalUniformValue(const String& name) override;

protected:
float m_alpha = 1.f;
Color m_color = Color::WHITE;
};
}
29 changes: 15 additions & 14 deletions engine/modules/ui/res/Transparent.shader
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<res class="ShaderProgram" Type="glsl" Domain="Surface" CullMode="CULL_BACK" BlendMode="Transparent" Uniforms.BaseTexture="">
<res class="ShaderProgram" Type="glsl" Domain="Surface" CullMode="CULL_BACK" BlendMode="Transparent" Uniforms.BaseColor="1 1 1 1 " Uniforms.BaseTexture="">
<property name="VertexShader"><![CDATA[#version 450

layout(binding = 0, std140) uniform UBO
Expand All @@ -26,6 +26,7 @@ void main()
layout(binding = 1, std140) uniform UBO
{
vec2 u_BaseTextureSize;
vec4 BaseColor;
} fs_ubo;

layout(binding = 2) uniform sampler2D BaseTexture;
Expand All @@ -36,7 +37,7 @@ layout(location = 0) out vec4 o_FragColor;
void main()
{
vec4 BaseTexture_Color = texture(BaseTexture, v_UV);
vec4 BaseColor_Value = vec4(1.0);
vec4 BaseColor_Value = vec4(fs_ubo.BaseColor);
float Multiplication_395 = BaseTexture_Color.w * BaseColor_Value.w;
vec3 Multiplication_394 = BaseTexture_Color.xyz * BaseColor_Value.xyz;
vec3 _Diffuse = Multiplication_394;
Expand Down Expand Up @@ -154,27 +155,27 @@ void main()
}
},
{
"id": "{8302a621-2de2-4086-8db6-2d001e1646f4}",
"id": "{99e60fe4-8498-44b1-b7bd-fa8178951ab2}",
"model": {
"Variable": "Multiplication_395",
"name": "Multiplication"
"Color": "1 1 1 1 ",
"Uniform": "true",
"Variable": "BaseColor",
"name": "Color"
},
"position": {
"x": -181,
"y": 373
"x": -343,
"y": 371
}
},
{
"id": "{99e60fe4-8498-44b1-b7bd-fa8178951ab2}",
"id": "{8302a621-2de2-4086-8db6-2d001e1646f4}",
"model": {
"Color": "1 1 1 1 ",
"Uniform": "false",
"Variable": "BaseColor",
"name": "Color"
"Variable": "Multiplication_395",
"name": "Multiplication"
},
"position": {
"x": -344,
"y": 371
"x": -181,
"y": 373
}
},
{
Expand Down

0 comments on commit aed8a68

Please sign in to comment.