diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-28 20:08:05 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-28 20:08:05 +0200 |
| commit | 7fdd5033ec93694b57d3471ff9a78164ec76943d (patch) | |
| tree | a15ce8da17914ac4239ba5d2576c156ab8588a17 | |
| parent | 421db65331663304466577b7187780d9eba18077 (diff) | |
Update graphics stack API.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
| -rw-r--r-- | dev/corecg/corecg.hxx | 239 | ||||
| -rw-r--r-- | dev/corecg/src/corecg_main.cxx (renamed from dev/corecg/src/corecg.cxx) | 2 | ||||
| -rw-r--r-- | dev/corecg/src/corecg_pdf.cxx | 7 | ||||
| -rw-r--r-- | dev/corecg/wm.hxx | 247 | ||||
| -rw-r--r-- | dev/zka/NewKit/Defines.hxx | 2 |
5 files changed, 256 insertions, 241 deletions
diff --git a/dev/corecg/corecg.hxx b/dev/corecg/corecg.hxx deleted file mode 100644 index 9a315b1d..00000000 --- a/dev/corecg/corecg.hxx +++ /dev/null @@ -1,239 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include <Modules/CoreCG/Desktop.hxx> - -namespace CG::WM -{ - struct CG_WINDOW_STRUCT; - - enum - { - cWndFlagNoShow = 0x02, - cWndFlagButton = 0x04, - cWndFlagWindow = 0x06, - cWndFlagButtonSelect = 0x08, - cWndFlagNoCloseButton = 0x010, - cWndFlagCloseButton = 0x012, - cWndFlagSelectBox = 0x014, - cWndFlagInputBox = 0x016, - cWndFlagCheckBoxFirstState = 0x018, - cWndFlagCheckBoxTwoState = 0x018, - cWndFlagCheckBoxThreeState = 0x018, - }; - - struct CG_WINDOW_STRUCT final - { - static constexpr auto cChildElementCount = 4096; - - Char w_window_name[255]{0}; - Char w_class_name[255]{0}; - Int32 w_type{0}; - Int32 w_sub_type{0}; - Int32 w_x{0}; - Int32 w_y{0}; - Int32 w_w{0}; - Int32 w_h{0}; - Size w_child_count{0}; - struct CG_WINDOW_STRUCT* w_child_list[cChildElementCount]{0}; - struct CG_WINDOW_STRUCT* w_parent_wnd{nullptr}; - UInt32* w_canvas{nullptr}; - Bool w_needs_repaint{false}; - }; - - typedef struct CG_WINDOW_STRUCT CG_WINDOW_STRUCT; - - inline struct CG_WINDOW_STRUCT* CGCreateWindow(Int32 kind, const Char* window_name, const Char* class_name, Int32 x, Int32 y, Int32 width, Int32 height, CG_WINDOW_STRUCT* parent = nullptr) - { - CG_WINDOW_STRUCT* wnd = new CG_WINDOW_STRUCT(); - - if (!wnd) - { - ErrLocal() = kErrorHeapOutOfMemory; - return nullptr; - } - - rt_copy_memory((VoidPtr)window_name, wnd->w_window_name, rt_string_len(window_name)); - rt_copy_memory((VoidPtr)class_name, wnd->w_class_name, rt_string_len(class_name)); - - if (parent) - { - wnd->w_parent_wnd = parent; - - ++wnd->w_parent_wnd->w_child_count; - wnd->w_parent_wnd->w_child_list[wnd->w_parent_wnd->w_child_count - 1] = wnd; - } - - wnd->w_sub_type = 0; - wnd->w_type = kind; - wnd->w_x = x; - wnd->w_y = y; - - wnd->w_w = width; - wnd->w_h = height; - - wnd->w_canvas = new UInt32[width * height]; - rt_set_memory(wnd->w_canvas, CGColor(0xF5, 0xF5, 0xF5), width * height); - - return wnd; - } - - /// \brief Destroys a window and it's contents. - inline Bool CGDestroyWindow(struct CG_WINDOW_STRUCT* wnd) - { - if (wnd) - { - if (!mm_is_valid_heap(wnd)) - { - wnd = nullptr; - return true; - } - - wnd->w_needs_repaint = No; - - for (SizeT index = 0UL; index < wnd->w_child_count; ++index) - { - CGDestroyWindow(wnd->w_child_list[index]); - } - - delete wnd; - wnd = nullptr; - - return true; - } - - return false; - } - - inline Kernel::Void CGDrawStringToWnd(CG_WINDOW_STRUCT* wnd, const Kernel::Char* text, Kernel::Int32 y_dst, Kernel::Int32 x_dst, Kernel::Int32 color) - { - y_dst += wnd->w_y + cFlatCtrlsHeight; - x_dst += wnd->w_x; - - if (y_dst > (wnd->w_h + wnd->w_y)) - return; - - for (Kernel::SizeT i = 0; text[i] != 0; ++i) - { - if (x_dst > (wnd->w_w + wnd->w_x)) - break; - - CGRenderStringFromBitMap(&cFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, y_dst, x_dst, color); - x_dst += FONT_SIZE_Y; - } - } - - inline SizeT CGDrawWindowList(CG_WINDOW_STRUCT** wnd, SizeT wnd_cnt) - { - if (wnd_cnt == 0 || - !wnd) - return 0; - - SizeT cnt = 0; - - for (SizeT index = 0; index < wnd_cnt; ++index) - { - if (!wnd[index] || - (wnd[index]->w_type == cWndFlagNoShow) || - !wnd[index]->w_needs_repaint) - continue; - - CGInit(); - - wnd[index]->w_needs_repaint = false; - - if (CGAccessibilty::The().Width() < wnd[index]->w_x) - { - if ((wnd[index]->w_x - CGAccessibilty::The().Width()) > 1) - { - wnd[index]->w_x -= wnd[index]->w_x - CGAccessibilty::The().Width(); - } - else - { - wnd[index]->w_x = 0; - } - } - - if (CGAccessibilty::The().Height() < wnd[index]->w_y) - { - if ((wnd[index]->w_y - CGAccessibilty::The().Height()) > 1) - { - wnd[index]->w_y -= wnd[index]->w_y - CGAccessibilty::The().Width(); - } - else - { - wnd[index]->w_y = 0; - } - } - - ++cnt; - - // Draw fake controls, just for the looks of it (WINDOW ONLY) - if (wnd[index]->w_type == cWndFlagWindow) - { - CGDrawBitMapInRegion(wnd[index]->w_canvas, wnd[index]->w_h, wnd[index]->w_w, wnd[index]->w_y, wnd[index]->w_x); - CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w, cFlatCtrlsHeight, wnd[index]->w_y, wnd[index]->w_x); - - if (wnd[index]->w_sub_type != cWndFlagNoCloseButton) - { - if (wnd[index]->w_sub_type == cWndFlagCloseButton) - { - CGDrawBitMapInRegion(FlatControlsClose, cFlatCtrlsHeight, cFlatCtrlsWidth, wnd[index]->w_y, wnd[index]->w_x + wnd[index]->w_w - cFlatCtrlsWidth); - } - else - { - CGDrawBitMapInRegion(FlatControls, cFlatCtrlsHeight, cFlatCtrlsWidth, wnd[index]->w_y, wnd[index]->w_x + wnd[index]->w_w - cFlatCtrlsWidth); - } - } - - CGDrawString(wnd[index]->w_window_name, wnd[index]->w_y + 8, wnd[index]->w_x + 8, CGColor(0x00, 0x00, 0x00)); - } - /// @note buttons in this library are dynamic, it's because we want to avoid as much as computations as possible. - /// (Such as getting the middle coordinates of a button, to center the text.) - else if (wnd[index]->w_type == cWndFlagButtonSelect) - { - auto x_center = wnd[index]->w_x + 6; - auto y_center = wnd[index]->w_y + 7; - - CGDrawInRegion(CGColor(0xD3, 0x74, 0x00), wnd[index]->w_w + 1, wnd[index]->w_h + 1, wnd[index]->w_y, wnd[index]->w_x); - CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w - 1, wnd[index]->w_h - 1, wnd[index]->w_y + 1, wnd[index]->w_x + 1); - CGDrawStringToWnd(wnd[index], wnd[index]->w_window_name, y_center, x_center, CGColor(0x00, 0x00, 0x00)); - } - else if (wnd[index]->w_type == cWndFlagButton) - { - auto x_center = wnd[index]->w_x + 6; - auto y_center = wnd[index]->w_y + 7; - - CGDrawInRegion(CGColor(0xDC, 0xDC, 0xDC), wnd[index]->w_w + 1, wnd[index]->w_h + 1, wnd[index]->w_y, wnd[index]->w_x); - CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w - 1, wnd[index]->w_h - 1, wnd[index]->w_y + 1, wnd[index]->w_x + 1); - CGDrawString(wnd[index]->w_window_name, y_center, x_center, CGColor(0x00, 0x00, 0x00)); - } - - CGFini(); - - // draw child windows and controls. - // doesn't have to be a window, enabling then windows in windows. - - for (SizeT child = 0; child < wnd[index]->w_child_count; ++child) - { - wnd[index]->w_child_list[child]->w_x += wnd[index]->w_x; - wnd[index]->w_child_list[child]->w_y += wnd[index]->w_y + cFlatCtrlsHeight; - - if ((wnd[index]->w_child_list[child]->w_w + wnd[index]->w_child_list[child]->w_x) > (wnd[index]->w_x + wnd[index]->w_w) || - (wnd[index]->w_child_list[child]->w_h + wnd[index]->w_child_list[child]->w_y) > (wnd[index]->w_y + wnd[index]->w_h)) - continue; - - CGDrawWindowList(&wnd[index]->w_child_list[child], 1); - } - - CGFini(); - } - - return cnt; - } -} // namespace CG::WM diff --git a/dev/corecg/src/corecg.cxx b/dev/corecg/src/corecg_main.cxx index d964888b..c4039db2 100644 --- a/dev/corecg/src/corecg.cxx +++ b/dev/corecg/src/corecg_main.cxx @@ -7,7 +7,7 @@ ------------------------------------------- */ -#include <corecg/corecg.hxx> +#include <corecg/wm.hxx> /** @brief CoreCG main, ZWM acts a proxy to the Installed GPU Driver. */ CG::Int32 ModuleMain(CG::Void) diff --git a/dev/corecg/src/corecg_pdf.cxx b/dev/corecg/src/corecg_pdf.cxx new file mode 100644 index 00000000..ac785ff8 --- /dev/null +++ b/dev/corecg/src/corecg_pdf.cxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include <corecg/pdf.hxx> diff --git a/dev/corecg/wm.hxx b/dev/corecg/wm.hxx new file mode 100644 index 00000000..c33c3dde --- /dev/null +++ b/dev/corecg/wm.hxx @@ -0,0 +1,247 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <Modules/CoreCG/Desktop.hxx> + +namespace CG::WM +{ + struct ICGWindowViewport; + struct ICGWindowManager; + + enum + { + cWndFlagNoShow = 0x02, + cWndFlagButton = 0x04, + cWndFlagWindow = 0x06, + cWndFlagButtonSelect = 0x08, + cWndFlagNoCloseButton = 0x010, + cWndFlagCloseButton = 0x012, + cWndFlagSelectBox = 0x014, + cWndFlagInputBox = 0x016, + cWndFlagCheckBoxFirstState = 0x018, + cWndFlagCheckBoxTwoState = 0x018, + cWndFlagCheckBoxThreeState = 0x018, + }; + + struct ICGWindowViewport final + { + private: + friend ICGWindowManager; + + STATIC constexpr auto cChildElementCount = 4096; + + Char w_window_name[255]{0}; + Char w_class_name[255]{0}; + Int32 w_type{0}; + Int32 w_sub_type{0}; + Int32 w_x{0}; + Int32 w_y{0}; + Int32 w_w{0}; + Int32 w_h{0}; + Size w_child_count{0}; + struct ICGWindowViewport* w_child_list[cChildElementCount]{0}; + struct ICGWindowViewport* w_parent_wnd{nullptr}; + UInt32* w_canvas{nullptr}; + Bool w_needs_repaint{false}; + }; + + class ICGWindowManager + { + public: + struct ICGWindowViewport* Create(Int32 kind, const Char* window_name, const Char* class_name, Int32 x, Int32 y, Int32 width, Int32 height, ICGWindowViewport* parent = nullptr) + { + ICGWindowViewport* wnd = new ICGWindowViewport(); + + if (!wnd) + { + ErrLocal() = kErrorHeapOutOfMemory; + return nullptr; + } + + rt_copy_memory((VoidPtr)window_name, wnd->w_window_name, rt_string_len(window_name)); + rt_copy_memory((VoidPtr)class_name, wnd->w_class_name, rt_string_len(class_name)); + + if (parent) + { + wnd->w_parent_wnd = parent; + + ++wnd->w_parent_wnd->w_child_count; + wnd->w_parent_wnd->w_child_list[wnd->w_parent_wnd->w_child_count - 1] = wnd; + } + + wnd->w_sub_type = 0; + wnd->w_type = kind; + wnd->w_x = x; + wnd->w_y = y; + + wnd->w_w = width; + wnd->w_h = height; + + wnd->w_canvas = new UInt32[width * height]; + rt_set_memory(wnd->w_canvas, CGColor(0xF5, 0xF5, 0xF5), width * height); + + return wnd; + } + + /// \brief Destroys a window and it's contents. + Bool Destroy(struct ICGWindowViewport* wnd) + { + if (wnd) + { + if (!mm_is_valid_heap(wnd)) + { + wnd = nullptr; + return true; + } + + wnd->w_needs_repaint = No; + + for (SizeT index = 0UL; index < wnd->w_child_count; ++index) + { + this->Destroy(wnd->w_child_list[index]); + } + + delete wnd; + wnd = nullptr; + + return true; + } + + return false; + } + + Kernel::Void DrawTextToWnd(ICGWindowViewport* wnd, const Kernel::Char* text, Kernel::Int32 y_dst, Kernel::Int32 x_dst, Kernel::Int32 color) + { + y_dst += wnd->w_y + cFlatCtrlsHeight; + x_dst += wnd->w_x; + + if (y_dst > (wnd->w_h + wnd->w_y)) + return; + + for (Kernel::SizeT i = 0; text[i] != 0; ++i) + { + if (x_dst > (wnd->w_w + wnd->w_x)) + break; + + CGRenderStringFromBitMap(&cFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, y_dst, x_dst, color); + x_dst += FONT_SIZE_Y; + } + } + + SizeT Draw(ICGWindowViewport** wnd, SizeT wnd_cnt) + { + if (wnd_cnt == 0 || + !wnd) + return 0; + + SizeT cnt = 0; + + for (SizeT index = 0; index < wnd_cnt; ++index) + { + if (!wnd[index] || + (wnd[index]->w_type == cWndFlagNoShow) || + !wnd[index]->w_needs_repaint) + continue; + + CGInit(); + + wnd[index]->w_needs_repaint = false; + + if (CGAccessibilty::The().Width() < wnd[index]->w_x) + { + if ((wnd[index]->w_x - CGAccessibilty::The().Width()) > 1) + { + wnd[index]->w_x -= wnd[index]->w_x - CGAccessibilty::The().Width(); + } + else + { + wnd[index]->w_x = 0; + } + } + + if (CGAccessibilty::The().Height() < wnd[index]->w_y) + { + if ((wnd[index]->w_y - CGAccessibilty::The().Height()) > 1) + { + wnd[index]->w_y -= wnd[index]->w_y - CGAccessibilty::The().Width(); + } + else + { + wnd[index]->w_y = 0; + } + } + + ++cnt; + + // Draw fake controls, just for the looks of it (WINDOW ONLY) + if (wnd[index]->w_type == cWndFlagWindow) + { + CGDrawBitMapInRegion(wnd[index]->w_canvas, wnd[index]->w_h, wnd[index]->w_w, wnd[index]->w_y, wnd[index]->w_x); + CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w, cFlatCtrlsHeight, wnd[index]->w_y, wnd[index]->w_x); + + if (wnd[index]->w_sub_type != cWndFlagNoCloseButton) + { + if (wnd[index]->w_sub_type == cWndFlagCloseButton) + { + CGDrawBitMapInRegion(FlatControlsClose, cFlatCtrlsHeight, cFlatCtrlsWidth, wnd[index]->w_y, wnd[index]->w_x + wnd[index]->w_w - cFlatCtrlsWidth); + } + else + { + CGDrawBitMapInRegion(FlatControls, cFlatCtrlsHeight, cFlatCtrlsWidth, wnd[index]->w_y, wnd[index]->w_x + wnd[index]->w_w - cFlatCtrlsWidth); + } + } + + CGDrawString(wnd[index]->w_window_name, wnd[index]->w_y + 8, wnd[index]->w_x + 8, CGColor(0x00, 0x00, 0x00)); + } + /// @note buttons in this library are dynamic, it's because we want to avoid as much as computations as possible. + /// (Such as getting the middle coordinates of a button, to center the text.) + else if (wnd[index]->w_type == cWndFlagButtonSelect) + { + auto x_center = wnd[index]->w_w / 2; + auto y_center = wnd[index]->w_h / 2; + + CGDrawInRegion(CGColor(0xD3, 0x74, 0x00), wnd[index]->w_w + 1, wnd[index]->w_h + 1, wnd[index]->w_y, wnd[index]->w_x); + CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w - 1, wnd[index]->w_h - 1, wnd[index]->w_y + 1, wnd[index]->w_x + 1); + + this->DrawTextToWnd(wnd[index], wnd[index]->w_window_name, y_center, x_center, CGColor(0x00, 0x00, 0x00)); + } + else if (wnd[index]->w_type == cWndFlagButton) + { + auto x_center = wnd[index]->w_w / 2; + auto y_center = wnd[index]->w_h / 2; + + CGDrawInRegion(CGColor(0xDC, 0xDC, 0xDC), wnd[index]->w_w + 1, wnd[index]->w_h + 1, wnd[index]->w_y, wnd[index]->w_x); + CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w - 1, wnd[index]->w_h - 1, wnd[index]->w_y + 1, wnd[index]->w_x + 1); + + this->DrawTextToWnd(wnd[index], wnd[index]->w_window_name, y_center, x_center, CGColor(0x00, 0x00, 0x00)); + } + + CGFini(); + + // draw child windows and controls. + // doesn't have to be a window, enabling then windows in windows. + + for (SizeT child = 0; child < wnd[index]->w_child_count; ++child) + { + wnd[index]->w_child_list[child]->w_x += wnd[index]->w_x; + wnd[index]->w_child_list[child]->w_y += wnd[index]->w_y + cFlatCtrlsHeight; + + if ((wnd[index]->w_child_list[child]->w_w + wnd[index]->w_child_list[child]->w_x) > (wnd[index]->w_x + wnd[index]->w_w) || + (wnd[index]->w_child_list[child]->w_h + wnd[index]->w_child_list[child]->w_y) > (wnd[index]->w_y + wnd[index]->w_h)) + continue; + + this->Draw(&wnd[index]->w_child_list[child], 1); + } + + CGFini(); + } + + return cnt; + } + }; +} // namespace CG::WM diff --git a/dev/zka/NewKit/Defines.hxx b/dev/zka/NewKit/Defines.hxx index d6049afd..a758effc 100644 --- a/dev/zka/NewKit/Defines.hxx +++ b/dev/zka/NewKit/Defines.hxx @@ -12,7 +12,7 @@ #define NEWKIT_VERSION_CB 0x0101 #if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__) -#include <crt/__ndk_defines.hxx> +#include <crt/defines.hxx> #endif #ifdef __has_feature |
