예제 #1
0
        public static bool ButtonImageTextStyled(this NuklearContext ctx, nk_style_button style, nk_image img,
                                                 string text,
                                                 nk_text_align align)
        {
            nk_window win;
            nk_panel  layout;
            nk_input  _in_;
            var       bounds = new RectangleF();
            int       state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win    = ctx.current;
            layout = win.Layout;
            state  = ctx.Widget(ref bounds);
            if (state == 0)
            {
                return(false);
            }
            _in_ = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            return(DoButtonTextImage(ref ctx.last_widget_state, win.Buffer, bounds, img, text,
                                     align, ctx.button_behavior, style, ctx.style.font, _in_));
        }
예제 #2
0
        public static bool Progress(this NuklearContext ctx, ref ulong cur, ulong max, int is_modifyable)
        {
            nk_window win;
            nk_panel  layout;
            nk_style  style;
            nk_input  _in_;
            var       bounds = new RectangleF();
            int       state;
            ulong     old_value;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null || cur == null)
            {
                return(false);
            }
            win    = ctx.current;
            style  = ctx.style;
            layout = win.Layout;
            state  = ctx.Widget(ref bounds);
            if (state == 0)
            {
                return(false);
            }
            _in_      = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            old_value = cur;
            cur       =
                DoProgress(ref ctx.last_widget_state, win.Buffer, bounds, cur,
                           max,
                           is_modifyable, style.progress, _in_);
            return(cur != old_value);
        }
예제 #3
0
        public static bool ButtonColor(this NuklearContext ctx, Color color)
        {
            nk_window win;
            nk_panel  layout;
            nk_input  _in_;
            var       button  = new nk_style_button();
            var       ret     = false;
            var       bounds  = new RectangleF();
            var       content = new RectangleF();
            int       state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win    = ctx.current;
            layout = win.Layout;
            state  = ctx.Widget(ref bounds);
            if (state == 0)
            {
                return(false);
            }
            _in_          = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            button        = ctx.style.button;
            button.normal = new nk_style_item(color);
            button.hover  = new nk_style_item(color);
            button.active = new nk_style_item(color);
            ret           =
                DoButton(ref ctx.last_widget_state, win.Buffer, bounds, button, _in_, ctx.button_behavior,
                         &content);
            win.Buffer.DrawButton(&bounds, ctx.last_widget_state, button);
            return(ret);
        }
예제 #4
0
        public static bool nk_selectable_image_text(this NuklearContext ctx, nk_image img, string str,
                                                    nk_text_align align, ref bool value)
        {
            nk_window win;
            nk_panel  layout;
            nk_input  _in_;
            nk_style  style;
            int       state;
            var       bounds = new RectangleF();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win    = ctx.current;
            layout = win.Layout;
            style  = ctx.style;
            state  = ctx.Widget(ref bounds);
            if (state == 0)
            {
                return(false);
            }
            _in_ = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            return
                (nk_do_selectable_image(ref ctx.last_widget_state, win.Buffer, bounds, str, align,
                                        ref value, img, style.selectable, _in_, style.font));
        }
예제 #5
0
        public static int ColorPick(this NuklearContext ctx, Colorf *color, int fmt)
        {
            nk_window win;
            nk_panel  layout;
            nk_style  config;
            nk_input  _in_;
            int       state;
            var       bounds = new RectangleF();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null || color == null)
            {
                return(0);
            }
            win    = ctx.current;
            config = ctx.style;
            layout = win.Layout;
            state  = ctx.Widget(ref bounds);
            if (state == 0)
            {
                return(0);
            }
            _in_ = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            return
                (nk_do_color_picker(ref ctx.last_widget_state, win.Buffer, color, fmt, bounds,
                                    new Vector2(0, 0), _in_, config.font));
        }
