Esempio n. 1
0
        public static void PopupEnd(this NuklearContext ctx)
        {
            nk_window win;
            nk_window popup;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            popup = ctx.current;
            if (popup.Parent == null)
            {
                return;
            }
            win = popup.Parent;
            if ((popup.Flags & NK_WINDOW_HIDDEN) != 0)
            {
                nk_panel root;
                root = win.Layout;
                while (root != null)
                {
                    root.Flags |= NK_WINDOW_REMOVE_ROM;
                    root        = root.Parent;
                }

                win.Popup.Active = 0;
            }

            popup.Buffer.Scissor(RectangleF.Null);
            ctx.End();
            win.Buffer = popup.Buffer;
            FinishPopup(ctx, win);
            ctx.current = win;
            win.Buffer.Scissor(win.Layout.Clip);
        }
Esempio n. 2
0
        public static bool CheckText(this NuklearContext ctx, string text, bool active)
        {
            nk_window win;
            nk_panel  layout;
            nk_input  _in_;
            nk_style  style;
            var       bounds = new RectangleF();
            int       state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(active);
            }
            win    = ctx.current;
            style  = ctx.style;
            layout = win.Layout;
            state  = ctx.Widget(ref bounds);
            if (state == 0)
            {
                return(active);
            }
            _in_ = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            DoToggle(ref ctx.last_widget_state, win.Buffer, bounds, ref active, text,
                     NK_TOGGLE_CHECK, style.checkbox, _in_, style.font);
            return(active);
        }
Esempio n. 3
0
        public static void MenubarEnd(this NuklearContext ctx)
        {
            nk_window     win;
            nk_panel      layout;
            CommandBuffer _out_;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            win    = ctx.current;
            _out_  = win.Buffer;
            layout = win.Layout;
            if ((layout.Flags & NK_WINDOW_HIDDEN) != 0 || (layout.Flags & NK_WINDOW_MINIMIZED) != 0)
            {
                return;
            }
            layout.Menu.Height    = layout.At_y - layout.Menu.Y;
            layout.Bounds.Y      += layout.Menu.Height + ctx.style.window.spacing.Y + layout.Row.height;
            layout.Bounds.Height -= layout.Menu.Height + ctx.style.window.spacing.Y + layout.Row.height;
            layout.Offset         = layout.Menu.offset;
            layout.At_y           = layout.Bounds.Y - layout.Row.height;
            layout.Clip.Y         = layout.Bounds.Y;
            layout.Clip.Height    = layout.Bounds.Height;
            _out_.Scissor(layout.Clip);
        }
Esempio n. 4
0
        public static void FinishPopup(this NuklearContext ctx, nk_window win)
        {
            if (ctx == null || win == null)
            {
                return;
            }

            win.Buffer = win.Popup.Buffer.OldBuffer;
        }
Esempio n. 5
0
        public static void PopupClose(this NuklearContext ctx)
        {
            nk_window popup;

            if (ctx == null || ctx.current == null)
            {
                return;
            }
            popup        = ctx.current;
            popup.Flags |= NK_WINDOW_HIDDEN;
        }
Esempio n. 6
0
        public static bool RadioText(this NuklearContext ctx, string text, bool *active)
        {
            bool old_value;

            if (ctx == null || text == null || active == null)
            {
                return(false);
            }
            old_value = *active;
            *active = OptionText(ctx, text, old_value);
            return(old_value != *active);
        }
Esempio n. 7
0
        public static bool CheckboxText(this NuklearContext ctx, string text, ref bool active)
        {
            bool old_val;

            if (ctx == null || text == null)
            {
                return(false);
            }
            old_val = active;
            active  = CheckText(ctx, text, active);
            return(old_val != active);
        }
Esempio n. 8
0
        public static void StartPopup(this NuklearContext ctx, nk_window win)
        {
            if (ctx == null || win == null)
            {
                return;
            }

            var buf = win.Popup.Buffer.Buffer;

            buf.First = buf.Last = null;
            buf.Count = 0;

            win.Popup.Buffer.OldBuffer = win.Buffer;
            win.Buffer = buf;
        }
Esempio n. 9
0
        public static void Image(this NuklearContext ctx, nk_image img)
        {
            nk_window win;
            var       bounds = new RectangleF();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            win = ctx.current;
            if (ctx.Widget(ref bounds) == 0)
            {
                return;
            }
            win.Buffer.DrawImage(bounds, img, nk_white);
        }
