DrawWidgetBack fix

This commit is contained in:
Nishi 2026-05-07 19:40:06 +09:00
commit 19416d7451
Signed by: nishi
GPG key ID: 27EF69B208EB9343
17 changed files with 88 additions and 34 deletions

View file

@ -83,6 +83,12 @@ MWDECL const int MwDefaultShadow;
*/
MWDECL int MWAPI MwDefaultBorderWidth(MwWidget handle);
/*!
* @brief Gets default thin border width
* @param handle Widget
*/
MWAPI int MwDefaultThinBorderWidth(MwWidget handle);
#ifdef __cplusplus
}
#endif

View file

@ -65,6 +65,17 @@ MWDECL void MWAPI MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor colo
*/
MWDECL void MWAPI MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert);
/*!
* @brief Draws a frame
* @param handle Widget
* @param rect Rectangle area
* @param color Color
* @param invert Invert the 3D border color or not
* @param border Border
* @warning `rect` gets changed to the area of rectangle inside
*/
MWDECL void MWAPI MwDrawFrameWithBorder(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border);
/*!
* @brief Does the DrawFrame/DrawRect combo used for drawing widget.
* @param handle Widget

View file

@ -887,14 +887,14 @@ static void MwLLRaiseImpl(MwLL handle) {
}
static void MwLLClipImpl(MwLL handle, MwRect* rect) {
if(rect == NULL){
if(rect == NULL) {
SelectClipRgn(handle->gdi.hDC, NULL);
if(handle->gdi.clip != NULL){
if(handle->gdi.clip != NULL) {
DeleteObject(handle->gdi.clip);
handle->gdi.clip = NULL;
}
}else{
} else {
HRGN clip = CreateRectRgn(rect->x, rect->y, rect->x + rect->width, rect->y + rect->height);
SelectClipRgn(handle->gdi.hDC, clip);

View file

@ -592,7 +592,7 @@ static void clip(MwLL handle) {
cairo_clip(handle->wayland.front_cairo);
}
if(handle->wayland.is_clipping){
if(handle->wayland.is_clipping) {
cairo_rectangle(handle->wayland.front_cairo, handle->wayland.clip.x, handle->wayland.clip.y, handle->wayland.clip.width, handle->wayland.clip.height);
cairo_clip(handle->wayland.front_cairo);
}
@ -1603,9 +1603,9 @@ static void MwLLRaiseImpl(MwLL handle) {
}
static void MwLLClipImpl(MwLL handle, MwRect* rect) {
if(rect == NULL){
if(rect == NULL) {
handle->wayland.is_clipping = MwFALSE;
}else{
} else {
handle->wayland.clip = *rect;
}
}

View file

@ -27,3 +27,15 @@ int MwDefaultBorderWidth(MwWidget handle) {
return 2;
}
}
int MwDefaultThinBorderWidth(MwWidget handle) {
int bw = MwGetInteger(handle, MwNborderWidth);
if(bw != MwDEFAULT) return bw;
if(MwGetInteger(handle, MwNmodernLook)) {
return 1;
} else {
return 2;
}
}

View file

@ -141,23 +141,35 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
}
void MwDrawFrame(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
MwDrawFrameWithBorder(handle, rect, color, invert, MwDefaultBorderWidth(handle));
}
static int translate_border(MwWidget handle, int border) {
if(border == MwDEFAULT) return MwDefaultBorderWidth(handle);
return border;
}
void MwDrawFrameWithBorder(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border) {
int inv;
border = translate_border(handle, border);
if((inv = MwGetInteger(handle, MwNforceInverted)) != MwDEFAULT && inv) invert = 1;
if(MwGetInteger(handle, MwNmodernLook)) {
MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth(handle), 0, 0);
MwDrawFrameEx(handle, rect, color, invert, border, 0, 0);
} else {
int diff = get_color_diff(handle) / 3 * 2;
if(MwDefaultBorderWidth(handle) >= 2) {
if(border >= 2) {
int i;
int st = invert ? 1 : 0;
for(i = st; i < st + 2; i++) {
if((i % 2) == 0) MwDrawFrameEx(handle, rect, color, invert, MwDefaultBorderWidth(handle) - 1, -diff, (handle->parent == NULL || handle->parent->lowlevel == NULL) ? 1 : 0);
if((i % 2) == 0) MwDrawFrameEx(handle, rect, color, invert, border - 1, -diff, (handle->parent == NULL || handle->parent->lowlevel == NULL) ? 1 : 0);
if((i % 2) == 1) MwDrawFrameEx(handle, rect, color, invert, 1, diff, 0);
}
} else {
MwDrawFrameEx(handle, rect, color, invert, 1, 0, 0);
MwDrawFrameEx(handle, rect, color, invert, border, 0, 0);
}
}
}
@ -177,7 +189,16 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert
}
}
MwDrawFrame(handle, rect, color, invert);
MwDrawFrameWithBorder(handle, rect, color, invert, border);
if(border == MwDEFAULT) {
int d = MwDefaultBorderWidth(handle) - MwDefaultThinBorderWidth(handle);
rect->x -= d;
rect->y -= d;
rect->width += d * 2;
rect->height += d * 2;
}
}
if(rect->width <= 0 || rect->height <= 0) return;
@ -359,13 +380,15 @@ static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color
MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff);
MwRect r = *rect;
frame_border_complex(handle, rect, lighter, darker, invert, border / 2, diff, same);
frame_border_complex(handle, rect, lighter, darker, invert, border == 1 ? 1 : (border / 2), diff, same);
r.x += 1;
r.y += 1;
r.width -= 2;
r.height -= 2;
frame_border_complex(handle, &r, lighter, darker, !invert, border / 2, diff, same);
if(border > 1) {
r.x += border / 2;
r.y += border / 2;
r.width -= border;
r.height -= border;
frame_border_complex(handle, &r, lighter, darker, !invert, border / 2, diff, same);
}
MwLLFreeColor(lighter);
MwLLFreeColor(darker);
@ -377,6 +400,8 @@ static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color
}
void MwDrawFrameEx(MwWidget handle, MwRect* rect, MwLLColor color, int invert, int border, int diff, int same) {
border = translate_border(handle, border);
if(MwGetInteger(handle, MwNmodernLook)) {
MwDrawFrameEx_complex(handle, rect, color, invert, border, diff, same);
} else {

View file

@ -31,12 +31,12 @@ static void draw(MwWidget handle) {
if(MwGetInteger(handle, MwNflat)) {
if(handle->pressed || ((inv = MwGetInteger(handle, MwNforceInverted)) != MwDEFAULT && inv)) {
MwDrawWidgetBack(handle, &r, base, handle->pressed, 1);
MwDrawWidgetBack(handle, &r, base, handle->pressed, MwDEFAULT);
} else {
MwDrawRect(handle, &r, base);
}
} else {
MwDrawWidgetBack(handle, &r, base, handle->pressed, 1);
MwDrawWidgetBack(handle, &r, base, handle->pressed, MwDEFAULT);
}
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
if(MwGetInteger(handle, MwNflat) && !(handle->pressed || ((inv = MwGetInteger(handle, MwNforceInverted)) != MwDEFAULT && inv))) {

View file

@ -27,7 +27,7 @@ static void draw(MwWidget handle) {
r.x = (MwGetInteger(handle, MwNwidth) - r.width) / 2;
r.y = (MwGetInteger(handle, MwNheight) - r.height) / 2;
MwDrawWidgetBack(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0, MwTRUE);
MwDrawWidgetBack(handle, &r, base, (handle->pressed || MwGetInteger(handle, MwNchecked)) ? 1 : 0, MwDEFAULT);
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
if(handle->pressed || MwGetInteger(handle, MwNchecked)) {
/* TODO: write check mark */

