Beispiel #1
0
        public static bool WidgetIsMouseClicked(this NuklearContext ctx, int btn)
        {
            var c      = new RectangleF();
            var v      = new RectangleF();
            var bounds = new RectangleF();

            if (ctx == null || ctx.current == null || ctx.active != ctx.current)
            {
                return(false);
            }
            c        = ctx.current.Layout.Clip;
            c.X      = (int)c.X;
            c.Y      = (int)c.Y;
            c.Width  = (int)c.Width;
            c.Height = (int)c.Height;
            ctx.LayoutPeek(ref bounds);
            RectangleF.nk_unify(ref v, ref c, bounds.X, bounds.Y, bounds.X + bounds.Width,
                                bounds.Y + bounds.Height);
            if (
                !!(bounds.X > c.X + c.Width || bounds.X + bounds.Width < c.X || bounds.Y > c.Y + c.Height ||
                   bounds.Y + bounds.Height < c.Y))
            {
                return(false);
            }
            return(nk_input_mouse_clicked(ctx.input, btn, bounds));
        }
Beispiel #2
0
 public static bool nk_select_image_label(this NuklearContext ctx, nk_image img, string str,
                                          nk_text_align align,
                                          bool value)
 {
     nk_selectable_image_text(ctx, img, str, align, ref value);
     return(value);
 }
Beispiel #3
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));
        }
Beispiel #4
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));
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public static void nk_plot(this NuklearContext ctx, int type, float *values, int count, int offset)
        {
            var   i = 0;
            float min_value;
            float max_value;

            if (ctx == null || values == null || count == 0)
            {
                return;
            }
            min_value = values[offset];
            max_value = values[offset];
            for (i = 0; i < count; ++i)
            {
                min_value = values[i + offset] < min_value ? values[i + offset] : min_value;
                max_value = values[i + offset] < max_value ? max_value : values[i + offset];
            }

            if (nk_chart_begin(ctx, type, count, min_value, max_value) != 0)
            {
                for (i = 0; i < count; ++i)
                {
                    nk_chart_push(ctx, values[i + offset]);
                }
                nk_chart_end(ctx);
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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_));
        }
Beispiel #9
0
 public static bool ButtonSymbolLabelStyled(this NuklearContext ctx, nk_style_button style,
                                            nk_symbol_type symbol, string title,
                                            nk_text_align align)
 {
     return
         (ButtonSymbolTextStyled(ctx, style, symbol, title, align));
 }
Beispiel #10
0
        public static void LayoutPeek(this NuklearContext ctx, ref RectangleF bounds)
        {
            float     y;
            int       index;
            nk_window win;
            nk_panel  layout;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            win    = ctx.current;
            layout = win.Layout;
            y      = layout.At_y;
            index  = layout.Row.index;
            if (layout.Row.index >= layout.Row.columns)
            {
                layout.At_y     += layout.Row.height;
                layout.Row.index = 0;
            }

            LayoutWidgetSpace(ref bounds, ctx, win, nk_false);
            if (layout.Row.index == 0)
            {
                bounds.X -= layout.Row.item_offset;
            }

            layout.At_y      = y;
            layout.Row.index = index;
        }
Beispiel #11
0
        public static bool MenuBegin(this NuklearContext ctx, nk_window win, string id, bool is_clicked,
                                     RectangleF header, Vector2 size)
        {
            var       is_open   = 0;
            var       is_active = 0;
            var       body      = new RectangleF();
            nk_window popup;
            var       hash = nk_murmur_hash(id, NK_PANEL_MENU);

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            body.X      = header.X;
            body.Width  = size.X;
            body.Y      = header.Y + header.Height;
            body.Height = size.Y;
            popup       = win.Popup.Window;
            is_open     = popup != null ? nk_true : nk_false;
            is_active   =
                popup != null && win.Popup.Name == hash && win.Popup.Type == NK_PANEL_MENU ? 1 : 0;
            if (is_clicked && is_open != 0 && is_active == 0 || is_open != 0 && is_active == 0 ||
                is_open == 0 && is_active == 0 && !is_clicked)
            {
                return(false);
            }
            if (!ctx.NonBlockBegin(NK_WINDOW_NO_SCROLLBAR, body, header, NK_PANEL_MENU))
            {
                return(false);
            }
            win.Popup.Type = NK_PANEL_MENU;
            win.Popup.Name = hash;
            return(true);
        }
