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)); }
static void Main(string[] args) { var logger = Lumberjack.CreateLogger("Sandbox"); var screen = OutputDevices.Display; var w = new Window(screen.VisibleWidth, screen.VisibleHeight); w.Update += WindowUpdate; InputDevices.Digitizer.Pressed += (sender, code) => w.ConsumePress(InputDevices.Digitizer.State, code); InputDevices.Digitizer.Released += (sender, code) => w.ConsumeRelease(InputDevices.Digitizer.State, code); InputDevices.Digitizer.StylusUpdate += (sender, state) => w.ConsumeMove(state); InputDevices.Touchscreen.Pressed += (sender, finger) => w.ConsumePress(finger); InputDevices.Touchscreen.Released += (sender, finger) => w.ConsumeRelease(finger); InputDevices.Touchscreen.Moved += (sender, finger) => w.ConsumeMove(finger); var mainPage = w.CreatePage <MainPage>(); logger.Info("Showing main page"); w.ShowPage(mainPage); while (true) { } }
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}"); } }
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()); } }
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"); } }
private void HandleLoad(object sender, EventArgs e) { SetupOpenGl(); // Init keyboard to ensure first frame won't NPE Keyboard = OpenTK.Input.Keyboard.GetState(); _nodeRenderer = new NodeRenderer(this); Node.WidthCalculator = _nodeRenderer.GetNodeWidth; Selection = new SelectionHandler(this); DialogEditor = new FormDialogueEditor(this); DialogEditor.Show(); DialogEditor.Hide(); CreateContextMenu(null, 0, 0); _draggingConnectionPredicate = connection => Selection.DraggingConnection == null || Selection.DraggingConnection.ParentNode != connection.ParentNode && Selection.DraggingConnection.Side != connection.Side; RegisterKeybinds(); var keybinds = KeybindHandler.GetKeybinds(); Lumberjack.Info("Keybinds:"); foreach (var keyCombo in keybinds) { Lumberjack.Info($"- {keyCombo}"); } Lumberjack.Info("Window Loaded."); }
static void Main(string[] args) { var logger = Lumberjack.CreateLogger("Sandbox"); var threadLock = new ManualResetEventSlim(); var screen = OutputDevices.Display; // var w = new Window(screen.VisibleWidth, screen.VisibleHeight); // w.Update += WindowUpdate; // // InputDevices.Digitizer.Pressed += (sender, code) => w.ConsumePress(InputDevices.Digitizer.State, code); // InputDevices.Digitizer.Released += (sender, code) => w.ConsumeRelease(InputDevices.Digitizer.State, code); // InputDevices.Digitizer.StylusUpdate += (sender, state) => w.ConsumeMove(state); // // InputDevices.Touchscreen.Pressed += (sender, finger) => w.ConsumePress(finger); // InputDevices.Touchscreen.Released += (sender, finger) => w.ConsumeRelease(finger); // InputDevices.Touchscreen.Moved += (sender, finger) => w.ConsumeMove(finger); // // var mainPage = w.CreatePage<MainPage>(); // // logger.Info("Showing main page"); // w.ShowPage(mainPage); var center = new PointF(screen.VisibleWidth / 2f, screen.VisibleHeight / 2f); var margin = 50; _referencePoints = new[] { new PointF(margin, margin), new PointF(center.X, margin), new PointF(screen.VisibleWidth - margin, margin), new PointF(margin, center.Y), new PointF(center.X, center.Y), new PointF(screen.VisibleWidth - margin, center.Y), new PointF(margin, screen.VisibleHeight - margin), new PointF(center.X, screen.VisibleHeight - margin), new PointF(screen.VisibleWidth - margin, screen.VisibleHeight - margin), }; _frame = new Image <Rgb24>(screen.VisibleWidth, screen.VisibleHeight); _frame.Mutate(context => context .SetGraphicsOptions(options => options.Antialias = false) .Clear(Color.White) // .DrawPolygon(Color.Black, 1, Square(5, center, 45)) // .DrawPolygon(Color.Black, 1, Square(1, center)) ); OutputDevices.Display.Draw(_frame, _frame.Bounds(), Point.Empty, waveformMode: WaveformMode.Auto); // InputDevices.Digitizer.Calibrator.Calibration = BuiltinStylusCalibrations.FujitsuLifebookStylus; StylusState prevState = null; var time = DateTime.Now; InputDevices.Digitizer.StylusUpdate += (sender, state) => { if (prevState == null) { prevState = state; return; } if (((prevState.Pressure < 10 && state.Pressure >= 10) || _currentPointIdx == -1) && time <= DateTime.Now) { StylusPress(state); time = DateTime.Now + TimeSpan.FromMilliseconds(50); } prevState = state; }; OutputDevices.Display.Draw(_frame.Clone(DrawCalibrationMarker), _frame.Bounds(), Point.Empty, waveformMode: WaveformMode.Auto); threadLock.Wait(); }