예제 #1
0
    public void Init()
    {
        if (inialized)
        {
            return;
        }
        else
        {
            inialized = true;
        }

        idleValue    *= Mathf.Deg2Rad;
        scrollerState = UIElementState.Active;

        // circleCenter = transform.position+ Vector3.forward * zOffset;
        cvs             = new List <CanvasGroup>();
        scrollableItems = new List <Transform>();
        for (int i = 0; i < transform.childCount; i++)
        {
            if (transform.GetChild(i).tag != "notScrollable")
            {
                CanvasGroup cv = transform.GetChild(i).gameObject.AddComponent <CanvasGroup>();
                cvs.Add(cv);
                scrollableItems.Add(transform.GetChild(i));
            }
        }
    }
예제 #2
0
    void Start()
    {
        if (inialized)
        {
            return;
        }
        inialized     = true;
        originalPos   = transform.localPosition;
        originalScale = transform.localScale;
        currentIndex  = 0;
        tabsButtons   = SideButtonsParent.GetComponentsInChildren <Button>();

        circularScrolls = GetComponentsInChildren <CircularScroll>(true);
        for (int i = 0; i < circularScrolls.Length; i++)
        {
            circularScrolls[i].Init();
            circularScrolls[i].ForceIdle();
        }
        SwitchTab(0);
        for (int i = 1; i < tabsButtons.Length; i++)
        {
            tabsButtons[i].image.color = new Color(1, 1, 1, 0.5f);
        }
        managerState = UIElementState.Active;
    }
예제 #3
0
        private async void AddImageByUriAsync(UIElementState uiElementState) // string assetUri, string aggregateId)
        {
            var layoutDetail = AppDatabase.Current.GetLayoutDetail(0);       // 0 = LayoutDetail

            AppDatabase.Current.UpdateUIElementStateField(uiElementState.AggregateId, "udfBool1", true, sendAggregateUpdateMessage: false);
            uiElementState.udfBool1 = true;
            DoAggregateUpdatedForImage(uiElementState, false);
        }
예제 #4
0
 public void Close()
 {
     CanvasManager.instance.RenableButtons();
     timer        = 0;
     managerState = UIElementState.TransitionOut;
     ToggleHitBox(true);
     TrackingManager.instance.ToggleArrows(false);
     gameObject.SetActive(false);
 }
예제 #5
0
 public void Disable()
 {
     gameObject.GetComponent <Image>().raycastTarget = false;
     gameObject.GetComponent <Button>().interactable = false;
     if (fade != null)
     {
         fade.TextFadeOut();
     }
     elemState = UIElementState.Inactive;
 }
예제 #6
0
 public Button(UIElementState state, Point position, Point size, string text, SpriteFont font, Color fontColor, Texture2D texture, Color hoverColor) : base(state, position)
 {
     Size       = size;
     Text       = text;
     Font       = font;
     FontColor  = fontColor;
     Texture    = texture;
     Hovered    = false;
     HoverColor = hoverColor;
 }
예제 #7
0
 public void Enable()
 {
     gameObject.GetComponent <Image>().raycastTarget = true;
     gameObject.GetComponent <Button>().interactable = true;
     if (fade != null)
     {
         fade.TextFadeIn();
     }
     elemState = UIElementState.Active;
 }
예제 #8
0
 public Textbox(UIElementState state, Point position, Point size, int maxTextLength, string text, SpriteFont font, Color fontColor, Texture2D texture, Color selectedColor) : base(state, position)
 {
     Size          = size;
     MaxTextLength = maxTextLength;
     Text          = text;
     Font          = font;
     FontColor     = fontColor;
     Texture       = texture;
     Selected      = false;
     SelectedColor = selectedColor;
 }
예제 #9
0
    // Update is called once per frame
    void Update()
    {
        transform.LookAt(Camera.main.transform.position);
        int selectedPage = circularScrolls[currentIndex].GetCurIndex();

        for (int i = 0; i < circularScrolls[currentIndex].scrollableItems.Count; i++)
        {
            scrollIconsPanel.GetChild(i).GetComponent <Image>().color = Color.white * (i == selectedPage ? 1 : 0.5f);
        }

        switch (managerState)
        {
        case UIElementState.Active:

            for (int i = 0; i < tabsButtons.Length; i++)
            {
                float rotDelta = -20 * Mathf.Clamp01(Mathf.Abs(currentIndex - i) / 2f);

                tabsButtons[i].transform.localRotation = Quaternion.RotateTowards(tabsButtons[i].transform.localRotation, Quaternion.Euler(0, rotDelta, 0), 5f);
                //0.9f original max degrees delta value
            }
            break;

        case UIElementState.TransitionIn:
            transform.localPosition = Vector3.Lerp(Vector3.zero, originalPos, timer);
            transform.localScale    = Vector3.Lerp(Vector3.zero, originalScale, timer);
            timer += Time.deltaTime;
            if (timer >= 1)
            {
                timer        = 0;
                managerState = UIElementState.Active;
            }
            break;

        case UIElementState.TransitionOut:
            transform.localPosition = Vector3.Lerp(originalPos, Vector3.zero, timer);
            transform.localScale    = Vector3.Lerp(originalScale, Vector3.zero, timer);
            timer += Time.deltaTime;
            if (timer >= 1)
            {
                timer        = 0;
                managerState = UIElementState.Idle;
                gameObject.SetActive(false);
            }
            break;

        default:
            break;
        }
    }
예제 #10
0
        public Color GetColor(UIElementState state)
        {
            switch (state)
            {
            case UIElementState.Normal:
                return(Color);

            case UIElementState.Highlighted:
                return(HighlightedColor);

            case UIElementState.Selected:
                return(SelectedColor);

            case UIElementState.Disabled:
                return(DisabledColor);
            }

            return(Color);
        }