Beispiel #12
0
        public static bool ContextualItemText(this NuklearContext ctx, StringSegment text, nk_text_align alignment)
        {
            nk_window win;
            nk_input  _in_;
            nk_style  style;
            var       bounds = new RectangleF();
            int       state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win   = ctx.current;
            style = ctx.style;
            state = ctx.WidgetFitting(ref bounds, style.contextual_button.padding);
            if (state == 0)
            {
                return(false);
            }
            _in_ = state == NK_WIDGET_ROM || (win.Layout.Flags & NK_WINDOW_ROM) != 0 ? null : ctx.input;
            if (
                DoButtonText(ref ctx.last_widget_state, win.Buffer, bounds, text, alignment,
                             NK_BUTTON_DEFAULT, style.contextual_button, _in_, style.font))
            {
                ctx.ContextualClose();
                return(true);
            }

            return(false);
        }
Beispiel #13
0
 public static void nk_combobox_callback(this NuklearContext ctx, NkComboCallback item_getter, ref int selected,
                                         int count, int item_height, Vector2 size)
 {
     selected =
         nk_combo_callback(ctx, item_getter, selected, count, item_height,
                           size);
 }
Beispiel #14
0
        public static void LayoutRowBegin(this NuklearContext ctx, int fmt, float row_height, int cols)
        {
            nk_window win;
            nk_panel  layout;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            win    = ctx.current;
            layout = win.Layout;
            PanelLayout(ctx, win, row_height, cols);
            if (fmt == NK_DYNAMIC)
            {
                layout.Row.type = NK_LAYOUT_DYNAMIC_ROW;
            }
            else
            {
                layout.Row.type = NK_LAYOUT_STATIC_ROW;
            }
            layout.Row.ratio       = null;
            layout.Row.Filled      = 0;
            layout.Row.item_width  = 0;
            layout.Row.item_offset = 0;
            layout.Row.columns     = cols;
        }
Beispiel #15
0
        public static void nk_plot_function(this NuklearContext ctx, int type, NkFloatValueGetter value_getter,
                                            int count, int offset)
        {
            var   i = 0;
            float min_value;
            float max_value;

            if (ctx == null || value_getter == null || count == 0)
            {
                return;
            }
            max_value = min_value = value_getter(offset);
            for (i = 0; i < count; ++i)
            {
                var value = value_getter(i + offset);
                min_value = value < min_value ? value : min_value;
                max_value = value < max_value ? max_value : value;
            }

            if (nk_chart_begin(ctx, type, count, min_value, max_value) != 0)
            {
                for (i = 0; i < count; ++i)
                {
                    nk_chart_push(ctx, value_getter(i + offset));
                }
                nk_chart_end(ctx);
            }
        }
Beispiel #16
0
 public static int nk_tree_push_hashed(this NuklearContext ctx, int type, string title, int initial_state,
                                       string hash,
                                       int len,
                                       int line)
 {
     return(nk_tree_base(ctx, type, null, title, initial_state, hash, len, line));
 }
Beispiel #17
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));
        }
Beispiel #18
0
 public static int nk_tree_image_push_hashed(this NuklearContext ctx, int type, nk_image img,
                                             string title,
                                             int initial_state,
                                             string hash, int len, int seed)
 {
     return(nk_tree_base(ctx, type, img, title, initial_state, hash, len, seed));
 }
