diff --git a/CMakeLists.txt b/CMakeLists.txt index 1937060..1a59c21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,3 +25,4 @@ add_subdirectory(Externals) add_subdirectory(Connection) add_subdirectory(Graphics) add_subdirectory(Objects) +add_subdirectory(Chat) diff --git a/Chat/CMakeLists.txt b/Chat/CMakeLists.txt new file mode 100644 index 0000000..c3947c1 --- /dev/null +++ b/Chat/CMakeLists.txt @@ -0,0 +1,33 @@ + +cmake_minimum_required(VERSION 3.2) + +set(CMAKE_CXX_STANDARD 23) + +project(Chat) + +### ---------------------- Externals --------------------- ### +set(BINDINGS_INCLUDE ${EXTERNALS}/glfw/include ${EXTERNALS}/glew/include) +set(BINDINGS_LIBS glfw glew_s Imgui Nanovg) + +### ---------------------- Static Library --------------------- ### +file(GLOB SOURCES "./private/*.cpp" "./private/*/*.cpp") +file(GLOB HEADERS "./public/*.hpp") +add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) +target_include_directories(${PROJECT_NAME} PUBLIC ./public/) +target_include_directories(${PROJECT_NAME} PRIVATE ${BINDINGS_INCLUDE}) +target_link_libraries(${PROJECT_NAME} PUBLIC Graphics Connection) +target_link_libraries(${PROJECT_NAME} PRIVATE ${BINDINGS_LIBS}) + +### -------------------------- Examples -------------------------- ### +add_executable(ChatGUI applications/ChatGUI.cpp) +target_link_libraries(ChatGUI ${PROJECT_NAME} ${BINDINGS_LIBS}) +target_include_directories(ChatGUI PRIVATE ${BINDINGS_INCLUDE}) + +### -------------------------- Tests -------------------------- ### +enable_testing() +file(GLOB TEST_SOURCES "./tests/*.cpp") +add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES}) +target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} Utils) +add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests) + +install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/lib) \ No newline at end of file diff --git a/Chat/applications/ChatGUI.cpp b/Chat/applications/ChatGUI.cpp new file mode 100644 index 0000000..305dee1 --- /dev/null +++ b/Chat/applications/ChatGUI.cpp @@ -0,0 +1,39 @@ + +#include "ClientGui.hpp" +#include "Window.hpp" + +using namespace tp; + +int main() { + + ModuleManifest* deps[] = { &tp::gModuleChat, nullptr }; + ModuleManifest testModule("ClientGUI", nullptr, nullptr, deps); + + if (!testModule.initialize()) { + return 1; + } + + { + ChatAPI chat; + ClientGUI gui; + + auto window = Window::createWindow(1000, 700, "Window 1"); + + if (window) { + + window->getGraphics().getDebugGui().setFontSize(4); + + while (!window->shouldClose()) { + window->processEvents(); + + gui.draw(chat); + + window->draw(); + } + } + + Window::destroyWindow(window); + } + + testModule.deinitialize(); +} diff --git a/Chat/private/Chat.cpp b/Chat/private/Chat.cpp new file mode 100644 index 0000000..52fd26b --- /dev/null +++ b/Chat/private/Chat.cpp @@ -0,0 +1,18 @@ + +#include "Chat.hpp" + +#include "Graphics.hpp" + +using namespace tp; + +static ModuleManifest* deps[] = { &gModuleGraphics, nullptr }; + +ModuleManifest tp::gModuleChat = ModuleManifest("Chat", nullptr, nullptr, deps ); + +bool ChatAPI::isLogged() const { + return mLogged; +} + +void ChatAPI::login(const Credentials& credentials) { + mLogged = String::Logic::isEqualLogic(credentials.name, "111"); +} \ No newline at end of file diff --git a/Chat/private/ClientGUI.cpp b/Chat/private/ClientGUI.cpp new file mode 100644 index 0000000..c30755b --- /dev/null +++ b/Chat/private/ClientGUI.cpp @@ -0,0 +1,46 @@ + +#include "ClientGui.hpp" +#include "imgui.h" + +using namespace tp; +using namespace ImGui; + +void ClientGUI::draw(ChatAPI& api) { + + if (Begin("window_name")) { + + if (api.isLogged()) { + + static int item_current1 = 0; + const char *items1[] = {"Never", "Gonna", "Give", "You", "Up"}; + Combo("User", &item_current1, items1, IM_ARRAYSIZE(items1)); + + BeginListBox("History"); + Text("as"); + Text("asa"); + EndListBox(); + + static char buff[1000]; + InputTextMultiline("Message", buff, 1000); + + if (Button("Send")) { + + } + + } else { + + InputText("Name", mCredentials.name, ChatAPI::Credentials::SIZE); + InputText("Pass", mCredentials.pass, ChatAPI::Credentials::SIZE); + + if (mInvalidCredentials) { + Text("Invalid Credentials"); + } + + if (Button("Login")) { + api.login(mCredentials); + mInvalidCredentials = !api.isLogged(); + } + } + + } End(); +} \ No newline at end of file diff --git a/Chat/public/Chat.hpp b/Chat/public/Chat.hpp new file mode 100644 index 0000000..f76b0a4 --- /dev/null +++ b/Chat/public/Chat.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include "Module.hpp" + +namespace tp { + + extern ModuleManifest gModuleChat; + + class ChatAPI { + public: + struct Credentials { + enum { SIZE = 64 }; + tp::int1 name[SIZE] {0}; + tp::int1 pass[SIZE] {0}; + }; + + public: + ChatAPI() = default; + [[nodiscard]] bool isLogged() const; + void login(const Credentials& credentials); + + private: + bool mLogged = false; + Credentials mCredentials; + }; +} + diff --git a/Chat/public/ClientGui.hpp b/Chat/public/ClientGui.hpp new file mode 100644 index 0000000..189fdb0 --- /dev/null +++ b/Chat/public/ClientGui.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "Chat.hpp" + +namespace tp { + class ClientGUI { + ChatAPI::Credentials mCredentials; + bool mInvalidCredentials = false; + public: + ClientGUI() = default; + void draw(ChatAPI& api); + }; +} \ No newline at end of file diff --git a/Chat/tests/Tests.cpp b/Chat/tests/Tests.cpp new file mode 100644 index 0000000..ab1ae89 --- /dev/null +++ b/Chat/tests/Tests.cpp @@ -0,0 +1,4 @@ + +int main () { + +} \ No newline at end of file diff --git a/Graphics/private/bindings/DebugGUI.cpp b/Graphics/private/bindings/DebugGUI.cpp index c8c7fc4..4fb6718 100644 --- a/Graphics/private/bindings/DebugGUI.cpp +++ b/Graphics/private/bindings/DebugGUI.cpp @@ -88,9 +88,20 @@ void Graphics::GUI::draw() { halnf Graphics::GUI::getFontSize() const { return mContext->fontSizeMM; } halnf Graphics::GUI::getUIScale() const { return mContext->uiScale; } -void Graphics::GUI::setDPMM(ualni dpmm) { mContext->dpmm = dpmm; } -void Graphics::GUI::setFontSize(ualni size) { mContext->fontSizeMM = size; } -void Graphics::GUI::setUIScale(ualni scale) { mContext->uiScale = scale; } +void Graphics::GUI::setDPMM(ualni dpmm) { + mContext->dpmm = dpmm; + setStyle(); +} + +void Graphics::GUI::setFontSize(ualni size) { + mContext->fontSizeMM = size; + setStyle(); +} + +void Graphics::GUI::setUIScale(ualni scale) { + mContext->uiScale = scale; + setStyle(); +} void Graphics::GUI::drawDebugInfoWindow() { ImGui::Begin("Debug Info");