Esempio n. 10
0
        /// <summary>
        ///     Allows the game to perform any initialization it needs to before starting to run.
        ///     This is where it can query for any required services and load any non-graphic
        ///     related content.  Calling base.Initialize will enumerate through any components
        ///     and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _nuklearContext = new NuklearContext(this);

            nk_font font = nk_font.FromTtf(File.ReadAllBytes(Path.Combine(Content.RootDirectory, "Fonts/Roboto-Regular.ttf")));

            _nuklearContext.SetFont(font);

            IsMouseVisible           = true;
            Window.AllowUserResizing = true;
        }
Esempio n. 11
0
        /// <summary>
        ///     Allows the game to perform any initialization it needs to before starting to run.
        ///     This is where it can query for any required services and load any non-graphic
        ///     related content.  Calling base.Initialize will enumerate through any components
        ///     and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            Window.Title = "Demo";

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _contextWrapper = new NuklearContext(this);

            // Fonts
            var fontData = File.ReadAllBytes(GetAssetPath("Fonts/Roboto-Regular.ttf"));

            _media.font = nk_font.FromTtf(fontData);

            _media.uncheckd = LoadImage("Icons/unchecked.png");
            _media.checkd   = LoadImage("Icons/checked.png");
            _media.rocket   = LoadImage("Icons/rocket.png");
            _media.cloud    = LoadImage("Icons/cloud.png");
            _media.pen      = LoadImage("Icons/pen.png");
            _media.play     = LoadImage("Icons/play.png");
            _media.pause    = LoadImage("Icons/pause.png");
            _media.stop     = LoadImage("Icons/stop.png");
            _media.next     = LoadImage("Icons/next.png");
            _media.prev     = LoadImage("Icons/prev.png");
            _media.tools    = LoadImage("Icons/tools.png");
            _media.dir      = LoadImage("Icons/directory.png");
            _media.copy     = LoadImage("Icons/copy.png");
            _media.convert  = LoadImage("Icons/export.png");
            _media.del      = LoadImage("Icons/delete.png");
            _media.edit     = LoadImage("Icons/edit.png");
            _media.menu[0]  = LoadImage("Icons/home.png");
            _media.menu[1]  = LoadImage("Icons/phone.png");
            _media.menu[2]  = LoadImage("Icons/plane.png");
            _media.menu[3]  = LoadImage("Icons/wifi.png");
            _media.menu[4]  = LoadImage("Icons/settings.png");
            _media.menu[5]  = LoadImage("Icons/volume.png");

            for (var i = 0; i < _media.images.Length; ++i)
            {
                _media.images[i] = LoadImage("Images/image" + (i + 1) + ".png");
            }

            base.Initialize();
        }
Esempio n. 12
0
        public static uint CheckFlagsText(this NuklearContext ctx, string text, uint flags, uint value)
        {
            bool old_active;

            if (ctx == null || text == null)
            {
                return(flags);
            }
            old_active = (flags & value) != 0;
            if (CheckText(ctx, text, old_active))
            {
                flags |= value;
            }
            else
            {
                flags &= ~value;
            }
            return(flags);
        }
Esempio n. 13
0
        public static void MenubarBegin(this NuklearContext ctx)
        {
            nk_panel layout;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            layout = ctx.current.Layout;
            if ((layout.Flags & NK_WINDOW_HIDDEN) != 0 || (layout.Flags & NK_WINDOW_MINIMIZED) != 0)
            {
                return;
            }
            layout.Menu.X      = layout.At_x;
            layout.Menu.Y      = layout.At_y + layout.Row.height;
            layout.Menu.Width  = layout.Bounds.Width;
            layout.Menu.offset = layout.Offset;

            layout.Offset.Y = 0;
        }