View file

@ -40,7 +40,7 @@ static void draw(MwWidget handle) {
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
MwDrawWidgetBack(handle, &r, base, 0, 1);
MwDrawWidgetBack(handle, &r, base, 0, MwDEFAULT);
rc = r;

View file

@ -34,7 +34,7 @@ static void draw(MwWidget handle) {
r.width = MwGetInteger(handle, MwNwidth) - t->right;
r.height = MwGetInteger(handle, MwNheight);
MwDrawWidgetBack(handle, &r, base, 1, 1);
MwDrawWidgetBack(handle, &r, base, 1, MwDEFAULT);
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
if(str != NULL) {
int w = MwTextWidth(handle, font, "M");

View file

@ -107,12 +107,12 @@ static void draw(MwWidget handle) {
MENU_LOOP_INIT;
MwDrawWidgetBack(handle, &r, base, 0, MwTRUE);
MwDrawWidgetBack(handle, &r, base, 0, MwDEFAULT);
BEGIN_MENU_LOOP;
if(m->sub[i]->wsub != NULL || (in_area && handle->pressed)) {
MwDrawFrame(handle, &r, base, MwFALSE);
MwDrawWidgetBack(handle, &r, base, 0, MwFALSE);
MwDrawWidgetBack(handle, &r, base, 0, 0);
}
MwDrawText(handle, MwFLBuildFont((m->sub[i]->wsub != NULL || (in_area && handle->pressed)) ? MwFLFlagBold : 0), &p, m->sub[i]->name + incr, MwALIGNMENT_CENTER, text);

View file

@ -33,7 +33,7 @@ static void draw(MwWidget handle) {
r.y = 0;
r.width = e->right;
r.height = h / 2;
MwDrawWidgetBack(handle, &r, base, pr, MwTRUE);
MwDrawWidgetBack(handle, &r, base, pr, MwDEFAULT);
if(r.width > r.height) {
r.width = r.height;
@ -49,7 +49,7 @@ static void draw(MwWidget handle) {
r.y = h / 2;
r.width = e->right;
r.height = h / 2;
MwDrawWidgetBack(handle, &r, base, pr, MwTRUE);
MwDrawWidgetBack(handle, &r, base, pr, MwDEFAULT);
if(r.width > r.height) {
r.width = r.height;

View file

@ -26,7 +26,7 @@ static void draw(MwWidget handle) {
w = MwGetInteger(handle, MwNvalue) - MwGetInteger(handle, MwNminValue);
w = w / (MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue));
MwDrawWidgetBack(handle, &r, base, 1, MwTRUE);
MwDrawWidgetBack(handle, &r, base, 1, MwDEFAULT);
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
r.x += MwDefaultBorderWidth(handle);

View file

@ -73,7 +73,7 @@ static void draw(MwWidget handle) {
ux = r.height;
dx = r.width - r.height;
MwDrawWidgetBack(handle, &r, dark, 1, MwTRUE);
MwDrawWidgetBack(handle, &r, dark, 1, MwDEFAULT);
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
rt = r;
@ -131,7 +131,7 @@ static void draw(MwWidget handle) {
}
}
if(rbar.height >= 0) MwDrawWidgetBack(handle, &rbar, base, 0, MwTRUE);
if(rbar.height >= 0) MwDrawWidgetBack(handle, &rbar, base, 0, MwDEFAULT);
MwLLFreeColor(dark);
MwLLFreeColor(base);

View file

@ -25,7 +25,7 @@ static void draw(MwWidget handle) {
r.y = (r.height - 2) / 2;
r.height = 2;
}
MwDrawFrameEx(handle, &r, base, 1, 1, 0, 0);
MwDrawFrameEx(handle, &r, base, 1, MwDEFAULT, 0, 0);
MwLLFreeColor(base);
}

View file

@ -39,7 +39,7 @@ static void draw(MwWidget handle) {
r.width = MwGetInteger(handle, MwNwidth);
r.height = MwGetInteger(handle, MwNheight);
MwDrawWidgetBack(handle, &r, base, 0, MwTRUE);
MwDrawWidgetBack(handle, &r, base, 0, MwDEFAULT);
if(menu != NULL) {
MwPoint p;
@ -73,7 +73,7 @@ static void draw(MwWidget handle) {
r.y = p.y - 3;
r.width = MwGetInteger(handle, MwNwidth) - MwGetInteger(handle, MwNleftPadding);
r.height = th + 3 * 2;
MwDrawWidgetBack(handle, &r, base, 0, MwTRUE);
MwDrawWidgetBack(handle, &r, base, 0, MwDEFAULT);
}
p.x = 5 + tw / 2 + MwGetInteger(handle, MwNleftPadding);

View file

@ -156,10 +156,10 @@ static void show_frame(MwWidget handle) {
if(i != n) MwLLShow(t->frames[i]->lowlevel, 0);
}
MwLLShow(t->frames[n]->lowlevel, 1);
resize(handle);
MwLLShow(t->frames[n]->lowlevel, 1);
MwForceRender(handle);
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);