예제 #1
0
        public Slider(Func <int> getter, Action <int> setter, int min, int max, Func <int, string> format = null)
        {
            _getter = getter;
            _setter = setter;
            _min    = min;
            _max    = max;

            _decrement = new Button("<")
            {
                Typematic = true
            }.OnClick(Decrement);
            _increment = new Button(">")
            {
                Typematic = true
            }.OnClick(Increment);

            var track = new SliderTrack(getter, x => _setter(Math.Clamp(x, _min, _max)), min, max, format);

            _frame = new ButtonFrame(track)
            {
                State   = ButtonState.Pressed,
                Padding = 0
            };

            AttachChild(_decrement);
            AttachChild(_frame);
            AttachChild(_increment);
        }
예제 #2
0
        public SliderThumb(Func <int> getter, Func <int, string> format = null)
        {
            On <HoverEvent>(e => _frame.State = ButtonState.Hover);
            On <BlurEvent>(e => _frame.State  = ButtonState.Normal);

            _getter = getter;
            _format = format;
            _text   = new SimpleText("").Center();
            _frame  = new ButtonFrame(_text)
            {
                Theme = ButtonTheme.SliderThumb
            };
            AttachChild(_frame);
        }
예제 #3
0
        public ProgressBar(IText hover, Func <int> getValue, Func <int> getMax, int absoluteMax)
        {
            On <HoverEvent>(e => Hover());
            On <BlurEvent>(e => Raise(new HoverTextEvent(null)));

            _hover       = hover;
            _getValue    = getValue;
            _getMax      = getMax;
            _absoluteMax = absoluteMax;

            _bar   = new UiRectangle(CommonColor.Blue4);
            _frame = AttachChild(new ButtonFrame(_bar)
            {
                State = ButtonState.Pressed, Padding = 0
            });
        }
예제 #4
0
파일: Button.cs 프로젝트: Metibor/ualbion
        public Button(IUiElement content)
        {
            On <HoverEvent>(_ => { IsHovered = true; Hover?.Invoke(); });
            On <BlurEvent>(_ => { IsHovered = false; Blur?.Invoke(); });
            On <UiLeftClickEvent>(e =>
            {
                if (!IsHovered)
                {
                    return;
                }

                if (!IsClicked)
                {
                    ButtonDown?.Invoke();
                }

                IsClicked = true;
                if (Typematic)
                {
                    Click?.Invoke();
                }

                e.Propagating = false;
            });

            On <UiLeftReleaseEvent>(e =>
            {
                if (!IsClicked)
                {
                    return;
                }
                IsClicked = false;

                if (Typematic)
                {
                    _typematicAccrual = 0;
                    return;
                }

                if (!IsHovered)
                {
                    return;
                }

                if (DoubleClick == null || !AllowDoubleClick || SuppressNextDoubleClick) // Simple single click only button
                {
                    Click?.Invoke();
                    SuppressNextDoubleClick = false;
                    return;
                }

                if (ClickTimerPending) // If they double-clicked...
                {
                    DoubleClick?.Invoke();
                    ClickTimerPending = false; // Ensure the single-click behaviour doesn't happen.
                }
                else // For the first click, just start the double-click timer.
                {
                    var config = Resolve <GameConfig>();
                    Raise(new StartTimerEvent(TimerName, config.UI.ButtonDoubleClickIntervalSeconds, this));
                    ClickTimerPending = true;
                }
            });

            On <UiRightClickEvent>(e =>
            {
                e.Propagating  = false;
                IsRightClicked = true;
            });

            On <UiRightReleaseEvent>(e =>
            {
                if (IsRightClicked && IsHovered)
                {
                    RightClick?.Invoke();
                }
                IsRightClicked = false;
            });

            On <TimerElapsedEvent>(e =>
            {
                if (e.Id != TimerName)
                {
                    return;
                }

                if (!ClickTimerPending) // They've already double-clicked
                {
                    return;
                }

                Click?.Invoke();
                ClickTimerPending = false;
            });

            On <EngineUpdateEvent>(e =>
            {
                if (!Typematic || !IsClicked)
                {
                    return;
                }

                var oldAccrual     = _typematicAccrual;
                _typematicAccrual += e.DeltaSeconds;
                var rate           = 8 * (int)(2 * oldAccrual);
                var oldAmount      = (int)(oldAccrual * rate);
                var newAmount      = (int)(_typematicAccrual * rate);
                var delta          = newAmount - oldAmount;
                for (int i = 0; i < delta; i++)
                {
                    Click?.Invoke();
                }
            });

            _id    = Interlocked.Increment(ref _nextId);
            _frame = AttachChild(new ButtonFrame(content));
        }