Esempio n. 14
0
        /// <summary>
        ///     Grids the demo.
        /// </summary>
        /// <param name="ctx">Context.</param>
        /// <param name="media">Media.</param>
        public static void grid_demo(this NuklearContext ctx, Media media)
        {
            int i;

            ctx.StyleSetFont(media.font);
            ctx.StyleSetFontSize(20);
            if (ctx.Begin("Grid Demo", new RectangleF(600, 350, 275, 250),
                          Nuklear.NK_WINDOW_TITLE | Nuklear.NK_WINDOW_BORDER | Nuklear.NK_WINDOW_MOVABLE |
                          Nuklear.NK_WINDOW_NO_SCROLLBAR))
            {
                ctx.StyleSetFontSize(18);
                ctx.LayoutRowDynamic(30, 2);
                ctx.Label("String:", nk_text_align.NK_TEXT_RIGHT);
                ctx.EditString(Nuklear.NK_EDIT_FIELD, ref edit_strings[0], 64, Nuklear.nk_filter_default);
                ctx.Label("Floating point:", nk_text_align.NK_TEXT_RIGHT);
                ctx.EditString(Nuklear.NK_EDIT_FIELD, ref edit_strings[1], 64, Nuklear.nk_filter_float);
                ctx.Label("Hexadecimal:", nk_text_align.NK_TEXT_RIGHT);
                ctx.EditString(Nuklear.NK_EDIT_FIELD, ref edit_strings[2], 64, Nuklear.nk_filter_hex);
                ctx.Label("Binary:", nk_text_align.NK_TEXT_RIGHT);
                ctx.EditString(Nuklear.NK_EDIT_FIELD, ref edit_strings[3], 64, Nuklear.nk_filter_binary);
                ctx.Label("Checkbox:", nk_text_align.NK_TEXT_RIGHT);
                ctx.CheckboxLabel("Check me", ref grid_check);
                ctx.Label("Combobox:", nk_text_align.NK_TEXT_RIGHT);
                if (ctx.ComboBeginLabel(items[selectedItem], new Vector2(ctx.WidgetWidth(), 200)))
                {
                    ctx.LayoutRowDynamic(25, 1);
                    for (i = 0; i < 3; ++i)
                    {
                        if (ctx.ComboItemLabel(items[i], nk_text_align.NK_TEXT_LEFT))
                        {
                            selectedItem = i;
                        }
                    }
                    ctx.ComboEnd();
                }
            }

            ctx.End();
            ctx.StyleSetFontSize(14);
        }
Esempio n. 15
0
        /// <summary>
        ///     Grids the demo.
        /// </summary>
        /// <param name="ctx">Context.</param>
        /// <param name="media">Media.</param>
        public static void grid_demo(NuklearContext ctx, Media media)
        {
            int i;

            ctx.StyleSetFont(media.Font20.Handle);
            if (ctx.Begin("Grid Demo", Nk.nk_rect_(600, 350, 275, 250),
                          PanelFlags.TITLE | PanelFlags.BORDER | PanelFlags.MOVABLE |
                          PanelFlags.NO_SCROLLBAR))
            {
                ctx.StyleSetFont(media.Font18.Handle);
                ctx.LayoutRowDynamic(30, 2);
                ctx.Label("String:", Alignment.MIDDLERIGHT);
                ctx.EditString(NkEditFlags.FIELD, ref EditStrings[0], 64, Nk.nk_filter_default);
                ctx.Label("Floating point:", Alignment.MIDDLERIGHT);
                ctx.EditString(NkEditFlags.FIELD, ref EditStrings[1], 64, Nk.nk_filter_float);
                ctx.Label("Hexadecimal:", Alignment.MIDDLERIGHT);
                ctx.EditString(NkEditFlags.FIELD, ref EditStrings[2], 64, Nk.nk_filter_hex);
                ctx.Label("Binary:", Alignment.MIDDLERIGHT);
                ctx.EditString(NkEditFlags.FIELD, ref EditStrings[3], 64, Nk.nk_filter_binary);
                ctx.Label("Checkbox:", Alignment.MIDDLERIGHT);
                ctx.CheckboxLabel("Check me", ref _gridCheck);
                ctx.Label("Combobox:", Alignment.MIDDLERIGHT);
                if (ctx.ComboBeginLabel(Items[_selectedItem2], Nk.nk_vec2_(ctx.WidgetWidth(), 200)))
                {
                    ctx.LayoutRowDynamic(25, 1);
                    for (i = 0; i < 3; ++i)
                    {
                        if (ctx.ComboItemLabel(Items[i], Alignment.MIDDLELEFT))
                        {
                            _selectedItem2 = i;
                        }
                    }
                    ctx.ComboEnd();
                }
            }
            ctx.End();
            ctx.StyleSetFont(media.Font14.Handle);
        }
Esempio n. 16
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _nuklearContext = new NuklearContext(GraphicsDevice);

            Nuklear.nk_font font;
            using (var stream = File.OpenRead(Path.Combine(Content.RootDirectory, "Fonts/Roboto-Regular.ttf")))
            {
                var fontAtlas = new FontAtlasWrapper(_nuklearContext);
                font = fontAtlas.AddFont(stream, 22);
                fontAtlas.Bake();
            }

            _nuklearContext.SetFont(font);

            IsMouseVisible           = true;
            Window.AllowUserResizing = true;
        }
Esempio n. 17
0
        public static bool CheckboxFlagsText(this NuklearContext ctx, string text, uint *flags, uint value)
        {
            bool active;

            if (ctx == null || text == null || flags == null)
            {
                return(false);
            }
            active = (*flags & value) != 0;
            if (CheckboxText(ctx, text, ref active))
            {
                if (active)
                {
                    *flags |= value;
                }
                else
                {
                    *flags &= ~value;
                }
                return(true);
            }

            return(false);
        }
