Example #1
0
        public static void nk_layout_peek(nk_rect *bounds, nk_context ctx)
        {
            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      = (float)(layout.at_y);
            index  = (int)(layout.row.index);
            if ((layout.row.index) >= (layout.row.columns))
            {
                layout.at_y     += (float)(layout.row.height);
                layout.row.index = (int)(0);
            }

            nk_layout_widget_space(bounds, ctx, win, (int)(nk_false));
            if (layout.row.index == 0)
            {
                bounds->x -= (float)(layout.row.item_offset);
            }

            layout.at_y      = (float)(y);
            layout.row.index = (int)(index);
        }
Example #2
0
 public static int nk_popup_begin(nk_context ctx, int type, string title, uint flags, nk_rect rect)
 {
     fixed(char *ptr = title)
     {
         return(nk_popup_begin(ctx, type, ptr, flags, rect));
     }
 }
Example #3
0
        public static nk_window nk_create_window(nk_context ctx)
        {
            var result = new nk_window {
                seq = ctx.seq
            };

            return(result);
        }
Example #4
0
 public static int nk_init_fixed(nk_context ctx, void *memory, ulong size, nk_user_font font)
 {
     if (memory == null)
     {
         return(0);
     }
     nk_setup(ctx, font);
     return(1);
 }
Example #5
0
        public static void nk_free(nk_context ctx)
        {
            if (ctx == null)
            {
                return;
            }

            ctx.seq     = 0;
            ctx.build   = 0;
            ctx.begin   = null;
            ctx.end     = null;
            ctx.active  = null;
            ctx.current = null;
            ctx.count   = 0;
        }
Example #6
0
        public static void nk_panel_alloc_space(nk_rect *bounds, nk_context ctx)
        {
            nk_window win;
            nk_panel  layout;

            if (((ctx == null) || (ctx.current == null)) || (ctx.current.layout == null))
            {
                return;
            }
            win    = ctx.current;
            layout = win.layout;
            if ((layout.row.index) >= (layout.row.columns))
            {
                nk_panel_alloc_row(ctx, win);
            }
            nk_layout_widget_space(bounds, ctx, win, (int)(nk_true));
            layout.row.index++;
        }
Example #7
0
        public static int nk_widget(nk_rect *bounds, nk_context ctx)
        {
            nk_rect   c = new nk_rect();
            nk_rect   v = new nk_rect();
            nk_window win;
            nk_panel  layout;
            nk_input  _in_;

            if (((ctx == null) || (ctx.current == null)) || (ctx.current.layout == null))
            {
                return((int)(NK_WIDGET_INVALID));
            }
            nk_panel_alloc_space(bounds, ctx);
            win       = ctx.current;
            layout    = win.layout;
            _in_      = ctx.input;
            c         = (nk_rect)(layout.clip);
            bounds->x = ((float)((int)(bounds->x)));
            bounds->y = ((float)((int)(bounds->y)));
            bounds->w = ((float)((int)(bounds->w)));
            bounds->h = ((float)((int)(bounds->h)));
            c.x       = ((float)((int)(c.x)));
            c.y       = ((float)((int)(c.y)));
            c.w       = ((float)((int)(c.w)));
            c.h       = ((float)((int)(c.h)));
            nk_unify(ref v, ref c, (float)(bounds->x), (float)(bounds->y), (float)(bounds->x + bounds->w),
                     (float)(bounds->y + bounds->h));
            if (
                !(!(((((bounds->x) > (c.x + c.w)) || ((bounds->x + bounds->w) < (c.x))) || ((bounds->y) > (c.y + c.h))) ||
                    ((bounds->y + bounds->h) < (c.y)))))
            {
                return((int)(NK_WIDGET_INVALID));
            }
            if (
                !((((v.x) <= (_in_.mouse.pos.x)) && ((_in_.mouse.pos.x) < (v.x + v.w))) &&
                  (((v.y) <= (_in_.mouse.pos.y)) && ((_in_.mouse.pos.y) < (v.y + v.h)))))
            {
                return((int)(NK_WIDGET_ROM));
            }
            return((int)(NK_WIDGET_VALID));
        }
Example #8
0
        public static nk_window nk__begin(nk_context ctx)
        {
            if (ctx == null || ctx.count == 0)
            {
                return(null);
            }
            if (ctx.build == 0)
            {
                nk_build(ctx);
                ctx.build = nk_true;
            }

            var iter = ctx.begin;

            while ((iter != null) &&
                   ((iter.buffer.count == 0) || (iter.flags & NK_WINDOW_HIDDEN) != 0 || (iter.seq != ctx.seq)))
            {
                iter = iter.next;
            }

            return(iter);
        }
Example #9
0
        public static void nk_free_window(nk_context ctx, nk_window win)
        {
            nk_table it = win.tables;

            if (win.popup.win != null)
            {
                nk_free_window(ctx, win.popup.win);
                win.popup.win = null;
            }

            win.next = null;
            win.prev = null;
            while (it != null)
            {
                var n = it.next;
                nk_remove_table(win, it);
                if (it == win.tables)
                {
                    win.tables = n;
                }
                it = n;
            }
        }