예제 #11
0
        ///// <summary>
        ///// Loads bitmap asynchronously and injects into global variables. I need to work out how to NOT make them global
        ///// </summary>
        ///// <param name="assetNativeUri"></param>
        ///// <returns></returns>
        //public async Task<bool> LoadAssetAsync(string assetNativeUri)
        //{
        //    var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

        //    var storageFile = await Windows.Storage.StorageFile.GetFileFromPathAsync(assetNativeUri);

        //    Stream ms = await storageFile.OpenStreamForReadAsync();  //ras.GetResults().AsStreamForRead())
        //    //var data = SharpDX.IO.NativeFile.ReadAllBytes(assetNativeUri);
        //    //using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
        //    {
        //        if (ms != null)
        //        {

        //            SharpDX.WIC.BitmapDecoder bitmapDecoder = new SharpDX.WIC.BitmapDecoder(
        //                                                                                        _deviceManager.WICFactory,
        //                                                                                        ms,
        //                                                                                        SharpDX.WIC.DecodeOptions.CacheOnDemand
        //                                                                                    );
        //            {


        //                SharpDX.WIC.BitmapFrameDecode bitmapFrameDecode = bitmapDecoder.GetFrame(0);
        //                {

        //                    SharpDX.WIC.BitmapSource bitmapSource = new SharpDX.WIC.BitmapSource(bitmapFrameDecode.NativePointer);
        //                    {

        //                        SharpDX.WIC.FormatConverter formatConverter = new SharpDX.WIC.FormatConverter(_deviceManager.WICFactory);
        //                        //formatConverter.Initialize( bitmapSource, SharpDX.WIC.PixelFormat.Format32bppBGRA);
        //                        formatConverter.Initialize(
        //                            bitmapSource,
        //                            SharpDX.WIC.PixelFormat.Format32bppBGRA,
        //                            SharpDX.WIC.BitmapDitherType.None,
        //                            null,
        //                            0.0f,
        //                            SharpDX.WIC.BitmapPaletteType.Custom
        //                            );

        //                        _backgroundImageSize = formatConverter.Size;

        //                        _backgroundImageFormatConverter = formatConverter;

        //                        return true;
        //                    }

        //                }

        //            }

        //        }
        //    }

        //    //ras.Close();

        //    _backgroundImageFormatConverter = null;
        //    _backgroundImageSize = new Size2(0, 0);

        //    return false;
        //}



        /// <summary>
        /// Used to update an existing bitmap effect with a new image
        /// </summary>
        /// <param name="assetUri"></param>
        /// <param name="aggregateId"></param>
        private async void UpdateImageByUri(UIElementState uistate, LayoutDetail layoutDetail, bool resetTransforms = true)
        {
            try
            {
                //string assetUri, string aggregateId
                var found = _renderTree.Where(x => x.Type == eRenderType.Effect && x.EffectDTO.AggregateId == uistate.AggregateId).FirstOrDefault();
                if (found != null)
                {
                    var ret = await LoadAssetAsync(_deviceManager.WICFactory, uistate.udfString1, uistate.AggregateId);

                    //LoadLocalNativeAsset(assetUri, out backgroundImageFormatConverter, out backgroundImageSize);

                    if (ret != null)
                    {
                        found.EffectDTO.Effect.SetValueByName("WicBitmapSource", _backgroundImageFormatConverter);
                        _backgroundImageFormatConverter.Dispose();
                        _backgroundImageFormatConverter = null;


                        //double newRatio = (_backgroundImageSize.Width > Window.Current.Bounds.Width) ? (Window.Current.Bounds.Width/_backgroundImageSize.Width) : 1d;
                        double newRatio = (_backgroundImageSize.Width > layoutDetail.Width) ? (layoutDetail.Width / _backgroundImageSize.Width) : 1d;

                        AppDatabase.Current.UpdateUIElementStateField(uistate.AggregateId, "udfBool1", false, sendAggregateUpdateMessage: false);

                        if (resetTransforms)
                        {
                            AppDatabase.Current.AddUpdateUIElementState(uistate.AggregateId, State.SelectedScene.AggregateId, 0, 0, _backgroundImageSize.Width, _backgroundImageSize.Height, newRatio, true, null, null, false);
                        }
                        else
                        {
                            AppDatabase.Current.AddUpdateUIElementState(uistate.AggregateId, State.SelectedScene.AggregateId, uistate.Left, uistate.Top, _backgroundImageSize.Width, _backgroundImageSize.Height, uistate.Scale, true, null, null, false);
                        }


                        NumberFramesToRender = 3;
                    }
                }

                //TurnOnRenderingBecauseThereAreRenderableEffects();
            }
            catch (Exception ex) {
            }
        }
예제 #12
0
    // Update is called once per frame
    void Update()
    {
        switch (scrollerState)
        {
        case UIElementState.Active:
            if (!SlidingWindow.IsOpen())
            {
                UpdateInput();
            }
            break;

        case UIElementState.TransitionOut:
            scrollValue += 0.1f * (idleValue - scrollValue);
            if (Mathf.Abs(idleValue - scrollValue) < 0.01f)
            {
                ForceIdle();
            }
            break;

        case UIElementState.TransitionIn:
            scrollValue -= 0.1f * scrollValue;
            if (Mathf.Abs(scrollValue) < 0.01f)
            {
                scrollerState = UIElementState.Active;
            }
            break;

        default:
            break;
        }


        for (int i = 0; i < scrollableItems.Count; i++)
        {
            float angle = scrollValue - i * step;
            float x     = radius * Mathf.Sin(angle);
            float y     = radius * Mathf.Cos(angle);
            cvs[i].alpha = (y - (1 - alpharange) * radius) / (alpharange * radius);
            scrollableItems[i].localPosition           = new Vector3(0, x, y);
            scrollableItems[i].transform.localRotation = Quaternion.Euler(Mathf.Sign(x) * cvs[i].alpha * angleShift, 0, 180);//Quaternion.AngleAxis( Mathf.Sign(x)*cvs[i].alpha*angleShift,Vector3.right);
        }
    }
예제 #13
0
        private void CalculateState()
        {
            if (m_Disabled)
            {
                m_State = UIElementState.Disabled;
                return;
            }

            m_State = UIElementState.Normal;
            switch (m_CurrentFrame)
            {
            case 1:
                m_State = UIElementState.Selected;
                break;

            case 2:
                m_State = UIElementState.Highlighted;
                break;
            }
        }
예제 #14
0
        private void SetActiveState(UIElementState newState)
        {
            if (newState == UIElementState.Pressed && _activeState != UIElementState.Pressed)
            {
                OnRaiseUIElementPressedEvent(new UIElementPressedEventArgs(this, _command));
            }
            else if (newState != UIElementState.Pressed && _activeState == UIElementState.Pressed)
            {
                OnRaiseUIElementReleasedEvent(new UIElementReleasedEventArgs(this, _command));
            }

            _activeState = newState;

            if (_spriteMap.Keys.Contains(newState))
            {
                _activeSprite = _spriteMap[newState];
            }
            else
            {
                _activeSprite = _spriteMap[UIElementState.None];
            }
        }
예제 #15
0
        public async void PushToCloud(UIElementState uiElementState)
        {
            if (!AppService.IsConnected())
            {
                return;
            }

            try
            {
                if (uiElementState.MSId != 0)
                {
                    int id = uiElementState.Id;
                    uiElementState.Id   = uiElementState.MSId;
                    uiElementState.MSId = id;
                    await mstUIElementState.UpdateAsync(uiElementState);

                    uiElementState.Id = id;
                }
                else
                {
                    uiElementState.Id = 0;
                    await mstUIElementState.InsertAsync(uiElementState);

                    AppDatabase.Current.UpdateSolutionField(uiElementState.AggregateId, "MSId", uiElementState.Id, false);
                }

                Messenger.Default.Send <GeneralSystemWideMessage>(new GeneralSystemWideMessage("writing ...")
                {
                    Identifier = "CLOUD BAR", SourceId = "AzureMobileService", Action = "WRITE"
                });
            }
            catch {
                Messenger.Default.Send <GeneralSystemWideMessage>(new GeneralSystemWideMessage("writing ...")
                {
                    Identifier = "CLOUD BAR", SourceId = "AzureMobileService", Action = "ERROR"
                });
            }
        }
예제 #16
0
        private void DoAggregateUpdatedForImage(UIElementState uistate, bool resetTransforms = true)
        {
            //we only care about images that are the root parent, effects that are children are handled in the Effect class
            RenderDTO found = _renderTree.Where(
                x => x.Type == eRenderType.Effect &&
                x.EffectDTO.AggregateId == uistate.AggregateId &&
                string.IsNullOrEmpty(x.EffectDTO.Grouping1)
                ).FirstOrDefault();

            if (found != null)
            {
                found.EffectDTO.IsRenderable    = uistate.IsRenderable;
                found.EffectDTO.MainTranslation = new Vector3((float)uistate.Left, (float)uistate.Top, (float)0);
                found.EffectDTO.MainScale       = new Vector3((float)uistate.Scale, (float)uistate.Scale, 0);


                //update linked effects (parent got changed so update the children where applicable)
                if (found.HasLinkedEffects)
                {
                    var linkedRenderTreeItems = _renderTree.Where(x => x.Type == eRenderType.Effect && x.EffectDTO.Grouping1 == uistate.AggregateId);
                    foreach (var linkedRenderTreeItem in linkedRenderTreeItems)
                    {
                        linkedRenderTreeItem.EffectDTO.MainScale       = found.EffectDTO.MainScale;
                        linkedRenderTreeItem.EffectDTO.MainTranslation = found.EffectDTO.MainTranslation;
                        //linkedRenderTreeItem.EffectDTO.IsRenderable = found.EffectDTO.IsRenderable;
                    }
                }

                //udfBool1 is used to trigger an update of the image
                if (!string.IsNullOrEmpty(uistate.udfString1) && uistate.udfBool1)
                {
                    var layoutDetail = AppDatabase.Current.GetLayoutDetail(uistate.LayoutStyle);
                    UpdateImageByUri(uistate, layoutDetail, resetTransforms);
                }
            }
        }
