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 LoadHandler(object sender, EventArgs e) { // 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); // Init keyboard to ensure first frame won't NPE _keyboard = Keyboard.GetState(); _mouse = Mouse.GetState(); GlNanoVG.nvgCreateGL(ref _nvg, (int)NvgCreateFlags.AntiAlias | (int)NvgCreateFlags.StencilStrokes); NanoVG.nvgStrokeWidth(_nvg, 1); NanoVG.nvgStrokeColor(_nvg, NanoVG.nvgRGBA(0, 0, 0, 255)); _simulator = new Simulator(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); GL.ClearColor(Color.Cornsilk); GlNanoVG.nvgCreateGL(ref ctx, (int)NVGcreateFlags.NVG_ANTIALIAS | (int)NVGcreateFlags.NVG_STENCIL_STROKES | (int)NVGcreateFlags.NVG_DEBUG); Fonts.Load(ctx, "sans", "Roboto-Regular.ttf"); Fonts.Load(ctx, "sans-bold", "Roboto-Bold.ttf"); Fonts.Load(ctx, "icons", "entypo.ttf"); screen = new Widget() .WithLocalPosition(Vector2.Zero) .WithSize(new Vector2(this.Width, this.Height)); { Window window = screen.AddNewWidget <Window> (); window.WithTitle("Button demo") .WithLocalPosition(new Vector2(15f, 50f)) .WithSize(new Vector2(250f, 400f)) .WithLayout(new GroupLayout()); // -- Push buttons window.AddNewWidget <Label> () .WithCaption("Push buttons") .WithFont("sans-bold"); window.AddNewWidget <Button> () .WithCaption("Plain button") .WithClickCallback((btn) => Console.WriteLine("Click!")); window.AddNewWidget <Button> () .WithCaption("Styled") .WithIcon((int)MonoNanoGUI.Font.Entypo.ICON_ROCKET, Button.IconAnchorType.LeftCentered); // -- Toggle buttons window.AddNewWidget <Label> () .WithCaption("Toggle buttons") .WithFont("sans-bold"); window.AddNewWidget <Button> () .WithFlags(Button.Flags.ToggleButton) .WithCaption("Toggle me"); // -- Radio buttons window.AddNewWidget <Label> () .WithCaption("Radio buttons") .WithFont("sans-bold"); window.AddNewWidget <Button> () .WithCaption("Radio button 1") .WithFlags(Button.Flags.RadioButton); window.AddNewWidget <Button> () .WithCaption("Radio button 2") .WithFlags(Button.Flags.RadioButton); // -- Tool buttons palette window.AddNewWidget <Label> () .WithCaption("A tool palette") .WithFont("sans-bold"); Widget tools = window.AddNewWidget <Widget> () .WithLayout(new BoxLayout(Layout.Orientation.Horizontal, Layout.Alignment.Middle, 0, 6)); tools.AddChild(Button.MakeToolButton((int)MonoNanoGUI.Font.Entypo.ICON_CLOUD)); tools.AddChild(Button.MakeToolButton((int)MonoNanoGUI.Font.Entypo.ICON_FF)); tools.AddChild(Button.MakeToolButton((int)MonoNanoGUI.Font.Entypo.ICON_COMPASS)); tools.AddChild(Button.MakeToolButton((int)MonoNanoGUI.Font.Entypo.ICON_INSTALL)); // -- Popup buttons window.AddNewWidget <Label> () .WithCaption("Popup buttons") .WithFont("sans-bold"); PopupButton pButton = window.AddNewWidget <PopupButton> () .WithIcon((int)MonoNanoGUI.Font.Entypo.ICON_EXPORT) .WithCaption("Popup") as PopupButton; pButton.popup.WithLayout(new GroupLayout()); pButton.popup.AddNewWidget <Label> () .WithCaption("Arbitrary widgets can be placed here"); pButton.popup.AddNewWidget <CheckBox> () .WithCaption("A check box"); PopupButton rpButton = pButton.popup.AddNewWidget <PopupButton> () .WithIcon((int)MonoNanoGUI.Font.Entypo.ICON_FLASH) .WithCaption("Recursive popup") as PopupButton; rpButton.popup.WithLayout(new GroupLayout()); rpButton.popup.AddNewWidget <CheckBox> () .WithCaption("Another check box"); } screen.PerformLayout(ctx); PerfGraph.InitGraph((int)GraphrenderStyle.GRAPH_RENDER_FPS, "FPS"); Console.WriteLine("Load"); //Console.WriteLine ("Test Unicode to UTF8 = " + Fonts.UnicodeToUTF8 (0).Length); }