示例#1
0
        public static void DoProperty(ref uint ws, CommandBuffer _out_, RectangleF property, string name,
                                      nk_property_variant *variant, float inc_per_pixel, ref string buffer, ref int state, ref int cursor,
                                      ref int select_begin, ref int select_end, nk_style_property style, int filter, nk_input _in_,
                                      nk_font font,
                                      nk_text_edit text_edit, int behavior)
        {
            var filters = new NkPluginFilter[2];

            filters[0] = nk_filter_decimal;
            filters[1] = nk_filter_float;

            bool   active;
            int    old;
            float  size;
            string dst   = null;
            var    left  = new RectangleF();
            var    right = new RectangleF();
            var    label = new RectangleF();
            var    edit  = new RectangleF();
            var    empty = new RectangleF();

            left.Height  = font.Size / 2;
            left.Width   = left.Height;
            left.X       = property.X + style.border + style.padding.X;
            left.Y       = property.Y + style.border + property.Height / 2.0f - left.Height / 2;
            size         = font.width(name);
            label.X      = left.X + left.Width + style.padding.X;
            label.Width  = size + 2 * style.padding.X;
            label.Y      = property.Y + style.border + style.padding.Y;
            label.Height = property.Height - (2 * style.border + 2 * style.padding.Y);
            right.Y      = left.Y;
            right.Width  = left.Width;
            right.Height = left.Height;
            right.X      = property.X + property.Width - (right.Width + style.padding.X);
            if (state == NK_PROPERTY_EDIT)
            {
                size = font.width(buffer);

                size += style.edit.Cursor_size;
                dst   = buffer;
            }
            else
            {
                var _string_ = string.Empty;
                switch (variant->kind)
                {
                case NK_PROPERTY_INT:
                    _string_ = variant->value.i.ToString();
                    break;

                case NK_PROPERTY_FLOAT:
                    _string_ = variant->value.f.ToString();
                    break;

                case NK_PROPERTY_DOUBLE:
                    _string_ = variant->value.d.ToString();
                    break;
                }

                size = font.width(_string_);
                dst  = _string_;
            }

            edit.Width = size + 2 * style.padding.X;
            edit.Width = edit.Width < right.X - (label.X + label.Width)
                                ? edit.Width
                                : right.X - (label.X + label.Width);
            edit.X       = right.X - (edit.Width + style.padding.X);
            edit.Y       = property.Y + style.border;
            edit.Height  = property.Height - 2 * style.border;
            empty.Width  = edit.X - (label.X + label.Width);
            empty.X      = label.X + label.Width;
            empty.Y      = property.Y;
            empty.Height = property.Height;
            old          = state == NK_PROPERTY_EDIT ? 1 : 0;
            PropertyBehavior(ref ws, _in_, property, label, edit,
                             empty,
                             ref state, variant, inc_per_pixel);
            if (style.draw_begin != null)
            {
                style.draw_begin(_out_);
            }
            _out_.DrawProperty(style, &property, &label, ws, name, font);
            if (style.draw_end != null)
            {
                style.draw_end(_out_);
            }
            if (
                DoButtonSymbol(ref ws, _out_, left, style.sym_left, behavior,
                               style.dec_button,
                               _in_, font))
            {
                switch (variant->kind)
                {
                case NK_PROPERTY_INT:
                    variant->value.i =
                        (variant->value.i - variant->step.i < variant->max_value.i
                                                                ? variant->value.i - variant->step.i
                                                                : variant->max_value.i) < variant->min_value.i
                                                                ? variant->min_value.i
                                                                : variant->value.i - variant->step.i < variant->max_value.i
                                                                        ? variant->value.i - variant->step.i
                                                                        : variant->max_value.i;
                    break;

                case NK_PROPERTY_FLOAT:
                    variant->value.f =
                        (variant->value.f - variant->step.f < variant->max_value.f
                                                                ? variant->value.f - variant->step.f
                                                                : variant->max_value.f) < variant->min_value.f
                                                                ? variant->min_value.f
                                                                : variant->value.f - variant->step.f < variant->max_value.f
                                                                        ? variant->value.f - variant->step.f
                                                                        : variant->max_value.f;
                    break;

                case NK_PROPERTY_DOUBLE:
                    variant->value.d =
                        (variant->value.d - variant->step.d < variant->max_value.d
                                                                ? variant->value.d - variant->step.d
                                                                : variant->max_value.d) < variant->min_value.d
                                                                ? variant->min_value.d
                                                                : variant->value.d - variant->step.d < variant->max_value.d
                                                                        ? variant->value.d - variant->step.d
                                                                        : variant->max_value.d;
                    break;
                }
            }

            if (
                DoButtonSymbol(ref ws, _out_, right, style.sym_right, behavior,
                               style.inc_button,
                               _in_, font))
            {
                switch (variant->kind)
                {
                case NK_PROPERTY_INT:
                    variant->value.i =
                        (variant->value.i + variant->step.i < variant->max_value.i
                                                                ? variant->value.i + variant->step.i
                                                                : variant->max_value.i) < variant->min_value.i
                                                                ? variant->min_value.i
                                                                : variant->value.i + variant->step.i < variant->max_value.i
                                                                        ? variant->value.i + variant->step.i
                                                                        : variant->max_value.i;
                    break;

                case NK_PROPERTY_FLOAT:
                    variant->value.f =
                        (variant->value.f + variant->step.f < variant->max_value.f
                                                                ? variant->value.f + variant->step.f
                                                                : variant->max_value.f) < variant->min_value.f
                                                                ? variant->min_value.f
                                                                : variant->value.f + variant->step.f < variant->max_value.f
                                                                        ? variant->value.f + variant->step.f
                                                                        : variant->max_value.f;
                    break;

                case NK_PROPERTY_DOUBLE:
                    variant->value.d =
                        (variant->value.d + variant->step.d < variant->max_value.d
                                                                ? variant->value.d + variant->step.d
                                                                : variant->max_value.d) < variant->min_value.d
                                                                ? variant->min_value.d
                                                                : variant->value.d + variant->step.d < variant->max_value.d
                                                                        ? variant->value.d + variant->step.d
                                                                        : variant->max_value.d;
                    break;
                }
            }

            if (old != NK_PROPERTY_EDIT && state == NK_PROPERTY_EDIT)
            {
                buffer = dst;
                cursor = buffer != null ? buffer.Length : 0;
                active = false;
            }
            else
            {
                active = state == NK_PROPERTY_EDIT;
            }

            nk_textedit_clear_state(text_edit, NK_TEXT_EDIT_SINGLE_LINE, filters[filter]);
            text_edit.Active = active;

            text_edit.Text.str = dst;

            var length = dst != null ? dst.Length : 0;

            text_edit.Cursor =
                (cursor < length ? cursor : length) < 0
                                        ? 0
                                        : cursor < length
                                                ? cursor
                                                : length;
            text_edit.SelectionStart =
                (select_begin < length ? select_begin : length) < 0
                                        ? 0
                                        : select_begin < length
                                                ? select_begin
                                                : length;
            text_edit.SelectionEnd =
                (select_end < length ? select_end : length) < 0
                                        ? 0
                                        : select_end < length
                                                ? select_end
                                                : length;
            text_edit.Mode = NK_TEXT_EDIT_MODE_INSERT;
            DoEdit(ref ws, _out_, edit, NK_EDIT_FIELD | NK_EDIT_AUTO_SELECT,
                   filters[filter], text_edit,
                   style.edit, state == NK_PROPERTY_EDIT ? _in_ : null, font);
            cursor       = text_edit.Cursor;
            select_begin = text_edit.SelectionStart;
            select_end   = text_edit.SelectionEnd;
            if (text_edit.Active && nk_input_is_key_pressed(_in_, NK_KEY_ENTER))
            {
                text_edit.Active = false;
            }
            if (active && !text_edit.Active)
            {
                state = NK_PROPERTY_DEFAULT;

                switch (variant->kind)
                {
                case NK_PROPERTY_INT:
                    int.TryParse(buffer, out variant->value.i);
                    variant->value.i =
                        (variant->value.i < variant->max_value.i
                                                                ? variant->value.i
                                                                : variant->max_value.i) <
                        variant->min_value.i
                                                                ? variant->min_value.i
                                                                : variant->value.i < variant->max_value.i
                                                                        ? variant->value.i
                                                                        : variant->max_value.i;
                    break;

                case NK_PROPERTY_FLOAT:
                    float.TryParse(buffer, out variant->value.f);
                    variant->value.f =
                        (variant->value.f < variant->max_value.f
                                                                ? variant->value.f
                                                                : variant->max_value.f) <
                        variant->min_value.f
                                                                ? variant->min_value.f
                                                                : variant->value.f < variant->max_value.f
                                                                        ? variant->value.f
                                                                        : variant->max_value.f;
                    break;

                case NK_PROPERTY_DOUBLE:
                    double.TryParse(buffer, out variant->value.d);
                    variant->value.d =
                        (variant->value.d < variant->max_value.d
                                                                ? variant->value.d
                                                                : variant->max_value.d) <
                        variant->min_value.d
                                                                ? variant->min_value.d
                                                                : variant->value.d < variant->max_value.d
                                                                        ? variant->value.d
                                                                        : variant->max_value.d;
                    break;
                }
            }
        }
 public static void StylePushFont(this NuklearContext ctx, nk_font font)
 {
     ctx.stacks.fonts.Push(font);
     ctx.style.font = font;
 }
