diff --git a/src/console/Console.cpp b/src/console/Console.cpp index 1609c64..1c1da99 100644 --- a/src/console/Console.cpp +++ b/src/console/Console.cpp @@ -1,8 +1,17 @@ #include "console/Console.hpp" +const int32_t HISTORY_DEPTH = 32; +const int32_t BUFFER_SIZE = 1024; + static int32_t s_active; static int32_t s_consoleAccessEnabled; static KEY s_consoleKey = KEY_TILDE; +static float s_fontHeight = 0.02f; +static float s_consoleLines = 10.0f; +static float s_consoleHeight = s_fontHeight * s_consoleLines; +static CONSOLERESIZESTATE s_consoleResizeState; +static uint32_t s_repeatCount; +static char s_repeatBuffer[HISTORY_DEPTH][BUFFER_SIZE]; int32_t ConsoleAccessGetEnabled() { return s_consoleAccessEnabled; @@ -16,14 +25,46 @@ int32_t ConsoleGetActive() { return s_active; } +float ConsoleGetFontHeight() { + return s_fontHeight; +} + +float ConsoleGetHeight() { + return s_consoleHeight; +} + KEY ConsoleGetHotKey() { return s_consoleKey; } +char* ConsoleGetRepeatBuffer() { + return *s_repeatBuffer; +} + +uint32_t ConsoleGetRepeatCount() { + return s_repeatCount; +} + +CONSOLERESIZESTATE ConsoleGetResizeState() { + return s_consoleResizeState; +} + void ConsoleSetActive(int32_t active) { s_active = active; } +void ConsoleSetFontHeight(float fontHeight) { + s_fontHeight = fontHeight; +} + void ConsoleSetHotKey(KEY hotkey) { s_consoleKey = hotkey; } + +void ConsoleSetRepeatCount(uint32_t repeatCount) { + s_repeatCount = repeatCount; +} + +void ConsoleSetResizeState(CONSOLERESIZESTATE resizeState) { + s_consoleResizeState = resizeState; +} diff --git a/src/console/Console.hpp b/src/console/Console.hpp index e9bfac8..89429e3 100644 --- a/src/console/Console.hpp +++ b/src/console/Console.hpp @@ -1,6 +1,7 @@ #ifndef CONSOLE_CONSOLE_HPP #define CONSOLE_CONSOLE_HPP +#include "console/Types.hpp" #include "event/Types.hpp" #include @@ -10,10 +11,28 @@ void ConsoleAccessSetEnabled(int32_t enable); int32_t ConsoleGetActive(); +float ConsoleGetFontHeight(); + +float ConsoleGetHeight(); + +char* ConsoleGetRepeatBuffer(); + +uint32_t ConsoleGetRepeatCount(); + +CONSOLERESIZESTATE ConsoleGetResizeState(); + KEY ConsoleGetHotKey(); void ConsoleSetActive(int32_t active); +void ConsoleSetFontHeight(float fontHeight); + +void ConsoleSetHeight(float height); + void ConsoleSetHotKey(KEY hotkey); +void ConsoleSetRepeatCount(uint32_t repeatCount); + +void ConsoleSetResizeState(CONSOLERESIZESTATE resizeState); + #endif // ifndef CONSOLE_CONSOLE_HPP diff --git a/src/console/Handlers.cpp b/src/console/Handlers.cpp index a3e4cf5..d38577a 100644 --- a/src/console/Handlers.cpp +++ b/src/console/Handlers.cpp @@ -1,6 +1,8 @@ #include "console/Handlers.hpp" #include "console/Console.hpp" +#include "console/Screen.hpp" #include "event/Event.hpp" +#include "gx/Screen.hpp" #include namespace { @@ -25,7 +27,74 @@ int32_t OnChar(const EVENT_DATA_CHAR* data, void* param) { } int32_t OnIdle(const EVENT_DATA_IDLE* data, void* param) { - // TODO + double currentPos; + double direction; + float finalPos; + char* repeatBuffer; + uint32_t repeatCount; + RECTF* rect; + + rect = ConsoleScreenGetRect(); + + if (ConsoleGetActive()) { + finalPos = 1.0 - ConsoleGetHeight(); + + if (finalPos > 1.0) { + finalPos = 1.0; + goto LABEL_7; + } + } + else { + finalPos = 1.0; + } + if (finalPos <= 0.0) { + finalPos = 0.0; + } +LABEL_7: + repeatCount = ConsoleGetRepeatCount(); + repeatBuffer = ConsoleGetRepeatBuffer(); + + if (repeatCount && repeatBuffer[0]) { + // TODO + // ConsoleCommandExecute(repeatBuffer, 1); + ConsoleSetRepeatCount(--repeatCount); + } + else if (rect->bottom != finalPos) { + if (ConsoleGetResizeState() == CS_NONE) { + rect->bottom = finalPos; +LABEL_22: + ScrnLayerSetRect(ConsoleScreenGetBackgroundLayer(), rect); + ScrnLayerSetRect(ConsoleScreenGetTextLayer(), rect); + + return 1; + } + if (rect->bottom <= finalPos) { + direction = 1.0; + } + else { + direction = -1.0; + } + + currentPos = direction * data->elapsedSec * 5.0 + rect->bottom; + + if (ConsoleGetActive()) { + if ( finalPos > currentPos ) { + rect->bottom = finalPos; + + goto LABEL_22; + } + } + else if (finalPos < currentPos) { + rect->bottom = finalPos; + + goto LABEL_22; + } + + rect->bottom = currentPos; + + goto LABEL_22; + } + return 1; } diff --git a/src/console/Screen.cpp b/src/console/Screen.cpp index 2e2844c..92fab18 100644 --- a/src/console/Screen.cpp +++ b/src/console/Screen.cpp @@ -1,4 +1,5 @@ #include "console/Screen.hpp" +#include "console/Console.hpp" #include "console/Handlers.hpp" #include "console/Types.hpp" #include "gx/Buffer.hpp" @@ -15,7 +16,6 @@ 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 int32_t s_highlightState; static HLAYER s_layerBackground; @@ -83,6 +83,18 @@ void PaintText(void* param, const RECTF* rect, const RECTF* visible, float elaps // TODO } +HLAYER ConsoleScreenGetBackgroundLayer() { + return s_layerBackground; +} + +HLAYER ConsoleScreenGetTextLayer() { + return s_layerText; +} + +RECTF* ConsoleScreenGetRect() { + return &s_rect; +} + void ConsoleScreenInitialize(const char* title) { CRect windowSize; GxCapsWindowSize(windowSize); @@ -93,7 +105,7 @@ void ConsoleScreenInitialize(const char* title) { 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)); + s_textFont = TextBlockGenerateFont(s_fontName, 0, NDCToDDCHeight(ConsoleGetFontHeight())); ScrnLayerCreate(&s_rect, 6.0f, 0x1 | 0x2, nullptr, PaintBackground, &s_layerBackground); ScrnLayerCreate(&s_rect, 7.0f, 0x1 | 0x2, nullptr, PaintText, &s_layerText); diff --git a/src/console/Screen.hpp b/src/console/Screen.hpp index 709ec75..1a9942d 100644 --- a/src/console/Screen.hpp +++ b/src/console/Screen.hpp @@ -1,6 +1,14 @@ #ifndef CONSOLE_SCREEN_HPP #define CONSOLE_SCREEN_HPP +#include "gx/Screen.hpp" + +HLAYER ConsoleScreenGetBackgroundLayer(); + +HLAYER ConsoleScreenGetTextLayer(); + +RECTF* ConsoleScreenGetRect(); + void ConsoleScreenInitialize(const char* title); #endif diff --git a/src/console/Types.hpp b/src/console/Types.hpp index 0099be2..88751fe 100644 --- a/src/console/Types.hpp +++ b/src/console/Types.hpp @@ -14,4 +14,10 @@ enum COLOR_T { NUM_COLORTYPES, }; +enum CONSOLERESIZESTATE { + CS_NONE = 0, + CS_STRETCH = 1, + NUM_CONSOLERESIZESTATES +}; + #endif