示例#1
0
        public override Vector2 GetPreferredSize(NVGcontext ctx)
        {
            if (string.IsNullOrEmpty(caption))
            {
                return(Vector2.Zero);
            }

            Vector2 ret          = Vector2.Zero;
            int     prefFontSize = GetPreferredFontSize();

            NanoVG.nvgFontFace(ctx, font);
            NanoVG.nvgFontSize(ctx, prefFontSize);

            int fixedWidth = (int)this.fixedSize.X;

            if (0 < fixedWidth)
            {
                Vector2 pos = this.localPosition;
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP));
                NanoVG.nvgTextBoxBounds(ctx, pos.X, pos.Y, fixedWidth, caption, m_Bounds);

                ret.X = fixedWidth;
                ret.Y = (m_Bounds[3] - m_Bounds[1]);
            }
            else
            {
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE));
                ret.X = NanoVG.nvgTextBounds(ctx, 0, 0, caption, m_Bounds);
                ret.Y = prefFontSize;
            }
            return(ret);
        }
示例#2
0
        public void Render()
        {
            var picked = Pick(_window.MouseScreenSpace.X, _window.MouseScreenSpace.Y);

            var lineHeight = (int)(_window.FontLineHeight * 1.5f);

            NanoVG.nvgFillColor(MainWindow.Nvg, picked ? Color.LightGray.ToNvgColor() : Color.White.ToNvgColor());
            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRect(MainWindow.Nvg, 0, lineHeight * Index, Parent.Width, lineHeight);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgSave(MainWindow.Nvg);
            NanoVG.nvgFillColor(MainWindow.Nvg, Color.Black.ToNvgColor());
            NanoVG.nvgTranslate(MainWindow.Nvg, 3, lineHeight * Index + 3);
            if (Shortcut == null)
            {
                NvgHelper.RenderString(Text);
            }
            else
            {
                NvgHelper.RenderString($"{Shortcut} {Text}");
                NanoVG.nvgFillColor(MainWindow.Nvg, Color.DarkGray.ToNvgColor());
                NvgHelper.RenderString(Shortcut);
            }

            NanoVG.nvgRestore(MainWindow.Nvg);
        }
示例#3
0
        public static SizeF MeasureString(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return(SizeF.Empty);
            }

            if (text.EndsWith(" "))
            {
                text = $"{text.Substring(0, text.Length - 1)}(";
            }
            NanoVG.nvgFontFace(MainWindow.Nvg, "sans");
            var sb = new float[4];

            try
            {
                NanoVG.nvgTextBounds(MainWindow.Nvg, 0, 0, text, sb);
            }
            catch (Exception e)
            {
                Lumberjack.Error($"NvgHelper::MeasureString: {e.Message}");
            }

            var sfw = sb[2] - sb[0];
            var sfh = sb[3] - sb[1];

            return(new SizeF(sfw, sfh));
        }
示例#4
0
        public override void Draw(NVGcontext ctx)
        {
            if (!this.enabled && this.pushed)
            {
                this.pushed = false;
            }

            if (m_Popup)
            {
                m_Popup.isVisible = this.pushed;
            }

            base.Draw(ctx);

            if (0 != this.chevronIcon)
            {
                Theme    style         = this.theme;
                byte[]   icon          = Fonts.GetIconUTF8(this.chevronIcon);
                NVGcolor currTextColor = GetCurrTextColor();
                int      currFontSize  = (0 <= this.fontSize) ? this.fontSize : style.buttonFontSize;
                int      fontFace      = Fonts.Get(style.fontIcons);

                NanoVG.nvgFontSize(ctx, currFontSize * 1.5f);
                NanoVG.nvgFontFace(ctx, fontFace);
                NanoVG.nvgFillColor(ctx, currTextColor);
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE));

                float   iw      = NanoVG.nvgTextBounds(ctx, 0f, 0f, icon, null);
                Vector2 iconPos = this.localPosition;
                iconPos.X += this.size.X - iw - 8;
                iconPos.Y += this.size.Y * 0.5f - 1;
                NanoVG.nvgText(ctx, iconPos.X, iconPos.Y, icon);
            }
        }
示例#5
0
文件: UI.cs 项目: WildGenie/Libraria
        public override bool OnMouseMove(MouseMoveEventArgs E)
        {
            int X = NanoVG.ScaleX(E.X);
            int Y = NanoVG.ScaleY(E.Y);

            if (DemoGameButton?.Collide(X, Y) == true)
            {
                DemoGameColor = Color.Green;
            }
            else
            {
                DemoGameColor = Color.White;
            }

            if (ExitButton?.Collide(X, Y) == true)
            {
                ExitColor = Color.Green;
            }
            else
            {
                ExitColor = Color.White;
            }

            return(true);
        }