Beispiel #19
0
        public static uint nk_chart_push_column(this NuklearContext ctx, nk_window win, nk_chart chart, float value,
                                                int slot)
        {
            var   _out_  = win.Buffer;
            var   _in_   = ctx.input;
            var   layout = win.Layout;
            float ratio;
            var   ret   = (uint)0;
            var   color = new Color();
            var   item  = new RectangleF();

            if (chart.slots[slot].Index >= chart.slots[slot].Count)
            {
                return(nk_false);
            }
            if (chart.slots[slot].Count != 0)
            {
                var padding = (float)(chart.slots[slot].Count - 1);
                item.Width = (chart.Width - padding) / chart.slots[slot].Count;
            }

            color       = chart.slots[slot].Color;
            item.Height =
                chart.Height *
                (value / chart.slots[slot].Range < 0
                                        ? -(value / chart.slots[slot].Range)
                                        : value / chart.slots[slot].Range);
            if (value >= 0)
            {
                ratio =
                    (value + (chart.slots[slot].Min < 0 ? -chart.slots[slot].Min : chart.slots[slot].Min)) /
                    (chart.slots[slot].Range < 0 ? -chart.slots[slot].Range : chart.slots[slot].Range);
                item.Y = chart.Y + chart.Height - chart.Height * ratio;
            }
            else
            {
                ratio  = (value - chart.slots[slot].Max) / chart.slots[slot].Range;
                item.Y = chart.Y + chart.Height * (ratio < 0 ? -ratio : ratio) - item.Height;
            }

            item.X = chart.X + chart.slots[slot].Index * item.Width;
            item.X = item.X + chart.slots[slot].Index;
            if ((layout.Flags & NK_WINDOW_ROM) == 0 && item.X <= _in_.mouse.pos.X &&
                _in_.mouse.pos.X < item.X + item.Width && item.Y <= _in_.mouse.pos.Y &&
                _in_.mouse.pos.Y < item.Y + item.Height)
            {
                ret  = NK_CHART_HOVERING;
                ret |=
                    (uint)
                    (!_in_.mouse.buttons[NK_BUTTON_LEFT].down &&
                     _in_.mouse.buttons[NK_BUTTON_LEFT].clicked != 0
                                                ? NK_CHART_CLICKED
                                                : 0);
                color = chart.slots[slot].Highlight;
            }

            _out_.FillRect(item, 0, color);
            chart.slots[slot].Index += 1;
            return(ret);
        }
Beispiel #20
0
        public static int Combo(this NuklearContext ctx, string[] items, int count, int selected, int item_height,
                                Vector2 size)
        {
            var i = 0;
            int max_height;
            var item_spacing   = new Vector2();
            var window_padding = new Vector2();

            if (ctx == null || items == null || count == 0)
            {
                return(selected);
            }
            item_spacing   = ctx.style.window.spacing;
            window_padding = nk_panel_get_padding(ctx.style, ctx.current.Layout.Type);
            max_height     = count * item_height + count * (int)item_spacing.Y;
            max_height    += (int)item_spacing.Y * 2 + (int)window_padding.Y * 2;
            size.Y         = size.Y < (float)max_height ? size.Y : max_height;
            if (ComboBeginLabel(ctx, items[selected], size))
            {
                ctx.LayoutRowDynamic(item_height, 1);
                for (i = 0; i < count; ++i)
                {
                    if (ComboItemLabel(ctx, items[i], nk_text_align.NK_TEXT_LEFT))
                    {
                        selected = i;
                    }
                }
                ComboEnd(ctx);
            }

            return(selected);
        }
Beispiel #21
0
        public static void LayoutSpaceBegin(this NuklearContext ctx, int fmt, float height, int widget_count)
        {
            nk_window win;
            nk_panel  layout;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return;
            }
            win    = ctx.current;
            layout = win.Layout;
            PanelLayout(ctx, win, height, widget_count);
            if (fmt == NK_STATIC)
            {
                layout.Row.type = NK_LAYOUT_STATIC_FREE;
            }
            else
            {
                layout.Row.type = NK_LAYOUT_DYNAMIC_FREE;
            }
            layout.Row.ratio       = null;
            layout.Row.Filled      = 0;
            layout.Row.item_width  = 0;
            layout.Row.item_offset = 0;
        }
