mouse cursor

This commit is contained in:
2026-01-29 13:34:34 +11:00
parent dc825fb6d3
commit df3f9478e8
9 changed files with 55 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -51,6 +51,33 @@ void BasicRenderer::Print(const char* str) {
}
}
void BasicRenderer::PutPixel(uint32_t x, uint32_t y, uint32_t colour) {
*(uint32_t*)((uint64_t)targetFramebuffer->BaseAddress + (x*4) + (y * targetFramebuffer->PixelsPerScanline * 4)) = colour;
}
void BasicRenderer::DrawOverlayMouseCursor(uint8_t* mouseCursor, Point position, uint32_t colour) {
int xMax = 16;
int yMax = 19;
int diffX = targetFramebuffer->Width - position.x;
int diffY = targetFramebuffer->Height - position.y;
if (diffX < 16) xMax = diffX;
if (diffY < 19) yMax = diffY;
for (int y = 0; y < yMax; y++) {
for (int x = 0; x < xMax; x++) {
int bit = y * 16 + x;
int byte = bit / 8;
if (mouseCursor[byte] & (0b10000000 >> (x % 8))) {
PutPixel(position.x + x, position.y + y, colour);
}
}
}
}
void BasicRenderer::Clear() {
uint64_t fbBase = (uint64_t)targetFramebuffer->BaseAddress;
uint64_t bytesPerScanline = targetFramebuffer->PixelsPerScanline * 4;

View File

@@ -15,9 +15,11 @@ class BasicRenderer {
void Print(const char* str);
void PutChar(char chr, unsigned int xOff, unsigned int yOff);
void PutChar(char chr);
void PutPixel(uint32_t x, uint32_t y, uint32_t colour);
void ClearChar();
void Clear();
void Next();
void DrawOverlayMouseCursor(uint8_t* mouseCursor, Point position, uint32_t colour);
};
extern BasicRenderer* GlobalRenderer;

View File

@@ -1,6 +1,29 @@
#include "mouse.h"
#include "../IO.h"
uint8_t MousePointer[] = {
0b10000000, 0b00000000,
0b11000000, 0b00000000,
0b10100000, 0b00000000,
0b10010000, 0b00000000,
0b10001000, 0b00000000,
0b10000100, 0b00000000,
0b10000010, 0b00000000,
0b10000001, 0b00000000,
0b10000000, 0b10000000,
0b10000000, 0b01000000,
0b10000000, 0b00100000,
0b10000000, 0b00010000,
0b10000001, 0b11110000,
0b10010001, 0b00000000,
0b10101000, 0b10000000,
0b11000100, 0b10000000,
0b00000010, 0b01000000,
0b00000010, 0b01000000,
0b00000001, 0b10000000,
};
void MouseWait() {
uint64_t timeout = 100000;
while (timeout--) {
@@ -113,6 +136,8 @@ void ProcessMousePacket() {
if (mousePosition.x > GlobalRenderer->targetFramebuffer->Width-1) mousePosition.x = GlobalRenderer->targetFramebuffer->Width;
if (mousePosition.y < 0) mousePosition.y = 0;
if (mousePosition.y > GlobalRenderer->targetFramebuffer->Height-1) mousePosition.y = GlobalRenderer->targetFramebuffer->Height;
GlobalRenderer->DrawOverlayMouseCursor(MousePointer, mousePosition, 0xFFFFFFFF);
}
void InitPS2Mouse() {

View File

@@ -3,6 +3,7 @@
#include "../math.h"
#include "../BasicRenderer.h"
extern uint8_t MousePointer[];
#define PS2LeftButton 0b00000001
#define PS2MiddleButton 0b00000010
#define PS2RightButton 0b00000100