Esempio n. 18
0
 public static bool CheckboxLabel(this NuklearContext ctx, string label, ref bool active)
 {
     return(CheckboxText(ctx, label, ref active));
 }
Esempio n. 19
0
 public static bool CheckLabel(this NuklearContext ctx, string label, bool active)
 {
     return(CheckText(ctx, label, active));
 }
Esempio n. 20
0
 public static bool OptionLabel(this NuklearContext ctx, string label, bool active)
 {
     return(OptionText(ctx, label, active));
 }
Esempio n. 21
0
        public static void basic_demo(this NuklearContext ctx, Media media)
        {
            int i;

            ctx.StyleSetFont(media.font);
            ctx.StyleSetFontSize(20);
            ctx.Begin("Basic Demo", new RectangleF(320, 50, 275, 610),
                      Nuklear.NK_WINDOW_BORDER | Nuklear.NK_WINDOW_MOVABLE | Nuklear.NK_WINDOW_TITLE);

            ui_header(ctx, media, "Popup & Scrollbar & Images");
            ui_widget(ctx, media, 35);
            if (ctx.ButtonImageLabel(media.dir, "Images", nk_text_align.NK_TEXT_CENTERED))
            {
                image_active = !image_active;
            }

            ui_header(ctx, media, "Selected Image");
            ui_widget_centered(ctx, media, 100);
            ctx.Image(media.images[selected_image]);

            if (image_active)
            {
                if (ctx.PopupBegin(Nuklear.NK_POPUP_STATIC, "Image Popup", 0, new RectangleF(265, 0, 320, 220)))
                {
                    ctx.LayoutRowStatic(82, 82, 3);
                    for (i = 0; i < 9; ++i)
                    {
                        if (ctx.ButtonImage(media.images[i]))
                        {
                            selected_image = i;
                            image_active   = false;
                            ctx.PopupClose();
                        }
                    }

                    ctx.PopupEnd();
                }
            }

            ui_header(ctx, media, "Combo box");
            ui_widget(ctx, media, 40);
            if (ctx.ComboBeginLabel(items2[selected_item], new Vector2(ctx.WidgetWidth(), 200)))
            {
                ctx.LayoutRowDynamic(35, 1);
                for (i = 0; i < 3; ++i)
                {
                    if (ctx.ComboItemLabel(items2[i], nk_text_align.NK_TEXT_LEFT))
                    {
                        selected_item = i;
                    }
                }
                ctx.ComboEnd();
            }

            ui_widget(ctx, media, 40);
            if (ctx.ComboBeginImageLabel(items2[selected_icon], media.images[selected_icon],
                                         new Vector2(ctx.WidgetWidth(), 200)))
            {
                ctx.LayoutRowDynamic(35, 1);
                for (i = 0; i < 3; ++i)
                {
                    if (ctx.ComboItemImageLabel(media.images[i], items2[i], nk_text_align.NK_TEXT_RIGHT))
                    {
                        selected_icon = i;
                    }
                }
                ctx.ComboEnd();
            }

            ui_header(ctx, media, "Checkbox");
            ui_widget(ctx, media, 30);
            ctx.CheckboxLabel("Flag 1", ref check0);
            ui_widget(ctx, media, 30);
            ctx.CheckboxLabel("Flag 2", ref check1);

            ui_header(ctx, media, "Progressbar");
            ui_widget(ctx, media, 35);
            ctx.Progress(ref prog, 100, Nuklear.nk_true);

            if (Nuklear.nk_input_is_mouse_click_down_in_rect(ctx.input, Nuklear.NK_BUTTON_RIGHT, ctx.WindowGetBounds(),
                                                             true))
            {
                piemenu_pos    = ctx.input.mouse.pos;
                piemenu_active = true;
            }

            if (piemenu_active)
            {
                var ret = ui_piemenu(ctx, piemenu_pos, 140, media.menu, 6);
                if (ret == -2)
                {
                    piemenu_active = false;
                }
                if (ret != -1)
                {
                    Console.Write("piemenu selected: {0}\n", ret);
                    piemenu_active = false;
                }
            }

            ctx.StyleSetFontSize(14);
            ctx.End();
        }
