diff --git a/src/console/Console.cpp b/src/console/Console.cpp index 1609c64..9ceb7f8 100644 --- a/src/console/Console.cpp +++ b/src/console/Console.cpp @@ -3,6 +3,7 @@ static int32_t s_active; static int32_t s_consoleAccessEnabled; static KEY s_consoleKey = KEY_TILDE; +static CONSOLERESIZESTATE s_consoleResizeState = CS_NONE; int32_t ConsoleAccessGetEnabled() { return s_consoleAccessEnabled; @@ -20,6 +21,10 @@ KEY ConsoleGetHotKey() { return s_consoleKey; } +CONSOLERESIZESTATE ConsoleGetResizeState() { + return s_consoleResizeState; +} + void ConsoleSetActive(int32_t active) { s_active = active; } @@ -27,3 +32,7 @@ void ConsoleSetActive(int32_t active) { void ConsoleSetHotKey(KEY hotkey) { s_consoleKey = hotkey; } + +void ConsoleSetResizeState(CONSOLERESIZESTATE state) { + s_consoleResizeState = state; +} diff --git a/src/console/Console.hpp b/src/console/Console.hpp index e9bfac8..82d967c 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 @@ -12,8 +13,12 @@ int32_t ConsoleGetActive(); KEY ConsoleGetHotKey(); +CONSOLERESIZESTATE ConsoleGetResizeState(); + void ConsoleSetActive(int32_t active); void ConsoleSetHotKey(KEY hotkey); +void ConsoleSetResizeState(CONSOLERESIZESTATE state); + #endif // ifndef CONSOLE_CONSOLE_HPP diff --git a/src/console/Handlers.cpp b/src/console/Handlers.cpp index ac1d248..38880bb 100644 --- a/src/console/Handlers.cpp +++ b/src/console/Handlers.cpp @@ -1,5 +1,6 @@ #include "console/Handlers.hpp" #include "console/Console.hpp" +#include "console/Screen.hpp" #include "event/Event.hpp" #include @@ -11,7 +12,10 @@ int32_t OnChar(const EVENT_DATA_CHAR* data, void* param) { } int32_t OnIdle(const EVENT_DATA_IDLE* data, void* param) { - // TODO + // TODO repeat buffer logic + + ConsoleScreenAnimate(data->elapsedSec); + return 1; } @@ -28,7 +32,7 @@ int32_t OnKeyDown(const EVENT_DATA_KEY* data, void* param) { return 0; } - + if (EventIsKeyDown(ConsoleGetHotKey()) || !ConsoleGetActive()) { return 1; } diff --git a/src/console/Screen.cpp b/src/console/Screen.cpp index 2e2844c..63b3821 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" @@ -11,11 +12,14 @@ #include "gx/Screen.hpp" #include #include +#include static CGxStringBatch* s_batch; static float s_caretpixwidth; static float s_caretpixheight; +static float s_consoleLines = 10.0f; static float s_fontHeight = 0.02f; +static float s_consoleHeight = s_consoleLines * s_fontHeight; static char s_fontName[STORM_MAX_PATH]; static int32_t s_highlightState; static HLAYER s_layerBackground; @@ -83,6 +87,29 @@ void PaintText(void* param, const RECTF* rect, const RECTF* visible, float elaps // TODO } +void ConsoleScreenAnimate(float elapsedSec) { + auto finalPos = ConsoleGetActive() ? std::min(1.0f - s_consoleHeight, 1.0f) : 1.0f; + finalPos = std::max(finalPos, 0.0f); + + if (s_rect.bottom == finalPos) { + return; + } + + auto currentPos = finalPos; + + if (ConsoleGetResizeState() == CS_NONE) { + auto direction = s_rect.bottom <= finalPos ? 1.0f : -1.0f; + + currentPos = s_rect.bottom + direction * elapsedSec * 5.0f; + currentPos = ConsoleGetActive() ? std::max(currentPos, finalPos) : std::min(currentPos, finalPos); + } + + s_rect.bottom = currentPos; + + ScrnLayerSetRect(s_layerBackground, &s_rect); + ScrnLayerSetRect(s_layerText, &s_rect); +} + void ConsoleScreenInitialize(const char* title) { CRect windowSize; GxCapsWindowSize(windowSize); diff --git a/src/console/Screen.hpp b/src/console/Screen.hpp index 709ec75..e065fb1 100644 --- a/src/console/Screen.hpp +++ b/src/console/Screen.hpp @@ -1,6 +1,8 @@ #ifndef CONSOLE_SCREEN_HPP #define CONSOLE_SCREEN_HPP +void ConsoleScreenAnimate(float elapsedSec); + void ConsoleScreenInitialize(const char* title); #endif diff --git a/src/console/Types.hpp b/src/console/Types.hpp index 0099be2..a66edb1 100644 --- a/src/console/Types.hpp +++ b/src/console/Types.hpp @@ -14,4 +14,10 @@ enum COLOR_T { NUM_COLORTYPES, }; +enum CONSOLERESIZESTATE { + CS_NONE, + CS_STRETCH, + NUM_CONSOLERESIZESTATES, +}; + #endif