diff --git a/include/Mw/Default.h b/include/Mw/Default.h index f20a60c68..d1fd52105 100644 --- a/include/Mw/Default.h +++ b/include/Mw/Default.h @@ -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 diff --git a/include/Mw/Draw.h b/include/Mw/Draw.h index 901379b0b..ae428990b 100644 --- a/include/Mw/Draw.h +++ b/include/Mw/Draw.h @@ -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 diff --git a/src/backend/gdi.c b/src/backend/gdi.c index 074306ec5..bbab256d4 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -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); diff --git a/src/backend/wayland/wayland.c b/src/backend/wayland/wayland.c index 1db2c1598..bb5a924b6 100644 --- a/src/backend/wayland/wayland.c +++ b/src/backend/wayland/wayland.c @@ -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; } } diff --git a/src/default.c b/src/default.c index 8b8cf5817..44e4c4d6f 100644 --- a/src/default.c +++ b/src/default.c @@ -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; + } +} diff --git a/src/draw.c b/src/draw.c index 8145df8aa..4d419bc54 100644 --- a/src/draw.c +++ b/src/draw.c @@ -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 { diff --git a/src/widget/button.c b/src/widget/button.c index a73635628..51337e69d 100644 --- a/src/widget/button.c +++ b/src/widget/button.c @@ -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))) { diff --git a/src/widget/checkbox.c b/src/widget/checkbox.c index 353397619..f196954d3 100644 --- a/src/widget/checkbox.c +++ b/src/widget/checkbox.c @@ -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 */ diff --git a/src/widget/combobox.c b/src/widget/combobox.c index d650dadac..79f3e332b 100644 --- a/src/widget/combobox.c +++ b/src/widget/combobox.c @@ -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; diff --git a/src/widget/entry.c b/src/widget/entry.c index 6164af673..85807688f 100644 --- a/src/widget/entry.c +++ b/src/widget/entry.c @@ -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"); diff --git a/src/widget/menu.c b/src/widget/menu.c index 25802b1cc..0422e493e 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -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); diff --git a/src/widget/numberentry.c b/src/widget/numberentry.c index 969d54403..f3a80e94c 100644 --- a/src/widget/numberentry.c +++ b/src/widget/numberentry.c @@ -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; diff --git a/src/widget/progressbar.c b/src/widget/progressbar.c index 5cb6f1569..3185c233b 100644 --- a/src/widget/progressbar.c +++ b/src/widget/progressbar.c @@ -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); diff --git a/src/widget/scrollbar.c b/src/widget/scrollbar.c index 98a050d9c..346f818ab 100644 --- a/src/widget/scrollbar.c +++ b/src/widget/scrollbar.c @@ -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); diff --git a/src/widget/separator.c b/src/widget/separator.c index 4e70ccc7b..d49873ec7 100644 --- a/src/widget/separator.c +++ b/src/widget/separator.c @@ -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); } diff --git a/src/widget/submenu.c b/src/widget/submenu.c index addd999c3..6bc5d550c 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -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); diff --git a/src/widget/tab.c b/src/widget/tab.c index 408b73a87..9c6b98d8f 100644 --- a/src/widget/tab.c +++ b/src/widget/tab.c @@ -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);