Esempio n. 22
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            Window.Title = "Demo";

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _contextWrapper = new NuklearContext(GraphicsDevice);

            // Fonts
            var fontData  = File.ReadAllBytes(GetAssetPath("Fonts/Roboto-Regular.ttf"));
            var fontAtlas = new FontAtlasWrapper(_contextWrapper);

            using (var stream = new MemoryStream(fontData))
            {
                _media.font_14 = fontAtlas.AddFont(stream, 14);
            }

            using (var stream = new MemoryStream(fontData))
            {
                _media.font_18 = fontAtlas.AddFont(stream, 18);
            }

            using (var stream = new MemoryStream(fontData))
            {
                _media.font_20 = fontAtlas.AddFont(stream, 20);
            }

            using (var stream = new MemoryStream(fontData))
            {
                _media.font_22 = fontAtlas.AddFont(stream, 22);
            }

            _contextWrapper.ConvertConfig._null_ = fontAtlas.Bake();

            _media.uncheckd = LoadImage("Icons/unchecked.png");
            _media.checkd   = LoadImage("Icons/checked.png");
            _media.rocket   = LoadImage("Icons/rocket.png");
            _media.cloud    = LoadImage("Icons/cloud.png");
            _media.pen      = LoadImage("Icons/pen.png");
            _media.play     = LoadImage("Icons/play.png");
            _media.pause    = LoadImage("Icons/pause.png");
            _media.stop     = LoadImage("Icons/stop.png");
            _media.next     = LoadImage("Icons/next.png");
            _media.prev     = LoadImage("Icons/prev.png");
            _media.tools    = LoadImage("Icons/tools.png");
            _media.dir      = LoadImage("Icons/directory.png");
            _media.copy     = LoadImage("Icons/copy.png");
            _media.convert  = LoadImage("Icons/export.png");
            _media.del      = LoadImage("Icons/delete.png");
            _media.edit     = LoadImage("Icons/edit.png");
            _media.menu[0]  = LoadImage("Icons/home.png");
            _media.menu[1]  = LoadImage("Icons/phone.png");
            _media.menu[2]  = LoadImage("Icons/plane.png");
            _media.menu[3]  = LoadImage("Icons/wifi.png");
            _media.menu[4]  = LoadImage("Icons/settings.png");
            _media.menu[5]  = LoadImage("Icons/volume.png");

            for (var i = 0; i < _media.images.Length; ++i)
            {
                _media.images [i] = LoadImage("Images/image" + (i + 1) + ".png");
            }

            base.Initialize();
        }
Esempio n. 23
0
        public static bool NonBlockBegin(this NuklearContext ctx, uint flags, RectangleF body, RectangleF header,
                                         int panel_type)
        {
            nk_window popup;
            nk_window win;
            nk_panel  panel;
            var       is_active = true;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win   = ctx.current;
            panel = win.Layout;
            popup = win.Popup.Window;
            if (popup == null)
            {
                popup            = ctx.nk_create_window();
                popup.Parent     = win;
                win.Popup.Window = popup;
                win.Popup.Type   = panel_type;
                popup.Buffer.Init(true);
            }
            else
            {
                bool pressed;
                bool in_body;
                bool in_header;
                pressed   = nk_input_is_mouse_pressed(ctx.input, NK_BUTTON_LEFT);
                in_body   = nk_input_is_mouse_hovering_rect(ctx.input, body);
                in_header = nk_input_is_mouse_hovering_rect(ctx.input, header);
                if (pressed && (!in_body || in_header))
                {
                    is_active = false;
                }
            }

            win.Popup.Header = header;
            if (!is_active)
            {
                var root = win.Layout;
                while (root != null)
                {
                    root.Flags |= NK_WINDOW_REMOVE_ROM;
                    root        = root.Parent;
                }

                return(is_active);
            }

            popup.Bounds     = body;
            popup.Seq        = ctx.seq;
            popup.Parent     = win;
            popup.Layout     = new nk_panel();
            popup.Flags      = flags;
            popup.Flags     |= NK_WINDOW_BORDER;
            popup.Flags     |= NK_WINDOW_DYNAMIC;
            win.Popup.Active = 1;
            StartPopup(ctx, win);
            popup.Buffer = win.Buffer;
            popup.Buffer.Scissor(RectangleF.Null);
            ctx.current = popup;
            ctx.nk_panel_begin(null, panel_type);
            win.Buffer          = popup.Buffer;
            popup.Layout.Parent = win.Layout;
            popup.Layout.Offset = popup;

            {
                nk_panel root;
                root = win.Layout;
                while (root != null)
                {
                    root.Flags |= NK_WINDOW_ROM;
                    root        = root.Parent;
                }
            }

            return(is_active);
        }
Esempio n. 24
0
 public static bool CheckboxFlagsLabel(this NuklearContext ctx, string label, uint *flags, uint value)
 {
     return(CheckboxFlagsText(ctx, label, flags, value));
 }
Esempio n. 25
0
 public static void ui_header(this NuklearContext ctx, Media media, string title)
 {
     ctx.StyleSetFontSize(18);
     ctx.LayoutRowDynamic(20, 1);
     ctx.Label(title, nk_text_align.NK_TEXT_LEFT);
 }
