Skip to content

Commit

Permalink
Add preview window clear color option
Browse files Browse the repository at this point in the history
  • Loading branch information
dfranx committed Jun 28, 2019
1 parent bb07ae2 commit 02061b4
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 8 deletions.
Empty file added CHANGELOG.txt
Empty file.
6 changes: 6 additions & 0 deletions GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ namespace ed
std::string oldFile = m_data->Parser.GetOpenedFile();

if (m_selectedTemplate == "?empty") {
strcpy(Settings::Instance().Project.GLSLVS_Extenstion, "vert");
strcpy(Settings::Instance().Project.GLSLPS_Extenstion, "frag");
strcpy(Settings::Instance().Project.GLSLGS_Extenstion, "geom");
Settings::Instance().Project.FPCamera = false;
Settings::Instance().Project.ClearColor = ml::Color(0, 0, 0, 0);

m_data->Renderer.FlushCache();
((CodeEditorUI*)Get(ViewID::Code))->CloseAll();
((PinnedUI*)Get(ViewID::Pinned))->CloseAll();
Expand Down
21 changes: 21 additions & 0 deletions Objects/ProjectParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace ed
strcpy(Settings::Instance().Project.GLSLPS_Extenstion, "frag");
strcpy(Settings::Instance().Project.GLSLGS_Extenstion, "geom");
Settings::Instance().Project.FPCamera = false;
Settings::Instance().Project.ClearColor = ml::Color(0, 0, 0, 0);

// shader passes
for (pugi::xml_node passNode : doc.child("project").child("pipeline").children("pass")) {
Expand Down Expand Up @@ -641,6 +642,16 @@ namespace ed
if (stage == "geometry")
strcpy(Settings::Instance().Project.GLSLGS_Extenstion, settingItem.text().get());
}
else if (type == "clearcolor") {
if (!settingItem.attribute("r").empty())
Settings::Instance().Project.ClearColor.R = settingItem.attribute("r").as_uint();
if (!settingItem.attribute("g").empty())
Settings::Instance().Project.ClearColor.G = settingItem.attribute("g").as_uint();
if (!settingItem.attribute("b").empty())
Settings::Instance().Project.ClearColor.B = settingItem.attribute("b").as_uint();
if (!settingItem.attribute("a").empty())
Settings::Instance().Project.ClearColor.A = settingItem.attribute("a").as_uint();
}
}
}
}
Expand Down Expand Up @@ -1064,6 +1075,16 @@ namespace ed
extNodeGS.append_attribute("stage").set_value("geometry");
extNodeGS.text().set(Settings::Instance().Project.GLSLGS_Extenstion);
}

// clear color
{
pugi::xml_node colorNode = settingsNode.append_child("entry");
colorNode.append_attribute("type").set_value("clearcolor");
colorNode.append_attribute("r").set_value(Settings::Instance().Project.ClearColor.R);
colorNode.append_attribute("g").set_value(Settings::Instance().Project.ClearColor.G);
colorNode.append_attribute("b").set_value(Settings::Instance().Project.ClearColor.B);
colorNode.append_attribute("a").set_value(Settings::Instance().Project.ClearColor.A);
}
}

doc.save_file(file.c_str());
Expand Down
3 changes: 3 additions & 0 deletions Objects/RenderEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ namespace ed
}

// clear main rt only once
ml::Color oldWndClrColor = m_wnd->GetClearColor();
m_wnd->SetClearColor(Settings::Instance().Project.ClearColor);
m_rt.Clear();
m_rt.ClearDepthStencil(1.0f, 0);
m_wnd->SetClearColor(oldWndClrColor);

// bind default sampler state
m_sampler.BindVS(0);
Expand Down
2 changes: 2 additions & 0 deletions Objects/Settings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <ImGuiColorTextEdit/TextEditor.h>
#include <MoonLight/Base/Color.h>

namespace ed
{
Expand Down Expand Up @@ -55,6 +56,7 @@ namespace ed
char GLSLVS_Extenstion[12];
char GLSLPS_Extenstion[12];
char GLSLGS_Extenstion[12];
ml::Color ClearColor;
} Project;

static inline Settings& Instance()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ so please submit your own themes!

Want to create your own theme but don't know how? Visit [TUTORIAL.md](./TUTORIAL.md).

### Custom template
### Custom templates
You can create your own custom templates. SHADERed comes with a GLSL, HLSL and HLSL deferred rendering template.
Templates help you start with an already built base for your new project. To create your own project template, paste your project
directory in /templates directory and name your project file `template.sprj`. You have to reopen SHADERed if it was
Expand Down
3 changes: 3 additions & 0 deletions SHADERed.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<ItemGroup>
<Text Include="CHANGELOG.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
10 changes: 10 additions & 0 deletions UI/OptionsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,15 @@ namespace ed
ImGui::Text("First person camera: ");
ImGui::SameLine();
ImGui::Checkbox("##optpr_fpcamera", &settings->Project.FPCamera);

/* CLEAR COLOR: */
ImVec4 clearColor(settings->Project.ClearColor.R / 255.0f, settings->Project.ClearColor.G / 255.0f, settings->Project.ClearColor.B / 255.0f, settings->Project.ClearColor.A / 255.0f);
ImGui::Text("Preview window clear color: ");
ImGui::SameLine();
ImGui::ColorEdit4("##optpr_clrclr", (float*)&clearColor);
settings->Project.ClearColor.R = clearColor.x * 255;
settings->Project.ClearColor.G = clearColor.y * 255;
settings->Project.ClearColor.B = clearColor.z * 255;
settings->Project.ClearColor.A = clearColor.w * 255;
}
}
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[general]
theme=Dark
theme=Light
vsync=0
autoerror=1
recovery=0
Expand Down
13 changes: 7 additions & 6 deletions workspace.dat
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ Collapsed=0
DockId=0x00000003,0

[Window][###code_viewPS0]
Pos=17,27
Size=6,5
Pos=17,28
Size=6,4
Collapsed=0
DockId=0x00000008,0

[Window][###code_viewVS0]
Pos=17,19
Size=6,6
Size=6,7
Collapsed=0
DockId=0x00000007,0

Expand All @@ -57,7 +57,8 @@ Collapsed=0
DockId=0x00000004,0

[Window][Options]
Pos=326,160
ViewportPos=332,17
ViewportId=0x1F88C31B
Size=857,594
Collapsed=0

Expand Down Expand Up @@ -122,8 +123,8 @@ DockSpace ID=0x160B189F Pos=0,19 Size=32,13 Split=X
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=257,527 SelectedTab=0xC89E3217
DockNode ID=0x00000002 Parent=0x160B189F SizeRef=1665,998 Split=X
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=710,998 Split=Y SelectedTab=0xF7C3C717
DockNode ID=0x00000007 Parent=0x00000005 SizeRef=399,538 SelectedTab=0xF7C3C717
DockNode ID=0x00000008 Parent=0x00000005 SizeRef=399,458 SelectedTab=0xF34EBBA5
DockNode ID=0x00000007 Parent=0x00000005 SizeRef=399,596 SelectedTab=0xF7C3C717
DockNode ID=0x00000008 Parent=0x00000005 SizeRef=399,400 SelectedTab=0xF34EBBA5
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=953,998 Split=Y SelectedTab=0x763816AC
DockNode ID=0x00000009 Parent=0x00000006 SizeRef=953,884 CentralNode=1 SelectedTab=0x763816AC
DockNode ID=0x0000000A Parent=0x00000006 SizeRef=953,112 SelectedTab=0xCB7211A8
Expand Down

0 comments on commit 02061b4

Please sign in to comment.