Refactor display.hpp

This commit is contained in:
EnderIce2 2024-02-05 16:19:07 +02:00
parent b0575ba4f2
commit b31384fc55
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD

View File

@ -35,132 +35,132 @@ namespace Video
#define PSF2_MAGIC2 0x4a #define PSF2_MAGIC2 0x4a
#define PSF2_MAGIC3 0x86 #define PSF2_MAGIC3 0x86
struct PSF1_HEADER struct PSF1_HEADER
{ {
uint8_t magic[2]; uint8_t magic[2];
uint8_t mode; uint8_t mode;
uint8_t charsize; uint8_t charsize;
}; };
struct PSF2_HEADER struct PSF2_HEADER
{ {
uint8_t magic[4]; uint8_t magic[4];
uint32_t version; uint32_t version;
uint32_t headersize; uint32_t headersize;
uint32_t flags; uint32_t flags;
uint32_t length; uint32_t length;
uint32_t charsize; uint32_t charsize;
uint32_t height, width; uint32_t height, width;
}; };
typedef struct _PSF1_FONT typedef struct _PSF1_FONT
{ {
PSF1_HEADER *Header; PSF1_HEADER *Header;
void *GlyphBuffer; void *GlyphBuffer;
} PSF1_FONT; } PSF1_FONT;
typedef struct _PSF2_FONT typedef struct _PSF2_FONT
{ {
PSF2_HEADER *Header; PSF2_HEADER *Header;
void *GlyphBuffer; void *GlyphBuffer;
} PSF2_FONT; } PSF2_FONT;
enum FontType enum FontType
{ {
None, None,
PCScreenFont1, PCScreenFont1,
PCScreenFont2 PCScreenFont2
}; };
struct FontInfo struct FontInfo
{ {
uintptr_t *StartAddress; uintptr_t *StartAddress;
uintptr_t *EndAddress; uintptr_t *EndAddress;
PSF1_FONT *PSF1Font; PSF1_FONT *PSF1Font;
PSF2_FONT *PSF2Font; PSF2_FONT *PSF2Font;
uint32_t Width, Height; uint32_t Width, Height;
FontType Type; FontType Type;
}; };
class Font class Font
{ {
private: private:
FontInfo Info; FontInfo Info;
public: public:
FontInfo GetInfo() { return Info; } FontInfo GetInfo() { return Info; }
Font(uintptr_t *Start, uintptr_t *End, FontType Type); Font(uintptr_t *Start, uintptr_t *End, FontType Type);
~Font(); ~Font();
}; };
struct ScreenBuffer struct ScreenBuffer
{ {
void *Buffer = nullptr; void *Buffer = nullptr;
uint32_t Width, Height; uint32_t Width, Height;
size_t Size; size_t Size;
uint32_t Color; uint32_t Color;
uint32_t CursorX, CursorY; uint32_t CursorX, CursorY;
char Brightness; char Brightness;
bool DoNotScroll; bool DoNotScroll;
long long Checksum; long long Checksum;
}; };
class Display class Display
{ {
private: private:
BootInfo::FramebufferInfo framebuffer; BootInfo::FramebufferInfo framebuffer;
Font *CurrentFont = nullptr; Font *CurrentFont = nullptr;
ScreenBuffer Buffers[256]; ScreenBuffer Buffers[256];
bool ColorIteration = false; bool ColorIteration = false;
int ColorPickerIteration = 0; int ColorPickerIteration = 0;
public: public:
BootInfo::FramebufferInfo GetFramebufferStruct() { return framebuffer; } BootInfo::FramebufferInfo GetFramebufferStruct() { return framebuffer; }
Font *GetCurrentFont(); Font *GetCurrentFont();
void SetCurrentFont(Font *Font); void SetCurrentFont(Font *Font);
uint16_t GetBitsPerPixel(); uint16_t GetBitsPerPixel();
size_t GetPitch(); size_t GetPitch();
/** /**
* @brief Create a new buffer * @brief Create a new buffer
* *
* This function creates a new buffer. * This function creates a new buffer.
* *
* For @see Width and @see Height. Both values must be greater than 0. * For @see Width and @see Height. Both values must be greater than 0.
* *
* @note Some indexes are reserved for the kernel. * @note Some indexes are reserved for the kernel.
* 0 - Main buffer * 0 - Main buffer
* 1 - Loading screen buffer * 1 - Loading screen buffer
* 200 - GUI buffer * 200 - GUI buffer
* 250 - Empty (crash screen) * 250 - Empty (crash screen)
* 251 - Console (crash screen) * 251 - Console (crash screen)
* 252 - Tasks (crash screen) * 252 - Tasks (crash screen)
* 253 - Frames (crash screen) * 253 - Frames (crash screen)
* 254 - Details (crash screen) * 254 - Details (crash screen)
* 255 - Main (crash screen) * 255 - Main (crash screen)
* *
* @param Width The width of the buffer * @param Width The width of the buffer
* @param Height The height of the buffer * @param Height The height of the buffer
* @param Index The index of the buffer (0-255) * @param Index The index of the buffer (0-255)
*/ */
void CreateBuffer(uint32_t Width, uint32_t Height, int Index); void CreateBuffer(uint32_t Width, uint32_t Height, int Index);
void SetBuffer(int Index); void SetBuffer(int Index);
ScreenBuffer *GetBuffer(int Index); ScreenBuffer *GetBuffer(int Index);
void ClearBuffer(int Index); void ClearBuffer(int Index);
void DeleteBuffer(int Index); void DeleteBuffer(int Index);
void SetBrightness(int Value, int Index); void SetBrightness(int Value, int Index);
void SetBufferCursor(int Index, uint32_t X, uint32_t Y); void SetBufferCursor(int Index, uint32_t X, uint32_t Y);
void GetBufferCursor(int Index, uint32_t *X, uint32_t *Y); void GetBufferCursor(int Index, uint32_t *X, uint32_t *Y);
void SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int Index); void SetPixel(uint32_t X, uint32_t Y, uint32_t Color, int Index);
uint32_t GetPixel(uint32_t X, uint32_t Y, int Index); uint32_t GetPixel(uint32_t X, uint32_t Y, int Index);
void Scroll(int Index, int Lines); void Scroll(int Index, int Lines);
void SetDoNotScroll(bool Value, int Index); void SetDoNotScroll(bool Value, int Index);
char Print(char Char, int Index, bool WriteToUART = false); char Print(char Char, int Index, bool WriteToUART = false);
void DrawString(const char *String, uint32_t X, uint32_t Y, int Index, bool WriteToUART = false); void DrawString(const char *String, uint32_t X, uint32_t Y, int Index, bool WriteToUART = false);
Display(BootInfo::FramebufferInfo Info, bool LoadDefaultFont = true); Display(BootInfo::FramebufferInfo Info, bool LoadDefaultFont = true);
~Display(); ~Display();
}; };
} }
#endif // !__FENNIX_KERNEL_DISPLAY_H__ #endif // !__FENNIX_KERNEL_DISPLAY_H__