Esempio n. 26
0
        public static bool PopupBegin(this NuklearContext ctx, int type, string title, uint flags, RectangleF rect)
        {
            nk_window popup;
            nk_window win;
            nk_panel  panel;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win   = ctx.current;
            panel = win.Layout;
            var title_hash = nk_murmur_hash(title, NK_PANEL_POPUP);

            popup = win.Popup.Window;
            if (popup == null)
            {
                popup            = ctx.nk_create_window();
                popup.Parent     = win;
                win.Popup.Window = popup;
                win.Popup.Active = 0;
                win.Popup.Type   = NK_PANEL_POPUP;
            }

            if (win.Popup.Name != title_hash)
            {
                if (win.Popup.Active == 0)
                {
                    win.Popup.Name   = title_hash;
                    win.Popup.Active = 1;
                    win.Popup.Type   = NK_PANEL_POPUP;
                }
                else
                {
                    return(false);
                }
            }

            ctx.current  = popup;
            rect.X      += win.Layout.Clip.X;
            rect.Y      += win.Layout.Clip.Y;
            popup.Parent = win;
            popup.Bounds = rect;
            popup.Seq    = ctx.seq;
            popup.Layout = new nk_panel();
            popup.Flags  = flags;
            popup.Flags |= NK_WINDOW_BORDER;
            if (type == NK_POPUP_DYNAMIC)
            {
                popup.Flags |= NK_WINDOW_DYNAMIC;
            }
            StartPopup(ctx, win);
            popup.Buffer = win.Buffer;
            popup.Buffer.Scissor(RectangleF.Null);
            if (ctx.nk_panel_begin(title, NK_PANEL_POPUP))
            {
                nk_panel root;
                root = win.Layout;
                while (root != null)
                {
                    root.Flags |= NK_WINDOW_ROM;
                    root.Flags &= ~(uint)NK_WINDOW_REMOVE_ROM;
                    root        = root.Parent;
                }

                win.Popup.Active    = 1;
                popup.Layout.Offset = popup;
                popup.Layout.Parent = win.Layout;
                return(true);
            }
            else
            {
                nk_panel root;
                root = win.Layout;
                while (root != null)
                {
                    root.Flags |= NK_WINDOW_REMOVE_ROM;
                    root        = root.Parent;
                }

                win.Popup.Active = 0;
                ctx.current      = win;
                popup.Layout     = null;
                return(false);
            }
        }
Esempio n. 27
0
 public static void ui_widget_centered(this NuklearContext ctx, Media media, float height)
 {
     ctx.StyleSetFontSize(22);
     ctx.LayoutRow(Nuklear.NK_DYNAMIC, height, 3, ratio2);
     ctx.Spacing(1);
 }