예제 #17
0
    public void Open(string window = null)
    {
        if (!inialized)
        {
            Start();
        }
        CanvasManager.instance.DisableButtons();
        gameObject.SetActive(true);
        timer                   = 0;
        managerState            = UIElementState.TransitionIn;
        transform.localPosition = Vector3.Lerp(Vector3.zero, originalPos, timer);
        transform.localScale    = Vector3.Lerp(Vector3.zero, originalScale, timer);
        if (window != null)
        {
            SwitchTab(FindTabIndex(window + "Tab"));
        }
        for (int i = 0; i < tabsButtons.Length; i++)
        {
            tabsButtons[i].transform.localRotation = Quaternion.Euler(-60 * i, 0, 0);
        }

        ToggleHitBox(false);
        TrackingManager.instance.ToggleArrows(true);
    }
        private async Task <bool> UpdateRenderItemWithUIElement_Effect(UIElementState uies, RenderDTO renderItem)
        {
            if (_renderTree == null || _renderTree.Count == 0)
            {
                return(true);
            }

            UIElementState uiesParent = AppDatabase.Current.RetrieveUIElementState(renderItem.EffectDTO.Grouping1).First();

            string[] parts = uies.udfString1.Split("|".ToCharArray());


            //child got changed so re update from the parent where applicable
            renderItem.EffectDTO.IsRenderable = uies.IsRenderable;

            renderItem.EffectDTO.MainTranslation = new Vector3(
                (float)uiesParent.Left,
                (float)uiesParent.Top,
                (float)0);

            renderItem.EffectDTO.MainScale = new Vector3(
                (float)uiesParent.Scale,
                (float)uiesParent.Scale,
                0);

            if (string.IsNullOrEmpty(uies.Grouping2))
            {
                if (renderItem.EffectDTO.Effect != null)
                {
                    RenderDTO renderItemParent = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping1).First();
                    renderItem.EffectDTO.Effect.SetInputEffect(0, renderItemParent.EffectDTO.Effect, true);
                }
            }
            else
            {
                if (renderItem.EffectDTO.Effect != null)
                {
                    RenderDTO renderItemParent = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2).First();
                    renderItem.EffectDTO.Effect.SetInputEffect(0, renderItemParent.EffectDTO.Effect, true);
                }
            }

            //SharpDX.Direct2D1.Effects.Blend

            //now just update child based on new values from child UIElementState
            switch (parts[0])
            {
            case "SharpDX.Direct2D1.Effects.AffineTransform2D": break;

            case "SharpDX.Direct2D1.Effects.ArithmeticComposite": break;

            case "SharpDX.Direct2D1.Effects.Atlas": break;

            case "SharpDX.Direct2D1.Effects.BitmapSourceEffect":
                #region bitmap source
                var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId);

                ((SharpDX.Direct2D1.Effects.BitmapSource)renderItem.EffectDTO.Effect).SetValueByName("WicBitmapSource", asset.Item1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Blend": break;

            case "SharpDX.Direct2D1.Effects.Border": break;

            case "SharpDX.Direct2D1.Effects.Brightness":
                #region brightness
                ((SharpDX.Direct2D1.Effects.Brightness)renderItem.EffectDTO.Effect).WhitePoint = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ((SharpDX.Direct2D1.Effects.Brightness)renderItem.EffectDTO.Effect).BlackPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ColorManagement": break;

            case "SharpDX.Direct2D1.Effects.ColorMatrix": break;

            case "SharpDX.Direct2D1.Effects.Composite":
                #region composite
                if (!string.IsNullOrEmpty(uies.Grouping2) && !string.IsNullOrEmpty(uies.udfString2))
                {
                    //renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);

                    if (renderItem.EffectDTO.Effect == null)
                    {
                        renderItem.EffectDTO.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);
                    }
                    //else
                    //{
                    //    renderItem.EffectDTO.Effect.Dispose();
                    //    renderItem.EffectDTO.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);
                    //}

                    if (!string.IsNullOrEmpty(uies.Grouping2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2);
                        if (found != null && found.Count() > 0)
                        {
                            renderItem.EffectDTO.Effect.SetInputEffect(0, found.First().EffectDTO.Effect, true);
                        }
                    }

                    if (!string.IsNullOrEmpty(uies.udfString2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.udfString2);
                        if (found != null && found.Count() > 0)
                        {
                            renderItem.EffectDTO.Effect.SetInputEffect(1, found.First().EffectDTO.Effect, true);
                        }
                    }
                }
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ConvolveMatrix":
                #region convolve matrix
                if (!string.IsNullOrEmpty(uies.udfString2))     //matrix
                {
                    var matrixParts = uies.udfString2.Split("|".ToCharArray());
                    if (matrixParts.Length == 9)
                    {
                        float[] matrix = new float[9] {
                            float.Parse(matrixParts[0]),
                            float.Parse(matrixParts[1]),
                            float.Parse(matrixParts[2]),
                            float.Parse(matrixParts[3]),
                            float.Parse(matrixParts[4]),
                            float.Parse(matrixParts[5]),
                            float.Parse(matrixParts[6]),
                            float.Parse(matrixParts[7]),
                            float.Parse(matrixParts[8]),
                        };
                        ((SharpDX.Direct2D1.Effects.ConvolveMatrix)renderItem.EffectDTO.Effect).KernelMatrix = matrix;
                    }
                }

                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Crop":
                #region Crop
                ((SharpDX.Direct2D1.Effects.Crop)renderItem.EffectDTO.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DirectionalBlur":
                #region directional blur
                renderItem.EffectDTO.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                renderItem.EffectDTO.Effect.SetValueByName("Angle", (float)uies.udfDouble2);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DiscreteTransfer": break;

            case "SharpDX.Direct2D1.Effects.DisplacementMap": break;

            case "SharpDX.Direct2D1.Effects.DistantDiffuse": break;

            case "SharpDX.Direct2D1.Effects.DistantSpecular": break;

            case "SharpDX.Direct2D1.Effects.DpiCompensation": break;

            case "SharpDX.Direct2D1.Effects.Flood":
                #region flood
                ((SharpDX.Direct2D1.Effects.Flood)renderItem.EffectDTO.Effect).Color = new Color4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.GammaTransfer": break;

            case "SharpDX.Direct2D1.Effects.GaussianBlur":
                #region gaussian blur
                renderItem.EffectDTO.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Histogram": break;

            case "SharpDX.Direct2D1.Effects.HueRotate":
                #region hue rotate
                renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.LinearTransfer": break;

            case "SharpDX.Direct2D1.Effects.LuminanceToAlpha": break;

            case "SharpDX.Direct2D1.Effects.Morphology": break;

            case "SharpDX.Direct2D1.Effects.NamespaceDoc": break;

            case "SharpDX.Direct2D1.Effects.PointDiffuse": break;

            case "SharpDX.Direct2D1.Effects.PointSpecular": break;

            case "SharpDX.Direct2D1.Effects.Premultiply": break;

            case "SharpDX.Direct2D1.Effects.Saturation":
                #region saturation
                renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Scale":
                #region scale
                SharpDX.Direct2D1.Effects.Scale ef = (SharpDX.Direct2D1.Effects.Scale)renderItem.EffectDTO.Effect;
                ef.ScaleAmount = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ef.CenterPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Shadow":
                #region shadow
                renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.SpotDiffuse": break;

            case "SharpDX.Direct2D1.Effects.SpotSpecular": break;

            case "SharpDX.Direct2D1.Effects.TableTransfer": break;

            case "SharpDX.Direct2D1.Effects.Tile":
                #region tile
                ((SharpDX.Direct2D1.Effects.Tile)renderItem.EffectDTO.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Transform3D": break;

            case "SharpDX.Direct2D1.Effects.Turbulence": break;

            case "SharpDX.Direct2D1.Effects.UnPremultiply": break;
            }

            return(true);
        }