Example #10
0
        public static int nk_widget_fitting(nk_rect *bounds, nk_context ctx, nk_vec2 item_padding)
        {
            nk_window win;
            nk_style  style;
            nk_panel  layout;
            int       state;
            nk_vec2   panel_padding = new nk_vec2();

            if (((ctx == null) || (ctx.current == null)) || (ctx.current.layout == null))
            {
                return((int)(NK_WIDGET_INVALID));
            }
            win           = ctx.current;
            style         = ctx.style;
            layout        = win.layout;
            state         = (int)(nk_widget(bounds, ctx));
            panel_padding = (nk_vec2)(nk_panel_get_padding(style, (int)(layout.type)));
            if ((layout.row.index) == (1))
            {
                bounds->w += (float)(panel_padding.x);
                bounds->x -= (float)(panel_padding.x);
            }
            else
            {
                bounds->x -= (float)(item_padding.x);
            }
            if ((layout.row.index) == (layout.row.columns))
            {
                bounds->w += (float)(panel_padding.x);
            }
            else
            {
                bounds->w += (float)(item_padding.x);
            }
            return((int)(state));
        }
Example #11
0
 public static void nk_free_panel(nk_context ctx, nk_panel panel)
 {
 }
Example #12
0
        public static nk_table nk_create_table(nk_context ctx)
        {
            var result = new nk_table();

            return(result);
        }
Example #13
0
 public static int nk_init(nk_context ctx, nk_user_font font)
 {
     nk_setup(ctx, font);
     return(1);
 }
Example #14
0
        public static nk_panel nk_create_panel(nk_context ctx)
        {
            var result = new nk_panel();

            return(result);
        }
Example #15
0
        public static void nk_layout_widget_space(nk_rect *bounds, nk_context ctx, nk_window win, int modify)
        {
            nk_panel layout;
            nk_style style;
            nk_vec2  spacing      = new nk_vec2();
            nk_vec2  padding      = new nk_vec2();
            float    item_offset  = (float)(0);
            float    item_width   = (float)(0);
            float    item_spacing = (float)(0);
            float    panel_space  = (float)(0);

            if (((ctx == null) || (ctx.current == null)) || (ctx.current.layout == null))
            {
                return;
            }
            win         = ctx.current;
            layout      = win.layout;
            style       = ctx.style;
            spacing     = (nk_vec2)(style.window.spacing);
            padding     = (nk_vec2)(nk_panel_get_padding(style, (int)(layout.type)));
            panel_space =
                (float)
                (nk_layout_row_calculate_usable_space(ctx.style, (int)(layout.type), (float)(layout.bounds.w),
                                                      (int)(layout.row.columns)));
            switch (layout.row.type)
            {
            case NK_LAYOUT_DYNAMIC_FIXED:
            {
                item_width   = (float)(((1.0f) < (panel_space - 1.0f) ? (panel_space - 1.0f) : (1.0f)) / (float)(layout.row.columns));
                item_offset  = (float)((float)(layout.row.index) * item_width);
                item_spacing = (float)((float)(layout.row.index) * spacing.x);
            }
            break;

            case NK_LAYOUT_DYNAMIC_ROW:
            {
                item_width   = (float)(layout.row.item_width * panel_space);
                item_offset  = (float)(layout.row.item_offset);
                item_spacing = (float)(0);
                if ((modify) != 0)
                {
                    layout.row.item_offset += (float)(item_width + spacing.x);
                    layout.row.filled      += (float)(layout.row.item_width);
                    layout.row.index        = (int)(0);
                }
            }
            break;

            case NK_LAYOUT_DYNAMIC_FREE:
            {
                bounds->x  = (float)(layout.at_x + (layout.bounds.w * layout.row.item.x));
                bounds->x -= ((float)(layout.offset.x));
                bounds->y  = (float)(layout.at_y + (layout.row.height * layout.row.item.y));
                bounds->y -= ((float)(layout.offset.y));
                bounds->w  = (float)(layout.bounds.w * layout.row.item.w);
                bounds->h  = (float)(layout.row.height * layout.row.item.h);
                return;
            }

            case NK_LAYOUT_DYNAMIC:
            {
                float ratio;
                ratio =
                    (float)
                    (((layout.row.ratio[layout.row.index]) < (0)) ? layout.row.item_width : layout.row.ratio[layout.row.index]);
                item_spacing = (float)((float)(layout.row.index) * spacing.x);
                item_width   = (float)(ratio * panel_space);
                item_offset  = (float)(layout.row.item_offset);
                if ((modify) != 0)
                {
                    layout.row.item_offset += (float)(item_width);
                    layout.row.filled      += (float)(ratio);
                }
            }
            break;

            case NK_LAYOUT_STATIC_FIXED:
            {
                item_width   = (float)(layout.row.item_width);
                item_offset  = (float)((float)(layout.row.index) * item_width);
                item_spacing = (float)((float)(layout.row.index) * spacing.x);
            }
            break;

            case NK_LAYOUT_STATIC_ROW:
            {
                item_width   = (float)(layout.row.item_width);
                item_offset  = (float)(layout.row.item_offset);
                item_spacing = (float)((float)(layout.row.index) * spacing.x);
                if ((modify) != 0)
                {
                    layout.row.item_offset += (float)(item_width);
                }
            }
            break;

            case NK_LAYOUT_STATIC_FREE:
            {
                bounds->x = (float)(layout.at_x + layout.row.item.x);
                bounds->w = (float)(layout.row.item.w);
                if (((bounds->x + bounds->w) > (layout.max_x)) && ((modify) != 0))
                {
                    layout.max_x = (float)(bounds->x + bounds->w);
                }
                bounds->x -= ((float)(layout.offset.x));
                bounds->y  = (float)(layout.at_y + layout.row.item.y);
                bounds->y -= ((float)(layout.offset.y));
                bounds->h  = (float)(layout.row.item.h);
                return;
            }

            case NK_LAYOUT_STATIC:
            {
                item_spacing = (float)((float)(layout.row.index) * spacing.x);
                item_width   = (float)(layout.row.ratio[layout.row.index]);
                item_offset  = (float)(layout.row.item_offset);
                if ((modify) != 0)
                {
                    layout.row.item_offset += (float)(item_width);
                }
            }
            break;

            case NK_LAYOUT_TEMPLATE:
            {
                item_width   = (float)(layout.row.templates[layout.row.index]);
                item_offset  = (float)(layout.row.item_offset);
                item_spacing = (float)((float)(layout.row.index) * spacing.x);
                if ((modify) != 0)
                {
                    layout.row.item_offset += (float)(item_width);
                }
            }
            break;

            default:
                ;
                break;
            }

            bounds->w = (float)(item_width);
            bounds->h = (float)(layout.row.height - spacing.y);
            bounds->y = (float)(layout.at_y - (float)(layout.offset.y));
            bounds->x = (float)(layout.at_x + item_offset + item_spacing + padding.x);
            if (((bounds->x + bounds->w) > (layout.max_x)) && ((modify) != 0))
            {
                layout.max_x = (float)(bounds->x + bounds->w);
            }
            bounds->x -= ((float)(layout.offset.x));
        }
