Skip to content

Commit 7c07265

Browse files
committed
webpage update again
1 parent 640dcc4 commit 7c07265

11 files changed

Lines changed: 156 additions & 144 deletions

File tree

Binary file not shown.
-6.78 KB
Binary file not shown.

cmake-emscripten/Complex_Final_Proj.js

Lines changed: 44 additions & 44 deletions
Large diffs are not rendered by default.
-7.71 KB
Binary file not shown.

fractals/FractalConstants.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace gan::fractal {
2020
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2121
// ~~~~~~~~~~~~~ Fractal Creation ~~~~~~~~~~~~~~~~
2222

23-
inline constexpr int totalFractalNum = 7;
23+
inline constexpr int totalFractalNum = 6;
2424
inline constexpr FractalInfo fractalInfo[totalFractalNum] = {
2525
// Mandelbrot Set
2626
{"Mandelbrot", "mandelbrot.frag"},
@@ -37,8 +37,6 @@ namespace gan::fractal {
3737
{"Multibrot Power {Float}", "uMultiPower", FLOAT, {1, 100}, UniformData(2.f)}}},
3838
// Burning Ship Fractal
3939
{"Burning Ship", "burn_ship.frag"},
40-
// Popcorn Fractal
41-
{"Popcorn", "popcorn.frag", {}, "popcorn.vert"}
4240
};
4341

4442
inline constexpr const char* fractalNames[totalFractalNum] = {
@@ -47,8 +45,7 @@ namespace gan::fractal {
4745
fractalInfo[2].name,
4846
fractalInfo[3].name,
4947
fractalInfo[4].name,
50-
fractalInfo[5].name,
51-
fractalInfo[6].name,
48+
fractalInfo[5].name
5249
};
5350

5451
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

fractals/FractalExplorer.cpp

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ void FractalExplorer::display(const Window& window, vec2 mousePos) {
2828
for (auto it = panels.begin(); it != panels.end(); ++it) {
2929
it->imguiBegin(window);
3030

31-
bool remove = ImGui::Button("Remove Fractal View");
31+
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.4f, 0.2f, 0.2f, 1.0f));
32+
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.7f, 0.3f, 0.3f, 1.0f));
33+
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.4f, 0.4f, 1.0f));
34+
bool remove = ImGui::Button("Remove Fractal");
35+
ImGui::PopStyleColor(3);
3236

3337
it->imguiBody(window);
3438
it->imguiEnd();
3539