예제 #19
0
        private void initUIElementStates(RenderDrawContext context, RenderView renderView,
                                         RenderViewStage renderViewStage, ref UIElementState[] uiElementStates,
                                         int index, int storeIndex, GameTime drawTime, List <PointerEvent> events, ulong posecount)
        {
            var renderNodeReference = renderViewStage.SortedRenderNodes[index].RenderNode;
            var renderNode          = GetRenderNode(renderNodeReference);
            var renderElement       = (RenderUIElement)renderNode.RenderObject;

            var uiElementState = new UIElementState(renderElement);

            uiElementStates[storeIndex] = uiElementState;

            var renderObject = uiElementState.RenderObject;
            var rootElement  = renderObject.Page?.RootElement;

            if (rootElement != null)
            {
                UIBatch batch = getFreeBatch(context);

                var virtualResolution    = renderObject.Resolution;
                var updatableRootElement = (IUIElementUpdate)rootElement;

                // update the UI element disposition
                rootElement.Measure(virtualResolution);
                rootElement.Arrange(virtualResolution, false);

                // calculate an estimate of the UI real size by projecting the element virtual resolution on the screen
                var virtualOrigin            = uiElementState.WorldViewProjectionMatrix.Row4;
                var virtualWidth             = new Vector4(virtualResolution.X / 2, 0, 0, 1);
                var virtualHeight            = new Vector4(0, virtualResolution.Y / 2, 0, 1);
                var transformedVirtualWidth  = Vector4.Zero;
                var transformedVirtualHeight = Vector4.Zero;
                for (var i = 0; i < 4; i++)
                {
                    transformedVirtualWidth[i]  = virtualWidth[0] * uiElementState.WorldViewProjectionMatrix[0 + i] + uiElementState.WorldViewProjectionMatrix[12 + i];
                    transformedVirtualHeight[i] = virtualHeight[1] * uiElementState.WorldViewProjectionMatrix[4 + i] + uiElementState.WorldViewProjectionMatrix[12 + i];
                }

                var viewportSize           = context.CommandList.Viewport.Size;
                var projectedOrigin        = virtualOrigin.XY() / virtualOrigin.W;
                var projectedVirtualWidth  = viewportSize * (transformedVirtualWidth.XY() / transformedVirtualWidth.W - projectedOrigin);
                var projectedVirtualHeight = viewportSize * (transformedVirtualHeight.XY() / transformedVirtualHeight.W - projectedOrigin);

                // Set default services
                rootElement.UIElementServices = new UIElementServices {
                    Services = RenderSystem.Services
                };

                // perform the time-based updates of the UI element
                updatableRootElement.Update(drawTime);

                // update the UI element hierarchical properties
                var rootMatrix = Matrix.Translation(-virtualResolution / 2); // UI world is translated by a half resolution compared to its quad, which is centered around the origin
                updatableRootElement.UpdateWorldMatrix(ref rootMatrix, rootMatrix != uiElementState.RenderObject.LastRootMatrix);
                updatableRootElement.UpdateElementState(0);
                uiElementState.RenderObject.LastRootMatrix = rootMatrix;
                // set default resource dictionary

                // update layouting context.
                var layoutingContext = batch.layoutingContext as LayoutingContext;
                layoutingContext.VirtualResolution          = virtualResolution;
                layoutingContext.RealResolution             = viewportSize;
                layoutingContext.RealVirtualResolutionRatio = new Vector2(projectedVirtualWidth.Length() / virtualResolution.X, projectedVirtualHeight.Length() / virtualResolution.Y);
                rootElement.LayoutingContext = layoutingContext;

                if (renderObject.IsFullScreen)
                {
                    //var targetSize = viewportSize;
                    var targetSize = new Vector2(context.CommandList.RenderTargets[0].Width, context.CommandList.RenderTargets[0].Height);

                    // update the virtual resolution of the renderer
                    switch (renderObject.ResolutionStretch)
                    {
                    case ResolutionStretch.FixedWidthAdaptableHeight:
                        virtualResolution.Y = virtualResolution.X * targetSize.Y / targetSize.X;
                        break;

                    case ResolutionStretch.FixedHeightAdaptableWidth:
                        virtualResolution.X = virtualResolution.Y * targetSize.X / targetSize.Y;
                        break;

                    case ResolutionStretch.AutoFit:
                        float aspect     = targetSize.X / targetSize.Y;
                        float virtAspect = virtualResolution.X / virtualResolution.Y;
                        if (aspect >= virtAspect)
                        {
                            goto case ResolutionStretch.FixedHeightAdaptableWidth;
                        }
                        goto case ResolutionStretch.FixedWidthAdaptableHeight;

                    case ResolutionStretch.AutoShrink:
                        if (targetSize.X < virtualResolution.X ||
                            targetSize.Y < virtualResolution.Y)
                        {
                            goto case ResolutionStretch.AutoFit;
                        }
                        else
                        {
                            virtualResolution.X = targetSize.X * targetSize.X / virtualResolution.X;
                            virtualResolution.Y = targetSize.Y * targetSize.Y / virtualResolution.Y;
                        }
                        break;
                    }

                    uiElementState.Update(renderObject, virtualResolution);
                }
                else
                {
                    CameraComponent cameraComponent = renderView.Camera as CameraComponent;
                    if (cameraComponent != null)
                    {
                        uiElementState.Update(renderObject, cameraComponent.VerticalFieldOfView,
                                              ref renderView.View, ref renderView.Projection);
                    }
                }

                if (renderObject.Source is UIComponent uic)
                {
                    uic.RenderedResolution = virtualResolution;
                    if (posecount == 0 || posecount != uic.VRPoseUpdate)
                    {
                        PickingUpdate(uiElementState.RenderObject, context.CommandList.Viewport, ref uiElementState.WorldViewProjectionMatrix, drawTime, events);
                        uic.VRPoseUpdate = posecount;
                    }
                }

                ReturnBatch(batch);
            }
        }
