diff options
Diffstat (limited to 'dev/Modules')
| -rw-r--r-- | dev/Modules/FB/AccessibilityMgr.h (renamed from dev/Modules/FB/Accessibility.h) | 0 | ||||
| -rw-r--r-- | dev/Modules/FB/AppearanceMgr.h | 266 | ||||
| -rw-r--r-- | dev/Modules/FB/KWindow.h | 242 | ||||
| -rw-r--r-- | dev/Modules/FB/Math.h | 10 | ||||
| -rw-r--r-- | dev/Modules/FB/Text.h | 8 |
5 files changed, 277 insertions, 249 deletions
diff --git a/dev/Modules/FB/Accessibility.h b/dev/Modules/FB/AccessibilityMgr.h index 843ad9a7..843ad9a7 100644 --- a/dev/Modules/FB/Accessibility.h +++ b/dev/Modules/FB/AccessibilityMgr.h diff --git a/dev/Modules/FB/AppearanceMgr.h b/dev/Modules/FB/AppearanceMgr.h new file mode 100644 index 00000000..fd14e3d3 --- /dev/null +++ b/dev/Modules/FB/AppearanceMgr.h @@ -0,0 +1,266 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include <Modules/FB/AccessibilityMgr.h> +#include <KernelKit/Heap.h> +#include <KernelKit/UserProcessScheduler.h> +#include <KernelKit/LPC.h> +#include <NewKit/Defines.h> +#include <NewKit/Utils.h> +#include <Modules/FB/FB.h> +#include <Modules/FB/Rsrc/WndControls.rsrc> +#include <Modules/FB/Text.h> + +namespace CG +{ + using namespace Kernel; + + struct UIObject; + + enum + { + kUIFlagNoShow = 0x02, + kUIFlagButton = 0x04, + kUIFlagWindow = 0x06, + kUIFlagButtonSelect = 0x08, + kUIFlagHideCloseControl = 0x010, + kUIFlagCloseControlSelect = 0x012, + }; + + struct UIObject final + { + 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}; + Int32 w_display_ptr_w{0}; + Int32 w_display_ptr_h{0}; + SizeT w_child_count{0}; + struct UIObject* w_child_elements[255]{0}; + struct UIObject* w_parent{nullptr}; + UInt32* w_display_ptr{nullptr}; + Bool w_needs_repaint{false}; + + Void (*w_display_custom_draw)(struct UIObject* am_win); + }; + + typedef struct UIObject UIObject; + + inline Void ui_draw_background() noexcept + { + cg_init(); + + CGDrawInRegion(cg_get_clear_clr(), CG::UIAccessibilty::Height(), CG::UIAccessibilty::Width(), + 0, 0); + + cg_fini(); + } + + inline struct UIObject* ui_create_object(Int32 kind, const Char* obj_name, const Char* class_name, Int32 x, Int32 y, Int32 width, Int32 height, UIObject* parent = nullptr) + { + UIObject* obj = new UIObject(); + + if (!obj) + { + err_local_get() = kErrorHeapOutOfMemory; + return nullptr; + } + + rt_copy_memory((VoidPtr)obj_name, obj->w_window_name, rt_string_len(obj_name)); + rt_copy_memory((VoidPtr)class_name, obj->w_class_name, rt_string_len(class_name)); + + if (parent) + { + obj->w_parent = parent; + + ++obj->w_parent->w_child_count; + obj->w_parent->w_child_elements[obj->w_parent->w_child_count - 1] = obj; + } + + obj->w_sub_type = 0; + obj->w_type = kind; + obj->w_x = x; + obj->w_y = y; + obj->w_display_ptr = nullptr; + obj->w_w = width; + obj->w_h = height; + obj->w_display_custom_draw = nullptr; + + return obj; + } + + inline bool ui_destroy_object(struct UIObject* obj) + { + if (obj) + { + delete obj; + + if (!mm_is_valid_heap(obj)) + { + obj = nullptr; + return false; + } + + obj = nullptr; + return true; + } + + return false; + } + + inline Kernel::Void ui_render_text(UIObject* obj, const Kernel::Char* text, Kernel::Int32 y_dst, Kernel::Int32 x_dst, Kernel::Int32 color) + { + y_dst += obj->w_y + FLAT_CONTROLS_HEIGHT; + x_dst += obj->w_x; + + if (y_dst > (obj->w_h + obj->w_y)) + return; + + for (Kernel::SizeT i = 0; text[i] != 0; ++i) + { + if (x_dst > (obj->w_w + obj->w_x)) + break; + + fb_render_string_for_bitmap(&kFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, y_dst, x_dst, color); + x_dst += FONT_SIZE_X; + } + } + + inline SizeT ui_render_object(UIObject* obj) + { + if (!obj || + (obj->w_type == kUIFlagNoShow) || + !obj->w_needs_repaint) + return 1; + + cg_init(); + + obj->w_needs_repaint = false; + + kcout << "Begin paint\r"; + + if (UIAccessibilty::Width() < obj->w_x) + { + if ((obj->w_x - UIAccessibilty::Width()) > 1) + { + obj->w_x -= obj->w_x - UIAccessibilty::Width(); + } + else + { + obj->w_x = 0; + } + } + + if (UIAccessibilty::Height() < obj->w_y) + { + if ((obj->w_y - UIAccessibilty::Height()) > 1) + { + obj->w_y -= obj->w_y - UIAccessibilty::Width(); + } + else + { + obj->w_y = 0; + } + } + + // Draw fake controls, just for the looks of it (WINDOW ONLY) + if (obj->w_type == kUIFlagWindow) + { + kcout << "Begin paint window\r"; + + if (!obj->w_display_custom_draw) + { + if (obj->w_display_ptr) + { + CGDrawInRegion(cg_color(0xDF, 0xDF, 0xDF), obj->w_h, obj->w_w, obj->w_x, obj->w_y); + CGDrawBitMapInRegion(obj->w_display_ptr, obj->w_display_ptr_h, obj->w_display_ptr_w, obj->w_x, obj->w_y); + } + else + { + CGDrawInRegion(cg_color(0xDF, 0xDF, 0xDF), obj->w_w, obj->w_h, obj->w_y, obj->w_x); + } + + CGDrawInRegion(cg_color(0xFF, 0xFF, 0xFF), obj->w_w, FLAT_CONTROLS_HEIGHT, obj->w_y, obj->w_x); + + if (obj->w_sub_type != kUIFlagHideCloseControl) + { + CGDrawBitMapInRegion(zka_flat_controls, FLAT_CONTROLS_HEIGHT, FLAT_CONTROLS_WIDTH, obj->w_y, obj->w_x + obj->w_w - FLAT_CONTROLS_WIDTH); + } + else if (obj->w_sub_type == kUIFlagCloseControlSelect) + { + CGDrawBitMapInRegion(zka_flat_controls_active, FLAT_CONTROLS_CLOSEHEIGHT, FLAT_CONTROLS_CLOSEWIDTH, obj->w_y, obj->w_x + obj->w_w - FLAT_CONTROLS_WIDTH); + } + + fb_render_string(obj->w_window_name, obj->w_x + 8, obj->w_y + 8, cg_color(0x00, 0x00, 0x00)); + } + else + { + obj->w_display_custom_draw(obj); + } + } + /// @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 (obj->w_type == kUIFlagButtonSelect) + { + auto x_center = obj->w_x + 6; + auto y_center = obj->w_y + 7; + + if (!obj->w_display_custom_draw) + { + CGDrawInRegion(cg_color(0xD3, 0x74, 0x00), obj->w_w + 1, obj->w_h + 1, obj->w_x, obj->w_y); + CGDrawInRegion(cg_color(0xFF, 0xFF, 0xFF), obj->w_w - 1, obj->w_h - 1, obj->w_x + 1, obj->w_y + 1); + ui_render_text(obj, obj->w_window_name, y_center, x_center, cg_color(0x00, 0x00, 0x00)); + } + else + { + obj->w_display_custom_draw(obj); + } + } + else if (obj->w_type == kUIFlagButton) + { + auto x_center = obj->w_x + 6; + auto y_center = obj->w_y + 7; + + if (!obj->w_display_custom_draw) + { + CGDrawInRegion(cg_color(0xDC, 0xDC, 0xDC), obj->w_w + 1, obj->w_h + 1, obj->w_y, obj->w_x); + CGDrawInRegion(cg_color(0xFF, 0xFF, 0xFF), obj->w_w - 1, obj->w_h - 1, obj->w_y + 1, obj->w_x + 1); + fb_render_string(obj->w_window_name, y_center, x_center, cg_color(0x00, 0x00, 0x00)); + } + else + { + obj->w_display_custom_draw(obj); + } + } + + cg_fini(); + + // draw child windows and controls. + // doesn't have to be a window, enabling then windows in windows. + + for (SizeT child = 0; child < obj->w_child_count; ++child) + { + obj->w_child_elements[child]->w_x += obj->w_x; + obj->w_child_elements[child]->w_y += obj->w_y + FLAT_CONTROLS_HEIGHT; + + if ((obj->w_child_elements[child]->w_w + obj->w_child_elements[child]->w_x) > (obj->w_x + obj->w_w) || + (obj->w_child_elements[child]->w_h + obj->w_child_elements[child]->w_y) > (obj->w_y + obj->w_h)) + continue; + + ui_render_object(obj->w_child_elements[child]); + } + + cg_fini(); + + return 0; + } +} // namespace CG diff --git a/dev/Modules/FB/KWindow.h b/dev/Modules/FB/KWindow.h deleted file mode 100644 index f84e36d4..00000000 --- a/dev/Modules/FB/KWindow.h +++ /dev/null @@ -1,242 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include <Modules/FB/Accessibility.h> -#include <KernelKit/Heap.h> -#include <KernelKit/UserProcessScheduler.h> -#include <KernelKit/LPC.h> -#include <NewKit/Defines.h> -#include <NewKit/Utils.h> -#include <Modules/FB/FB.h> -#include <Modules/FB/Rsrc/WndControls.rsrc> -#include <Modules/FB/Text.h> - -namespace CG -{ - using namespace Kernel; - - struct ML_WINDOW_STRUCT; - - enum - { - kWndFlagNoShow = 0x02, - kWndFlagButton = 0x04, - kWndFlagWindow = 0x06, - kWndFlagButtonSelect = 0x08, - kWndFlagHideCloseControl = 0x010, - kWndFlagCloseControlSelect = 0x012, - }; - - struct ML_WINDOW_STRUCT final - { - 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}; - Int32 w_display_ptr_w{0}; - Int32 w_display_ptr_h{0}; - SizeT w_child_count{0}; - struct ML_WINDOW_STRUCT* w_child_elements[255]{0}; - struct ML_WINDOW_STRUCT* w_parent{nullptr}; - UInt32* w_display_ptr{nullptr}; - Bool w_needs_repaint{false}; - }; - - typedef struct ML_WINDOW_STRUCT ML_WINDOW_STRUCT; - - inline Void CGDrawBackground() noexcept - { - cg_init(); - - CGDrawInRegion(cg_get_clear_clr(), CG::UIAccessibilty::Height(), CG::UIAccessibilty::Width(), - 0, 0); - - cg_fini(); - } - - inline struct ML_WINDOW_STRUCT* CGCreateWindow(Int32 kind, const Char* window_name, const Char* class_name, Int32 x, Int32 y, Int32 width, Int32 height, ML_WINDOW_STRUCT* parent = nullptr) - { - ML_WINDOW_STRUCT* wnd = new ML_WINDOW_STRUCT(); - - if (!wnd) - { - err_local_get() = 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 = parent; - - ++wnd->w_parent->w_child_count; - wnd->w_parent->w_child_elements[wnd->w_parent->w_child_count - 1] = wnd; - } - - wnd->w_sub_type = 0; - wnd->w_type = kind; - wnd->w_x = x; - wnd->w_y = y; - wnd->w_display_ptr = nullptr; - wnd->w_w = width; - wnd->w_h = height; - - return wnd; - } - - inline bool CGDestroyWindow(struct ML_WINDOW_STRUCT* wnd) - { - if (wnd) - { - delete wnd; - - if (!mm_is_valid_heap(wnd)) - { - wnd = nullptr; - return true; - } - - wnd = nullptr; - } - - return false; - } - - inline Kernel::Void CGDrawStringToWnd(ML_WINDOW_STRUCT* wnd, const Kernel::Char* text, Kernel::Int32 y_dst, Kernel::Int32 x_dst, Kernel::Int32 color) - { - y_dst += wnd->w_y + FLAT_CONTROLS_HEIGHT; - 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 CGDrawWindow(ML_WINDOW_STRUCT* wnd) - { - if (!wnd || - (wnd->w_type == kWndFlagNoShow) || - !wnd->w_needs_repaint) - return 1; - - cg_init(); - - wnd->w_needs_repaint = false; - - kcout << "Begin paint\r"; - - if (UIAccessibilty::Width() < wnd->w_x) - { - if ((wnd->w_x - UIAccessibilty::Width()) > 1) - { - wnd->w_x -= wnd->w_x - UIAccessibilty::Width(); - } - else - { - wnd->w_x = 0; - } - } - - if (UIAccessibilty::Height() < wnd->w_y) - { - if ((wnd->w_y - UIAccessibilty::Height()) > 1) - { - wnd->w_y -= wnd->w_y - UIAccessibilty::Width(); - } - else - { - wnd->w_y = 0; - } - } - - // Draw fake controls, just for the looks of it (WINDOW ONLY) - if (wnd->w_type == kWndFlagWindow) - { - kcout << "Begin paint window\r"; - - if (wnd->w_display_ptr) - { - CGDrawInRegion(cg_color(0xDF, 0xDF, 0xDF), wnd->w_h, wnd->w_w, wnd->w_x, wnd->w_y); - CGDrawBitMapInRegion(wnd->w_display_ptr, wnd->w_display_ptr_h, wnd->w_display_ptr_w, wnd->w_x, wnd->w_y); - } - else - { - CGDrawInRegion(cg_color(0xDF, 0xDF, 0xDF), wnd->w_w, wnd->w_h, wnd->w_y, wnd->w_x); - } - - CGDrawInRegion(cg_color(0xFF, 0xFF, 0xFF), wnd->w_w, FLAT_CONTROLS_HEIGHT, wnd->w_y, wnd->w_x); - - if (wnd->w_sub_type != kWndFlagHideCloseControl) - { - CGDrawBitMapInRegion(zka_flat_controls, FLAT_CONTROLS_HEIGHT, FLAT_CONTROLS_WIDTH, wnd->w_y, wnd->w_x + wnd->w_w - FLAT_CONTROLS_WIDTH); - } - else if (wnd->w_sub_type == kWndFlagCloseControlSelect) - { - CGDrawBitMapInRegion(zka_flat_controls_active, FLAT_CONTROLS_CLOSEHEIGHT, FLAT_CONTROLS_CLOSEWIDTH, wnd->w_y, wnd->w_x + wnd->w_w - FLAT_CONTROLS_WIDTH); - } - - CGDrawString(wnd->w_window_name, wnd->w_x + 8, wnd->w_y + 8, cg_color(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->w_type == kWndFlagButtonSelect) - { - auto x_center = wnd->w_x + 6; - auto y_center = wnd->w_y + 7; - - CGDrawInRegion(cg_color(0xD3, 0x74, 0x00), wnd->w_w + 1, wnd->w_h + 1, wnd->w_x, wnd->w_y); - CGDrawInRegion(cg_color(0xFF, 0xFF, 0xFF), wnd->w_w - 1, wnd->w_h - 1, wnd->w_x + 1, wnd->w_y + 1); - CGDrawStringToWnd(wnd, wnd->w_window_name, y_center, x_center, cg_color(0x00, 0x00, 0x00)); - } - else if (wnd->w_type == kWndFlagButton) - { - auto x_center = wnd->w_x + 6; - auto y_center = wnd->w_y + 7; - - CGDrawInRegion(cg_color(0xDC, 0xDC, 0xDC), wnd->w_w + 1, wnd->w_h + 1, wnd->w_y, wnd->w_x); - CGDrawInRegion(cg_color(0xFF, 0xFF, 0xFF), wnd->w_w - 1, wnd->w_h - 1, wnd->w_y + 1, wnd->w_x + 1); - CGDrawString(wnd->w_window_name, y_center, x_center, cg_color(0x00, 0x00, 0x00)); - } - - cg_fini(); - - // draw child windows and controls. - // doesn't have to be a window, enabling then windows in windows. - - for (SizeT child = 0; child < wnd->w_child_count; ++child) - { - wnd->w_child_elements[child]->w_x += wnd->w_x; - wnd->w_child_elements[child]->w_y += wnd->w_y + FLAT_CONTROLS_HEIGHT; - - if ((wnd->w_child_elements[child]->w_w + wnd->w_child_elements[child]->w_x) > (wnd->w_x + wnd->w_w) || - (wnd->w_child_elements[child]->w_h + wnd->w_child_elements[child]->w_y) > (wnd->w_y + wnd->w_h)) - continue; - - CGDrawWindow(wnd->w_child_elements[child]); - } - - - cg_fini(); - - return 0; - } -} // namespace CG diff --git a/dev/Modules/FB/Math.h b/dev/Modules/FB/Math.h index 3ccbaf5d..123e9914 100644 --- a/dev/Modules/FB/Math.h +++ b/dev/Modules/FB/Math.h @@ -9,14 +9,18 @@ /// @file Math.h /// @brief Linear interpolation implementation. -typedef float CGReal; +#ifdef ZKA_FB_USE_DOUBLE +typedef double fb_real_t; +#else +typedef float fb_real_t; +#endif /// @brief Linear interpolation equation solver. /// @param from where? /// @param to to? /// @param at which state we're at **to**. -inline CGReal CGLerp(CGReal to, CGReal from, CGReal stat) +inline fb_real_t fb_math_lerp(fb_real_t to, fb_real_t from, fb_real_t stat) { - CGReal difference = to - from; + fb_real_t difference = to - from; return from + (difference * stat); } diff --git a/dev/Modules/FB/Text.h b/dev/Modules/FB/Text.h index 36e082c3..ba328314 100644 --- a/dev/Modules/FB/Text.h +++ b/dev/Modules/FB/Text.h @@ -13,7 +13,7 @@ #define FONT_SIZE_Y 8
#define FONT_NOF_CHARS 128
-inline const Kernel::UInt8 cFontBitmap[FONT_NOF_CHARS][FONT_SIZE_X] = {
+inline const Kernel::UInt8 kFontBitmap[FONT_NOF_CHARS][FONT_SIZE_X] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0000 (nul)
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0001
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // U+0002
@@ -145,7 +145,7 @@ inline const Kernel::UInt8 cFontBitmap[FONT_NOF_CHARS][FONT_SIZE_X] = { };
-inline Kernel::Void CGRenderStringFromBitMap(const Kernel::UInt8* bitmap, const Kernel::SizeT& x_sz, const Kernel::SizeT& y_sz, Kernel::Int32& x_dst, Kernel::Int32& y_dst, Kernel::Int32& color)
+inline Kernel::Void fb_render_string_for_bitmap(const Kernel::UInt8* bitmap, const Kernel::SizeT& x_sz, const Kernel::SizeT& y_sz, Kernel::Int32& x_dst, Kernel::Int32& y_dst, Kernel::Int32& color)
{
Kernel::Int32 x, y;
Kernel::Int32 set;
@@ -168,11 +168,11 @@ inline Kernel::Void CGRenderStringFromBitMap(const Kernel::UInt8* bitmap, const }
}
-inline Kernel::Void CGDrawString(const Kernel::Char* text, Kernel::Int32 x_dst, Kernel::Int32 y_dst, Kernel::Int32 color)
+inline Kernel::Void fb_render_string(const Kernel::Char* text, Kernel::Int32 x_dst, Kernel::Int32 y_dst, Kernel::Int32 color)
{
for (Kernel::SizeT i = 0; text[i] != 0; ++i)
{
- CGRenderStringFromBitMap(&cFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, x_dst, y_dst, color);
+ fb_render_string_for_bitmap(&kFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, x_dst, y_dst, color);
y_dst += FONT_SIZE_Y;
}
}
|