Esempio n. 28
0
        public static void button_demo(this NuklearContext ctx, Media media)
        {
            ctx.StyleSetFont(media.font);
            ctx.StyleSetFontSize(20);
            ctx.Begin("Button Demo", new RectangleF(50, 50, 255, 610),
                      Nuklear.NK_WINDOW_BORDER | Nuklear.NK_WINDOW_MOVABLE | Nuklear.NK_WINDOW_TITLE);

            /*------------------------------------------------
             *                  MENU
             *------------------------------------------------*/
            ctx.MenubarBegin();
            {
                /* toolbar */
                ctx.LayoutRowStatic(40, 40, 4);
                if (ctx.MenuBeginImage("Music", media.play, new Vector2(110, 120)))
                {
                    /* settings */
                    ctx.LayoutRowDynamic(25, 1);
                    ctx.MenuItemImageLabel(media.play, "Play", nk_text_align.NK_TEXT_RIGHT);
                    ctx.MenuItemImageLabel(media.stop, "Stop", nk_text_align.NK_TEXT_RIGHT);
                    ctx.MenuItemImageLabel(media.pause, "Pause", nk_text_align.NK_TEXT_RIGHT);
                    ctx.MenuItemImageLabel(media.next, "Next", nk_text_align.NK_TEXT_RIGHT);
                    ctx.MenuItemImageLabel(media.prev, "Prev", nk_text_align.NK_TEXT_RIGHT);
                    ctx.MenuEnd();
                }

                ctx.ButtonImage(media.tools);
                ctx.ButtonImage(media.cloud);
                ctx.ButtonImage(media.pen);
            }
            ctx.MenubarEnd();

            /*------------------------------------------------
             *                  BUTTON
             *------------------------------------------------*/
            ui_header(ctx, media, "Push buttons");
            ui_widget(ctx, media, 35);
            if (ctx.ButtonLabel("Push me"))
            {
                Console.Write("pushed!\n");
            }
            ui_widget(ctx, media, 35);
            if (ctx.ButtonImageLabel(media.rocket, "Styled", nk_text_align.NK_TEXT_CENTERED))
            {
                Console.Write("rocket!\n");
            }

            /*------------------------------------------------
             *                  REPEATER
             *------------------------------------------------*/
            ui_header(ctx, media, "Repeater");
            ui_widget(ctx, media, 35);
            if (ctx.ButtonLabel("Press me"))
            {
                Console.Write("pressed!\n");
            }

            /*------------------------------------------------
             *                  TOGGLE
             *------------------------------------------------*/
            ui_header(ctx, media, "Toggle buttons");
            ui_widget(ctx, media, 35);
            if (ctx.ButtonImageLabel(toggle0 ? media.checkd : media.uncheckd, "Toggle", nk_text_align.NK_TEXT_LEFT))
            {
                toggle0 = !toggle0;
            }

            ui_widget(ctx, media, 35);
            if (ctx.ButtonImageLabel(toggle1 ? media.checkd : media.uncheckd, "Toggle", nk_text_align.NK_TEXT_LEFT))
            {
                toggle1 = !toggle1;
            }

            ui_widget(ctx, media, 35);
            if (ctx.ButtonImageLabel(toggle2 ? media.checkd : media.uncheckd, "Toggle", nk_text_align.NK_TEXT_LEFT))
            {
                toggle2 = !toggle2;
            }

            /*------------------------------------------------
             *                  RADIO
             *------------------------------------------------*/
            ui_header(ctx, media, "Radio buttons");
            ui_widget(ctx, media, 35);
            if (ctx.ButtonSymbolLabel(
                    option == 0 ? nk_symbol_type.NK_SYMBOL_CIRCLE_OUTLINE : nk_symbol_type.NK_SYMBOL_CIRCLE_SOLID, "Select",
                    nk_text_align.NK_TEXT_LEFT))
            {
                option = 0;
            }
            ui_widget(ctx, media, 35);
            if (ctx.ButtonSymbolLabel(
                    option == 1 ? nk_symbol_type.NK_SYMBOL_CIRCLE_OUTLINE : nk_symbol_type.NK_SYMBOL_CIRCLE_SOLID, "Select",
                    nk_text_align.NK_TEXT_LEFT))
            {
                option = 1;
            }
            ui_widget(ctx, media, 35);
            if (ctx.ButtonSymbolLabel(
                    option == 2 ? nk_symbol_type.NK_SYMBOL_CIRCLE_OUTLINE : nk_symbol_type.NK_SYMBOL_CIRCLE_SOLID, "Select",
                    nk_text_align.NK_TEXT_LEFT))
            {
                option = 2;
            }

            /*------------------------------------------------
             *                  CONTEXTUAL
             *------------------------------------------------*/
            ctx.StyleSetFontSize(18);
            if (ctx.ContextualBegin(Nuklear.NK_WINDOW_NO_SCROLLBAR, new Vector2(150, 300), ctx.WindowGetBounds()))
            {
                ctx.LayoutRowDynamic(30, 1);
                if (ctx.ContextualItemImageLabel(media.copy, "Clone", nk_text_align.NK_TEXT_RIGHT))
                {
                    Console.Write("pressed clone!\n");
                }
                if (ctx.ContextualItemImageLabel(media.del, "Delete", nk_text_align.NK_TEXT_RIGHT))
                {
                    Console.Write("pressed delete!\n");
                }
                if (ctx.ContextualItemImageLabel(media.convert, "Convert", nk_text_align.NK_TEXT_RIGHT))
                {
                    Console.Write("pressed convert!\n");
                }
                if (ctx.ContextualItemImageLabel(media.edit, "Edit", nk_text_align.NK_TEXT_RIGHT))
                {
                    Console.Write("pressed edit!\n");
                }
                ctx.ContextualEnd();
            }

            ctx.StyleSetFontSize(14);
            ctx.End();
        }
Esempio n. 29
0
 public static bool RadioLabel(this NuklearContext ctx, string label, bool *active)
 {
     return(RadioText(ctx, label, active));
 }
