Skip to content

Commit d82b258

Browse files
author
MHDtA-dev
committed
Initial commit
0 parents  commit d82b258

291 files changed

Lines changed: 141120 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
project(LogiGates)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
6+
include(FetchContent)
7+
8+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/fonts DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
9+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Resources/icons DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
10+
11+
FetchContent_Declare(
12+
webgpu
13+
GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution
14+
GIT_TAG wgpu
15+
)
16+
FetchContent_MakeAvailable(webgpu)
17+
18+
find_package(SDL2 REQUIRED)
19+
20+
include_directories(${SDL2_INCLUDE_DIRS})
21+
add_subdirectory(thirdparty/sdl2webgpu)
22+
23+
add_executable(LogiGates main.cpp
24+
UI/Window.cpp
25+
UI/Window.h
26+
Core/App.cpp
27+
Core/App.h
28+
UI/Renderer.cpp
29+
UI/Renderer.h
30+
UI/imgui/Drawable.cpp
31+
UI/imgui/Drawable.h
32+
UI/imgui/Dockspace.cpp
33+
UI/imgui/Dockspace.h
34+
UI/UI.h
35+
UI/imgui/ElementsMenu.cpp
36+
UI/imgui/ElementsMenu.h
37+
UI/Fonts.cpp
38+
UI/Fonts.h
39+
UI/imgui/Workspace.cpp
40+
UI/imgui/Workspace.h
41+
Core/LogicalElements/Base.cpp
42+
Core/LogicalElements/Base.h
43+
Core/Pin.cpp
44+
Core/Pin.h
45+
Core/LogicalElements/And.cpp
46+
Core/LogicalElements/And.h
47+
UI/Images.cpp
48+
UI/Images.h
49+
Core/LogicalElements/LogicalElements.h
50+
Core/LogicalElements/Or.cpp
51+
Core/LogicalElements/Or.h
52+
Core/LogicalElements/Not.cpp
53+
Core/LogicalElements/Not.h
54+
Core/LogicalElements/Xor.cpp
55+
Core/LogicalElements/Xor.h
56+
Core/LogicalElements/Lamp.cpp
57+
Core/LogicalElements/Lamp.h
58+
Core/LogicalElements/Switch.cpp
59+
Core/LogicalElements/Switch.h
60+
Core/LogicalElements/Implication.cpp
61+
Core/LogicalElements/Implication.h
62+
Core/LogicalElements/Splitter.cpp
63+
Core/LogicalElements/Splitter.h
64+
UI/imgui/PreferencesWindow.cpp
65+
UI/imgui/PreferencesWindow.h
66+
UI/Localization.cpp
67+
UI/Localization.h
68+
Core/LogicalElements/Equivalent.cpp
69+
Core/LogicalElements/Equivalent.h
70+
Core/LogicalElements/FiveBitNumberEncoder.cpp
71+
Core/LogicalElements/FiveBitNumberEncoder.h
72+
thirdparty/DecToBase.h
73+
UI/imgui/AboutWindow.cpp
74+
UI/imgui/AboutWindow.h
75+
Core/LogicalElements/FiveBitNumberDisplay.cpp
76+
Core/LogicalElements/FiveBitNumberDisplay.h)
77+
78+
79+
target_sources(LogiGates PRIVATE
80+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui.h"
81+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui.cpp"
82+
83+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_draw.cpp"
84+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_demo.cpp"
85+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_widgets.cpp"
86+
87+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_internal.h"
88+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_tables.cpp"
89+
90+
91+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_impl_wgpu.h"
92+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_impl_wgpu.cpp"
93+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imgui/imgui_impl_sdl2.cpp"
94+
95+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imnodes/imnodes.h"
96+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imnodes/imnodes_internal.h"
97+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/imnodes/imnodes.cpp"
98+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/stb_image.h"
99+
100+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/tinyfiledialogs/tinyfiledialogs.h"
101+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/tinyfiledialogs/tinyfiledialogs.c"
102+
103+
"${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/lunada/lunada.h"
104+
105+
)
106+
107+
target_link_libraries(LogiGates webgpu ${SDL2_LIBRARIES} sdl2webgpu)
108+
target_copy_webgpu_binaries(LogiGates)