예제 #6
0
        public static bool MenuBeginImage(this NuklearContext ctx, string id, nk_image img, Vector2 size)
        {
            nk_window win;
            var       header = new RectangleF();
            nk_input  _in_;
            var       is_clicked = false;
            uint      state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win   = ctx.current;
            state = (uint)ctx.Widget(ref header);
            if (state == 0)
            {
                return(false);
            }
            _in_ = state == NK_WIDGET_ROM || (win.Layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            if (DoButtonImage(ref ctx.last_widget_state, win.Buffer, header, img,
                              NK_BUTTON_DEFAULT, ctx.style.menu_button, _in_))
            {
                is_clicked = true;
            }
            return(MenuBegin(ctx, win, id, is_clicked, header, size));
        }
예제 #7
0
        public static int nk_chart_begin_colored(this NuklearContext ctx, int type, Color color, Color highlight,
                                                 int count,
                                                 float min_value, float max_value)
        {
            nk_window      win;
            nk_chart       chart;
            nk_style       config;
            nk_style_chart style;
            nk_style_item  background;
            var            bounds = new RectangleF();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(0);
            }
            if (ctx.Widget(ref bounds) == 0)
            {
                chart = ctx.current.Layout.Chart;
                return(0);
            }

            win    = ctx.current;
            config = ctx.style;
            chart  = win.Layout.Chart;
            style  = config.chart;

            chart.X      = bounds.X + style.Padding.X;
            chart.Y      = bounds.Y + style.Padding.Y;
            chart.Width  = bounds.Width - 2 * style.Padding.X;
            chart.Height = bounds.Height - 2 * style.Padding.Y;
            chart.Width  = chart.Width < 2 * style.Padding.X ? 2 * style.Padding.X : chart.Width;
            chart.Height = chart.Height < 2 * style.Padding.Y ? 2 * style.Padding.Y : chart.Height;
            {
                var slot = chart.slots[chart.slot++];
                slot.Type      = type;
                slot.Count     = count;
                slot.Color     = color;
                slot.Highlight = highlight;
                slot.Min       = min_value < max_value ? min_value : max_value;
                slot.Max       = min_value < max_value ? max_value : min_value;
                slot.Range     = slot.Max - slot.Min;
            }

            background = style.background;
            if (background.type == NK_STYLE_ITEM_IMAGE)
            {
                win.Buffer.DrawImage(bounds, background.Image, nk_white);
            }
            else
            {
                win.Buffer.FillRect(bounds, style.Rounding, style.Border_color);
                win.Buffer.FillRect(RectangleF.nk_shrink_rect_(bounds, style.Border),
                                    style.Rounding, style.background.Color);
            }

            return(1);
        }
예제 #8
0
        public static int WidgetFitting(this NuklearContext ctx, ref RectangleF bounds, Vector2 item_padding)
        {
            nk_window win;
            nk_style  style;
            nk_panel  layout;
            int       state;
            var       panel_padding = new Vector2();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(NK_WIDGET_INVALID);
            }
            win           = ctx.current;
            style         = ctx.style;
            layout        = win.Layout;
            state         = ctx.Widget(ref bounds);
            panel_padding = nk_panel_get_padding(style, layout.Type);
            if (layout.Row.index == 1)
            {
                bounds.Width += panel_padding.X;
                bounds.X     -= panel_padding.X;
            }
            else
            {
                bounds.X -= item_padding.X;
            }

            if (layout.Row.index == layout.Row.columns)
            {
                bounds.Width += panel_padding.X;
            }
            else
            {
                bounds.Width += item_padding.X;
            }
            return(state);
        }
