Ejemplo n.º 1
0
        static void DrawGUI(float Dt)
        {
            Game.DrawGUI(Dt);

            NuklearAPI.Frame(() => {
                GConsole.NuklearDraw(10, 10);
            });
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Title = "Nuklear SFML .NET";
            Stopwatch SWatch = Stopwatch.StartNew();

            VideoMode    VMode      = new VideoMode(1366, 768);
            RenderWindow RWind      = new RenderWindow(VMode, Console.Title, Styles.Close);
            Color        ClearColor = new Color(50, 50, 50);

            RWind.Closed += (S, E) => RWind.Close();

            SFMLDevice Dev = new SFMLDevice(RWind);

            RWind.MouseButtonPressed  += (S, E) => Dev.OnMouseButton((NuklearEvent.MouseButton)E.Button, E.X, E.Y, true);
            RWind.MouseButtonReleased += (S, E) => Dev.OnMouseButton((NuklearEvent.MouseButton)E.Button, E.X, E.Y, false);
            RWind.MouseMoved          += (S, E) => Dev.OnMouseMove(E.X, E.Y);
            RWind.MouseWheelMoved     += (S, E) => Dev.OnScroll(0, E.Delta);
            RWind.TextEntered         += (S, E) => Dev.OnText(E.Unicode);
            RWind.KeyPressed          += (S, E) => OnKey(Dev, E, true);
            RWind.KeyReleased         += (S, E) => OnKey(Dev, E, false);

            NuklearAPI.Init(Dev);

            NuklearCalculator CalcA = new NuklearCalculator("Calc A", 50, 50);
            NuklearCalculator CalcB = new NuklearCalculator("Calc B", 300, 50);

            float Dt = 0.1f;

            while (RWind.IsOpen)
            {
                RWind.DispatchEvents();
                RWind.Clear(ClearColor);

                NuklearAPI.SetDeltaTime(Dt);
                NuklearAPI.Frame(() => {
                    if (CalcA.Open)
                    {
                        CalcA.Calculator();
                    }

                    if (CalcB.Open)
                    {
                        CalcB.Calculator();
                    }

                    TestWindow(400, 350);
                });

                RWind.Display();


                Dt = SWatch.ElapsedMilliseconds / 1000.0f;
                SWatch.Restart();
            }

            Environment.Exit(0);
        }
Ejemplo n.º 3
0
        public void Init(RenderWindow RWind, ShaderProgram GUIShader)
        {
            this.RWind = RWind;
            Docs       = new List <FMLDocument>();

            Dev = new FishGfxDevice(RWind.WindowSize, GUIShader);
            Dev.RegisterEvents(RWind);

            NuklearAPI.Init(Dev);
        }
Ejemplo n.º 4
0
        void PaintTag(FMLTag Tag)
        {
            FMLAttributes Attrib = Tag.Attributes;

            switch (Tag.TagName)
            {
            case "root": {
                PaintTags(Tag.Children);
                break;
            }

            case "window": {
                NkPanelFlags Flags = NkPanelFlags.BorderTitle;

                if (Attrib.GetAttribute("minimizable", true))
                {
                    Flags |= NkPanelFlags.Minimizable;
                }

                if (Attrib.GetAttribute("movable", false))
                {
                    Flags |= NkPanelFlags.Movable;
                }

                if (Attrib.GetAttribute("resizable", false))
                {
                    Flags |= NkPanelFlags.Scalable;
                }

                float X = Attrib.GetAttribute("x", 0.0f);
                float Y = Attrib.GetAttribute("y", 0.0f);
                float W = Attrib.GetAttribute("width", 50.0f);
                float H = Attrib.GetAttribute("height", 50.0f);

                NuklearAPI.Window(Attrib.GetAttribute("title", "Window"), X, Y, W, H, Flags, () => {
                        NuklearAPI.LayoutRowDynamic(35);

                        PaintTags(Tag.Children);
                    });
                break;
            }

            case "button": {
                if (NuklearAPI.ButtonLabel(Attrib.GetAttribute("text", "Button")))
                {
                }

                break;
            }

            default:
                throw new InvalidOperationException("Unknown tag name " + Tag.TagName);
            }
        }
