diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-18 15:09:12 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-18 15:09:12 +0200 |
| commit | c5b4c98fadd89fd114520e201e34a58a78025344 (patch) | |
| tree | adbcc550d6ef4a61764bd2cd2a534b9adb2af31f /dev/modules | |
| parent | 0a595d68cd69c365da98c58babf2217bd501615d (diff) | |
dev, fb: did some cleanup on the graphics stack.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/modules')
| -rw-r--r-- | dev/modules/CoreGfx/CoreGfx.h | 32 | ||||
| -rw-r--r-- | dev/modules/CoreGfx/CoreWindow.h | 75 |
2 files changed, 91 insertions, 16 deletions
diff --git a/dev/modules/CoreGfx/CoreGfx.h b/dev/modules/CoreGfx/CoreGfx.h index 74326f16..6df2329b 100644 --- a/dev/modules/CoreGfx/CoreGfx.h +++ b/dev/modules/CoreGfx/CoreGfx.h @@ -8,20 +8,20 @@ #include <NewKit/Defines.h> -#define fb_init() Kernel::SizeT kCGCursor = 0 +#define fb_init() Kernel::UInt32 kCGCursor = 0 #define fb_color(R, G, B) RGB(R, G, B) -#define fb_get_clear_clr() fb_color(0x20, 0x20, 0x20) +#define fb_get_clear_clr() RGB(0x20, 0x20, 0x20) #define fb_clear() kCGCursor = 0UL #ifdef __NE_AMD64__ /// @brief Performs Alpha drawing on the framebuffer. #define FBDrawBitMapInRegionA(reg_ptr, height, width, base_x, base_y) \ - for (Kernel::SizeT i = base_x; i < (width + base_x); ++i) \ + for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) \ { \ - for (Kernel::SizeT u = base_y; u < (height + base_y); ++u) \ + for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) \ { \ *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ @@ -34,9 +34,9 @@ /// @brief Performs drawing on the framebuffer. #define FBDrawBitMapInRegion(reg_ptr, height, width, base_x, base_y) \ - for (Kernel::SizeT i = base_x; i < (width + base_x); ++i) \ + for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) \ { \ - for (Kernel::SizeT u = base_y; u < (height + base_y); ++u) \ + for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) \ { \ *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ @@ -48,9 +48,9 @@ } #define FBDrawBitMapInRegionToRgn(_Rgn, reg_ptr, height, width, base_x, base_y) \ - for (Kernel::SizeT i = base_x; i < (width + base_x); ++i) \ + for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) \ { \ - for (Kernel::SizeT u = base_y; u < (height + base_y); ++u) \ + for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) \ { \ *(((Kernel::UInt32*)(_Rgn + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ @@ -63,9 +63,9 @@ /// @brief Cleans a resource. #define FBClearRegion(height, width, base_x, base_y) \ - for (Kernel::SizeT i = base_x; i < (width + base_x); ++i) \ + for (Kernel::UInt32 i = base_x; i < (width + base_x); ++i) \ { \ - for (Kernel::SizeT u = base_y; u < (height + base_y); ++u) \ + for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) \ { \ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ @@ -76,9 +76,9 @@ /// @brief Draws inside a zone. #define FBDrawInRegion(clr, height, width, base_x, base_y) \ - for (Kernel::SizeT x_base = base_x; x_base < (width + base_x); ++x_base) \ + for (Kernel::UInt32 x_base = base_x; x_base < (width + base_x); ++x_base) \ { \ - for (Kernel::SizeT y_base = base_y; y_base < (height + base_y); ++y_base) \ + for (Kernel::UInt32 y_base = base_y; y_base < (height + base_y); ++y_base) \ { \ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ @@ -89,9 +89,9 @@ /// @brief Draws inside a zone. #define FBDrawInRegionToRgn(_Rgn, clr, height, width, base_x, base_y) \ - for (Kernel::SizeT x_base = base_x; x_base < (width + base_x); ++x_base) \ + for (Kernel::UInt32 x_base = base_x; x_base < (width + base_x); ++x_base) \ { \ - for (Kernel::SizeT y_base = base_y; y_base < (height + base_y); ++y_base) \ + for (Kernel::UInt32 y_base = base_y; y_base < (height + base_y); ++y_base) \ { \ *(((volatile Kernel::UInt32*)(_Rgn + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ @@ -102,9 +102,9 @@ } #define FBDrawInRegionA(clr, height, width, base_x, base_y) \ - for (Kernel::SizeT x_base = base_x; x_base < (width + base_x); ++x_base) \ + for (Kernel::UInt32 x_base = base_x; x_base < (width + base_x); ++x_base) \ { \ - for (Kernel::SizeT y_base = base_y; y_base < (height + base_y); ++y_base) \ + for (Kernel::UInt32 y_base = base_y; y_base < (height + base_y); ++y_base) \ { \ *(((volatile Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * \ diff --git a/dev/modules/CoreGfx/CoreWindow.h b/dev/modules/CoreGfx/CoreWindow.h new file mode 100644 index 00000000..f925eecd --- /dev/null +++ b/dev/modules/CoreGfx/CoreWindow.h @@ -0,0 +1,75 @@ +#pragma once + +#include <modules/CoreGfx/CoreGfx.h> +#include <modules/CoreGfx/TextGfx.h> + +namespace UI +{ + struct UIRect final + { + Kernel::UInt32 x, y, height, width; + }; + + inline void draw_beveled_rect(const UIRect& rect, Kernel::UInt32 topLeftColor, Kernel::UInt32 bottomRightColor) + { + // Top edge + FBDrawInRegion(topLeftColor, rect.height, 1, rect.y, rect.x); + // Left edge + FBDrawInRegion(topLeftColor, 1, rect.width, rect.y, rect.x); + + // Bottom edge + FBDrawInRegion(bottomRightColor, rect.height, 1, rect.y + rect.width - 1, rect.x); + // Right edge + FBDrawInRegion(bottomRightColor, 1, rect.width, rect.y, rect.x + rect.height - 1); + } + + inline void draw_close_button(Kernel::UInt32 x, Kernel::UInt32 y) + { + const Kernel::UInt32 border = fb_color(0x00, 0x00, 0x00); + const Kernel::UInt32 fill = fb_color(0xD0, 0xD0, 0xD0); + + // A simple square for close button, 10x10 px + FBDrawInRegion(border, 10, 10, y, x); // Outer border + FBDrawInRegion(fill, 8, 8, y + 1, x + 1); // Inner fill + } + + inline void draw_title_bar(const UIRect& rect, const char* title) + { + const Kernel::Int32 barHeight = 22; + + Kernel::UInt32 lightEdge = fb_color(0xF0, 0xF0, 0xF0); // Light gray top + Kernel::UInt32 darkEdge = fb_color(0x40, 0x40, 0x40); // Shadow + Kernel::UInt32 fillColor = fb_color(0xA0, 0xA0, 0xA0); // Mid-gray + + // Title bar fill + FBDrawInRegion(fillColor, rect.height - 2, barHeight, rect.y + 1, rect.x + 1); + + // Beveled edges (top, left bright; right, bottom dark) + UIRect bevel = {rect.x + 1, rect.y + 1, rect.height - 2, barHeight}; + draw_beveled_rect(bevel, lightEdge, darkEdge); + + // Title text + fb_render_string(title, rect.y + 8, rect.x + 24, fb_color(0x00, 0x00, 0x00)); + + // Close button + draw_close_button(rect.x + 6, rect.y + 6); + } + + inline void draw_window(const UIRect& rect, const Char* title) + { + Kernel::UInt32 windowFill = fb_color(0xC0, 0xC0, 0xC0); // Body color + Kernel::UInt32 borderDark = fb_color(0x60, 0x60, 0x60); + Kernel::UInt32 borderHighlight = fb_color(0xE0, 0xE0, 0xE0); + + // Fill window body (excluding title bar) + const Kernel::Int32 titleBarHeight = 22; + + FBDrawInRegion(windowFill, rect.height - 2, rect.width - titleBarHeight - 1, rect.y + titleBarHeight + 1, rect.x + 1); + + // Full window bevel border + draw_beveled_rect(rect, borderHighlight, borderDark); + + // Title bar + draw_title_bar(rect, title); + } +}
\ No newline at end of file |