예제 #9
0
        public static bool ButtonSymbolStyled(this NuklearContext ctx, nk_style_button style, nk_symbol_type symbol)
        {
            nk_window win;
            nk_panel  layout;
            nk_input  _in_;
            var       bounds = new RectangleF();
            int       state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win    = ctx.current;
            layout = win.Layout;
            state  = ctx.Widget(ref bounds);
            if (state == 0)
            {
                return(false);
            }
            _in_ = state == NK_WIDGET_ROM || (layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            return
                (DoButtonSymbol(ref ctx.last_widget_state, win.Buffer, bounds, symbol,
                                ctx.button_behavior, style, _in_, ctx.style.font));
        }
예제 #10
0
        public static int nk_tree_state_base(this NuklearContext ctx, int type, nk_image img, string title,
                                             ref int state)
        {
            nk_window       win;
            nk_panel        layout;
            nk_style        style;
            CommandBuffer   _out_;
            nk_input        _in_;
            nk_style_button button;
            nk_symbol_type  symbol;
            float           row_height;
            var             item_spacing = new Vector2();
            var             header       = new RectangleF();
            var             sym          = new RectangleF();
            var             text         = new nk_text();
            uint            ws           = 0;
            int             widget_state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(0);
            }
            win          = ctx.current;
            layout       = win.Layout;
            _out_        = win.Buffer;
            style        = ctx.style;
            item_spacing = style.window.spacing;
            row_height   = style.font.Size + 2 * style.tab.padding.Y;
            ctx.LayoutSetMinRowHeight(row_height);
            ctx.LayoutRowDynamic(row_height, 1);
            ctx.LayoutResetMinRowHeight();
            widget_state = ctx.Widget(ref header);
            if (type == NK_TREE_TAB)
            {
                var background = style.tab.background;
                if (background.type == NK_STYLE_ITEM_IMAGE)
                {
                    _out_.DrawImage(header, background.Image, nk_white);
                    text.Background = Color.Transparent;
                }
                else
                {
                    text.Background = background.Color;
                    _out_.FillRect(header, 0, style.tab.border_color);
                    _out_.FillRect(RectangleF.nk_shrink_rect_(header, style.tab.border),
                                   style.tab.Rounding, background.Color);
                }
            }
            else
            {
                text.Background = style.window.background;
            }

            _in_ = (layout.Flags & NK_WINDOW_ROM) == 0 ? ctx.input : null;
            _in_ = _in_ != null && widget_state == NK_WIDGET_VALID ? ctx.input : null;
            if (ButtonBehavior(ref ws, header, _in_, NK_BUTTON_DEFAULT))
            {
                state = state == NK_MAXIMIZED ? NK_MINIMIZED : NK_MAXIMIZED;
            }
            if (state == NK_MAXIMIZED)
            {
                symbol = style.tab.sym_maximize;
                if (type == NK_TREE_TAB)
                {
                    button = style.tab.tab_maximize_button;
                }
                else
                {
                    button = style.tab.node_maximize_button;
                }
            }
            else
            {
                symbol = style.tab.sym_minimize;
                if (type == NK_TREE_TAB)
                {
                    button = style.tab.tab_minimize_button;
                }
                else
                {
                    button = style.tab.node_minimize_button;
                }
            }

            {
                sym.Width = sym.Height = style.font.Size;
                sym.Y     = header.Y + style.tab.padding.Y;
                sym.X     = header.X + style.tab.padding.X;
                DoButtonSymbol(ref ws, win.Buffer, sym, symbol, NK_BUTTON_DEFAULT, button, null,
                               style.font);
                if (img != null)
                {
                    sym.X = sym.X + sym.Width + 4 * item_spacing.X;
                    win.Buffer.DrawImage(sym, img, nk_white);
                    sym.Width = style.font.Size + style.tab.spacing.X;
                }
            }

            {
                var label = new RectangleF();
                header.Width = header.Width < sym.Width + item_spacing.X ? sym.Width + item_spacing.X : header.Width;
                label.X      = sym.X + sym.Width + item_spacing.X;
                label.Y      = sym.Y;
                label.Width  = header.Width - (sym.Width + item_spacing.Y + style.tab.indent);
                label.Height = style.font.Size;
                text.text    = style.tab.text;
                text.padding = new Vector2(0, 0);
                _out_.WidgetText(label, title, &text, nk_text_align.NK_TEXT_LEFT, style.font);
            }

            if (state == NK_MAXIMIZED)
            {
                layout.At_x          = header.X + layout.Offset.X + style.tab.indent;
                layout.Bounds.Width  = layout.Bounds.Width < style.tab.indent ? style.tab.indent : layout.Bounds.Width;
                layout.Bounds.Width -= style.tab.indent + style.window.padding.X;
                layout.Row.tree_depth++;
                return(nk_true);
            }

            return(nk_false);
        }
