Compare commits
5 commits
2810e06b3e
...
b0d5226915
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0d5226915 | ||
|
|
b3d06906ff | ||
|
|
3f2e6fdb4e | ||
|
|
c00750c95a | ||
|
|
b959afe8c2 |
17 changed files with 31454 additions and 29 deletions
206
.clang-format
206
.clang-format
|
|
@ -1,21 +1,55 @@
|
|||
# Generated from CLion C/C++ Code Style settings
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AlignTrailingComments:
|
||||
Kind: Always
|
||||
OverEmptyLines: 0
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakBeforeBraces: Custom
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BitFieldColonSpacing: Both
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
|
|
@ -23,44 +57,172 @@ BraceWrapping:
|
|||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakAfterAttributes: Never
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakArrays: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
ColumnLimit: 0
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 180
|
||||
CommentPragmas: "^ IWYU pragma:"
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: ^"(llvm|llvm-c|clang|clang-c)/
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: ^(<|"(gtest|gmock|isl|json)/)
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: .*
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: (Test)?$
|
||||
IncludeIsMainSourceRegex: ""
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: true
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: Indent
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: BeforeHash
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 2
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MaxEmptyLinesToKeep: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: true
|
||||
InsertNewlineAtEOF: true
|
||||
InsertTrailingCommas: None
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
BinaryMinDigits: 0
|
||||
Decimal: 0
|
||||
DecimalMinDigits: 0
|
||||
Hex: 0
|
||||
HexMinDigits: 0
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
LambdaBodyIndentation: Signature
|
||||
Language: Cpp
|
||||
LineEnding: DeriveLF
|
||||
MacroBlockBegin: ""
|
||||
MacroBlockEnd: ""
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: All
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PPIndentWidth: -1
|
||||
PackConstructorInitializers: CurrentLine
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Left
|
||||
ReflowComments: false
|
||||
QualifierAlignment: Custom
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: true
|
||||
RemoveBracesLLVM: false
|
||||
RemoveSemicolon: true
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Always
|
||||
ShortNamespaceLines: 1000
|
||||
SortIncludes: CaseSensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: LexicographicNumeric
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: false
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 0
|
||||
SpacesInAngles: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 2
|
||||
UseTab: Always
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- BOOST_PP_STRINGIZE
|
||||
- CF_SWIFT_NAME
|
||||
- NS_SWIFT_NAME
|
||||
- PP_STRINGIZE
|
||||
- STRINGIZE
|
||||
QualifierOrder:
|
||||
- inline
|
||||
- static
|
||||
- const
|
||||
- type
|
||||
|
|
|
|||
|
|
@ -25,3 +25,4 @@ add_subdirectory(Externals)
|
|||
add_subdirectory(Connection)
|
||||
add_subdirectory(Graphics)
|
||||
add_subdirectory(Objects)
|
||||
add_subdirectory(Chat)
|
||||
|
|
|
|||
33
Chat/CMakeLists.txt
Normal file
33
Chat/CMakeLists.txt
Normal file
|
|
@ -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)
|
||||
41
Chat/applications/ChatGUI.cpp
Normal file
41
Chat/applications/ChatGUI.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#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();
|
||||
}
|
||||
51
Chat/private/Chat.cpp
Normal file
51
Chat/private/Chat.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
#include "NewPlacement.hpp"
|
||||
|
||||
#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.pass, "1812") && String::Logic::isEqualLogic(credentials.name, "Igor");
|
||||
mChatsList = { "Serg", "Friends" };
|
||||
mChatHistories.put("Serg", { { "Serg", "Hello wanna some coke-cola?" }, { "Serg", "Will be in 5 mins" } });
|
||||
mChatHistories.put("Friends", { { "Artem", "Whos is that Serg?" }, { "Erog", "idunno" } });
|
||||
}
|
||||
|
||||
void ChatAPI::logout() {
|
||||
mLogged = false;
|
||||
mChatsList.removeAll();
|
||||
mChatHistories.removeAll();
|
||||
}
|
||||
|
||||
const ChatAPI::ChatsList* ChatAPI::getChatsList() const {
|
||||
return mLogged ? &mChatsList : nullptr;
|
||||
}
|
||||
|
||||
const ChatAPI::ChatHistory* ChatAPI::getChatHistory(const String& chatName) const {
|
||||
if (!mLogged) return nullptr;
|
||||
|
||||
auto history = mChatHistories.presents(chatName);
|
||||
return history ? &mChatHistories.getSlotVal(history) : nullptr;
|
||||
}
|
||||
|
||||
void ChatAPI::send(const String& chatName, const Message& message) {
|
||||
if (!mLogged) return;
|
||||
|
||||
auto iter = mChatHistories.presents(chatName);
|
||||
auto history = iter ? &mChatHistories.getSlotVal(iter) : nullptr;
|
||||
|
||||
if (!history) return;
|
||||
|
||||
history->pushBack(message);
|
||||
}
|
||||
89
Chat/private/ClientGUI.cpp
Normal file
89
Chat/private/ClientGUI.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
|
||||
#include "ClientGui.hpp"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
|
||||
using namespace tp;
|
||||
using namespace ImGui;
|
||||
|
||||
void ClientGUI::draw(ChatAPI& api) {
|
||||
DockSpaceOverViewport(GetWindowViewport());
|
||||
|
||||
if (api.isLogged()) {
|
||||
drawChat(api);
|
||||
|
||||
} else {
|
||||
if (Begin("Authentication")) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientGUI::drawChat(tp::ChatAPI& api) {
|
||||
if (Begin("Chats")) {
|
||||
if (Button("Logout", {GetContentRegionAvail().x, 0})) {
|
||||
api.logout();
|
||||
mCredentials.pass[0] = 0;
|
||||
mActiveChatName = "Not Selected";
|
||||
}
|
||||
|
||||
if (BeginListBox("##chats", GetContentRegionAvail())) {
|
||||
auto chats = api.getChatsList();
|
||||
if (chats) {
|
||||
for (auto user : *chats) {
|
||||
if (Selectable(user->read())) {
|
||||
mActiveChatName = user.data();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text("Error");
|
||||
}
|
||||
|
||||
EndListBox();
|
||||
}
|
||||
}
|
||||
End();
|
||||
|
||||
if (Begin("History")) {
|
||||
Text("%s", mActiveChatName.read());
|
||||
|
||||
auto history = api.getChatHistory(mActiveChatName);
|
||||
|
||||
if (history) {
|
||||
if (BeginListBox("##History", GetContentRegionAvail())) {
|
||||
for (auto message : *history) {
|
||||
Text("%s : %s", message->user.read(), message->text.read());
|
||||
Separator();
|
||||
}
|
||||
}
|
||||
|
||||
EndListBox();
|
||||
} else {
|
||||
Text("No History");
|
||||
}
|
||||
}
|
||||
End();
|
||||
|
||||
if (Begin("Message")) {
|
||||
if (Button("Send")) {
|
||||
if (String::Logic::calcLength(mMessageBuff) > 0) {
|
||||
api.send(mActiveChatName, {mCredentials.name, mMessageBuff});
|
||||
}
|
||||
mMessageBuff[0] = 0;
|
||||
}
|
||||
|
||||
InputTextMultiline("##Message", mMessageBuff, MESSAGE_SIZE, GetContentRegionAvail());
|
||||
}
|
||||
End();
|
||||
}
|
||||
45
Chat/public/Chat.hpp
Normal file
45
Chat/public/Chat.hpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include "Strings.hpp"
|
||||
#include "Map.hpp"
|
||||
#include "List.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
||||
extern ModuleManifest gModuleChat;
|
||||
|
||||
class ChatAPI {
|
||||
public:
|
||||
struct Credentials {
|
||||
enum { SIZE = 64 };
|
||||
tp::int1 name[SIZE] {0};
|
||||
tp::int1 pass[SIZE] {0};
|
||||
};
|
||||
|
||||
typedef List<String> ChatsList;
|
||||
|
||||
struct Message {
|
||||
String user;
|
||||
String text;
|
||||
};
|
||||
|
||||
typedef List<Message> ChatHistory;
|
||||
|
||||
public:
|
||||
ChatAPI() = default;
|
||||
[[nodiscard]] bool isLogged() const;
|
||||
void login(const Credentials& credentials);
|
||||
[[nodiscard]] const ChatsList* getChatsList() const;
|
||||
[[nodiscard]] const ChatHistory* getChatHistory(const String& chatName) const;
|
||||
void logout();
|
||||
void send(const String& chatName, const Message& message);
|
||||
|
||||
private:
|
||||
bool mLogged = false;
|
||||
Credentials mCredentials;
|
||||
ChatsList mChatsList;
|
||||
|
||||
Map<String, ChatHistory> mChatHistories;
|
||||
};
|
||||
}
|
||||
|
||||
20
Chat/public/ClientGui.hpp
Normal file
20
Chat/public/ClientGui.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "Chat.hpp"
|
||||
|
||||
namespace tp {
|
||||
class ClientGUI {
|
||||
enum { MESSAGE_SIZE = 1024 };
|
||||
ChatAPI::Credentials mCredentials;
|
||||
bool mInvalidCredentials = false;
|
||||
char mMessageBuff[1000] {0};
|
||||
String mActiveChatName = "Not Selected";
|
||||
|
||||
public:
|
||||
ClientGUI() = default;
|
||||
void draw(ChatAPI& api);
|
||||
|
||||
private:
|
||||
void drawChat(ChatAPI& api);
|
||||
};
|
||||
}
|
||||
4
Chat/tests/Tests.cpp
Normal file
4
Chat/tests/Tests.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
int main () {
|
||||
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ int main() {
|
|||
while (!window->shouldClose()) {
|
||||
window->processEvents();
|
||||
|
||||
ImGui::Text("Hello!");
|
||||
window->getGraphics().getDebugGui().drawDebugInfoWindow();
|
||||
|
||||
window->draw();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "Window.hpp"
|
||||
|
||||
#include "Timing.hpp"
|
||||
|
||||
#include "WindowContext.hpp"
|
||||
|
||||
// -------- Debug UI -------- //
|
||||
|
|
@ -7,11 +9,21 @@
|
|||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
|
||||
#include "DefaultFont.bin"
|
||||
|
||||
namespace tp {
|
||||
class Graphics::GUI::Context {
|
||||
public:
|
||||
ImGuiIO* io{};
|
||||
ImGuiContext* ctx{};
|
||||
|
||||
halnf dpmm = 3;
|
||||
halnf uiScale = 1;
|
||||
halnf fontSizeMM = 2.55f;
|
||||
|
||||
Timer timer = Timer(1000);
|
||||
ualni fps {};
|
||||
ualni frames = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -27,12 +39,19 @@ Graphics::GUI::~GUI() {
|
|||
|
||||
void Graphics::GUI::init(Window* window) {
|
||||
IMGUI_CHECKVERSION();
|
||||
|
||||
mContext->ctx = ImGui::CreateContext();
|
||||
mContext->io = &ImGui::GetIO();
|
||||
|
||||
mContext->io->ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
|
||||
// Initialize ImGui with GLFW and OpenGL
|
||||
ImGui_ImplGlfw_InitForOpenGL(window->getContext()->window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
|
||||
mContext->dpmm = (window->getMonitor().pixelSize.x / window->getMonitor().mmSize.x);
|
||||
|
||||
setStyle();
|
||||
}
|
||||
|
||||
void Graphics::GUI::deinit() {
|
||||
|
|
@ -50,12 +69,210 @@ void Graphics::GUI::proc() {
|
|||
|
||||
tp::HeapAllocGlobal::stopIgnore();
|
||||
|
||||
// ImGui code goes here
|
||||
ImGui::Begin("Window");
|
||||
ImGui::End();
|
||||
// ImGui::DockSpaceOverViewport(NULL, ImGuiDockNodeFlags_PassthruCentralNode);
|
||||
}
|
||||
|
||||
void Graphics::GUI::draw() {
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
mContext->frames++;
|
||||
|
||||
if (mContext->timer.isTimeout()) {
|
||||
mContext->fps = mContext->frames;
|
||||
mContext->frames = 0;
|
||||
mContext->timer.reset();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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");
|
||||
|
||||
ImGui::Text("FPS : %llu", mContext->fps);
|
||||
|
||||
ImGui::SliderFloat("UI Scale", &mContext->uiScale, 0, 10);
|
||||
ImGui::SliderFloat("Font Size MM", &mContext->fontSizeMM, 3, 20);
|
||||
ImGui::SliderFloat("DPMM", &mContext->dpmm, 2, 10);
|
||||
|
||||
setStyle();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void Graphics::GUI::setStyle() {
|
||||
auto dpmm = mContext->dpmm;
|
||||
auto font_size_mm = mContext->fontSizeMM;
|
||||
auto ui_scale = mContext->uiScale;
|
||||
|
||||
#define VAL(val) (val * dpmm * ui_scale)
|
||||
#define VEC(x, y) ImVec2(x * dpmm, y * dpmm * ui_scale)
|
||||
|
||||
ImGuiStyle* style = &ImGui::GetStyle();
|
||||
auto& io = *mContext->io;
|
||||
bool first_init = io.Fonts->Fonts.Size == 0;
|
||||
auto font_path = ".";
|
||||
//auto font_path = getFontPath();
|
||||
|
||||
// supports PDMM from 0.3 to 10
|
||||
const float min_dpmm = 0.3f;
|
||||
const float max_dpmm = 20.f;
|
||||
dpmm = tp::clamp(dpmm, min_dpmm, max_dpmm);
|
||||
|
||||
// calc font
|
||||
const float font_size_mm_max = 10;
|
||||
const float font_size_pixels_min = 9;
|
||||
float font_size_mm_min = font_size_pixels_min / dpmm;
|
||||
const int font_quality_steps = 3;
|
||||
font_size_mm = tp::clamp(font_size_mm, font_size_mm_min, font_size_mm_max);
|
||||
|
||||
float font_sizes[font_quality_steps];
|
||||
for (auto i = 0; i < font_quality_steps; i++) {
|
||||
auto mm = font_size_mm_min + (font_size_mm_max - font_size_mm_min) * tp::pow(((tp::halnf) (i + 1) / font_quality_steps), 3);
|
||||
font_sizes[i] = dpmm * mm;
|
||||
}
|
||||
|
||||
if (first_init) {
|
||||
for (auto i = 0; i < font_quality_steps; i++) {
|
||||
//io.Fonts->AddFontFromFileTTF(font_path, font_sizes[i] * 1);
|
||||
ImFontConfig font_cfg_template;
|
||||
font_cfg_template.FontDataOwnedByAtlas = false;
|
||||
io.Fonts->AddFontFromMemoryTTF(CONSOLAB_TTF, CONSOLAB_TTF_len, font_sizes[i] * 1, &font_cfg_template);
|
||||
}
|
||||
}
|
||||
|
||||
// select fonts
|
||||
auto const pixels_required = dpmm * font_size_mm;
|
||||
auto idx = -1;
|
||||
for (auto i = 0; i < font_quality_steps; i++) {
|
||||
idx = i;
|
||||
if (pixels_required <= font_sizes[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
io.FontDefault = io.Fonts->Fonts[idx];
|
||||
io.FontGlobalScale = font_size_mm / (font_size_mm_min + ((font_size_mm_max - font_size_mm_min) / font_quality_steps) * (idx + 1));
|
||||
io.FontGlobalScale = pixels_required / font_sizes[idx];
|
||||
|
||||
auto rounding = VAL(1);
|
||||
auto pudding = VEC(1, 1);
|
||||
|
||||
// style->WindowPadding = pudding;
|
||||
style->WindowRounding = rounding;
|
||||
//style->WindowMinSize = VEC(11, 11);
|
||||
style->ChildRounding = rounding;
|
||||
style->PopupRounding = rounding;
|
||||
style->FramePadding = pudding;
|
||||
style->FrameRounding = rounding;
|
||||
style->ItemSpacing = VEC(1, 2);
|
||||
style->ItemInnerSpacing = VEC(1, 1);
|
||||
style->CellPadding = pudding;
|
||||
style->TouchExtraPadding = pudding;
|
||||
style->IndentSpacing = VAL(3);
|
||||
style->ColumnsMinSpacing = VAL(1.2);
|
||||
style->ScrollbarSize = VAL(5);
|
||||
style->ScrollbarRounding = rounding;
|
||||
style->GrabMinSize = VAL(0.6);
|
||||
style->GrabRounding = rounding;
|
||||
style->LogSliderDeadzone = VAL(0.6);
|
||||
style->TabRounding = rounding;
|
||||
style->TabMinWidthForCloseButton = VAL(1.3);
|
||||
style->DisplayWindowPadding = pudding;
|
||||
style->DisplaySafeAreaPadding = pudding;
|
||||
// style->MouseCursorScale = VAL(1.3);
|
||||
|
||||
// style->FrameBorderSize = VAL(0);
|
||||
style->WindowBorderSize = VAL(0.5);
|
||||
style->ChildBorderSize = VAL(0.6);
|
||||
|
||||
// style->WindowTitleAlign = VEC(0.1f, 0.2f);
|
||||
style->WindowMenuButtonPosition = ImGuiDir_Right;
|
||||
|
||||
if (!first_init)
|
||||
return;
|
||||
|
||||
ImVec4* colors = ImGui::GetStyle().Colors;
|
||||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.09f, 0.09f, 0.10f, 1.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.10f, 1.00f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.14f, 0.14f, 0.17f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.27f, 0.27f, 0.33f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.43f, 0.43f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.09f, 0.09f, 0.10f, 0.00f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.15f, 0.15f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.21f, 0.20f, 0.25f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.30f, 0.29f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.48f, 0.50f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.53f, 0.57f, 0.64f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.69f, 0.74f, 0.83f, 1.00f);
|
||||
colors[ImGuiCol_Button] = ImVec4(0.14f, 0.14f, 0.17f, 1.00f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.27f, 0.27f, 0.33f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.43f, 0.43f, 0.53f, 1.00f);
|
||||
colors[ImGuiCol_Header] = ImVec4(0.14f, 0.14f, 0.17f, 1.00f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.27f, 0.27f, 0.33f, 1.00f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.33f, 0.33f, 0.40f, 1.00f);
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.37f, 0.37f, 0.40f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.33f, 0.35f, 0.38f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.37f, 0.39f, 0.42f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.16f, 0.17f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.33f, 0.35f, 0.38f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.28f, 0.34f, 0.42f, 1.00f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.14f, 0.14f, 0.17f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.23f, 0.23f, 0.28f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.23f, 0.23f, 0.28f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.11f, 0.15f, 0.17f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.43f, 0.45f, 0.48f, 1.00f);
|
||||
colors[ImGuiCol_DockingPreview] = ImVec4(0.81f, 0.81f, 0.81f, 0.18f);
|
||||
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.10f, 0.10f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.33f, 0.35f, 0.38f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.49f, 0.51f, 0.54f, 1.00f);
|
||||
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.13f, 0.13f, 0.20f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
|
||||
colors[ImGuiCol_TableRowBg] = ImVec4(0.23f, 0.20f, 0.20f, 0.00f);
|
||||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
||||
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.38f, 0.22f, 0.22f, 0.20f);
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.10f, 1.00f);
|
||||
colors[ImGuiCol_DockingPreview] = ImVec4(0.64f, 0.75f, 0.83f, 0.18f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.39f, 0.39f, 0.47f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.27f, 0.27f, 0.33f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.14f, 0.14f, 0.17f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.24f, 0.24f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.65f, 0.65f, 0.65f, 0.70f);
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
}
|
||||
30730
Graphics/private/bindings/DefaultFont.bin
Normal file
30730
Graphics/private/bindings/DefaultFont.bin
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -101,6 +101,16 @@ Window::Window(int width, int height, const char* title) {
|
|||
return;
|
||||
}
|
||||
|
||||
// get some common information. maybe call it in loop to pick up monitor changes
|
||||
int width_mm, height_mm;
|
||||
auto monitor = glfwGetPrimaryMonitor();
|
||||
glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
|
||||
mMonitor.mmSize = { width_mm, height_mm };
|
||||
|
||||
const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
mMonitor.pixelSize = { mode->width, mode->height };
|
||||
mMonitor.refreshRate = mode->refreshRate;
|
||||
|
||||
mGraphics.init(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,17 @@ namespace tp {
|
|||
void proc();
|
||||
void draw();
|
||||
|
||||
void setStyle();
|
||||
|
||||
public:
|
||||
// TODO : API
|
||||
void drawDebugInfoWindow();
|
||||
|
||||
halnf getFontSize() const;
|
||||
halnf getUIScale() const;
|
||||
|
||||
void setDPMM(ualni);
|
||||
void setFontSize(ualni);
|
||||
void setUIScale(ualni);
|
||||
};
|
||||
|
||||
class Canvas {
|
||||
|
|
@ -69,6 +78,9 @@ namespace tp {
|
|||
void draw();
|
||||
void proc();
|
||||
|
||||
public:
|
||||
GUI& getDebugGui() { return mGui; }
|
||||
|
||||
private:
|
||||
GUI mGui;
|
||||
GL mGl;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,12 @@ namespace tp {
|
|||
};
|
||||
};
|
||||
|
||||
struct Monitor {
|
||||
ualni refreshRate = 60;
|
||||
Vec2F pixelSize;
|
||||
Vec2F mmSize;
|
||||
};
|
||||
|
||||
private:
|
||||
Window(int width, int height, const char* title);
|
||||
~Window();
|
||||
|
|
@ -33,10 +39,14 @@ namespace tp {
|
|||
|
||||
auto getContext() -> Context*;
|
||||
|
||||
Graphics& getGraphics() { return mGraphics; }
|
||||
|
||||
[[nodiscard]] const Monitor& getMonitor() const { return mMonitor; }
|
||||
|
||||
private:
|
||||
Context* mContext;
|
||||
Graphics mGraphics;
|
||||
|
||||
Buffer<Event> mEvents;
|
||||
Monitor mMonitor;
|
||||
};
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ namespace tp {
|
|||
// Creates new string data from raw data pointer.
|
||||
// Does not own string buffer - string buffer will not be freed. Initializes as const memory.
|
||||
StringTemplate(const tChar* raw) {
|
||||
mData = new (sStringPool.allocate(0)) StringData(raw, true);
|
||||
mData = new (sStringPool.allocate(0)) StringData(raw, true);
|
||||
incReference(mData);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue