Merge remote-tracking branch 'Kernel/mb2_32_64_test' into Kernel-mb2_32_64_test

This commit is contained in:
EnderIce2
2024-11-20 05:15:06 +02:00
parent 47cf2c24d1
commit b348932172
353 changed files with 77068 additions and 0 deletions

218
Kernel/GUI/GUITools.cpp Normal file
View File

@@ -0,0 +1,218 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gui.hpp>
#include "../kernel.h"
namespace GraphicalUserInterface
{
Ofast inline void InlineSetPixel(ScreenBitmap *Bitmap, long X, long Y, uint32_t Color)
{
if (unlikely(X < 0 || Y < 0 || X >= Bitmap->Width || Y >= Bitmap->Height))
return;
uint32_t *Pixel = (uint32_t *)((uintptr_t)Bitmap->Data + (Y * Bitmap->Width + X) * (Bitmap->BitsPerPixel / 8));
*Pixel = Color;
// Bitmap->Data[Y * Bitmap->Width + X] = Color;
}
void SetPixel(ScreenBitmap *Bitmap, long X, long Y, uint32_t Color)
{
if (unlikely(!Bitmap))
return;
if (unlikely(!Bitmap->Data))
return;
InlineSetPixel(Bitmap, X, Y, Color);
}
uint32_t GetPixel(ScreenBitmap *Bitmap, long X, long Y)
{
if (unlikely(!Bitmap))
return 0;
if (unlikely(!Bitmap->Data))
return 0;
if (unlikely(X < 0 || Y < 0 || X >= Bitmap->Width || Y >= Bitmap->Height))
return 0;
uint32_t *Pixel = (uint32_t *)((uintptr_t)Bitmap->Data + (Y * Bitmap->Width + X) * (Bitmap->BitsPerPixel / 8));
return *Pixel;
}
Ofast void DrawOverBitmap(ScreenBitmap *DestinationBitmap,
ScreenBitmap *SourceBitmap,
long Top,
long Left, bool IgnoreZero)
{
if (unlikely(!SourceBitmap) || unlikely(!SourceBitmap->Data) ||
unlikely(!DestinationBitmap) || unlikely(!DestinationBitmap->Data))
return;
// for (uint32_t i = 0; i < SourceBitmap->Width; i++)
// for (uint32_t j = 0; j < SourceBitmap->Height; j++)
// {
// uint32_t *Pixel = (uint32_t *)((uintptr_t)SourceBitmap->Data + (j * SourceBitmap->Width + i) * (SourceBitmap->BitsPerPixel / 8));
// if (IgnoreZero && (*Pixel != 0x000000))
// InlineSetPixel(DestinationBitmap, Left + i, Top + j, *Pixel);
// }
for (uint32_t j = 0; j < SourceBitmap->Height; j++)
{
uint32_t *Pixel = (uint32_t *)((uintptr_t)SourceBitmap->Data + j * SourceBitmap->Width * (SourceBitmap->BitsPerPixel / 8));
if (IgnoreZero)
{
for (uint32_t i = 0; i < SourceBitmap->Width; i++)
{
if (Pixel[i] != 0x000000)
InlineSetPixel(DestinationBitmap, Left + i, Top + j, Pixel[i]);
}
}
else
{
memcpy((void *)((uintptr_t)DestinationBitmap->Data + (Top + j) * DestinationBitmap->Width * (DestinationBitmap->BitsPerPixel / 8) + Left * (DestinationBitmap->BitsPerPixel / 8)),
(void *)((uintptr_t)SourceBitmap->Data + j * SourceBitmap->Width * (SourceBitmap->BitsPerPixel / 8)),
SourceBitmap->Width * (SourceBitmap->BitsPerPixel / 8));
}
}
}
Ofast void PutRect(ScreenBitmap *Bitmap, Rect rect, uint32_t Color)
{
if (unlikely(!Bitmap))
return;
if (unlikely(!Bitmap->Data))
return;
for (uint32_t i = 0; i < rect.Width; i++)
for (uint32_t j = 0; j < rect.Height; j++)
InlineSetPixel(Bitmap, rect.Left + i, rect.Top + j, Color);
}
void PutBorder(ScreenBitmap *Bitmap, Rect rect, uint32_t Color)
{
if (unlikely(!Bitmap))
return;
if (unlikely(!Bitmap->Data))
return;
for (uint32_t i = 0; i < rect.Width; i++)
{
InlineSetPixel(Bitmap, rect.Left + i, rect.Top, Color);
InlineSetPixel(Bitmap, rect.Left + i, rect.Top + rect.Height - 1, Color);
}
for (uint32_t i = 0; i < rect.Height; i++)
{
InlineSetPixel(Bitmap, rect.Left, rect.Top + i, Color);
InlineSetPixel(Bitmap, rect.Left + rect.Width - 1, rect.Top + i, Color);
}
}
uint32_t BlendColors(uint32_t c1, uint32_t c2, float t)
{
uint8_t r1 = (c1 >> 16) & 0xFF;
uint8_t g1 = (c1 >> 8) & 0xFF;
uint8_t b1 = c1 & 0xFF;
uint8_t r2 = (c2 >> 16) & 0xFF;
uint8_t g2 = (c2 >> 8) & 0xFF;
uint8_t b2 = c2 & 0xFF;
uint8_t r = (uint8_t)(r1 + t * (r2 - r1));
uint8_t g = (uint8_t)(g1 + t * (g2 - g1));
uint8_t b = (uint8_t)(b1 + t * (b2 - b1));
return (r << 16) | (g << 8) | b;
}
void PutBorderWithShadow(ScreenBitmap *Bitmap, Rect rect, uint32_t Color)
{
UNUSED(Bitmap);
UNUSED(rect);
UNUSED(Color);
}
#define SHADOW_SIZE 12
void DrawShadow(ScreenBitmap *Bitmap, Rect rect)
{
UNUSED(Bitmap);
UNUSED(rect);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-overflow"
void PaintChar(Video::Font *font, ScreenBitmap *Bitmap, char c, uint32_t Color, long *CharCursorX, long *CharCursorY)
{
switch (font->GetInfo().Type)
{
case Video::FontType::PCScreenFont1:
{
// uint32_t *PixelPtr = (uint32_t *)Bitmap->Data;
char *FontPtr = (char *)font->GetInfo().PSF1Font->GlyphBuffer + (c * font->GetInfo().PSF1Font->Header->charsize);
for (int64_t Y = *CharCursorY; Y < *CharCursorY + 16; Y++)
{
for (int64_t X = *CharCursorX; X < *CharCursorX + 8; X++)
if ((*FontPtr & (0b10000000 >> (X - *CharCursorX))) > 0)
InlineSetPixel(Bitmap, X, Y, Color);
FontPtr++;
}
*CharCursorX += 8;
break;
}
case Video::FontType::PCScreenFont2:
{
// if (font->PSF2Font->GlyphBuffer == (uint16_t *)0x01) // HAS UNICODE TABLE
// Char = font->PSF2Font->GlyphBuffer[Char];
int BytesPerLine = (font->GetInfo().PSF2Font->Header->width + 7) / 8;
char *FontPtr = (char *)font->GetInfo().StartAddress +
font->GetInfo().PSF2Font->Header->headersize +
(c > 0 && (unsigned char)c < font->GetInfo().PSF2Font->Header->length ? c : 0) *
font->GetInfo().PSF2Font->Header->charsize;
uint32_t fonthdrWidth = font->GetInfo().PSF2Font->Header->width;
uint32_t fonthdrHeight = font->GetInfo().PSF2Font->Header->height;
for (int64_t Y = *CharCursorY; Y < *CharCursorY + fonthdrHeight; Y++)
{
for (int64_t X = *CharCursorX; X < *CharCursorX + fonthdrWidth; X++)
if ((*FontPtr & (0b10000000 >> (X - *CharCursorX))) > 0)
InlineSetPixel(Bitmap, X, Y, Color);
FontPtr += BytesPerLine;
}
*CharCursorX += fonthdrWidth;
break;
}
default:
warn("Unsupported font type");
break;
}
}
#pragma GCC diagnostic pop
void DrawString(ScreenBitmap *Bitmap, Rect rect, const char *Text, uint32_t Color)
{
UNUSED(Bitmap);
UNUSED(rect);
UNUSED(Text);
UNUSED(Color);
}
}

View File

@@ -0,0 +1,665 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gui.hpp>
#include <driver.hpp>
#include <task.hpp>
#include <debug.h>
#include "icons.hpp"
#include "../kernel.h"
#include "../DAPI.hpp"
#include "../Fex.hpp"
extern uintptr_t _binary_Files_tamsyn_font_1_11_Tamsyn7x14r_psf_start;
extern uintptr_t _binary_Files_tamsyn_font_1_11_Tamsyn7x14r_psf_end;
extern uintptr_t _binary_Files_tamsyn_font_1_11_Tamsyn7x14r_psf_size;
#ifdef DEBUG
uint64_t FIi = 0, PDi = 0, PWi = 0, PWWi = 0, PCi = 0, mmi = 0;
#endif
namespace GraphicalUserInterface
{
void GUI::FetchInputs()
{
MouseData Mouse;
bool FoundMouseDriver = false;
if (likely(DriverManager->GetDrivers().size() > 0))
{
foreach (auto Driver in DriverManager->GetDrivers())
{
if (((FexExtended *)((uintptr_t)Driver.Address + EXTENDED_SECTION_ADDRESS))->Driver.Type == FexDriverType::FexDriverType_Input &&
((FexExtended *)((uintptr_t)Driver.Address + EXTENDED_SECTION_ADDRESS))->Driver.TypeFlags & FexDriverInputTypes::FexDriverInputTypes_Mouse)
{
#ifdef DEBUG
static int once = 0;
if (!once++)
debug("Found mouse driver %ld", Driver.DriverUID);
#endif
KernelCallback callback{};
callback.Reason = FetchReason;
DriverManager->IOCB(Driver.DriverUID, &callback);
Mouse.X = callback.InputCallback.Mouse.X;
Mouse.Y = callback.InputCallback.Mouse.Y;
Mouse.Z = callback.InputCallback.Mouse.Z;
Mouse.Left = callback.InputCallback.Mouse.Buttons.Left;
Mouse.Right = callback.InputCallback.Mouse.Buttons.Right;
Mouse.Middle = callback.InputCallback.Mouse.Buttons.Middle;
FoundMouseDriver = true;
break;
}
}
}
if (unlikely(!FoundMouseDriver))
{
debug("No mouse driver found.");
Mouse.X = Display->GetBuffer(200)->Width / 2;
Mouse.Y = Display->GetBuffer(200)->Height / 2;
Mouse.Z = 0;
Mouse.Left = false;
Mouse.Right = false;
Mouse.Middle = false;
}
Event eTemplate;
memset(&eTemplate, 0, sizeof(Event));
foreach (auto wnd in this->Windows)
{
/* On mouse down event */
if (unlikely((!MouseArray[1].Left || !MouseArray[1].Right || !MouseArray[1].Middle) &&
(Mouse.Left || Mouse.Right || Mouse.Middle)))
{
eTemplate.MouseDown.X = Mouse.X;
eTemplate.MouseDown.Y = Mouse.Y;
eTemplate.MouseDown.Left = Mouse.Left;
eTemplate.MouseDown.Right = Mouse.Right;
eTemplate.MouseDown.Middle = Mouse.Middle;
wnd->OnMouseDown(&eTemplate);
}
/* On mouse up event */
if (unlikely((MouseArray[1].Left || MouseArray[1].Right || MouseArray[1].Middle) &&
(!Mouse.Left || !Mouse.Right || !Mouse.Middle)))
{
eTemplate.MouseUp.X = Mouse.X;
eTemplate.MouseUp.Y = Mouse.Y;
eTemplate.MouseUp.Left = Mouse.Left;
eTemplate.MouseUp.Right = Mouse.Right;
eTemplate.MouseUp.Middle = Mouse.Middle;
wnd->OnMouseUp(&eTemplate);
}
static int Idle = 0;
if (likely(Mouse.X != MouseArray[1].X || Mouse.Y != MouseArray[1].Y))
{
Idle = 0;
Rect TopBarPos = wnd->GetPosition();
TopBarPos.Top -= 20;
TopBarPos.Height = 20;
TopBarPos.Width -= 60; /* buttons */
if (unlikely(TopBarPos.Top < 0))
{
TopBarPos.Top = 0;
wnd->GetPositionPtr()->Top = 20;
}
Rect ResizeHintPos = wnd->GetPosition();
ResizeHintPos.Left += ResizeHintPos.Width - 20;
ResizeHintPos.Top += ResizeHintPos.Height - 20;
ResizeHintPos.Width = 20;
ResizeHintPos.Height = 20;
if (unlikely(TopBarPos.Contains(Mouse.X, Mouse.Y) ||
TopBarPos.Contains(MouseArray[0].X, MouseArray[0].Y) ||
TopBarPos.Contains(MouseArray[1].X, MouseArray[1].Y)))
{
if (likely(Mouse.Left))
{
if (likely(MouseArray[1].Left))
{
wnd->GetPositionPtr()->Left += Mouse.X - MouseArray[0].X;
wnd->GetPositionPtr()->Top += Mouse.Y - MouseArray[0].Y;
OverlayBufferRepaint = true;
OverlayFullRepaint = true;
}
}
}
if (ResizeHintPos.Contains(Mouse.X, Mouse.Y) ||
ResizeHintPos.Contains(MouseArray[0].X, MouseArray[0].Y) ||
ResizeHintPos.Contains(MouseArray[1].X, MouseArray[1].Y))
{
if (Mouse.Left)
{
if (MouseArray[1].Left)
{
wnd->GetPositionPtr()->Width += Mouse.X - MouseArray[0].X;
wnd->GetPositionPtr()->Height += Mouse.Y - MouseArray[0].Y;
if (wnd->GetPositionPtr()->Width < 200)
{
wnd->GetPositionPtr()->Width = 200;
Mouse.X = MouseArray[0].X;
}
if (wnd->GetPositionPtr()->Height < 100)
{
wnd->GetPositionPtr()->Height = 100;
Mouse.Y = MouseArray[0].Y;
}
OverlayBufferRepaint = true;
OverlayFullRepaint = true;
eTemplate.Resize.Width = wnd->GetPosition().Width;
eTemplate.Resize.Height = wnd->GetPosition().Height;
wnd->OnResize(&eTemplate);
}
}
if (unlikely(Cursor != CursorType::ResizeAll))
{
Cursor = CursorType::ResizeAll;
CursorBufferRepaint = true;
}
}
else
{
if (unlikely(Cursor != CursorType::Arrow))
{
Cursor = CursorType::Arrow;
CursorBufferRepaint = true;
}
}
eTemplate.MouseMove.X = Mouse.X;
eTemplate.MouseMove.Y = Mouse.Y;
eTemplate.MouseMove.Left = Mouse.Left;
eTemplate.MouseMove.Right = Mouse.Right;
eTemplate.MouseMove.Middle = Mouse.Middle;
wnd->OnMouseMove(&eTemplate);
}
else
{
if (unlikely(Idle > 1000))
CPU::Pause();
else
Idle++;
}
}
foreach (auto wdg in this->Widgets)
{
// TODO: Implement mouse events for widgets
UNUSED(wdg);
}
memmove(MouseArray + 1, MouseArray, sizeof(MouseArray) - sizeof(MouseArray[1]));
MouseArray[0] = Mouse;
LastCursor = Cursor;
}
void GUI::PaintDesktop()
{
if (DesktopBufferRepaint)
{
// PutRect(this->DesktopBuffer, this->Desktop, 0x404040);
memset(this->DesktopBuffer->Data, 0x404040, this->DesktopBuffer->Size);
DesktopBufferRepaint = false;
}
// Well... I have to do some code optimization on DrawOverBitmap. It's too slow and it's not even using SIMD
memcpy(this->BackBuffer->Data, this->DesktopBuffer->Data, this->DesktopBuffer->Size);
}
void GUI::PaintWidgets()
{
Event eTemplate;
memset(&eTemplate, 0, sizeof(Event));
foreach (auto wdg in this->Widgets)
wdg->OnPaint(nullptr);
}
void GUI::PaintWindows()
{
foreach (auto wnd in this->Windows)
{
ScreenBitmap *wndBuffer = wnd->GetBuffer();
if (unlikely(wndBuffer == nullptr)) // I think "unlikely" is not needed here
continue;
Rect WndPos = wnd->GetPosition();
// Draw window content
DrawOverBitmap(this->BackBuffer,
wndBuffer,
WndPos.Top,
WndPos.Left);
/* We can't use memcpy because the window buffer
is not the same size as the screen buffer
https://i.imgur.com/OHfaYnS.png */
// memcpy(this->BackBuffer->Data + wnd->GetPositionPtr()->Top * this->BackBuffer->Width + wnd->GetPositionPtr()->Left, wndBuffer->Data, wndBuffer->Size);
Rect TopBarPos = WndPos;
TopBarPos.Top -= 20;
TopBarPos.Height = 20;
if (TopBarPos.Top < 0)
{
TopBarPos.Top = 0;
wnd->GetPositionPtr()->Top = 20;
}
Rect CloseButtonPos;
Rect MinimizeButtonPos;
CloseButtonPos.Left = TopBarPos.Left + TopBarPos.Width - 20;
CloseButtonPos.Top = TopBarPos.Top;
CloseButtonPos.Width = 20;
CloseButtonPos.Height = 20;
MinimizeButtonPos.Left = TopBarPos.Left + TopBarPos.Width - 60;
if (unlikely(MouseArray[0].X >= MinimizeButtonPos.Left &&
MouseArray[0].X <= CloseButtonPos.Left + CloseButtonPos.Width &&
MouseArray[0].Y >= CloseButtonPos.Top &&
MouseArray[0].Y <= CloseButtonPos.Top + CloseButtonPos.Height))
{
OverlayBufferRepaint = true;
}
// Title bar
if (unlikely(OverlayBufferRepaint))
{
if (OverlayFullRepaint)
{
memset(this->OverlayBuffer->Data, 0, this->OverlayBuffer->Size);
OverlayFullRepaint = false;
}
static bool RepaintNeeded = false;
DrawShadow(this->OverlayBuffer, wnd->GetPosition());
Rect MaximizeButtonPos;
MaximizeButtonPos.Left = TopBarPos.Left + TopBarPos.Width - 40;
MaximizeButtonPos.Top = TopBarPos.Top;
MaximizeButtonPos.Width = 20;
MaximizeButtonPos.Height = 20;
MinimizeButtonPos.Top = TopBarPos.Top;
MinimizeButtonPos.Width = 20;
MinimizeButtonPos.Height = 20;
PutRect(this->OverlayBuffer, TopBarPos, 0x282828);
// Title bar buttons (close, minimize, maximize) on the right
if (MouseArray[0].X >= CloseButtonPos.Left &&
MouseArray[0].X <= CloseButtonPos.Left + CloseButtonPos.Width &&
MouseArray[0].Y >= CloseButtonPos.Top &&
MouseArray[0].Y <= CloseButtonPos.Top + CloseButtonPos.Height)
{
PutRect(this->OverlayBuffer, CloseButtonPos, MouseArray[0].Left ? 0xFF5500 : 0xFF0000);
RepaintNeeded = true;
}
else
{
PutRect(this->OverlayBuffer, MaximizeButtonPos, 0x282828);
}
if (MouseArray[0].X >= MaximizeButtonPos.Left &&
MouseArray[0].X <= MaximizeButtonPos.Left + MaximizeButtonPos.Width &&
MouseArray[0].Y >= MaximizeButtonPos.Top &&
MouseArray[0].Y <= MaximizeButtonPos.Top + MaximizeButtonPos.Height)
{
PutRect(this->OverlayBuffer, MaximizeButtonPos, MouseArray[0].Left ? 0x454545 : 0x404040);
RepaintNeeded = true;
}
else
{
PutRect(this->OverlayBuffer, MaximizeButtonPos, 0x282828);
}
if (MouseArray[0].X >= MinimizeButtonPos.Left &&
MouseArray[0].X <= MinimizeButtonPos.Left + MinimizeButtonPos.Width &&
MouseArray[0].Y >= MinimizeButtonPos.Top &&
MouseArray[0].Y <= MinimizeButtonPos.Top + MinimizeButtonPos.Height)
{
PutRect(this->OverlayBuffer, MinimizeButtonPos, MouseArray[0].Left ? 0x454545 : 0x404040);
RepaintNeeded = true;
}
else
{
PutRect(this->OverlayBuffer, MinimizeButtonPos, 0x282828);
}
// Title bar icons (close, minimize, maximize) on the right
for (short i = 0; i < 20; i++)
{
for (short j = 0; j < 20; j++)
{
if (CloseButton[i * 20 + j] == 1)
SetPixel(this->OverlayBuffer,
CloseButtonPos.Left + j,
CloseButtonPos.Top + i,
0xFFFFFF);
if ((MaximizeButtonMaximized[i * 20 + j] == 1) && !wnd->IsMaximized())
SetPixel(this->OverlayBuffer,
MaximizeButtonPos.Left + j,
MaximizeButtonPos.Top + i,
0xFFFFFF);
else if ((MaximizeButtonNormal[i * 20 + j] == 1) && wnd->IsMaximized())
SetPixel(this->OverlayBuffer,
MaximizeButtonPos.Left + j,
MaximizeButtonPos.Top + i,
0xFFFFFF);
if (MinimizeButton[i * 20 + j] == 1)
SetPixel(this->OverlayBuffer,
MinimizeButtonPos.Left + j,
MinimizeButtonPos.Top + i,
0xFFFFFF);
}
}
Rect wndPos = wnd->GetPosition();
// Resize hint
for (short i = 0; i < 20; i++)
for (short j = 0; j < 20; j++)
if (ResizeHint[i * 20 + j] == 1)
SetPixel(this->OverlayBuffer, wndPos.Left + wndPos.Width - 20 + j, wndPos.Top + wndPos.Height - 20 + i, 0xFFFFFF);
// Title bar border
PutBorder(this->OverlayBuffer, TopBarPos, 0xFF000000);
// Window border
PutBorder(this->OverlayBuffer, wndPos, 0xFF000000);
Rect TopBarTextPos = TopBarPos;
TopBarTextPos.Left += 4;
TopBarTextPos.Top += 4;
// Title bar text
long CharCursorX = TopBarTextPos.Left;
long CharCursorY = TopBarTextPos.Top;
for (uint64_t i = 0; i < strlen(wnd->GetTitle()); i++)
PaintChar(this->CurrentFont, this->OverlayBuffer, wnd->GetTitle()[i], 0xFFFFFF, &CharCursorX, &CharCursorY);
if (!RepaintNeeded)
{
OverlayBufferRepaint = false;
RepaintNeeded = false;
}
}
wnd->OnPaint(nullptr);
}
DrawOverBitmap(this->BackBuffer, this->OverlayBuffer, 0, 0);
}
/*
"* 2" to increase the size of the cursor
"/ 2" to decrease the size of the cursor
*/
#define ICON_SIZE
void GUI::PaintCursor()
{
uint32_t CursorColorInner = 0xFFFFFFFF;
uint32_t CursorColorOuter = 0xFF000000;
if (MouseArray[0].X != MouseArray[1].X ||
MouseArray[0].Y != MouseArray[1].Y ||
MouseArray[0].Z != MouseArray[1].Z ||
Cursor != LastCursor)
CursorBufferRepaint = true;
if (CursorBufferRepaint)
{
memset(this->CursorBuffer->Data, 0, this->CursorBuffer->Size);
switch (this->Cursor)
{
case CursorType::Visible:
{
CursorVisible = true;
break;
}
case CursorType::Hidden:
{
CursorVisible = false;
break;
}
default:
fixme("Unknown cursor type %d", this->Cursor);
[[fallthrough]];
case CursorType::Arrow:
{
if (CursorVisible)
for (int i = 0; i < 19; i++)
{
for (int j = 0; j < 12; j++)
{
if (CursorArrow[i * 12 + j] == 1)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorOuter);
}
else if (CursorArrow[i * 12 + j] == 2)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorInner);
}
}
}
break;
}
case CursorType::Hand:
{
if (CursorVisible)
for (int i = 0; i < 24; i++)
{
for (int j = 0; j < 17; j++)
{
if (CursorHand[i * 17 + j] == 1)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorOuter);
}
else if (CursorHand[i * 17 + j] == 2)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorInner);
}
}
}
break;
}
case CursorType::Wait:
{
if (CursorVisible)
for (int i = 0; i < 22; i++)
{
for (int j = 0; j < 13; j++)
{
if (CursorWait[i * 13 + j] == 1)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorOuter);
}
else if (CursorWait[i * 13 + j] == 2)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorInner);
}
}
}
break;
}
case CursorType::IBeam:
{
if (CursorVisible)
for (int i = 0; i < 22; i++)
{
for (int j = 0; j < 13; j++)
{
if (CursorIBeam[i * 13 + j] == 1)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorOuter);
}
else if (CursorIBeam[i * 13 + j] == 2)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorInner);
}
}
}
break;
}
case CursorType::ResizeAll:
{
if (CursorVisible)
for (int i = 0; i < 23; i++)
{
for (int j = 0; j < 23; j++)
{
if (CursorResizeAll[i * 23 + j] == 1)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorOuter);
}
else if (CursorResizeAll[i * 23 + j] == 2)
{
SetPixel(this->CursorBuffer, j ICON_SIZE, i ICON_SIZE, CursorColorInner);
}
}
}
break;
}
}
CursorBufferRepaint = false;
}
DrawOverBitmap(this->BackBuffer, this->CursorBuffer, MouseArray[0].Y, MouseArray[0].X);
}
void GUI::Loop()
{
/*
Because we do not use a gpu to do the rendering, we need to do it manually.
This is why the mouse is slow when we have to draw a bunch of things.
*/
while (IsRunning)
{
#ifdef DEBUG
FIi = CPU::Counter();
#endif
FetchInputs();
#ifdef DEBUG
FIi = CPU::Counter() - FIi;
PDi = CPU::Counter();
#endif
PaintDesktop();
#ifdef DEBUG
PDi = CPU::Counter() - PDi;
PWi = CPU::Counter();
#endif
PaintWidgets();
#ifdef DEBUG
PWi = CPU::Counter() - PWi;
PWWi = CPU::Counter();
#endif
PaintWindows();
#ifdef DEBUG
PWWi = CPU::Counter() - PWWi;
PCi = CPU::Counter();
#endif
PaintCursor();
#ifdef DEBUG
PCi = CPU::Counter() - PCi;
mmi = CPU::Counter();
#endif
memcpy(Display->GetBuffer(200)->Buffer, this->BackBuffer->Data, this->BackBuffer->Size);
Display->SetBuffer(200);
#ifdef DEBUG
mmi = CPU::Counter() - mmi;
#endif
}
}
void GUI::AddWindow(Window *window)
{
this->Windows.push_back(window);
}
void GUI::AddWidget(WidgetCollection *widget)
{
this->Widgets.push_back(widget);
}
GUI::GUI()
{
Display->CreateBuffer(0, 0, 200);
this->CurrentFont = new Video::Font(&_binary_Files_tamsyn_font_1_11_Tamsyn7x14r_psf_start, &_binary_Files_tamsyn_font_1_11_Tamsyn7x14r_psf_end, Video::FontType::PCScreenFont2);
this->mem = new Memory::MemMgr;
this->Desktop.Top = 0;
this->Desktop.Left = 0;
this->Desktop.Width = Display->GetBuffer(200)->Width;
this->Desktop.Height = Display->GetBuffer(200)->Height;
this->BackBuffer = new ScreenBitmap;
this->BackBuffer->Width = this->Desktop.Width;
this->BackBuffer->Height = this->Desktop.Height;
this->BackBuffer->BitsPerPixel = Display->GetBitsPerPixel();
this->BackBuffer->Pitch = Display->GetPitch();
this->BackBuffer->Size = Display->GetBuffer(200)->Size;
this->BackBuffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->BackBuffer->Size + 1));
memset(this->BackBuffer->Data, 0, this->BackBuffer->Size);
this->DesktopBuffer = new ScreenBitmap;
this->DesktopBuffer->Width = this->Desktop.Width;
this->DesktopBuffer->Height = this->Desktop.Height;
this->DesktopBuffer->BitsPerPixel = Display->GetBitsPerPixel();
this->DesktopBuffer->Pitch = Display->GetPitch();
this->DesktopBuffer->Size = Display->GetBuffer(200)->Size;
this->DesktopBuffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->DesktopBuffer->Size + 1));
memset(this->DesktopBuffer->Data, 0, this->DesktopBuffer->Size);
this->OverlayBuffer = new ScreenBitmap;
this->OverlayBuffer->Width = this->Desktop.Width;
this->OverlayBuffer->Height = this->Desktop.Height;
this->OverlayBuffer->BitsPerPixel = Display->GetBitsPerPixel();
this->OverlayBuffer->Pitch = Display->GetPitch();
this->OverlayBuffer->Size = Display->GetBuffer(200)->Size;
this->OverlayBuffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->OverlayBuffer->Size + 1));
memset(this->OverlayBuffer->Data, 0, this->OverlayBuffer->Size);
this->CursorBuffer = new ScreenBitmap;
this->CursorBuffer->Width = 25;
this->CursorBuffer->Height = 25;
this->CursorBuffer->BitsPerPixel = Display->GetBitsPerPixel();
this->CursorBuffer->Pitch = Display->GetPitch();
this->CursorBuffer->Size = this->CursorBuffer->Width * this->CursorBuffer->Height * (this->CursorBuffer->BitsPerPixel / 8);
this->CursorBuffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->CursorBuffer->Size + 1));
memset(this->CursorBuffer->Data, 0, this->CursorBuffer->Size);
this->IsRunning = true;
}
GUI::~GUI()
{
debug("Destructor called");
delete this->mem, this->mem = nullptr;
delete this->BackBuffer, this->BackBuffer = nullptr;
delete this->DesktopBuffer, this->DesktopBuffer = nullptr;
delete this->OverlayBuffer, this->OverlayBuffer = nullptr;
delete this->CursorBuffer, this->CursorBuffer = nullptr;
Display->DeleteBuffer(200);
this->Windows.clear();
}
}

253
Kernel/GUI/Icons.cpp Normal file
View File

@@ -0,0 +1,253 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include "icons.hpp"
char CursorArrow[] = {
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 12x19
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
1, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, //
1, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, //
1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 0, //
1, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, //
1, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0, //
1, 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, //
1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, 0, //
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, //
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, //
1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, //
1, 2, 2, 2, 1, 2, 2, 1, 0, 0, 0, 0, //
1, 2, 2, 1, 0, 1, 2, 2, 1, 0, 0, 0, //
1, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
};

159
Kernel/GUI/WidgetEvents.cpp Normal file
View File

@@ -0,0 +1,159 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gui.hpp>
#include <driver.hpp>
#include <task.hpp>
#include <printf.h>
#include <debug.h>
#include "../kernel.h"
#include "../DAPI.hpp"
#include "../Fex.hpp"
namespace GraphicalUserInterface
{
void WidgetCollection::OnPaintBackground(Event *e)
{
UNUSED(e);
}
void WidgetCollection::OnPaintForeground(Event *e)
{
UNUSED(e);
foreach (auto Panel in this->Panels)
{
PutRect(this->Buffer, Panel->rect, Panel->Color);
}
foreach (auto Label in this->Labels)
{
Label->CharCursorX = Label->rect.Left;
Label->CharCursorY = Label->rect.Top;
for (uint64_t i = 0; i < strlen(Label->Text); i++)
PaintChar(this->CurrentFont, this->Buffer, Label->Text[i], 0xFFFFFF, &Label->CharCursorX, &Label->CharCursorY);
}
foreach (auto Button in this->Buttons)
{
if (Button->Pressed)
PutRect(this->Buffer, Button->rect, Button->PressedColor);
else if (Button->Hover)
PutRect(this->Buffer, Button->rect, Button->HoverColor);
else
PutRect(this->Buffer, Button->rect, Button->Color);
Button->CharCursorX = Button->rect.Left + (((Button->rect.Width / 2) - (this->CurrentFont->GetInfo().Width * strlen(Button->Text) / 2)));
Button->CharCursorY = Button->rect.Top + (((Button->rect.Height / 2) - (this->CurrentFont->GetInfo().Height / 2)));
for (uint64_t i = 0; i < strlen(Button->Text); i++)
PaintChar(this->CurrentFont, this->Buffer, Button->Text[i], 0xFFFFFF, &Button->CharCursorX, &Button->CharCursorY);
}
}
void WidgetCollection::OnPaint(Event *e)
{
static long LastWidth = 0;
static long LastHeight = 0;
if (LastWidth != ((Window *)this->ParentWindow)->GetPosition().Width ||
LastHeight != ((Window *)this->ParentWindow)->GetPosition().Height)
{
LastWidth = ((Window *)this->ParentWindow)->GetPosition().Width;
LastHeight = ((Window *)this->ParentWindow)->GetPosition().Height;
this->mem->FreePages(this->Buffer->Data, TO_PAGES(this->Buffer->Size + 1));
this->Buffer->Data = nullptr;
delete this->Buffer, this->Buffer = nullptr;
this->Buffer = new ScreenBitmap;
this->Buffer->Width = LastWidth;
this->Buffer->Height = LastHeight;
this->Buffer->BitsPerPixel = Display->GetBitsPerPixel();
this->Buffer->Pitch = Display->GetPitch();
this->Buffer->Size = this->Buffer->Pitch * LastHeight;
this->Buffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->Buffer->Size + 1));
memset(this->Buffer->Data, 0, this->Buffer->Size);
this->NeedRedraw = true;
}
if (this->NeedRedraw)
{
memset(this->Buffer->Data, 0, this->Buffer->Size);
this->OnPaintBackground(e);
this->OnPaintForeground(e);
this->NeedRedraw = false;
}
DrawOverBitmap(((Window *)this->ParentWindow)->GetBuffer(), this->Buffer, 0, 0);
}
void WidgetCollection::OnMouseDown(Event *e)
{
foreach (auto Button in this->Buttons)
{
if (Button->rect.Contains(e->MouseDown.X, e->MouseDown.Y))
{
if (e->MouseDown.Left)
{
debug("Button Hold");
Button->Pressed = true;
this->NeedRedraw = true;
}
}
}
}
void WidgetCollection::OnMouseUp(Event *e)
{
foreach (auto Button in this->Buttons)
{
if (Button->rect.Contains(e->MouseUp.X, e->MouseUp.Y))
{
if (e->MouseUp.Left)
{
debug("Button Release");
if (Button->Pressed)
{
debug("Button Clicked");
if (Button->OnClick != (uintptr_t) nullptr)
((void (*)(void))Button->OnClick)();
Button->Pressed = false;
this->NeedRedraw = true;
}
}
}
}
}
void WidgetCollection::OnMouseMove(Event *e)
{
foreach (auto Button in this->Buttons)
{
if (Button->rect.Contains(e->MouseMove.X, e->MouseMove.Y))
{
Button->Hover = true;
this->NeedRedraw = true;
}
else
{
Button->Hover = false;
this->NeedRedraw = true;
}
}
}
}

141
Kernel/GUI/Widgets.cpp Normal file
View File

@@ -0,0 +1,141 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gui.hpp>
#include <driver.hpp>
#include <task.hpp>
#include <printf.h>
#include <debug.h>
#include "../kernel.h"
#include "../DAPI.hpp"
#include "../Fex.hpp"
extern uintptr_t _binary_Files_tamsyn_font_1_11_Tamsyn10x20r_psf_start;
extern uintptr_t _binary_Files_tamsyn_font_1_11_Tamsyn10x20r_psf_end;
extern uintptr_t _binary_Files_tamsyn_font_1_11_Tamsyn10x20r_psf_size;
namespace GraphicalUserInterface
{
Handle WidgetCollection::CreatePanel(Rect rect, uint32_t Color)
{
PanelObject *panel = (PanelObject *)this->mem->RequestPages(TO_PAGES(sizeof(PanelObject) + 1));
panel->Handle.Type[0] = 'P';
panel->Handle.Type[1] = 'N';
panel->Handle.Type[2] = 'L';
panel->Handle.Type[3] = '\0';
panel->rect = rect;
panel->Color = Color;
panel->BorderColor = 0xFF000000;
panel->ShadowColor = 0xFF000000;
panel->Shadow = false;
Panels.push_back(panel);
this->NeedRedraw = true;
return (Handle)panel;
}
Handle WidgetCollection::CreateLabel(Rect rect, const char *Text)
{
LabelObject *label = (LabelObject *)this->mem->RequestPages(TO_PAGES(sizeof(LabelObject) + 1));
label->Handle.Type[0] = 'L';
label->Handle.Type[1] = 'B';
label->Handle.Type[2] = 'L';
label->Handle.Type[3] = '\0';
label->rect = rect;
strcpy(label->Text, Text);
label->Color = 0xFFFFFF;
label->CharCursorX = rect.Left;
label->CharCursorY = rect.Top;
Labels.push_back(label);
NeedRedraw = true;
return (Handle)label;
}
Handle WidgetCollection::CreateButton(Rect rect, const char *Text, uintptr_t OnClick)
{
ButtonObject *button = (ButtonObject *)this->mem->RequestPages(TO_PAGES(sizeof(ButtonObject) + 1));
button->Handle.Type[0] = 'B';
button->Handle.Type[1] = 'T';
button->Handle.Type[2] = 'N';
button->Handle.Type[3] = '\0';
button->rect = rect;
strcpy(button->Text, Text);
button->Color = 0x252525;
button->HoverColor = 0x353535;
button->PressedColor = 0x555555;
button->BorderColor = 0xFF000000;
button->ShadowColor = 0xFF000000;
button->Shadow = false;
button->Hover = false;
button->Pressed = false;
button->OnClick = OnClick;
Buttons.push_back(button);
this->NeedRedraw = true;
return (Handle)button;
}
void WidgetCollection::SetText(Handle handle, const char *Text)
{
HandleMeta *meta = (HandleMeta *)handle;
if (meta->Type[0] == 'L' && meta->Type[1] == 'B' && meta->Type[2] == 'L')
{
LabelObject *label = (LabelObject *)handle;
strcpy(label->Text, Text);
this->NeedRedraw = true;
}
}
WidgetCollection::WidgetCollection(void *ParentWindow)
{
if (!ParentWindow)
{
error("ParentWindow is null");
return;
}
this->ParentWindow = ParentWindow;
this->mem = new Memory::MemMgr;
this->Buffer = new ScreenBitmap;
this->Buffer->Width = ((Window *)this->ParentWindow)->GetPosition().Width;
this->Buffer->Height = ((Window *)this->ParentWindow)->GetPosition().Height;
this->Buffer->BitsPerPixel = Display->GetBitsPerPixel();
this->Buffer->Pitch = Display->GetPitch();
this->Buffer->Size = this->Buffer->Pitch * ((Window *)this->ParentWindow)->GetPosition().Height;
this->Buffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->Buffer->Size + 1));
memset(this->Buffer->Data, 0, this->Buffer->Size);
this->CurrentFont = new Video::Font(&_binary_Files_tamsyn_font_1_11_Tamsyn10x20r_psf_start, &_binary_Files_tamsyn_font_1_11_Tamsyn10x20r_psf_end, Video::FontType::PCScreenFont2);
}
WidgetCollection::~WidgetCollection()
{
delete this->mem, this->mem = nullptr;
delete this->Buffer, this->Buffer = nullptr;
delete this->CurrentFont, this->CurrentFont = nullptr;
}
}

82
Kernel/GUI/Window.cpp Normal file
View File

@@ -0,0 +1,82 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gui.hpp>
#include <driver.hpp>
#include <task.hpp>
#include <printf.h>
#include <debug.h>
#include "../kernel.h"
#include "../DAPI.hpp"
#include "../Fex.hpp"
namespace GraphicalUserInterface
{
#define TASKBAR_HEIGHT 25
// if (!Maximized)
// {
// this->LastPosition.Left = this->Position.Left;
// this->LastPosition.Top = this->Position.Top;
// this->LastPosition.Width = this->Position.Width;
// this->LastPosition.Height = this->Position.Height;
// this->Position.Left = 0;
// this->Position.Top = 0;
// this->Position.Width = Display->GetBuffer(200)->Width;
// this->Position.Height = Display->GetBuffer(200)->Height - 20 - TASKBAR_HEIGHT;
// Maximized = true;
// }
// else
// {
// this->Position.Left = this->LastPosition.Left;
// this->Position.Top = this->LastPosition.Top;
// this->Position.Width = this->LastPosition.Width;
// this->Position.Height = this->LastPosition.Height;
// Maximized = false;
// }
void Window::AddWidget(WidgetCollection *widget)
{
this->Widgets.push_back(widget);
}
Window::Window(void *ParentGUI, Rect rect, const char *Title)
{
this->mem = new Memory::MemMgr;
this->Buffer = new ScreenBitmap;
this->Buffer->Width = rect.Width;
this->Buffer->Height = rect.Height;
this->Buffer->BitsPerPixel = Display->GetBitsPerPixel();
this->Buffer->Pitch = Display->GetPitch();
this->Buffer->Size = this->Buffer->Pitch * rect.Height;
this->Buffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->Buffer->Size + 1));
memset(this->Buffer->Data, 0, this->Buffer->Size);
this->ParentGUI = ParentGUI;
this->Position = rect;
strcpy(this->Title, Title);
this->Maximized = false;
this->Minimized = false;
}
Window::~Window()
{
delete this->mem, this->mem = nullptr;
}
}

