mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-02 00:32:45 +03:00
feat(console): add partial implementation for function OnIdle
This commit is contained in:
parent
e8cebed60e
commit
db22711646
@ -1,8 +1,17 @@
|
|||||||
#include "console/Console.hpp"
|
#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_active;
|
||||||
static int32_t s_consoleAccessEnabled;
|
static int32_t s_consoleAccessEnabled;
|
||||||
static KEY s_consoleKey = KEY_TILDE;
|
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() {
|
int32_t ConsoleAccessGetEnabled() {
|
||||||
return s_consoleAccessEnabled;
|
return s_consoleAccessEnabled;
|
||||||
@ -16,14 +25,46 @@ int32_t ConsoleGetActive() {
|
|||||||
return s_active;
|
return s_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ConsoleGetFontHeight() {
|
||||||
|
return s_fontHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ConsoleGetHeight() {
|
||||||
|
return s_consoleHeight;
|
||||||
|
}
|
||||||
|
|
||||||
KEY ConsoleGetHotKey() {
|
KEY ConsoleGetHotKey() {
|
||||||
return s_consoleKey;
|
return s_consoleKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* ConsoleGetRepeatBuffer() {
|
||||||
|
return *s_repeatBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ConsoleGetRepeatCount() {
|
||||||
|
return s_repeatCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONSOLERESIZESTATE ConsoleGetResizeState() {
|
||||||
|
return s_consoleResizeState;
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleSetActive(int32_t active) {
|
void ConsoleSetActive(int32_t active) {
|
||||||
s_active = active;
|
s_active = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleSetFontHeight(float fontHeight) {
|
||||||
|
s_fontHeight = fontHeight;
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleSetHotKey(KEY hotkey) {
|
void ConsoleSetHotKey(KEY hotkey) {
|
||||||
s_consoleKey = hotkey;
|
s_consoleKey = hotkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleSetRepeatCount(uint32_t repeatCount) {
|
||||||
|
s_repeatCount = repeatCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleSetResizeState(CONSOLERESIZESTATE resizeState) {
|
||||||
|
s_consoleResizeState = resizeState;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#ifndef CONSOLE_CONSOLE_HPP
|
#ifndef CONSOLE_CONSOLE_HPP
|
||||||
#define CONSOLE_CONSOLE_HPP
|
#define CONSOLE_CONSOLE_HPP
|
||||||
|
|
||||||
|
#include "console/Types.hpp"
|
||||||
#include "event/Types.hpp"
|
#include "event/Types.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@ -10,10 +11,28 @@ void ConsoleAccessSetEnabled(int32_t enable);
|
|||||||
|
|
||||||
int32_t ConsoleGetActive();
|
int32_t ConsoleGetActive();
|
||||||
|
|
||||||
|
float ConsoleGetFontHeight();
|
||||||
|
|
||||||
|
float ConsoleGetHeight();
|
||||||
|
|
||||||
|
char* ConsoleGetRepeatBuffer();
|
||||||
|
|
||||||
|
uint32_t ConsoleGetRepeatCount();
|
||||||
|
|
||||||
|
CONSOLERESIZESTATE ConsoleGetResizeState();
|
||||||
|
|
||||||
KEY ConsoleGetHotKey();
|
KEY ConsoleGetHotKey();
|
||||||
|
|
||||||
void ConsoleSetActive(int32_t active);
|
void ConsoleSetActive(int32_t active);
|
||||||
|
|
||||||
|
void ConsoleSetFontHeight(float fontHeight);
|
||||||
|
|
||||||
|
void ConsoleSetHeight(float height);
|
||||||
|
|
||||||
void ConsoleSetHotKey(KEY hotkey);
|
void ConsoleSetHotKey(KEY hotkey);
|
||||||
|
|
||||||
|
void ConsoleSetRepeatCount(uint32_t repeatCount);
|
||||||
|
|
||||||
|
void ConsoleSetResizeState(CONSOLERESIZESTATE resizeState);
|
||||||
|
|
||||||
#endif // ifndef CONSOLE_CONSOLE_HPP
|
#endif // ifndef CONSOLE_CONSOLE_HPP
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
#include "console/Handlers.hpp"
|
#include "console/Handlers.hpp"
|
||||||
#include "console/Console.hpp"
|
#include "console/Console.hpp"
|
||||||
|
#include "console/Screen.hpp"
|
||||||
#include "event/Event.hpp"
|
#include "event/Event.hpp"
|
||||||
|
#include "gx/Screen.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace {
|
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) {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "console/Screen.hpp"
|
#include "console/Screen.hpp"
|
||||||
|
#include "console/Console.hpp"
|
||||||
#include "console/Handlers.hpp"
|
#include "console/Handlers.hpp"
|
||||||
#include "console/Types.hpp"
|
#include "console/Types.hpp"
|
||||||
#include "gx/Buffer.hpp"
|
#include "gx/Buffer.hpp"
|
||||||
@ -15,7 +16,6 @@
|
|||||||
static CGxStringBatch* s_batch;
|
static CGxStringBatch* s_batch;
|
||||||
static float s_caretpixwidth;
|
static float s_caretpixwidth;
|
||||||
static float s_caretpixheight;
|
static float s_caretpixheight;
|
||||||
static float s_fontHeight = 0.02f;
|
|
||||||
static char s_fontName[STORM_MAX_PATH];
|
static char s_fontName[STORM_MAX_PATH];
|
||||||
static int32_t s_highlightState;
|
static int32_t s_highlightState;
|
||||||
static HLAYER s_layerBackground;
|
static HLAYER s_layerBackground;
|
||||||
@ -83,6 +83,18 @@ void PaintText(void* param, const RECTF* rect, const RECTF* visible, float elaps
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HLAYER ConsoleScreenGetBackgroundLayer() {
|
||||||
|
return s_layerBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
HLAYER ConsoleScreenGetTextLayer() {
|
||||||
|
return s_layerText;
|
||||||
|
}
|
||||||
|
|
||||||
|
RECTF* ConsoleScreenGetRect() {
|
||||||
|
return &s_rect;
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleScreenInitialize(const char* title) {
|
void ConsoleScreenInitialize(const char* title) {
|
||||||
CRect windowSize;
|
CRect windowSize;
|
||||||
GxCapsWindowSize(windowSize);
|
GxCapsWindowSize(windowSize);
|
||||||
@ -93,7 +105,7 @@ void ConsoleScreenInitialize(const char* title) {
|
|||||||
s_caretpixheight = height == 0.0f ? 1.0f : 1.0f / height;
|
s_caretpixheight = height == 0.0f ? 1.0f : 1.0f / height;
|
||||||
|
|
||||||
SStrCopy(s_fontName, "Fonts\\ARIALN.ttf", sizeof(s_fontName));
|
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, 6.0f, 0x1 | 0x2, nullptr, PaintBackground, &s_layerBackground);
|
||||||
ScrnLayerCreate(&s_rect, 7.0f, 0x1 | 0x2, nullptr, PaintText, &s_layerText);
|
ScrnLayerCreate(&s_rect, 7.0f, 0x1 | 0x2, nullptr, PaintText, &s_layerText);
|
||||||
|
|||||||
@ -1,6 +1,14 @@
|
|||||||
#ifndef CONSOLE_SCREEN_HPP
|
#ifndef CONSOLE_SCREEN_HPP
|
||||||
#define CONSOLE_SCREEN_HPP
|
#define CONSOLE_SCREEN_HPP
|
||||||
|
|
||||||
|
#include "gx/Screen.hpp"
|
||||||
|
|
||||||
|
HLAYER ConsoleScreenGetBackgroundLayer();
|
||||||
|
|
||||||
|
HLAYER ConsoleScreenGetTextLayer();
|
||||||
|
|
||||||
|
RECTF* ConsoleScreenGetRect();
|
||||||
|
|
||||||
void ConsoleScreenInitialize(const char* title);
|
void ConsoleScreenInitialize(const char* title);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -14,4 +14,10 @@ enum COLOR_T {
|
|||||||
NUM_COLORTYPES,
|
NUM_COLORTYPES,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum CONSOLERESIZESTATE {
|
||||||
|
CS_NONE = 0,
|
||||||
|
CS_STRETCH = 1,
|
||||||
|
NUM_CONSOLERESIZESTATES
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user