Example #16
0
        public static void nk_property_(nk_context ctx, char *name, nk_property_variant *variant, float inc_per_pixel,
                                        int filter)
        {
            var    bounds = new nk_rect();
            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      = nk_widget(&bounds, ctx);

            if (s == 0)
            {
                return;
            }
            if (name[0] == '#')
            {
                hash = nk_murmur_hash(name, nk_strlen(name), win.property.seq++);
                name++;
            }
            else
            {
                hash = nk_murmur_hash(name, nk_strlen(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;
                nk_do_property(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;
                nk_do_property(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;
            }
        }
Example #17
0
 public static int nk_init_default(nk_context ctx, nk_user_font font)
 {
     return(nk_init(ctx, font));
 }
Example #18
0
        public static void nk_build(nk_context ctx)
        {
            if (ctx.style.cursor_active == null)
            {
                ctx.style.cursor_active = ctx.style.cursors[NK_CURSOR_ARROW];
            }
            if ((ctx.style.cursor_active != null) && (ctx.input.mouse.grabbed == 0) && ((ctx.style.cursor_visible) != 0))
            {
                var mouse_bounds = new nk_rect();
                var cursor       = ctx.style.cursor_active;
                nk_command_buffer_init(ctx.overlay, NK_CLIPPING_OFF);
                nk_start_buffer(ctx, ctx.overlay);
                mouse_bounds.x = ctx.input.mouse.pos.x - cursor.offset.x;
                mouse_bounds.y = ctx.input.mouse.pos.y - cursor.offset.y;
                mouse_bounds.w = cursor.size.x;
                mouse_bounds.h = cursor.size.y;
                nk_draw_image(ctx.overlay, mouse_bounds, cursor.img, nk_white);
            }

            var             it  = ctx.begin;
            nk_command_base cmd = null;

            for (; it != null;)
            {
                var next = it.next;
                if (((it.flags & NK_WINDOW_HIDDEN) != 0) || (it.seq != ctx.seq))
                {
                    goto cont;
                }
                cmd = it.buffer.last;

                while ((next != null) &&
                       (next.buffer == null || next.buffer.count == 0 || (next.flags & NK_WINDOW_HIDDEN) != 0))
                {
                    next = next.next;
                }

                if (next != null)
                {
                    cmd.next = next.buffer.first;
                }
cont:
                it = next;
            }

            it = ctx.begin;

            while (it != null)
            {
                var next = it.next;

                if (it.popup.buf.buffer.count == 0)
                {
                    goto skip;
                }

                var buf = it.popup.buf.buffer;
                cmd.next = buf.first;
                cmd      = buf.last;

                it.popup.buf.buffer.count = 0;

skip:
                it = next;
            }
            if (cmd != null)
            {
                cmd.next = ctx.overlay.count > 0 ? ctx.overlay.first : null;
            }
        }