예제 #20
0
        private void DrawInternal(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, int startIndex, int endIndex)
        {
            base.Draw(context, renderView, renderViewStage, startIndex, endIndex);

            var uiProcessor = SceneInstance.GetCurrent(context.RenderContext).GetProcessor <UIRenderProcessor>();

            if (uiProcessor == null)
            {
                return;
            }

            // evaluate the current draw time (game instance is null for thumbnails)
            var drawTime = game != null ? game.DrawTime : new GameTime();

            // Prepare content required for Picking and MouseOver events
            var events = new List <PointerEvent>();

            PickingPrepare(events);

            ulong poseCount = VirtualReality.VRDeviceSystem.GetSystem?.Device?.PoseCount ?? 0;

            // build the list of the UI elements to render
            UIElementState[] uiElementStates = new UIElementState[endIndex - startIndex];
            if (uiElementStates.Length > 1 && GraphicsDevice.Platform == GraphicsPlatform.Vulkan)
            {
                Xenko.Core.Threading.Dispatcher.For(startIndex, endIndex, (index) =>
                {
                    initUIElementStates(context, renderView, renderViewStage, ref uiElementStates, index, index - startIndex, drawTime, events, poseCount);
                });
            }
            else
            {
                for (int i = startIndex; i < endIndex; i++)
                {
                    initUIElementStates(context, renderView, renderViewStage, ref uiElementStates, i, i - startIndex, drawTime, events, poseCount);
                }
            }

            events?.Clear();

            lock (drawLocker)
            {
                UIBatch batch = getFreeBatch(context);

                var renderingContext = batch.renderingContext as UIRenderingContext;

                // update the rendering context
                renderingContext.GraphicsContext = context.GraphicsContext;
                renderingContext.Time            = drawTime;

                DepthStencilStateDescription stencilState = uiSystem.KeepStencilValueState;

                // actually draw stuff
                for (int j = 0; j < uiElementStates.Length; j++)
                {
                    var uiElementState = uiElementStates[j];

                    renderingContext.RenderObject = uiElementState.RenderObject;
                    var rootElement = renderingContext.RenderObject.Page?.RootElement;
                    if (rootElement == null || rootElement.IsVisible == false)
                    {
                        continue;
                    }

                    // update the rendering context values specific to this element
                    renderingContext.ViewProjectionMatrix = uiElementState.WorldViewProjectionMatrix;

                    switch (renderingContext.RenderObject.depthMode)
                    {
                    case Sprites.RenderSprite.SpriteDepthMode.Ignore:
                        stencilState.DepthBufferWriteEnable = false;
                        stencilState.DepthBufferEnable      = false;
                        break;

                    case Sprites.RenderSprite.SpriteDepthMode.ReadOnly:
                        stencilState.DepthBufferWriteEnable = false;
                        stencilState.DepthBufferEnable      = true;
                        break;

                    default:
                        stencilState.DepthBufferWriteEnable = true;
                        stencilState.DepthBufferEnable      = true;
                        break;

                    case Sprites.RenderSprite.SpriteDepthMode.WriteOnly:
                        stencilState.DepthBufferWriteEnable = true;
                        stencilState.DepthBufferEnable      = true;
                        stencilState.DepthBufferFunction    = CompareFunction.Always;
                        break;
                    }

                    SamplerState samplerState;
                    switch (renderingContext.RenderObject.Sampler)
                    {
                    default:
                        samplerState = context.GraphicsDevice.SamplerStates.LinearClamp;
                        break;

                    case UIElementSampler.PointClamp:
                        samplerState = context.GraphicsDevice.SamplerStates.PointClamp;
                        break;

                    case UIElementSampler.AnisotropicClamp:
                        samplerState = context.GraphicsDevice.SamplerStates.AnisotropicClamp;
                        break;
                    }

                    // start the image draw session
                    renderingContext.StencilTestReferenceValue = 0;
                    batch.Begin(context.GraphicsContext, ref uiElementState.WorldViewProjectionMatrix, BlendStates.AlphaBlend, samplerState, null, stencilState, renderingContext.StencilTestReferenceValue);

                    // Render the UI elements in the final render target
                    RecursiveDrawWithClipping(context, rootElement, ref uiElementState.WorldViewProjectionMatrix, batch, ref stencilState, samplerState);

                    batch.End();
                }

                ReturnBatch(batch);
            }
        }
예제 #21
0
 public void ForceIdle()
 {
     scrollValue   = idleValue;
     scrollerState = UIElementState.Idle;
     this.gameObject.SetActive(false);
 }
예제 #22
0
 public Label(UIElementState state, Point position, string text, SpriteFont font, Color fontColor) : base(state, position)
 {
     Text      = text;
     Font      = font;
     FontColor = fontColor;
 }
예제 #23
0
        /// <summary>
        /// This utility will draw a line of text onto the UIElement.
        /// </summary>
        /// <param name="batch">The SpriteBatch to draw the text onto</param>
        /// <param name="text">The content of the text</param>
        /// <param name="to">The position of the text. Relative to this UIElement.</param>
        /// <param name="style">The text style</param>
        /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param>
        /// <param name="align">Alignment of the text within the bounds box.</param>
        /// <param name="margin">Margin offset from the bounding box.</param>
        /// <param name="state">State of the text, e.g. hover, down, normal</param>
        public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state)
        {
            //TODO: We should find some way to cache this data

            /**
             * Work out the scale of the vector font.
             *
             * We need to scale it based on the UIElement's scale factory,
             * but we also need to scale it based on the text styles scale factor.
             *
             * Aka if the vector font is 12px and we asked for 24px it would be scale of 2.0
             */
            var scale = _Scale;
            if (style.Scale != 1.0f)
            {
                scale = new Vector2(scale.X * style.Scale, scale.Y * style.Scale);
            }

            /** Work out how big the text will be so we can align it **/
            var textSize = style.SpriteFont.MeasureString(text);
            Vector2 size = textSize * style.Scale;

            /** Apply margins **/
            if (margin != Rectangle.Empty)
            {
                bounds.X += margin.X;
                bounds.Y += margin.Y;
                bounds.Width -= margin.Right;
                bounds.Height -= margin.Bottom;
            }

            /** Work out X and Y based on alignment & bounding box **/
            var pos = to;
            pos.X += bounds.X;
            pos.Y += bounds.Y;

            if ((align & TextAlignment.Right) == TextAlignment.Right)
            {
                pos.X += (bounds.Width - size.X);
            }
            else if ((align & TextAlignment.Center) == TextAlignment.Center)
            {
                pos.X += (bounds.Width - size.X) / 2;
            }

            if ((align & TextAlignment.Middle) == TextAlignment.Middle)
            {
                pos.Y += (bounds.Height - size.Y) / 2;
            }
            else if ((align & TextAlignment.Bottom) == TextAlignment.Bottom)
            {
                pos.Y += (bounds.Height - size.Y);
            }
            //pos.Y += (((style.Size + 5) * style.Scale) * style.Font.BaselineOffset);
            pos.X = (float)Math.Floor(pos.X);
            pos.Y = (float)Math.Floor(pos.Y);

            //DrawLocalTexture(batch, TextureUtils.TextureFromColor(batch.GraphicsDevice, Color.Red), null, pos, size);

            pos.Y += style.BaselineOffset;

            /** Draw the string **/
            pos = LocalPoint(pos);
            batch.DrawString(style.SpriteFont, text, pos, style.GetColor(state), 0, Vector2.Zero, scale, SpriteEffects.None, 0);
        }
예제 #24
0
 public InteractableUIElement(UIElementState state, Point position) : base(state, position)
 {
 }
예제 #25
0
        private async Task <RenderDTO> AddUpdateUIElementState_Path(UIElementState uistate, RenderDTO rDto)
        {
            if (rDto == null)
            {
                ShapePathDTO dto = new ShapePathDTO();
                dto.AggregateId = uistate.AggregateId;

                rDto = new RenderDTO()
                {
                    ShapePathDTO = dto, Type = eRenderType.ShapePath, Order = _renderTree.Count() + 1
                };

                rDto.ShapePathDTO.ShapeDatas.Add("M6.33675,26.318 L32.1257,26.318 C32.1257,26.318 44.2178,18.6175 32.1257,10.8489 C32.1257,10.8489 31.7393,1.25822 23.4461,0.582515 C23.4461,0.582515 16.6888,-0.631889 13.9267,6.25699 C13.9267,6.25699 11.8669,4.43488 8.52113,5.78424 C8.52113,5.78424 6.01503,6.73083 5.88855,10.6481 C5.88855,10.6481 0.609425,11.1868 0.547688,17.8748 C0.547688,17.8748 -0.417516,25.1005 6.33675,26.318 z");
                rDto.ShapePathDTO.Shapes.Add(_pathD2DConverter.parse(dto.ShapeDatas[0], _deviceManager.FactoryDirect2D));

                _renderTree.Add(rDto);
            }



            //stroke stuff
            rDto.ShapePathDTO.StrokeWidth = (float)uistate.udfDouble3;
            if (!string.IsNullOrEmpty(uistate.udfString4))
            {
                var strokeParts = uistate.udfString4.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapePathDTO.DashOffset     = float.Parse(strokeParts[0]);
                    rDto.ShapePathDTO.MiterLimit     = float.Parse(strokeParts[1]);
                    rDto.ShapePathDTO.DashStyleIndex = int.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]);
                    if (rDto.ShapePathDTO.DashStyleIndex < 0)
                    {
                        rDto.ShapePathDTO.DashStyleIndex = 0;
                    }
                    if (rDto.ShapePathDTO.DashStyleIndex == 5)
                    {
                        rDto.ShapePathDTO.DashStyleIndex = 0;
                    }
                }
            }


            if (uistate.udfInt2 == 1)
            {
                var parts1 = uistate.udfString2.Split("|".ToCharArray());
                var parts2 = uistate.udfString3.Split("|".ToCharArray());

                Color4 colorToUse1;
                Color4 colorToUse2;
                try
                {
                    colorToUse1 = new Color4(
                        float.Parse(parts1[0]) / 255,
                        float.Parse(parts1[1]) / 255,
                        float.Parse(parts1[2]) / 255,
                        parts1.Length > 6 ? float.Parse(parts1[6]) / 255 : float.Parse(parts1[3]) / 255
                        );

                    colorToUse2 = new Color4(
                        float.Parse(parts2[0]) / 255,
                        float.Parse(parts2[1]) / 255,
                        float.Parse(parts2[2]) / 255,
                        parts2.Length > 6 ? float.Parse(parts2[6]) / 255 : float.Parse(parts2[3]) / 255
                        );
                }
                catch
                {
                    colorToUse1 = Color.Black;
                    colorToUse2 = Color.White;
                }

                rDto.ShapePathDTO.Brush = CreateRadialGradientBrush(_deviceManager.ContextDirect2D, (float)uistate.Width, (float)uistate.Height, colorToUse1, colorToUse2, (float)uistate.udfDouble1 / 100, (float)uistate.udfDouble2 / 100);
            }
            else
            {
                var parts = uistate.udfString2.Split("|".ToCharArray());

                Color4 colorToUse;
                try
                {
                    colorToUse = new Color4(
                        float.Parse(parts[0]) / 255,
                        float.Parse(parts[1]) / 255,
                        float.Parse(parts[2]) / 255,
                        parts.Length > 6 ? float.Parse(parts[6]) / 255 : float.Parse(parts[3]) / 255
                        );
                }
                catch
                {
                    colorToUse = Color.Black;
                }

                rDto.ShapePathDTO.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, colorToUse);
            }

            rDto.ShapePathDTO.IsRenderable    = true;
            rDto.ShapePathDTO.MainScale       = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.ShapePathDTO.MainTranslation = new Vector3((float)uistate.Left, (float)uistate.Top, 0);

            //ROTATION
            if (!string.IsNullOrEmpty(uistate.udfString5))
            {
                var strokeParts = uistate.udfString5.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapePathDTO.MainRotation = new Vector3(
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[0]) ? "0" : strokeParts[0])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[1]) ? "0" : strokeParts[1])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]))
                        );
                }
            }



            NumberFramesToRender = 3;

            //TurnOnRenderingBecauseThereAreRenderableEffects();


            return(rDto);
        }
