Ejemplo n.º 1
0
        public override void Draw(NVGcontext ctx)
        {
            base.Draw(ctx);

            Theme   style = this.theme;
            Vector2 pos   = this.localPosition;
            Vector2 size  = this.size;

            if (!string.IsNullOrEmpty(this.caption))
            {
                int currFontSize = GetPreferredFontSize();
                if (0 < currFontSize)
                {
                    int      currFontFace  = Fonts.Get(this.theme.fontNormal);
                    NVGcolor currTextColor = this.enabled ? style.textColor : style.disabledTextColor;

                    NanoVG.nvgFontSize(ctx, currFontSize);
                    NanoVG.nvgFontFace(ctx, currFontFace);
                    NanoVG.nvgFillColor(ctx, currTextColor);
                    NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE));

                    NanoVG.nvgText(ctx, pos.X + size.Y * 1.2f + 5, pos.Y + this.size.Y * 0.5f, this.caption);
                }
            }

            Color4f col  = Color4f.Black;
            Color4f icol = this.pushed ? col.WithAlpha(100) : col.WithAlpha(32);
            Color4f ocol = col.WithAlpha(180);

            NVGpaint bg = NanoVG.nvgBoxGradient(ctx, pos.X + 1.5f, pos.Y + 1.5f
                                                , size.X - 2f, size.Y - 2f, 3f, 3f
                                                , icol.ToNVGColor()
                                                , ocol.ToNVGColor());

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRoundedRect(ctx, pos.X + 1f, pos.Y + 1f, size.Y - 2f, size.Y - 2f, 3f);
            NanoVG.nvgFillPaint(ctx, bg);
            NanoVG.nvgFill(ctx);

            if (this.check)
            {
                int      fontIcons = Fonts.Get(style.fontIcons);
                NVGcolor iconColor = this.enabled ? style.iconColor : style.disabledTextColor;
                NanoVG.nvgFontSize(ctx, 1.8f * size.Y);
                NanoVG.nvgFontFace(ctx, fontIcons);
                NanoVG.nvgFillColor(ctx, iconColor);
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_CENTER | NVGalign.NVG_ALIGN_MIDDLE));
                byte[] icon = Fonts.GetIconUTF8((int)Font.Entypo.ICON_CHECK);
                NanoVG.nvgText(ctx, pos.X + size.Y * 0.5f + 1f, pos.Y + size.Y * 0.5f, icon);
            }
        }
Ejemplo n.º 2
0
        public override void Draw(NVGcontext ctx)
        {
            RefreshRelativePlacement();
            if (!this.isVisible)
            {
                return;
            }

            Vector2 pos   = this.localPosition;
            Vector2 size  = this.size;
            Theme   style = this.theme;

            int ds  = style.windowDropShadowSize;
            int cr  = style.windowCornerRadius;
            int ds2 = 2 * ds;
            int cr2 = 2 * cr;
            int ah  = this.anchorHeight;

            // draw drop shadow.
            NVGpaint shadowPaint = NanoVG.nvgBoxGradient(ctx, pos.X, pos.Y, size.X, size.Y, cr2, ds2
                                                         , style.dropShadowColor
                                                         , style.transparentColor);

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRect(ctx, pos.X - ds, pos.Y - ds, size.X + ds2, size.Y + ds2);
            NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr);
            NanoVG.nvgPathWinding(ctx, (int)NVGsolidity.NVG_HOLE);
            NanoVG.nvgFillPaint(ctx, shadowPaint);
            NanoVG.nvgFill(ctx);

            // draw window.
            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr);
            // draw anchor triangle.
            NanoVG.nvgMoveTo(ctx, pos.X - 15, pos.Y + ah);
            NanoVG.nvgLineTo(ctx, pos.X + 1, pos.Y + ah - 15);
            NanoVG.nvgLineTo(ctx, pos.X + 1, pos.Y + ah + 15);

            NanoVG.nvgFillColor(ctx, style.windowPopupColor);
            NanoVG.nvgFill(ctx);

            // draw contents.
            DrawChildren(ctx);
        }