3640
if (remove) {
37-
cachedFractals.push_back(it->extract());
3841
panels.erase(it);
3942
reorganize(window);
4043
goto reset_display;
@@ -44,12 +47,14 @@ void FractalExplorer::display(const Window& window, vec2 mousePos) {
4447
}
4548

4649
// First get what we need from the compiler GUI.
47-
auto id = compilerGUI.display(window);
48-
if (id >= 0 && id < fractal::totalFractalNum) {
49-
instantiateNewFractalPanel(id);
50+
auto result = compilerGUI.display(window, panels.size());
51+
if (result == FractalCompilerGUI::NEW_FRACTAL_PANEL) {
52+
instantiateFractalPanel(compilerGUI.currentFractalSelection, true);
53+
reorganize(window);
54+
} else if (result == FractalCompilerGUI::INPLACE_FRACTAL) {
55+
instantiateFractalPanel(compilerGUI.currentFractalSelection, false);
5056
reorganize(window);
5157
}
52-
5358
}
5459

5560
void FractalExplorer::reorganize(const Window& window) {
@@ -85,47 +90,32 @@ void FractalExplorer::onMouseWheel(const Window& window, const Mouse& mouse) {
8590
cursor.onMouseWheel(window, mouse, panels);
8691
}
8792

88-
void FractalExplorer::instantiateNewFractalPanel(fractal_id id) {
89-
auto targetPanel = panels.size();
90-
91-
if (targetPanel >= fractal::maxFractalViews) {
92-
// If we already have the max number of views on the screen, steal the
93-
// existing fractal from the current view
94-
targetPanel = fractal::maxFractalViews - 1;
95-
if (auto ptr = panels[targetPanel].extract()) {
96-
cachedFractals.push_back(std::move(ptr));
93+
void FractalExplorer::instantiateFractalPanel(const fractal_id id, bool newPanel) {
94+
size_t targetPanel = panels.size();
95+
if (newPanel || panels.empty()) {
96+
if (targetPanel >= fractal::maxFractalViews) {
97+
targetPanel = fractal::maxFractalViews - 1;
98+
} else {
99+
panels.emplace_back();
97100
}
98-
} else {
99-
// Otherwise just create a new fractalViewer
101+
} else if (panels.empty()) {
100102
panels.emplace_back();
103+
} else {
104+
targetPanel--;
101105
}
102106

103-
auto it = locateCachedFractal(id);
104-
if (it != cachedFractals.end()) {
105-
panels[targetPanel].embed(std::move(*it));
106-
cachedFractals.erase(it);
107+
try {
108+
auto unique = Fractal::make_unique(
109+
fractal::fractalInfo[id]
110+
);
111+
panels[targetPanel].embed(std::move(unique));
107112
compilerGUI.clearCompileError();
108-
} else {
109-
try {
110-
auto unique = Fractal::make_unique(
111-
fractal::fractalInfo[id]
112-
);
113-
panels[targetPanel].embed(std::move(unique));
114-
compilerGUI.clearCompileError();
115-
} catch (...) {
116-
compilerGUI.reportCompileError();
117-
panels.pop_back();
118-
}
113+
} catch (...) {
114+
compilerGUI.reportCompileError();
115+
panels.pop_back();
119116
}
120117

121118
if (!panels.empty()) {
122119
std::println("{}", panels.back().checkHealth());
123120
}
124-
}
125-
126-
std::vector<std::unique_ptr<Fractal>>::iterator FractalExplorer::locateCachedFractal(fractal_id id) {
127-
auto targetName = fractal::fractalInfo[id].name;
128-
auto it = std::ranges::find_if(cachedFractals,
129-
[&](const auto& f) { return f->name == targetName; });
130-
return it;
131121
}

fractals/FractalExplorer.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ namespace gan {
1111
* Generates new fractals and handles the distribution of input to all fractals */
1212
class FractalExplorer {
1313
private:
14-
std::vector<std::unique_ptr<Fractal>> cachedFractals; ///< All compiled but unused fractals.
1514
std::vector<FractalPanel> panels; ///< All currently active views into fractals.
1615
FractalCompilerGUI compilerGUI;
1716
FractalCursor cursor;
1817

19-
void instantiateNewFractalPanel(fractal_id); ///< Creates a new fractalView from the compile window.
20-
std::vector<std::unique_ptr<Fractal>>::iterator locateCachedFractal(fractal_id);
18+
void instantiateFractalPanel(fractal_id, bool newPanel); ///< Creates a new fractalView from the compile window.
2119
public:
2220

2321
/** Displays all fractals and all relevant GUI interfaces */

fractals/gui-classes/FractalCompilerGUI.hpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,44 @@
99
namespace gan {
1010

1111
struct FractalCompilerGUI {
12-
int currentCompilerWindowItem{};
12+
int currentFractalSelection{};
1313
bool failedLastCompilation = false;
1414
std::string compilationFailureError;
1515

16+
enum displayResult {
17+
NO_RESULT ,
18+
NEW_FRACTAL_PANEL,
19+
INPLACE_FRACTAL
20+
};
21+
1622
/** Returns an index of the fractal to compile back to the FractalExplorer if there is something to compile.
1723
* -1 if there is nothing to compile.*/
18-
int display(const Window& window) {
19-
int ret = -1;
24+
displayResult display(const Window& window, const size_t num_fractal_panels) {
25+
displayResult ret = NO_RESULT;
2026
ImGui::Begin("Compiler", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove);
2127

22-
ImGui::Combo("##Compile", &currentCompilerWindowItem, fractal::fractalNames, fractal::totalFractalNum, 8);
23-
if (ImGui::Button("Compile")) {
24-
ret = currentCompilerWindowItem;
28+
ImGui::Combo("##Compile", &currentFractalSelection, fractal::fractalNames, fractal::totalFractalNum, 8);
29+
if (num_fractal_panels == 0) {
30+
if (ImGui::Button("Compile")) {
31+
ret = NEW_FRACTAL_PANEL;
32+
}
33+
} else {
34+
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.4f, 0.2f, 1.0f));
35+
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.3f, 0.7f, 0.3f, 1.0f));
36+
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.4f, 1.0f, 0.4f, 1.0f));
37+
if (ImGui::Button("Recompile")) {
38+
ret = INPLACE_FRACTAL;
39+
} ImGui::SameLine();
40+
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.4f, 0.4f, 1.0f));
41+
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.3f, 0.7f, 0.7f, 1.0f));
42+
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.4f, 1.0f, 1.0f, 1.0f));
43+
if (ImGui::Button("Compile New")) {
44+
ret = NEW_FRACTAL_PANEL;
45+
}
46+
ImGui::PopStyleColor(6);
2547
}
2648

27-
ImGui::SameLine();
28-
ImGui::Text("Hover For Help");
49+
ImGui::Text("> Hover For Help <");
2950
if (ImGui::IsItemHovered()) {
3051
ImGui::SetTooltip("Right-Click to move around fractal\n"
3152
"Scroll to Zoom in/out\n"

fractals/gui-classes/FractalCursor.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ namespace gan {
4848
vec2 nMousePos = window.normalizeToWindow(mouse.getPos());
4949
selectedFractal = findHoveredFractal(nMousePos, panels);
5050

51+
#ifndef __EMSCRIPTEN__
52+
constexpr float zoomAmount = -0.1f;
53+
#else
54+
constexpr float zoomAmount = -0.3f;
55+
#endif
56+
5157
if (selectedFractal != -1) {
5258
auto& panel = panels[selectedFractal];
5359

5460
float oldScale = panel.getScale();
55-
float zoomFactor = std::exp(mouse.getScrollWheelY() * -0.1f);
61+
float zoomFactor = std::exp(mouse.getScrollWheelY() * zoomAmount);
5662
float newScale = oldScale * zoomFactor;
5763
panel.setScale(newScale);
5864

0 commit comments

Comments
 (0)