Esempio n. 30
0
        /// <summary>
        ///     User interfaces the piemenu.
        /// </summary>
        /// <returns>The piemenu.</returns>
        /// <param name="ctx">Context.</param>
        /// <param name="pos">Position.</param>
        /// <param name="radius">Radius.</param>
        /// <param name="icons">Icons.</param>
        /// <param name="item_count">Item count.</param>
        public static int ui_piemenu(this NuklearContext ctx, Vector2 pos, float radius,
                                     nk_image[] icons, int item_count)
        {
            var ret = -1;

            /* pie menu popup */
            var border     = ctx.style.window.border_color;
            var background = ctx.style.window.fixed_background;

            ctx.style.window.fixed_background = Nuklear.nk_style_item_hide();
            ctx.style.window.border_color     = Color.Transparent;

            var total_space = ctx.WindowGetContentRegion();

            ctx.style.window.spacing = new Vector2(0, 0);
            ctx.style.window.padding = new Vector2(0, 0);

            if (ctx.PopupBegin(Nuklear.NK_POPUP_STATIC, "piemenu", Nuklear.NK_WINDOW_NO_SCROLLBAR,
                               new RectangleF(pos.X - total_space.X - radius, pos.Y - radius - total_space.Y,
                                              2 * radius, 2 * radius)))
            {
                var o   = ctx.WindowGetCanvas();
                var inp = ctx.input;

                total_space = ctx.WindowGetContentRegion();
                ctx.style.window.spacing = new Vector2(4, 4);
                ctx.style.window.padding = new Vector2(8, 8);
                ctx.LayoutRowDynamic(total_space.Height, 1);
                var bounds = new RectangleF();
                ctx.Widget(ref bounds);

                /* outer circle */
                o.nk_fill_circle(bounds, new Color(50, 50, 50));
                int active_item;
                {
                    /* circle buttons */
                    var   step  = 2 * 3.141592654f / Math.Max(1, item_count);
                    float a_min = 0;
                    var   a_max = step;

                    var center = new Vector2(bounds.X + bounds.Width / 2.0f, bounds.Y + bounds.Height / 2.0f);
                    var drag   = new Vector2(inp.mouse.pos.X - center.X, inp.mouse.pos.Y - center.Y);
                    var angle  = (float)Math.Atan2(drag.Y, drag.X);
                    if (angle < -0.0f)
                    {
                        angle += 2.0f * 3.141592654f;
                    }
                    active_item = (int)(angle / step);

                    int i;
                    for (i = 0; i < item_count; ++i)
                    {
                        RectangleF content;
                        o.FillArc(center.X, center.Y, bounds.Width / 2.0f,
                                  a_min, a_max, active_item == i ? new Color(45, 100, 255) : new Color(60, 60, 60));

                        /* separator line */
                        var   rx = bounds.Width / 2.0f;
                        float ry = 0;
                        var   dx = rx * (float)Math.Cos(a_min) - ry * (float)Math.Sin(a_min);
                        var   dy = rx * (float)Math.Sin(a_min) + ry * (float)Math.Cos(a_min);
                        o.StrokeLine(center.X, center.Y,
                                     center.X + dx, center.Y + dy, 1.0f, new Color(50, 50, 50));

                        /* button content */
                        var a = a_min + (a_max - a_min) / 2.0f;
                        rx             = bounds.Width / 2.5f;
                        ry             = 0;
                        content.Width  = 30;
                        content.Height = 30;
                        content.X      = center.X + (rx * (float)Math.Cos(a) - ry * (float)Math.Sin(a) -
                                                     content.Width / 2.0f);
                        content.Y = center.Y + (rx * (float)Math.Sin(a) + ry * (float)Math.Cos(a) -
                                                content.Height / 2.0f);
                        o.DrawImage(content, icons[i], Color.White);
                        a_min  = a_max;
                        a_max += step;
                    }
                }
                {
                    /* inner circle */
                    RectangleF inner;
                    inner.X      = bounds.X + bounds.Width / 2 - bounds.Width / 4;
                    inner.Y      = bounds.Y + bounds.Height / 2 - bounds.Height / 4;
                    inner.Width  = bounds.Width / 2;
                    inner.Height = bounds.Height / 2;
                    o.nk_fill_circle(inner, new Color(45, 45, 45));

                    /* active icon content */
                    bounds.Width  = inner.Width / 2.0f;
                    bounds.Height = inner.Height / 2.0f;
                    bounds.X      = inner.X + inner.Width / 2 - bounds.Width / 2;
                    bounds.Y      = inner.Y + inner.Height / 2 - bounds.Height / 2;
                    o.DrawImage(bounds, icons[active_item], Color.White);
                }
                ctx.LayoutSpaceEnd();
                if (!Nuklear.nk_input_is_mouse_down(ctx.input, Nuklear.NK_BUTTON_RIGHT))
                {
                    ctx.PopupClose();
                    ret = active_item;
                }
            }
            else
            {
                ret = -2;
            }

            ctx.style.window.spacing = new Vector2(4, 4);
            ctx.style.window.padding = new Vector2(8, 8);
            ctx.PopupEnd();

            ctx.style.window.fixed_background = background;
            ctx.style.window.border_color     = border;
            return(ret);
        }