示例#6
0
        public static void Load(NVGcontext ctx, string fontName, string fileName)
        {
            string filePath   = RESOURCES_PATH + fileName;
            int    fontHandle = NanoVG.nvgCreateFont(ctx, fontName, filePath);

            s_FontMap[fontName] = fontHandle;
        }
示例#7
0
        public override void Draw(NVGcontext ctx)
        {
            base.Draw(ctx);

            if (0 > m_FontId)
            {
                return;
            }
            int prefFontSize = GetPreferredFontSize();

            NanoVG.nvgFontFace(ctx, m_FontId);
            NanoVG.nvgFontSize(ctx, prefFontSize);
            NanoVG.nvgFillColor(ctx, this.color);

            int     fixedWidth = (int)this.fixedSize.X;
            Vector2 pos        = this.localPosition;

            if (0 < fixedWidth)
            {
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_TOP));
                NanoVG.nvgTextBox(ctx, pos.X, pos.Y, fixedWidth, caption);
            }
            else
            {
                NanoVG.nvgTextAlign(ctx, (int)(NVGalign.NVG_ALIGN_LEFT | NVGalign.NVG_ALIGN_MIDDLE));
                NanoVG.nvgText(ctx, pos.X, pos.Y + this.size.Y * 0.5f, caption);
            }

            // DEBUG: BOUNDS
            //NanoVG.nvgStrokeWidth (ctx, 1.0f);
            //NanoVG.nvgBeginPath (ctx);
            //NanoVG.nvgRect (ctx, pos.X, pos.Y, this.size.X, this.size.Y);
            //NanoVG.nvgStrokeColor (ctx, this.color);
            //NanoVG.nvgStroke(ctx);
        }
示例#8
0
        public override void Draw(NVGcontext ctx)
        {
            if (RadiusX == 0 || RadiusY == 0)
            {
                return;
            }

            NanoVG.nvgEllipse(ctx, X, Y, RadiusX, RadiusY);
        }
示例#9
0
        public override void Draw(NVGcontext ctx)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            NanoVG.nvgRoundedRect(ctx, X, Y, Width, Height, Radius);
        }
示例#10
0
        public override void Render(float Dt)
        {
            const float Offset = 20;

            NanoVG.DrawRectOutline(Color.DarkGray, 6.0f, Offset, Offset, NanoVG.Width - Offset * 2, NanoVG.Height - Offset * 2);

            /*NanoVG.SetFont("clacon", 24);
             * NanoVG.DrawParagraph("^FF0000Red^00FF00Green^0000FFBlue^FFFFFFWhite\nRedGreenBlueWhite", 100, 100, 100);*/
        }
示例#11
0
        public override void Draw(NVGcontext ctx)
        {
            if ((X == X1 && Y == Y1) || Radius == 0)
            {
                return;
            }

            NanoVG.nvgArcTo(ctx, X, Y, X1, Y1, Radius);
        }
示例#12
0
        public void RenderBackground()
        {
            var lineHeight = (int)(_window.FontLineHeight * 1.5f);

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.Black.ToNvgColor());
            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRect(MainWindow.Nvg, -1, lineHeight * Index - 1, Parent.Width + 2, lineHeight + 2);
            NanoVG.nvgRect(MainWindow.Nvg, 1, lineHeight * Index + 1, Parent.Width + 1, lineHeight + 1);
            NanoVG.nvgFill(MainWindow.Nvg);
        }