示例#3
0
        public static int nk_do_color_picker(ref uint state, CommandBuffer _out_, Colorf *col, int fmt,
                                             RectangleF bounds, Vector2 padding, nk_input _in_, nk_font font)
        {
            var   ret       = 0;
            var   matrix    = new RectangleF();
            var   hue_bar   = new RectangleF();
            var   alpha_bar = new RectangleF();
            float bar_w;

            if (_out_ == null || col == null || font == null)
            {
                return(ret);
            }
            bar_w            = font.Size;
            bounds.X        += padding.X;
            bounds.Y        += padding.X;
            bounds.Width    -= 2 * padding.X;
            bounds.Height   -= 2 * padding.Y;
            matrix.X         = bounds.X;
            matrix.Y         = bounds.Y;
            matrix.Height    = bounds.Height;
            matrix.Width     = bounds.Width - (3 * padding.X + 2 * bar_w);
            hue_bar.Width    = bar_w;
            hue_bar.Y        = bounds.Y;
            hue_bar.Height   = matrix.Height;
            hue_bar.X        = matrix.X + matrix.Width + padding.X;
            alpha_bar.X      = hue_bar.X + hue_bar.Width + padding.X;
            alpha_bar.Y      = bounds.Y;
            alpha_bar.Width  = bar_w;
            alpha_bar.Height = matrix.Height;
            ret =
                ColorPickerBehavior(ref state, &bounds, &matrix, &hue_bar, fmt == NK_RGBA ? &alpha_bar : null, col,
                                    _in_);
            _out_.DrawColorPicker(&matrix, &hue_bar, fmt == NK_RGBA ? &alpha_bar : null, *col);
            return(ret);
        }