137
Kernel/GUI/WindowEvents.cpp Normal file
View File

@@ -0,0 +1,137 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gui.hpp>
#include <driver.hpp>
#include <task.hpp>
#include <printf.h>
#include <debug.h>
#include "../kernel.h"
#include "../DAPI.hpp"
#include "../Fex.hpp"
namespace GraphicalUserInterface
{
void Window::OnResize(Event *e)
{
// TODO: Optimize this
this->mem->FreePages(this->Buffer->Data, TO_PAGES(this->Buffer->Size + 1));
this->Buffer->Data = nullptr;
delete this->Buffer, this->Buffer = nullptr;
this->Buffer = new ScreenBitmap;
this->Buffer->Width = e->Resize.Width;
this->Buffer->Height = e->Resize.Height;
this->Buffer->BitsPerPixel = Display->GetBitsPerPixel();
this->Buffer->Pitch = Display->GetPitch();
this->Buffer->Size = this->Buffer->Pitch * e->Resize.Height;
this->Buffer->Data = (uint8_t *)this->mem->RequestPages(TO_PAGES(this->Buffer->Size + 1));
memset(this->Buffer->Data, 0, this->Buffer->Size);
this->OnPaint(e);
}
void Window::OnMinimize(Event *e)
{
UNUSED(e);
fixme("Window::OnMinimize() not implemented");
}
void Window::OnMaximize(Event *e)
{
UNUSED(e);
fixme("Window::OnMaximize() not implemented");
}
void Window::OnClose(Event *e)
{
UNUSED(e);
fixme("Window::OnClose() not implemented");
}
void Window::OnPaintBackground(Event *e)
{
UNUSED(e);
Rect PaintPosition = this->Position;
PaintPosition.Left = 0;
PaintPosition.Top = 0;
PutRect(this->Buffer, PaintPosition, 0x121212);
}
void Window::OnPaintForeground(Event *e)
{
// Window content
if (!this->Maximized)
{
char buf[256];
sprintf(buf, "Left:\eAA11FF%ld\eFFFFFF Top:\eAA11FF%ld\eFFFFFF W:\eAA11FF%ld\eFFFFFF H:\eAA11FF%ld\eFFFFFF", this->Position.Left, this->Position.Top, this->Position.Width, this->Position.Height);
// Display->DrawString(buf, this->Position.Left + 20, this->Position.Top + 25, 200);
}
foreach (auto var in this->Widgets)
{
var->OnPaint(e);
}
}
void Window::OnPaint(Event *e)
{
memset(this->Buffer->Data, 0, this->Buffer->Size);
this->OnPaintBackground(e);
this->OnPaintForeground(e);
}
void Window::OnMouseDown(Event *e)
{
Event WindowPos = *e;
WindowPos.MouseDown.X -= this->Position.Left;
WindowPos.MouseDown.Y -= this->Position.Top;
foreach (auto var in this->Widgets)
{
var->OnMouseDown(&WindowPos);
}
}
void Window::OnMouseUp(Event *e)
{
Event WindowPos = *e;
WindowPos.MouseUp.X -= this->Position.Left;
WindowPos.MouseUp.Y -= this->Position.Top;
foreach (auto var in this->Widgets)
{
var->OnMouseUp(&WindowPos);
}
}
void Window::OnMouseMove(Event *e)
{
Event WindowPos = *e;
WindowPos.MouseMove.X -= this->Position.Left;
WindowPos.MouseMove.Y -= this->Position.Top;
foreach (auto var in this->Widgets)
{
var->OnMouseMove(&WindowPos);
}
}
}

34
Kernel/GUI/icons.hpp Normal file
View File

@@ -0,0 +1,34 @@
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __FENNIX_KERNEL_ICONS_AND_FONTS_H__
#define __FENNIX_KERNEL_ICONS_AND_FONTS_H__
#include <types.h>
extern char CursorArrow[];
extern char CursorHand[];
extern char CursorWait[];
extern char CursorIBeam[];
extern char CursorResizeAll[];
extern char CloseButton[];
extern char MinimizeButton[];
extern char MaximizeButtonNormal[];
extern char MaximizeButtonMaximized[];
extern char ResizeHint[];
#endif // !__FENNIX_KERNEL_ICONS_AND_FONTS_H__