Exemplo n.º 1
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));
        }
Exemplo n.º 2
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}");
            }
        }
Exemplo n.º 3
0
        private void Update(object sender, FrameEventArgs e)
        {
            Title = $"FPS: {Math.Round(RenderFrequency)} | RenderTime: {Math.Round(RenderTime * 1000)}ms";

            // Grab the new keyboard state
            Keyboard = OpenTK.Input.Keyboard.GetState();

            if (_shouldDie)
            {
                Exit();
            }

            Selection.HoveringConnection = Graph.PickConnection(_mouseCanvasSpace.X, _mouseCanvasSpace.Y);

            var err = GL.GetError();

            if (err != ErrorCode.NoError)
            {
                Lumberjack.Error(err.ToString());
            }
        }
Exemplo n.º 4
0
        private static void SetupOpenGl()
        {
            // Set up caps
            GL.Disable(EnableCap.DepthTest);
            GL.Enable(EnableCap.RescaleNormal);

            // Set up blending
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            // Set background color
            GL.ClearColor(Color.White);

            GlNanoVG.nvgCreateGL(ref Nvg, (int)NvgCreateFlags.AntiAlias | (int)NvgCreateFlags.StencilStrokes);
            var rSans = NanoVG.nvgCreateFont(Nvg, "sans",
                                             $"Resources{Path.DirectorySeparatorChar}Fonts{Path.DirectorySeparatorChar}latosemi.ttf");

            if (rSans == -1)
            {
                Lumberjack.Error("Unable to load sans");
            }
        }