66#include " hbitmap_utils.h"
77#include " menu_render.h"
88#include " nanovg.h"
9+ #include " nanovg_wrapper.h"
910#include " ui.h"
1011#include " widget.h"
1112#include < algorithm>
@@ -320,13 +321,75 @@ bool mb_shell::menu_widget::check_hit(const ui::update_context &ctx) {
320321}
321322
322323void mb_shell::menu_widget::render (ui::nanovg_context ctx) {
323- if (bg) {
324- ctx.transaction ([&]() {
324+
325+ auto bg_filler_factory = [&](auto bg, ui::nanovg_context &ctx) {
326+ return [bg, ctx]() mutable {
327+ ctx.globalAlpha (*bg->opacity / 255 .f );
328+ auto &theme = config::current->context_menu .theme ;
329+ bool light = menu_render::current.value ()->light_color ;
330+
331+ float boarder_width =
332+ theme.use_self_drawn_border ? theme.border_width : 0 .0f ;
333+
334+ if (theme.use_self_drawn_border ) {
335+ float shadow_size = theme.shadow_size ,
336+ shadow_offset_x = theme.shadow_offset_x ,
337+ shadow_offset_y = theme.shadow_offset_y ;
338+ float corner_radius = theme.radius ;
339+ NVGcolor shadow_color_from =
340+ parse_color (light ? theme.shadow_color_light_from
341+ : theme.shadow_color_dark_from ),
342+ shadow_color_to =
343+ parse_color (light ? theme.shadow_color_light_to
344+ : theme.shadow_color_dark_to );
345+
346+ ctx.beginPath ();
347+ ctx.beginPath ();
348+
349+ ctx.roundedRect (*bg->x - shadow_size + shadow_offset_x,
350+ *bg->y - shadow_size + shadow_offset_y,
351+ *bg->width + shadow_size * 2 ,
352+ *bg->height + shadow_size * 2 ,
353+ corner_radius + shadow_size);
354+ ctx.fillPaint (ctx.boxGradient (*bg->x + shadow_offset_x,
355+ *bg->y + shadow_offset_y, *bg->width ,
356+ *bg->height , corner_radius, shadow_size,
357+ shadow_color_from, shadow_color_to));
358+ ctx.fill ();
359+
360+ // Draw the border
361+ ctx.beginPath ();
362+
363+ if (theme.inset_border ) {
364+ ctx.roundedRect (*bg->x + boarder_width / 2 , *bg->y + boarder_width / 2 ,
365+ *bg->width - boarder_width,
366+ *bg->height - boarder_width, corner_radius);
367+ } else {
368+ ctx.roundedRect (*bg->x , *bg->y , *bg->width , *bg->height ,
369+ corner_radius);
370+ }
371+ ctx.strokeWidth (boarder_width);
372+ auto border_color =
373+ light ? theme.border_color_light : theme.border_color_dark ;
374+ border_color.apply_to_ctx (ctx, *bg->x , *bg->y , *bg->width , *bg->height );
375+ ctx.stroke ();
376+ }
377+
325378 ctx.globalCompositeOperation (NVG_DESTINATION_IN);
379+ ctx.globalAlpha (1 );
326380 auto cl = nvgRGBAf (0 , 0 , 0 , 1 - *bg->opacity / 255 .f );
327381 ctx.fillColor (cl);
328- ctx.fillRoundedRect (*bg->x , *bg->y , *bg->width , *bg->height , *bg->radius );
329- });
382+ if (theme.inset_border )
383+ ctx.fillRoundedRect (*bg->x + boarder_width, *bg->y + boarder_width,
384+ *bg->width - boarder_width * 2 ,
385+ *bg->height - boarder_width * 2 , *bg->radius );
386+ else
387+ ctx.fillRoundedRect (*bg->x , *bg->y , *bg->width , *bg->height ,
388+ *bg->radius );
389+ };
390+ };
391+ if (bg) {
392+ ctx.transaction (bg_filler_factory (bg, ctx));
330393 bg->render (ctx);
331394 }
332395
@@ -339,14 +402,7 @@ void mb_shell::menu_widget::render(ui::nanovg_context ctx) {
339402 auto ctx2 = ctx.with_offset (*x, *y);
340403
341404 if (bg_submenu) {
342- ctx2.transaction ([&]() {
343- ctx2.globalCompositeOperation (NVG_DESTINATION_IN);
344- ctx2.resetScissor ();
345- auto cl = nvgRGBAf (0 , 0 , 0 , 1 - *bg_submenu->opacity / 255 .f );
346- ctx2.fillColor (cl);
347- ctx2.fillRoundedRect (*bg_submenu->x , *bg_submenu->y , *bg_submenu->width ,
348- *bg_submenu->height , *bg_submenu->radius );
349- });
405+ ctx2.transaction (bg_filler_factory (bg_submenu, ctx2));
350406 bg_submenu->render (ctx2);
351407 }
352408 render_children (ctx2, rendering_submenus);
0 commit comments