Core/App.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright (C) 2024 Alexander Blinov
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include "App.h"
18+
19+
namespace LogiGates::Core {
20+
21+
App::App() {
22+
window = new UI::Window("LogiGates");
23+
renderer = new UI::Renderer(window);
24+
25+
UI::Images::load(renderer);
26+
27+
workspace = new UI::Workspace();
28+
dockspace = new UI::Dockspace(workspace);
29+
elementsMenu = new UI::ElementsMenu();
30+
31+
UI::Localization::init();
32+
33+
}
34+
35+
void App::run() {
36+
while (!this->window->shouldClose()) {
37+
window->pollEvents([] (SDL_Event e) {
38+
ImGui_ImplSDL2_ProcessEvent(&e);
39+
});
40+
41+
if (renderer->begin()) {
42+
43+
dockspace->render();
44+
elementsMenu->render();
45+
workspace->render();
46+
47+
renderer->end();
48+
}
49+
}
50+
}
51+
52+
App::~App() {
53+
delete window;
54+
delete renderer;
55+
delete dockspace;
56+
delete elementsMenu;
57+
}
58+
59+
}

Core/App.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright (C) 2024 Alexander Blinov
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef LOGIGATES_APP_H
18+
#define LOGIGATES_APP_H
19+
20+
#include <iostream>
21+
#include "../thirdparty/imgui/imgui_impl_sdl2.h"
22+
23+
#include "../UI/UI.h"
24+
#include "LogicalElements/And.h"
25+
26+
#include "../UI/Localization.h"
27+
28+
namespace LogiGates::Core {
29+
30+
class App {
31+
public:
32+
App();
33+
~App();
34+
35+
void run();
36+
37+
private:
38+
UI::Window* window;
39+
UI::Renderer* renderer;
40+
41+
UI::Dockspace* dockspace;
42+
UI::ElementsMenu* elementsMenu;
43+
UI::Workspace* workspace;
44+
};
45+
46+
47+
}
48+
49+
#endif //LOGIGATES_APP_H

Core/LogicalElements/And.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright (C) 2024 Alexander Blinov
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#include "And.h"
18+
#include "../../UI/imgui/Workspace.h"
19+
20+
namespace LogiGates::Core::LogicalElements {
21+
22+
And::And(UI::Workspace* workspace) : Base(workspace) {
23+
this->typeName = "and";
24+
25+
pins.push_back(new Pin(this, PinType::INPUT, "A"));
26+
pins.push_back(new Pin(this, PinType::INPUT, UI::Localization::localization[UI::Localization::currentLocalization]["b"]));
27+
pins.push_back(new Pin(this, PinType::OUTPUT, "A " + UI::Localization::localization[UI::Localization::currentLocalization]["and"] + " " + UI::Localization::localization[UI::Localization::currentLocalization]["b"]));
28+
}
29+
30+
void And::render() {
31+
ImNodes::BeginNode(id);
32+
ImGui::Image((ImTextureID) UI::Images::icons["and"]->texture, {70, 70});
33+
34+
for (Pin* p : pins) {
35+
p->render();
36+
}
37+
38+
ImNodes::EndNode();
39+
}
40+
41+
void And::perform() {
42+
if (pins[0]->getConnectedWith() != -1) pins[0]->setState(Pin::globalPinMap[pins[0]->getConnectedWith()]->getState());
43+
if (pins[1]->getConnectedWith() != -1) pins[1]->setState(Pin::globalPinMap[pins[1]->getConnectedWith()]->getState());
44+
pins[2]->setState(pins[0]->getState() and pins[1]->getState());
45+
pins[2]->performNext();
46+
}
47+
48+
49+
}

Core/LogicalElements/And.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright (C) 2024 Alexander Blinov
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
#ifndef LOGIGATES_AND_H
18+
#define LOGIGATES_AND_H
19+
20+
#include <iostream>
21+
#include "Base.h"
22+
#include "../../UI/Images.h"
23+
24+
namespace LogiGates::Core::LogicalElements {
25+
26+
class And : public Base {
27+
public:
28+
And(UI::Workspace* workspace);
29+
30+
void render() override;
31+
void perform() override;
32+
};
33+
34+
}
35+
36+
37+
#endif //LOGIGATES_AND_H

0 commit comments

Comments
 (0)