예제 #26
0
        private async Task <RenderDTO> AddUpdateUIElementState_Rectangle(UIElementState uistate, RenderDTO rDto)
        {
            if (rDto == null)
            {
                ShapeDTO dto = new ShapeDTO();
                dto.AggregateId = uistate.AggregateId;

                rDto = new RenderDTO()
                {
                    ShapeDTO = dto, Type = eRenderType.Shape, Order = _renderTree.Count() + 1
                };

                _renderTree.Add(rDto);
            }



            switch (uistate.udfString1)
            {
            case "Rectangle":
                RectangleF newGeometry1 = new RectangleF(0, 0, (float)uistate.Width, (float)uistate.Height);
                rDto.ShapeDTO.Shape = new SharpDX.Direct2D1.RectangleGeometry(_deviceManager.FactoryDirect2D, newGeometry1);
                rDto.ShapeDTO.Type  = uistate.udfInt1;
                break;

            case "Ellipse":
                SharpDX.Direct2D1.Ellipse newGeometry2 = new SharpDX.Direct2D1.Ellipse(
                    new Vector2(((float)uistate.Width / 2), ((float)uistate.Height / 2)),
                    (float)uistate.Width,
                    (float)uistate.Height
                    );
                rDto.ShapeDTO.Shape = new SharpDX.Direct2D1.EllipseGeometry(_deviceManager.FactoryDirect2D, newGeometry2);
                rDto.ShapeDTO.Type  = uistate.udfInt1;
                break;
            }



            //stroke stuff
            rDto.ShapeDTO.StrokeWidth = (float)uistate.udfDouble3;
            if (!string.IsNullOrEmpty(uistate.udfString4))
            {
                var strokeParts = uistate.udfString4.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapeDTO.DashOffset     = float.Parse(strokeParts[0]);
                    rDto.ShapeDTO.MiterLimit     = float.Parse(strokeParts[1]);
                    rDto.ShapeDTO.DashStyleIndex = int.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]);
                    if (rDto.ShapeDTO.DashStyleIndex < 0)
                    {
                        rDto.ShapeDTO.DashStyleIndex = 0;
                    }
                    if (rDto.ShapeDTO.DashStyleIndex == 5)
                    {
                        rDto.ShapeDTO.DashStyleIndex = 0;
                    }
                }
            }



            if (uistate.udfInt2 == 1)
            {
                var parts1 = uistate.udfString2.Split("|".ToCharArray());
                var parts2 = uistate.udfString3.Split("|".ToCharArray());

                Color4 colorToUse1;
                Color4 colorToUse2;
                try
                {
                    colorToUse1 = new Color4(
                        float.Parse(parts1[0]) / 255,
                        float.Parse(parts1[1]) / 255,
                        float.Parse(parts1[2]) / 255,
                        parts1.Length > 6 ? float.Parse(parts1[6]) / 255 : float.Parse(parts1[3]) / 255
                        );

                    colorToUse2 = new Color4(
                        float.Parse(parts2[0]) / 255,
                        float.Parse(parts2[1]) / 255,
                        float.Parse(parts2[2]) / 255,
                        parts2.Length > 6 ? float.Parse(parts2[6]) / 255 : float.Parse(parts2[3]) / 255
                        );
                }
                catch
                {
                    colorToUse1 = Color.Black;
                    colorToUse2 = Color.White;
                }

                rDto.ShapeDTO.Brush = CreateRadialGradientBrush(_deviceManager.ContextDirect2D, (float)uistate.Width, (float)uistate.Height, colorToUse1, colorToUse2, (float)uistate.udfDouble1 / 100, (float)uistate.udfDouble2 / 100);
            }
            else
            {
                var parts = uistate.udfString2.Split("|".ToCharArray());

                Color4 colorToUse;
                try
                {
                    colorToUse = new Color4(
                        float.Parse(parts[0]) / 255,
                        float.Parse(parts[1]) / 255,
                        float.Parse(parts[2]) / 255,
                        parts.Length > 6 ? float.Parse(parts[6]) / 255 : float.Parse(parts[3]) / 255
                        );
                }
                catch
                {
                    colorToUse = Color.Black;
                }

                rDto.ShapeDTO.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, colorToUse);
            }



            rDto.ShapeDTO.IsRenderable    = uistate.IsRenderable; //true
            rDto.ShapeDTO.MainScale       = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.ShapeDTO.MainTranslation = new Vector3((float)uistate.Left, (float)uistate.Top, 0);



            //ROTATION
            if (!string.IsNullOrEmpty(uistate.udfString5))
            {
                var strokeParts = uistate.udfString5.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapeDTO.MainRotation = new Vector3(
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[0]) ? "0" : strokeParts[0])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[1]) ? "0" : strokeParts[1])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]))
                        );
                }
            }



            if (NumberFramesToRender < 1)
            {
                NumberFramesToRender = 1;
            }

            //TurnOnRenderingBecauseThereAreRenderableEffects();

            return(rDto);
        }
예제 #27
0
        private void SetActiveState(UIElementState newState)
        {
            if (newState == UIElementState.Pressed && _activeState != UIElementState.Pressed)
            {
                OnRaiseUIElementPressedEvent(new UIElementPressedEventArgs(this, _command));
            }
            else if (newState != UIElementState.Pressed && _activeState == UIElementState.Pressed)
            {
                OnRaiseUIElementReleasedEvent(new UIElementReleasedEventArgs(this, _command));
            }

            _activeState = newState;

            if (_spriteMap.Keys.Contains(newState))
                _activeSprite = _spriteMap[newState];
            else
                _activeSprite = _spriteMap[UIElementState.None];
        }
