mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-04-09 23:06:47 +03:00
feat(console): animate console open and close
This commit is contained in:
parent
56092c6700
commit
df1ab32267
@ -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;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef CONSOLE_CONSOLE_HPP
|
||||
#define CONSOLE_CONSOLE_HPP
|
||||
|
||||
#include "console/Types.hpp"
|
||||
#include "event/Types.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
@ -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
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "console/Handlers.hpp"
|
||||
#include "console/Console.hpp"
|
||||
#include "console/Screen.hpp"
|
||||
#include "event/Event.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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 <storm/String.hpp>
|
||||
#include <tempest/Rect.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
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);
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef CONSOLE_SCREEN_HPP
|
||||
#define CONSOLE_SCREEN_HPP
|
||||
|
||||
void ConsoleScreenAnimate(float elapsedSec);
|
||||
|
||||
void ConsoleScreenInitialize(const char* title);
|
||||
|
||||
#endif
|
||||
|
@ -14,4 +14,10 @@ enum COLOR_T {
|
||||
NUM_COLORTYPES,
|
||||
};
|
||||
|
||||
enum CONSOLERESIZESTATE {
|
||||
CS_NONE,
|
||||
CS_STRETCH,
|
||||
NUM_CONSOLERESIZESTATES,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user