From 134d85bce6bc8e36beacae1628defccf0ff6eb1f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 8 Apr 2023 23:10:53 -0500 Subject: [PATCH] feat(console): add background drawing for console --- src/console/Screen.cpp | 60 +++++++++++++++++++++++++++++++++++++++++- src/console/Types.hpp | 17 ++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/console/Types.hpp diff --git a/src/console/Screen.cpp b/src/console/Screen.cpp index dd93622..31fe6aa 100644 --- a/src/console/Screen.cpp +++ b/src/console/Screen.cpp @@ -1,7 +1,12 @@ #include "console/Screen.hpp" +#include "console/Types.hpp" +#include "gx/Buffer.hpp" #include "gx/Coordinate.hpp" +#include "gx/Device.hpp" +#include "gx/Draw.hpp" #include "gx/Font.hpp" #include "gx/Gx.hpp" +#include "gx/RenderState.hpp" #include "gx/Screen.hpp" #include #include @@ -11,15 +16,68 @@ 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; 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) { +static CImVector s_colorArray[] = { + { 0xFF, 0xFF, 0xFF, 0xFF }, // DEFAULT_COLOR + { 0xFF, 0xFF, 0xFF, 0xFF }, // INPUT_COLOR + { 0x80, 0x80, 0x80, 0xFF }, // ECHO_COLOR + { 0x00, 0x00, 0xFF, 0xFF }, // ERROR_COLOR + { 0x00, 0xFF, 0xFF, 0xFF }, // WARNING_COLOR + { 0xFF, 0xFF, 0xFF, 0xFF }, // GLOBAL_COLOR + { 0xFF, 0xFF, 0xFF, 0xFF }, // ADMIN_COLOR + { 0xFF, 0xFF, 0xFF, 0x80 }, // HIGHLIGHT_COLOR + { 0x00, 0x00, 0x00, 0x80 }, // BACKGROUND_COLOR +}; + +void DrawBackground() { + uint16_t indices[] = { + 0, 1, 2, 3 + }; + + C3Vector position[] = { + { s_rect.left, s_rect.bottom, 0.0f }, + { s_rect.right, s_rect.bottom, 0.0f }, + { s_rect.left, s_rect.top, 0.0f }, + { s_rect.right, s_rect.top, 0.0f } + }; + + GxRsPush(); + + GxRsSet(GxRs_Lighting, 0); + GxRsSet(GxRs_Fog, 0); + GxRsSet(GxRs_DepthTest, 0); + GxRsSet(GxRs_DepthWrite, 0); + GxRsSet(GxRs_Culling, 0); + GxRsSet(GxRs_PolygonOffset, 0.0f); + GxRsSet(GxRs_BlendingMode, GxBlend_Alpha); + GxRsSet(GxRs_AlphaRef, CGxDevice::s_alphaRef[GxBlend_Alpha]); + + GxPrimLockVertexPtrs(4, position, sizeof(C3Vector), nullptr, 0, &s_colorArray[BACKGROUND_COLOR], 0, nullptr, 0, nullptr, 0, nullptr, 0); + GxDrawLockedElements(GxPrim_TriangleStrip, 4, indices); + GxPrimUnlockVertexPtrs(); + + GxRsPop(); +} + +void DrawHighLight() { // TODO } +void PaintBackground(void* param, const RECTF* rect, const RECTF* visible, float elapsedSec) { + if (s_rect.bottom < 1.0f) { + DrawBackground(); + + if (s_highlightState) { + DrawHighLight(); + } + } +} + void PaintText(void* param, const RECTF* rect, const RECTF* visible, float elapsedSec) { // TODO } diff --git a/src/console/Types.hpp b/src/console/Types.hpp new file mode 100644 index 0000000..0099be2 --- /dev/null +++ b/src/console/Types.hpp @@ -0,0 +1,17 @@ +#ifndef CONSOLE_TYPES_HPP +#define CONSOLE_TYPES_HPP + +enum COLOR_T { + DEFAULT_COLOR, + INPUT_COLOR, + ECHO_COLOR, + ERROR_COLOR, + WARNING_COLOR, + GLOBAL_COLOR, + ADMIN_COLOR, + HIGHLIGHT_COLOR, + BACKGROUND_COLOR, + NUM_COLORTYPES, +}; + +#endif