Beispiel #22
0
        public static void PanelAllocRow(this NuklearContext ctx, nk_window win)
        {
            var layout     = win.Layout;
            var spacing    = ctx.style.window.spacing;
            var row_height = layout.Row.height - spacing.Y;

            PanelLayout(ctx, win, row_height, layout.Row.columns);
        }
Beispiel #23
0
 public static bool ButtonImage(this NuklearContext ctx, nk_image img)
 {
     if (ctx == null)
     {
         return(false);
     }
     return(ButtonImageStyled(ctx, ctx.style.button, img));
 }
Beispiel #24
0
 public static void nk_combobox_separator(this NuklearContext ctx, string items_separated_by_separator,
                                          int separator,
                                          ref int selected, int count, int item_height, Vector2 size)
 {
     selected =
         nk_combo_separator(ctx, items_separated_by_separator, separator, selected, count,
                            item_height, size);
 }
Beispiel #25
0
 public static void ContextualClose(this NuklearContext ctx)
 {
     if (ctx == null || ctx.current == null || ctx.current.Layout == null)
     {
         return;
     }
     ctx.PopupClose();
 }
Beispiel #26
0
 public static int nk_combo_string(this NuklearContext ctx, string items_separated_by_zeros, int selected,
                                   int count,
                                   int item_height, Vector2 size)
 {
     return
         (nk_combo_separator(ctx, items_separated_by_zeros, '\0', selected, count,
                             item_height, size));
 }
Beispiel #27
0
        public static int nk_combo_separator(this NuklearContext ctx, string items_separated_by_separator,
                                             int separator, int selected,
                                             int count, int item_height, Vector2 size)
        {
            int           i;
            int           max_height;
            var           item_spacing   = new Vector2();
            var           window_padding = new Vector2();
            StringSegment current_item;
            StringSegment iter;

            if (ctx == null || items_separated_by_separator == null)
            {
                return(selected);
            }
            item_spacing   = ctx.style.window.spacing;
            window_padding = nk_panel_get_padding(ctx.style, ctx.current.Layout.Type);
            max_height     = count * item_height + count * (int)item_spacing.Y;
            max_height    += (int)item_spacing.Y * 2 + (int)window_padding.Y * 2;
            size.Y         = size.Y < (float)max_height ? size.Y : max_height;
            current_item   = items_separated_by_separator;
            for (i = 0; i < count; ++i)
            {
                iter = current_item;
                while (!iter.IsNullOrEmpty && iter[0] != separator)
                {
                    iter = iter + 1;
                }
                if (i == selected)
                {
                    break;
                }
                current_item = iter + 1;
            }

            if (ComboBeginText(ctx, current_item, size))
            {
                current_item = items_separated_by_separator;
                ctx.LayoutRowDynamic(item_height, 1);
                for (i = 0; i < count; ++i)
                {
                    iter = current_item;
                    while (!iter.IsNullOrEmpty && iter[0] != separator)
                    {
                        iter = iter + 1;
                    }
                    if (ComboItemText(ctx, current_item, nk_text_align.NK_TEXT_LEFT))
                    {
                        selected = i;
                    }
                    current_item = current_item + iter.Length + 1;
                }

                ComboEnd(ctx);
            }

            return(selected);
        }
Beispiel #28
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);
        }
Beispiel #29
0
 public static void nk_tooltip_end(this NuklearContext ctx)
 {
     if (ctx == null || ctx.current == null)
     {
         return;
     }
     ctx.PopupClose();
     ctx.PopupEnd();
 }
Beispiel #30
0
 public static bool ButtonSymbolText(this NuklearContext ctx, nk_symbol_type symbol, string text,
                                     nk_text_align align)
 {
     if (ctx == null)
     {
         return(false);
     }
     return(ButtonSymbolTextStyled(ctx, ctx.style.button, symbol, text, align));
 }