示例#13
0
        public void RenderNode(Node node)
        {
            if (!ScreenContains(node))
            {
                return;
            }
            const int   borderRadius   = 6;
            const int   panelInset     = 2;
            const float halfPanelInset = panelInset / 2f;

            var headerHeight = (int)(_window.FontLineHeight * 1.2f);

            NanoVG.nvgSave(MainWindow.Nvg);

            if (_window.Selection.SelectedNodes.Contains(node))
            {
                NanoVG.nvgFillColor(MainWindow.Nvg, Color.Black.ToNvgColor());
                NanoVG.nvgBeginPath(MainWindow.Nvg);
                NanoVG.nvgRoundedRect(MainWindow.Nvg, node.X - panelInset - 2, node.Y - 2, node.Width + 2 * (2 + panelInset), node.Height + 4, borderRadius + 2);
                NanoVG.nvgFill(MainWindow.Nvg);
            }

            NanoVG.nvgFillColor(MainWindow.Nvg, _colorMap.ContainsKey(node.NodeInfo) ? _colorMap[node.NodeInfo] : NanoVG.nvgRGBA(0, 0, 0, 255));

            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRoundedRect(MainWindow.Nvg, node.X - panelInset, node.Y, node.Width + 2 * panelInset, node.Height, borderRadius);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.DarkSlateGray.ToNvgColor());
            NanoVG.nvgBeginPath(MainWindow.Nvg);
            NanoVG.nvgRoundedRect(MainWindow.Nvg, node.X, node.Y + headerHeight + panelInset,
                                  node.Width, node.Height - headerHeight - 2 * panelInset,
                                  borderRadius - halfPanelInset);
            NanoVG.nvgFill(MainWindow.Nvg);

            NanoVG.nvgFillColor(MainWindow.Nvg, Color.White.ToNvgColor());

            NanoVG.nvgSave(MainWindow.Nvg);
            var headerOffset = (headerHeight + panelInset) / 2f - NvgHelper.MeasureString(node.Name).Height / 2;

            NanoVG.nvgTranslate(MainWindow.Nvg, (int)(node.X + 2 * panelInset), (int)(node.Y + headerOffset));
            NvgHelper.RenderString(node.Name);
            NanoVG.nvgRestore(MainWindow.Nvg);

            if (node.Input != null)
            {
                RenderConnector(node.Input);
            }

            foreach (var nodeOutput in node.Outputs)
            {
                RenderConnector(nodeOutput);
            }
            NanoVG.nvgRestore(MainWindow.Nvg);
        }
示例#14
0
        public override void Draw(NVGcontext ctx)
        {
            if (Width == 0 || Height == 0)
            {
                return;
            }

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgRect(ctx, X, Y, Width, Height);
            NanoVG.nvgStroke(ctx);
        }
示例#15
0
        public override void Draw(NVGcontext ctx)
        {
            if (A0 == A1 || Radius == 0)
            {
                return;
            }

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgArc(ctx, X, Y, Radius, A0, A1, Dir);
            NanoVG.nvgStroke(ctx);
        }
示例#16
0
        public override void Draw(NVGcontext ctx)
        {
            if (Radius == 0)
            {
                return;
            }

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgCircle(ctx, X, Y, Radius);
            NanoVG.nvgStroke(ctx);
        }
示例#17
0
 public void Render(NVGcontext nvg)
 {
     lock (_commands)
     {
         NanoVG.nvgSave(nvg);
         foreach (var simBody in _commands)
         {
             simBody.Execute(nvg);
         }
         NanoVG.nvgRestore(nvg);
     }
 }
示例#18
0
        public override void Draw(NVGcontext ctx)
        {
            if (X == X1 && Y == Y1)
            {
                return;
            }

            NanoVG.nvgBeginPath(ctx);
            NanoVG.nvgMoveTo(ctx, X, Y);
            NanoVG.nvgLineTo(ctx, X1, Y1);
            NanoVG.nvgStroke(ctx);
        }
示例#19
0
 public void Execute(NVGcontext ctx)
 {
     NanoVG.nvgBeginPath(ctx);
     Draw(ctx);
     if (Fill)
     {
         NanoVG.nvgFill(ctx);
     }
     else
     {
         NanoVG.nvgStroke(ctx);
     }
 }
示例#20
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);
            }
        }
示例#21
0
文件: UI.cs 项目: WildGenie/Libraria
        public override void Render(float Dt)
        {
            if (StateManager.GetTopState() != this)
            {
                return;
            }

            const float Offset = 20;

            NanoVG.DrawRectOutline(Color.DarkGray, 6.0f, Offset, Offset, NanoVG.Width - Offset * 2, NanoVG.Height - Offset * 2);

            NanoVG.DrawText("clacon", 24, TextAlign.TopLeft, DemoGameColor, 100, NanoVG.Height - 200, "Demo Game", ref DemoGameButton);
            NanoVG.DrawText("clacon", 24, TextAlign.TopLeft, ExitColor, 100, NanoVG.Height - 170, "Exit", ref ExitButton);
        }
示例#22
0
        private void RenderHandler(object sender, FrameEventArgs e)
        {
            // Reset the view
            GL.Clear(ClearBufferMask.ColorBufferBit |
                     ClearBufferMask.DepthBufferBit |
                     ClearBufferMask.StencilBufferBit);

            NanoVG.nvgBeginFrame(_nvg, Width, Height, 1);
            _simulator.Render(_nvg);
            NanoVG.nvgEndFrame(_nvg);

            // Swap the graphics buffer
            SwapBuffers();
        }
