From 6b4c5e9179dd14f61f574ce8b4b3a0d97c920c2f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Fri, 7 Apr 2023 23:06:08 -0500 Subject: [PATCH] feat(console): initialize console screen --- src/client/Client.cpp | 3 ++- src/console/CMakeLists.txt | 1 + src/console/Screen.cpp | 55 ++++++++++++++++++++++++++++++++++++++ src/console/Screen.hpp | 6 +++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/console/Screen.cpp create mode 100644 src/console/Screen.hpp diff --git a/src/client/Client.cpp b/src/client/Client.cpp index f3918cf..8d423b7 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -4,6 +4,7 @@ #include "console/CVar.hpp" #include "console/Client.hpp" #include "console/Device.hpp" +#include "console/Screen.hpp" #include "db/Db.hpp" #include "glue/CGlueMgr.hpp" #include "gx/Screen.hpp" @@ -72,7 +73,7 @@ int32_t InitializeEngineCallback(const void* a1, void* a2) { // } ScrnInitialize(0); - // ConsoleScreenInitialize(a2); + ConsoleScreenInitialize(nullptr); // TODO argument // s_cvarTextureFilteringMode = CVar::Register( // "textureFilteringMode", diff --git a/src/console/CMakeLists.txt b/src/console/CMakeLists.txt index e4c6af1..5c38523 100644 --- a/src/console/CMakeLists.txt +++ b/src/console/CMakeLists.txt @@ -14,6 +14,7 @@ target_include_directories(console target_link_libraries(console PUBLIC common + gx storm PRIVATE client diff --git a/src/console/Screen.cpp b/src/console/Screen.cpp new file mode 100644 index 0000000..dd93622 --- /dev/null +++ b/src/console/Screen.cpp @@ -0,0 +1,55 @@ +#include "console/Screen.hpp" +#include "gx/Coordinate.hpp" +#include "gx/Font.hpp" +#include "gx/Gx.hpp" +#include "gx/Screen.hpp" +#include +#include + +static CGxStringBatch* s_batch; +static float s_caretpixwidth; +static float s_caretpixheight; +static float s_fontHeight = 0.02f; +static char s_fontName[STORM_MAX_PATH]; +static HLAYER s_layerBackground; +static HLAYER s_layerText; +static RECTF s_rect = { 0.0f, 1.0f, 1.0f, 1.0f }; +static HTEXTFONT s_textFont; + +void PaintBackground(void* param, const RECTF* rect, const RECTF* visible, float elapsedSec) { + // TODO +} + +void PaintText(void* param, const RECTF* rect, const RECTF* visible, float elapsedSec) { + // TODO +} + +void RegisterHandlers() { + // TODO +} + +void ConsoleScreenInitialize(const char* title) { + CRect windowSize; + GxCapsWindowSize(windowSize); + + auto width = windowSize.maxX - windowSize.minX; + auto height = windowSize.maxY - windowSize.minY; + s_caretpixwidth = width == 0.0f ? 1.0f : 1.0f / width; + s_caretpixheight = height == 0.0f ? 1.0f : 1.0f / height; + + SStrCopy(s_fontName, "Fonts\\ARIALN.ttf", sizeof(s_fontName)); + s_textFont = TextBlockGenerateFont(s_fontName, 0, NDCToDDCHeight(s_fontHeight)); + + ScrnLayerCreate(&s_rect, 6.0f, 0x1 | 0x2, nullptr, PaintBackground, &s_layerBackground); + ScrnLayerCreate(&s_rect, 7.0f, 0x1 | 0x2, nullptr, PaintText, &s_layerText); + + RegisterHandlers(); + + // TODO register commands + + // TODO EventSetConfirmCloseCallback(EventCloseCallback, 0); + + // TODO ConsoleCommandExecute("ver", 1); + + s_batch = GxuFontCreateBatch(false, false); +} diff --git a/src/console/Screen.hpp b/src/console/Screen.hpp new file mode 100644 index 0000000..709ec75 --- /dev/null +++ b/src/console/Screen.hpp @@ -0,0 +1,6 @@ +#ifndef CONSOLE_SCREEN_HPP +#define CONSOLE_SCREEN_HPP + +void ConsoleScreenInitialize(const char* title); + +#endif