Ejemplo n.º 5
0
        public static void Init(NuklearDevice Dev)
        {
            NuklearAPI.Init(Dev);

            CalcA = new NuklearCalculator("Calc A", 50, 50);
            CalcB = new NuklearCalculator("Calc B", 300, 50);

            for (int i = 0; i < 30; i++)
            {
                ConsoleBuffer.AppendLine("LINE NUMBER " + i);
            }
        }
Ejemplo n.º 6
0
        public void Init(RenderWindow RWind, ShaderProgram GUIShader)
        {
            this.RWind = RWind;
            Docs       = new List <FMLDocument>();

            Dev = new FishGfxDevice(RWind.WindowSize, GUIShader);
            Dev.RegisterEvents(RWind);

            NuklearAPI.Init(Dev);

            // TODO: Skinning
            ref nk_style style = ref NuklearAPI.Ctx->style;
Ejemplo n.º 7
0
        public static void DrawLoop(float DeltaTime = 0)
        {
            NuklearAPI.SetDeltaTime(DeltaTime);

            NuklearAPI.Frame(() => {
                if (CalcA.Open)
                {
                    CalcA.Calculator();
                }

                if (CalcB.Open)
                {
                    CalcB.Calculator();
                }

                TestWindow(400, 350);
                ConsoleThing(450, 200, ConsoleBuffer, InputBuffer);
            });
        }
Ejemplo n.º 8
0
        public static void NuklearDraw(int X, int Y)
        {
            const NkPanelFlags Flags         = NkPanelFlags.BorderTitle | NkPanelFlags.MovableScalable | NkPanelFlags.ClosableMinimizable;
            const string       ConWindowName = "GConsole";

            if (Open)
            {
                NuklearAPI.Window(ConWindowName, X, Y, 600, 400, Flags, () => {
                    NkRect Bounds = NuklearAPI.WindowGetBounds();
                    if (Bounds.H > 85)
                    {
                        NuklearAPI.LayoutRowDynamic(Bounds.H - 85);

                        NuklearAPI.Group("Console_OutBufferGroup", 0, () => {
                            NuklearAPI.LayoutRowDynamic(12);

                            for (int i = 0; i < OutBuffer.Length; i++)
                            {
                                GConsoleEntry E = OutBuffer[i];
                                if (E.Msg != null)
                                {
                                    NuklearAPI.LabelColored(E.Msg, E.Clr);
                                }
                            }
                        });
                    }

                    NuklearAPI.LayoutRowDynamic();
                    if (NuklearAPI.EditString(NkEditTypes.Field, InBuffer).HasFlag(NkEditEvents.Active) && NuklearAPI.IsKeyPressed(NkKeys.Enter))
                    {
                        SendInput(InBuffer.ToString());
                        InBuffer.Clear();
                    }
                });

                if (NuklearAPI.WindowIsHidden(ConWindowName))
                {
                    NuklearAPI.WindowClose(ConWindowName);
                    Open = false;
                }
            }
        }
Ejemplo n.º 9
0
        static void TestWindow(float X, float Y)
        {
            const NkPanelFlags Flags = NkPanelFlags.BorderTitle | NkPanelFlags.MovableScalable | NkPanelFlags.Minimizable | NkPanelFlags.ScrollAutoHide;

            NuklearAPI.Window("Test Window", X, Y, 200, 200, Flags, () => {
                NuklearAPI.LayoutRowDynamic(35);

                for (int i = 0; i < 5; i++)
                {
                    if (NuklearAPI.ButtonLabel("Some Button " + i))
                    {
                        Console.WriteLine("You pressed button " + i);
                    }
                }

                if (NuklearAPI.ButtonLabel("Exit"))
                {
                    Environment.Exit(0);
                }
            });
        }
Ejemplo n.º 10
0
        static void ConsoleThing(int X, int Y, StringBuilder OutBuffer, StringBuilder InBuffer)
        {
            const NkPanelFlags Flags = NkPanelFlags.BorderTitle | NkPanelFlags.MovableScalable | NkPanelFlags.Minimizable;

            NuklearAPI.Window("Console", X, Y, 300, 300, Flags, () => {
                NkRect Bounds = NuklearAPI.WindowGetBounds();
                NuklearAPI.LayoutRowDynamic(Bounds.H - 85);
                NuklearAPI.EditString(NkEditTypes.Editor | (NkEditTypes)(NkEditFlags.GotoEndOnActivate), OutBuffer);

                NuklearAPI.LayoutRowDynamic();
                if (NuklearAPI.EditString(NkEditTypes.Field, InBuffer).HasFlag(NkEditEvents.Active) && NuklearAPI.IsKeyPressed(NkKeys.Enter))
                {
                    string Txt = InBuffer.ToString().Trim();
                    InBuffer.Clear();

                    if (Txt.Length > 0)
                    {
                        OutBuffer.AppendLine(Txt);
                    }
                }
            });
        }
Ejemplo n.º 11
0
        static void TestWindow(float X, float Y)
        {
            nk_panel_flags Flags = nk_panel_flags.NK_WINDOW_BORDER | nk_panel_flags.NK_WINDOW_MOVABLE | nk_panel_flags.NK_WINDOW_TITLE
                                   | nk_panel_flags.NK_WINDOW_MINIMIZABLE | nk_panel_flags.NK_WINDOW_SCALABLE | nk_panel_flags.NK_WINDOW_SCROLL_AUTO_HIDE;

            NuklearAPI.Window("Test Window", X, Y, 200, 200, Flags, () => {
                NuklearAPI.LayoutRowDynamic(35);

                for (int i = 0; i < 5; i++)
                {
                    if (NuklearAPI.ButtonLabel("Some Button " + i))
                    {
                        Console.WriteLine("You pressed button " + i);
                    }
                }

                if (NuklearAPI.ButtonLabel("Exit"))
                {
                    Environment.Exit(0);
                }
            });
        }
Ejemplo n.º 12
0
        public void Draw()
        {
            Dev.WindowSize = RWind.WindowSize;

            NuklearAPI.Frame(() => {
                foreach (var D in Docs)
                {
                    PaintTags(D.Tags);
                }

                /*const NkPanelFlags Flags = NkPanelFlags.BorderTitle | NkPanelFlags.MovableScalable | NkPanelFlags.Minimizable | NkPanelFlags.ScrollAutoHide;
                 *
                 * NuklearAPI.Window("Test Window", 100, 100, 200, 200, Flags, () => {
                 *      NuklearAPI.LayoutRowDynamic(35);
                 *
                 *      for (int i = 0; i < 10; i++) {
                 *              if (NuklearAPI.ButtonLabel("Some Button #" + i))
                 *                      Console.WriteLine("You pressed Some Button #" + i);
                 *      }
                 * });*/
            });

            Docs.Clear();
        }
Ejemplo n.º 13
0
        static void LoadContent()
        {
            string GameDllPath = Path.Combine(CVar.GetString("game"), "Game.dll");

            if (!File.Exists(GameDllPath))
            {
                FatalError("File not found: {0}", GameDllPath);
            }

            Assembly GameAssembly = Reflect.LoadAssembly(GameDllPath);

            Importers.RegisterAll(GameAssembly);

            Type[] GameImplementations = Reflect.GetAllImplementationsOf(GameAssembly, typeof(LibTechGame)).ToArray();

            if (GameImplementations.Length == 0)
            {
                FatalError("Could not find game implementation in {0}", GameDllPath);
            }
            if (GameImplementations.Length > 1)
            {
                FatalError("Found too many game implementations in {0}", GameDllPath);
            }

            Game = (LibTechGame)Activator.CreateInstance(GameImplementations[0]);
            Game.Load();

            RenderDevice = new RenderDevice(ShaderProgram.GUI, Width, Height);
            NuklearAPI.Init(RenderDevice);
            NuklearAPI.SetClipboardCallback((Txt) => {
                if (string.IsNullOrEmpty(Txt))
                {
                    return;
                }

                Glfw.SetClipboardString(Window, Txt);
            }, () => {
                string Str = Glfw.GetClipboardString(Window);
                if (Str == null)
                {
                    Str = "";
                }

                return(Str);
            });

            Glfw.SetCursorPosCallback(Window, (Wnd, X, Y) => {
                RenderDevice.OnMouseMove((int)X, (int)Y);
            });

            Glfw.SetMouseButtonCallback(Window, (Wnd, Button, State, Mods) => {
                NuklearEvent.MouseButton NkButton;
                bool IsDown = State == Glfw.InputState.Press ? true : false;

                if (!(State == Glfw.InputState.Press || State == Glfw.InputState.Release))
                {
                    return;
                }

                if (Button == Glfw.MouseButton.ButtonLeft)
                {
                    NkButton = NuklearEvent.MouseButton.Left;
                }
                else if (Button == Glfw.MouseButton.ButtonMiddle)
                {
                    NkButton = NuklearEvent.MouseButton.Middle;
                }
                else if (Button == Glfw.MouseButton.ButtonRight)
                {
                    NkButton = NuklearEvent.MouseButton.Right;
                }
                else
                {
                    return;
                }

                RenderDevice.OnMouseButton(NkButton, (int)MousePos.X, (int)MousePos.Y, IsDown);
            });

            Glfw.SetScrollCallback(Window, (Wnd, X, Y) => {
                RenderDevice.OnScroll((float)X, (float)Y);
            });

            Glfw.SetCharCallback(Window, (Wnd, Chr) => {
                RenderDevice.OnText(((char)Chr).ToString());
            });

            Glfw.SetKeyCallback(Window, (Wnd, KCode, SCode, State, Mods) => {
                if (KCode == Glfw.KeyCode.F1 && State == Glfw.InputState.Press)
                {
                    GConsole.Open = true;
                }

                NkKeys K = ConvertToNkKey(KCode, Mods);

                if (K != NkKeys.None)
                {
                    RenderDevice.OnKey(K, State == Glfw.InputState.Press);
                    if (State == Glfw.InputState.Repeat)
                    {
                        RenderDevice.OnKey(K, true);
                    }
                }
            });

            Glfw.SetDropCallback(Window, (Wnd, Cnt, Paths) => {
                DragDropPaths = Paths;
            });
        }
Ejemplo n.º 14
0
            public void Calculator()
            {
                const string       Numbers = "789456123";
                const string       Ops     = "+-*/";
                const NkPanelFlags F       = NkPanelFlags.Border | NkPanelFlags.Movable | NkPanelFlags.NoScrollbar | NkPanelFlags.Title
                                             | NkPanelFlags.Closable | NkPanelFlags.Minimizable;

                bool   Solve = false;
                string BufferStr;

                NuklearAPI.Window(Name, X, Y, 180, 250, F, () => {
                    NuklearAPI.LayoutRowDynamic(35, 1);

                    Buffer.Clear();
                    Buffer.AppendFormat("{0:0.00}", Current);

                    NuklearAPI.EditString(NkEditTypes.Simple, Buffer, (ref nk_text_edit TextBox, uint Rune) => {
                        char C = (char)Rune;

                        if (char.IsNumber(C))
                        {
                            return(1);
                        }

                        return(0);
                    });

                    BufferStr = Buffer.ToString().Trim();
                    if (BufferStr.Length > 0)
                    {
                        if (float.TryParse(BufferStr, out float CurFloat))
                        {
                            Current = CurFloat;
                        }
                    }

                    NuklearAPI.LayoutRowDynamic(35, 4);
                    for (int i = 0; i < 16; i++)
                    {
                        if (i == 12)
                        {
                            if (NuklearAPI.ButtonLabel("C"))
                            {
                                A             = B = 0;
                                Op            = ' ';
                                Set           = false;
                                CurrentThingy = CurrentThing.A;
                            }

                            if (NuklearAPI.ButtonLabel("0"))
                            {
                                Current = Current * 10;
                                Op      = ' ';
                            }

                            if (NuklearAPI.ButtonLabel("="))
                            {
                                Solve = true;
                                Prev  = Op;
                                Op    = ' ';
                            }
                        }
                        else if (((i + 1) % 4) != 0)
                        {
                            int NumIdx = (i / 4) * 3 + i % 4;

                            if (NumIdx < Numbers.Length && NuklearAPI.ButtonText(Numbers[NumIdx]))
                            {
                                Current = Current * 10 + int.Parse(Numbers[NumIdx].ToString());
                                Set     = false;
                            }
                        }
                        else if (NuklearAPI.ButtonText(Ops[i / 4]))
                        {
                            if (!Set)
                            {
                                if (CurrentThingy != CurrentThing.B)
                                {
                                    CurrentThingy = CurrentThing.B;
                                }
                                else
                                {
                                    Prev  = Op;
                                    Solve = true;
                                }
                            }

                            Op  = Ops[i / 4];
                            Set = true;
                        }
                    }

                    if (Solve)
                    {
                        if (Prev == '+')
                        {
                            A = A + B;
                        }
                        else if (Prev == '-')
                        {
                            A = A - B;
                        }
                        else if (Prev == '*')
                        {
                            A = A * B;
                        }
                        else if (Prev == '/')
                        {
                            A = A / B;
                        }

                        CurrentThingy = CurrentThing.A;
                        if (Set)
                        {
                            CurrentThingy = CurrentThing.B;
                        }

                        B   = 0;
                        Set = false;
                    }
                });

                if (NuklearAPI.WindowIsClosed(Name) || NuklearAPI.WindowIsHidden(Name))
                {
                    Open = false;
                }
            }
Ejemplo n.º 15
0
            public void Calculator()
            {
                const string         Numbers = "789456123";
                const string         Ops     = "+-*/";
                const nk_panel_flags F       = nk_panel_flags.NK_WINDOW_BORDER | nk_panel_flags.NK_WINDOW_MOVABLE | nk_panel_flags.NK_WINDOW_NO_SCROLLBAR | nk_panel_flags.NK_WINDOW_TITLE
                                               | nk_panel_flags.NK_WINDOW_CLOSABLE | nk_panel_flags.NK_WINDOW_MINIMIZABLE;

                bool   Solve = false;
                string BufferStr;

                NuklearAPI.Window(Name, X, Y, 180, 250, F, () => {
                    NuklearAPI.LayoutRowDynamic(35, 1);

                    Buffer.Clear();
                    Buffer.AppendFormat("{0:0.00}", Current);
                    int Len = Buffer.Length;

                    NuklearAPI.EditString(nk_edit_types.NK_EDIT_SIMPLE, Buffer, ref Len, (ref nk_text_edit TextBox, uint Rune) => {
                        char C = (char)Rune;

                        if (char.IsNumber(C))
                        {
                            return(1);
                        }

                        return(0);
                    });

                    BufferStr = Buffer.ToString().Trim();
                    if (BufferStr.Length > 0)
                    {
                        if (float.TryParse(BufferStr, out float CurFloat))
                        {
                            Current = CurFloat;
                        }
                    }

                    NuklearAPI.LayoutRowDynamic(35, 4);
                    for (int i = 0; i < 16; i++)
                    {
                        if (i == 12)
                        {
                            if (NuklearAPI.ButtonLabel("C"))
                            {
                                A             = B = 0;
                                Op            = ' ';
                                Set           = false;
                                CurrentThingy = CurrentThing.A;
                            }

                            if (NuklearAPI.ButtonLabel("0"))
                            {
                                Current = Current * 10;
                                Op      = ' ';
                            }

                            if (NuklearAPI.ButtonLabel("="))
                            {
                                Solve = true;
                                Prev  = Op;
                                Op    = ' ';
                            }
                        }
                        else if (((i + 1) % 4) != 0)
                        {
                            int NumIdx = (i / 4) * 3 + i % 4;

                            if (NumIdx < Numbers.Length && NuklearAPI.ButtonText(Numbers[NumIdx]))
                            {
                                Current = Current * 10 + int.Parse(Numbers[NumIdx].ToString());
                                Set     = false;
                            }
                        }
                        else if (NuklearAPI.ButtonText(Ops[i / 4]))
                        {
                            if (!Set)
                            {
                                if (CurrentThingy != CurrentThing.B)
                                {
                                    CurrentThingy = CurrentThing.B;
                                }
                                else
                                {
                                    Prev  = Op;
                                    Solve = true;
                                }
                            }

                            Op  = Ops[i / 4];
                            Set = true;
                        }
                    }

                    if (Solve)
                    {
                        if (Prev == '+')
                        {
                            A = A + B;
                        }
                        else if (Prev == '-')
                        {
                            A = A - B;
                        }
                        else if (Prev == '*')
                        {
                            A = A * B;
                        }
                        else if (Prev == '/')
                        {
                            A = A / B;
                        }

                        CurrentThingy = CurrentThing.A;
                        if (Set)
                        {
                            CurrentThingy = CurrentThing.B;
                        }

                        B   = 0;
                        Set = false;
                    }
                });

                if (NuklearAPI.WindowIsClosed(Name) || NuklearAPI.WindowIsHidden(Name))
                {
                    Open = false;
                }
            }