Files
tp/include/JSystem/JUtility/JUTConsole.h
T

173 lines
5.2 KiB
C++
Raw Normal View History

2021-03-28 22:49:05 +02:00
#ifndef JUTCONSOLE_H
#define JUTCONSOLE_H
#include "JSystem/JGadget/linklist.h"
#include "JSystem/JKernel/JKRDisposer.h"
#include "JSystem/JUtility/JUTFont.h"
#include <cstdarg>
2021-03-28 22:49:05 +02:00
2026-01-18 17:59:57 -08:00
class JUTConsole;
extern "C" void JUTConsole_print_f_va_(JUTConsole*, const char*, va_list);
extern "C" void JUTSetReportConsole(JUTConsole*);
extern "C" JUTConsole* JUTGetReportConsole();
extern "C" void JUTSetWarningConsole(JUTConsole*);
extern "C" JUTConsole* JUTGetWarningConsole();
extern "C" void JUTWarningConsole_f_va(const char*, va_list);
extern "C" void JUTReportConsole_f_va(const char*, va_list);
extern "C" void JUTReportConsole_f(const char*, ...);
extern "C" void JUTWarningConsole(const char* message);
extern "C" void JUTWarningConsole_f(const char* message, ...);
extern "C" void JUTReportConsole(const char* message);
2024-04-12 00:10:30 -06:00
/**
* @ingroup jsystem-jutility
*
*/
class JUTConsole : public JKRDisposer {
public:
2021-09-27 15:27:58 -07:00
enum EConsoleType {
CONSOLE_TYPE_0 = 0,
CONSOLE_TYPE_1 = 1,
CONSOLE_TYPE_2 = 2,
2021-09-27 15:27:58 -07:00
};
2022-01-09 17:33:14 -08:00
enum OutputFlag {
/* 0x0 */ OUTPUT_NONE,
/* 0x1 */ OUTPUT_OSREPORT,
2022-12-19 11:06:32 -08:00
/* 0x2 */ OUTPUT_CONSOLE,
/* 0x3 */ OUTPUT_OSR_AND_CONSOLE,
2022-01-09 17:33:14 -08:00
};
2025-11-30 14:23:42 -08:00
static JUTConsole* create(unsigned int, void*, u32);
static JUTConsole* create(unsigned int, unsigned int, JKRHeap*);
JUTConsole(unsigned int, unsigned int, bool);
static size_t getObjectSizeFromBufferSize(unsigned int, unsigned int);
static size_t getLineFromObjectSize(u32, unsigned int);
void clear();
void doDraw(JUTConsole::EConsoleType) const;
void print_f(char const*, ...);
void print(char const*);
void dumpToTerminal(unsigned int);
void scroll(int);
int getUsedLine() const;
int getLineOffset() const;
2025-11-30 14:23:42 -08:00
virtual ~JUTConsole();
2022-04-10 15:29:28 -07:00
void setOutput(unsigned int output) { mOutput = output; }
void setPosition(int x, int y) {
mPositionX = x;
mPositionY = y;
}
2021-11-09 23:09:38 +01:00
void setFontSize(f32 x, f32 y) {
mFontSizeX = x;
mFontSizeY = y;
}
void setHeight(unsigned int height) {
2021-11-09 23:09:38 +01:00
mHeight = height;
if (mHeight > mMaxLines) {
mHeight = mMaxLines;
2021-11-09 23:09:38 +01:00
}
}
2022-01-09 17:33:14 -08:00
void setFont(JUTFont* p_font) {
2025-12-19 20:25:09 -05:00
// Fakematch...? Fixes GCN but breaks Wii. TODO: Test after Wii flags are fixed.
p_font = mFont = p_font;
2022-01-09 17:33:14 -08:00
setFontSize(p_font->getWidth(), p_font->getHeight());
}
2021-11-09 23:09:38 +01:00
u32 getOutput() const { return mOutput; }
int getPositionY() const { return mPositionY; }
int getPositionX() const { return mPositionX; }
2021-11-09 23:09:38 +01:00
u32 getHeight() const { return mHeight; }
bool isVisible() const { return mVisible; }
void setVisible(bool visible) { mVisible = visible; }
2026-01-05 04:07:04 -08:00
u8 getLineAttr(int param_0) const { return mBuf[(field_0x20 + 2) * param_0]; }
2021-09-27 16:51:38 -07:00
void setLineAttr(int param_0, u8 param_1) { mBuf[(field_0x20 + 2) * param_0] = param_1; }
u8* getLinePtr(int param_0) const { return &mBuf[(field_0x20 + 2) * param_0] + 1; }
2021-09-27 15:27:58 -07:00
int diffIndex(int param_0, int param_1) const {
2026-01-05 04:07:04 -08:00
int result;
2021-09-27 15:27:58 -07:00
int diff = param_1 - param_0;
if (diff >= 0) {
2026-01-05 04:07:04 -08:00
result = diff;
} else {
result = diff + mMaxLines;
2021-09-27 15:27:58 -07:00
}
2026-01-05 04:07:04 -08:00
return result;
2021-09-27 15:27:58 -07:00
}
2023-09-20 05:30:44 -07:00
int prevIndex(int index) const {
return --index < 0 ? index = mMaxLines - 1 : index;
}
2023-09-20 05:30:44 -07:00
int nextIndex(int index) const {
return ++index >= mMaxLines ? 0 : index;
}
void scrollToLastLine() { scroll(mMaxLines); }
void scrollToFirstLine() { scroll(-mMaxLines); }
2026-01-18 17:59:57 -08:00
void print_f_va(const char* fmt, va_list args) { JUTConsole_print_f_va_(this, fmt, args); }
2021-11-09 23:09:38 +01:00
/* 0x18 */ JGadget::TLinkListNode mListNode;
2024-12-29 07:53:54 -08:00
/* 0x20 */ unsigned int field_0x20;
2024-01-19 16:22:19 -08:00
/* 0x24 */ int mMaxLines;
2021-09-27 16:51:38 -07:00
/* 0x28 */ u8* mBuf;
/* 0x2C */ bool field_0x2c;
/* 0x30 */ int field_0x30;
/* 0x34 */ int field_0x34;
/* 0x38 */ int field_0x38;
/* 0x3C */ int field_0x3c;
/* 0x40 */ int mPositionX;
/* 0x44 */ int mPositionY;
/* 0x48 */ u32 mHeight;
/* 0x4C */ JUTFont* mFont;
/* 0x50 */ f32 mFontSizeX;
/* 0x54 */ f32 mFontSizeY;
/* 0x58 */ int mOutput;
/* 0x5C */ JUtility::TColor field_0x5c;
/* 0x60 */ JUtility::TColor field_0x60;
/* 0x64 */ int field_0x64;
/* 0x68 */ bool mVisible;
/* 0x69 */ bool field_0x69;
/* 0x6A */ bool field_0x6a;
/* 0x6B */ bool field_0x6b;
}; // Size: 0x6C
2024-04-12 00:10:30 -06:00
/**
* @ingroup jsystem-jutility
*
*/
2021-09-27 15:27:58 -07:00
class JUTConsoleManager {
public:
2025-11-30 14:23:42 -08:00
JUTConsoleManager();
static JUTConsoleManager* createManager(JKRHeap*);
void appendConsole(JUTConsole*);
void removeConsole(JUTConsole*);
void draw() const;
void drawDirect(bool) const;
void setDirectConsole(JUTConsole*);
2021-09-27 15:27:58 -07:00
JUTConsole* getDirectConsole() const { return mDirectConsole; }
2024-12-29 07:53:54 -08:00
static JUTConsoleManager* const getManager() { return sManager; }
2021-09-27 15:27:58 -07:00
static JUTConsoleManager* sManager;
2024-12-29 07:53:54 -08:00
#ifdef __MWERKS__
2024-01-24 04:00:46 -08:00
typedef JGadget::TLinkList<JUTConsole, -offsetof(JUTConsole, mListNode)> ConsoleList;
2024-12-29 07:53:54 -08:00
#else
// clangd does not support offsetof in template arguments.
typedef JGadget::TLinkList<JUTConsole, -sizeof(JKRDisposer)> ConsoleList;
#endif
2024-01-24 04:00:46 -08:00
2021-09-27 15:27:58 -07:00
private:
2024-01-24 04:00:46 -08:00
/* 0x00 */ ConsoleList soLink_;
2021-09-27 15:27:58 -07:00
/* 0x0C */ JUTConsole* mActiveConsole;
/* 0x10 */ JUTConsole* mDirectConsole;
}; // Size: 0x14
2021-03-28 22:49:05 +02:00
#endif /* JUTCONSOLE_H */