예제 #11
0
        public static bool ComboBeginImageText(this NuklearContext ctx, string selected, nk_image img, Vector2 size)
        {
            nk_window     win;
            nk_style      style;
            nk_input      _in_;
            var           header     = new RectangleF();
            var           is_clicked = false;
            int           s;
            nk_style_item background;
            var           text = new nk_text();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win   = ctx.current;
            style = ctx.style;
            s     = ctx.Widget(ref header);
            if (s == 0)
            {
                return(false);
            }
            _in_ = (win.Layout.Flags & NK_WINDOW_ROM) != 0 || s == NK_WIDGET_ROM ? null : ctx.input;
            if (ButtonBehavior(ref ctx.last_widget_state, header, _in_, NK_BUTTON_DEFAULT))
            {
                is_clicked = true;
            }
            if ((ctx.last_widget_state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                background = style.combo.active;
                text.text  = style.combo.label_active;
            }
            else if ((ctx.last_widget_state & NK_WIDGET_STATE_HOVER) != 0)
            {
                background = style.combo.hover;
                text.text  = style.combo.label_hover;
            }
            else
            {
                background = style.combo.normal;
                text.text  = style.combo.label_normal;
            }

            if (background.type == NK_STYLE_ITEM_IMAGE)
            {
                text.Background = Color.Transparent;
                win.Buffer.DrawImage(header, background.Image, nk_white);
            }
            else
            {
                text.Background = background.Color;
                win.Buffer.FillRect(header, style.combo.Rounding, background.Color);
                win.Buffer.StrokeRect(header, style.combo.Rounding, style.combo.border,
                                      style.combo.border_color);
            }

            {
                var            content = new RectangleF();
                var            button  = new RectangleF();
                var            label   = new RectangleF();
                var            image   = new RectangleF();
                nk_symbol_type sym;
                if ((ctx.last_widget_state & NK_WIDGET_STATE_HOVER) != 0)
                {
                    sym = style.combo.sym_hover;
                }
                else if (is_clicked)
                {
                    sym = style.combo.sym_active;
                }
                else
                {
                    sym = style.combo.sym_normal;
                }
                button.Width   = header.Height - 2 * style.combo.button_padding.Y;
                button.X       = header.X + header.Width - header.Height - style.combo.button_padding.X;
                button.Y       = header.Y + style.combo.button_padding.Y;
                button.Height  = button.Width;
                content.X      = button.X + style.combo.button.padding.X;
                content.Y      = button.Y + style.combo.button.padding.Y;
                content.Width  = button.Width - 2 * style.combo.button.padding.X;
                content.Height = button.Height - 2 * style.combo.button.padding.Y;
                win.Buffer.DrawButtonSymbol(&button, &content, ctx.last_widget_state, ctx.style.combo.button,
                                            sym, style.font);
                image.X      = header.X + style.combo.content_padding.X;
                image.Y      = header.Y + style.combo.content_padding.Y;
                image.Height = header.Height - 2 * style.combo.content_padding.Y;
                image.Width  = image.Height;
                win.Buffer.DrawImage(image, img, nk_white);
                text.padding = new Vector2(0, 0);
                label.X      = image.X + image.Width + style.combo.spacing.X + style.combo.content_padding.X;
                label.Y      = header.Y + style.combo.content_padding.Y;
                label.Width  = button.X - style.combo.content_padding.X - label.X;
                label.Height = header.Height - 2 * style.combo.content_padding.Y;
                win.Buffer.WidgetText(label, selected, &text, nk_text_align.NK_TEXT_LEFT, style.font);
            }

            return(ComboBegin(ctx, win, size, is_clicked, header));
        }
예제 #12
0
        public static bool ComboBeginImage(this NuklearContext ctx, nk_image img, Vector2 size)
        {
            nk_window     win;
            nk_style      style;
            nk_input      _in_;
            var           header     = new RectangleF();
            var           is_clicked = false;
            int           s;
            nk_style_item background;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win   = ctx.current;
            style = ctx.style;
            s     = ctx.Widget(ref header);
            if (s == NK_WIDGET_INVALID)
            {
                return(false);
            }
            _in_ = (win.Layout.Flags & NK_WINDOW_ROM) != 0 || s == NK_WIDGET_ROM ? null : ctx.input;
            if (ButtonBehavior(ref ctx.last_widget_state, header, _in_, NK_BUTTON_DEFAULT))
            {
                is_clicked = true;
            }
            if ((ctx.last_widget_state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                background = style.combo.active;
            }
            else if ((ctx.last_widget_state & NK_WIDGET_STATE_HOVER) != 0)
            {
                background = style.combo.hover;
            }
            else
            {
                background = style.combo.normal;
            }
            if (background.type == NK_STYLE_ITEM_IMAGE)
            {
                win.Buffer.DrawImage(header, background.Image, nk_white);
            }
            else
            {
                win.Buffer.FillRect(header, style.combo.Rounding, background.Color);
                win.Buffer.StrokeRect(header, style.combo.Rounding, style.combo.border,
                                      style.combo.border_color);
            }

            {
                var            bounds  = new RectangleF();
                var            content = new RectangleF();
                var            button  = new RectangleF();
                nk_symbol_type sym;
                if ((ctx.last_widget_state & NK_WIDGET_STATE_HOVER) != 0)
                {
                    sym = style.combo.sym_hover;
                }
                else if (is_clicked)
                {
                    sym = style.combo.sym_active;
                }
                else
                {
                    sym = style.combo.sym_normal;
                }
                button.Width   = header.Height - 2 * style.combo.button_padding.Y;
                button.X       = header.X + header.Width - header.Height - style.combo.button_padding.Y;
                button.Y       = header.Y + style.combo.button_padding.Y;
                button.Height  = button.Width;
                content.X      = button.X + style.combo.button.padding.X;
                content.Y      = button.Y + style.combo.button.padding.Y;
                content.Width  = button.Width - 2 * style.combo.button.padding.X;
                content.Height = button.Height - 2 * style.combo.button.padding.Y;
                bounds.Height  = header.Height - 2 * style.combo.content_padding.Y;
                bounds.Y       = header.Y + style.combo.content_padding.Y;
                bounds.X       = header.X + style.combo.content_padding.X;
                bounds.Width   = button.X - style.combo.content_padding.Y - bounds.X;
                win.Buffer.DrawImage(bounds, img, nk_white);
                win.Buffer.DrawButtonSymbol(&bounds, &content, ctx.last_widget_state, ctx.style.combo.button,
                                            sym, style.font);
            }

            return(ComboBegin(ctx, win, size, is_clicked, header));
        }
예제 #13
0
        public static void Property(this NuklearContext ctx, string name, nk_property_variant *variant,
                                    float inc_per_pixel,
                                    int filter)
        {
            var    bounds = new RectangleF();
            uint   hash;
            string dummy_buffer       = null;
            var    dummy_state        = NK_PROPERTY_DEFAULT;
            var    dummy_cursor       = 0;
            var    dummy_select_begin = 0;
            var    dummy_select_end   = 0;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            var win    = ctx.current;
            var layout = win.Layout;
            var style  = ctx.style;
            var s      = ctx.Widget(ref bounds);

            if (s == 0)
            {
                return;
            }
            if (name[0] == '#')
            {
                hash = nk_murmur_hash(name, win.Property.seq++);
                name = name + 1;
            }
            else
            {
                hash = nk_murmur_hash(name, 42);
            }

            var _in_ = s == NK_WIDGET_ROM && win.Property.active == 0 || (layout.Flags & NK_WINDOW_ROM) != 0
                                ? null
                                : ctx.input;

            int    old_state, state;
            string buffer;
            int    cursor, select_begin, select_end;

            if (win.Property.active != 0 && hash == win.Property.name)
            {
                old_state = win.Property.state;
                DoProperty(ref ctx.last_widget_state, win.Buffer, bounds, name, variant, inc_per_pixel,
                           ref win.Property.buffer, ref win.Property.state, ref win.Property.cursor,
                           ref win.Property.select_start, ref win.Property.select_end, style.property, filter, _in_,
                           style.font,
                           ctx.text_edit, ctx.button_behavior);
                state        = win.Property.state;
                buffer       = win.Property.buffer;
                cursor       = win.Property.cursor;
                select_begin = win.Property.select_start;
                select_end   = win.Property.select_end;
            }
            else
            {
                old_state = dummy_state;
                DoProperty(ref ctx.last_widget_state, win.Buffer, bounds, name, variant, inc_per_pixel,
                           ref dummy_buffer, ref dummy_state, ref dummy_cursor,
                           ref dummy_select_begin, ref dummy_select_end, style.property, filter, _in_, style.font,
                           ctx.text_edit, ctx.button_behavior);
                state        = dummy_state;
                buffer       = dummy_buffer;
                cursor       = dummy_cursor;
                select_begin = dummy_select_begin;
                select_end   = dummy_select_end;
            }

            ctx.text_edit.Clip = ctx.clip;
            if (_in_ != null && state != NK_PROPERTY_DEFAULT && win.Property.active == 0)
            {
                win.Property.active       = 1;
                win.Property.buffer       = buffer;
                win.Property.cursor       = cursor;
                win.Property.state        = state;
                win.Property.name         = hash;
                win.Property.select_start = select_begin;
                win.Property.select_end   = select_end;
                if (state == NK_PROPERTY_DRAG)
                {
                    ctx.input.mouse.grab    = nk_true;
                    ctx.input.mouse.grabbed = nk_true;
                }
            }

            if (state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT)
            {
                if (old_state == NK_PROPERTY_DRAG)
                {
                    ctx.input.mouse.grab    = nk_false;
                    ctx.input.mouse.grabbed = nk_false;
                    ctx.input.mouse.ungrab  = nk_true;
                }

                win.Property.select_start = 0;
                win.Property.select_end   = 0;
                win.Property.active       = 0;
            }
        }