From f8c678ac53bee5be4005afb19317d2b192525c62 Mon Sep 17 00:00:00 2001 From: Nishi Date: Mon, 21 Sep 2026 12:41:56 +0900 Subject: [PATCH] ok --- include/Mw/Core.h | 7 +++++++ include/Mw/Draw.h | 7 +++++++ src/core.c | 27 +++++++++++++++++++++++++++ src/draw.c | 32 ++++++++++++++++++++++++++++++++ src/widget/document.c | 17 +++++------------ 5 files changed, 78 insertions(+), 12 deletions(-) diff --git a/include/Mw/Core.h b/include/Mw/Core.h index 61cb085..318a8ca 100644 --- a/include/Mw/Core.h +++ b/include/Mw/Core.h @@ -390,6 +390,13 @@ MWDECL void MWAPI MwFreeWidget(MwWidget handle); */ MWDECL void MWAPI MwGetFrame(MwWidget handle, MwRect* rect); +/*! + * @brief Gets the clipping frame of the widget + * @param handle Widget + * @param rect Frame + */ +MWDECL void MWAPI MwGetClipFrame(MwWidget handle, MwRect* rect); + #ifdef _MILSKO MWDECL void MwForceRender_Internal(MwWidget handle); MWDECL void MwForceRender2_Internal(MwWidget handle, void* ptr); diff --git a/include/Mw/Draw.h b/include/Mw/Draw.h index ad13c60..12d3d45 100644 --- a/include/Mw/Draw.h +++ b/include/Mw/Draw.h @@ -220,6 +220,13 @@ MWDECL void MWAPI MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, */ MWDECL void MWAPI MwDrawCircle(MwWidget handle, MwRect* rect, MwLLColor color, MwLLColor background, int filled); +/*! + * @brief Calculate intersect of 2 rectangles + * @param a 1st rectangle + * @param a 2nd rectangle + */ +MWDECL void MwIntersectRect(MwRect* a, const MwRect* b); + /* text.c */ /*! diff --git a/src/core.c b/src/core.c index 1403310..7bc7065 100644 --- a/src/core.c +++ b/src/core.c @@ -1241,4 +1241,31 @@ void MwGetFrame(MwWidget handle, MwRect* rect) { rect->height = MwGetInteger(handle, MwNheight); } +void MwGetClipFrame(MwWidget handle, MwRect* rect) { + MwWidget child = handle; + MwWidget p = handle->parent; + int o_x = 0, o_y = 0; + + rect->x = 0; + rect->y = 0; + rect->width = MwGetInteger(handle, MwNwidth); + rect->height = MwGetInteger(handle, MwNheight); + while(p != NULL && p->widget_class != MwWindowClass) { + MwRect pclip; + + o_x += MwGetInteger(child, MwNx); + o_y += MwGetInteger(child, MwNy); + + pclip.x = -o_x; + pclip.y = -o_y; + pclip.width = MwGetInteger(p, MwNwidth); + pclip.height = MwGetInteger(p, MwNheight); + MwIntersectRect(rect, &pclip); + if(rect->width == 0 || rect->height == 0) break; + + child = p; + p = p->parent; + } +} + const char* MwVersionString = MwVERSION; diff --git a/src/draw.c b/src/draw.c index ab4c9cb..b2ab8b1 100644 --- a/src/draw.c +++ b/src/draw.c @@ -1125,3 +1125,35 @@ MwLLPixmap MwLoadXPM(MwWidget handle, char** data) { return px; } + +static int _min(int a, int b) { + return a < b ? a : b; +} + +static int _max(int a, int b) { + return a > b ? a : b; +} + +void MwIntersectRect(MwRect* a, const MwRect* b) { + int x; + int y; + int right; + int bottom; + + x = _max(a->x, b->x); + y = _max(a->y, b->y); + right = _min(a->x + a->width, b->x + b->width); + bottom = _min(a->y + a->height, b->y + b->height); + + a->x = x; + a->y = y; + + if(right <= x || bottom <= x) { + a->width = 0; + a->height = 0; + return; + } + + a->width = right - x; + a->height = bottom - y; +} diff --git a/src/widget/document.c b/src/widget/document.c index f71e1bc..eb5233d 100644 --- a/src/widget/document.c +++ b/src/widget/document.c @@ -59,17 +59,9 @@ static void draw(MwWidget handle) { MwFLFont font = NULL; MwPoint u_p, s_p, c_p; int u = 0, s = 0, c = 0; - int s_y = 0; - int s_h = MwGetInteger(handle, MwNheight); - MwWidget p = handle->parent; + MwRect clip; - s_y = MwGetInteger(handle, MwNy); - while(p != NULL && p->widget_class != MwWindowClass) { - s_y += MwGetInteger(p, MwNy); - - p = p->parent; - } - s_y *= -1; + MwGetClipFrame(handle, &clip); u_p.x = s_p.x = c_p.x = 0; u_p.y = s_p.y = c_p.y = 0; @@ -87,11 +79,12 @@ static void draw(MwWidget handle) { case MwDOCUMENT_TEXT: { MwPoint p; + int th2; p.x = l->x; - p.y = l->y + MwTextHeight(handle, font, l->text) / 2; + p.y = l->y + (th2 = MwTextHeight(handle, font, l->text) / 2); - if(p.y <= s_y || p.y >= s_y + s_h) break; + if((p.y + th2) <= clip.y || (p.y - th2) >= clip.y + clip.height) break; if(u || s || c) { MwPoint line[2];