예제 #28
0
 private void AddStateRect(UIElementState state, int x, int y, int w, int h)
 {
     staterects[(int)state] = new Rectangle(x, y, w, h);
 }
        private async Task <RenderDTO> CreateRenderItemWithUIElement_Effect(UIElementState uies, string effectClass, RenderDTO parentRenderTreeItem)
        {
            EffectDTO edto = new EffectDTO();

            edto.IsRenderable = uies.IsRenderable;
            edto.AggregateId  = uies.AggregateId;
            edto.Grouping1    = uies.Grouping1;
            if (parentRenderTreeItem != null)
            {
                edto.MainTranslation = parentRenderTreeItem.EffectDTO.MainTranslation;
                edto.MainScale       = parentRenderTreeItem.EffectDTO.MainScale;
            }
            else
            {
                edto.MainTranslation = new Vector3(0);
                edto.MainScale       = new Vector3(1);
            }

            switch (effectClass)
            {
            case "SharpDX.Direct2D1.Effects.AffineTransform2D": break;

            case "SharpDX.Direct2D1.Effects.ArithmeticComposite": break;

            case "SharpDX.Direct2D1.Effects.Atlas": break;

            case "SharpDX.Direct2D1.Effects.BitmapSourceEffect":
                #region bitmap source

                try
                {
                    if (uies.udfString2 == "PicturesLibrary")
                    {
                        var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId, path : "PicturesLibrary");

                        edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                        edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                        uies.Width  = asset.Item2.Width;
                        uies.Height = asset.Item2.Height;
                    }
                    else if (uies.udfString2 == "PublicPicturesLibrary")
                    {
                        var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId, path : "PublicPicturesLibrary");

                        edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                        edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                        uies.Width  = asset.Item2.Width;
                        uies.Height = asset.Item2.Height;
                    }
                    else
                    {
                        var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId);

                        edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                        edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                        uies.Width  = asset.Item2.Width;
                        uies.Height = asset.Item2.Height;
                    }
                }
                catch {
                    var asset = LoadAssetAsync(_deviceManager.WICFactory, "Assets\\StartDemo\\Backgrounds\\green1.jpg", uies.AggregateId);

                    edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                    edto.Effect.SetValueByName("WicBitmapSource", asset.Result.Item1);
                    uies.Width  = asset.Result.Item2.Width;
                    uies.Height = asset.Result.Item2.Height;
                }


                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Blend": break;

            case "SharpDX.Direct2D1.Effects.Border": break;

            case "SharpDX.Direct2D1.Effects.Brightness":
                #region brightness
                edto.Effect = new SharpDX.Direct2D1.Effects.Brightness(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Brightness)edto.Effect).WhitePoint = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ((SharpDX.Direct2D1.Effects.Brightness)edto.Effect).BlackPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);

                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ColorManagement": break;

            case "SharpDX.Direct2D1.Effects.ColorMatrix": break;

            case "SharpDX.Direct2D1.Effects.Composite":
                #region composite
                if (!string.IsNullOrEmpty(uies.Grouping2) && !string.IsNullOrEmpty(uies.udfString2))
                {
                    edto.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);

                    if (!string.IsNullOrEmpty(uies.Grouping2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2);
                        if (found != null && found.Count() > 0)
                        {
                            edto.Effect.SetInputEffect(0, found.First().EffectDTO.Effect, true);
                        }
                        else
                        {
                            edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                        }
                    }
                    else
                    {
                        edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                    }

                    if (!string.IsNullOrEmpty(uies.udfString2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.udfString2);
                        if (found != null && found.Count() > 0)
                        {
                            edto.Effect.SetInputEffect(1, found.First().EffectDTO.Effect, true);
                        }
                        else
                        {
                            edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                        }
                    }
                    else
                    {
                        edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                    }
                }
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ConvolveMatrix":
                #region convolve matrix

                edto.Effect = new SharpDX.Direct2D1.Effects.ConvolveMatrix(_deviceManager.ContextDirect2D);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);

                if (!string.IsNullOrEmpty(uies.udfString2))     //matrix
                {
                    var parts = uies.udfString2.Split("|".ToCharArray());
                    if (parts.Length == 9)
                    {
                        float[] matrix = new float[9] {
                            float.Parse(parts[0]),
                            float.Parse(parts[1]),
                            float.Parse(parts[2]),
                            float.Parse(parts[3]),
                            float.Parse(parts[4]),
                            float.Parse(parts[5]),
                            float.Parse(parts[6]),
                            float.Parse(parts[7]),
                            float.Parse(parts[8]),
                        };
                        ((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = matrix;
                    }
                    //edto.Effect.SetInput(0, parentRenderTreeItem.EffectDTO.Effect.Output, true);
                    //var kernelmatrix = new float[9] { 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f };
                    //((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = kernelmatrix;
                }
                else
                {
                    ((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = new float[9] {
                        0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f
                    };
                }


                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Crop":
                #region crop
                edto.Effect = new SharpDX.Direct2D1.Effects.Crop(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Crop)edto.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DirectionalBlur":
                #region directional blur
                edto.Effect = new SharpDX.Direct2D1.Effects.DirectionalBlur(_deviceManager.ContextDirect2D);
                edto.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                edto.Effect.SetValueByName("Angle", (float)uies.udfDouble2);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DiscreteTransfer": break;

            case "SharpDX.Direct2D1.Effects.DisplacementMap": break;

            case "SharpDX.Direct2D1.Effects.DistantDiffuse": break;

            case "SharpDX.Direct2D1.Effects.DistantSpecular": break;

            case "SharpDX.Direct2D1.Effects.DpiCompensation": break;

            case "SharpDX.Direct2D1.Effects.Flood":
                #region flood
                edto.Effect = new SharpDX.Direct2D1.Effects.Flood(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Flood)edto.Effect).Color = new Color4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.GammaTransfer": break;

            case "SharpDX.Direct2D1.Effects.GaussianBlur":
                #region gaussian blur
                edto.Effect = new SharpDX.Direct2D1.Effects.GaussianBlur(_deviceManager.ContextDirect2D);
                edto.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Histogram": break;

            case "SharpDX.Direct2D1.Effects.HueRotate":
                #region hue rotate
                edto.Effect = new SharpDX.Direct2D1.Effects.HueRotation(_deviceManager.ContextDirect2D);
                edto.Effect.SetValue(0, (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.LinearTransfer": break;

            case "SharpDX.Direct2D1.Effects.LuminanceToAlpha": break;

            case "SharpDX.Direct2D1.Effects.Morphology": break;

            case "SharpDX.Direct2D1.Effects.NamespaceDoc": break;

            case "SharpDX.Direct2D1.Effects.PointDiffuse": break;

            case "SharpDX.Direct2D1.Effects.PointSpecular": break;

            case "SharpDX.Direct2D1.Effects.Premultiply": break;

            case "SharpDX.Direct2D1.Effects.Saturation":
                #region saturation
                edto.Effect = new SharpDX.Direct2D1.Effects.Saturation(_deviceManager.ContextDirect2D);
                edto.Effect.SetValue(0, (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Scale":
                #region scale

                SharpDX.Direct2D1.Effects.Scale ef = new SharpDX.Direct2D1.Effects.Scale(_deviceManager.ContextDirect2D);
                ef.BorderMode  = SharpDX.Direct2D1.BorderMode.Soft;
                ef.Cached      = false;
                ef.ScaleAmount = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ef.CenterPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect    = ef;

                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Shadow":
                #region shadow
                edto.Effect = new SharpDX.Direct2D1.Effects.Shadow(_deviceManager.ContextDirect2D);
                edto.Effect.SetValue(0, (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.SpotDiffuse": break;

            case "SharpDX.Direct2D1.Effects.SpotSpecular": break;

            case "SharpDX.Direct2D1.Effects.TableTransfer": break;

            case "SharpDX.Direct2D1.Effects.Tile":
                #region tile
                edto.Effect = new SharpDX.Direct2D1.Effects.Tile(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Tile)edto.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Transform3D": break;

            case "SharpDX.Direct2D1.Effects.Turbulence": break;

            case "SharpDX.Direct2D1.Effects.UnPremultiply": break;
            }


            RenderDTO _newRenderDto;

            if (parentRenderTreeItem != null)
            {
                _newRenderDto = new RenderDTO()
                {
                    EffectDTO = edto, Type = eRenderType.Effect, Order = parentRenderTreeItem.Order
                }
            }
            ;
            else
            {
                _newRenderDto = new RenderDTO()
                {
                    EffectDTO = edto, Type = eRenderType.Effect, Order = 1
                }
            };

            _renderTree.Add(_newRenderDto);

            return(_newRenderDto);
        }
예제 #30
0
        /// <summary>
        /// This utility will draw a line of text onto the UIElement.
        /// </summary>
        /// <param name="batch">The SpriteBatch to draw the text onto</param>
        /// <param name="text">The content of the text</param>
        /// <param name="to">The position of the text. Relative to this UIElement.</param>
        /// <param name="style">The text style</param>
        /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param>
        /// <param name="align">Alignment of the text within the bounds box.</param>
        /// <param name="margin">Margin offset from the bounding box.</param>
        /// <param name="state">State of the text, e.g. hover, down, normal</param>
        public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state)
        {
            //TODO: We should find some way to cache this data

            /**
             * Work out the scale of the vector font.
             *
             * We need to scale it based on the UIElement's scale factory,
             * but we also need to scale it based on the text styles scale factor.
             *
             * Aka if the vector font is 12px and we asked for 24px it would be scale of 2.0
             */
            var scale = _Scale;

            if (style.Scale != 1.0f)
            {
                scale = new Vector2(scale.X * style.Scale, scale.Y * style.Scale);
            }

            /** Work out how big the text will be so we can align it **/
            var     textSize = style.SpriteFont.MeasureString(text);
            Vector2 size     = textSize * style.Scale;

            /** Apply margins **/
            if (margin != Rectangle.Empty)
            {
                bounds.X      += margin.X;
                bounds.Y      += margin.Y;
                bounds.Width  -= margin.Right;
                bounds.Height -= margin.Bottom;
            }

            /** Work out X and Y based on alignment & bounding box **/
            var pos = to;

            pos.X += bounds.X;
            pos.Y += bounds.Y;

            if ((align & TextAlignment.Right) == TextAlignment.Right)
            {
                pos.X += (bounds.Width - size.X);
            }
            else if ((align & TextAlignment.Center) == TextAlignment.Center)
            {
                pos.X += (bounds.Width - size.X) / 2;
            }

            if ((align & TextAlignment.Middle) == TextAlignment.Middle)
            {
                pos.Y += (bounds.Height - size.Y) / 2;
            }
            else if ((align & TextAlignment.Bottom) == TextAlignment.Bottom)
            {
                pos.Y += (bounds.Height - size.Y);
            }

            pos.X = (float)Math.Floor(pos.X);
            pos.Y = (float)Math.Floor(pos.Y);

            pos.Y += style.BaselineOffset;

            /** Draw the string **/
            pos = LocalPoint(pos);
            batch.DrawString(style.SpriteFont, text, pos, style.GetColor(state), 0, Vector2.Zero, scale, SpriteEffects.None, 0);
        }
예제 #31
0
 public UIElement(UIElementState state, Point position)
 {
     State    = state;
     Position = position;
 }
예제 #32
0
        /// <summary>
        /// This utility will draw a line of text onto the UIElement.
        /// </summary>
        /// <param name="batch">The SpriteBatch to draw the text onto</param>
        /// <param name="text">The content of the text</param>
        /// <param name="to">The position of the text. Relative to this UIElement.</param>
        /// <param name="style">The text style</param>
        /// <param name="bounds">Rectangle relative to this UIElement which the text should be positioned within</param>
        /// <param name="align">Alignment of the text within the bounds box.</param>
        /// <param name="margin">Margin offset from the bounding box.</param>
        /// <param name="state">State of the text, e.g. hover, down, normal</param>
        public void DrawLocalString(SpriteBatch batch, string text, Vector2 to, TextStyle style, Rectangle bounds, TextAlignment align, Rectangle margin, UIElementState state)
        {
            //TODO: We should find some way to cache this data

            /**
             * Work out the scale of the vector font.
             *
             * We need to scale it based on the UIElement's scale factory,
             * but we also need to scale it based on the text styles scale factor.
             *
             * Aka if the vector font is 12px and we asked for 24px it would be scale of 2.0
             */
            var scale = _Scale;

            if (style.Scale != 1.0f)
            {
                scale = new Vector2(scale.X * style.Scale, scale.Y * style.Scale);
            }

            /** Work out how big the text will be so we can align it **/
            var size = (align == 0) ? Vector2.Zero : style.MeasureString(text);

            /** Apply margins **/
            if (margin != Rectangle.Empty)
            {
                bounds.X      += margin.X;
                bounds.Y      += margin.Y;
                bounds.Width  -= margin.Right;
                bounds.Height -= margin.Bottom;
            }

            /** Work out X and Y based on alignment & bounding box **/
            var pos = to;

            pos.X += bounds.X;
            pos.Y += bounds.Y;

            if ((align & TextAlignment.Right) == TextAlignment.Right)
            {
                pos.X += (bounds.Width - size.X);
            }
            else if ((align & TextAlignment.Center) == TextAlignment.Center)
            {
                pos.X += (bounds.Width - size.X) / 2;
            }

            if ((align & TextAlignment.Middle) == TextAlignment.Middle)
            {
                pos.Y += (bounds.Height - size.Y) / 2;
            }
            else if ((align & TextAlignment.Bottom) == TextAlignment.Bottom)
            {
                pos.Y += (bounds.Height - size.Y);
            }

            //pos.Y += style.BaselineOffset;

            /** Draw the string **/
            pos = FlooredLocalPoint(pos);

            if (style.VFont != null)
            {
                batch.End();
                Matrix?mat = null;
                var    ui  = (batch as UISpriteBatch);
                if (ui != null && ui.BatchMatrixStack.Count > 0)
                {
                    mat = ui.BatchMatrixStack.Peek();
                }

                if (style.Shadow)
                {
                    style.VFont.Draw(batch.GraphicsDevice, text, pos + new Vector2(FSOEnvironment.DPIScaleFactor), Color.Black, scale, mat);
                }
                style.VFont.Draw(batch.GraphicsDevice, text, pos, style.GetColor(state) * Opacity, scale, mat);

                if (mat != null)
                {
                    batch.Begin(transformMatrix: mat, rasterizerState: RasterizerState.CullNone);
                }
                else
                {
                    batch.Begin(rasterizerState: RasterizerState.CullNone);
                }
            }
            else
            {
                if (style.Shadow)
                {
                    batch.DrawString(style.SpriteFont, text, pos + new Vector2(FSOEnvironment.DPIScaleFactor), Color.Black, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
                }
                batch.DrawString(style.SpriteFont, text, pos, style.GetColor(state) * Opacity, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
            }
        }
예제 #33
0
        private void CalculateState()
        {
            if (m_Disabled) {
                m_State = UIElementState.Disabled;
                return;
            }

            m_State = UIElementState.Normal;
            switch(m_CurrentFrame){
                case 1:
                    m_State = UIElementState.Selected;
                    break;

                case 2:
                    m_State = UIElementState.Highlighted;
                    break;
            }
        }
예제 #34
0
        public Color GetColor(UIElementState state)
        {
            switch (state)
            {
                case UIElementState.Normal:
                    return Color;
                case UIElementState.Highlighted:
                    return HighlightedColor;
                case UIElementState.Selected:
                    return SelectedColor;
                case UIElementState.Disabled:
                    return DisabledColor;
            }

            return Color;
        }
예제 #35
0
 public Sprite(UIElementState state, Point position, Point size, Texture2D image, Color imageColor) : base(state, position)
 {
     Size       = size;
     Image      = image;
     ImageColor = imageColor;
 }