示例#1
0
        public void PreDraw(float DT)
        {
            seenElementKeys.Clear();
            if (wasUpdated)
            {
                rootDrawCall = Builder().RenderAsRoot();
                wasUpdated   = false;

                componentStates = componentStates
                                  .Where(entry => seenElementKeys.Contains(entry.Key))
                                  .ToDictionary(entry => entry.Key, entry => entry.Value);
                componentEventStates = componentEventStates
                                       .Where(entry => seenElementKeys.Contains(entry.Key))
                                       .ToDictionary(entry => entry.Key, entry => entry.Value);
            }

            rootDrawCall.PreDraw(
                DT,
                false,
                focusedElementKey,
                GameService.GetService <IInputService>().GetMouseInScreenSpace()
                );
        }
示例#2
0
        public bool PreDrawBase(float DT, UIDrawCall DrawCall, bool AreMouseEventsBlocked, bool IsFocused, Vector2?MaybeCursorPosition)
        {
            bool isMouseInside = GetEventState <bool>("isMouseInside");

            if (DrawCall.ContainsPoint(MaybeCursorPosition))
            {
                Vector2       cursorPosition   = MaybeCursorPosition.Value;
                IInputService inputService     = GameService.GetService <IInputService>();
                Vector2       interiorPosition = new Vector2(cursorPosition.X - DrawCall.X, cursorPosition.Y - DrawCall.Y);

                SetEventState("scroll", GetEventState <int>("scroll") - inputService.GetMouseScroll());
                if (!AreMouseEventsBlocked)
                {
                    if (!isMouseInside)
                    {
                        onEnter?.Invoke(interiorPosition);

                        if (inputService.IsLeftMouseButtonHeld())
                        {
                            onPress?.Invoke(interiorPosition);
                        }

                        if (inputService.IsMiddleMouseButtonHeld())
                        {
                            onPressMiddle?.Invoke(interiorPosition);
                        }

                        SetEventState("isMouseInside", true);
                    }
                    else
                    {
                        if (inputService.WasLeftMouseButtonClicked())
                        {
                            uiRendererInstance.SetFocusedElement(key);
                            onClick?.Invoke(interiorPosition);
                            onRelease?.Invoke(interiorPosition);
                            onEnter?.Invoke(interiorPosition);
                        }
                        else if (inputService.IsLeftMouseButtonHeld())
                        {
                            onPress?.Invoke(interiorPosition);
                        }

                        if (inputService.WasMiddleMouseButtonClicked())
                        {
                            //onClick?.Invoke();
                            onReleaseMiddle?.Invoke(interiorPosition);
                        }
                        else if (inputService.IsMiddleMouseButtonHeld())
                        {
                            onPressMiddle?.Invoke(interiorPosition);
                        }

                        if (inputService.WasRightMouseButtonClicked())
                        {
                            onRightClick?.Invoke(interiorPosition);
                        }
                    }
                    if (inputService.GetCurrentMouseState().Position != inputService.GetRolledbackMouseState(1).Position)
                    {
                        onMove?.Invoke(interiorPosition);
                    }
                    if (HasMouseClickHandler() || shouldBlockMouseEvents)
                    {
                        AreMouseEventsBlocked = true;
                    }
                }
            }
            else
            {
                if (isMouseInside)
                {
                    onExit?.Invoke(Vector2.Zero);
                    SetEventState("isMouseInside", false);
                }
            }
            PreDraw(DT, IsFocused);
            return(AreMouseEventsBlocked);
        }