Ejemplo n.º 3
0
        public override void Draw(NVGcontext ctx)
        {
            Theme style = this.theme;
            int   ds    = style.windowDropShadowSize;
            int   cr    = style.windowCornerRadius;
            int   hh    = style.windowHeaderHeight;

            Vector2 pos  = this.localPosition;
            Vector2 size = this.size;

            NanoVG.nvgSave(ctx);
            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr);
            NanoVG.nvgFillColor(ctx, this.mouseFocus ? style.windowFillFocusedColor
                                 : style.windowFillUnfocusedColor);

            NanoVG.nvgFill(ctx);

            NVGpaint shadowPaint = NanoVG.nvgBoxGradient(ctx
                                                         , pos.X, pos.Y, size.X, size.Y
                                                         , cr * 2, ds * 2
                                                         , style.dropShadowColor
                                                         , style.transparentColor);

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRect(ctx, pos.X - ds, pos.Y - ds, size.X + 2 * ds, size.Y + 2 * ds);
            NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, size.Y, cr);
            NanoVG.nvgPathWinding(ctx, (int)NVGsolidity.NVG_HOLE);
            NanoVG.nvgFillPaint(ctx, shadowPaint);
            NanoVG.nvgFill(ctx);

            // draw header.
            if (!string.IsNullOrEmpty(this.title))
            {
                NVGpaint headerPaint = NanoVG.nvgLinearGradient(
                    ctx
                    , pos.X, pos.Y, pos.X, pos.Y + hh
                    , style.windowHeaderGradientTopColor
                    , style.windowHeaderGradientBotColor
                    );

                NanoVG.nvgBeginPath(ctx);
                NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, hh, cr);
                NanoVG.nvgFillPaint(ctx, headerPaint);
                NanoVG.nvgFill(ctx);

                NanoVG.nvgBeginPath(ctx);
                NanoVG.nvgRoundedRect(ctx, pos.X, pos.Y, size.X, hh, cr);
                NanoVG.nvgStrokeColor(ctx, style.windowHeaderSepTopColor);

                NanoVG.nvgSave(ctx);
                NanoVG.nvgIntersectScissor(ctx, pos.X, pos.Y, size.X, 0.5f);
                NanoVG.nvgStroke(ctx);
                NanoVG.nvgResetScissor(ctx);
                NanoVG.nvgRestore(ctx);

                NanoVG.nvgBeginPath(ctx);
                NanoVG.nvgMoveTo(ctx, pos.X + 0.5f, pos.Y + hh - 1.5f);
                NanoVG.nvgLineTo(ctx, pos.X + size.X - 0.5f, pos.Y + hh - 1.5f);
                NanoVG.nvgStrokeColor(ctx, style.windowHeaderSepBotColor);
                NanoVG.nvgStroke(ctx);

                NanoVG.nvgFontSize(ctx, style.standardFontSize + 2f);
                NanoVG.nvgFontFace(ctx, style.fontBold);
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_CENTER | NVGalign.NVG_ALIGN_MIDDLE));

                Vector2 headerTextPos;
                headerTextPos.X = pos.X + size.X * 0.5f;
                headerTextPos.Y = pos.Y + hh * 0.5f;

                NanoVG.nvgFontBlur(ctx, 2f);
                NanoVG.nvgFillColor(ctx, style.dropShadowColor);
                NanoVG.nvgText(ctx, headerTextPos.X, headerTextPos.Y, this.title);

                NanoVG.nvgFontBlur(ctx, 0f);
                NanoVG.nvgFillColor(ctx, this.focused ? style.windowTitleFocusedColor
                                     : style.windowTitleUnfocusedColor);
                NanoVG.nvgText(ctx, headerTextPos.X, headerTextPos.Y - 1f, this.title);
            }

            NanoVG.nvgRestore(ctx);
            base.Draw(ctx);
        }