示例#4
0
        public static void DrawCheckBox(this CommandBuffer _out_, uint state, nk_style_toggle style, bool active,
                                        RectangleF *label, RectangleF *selector, RectangleF *cursors, string _string_, nk_font font)
        {
            nk_style_item background;
            nk_style_item cursor;
            var           text = new nk_text();

            if ((state & NK_WIDGET_STATE_HOVER) != 0)
            {
                background = style.hover;
                cursor     = style.cursor_hover;
                text.text  = style.text_hover;
            }
            else if ((state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                background = style.hover;
                cursor     = style.cursor_hover;
                text.text  = style.text_active;
            }
            else
            {
                background = style.normal;
                cursor     = style.cursor_normal;
                text.text  = style.text_normal;
            }

            if (background.type == NK_STYLE_ITEM_COLOR)
            {
                _out_.FillRect(*selector, 0, style.border_color);
                _out_.FillRect(RectangleF.nk_shrink_rect_(*selector, style.border),
                               0, background.Color);
            }
            else
            {
                _out_.DrawImage(*selector, background.Image, nk_white);
            }

            if (active)
            {
                if (cursor.type == NK_STYLE_ITEM_IMAGE)
                {
                    _out_.DrawImage(*cursors, cursor.Image, nk_white);
                }
                else
                {
                    _out_.FillRect(*cursors, 0, cursor.Color);
                }
            }

            text.padding.X  = 0;
            text.padding.Y  = 0;
            text.Background = style.text_background;
            _out_.WidgetText(*label, _string_, &text, nk_text_align.NK_TEXT_LEFT, font);
        }