示例#23
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);
        }
示例#24
0
        public static void RenderString(string s)
        {
            if (string.IsNullOrWhiteSpace(s))
            {
                return;
            }

            NanoVG.nvgTextAlign(MainWindow.Nvg, (int)NvgAlign.Top | (int)NvgAlign.Left);
            NanoVG.nvgFontSize(MainWindow.Nvg, 16);
            NanoVG.nvgFontFace(MainWindow.Nvg, "sans");
            try
            {
                NanoVG.nvgText(MainWindow.Nvg, 0, 0, s);
            }
            catch (Exception e)
            {
                Lumberjack.Error($"NvgHelper::RenderString: {e.Message}");
            }
        }
示例#25
0
        public void RenderConnections(Node node)
        {
            if (!ScreenContains(node))
            {
                return;
            }
            NanoVG.nvgSave(MainWindow.Nvg);
            NanoVG.nvgStrokeColor(MainWindow.Nvg, NanoVG.nvgRGBA(128, 128, 128, 255));

            foreach (var connection in node.Outputs)
            {
                if (connection.ConnectedNode != null)
                {
                    RenderConnection(connection, connection.ConnectedNode);
                }
            }

            NanoVG.nvgRestore(MainWindow.Nvg);
        }
示例#26
0
        public void Render()
        {
            if (!Visible)
            {
                return;
            }

            NanoVG.nvgSave(MainWindow.Nvg);
            NanoVG.nvgTranslate(MainWindow.Nvg, X, Y);
            foreach (var menuItem in this)
            {
                menuItem.RenderBackground();
            }
            foreach (var menuItem in this)
            {
                menuItem.Render();
            }
            NanoVG.nvgRestore(MainWindow.Nvg);
        }
示例#27
0
        static void RenderContent(float Dt)
        {
            NanoVG.BeginFrame(RT.Width, RT.Height);
            //NanoVG.DrawRect(ClearColor, 0, 0, RT.Width, RT.Height);

            NanoVG.SetFont("clacon", LineHeight);
            NanoVG.TextAlign(TextAlign.TopLeft);

            string[] Lines = ConsoleLines.ToArray();
            for (int i = 0; i < Lines.Length; i++)
            {
                NanoVG.FillColor(Color.White);
                NanoVG.StyledText(0, LineHeight * i, Lines[i]);
            }

            NanoVG.FillColor(Color.Wheat);
            NanoVG.Text(0, LineHeight * MaxLines + 1, InputPrefix + Input + "_");
            NanoVG.EndFrame();
        }
示例#28
0
文件: UI.cs 项目: WildGenie/Libraria
        public override bool OnMouseButton(MouseButtonEventArgs E, bool Pressed)
        {
            int X = NanoVG.ScaleX(E.X);
            int Y = NanoVG.ScaleY(E.Y);

            if (Pressed && DemoGameButton?.Collide(X, Y) == true)
            {
                StateManager.Push(new DemoGameState());
                return(true);
            }

            if (Pressed && ExitButton?.Collide(X, Y) == true)
            {
                StateManager.Pop();
                Engine.Running = false;
                return(true);
            }

            return(base.OnMouseButton(E, Pressed));
        }
示例#29
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            PerfGraph.UpdateGraph((float)e.Time);

            GL.Viewport(0, 0, Width, Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);

            NanoVG.nvgBeginFrame(ctx, Width, Height, 1);

            if (screen)
            {
                screen.Draw(ctx);
            }
            PerfGraph.RenderGraph(ctx, 5, 5);

            NanoVG.nvgEndFrame(ctx);

            this.SwapBuffers();
        }
示例#30
0
        public override Vector2 GetPreferredSize(NVGcontext ctx)
        {
            if (!Vector2.Zero.Equals(this.fixedSize))
            {
                return(this.fixedSize);
            }

            int currFontSize = GetPreferredFontSize();
            int currFontFace = Fonts.Get(this.theme.fontNormal);

            NanoVG.nvgFontSize(ctx, currFontSize);
            NanoVG.nvgFontFace(ctx, currFontFace);

            float   tw = NanoVG.nvgTextBounds(ctx, 0f, 0f, this.caption, null);
            Vector2 ret;

            ret.X = tw + 1.7f * currFontSize;
            ret.Y = 1.3f * currFontSize;

            return(ret);
        }