Beispiel #1
0
        }                                                                      // reduce the size of billboard gizmos.

        protected override Entity Create()
        {
            var gizmoTexture = GraphicsDevice.GetOrCreateSharedData(gizmoName, d => TextureExtensions.FromFileData(d, billboardData));

            // Create a root that will contains the billboard as a child, so that it is easier to add other elements with only the billboard set as a GizmoScalingEntity
            var root = new Entity(gizmoName);

            var billboard = new Entity(gizmoName + " Billboard")
            {
                new SpriteComponent
                {
                    SpriteType     = SpriteType.Billboard,
                    SpriteProvider = new SpriteFromTexture
                    {
                        IsTransparent = true,
                        Texture       = gizmoTexture,
                        PixelsPerUnit = gizmoTexture.Width,
                    },
                    PremultipliedAlpha = false,
                    Color         = new Color(255, 255, 255, 192),
                    IsAlphaCutoff = false,
                    RenderGroup   = RenderGroup,
                }
            };

            root.AddChild(billboard);

            // Scaling should only affect billboard
            GizmoScalingEntity = billboard;

            return(root);
        }
Beispiel #2
0
        /// <summary>
        /// Applies the build status on top of a thumbnail image (using overlay icons).
        /// </summary>
        /// <param name="thumbnailImage">The thumbnail image.</param>
        /// <param name="dependencyBuildStatus">The dependency build status.</param>
        public static void ApplyThumbnailStatus(Image thumbnailImage, LogMessageType dependencyBuildStatus)
        {
            // No warning or error, nothing to do (or maybe we should display a logo for "info"?)
            if (dependencyBuildStatus < LogMessageType.Warning)
            {
                return;
            }

            using (var thumbnailBuilderHelper = new ThumbnailBuildHelper())
            {
                if (errorTexture == null)
                {
                    // Load status textures
                    errorTexture   = TextureExtensions.FromFileData(thumbnailBuilderHelper.GraphicsDevice, DefaultThumbnails.ThumbnailDependencyError);
                    warningTexture = TextureExtensions.FromFileData(thumbnailBuilderHelper.GraphicsDevice, DefaultThumbnails.ThumbnailDependencyWarning);
                }

                var texture = dependencyBuildStatus == LogMessageType.Warning ? warningTexture : errorTexture;
                using (var thumbnailTexture = Texture.New(thumbnailBuilderHelper.GraphicsDevice, thumbnailImage))
                {
                    thumbnailBuilderHelper.CombineTextures(thumbnailTexture, texture, thumbnailImage.Description.Width - texture.Width - 4, thumbnailImage.Description.Height - texture.Height - 4);
                }

                // Read back result to image
                thumbnailBuilderHelper.RenderTarget.GetData(thumbnailBuilderHelper.GraphicsContext.CommandList, thumbnailBuilderHelper.RenderTargetStaging, new DataPointer(thumbnailImage.PixelBuffer[0].DataPointer, thumbnailImage.PixelBuffer[0].BufferStride));
                thumbnailImage.Description.Format = thumbnailBuilderHelper.RenderTarget.Format; // In case channels are swapped
            }
        }
Beispiel #3
0
 /// <summary>
 /// Presents composer to tweet text along with screenshot.
 /// </summary>
 /// <param name="_message">The text to tweet.</param>
 /// <param name="_onCompletion">Calls the delegate when the user finished or cancelled the Tweet composition.</param>
 public void ShowTweetComposerWithScreenshot(string _message, TWTRTweetCompletion _onCompletion)
 {
     // First capture screenshot, once its done tweet about it
     StartCoroutine(TextureExtensions.TakeScreenshot((_texture) => {
         ShowTweetComposerWithImage(_message, _texture, _onCompletion);
     }));
 }
Beispiel #4
0
 /// <summary>
 /// Saves the screenshot to gallery/media library of the users device.
 /// </summary>
 /// <param name="_onCompletion">Callback triggered once  save to gallery is done.</param>
 public void SaveScreenshotToGallery(SaveImageToGalleryCompletion _onCompletion)
 {
     // First capture screenshot
     StartCoroutine(TextureExtensions.TakeScreenshot((_texture) => {
         // Now save it
         SaveImageToGallery(_texture, _onCompletion);
     }));
 }
Beispiel #5
0
 public void ShareScreenShot(string _message, eShareOptions[] _excludedOptions, SharingCompletion _onCompletion)
 {
     // First capture screenshot
     StartCoroutine(TextureExtensions.TakeScreenshot((_texture) => {
         // Share image
         ShareImage(_message, _texture, _excludedOptions, _onCompletion);
     }));
 }
Beispiel #6
0
 public void Dispose()
 {
     TextureExtensions.Unhook((Texture)this.TextureAtlas);
     this.TextureAtlas.Dispose();
     foreach (Trile trile in this.Triles.Values)
     {
         trile.Dispose();
     }
 }
Beispiel #7
0
 protected override void UnloadContent()
 {
     if (this.text == null)
     {
         return;
     }
     TextureExtensions.Unhook((Texture)this.text);
     this.text.Dispose();
 }
            protected override void SetThumbnailParameters()
            {
                var assetType = Parameters.Asset.GetType();

                TitleText         = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute <DisplayAttribute>(assetType)?.Name ?? assetType.Name;
                Font              = DefaultFont;
                FontColor         = Color.White;
                BackgroundColor   = (Color)assetType.GetUniqueColor();
                BackgroundTexture = TextureExtensions.FromFileData(GraphicsDevice, DefaultThumbnails.UserAssetThumbnail);
            }
Beispiel #9
0
 public void Dispose()
 {
     if (this.Texture != null)
     {
         TextureExtensions.Unhook((Texture)this.Texture);
         this.Texture.Dispose();
     }
     this.Texture = (Texture2D)null;
     this.Timing  = (AnimationTiming)null;
 }
        public void ShareScreenshotOnWhatsApp(SharingCompletion _onCompletion)
        {
            // First capture frame
            StartCoroutine(TextureExtensions.TakeScreenshot((_texture) => {
                // Convert texture into byte array
                byte[] _imageByteArray = _texture.EncodeToPNG();

                // Share
                ShareImageOnWhatsApp(_imageByteArray, _onCompletion);
            }));
        }
Beispiel #11
0
        public void SendMailWithScreenshot(string _subject, string _body, bool _isHTMLBody,
                                           string[] _recipients, SharingCompletion _onCompletion)
        {
            // First capture frame
            StartCoroutine(TextureExtensions.TakeScreenshot((_texture) => {
                // Convert texture into byte array
                byte[] _imageByteArray = _texture.EncodeToPNG();

                SendMail(_subject, _body, _isHTMLBody, _imageByteArray,
                         MIMEType.kPNG, "Screenshot.png", _recipients, _onCompletion);
            }));
        }
Beispiel #12
0
        public static void Parse(PngToTextureOptions op)
        {
            op.UpdateOptions();

            var appState = AppState.FromFile(op.InputPath);

            appState.UpdateSystemInfo(op.GetSystemInfo());

            var bitmap     = TextureExtensions.BitmapFromImage(op.InputPath, appState.SystemInfo);
            var serializer = appState.GetSerializer();

            serializer.WriteToFile(op.OutputPath, bitmap);
        }
Beispiel #13
0
 public void RefreshPreview(int size = 128)
 {
     if (matrix != null)
     {
         Matrix previewMatrix = matrix;                // new Matrix( new CoordRect(0,0,size,size) );
         //MatrixOps.Resize(matrix, previewMatrix);
         preview = new Texture2D(previewMatrix.rect.size.x, previewMatrix.rect.size.z);
         previewMatrix.ExportTexture(preview, -1);
     }
     else
     {
         preview = TextureExtensions.ColorTexture(2, 2, Color.black);
     }
 }
        /// <summary>
        /// Captures the screenshot and adds the image for sharing.
        /// </summary>
        public void AttachScreenShot()
        {
            // Stop existing requests
            StopAsyncRequests();

            // Mark async operation in progress
            ImageAsyncDownloadInProgress = true;

            // Start loading screenshot data
            m_takeScreenShotCoroutine = TextureExtensions.TakeScreenshot((_texture) => {
                // Share image
                AttachImage(_texture);

                // Set properties
                ImageAsyncDownloadInProgress = false;
            });

            NPBinding.Instance.StartCoroutine(m_takeScreenShotCoroutine);
        }
        public override void OnEnter()
        {
            if (attachmentOption != eAttachmentOption.None)
            {
                if (attachmentOption == eAttachmentOption.AttachScreenshot)
                {
                    TextureExtensions.TakeScreenshot((Texture2D _image) => {
                        m_imageData = _image.EncodeToPNG();

                        OnShareDataAvailable();
                    });

                    return;
                }
                else if (attachmentOption == eAttachmentOption.AttachImageAtPath)
                {
                    DownloadAsset _request = new DownloadAsset(new URLStruct(imagePath.Value), true);
                    _request.OnCompletion = (WWW _www, string _error) => {
                        if (_error == null)
                        {
                            m_imageData = _www.bytes;
                        }

                        OnShareDataAvailable();
                    };

                    return;
                }
                else
                {
                    m_imageData = ((Texture2D)image.Value).EncodeToPNG();

                    OnShareDataAvailable();
                    return;
                }
            }
            else
            {
                OnShareDataAvailable();
            }
        }
        public static void DrawTextureInout(GeneratorsTester.TextureInout inout)
        {
            using (Cell.LineStd)
            {
                using (Cell.RowRel(1 - Cell.current.fieldWidth))
                    Draw.Label("Create New");

                using (Cell.RowRel(Cell.current.fieldWidth))
                    if (Draw.Button("Create"))
                    {
                        //GeneratorTesterWindow window = (GeneratorTesterWindow)GetWindow(typeof (GeneratorTesterWindow));
                        inout.texture            = TextureExtensions.ColorTexture(512, 512, new Color(0.2f, 0.2f, 0.2f, 1));
                        inout.texture.filterMode = FilterMode.Point;
                        inout.texture.Apply();
                    }
            }

            using (Cell.LineStd) Draw.Toggle(ref inout.previewInScene, "Preview In Scene");
            using (Cell.LineStd) Draw.Toggle(ref inout.preview, "Preview");

            if (inout.preview && inout.texture != null)
            {
                using (Cell.LinePx(256))
                {
                    ScrollZoom scrollZoom = new ScrollZoom();
                    scrollZoom.scroll = inout.previewScroll;
                    scrollZoom.zoom   = inout.previewZoom;

                    Draw.ScrollableTexture(inout.texture, scrollZoom);

                    using (Cell.Custom(5, 5, 20, 20))
                        if (Draw.Button("Z"))
                        {
                            scrollZoom.scroll = Vector2.zero; scrollZoom.zoom = 1;
                        }

                    inout.previewScroll = scrollZoom.scroll;
                    inout.previewZoom   = scrollZoom.zoom;
                }
            }
        }
Beispiel #17
0
        public static void DrawRTPComponentWarning()
        {
                        #if RTP
            if (GraphWindow.current.mapMagic == null)
            {
                return;
            }

            if (GraphWindow.current.mapMagic?.gameObject.GetComponent <ReliefTerrain>() == null || GraphWindow.current.mapMagic?.gameObject.GetComponent <Renderer>() == null)
            {
                using (Cell.LinePx(70))
                {
                    GUIStyle backStyle = UI.current.textures.GetElementStyle("DPUI/Backgrounds/Foldout");

                    using (Cell.Row)
                        Draw.Label("RTP or Renderer \ncomponents are \nnot assigned to \nMapMagic object");

                    using (Cell.RowPx(30))
                        if (Draw.Button("Fix"))
                        {
                            if (GraphWindow.current.mapMagic.gameObject.GetComponent <Renderer>() == null)
                            {
                                MeshRenderer renderer = GraphWindow.current.mapMagic.gameObject.AddComponent <MeshRenderer>();
                                renderer.enabled = false;
                            }
                            if (GraphWindow.current.mapMagic.gameObject.GetComponent <ReliefTerrain>() == null)
                            {
                                ReliefTerrain rtp = GraphWindow.current.mapMagic.gameObject.AddComponent <ReliefTerrain>();

                                //filling empty splats
                                Texture2D emptyTex = TextureExtensions.ColorTexture(4, 4, new Color(0.5f, 0.5f, 0.5f, 1f));
                                emptyTex.name = "Empty";
                                rtp.globalSettingsHolder.splats = new Texture2D[] { emptyTex, emptyTex, emptyTex, emptyTex };
                            }
                        }
                }
                Cell.EmptyLinePx(5);
            }
                        #endif
        }
			public static void DrawRTPComponentWarning ()
			{
				#if RTP
				if (MapMagic.instance.gameObject.GetComponent<ReliefTerrain>()==null || MapMagic.instance.gameObject.GetComponent<Renderer>()==null)
				{
					using (Cell.LinePx(70)))
					{
						Cell.current.margins = new Padding(4);

						GUIStyle backStyle = UI.current.textures.GetElementStyle("DPUI/Backgrounds/Foldout");
						Draw.Element(backStyle, Cell.current);
						Draw.Element(backStyle, Cell.current);

						Draw.Label("RTP or Renderer \ncomponents are \nnot assigned to \nMapMagic object", cell:UI.Empty(Size.row));

						if (Draw.Button("Fix", cell:UI.Empty(Size.RowPixels(30))))
						{
							if (MapMagic.instance.gameObject.GetComponent<Renderer>() == null)
							{
								MeshRenderer renderer = MapMagic.instance.gameObject.AddComponent<MeshRenderer>();
								renderer.enabled = false;
							}
							if (MapMagic.instance.gameObject.GetComponent<ReliefTerrain>() == null)
							{
								ReliefTerrain rtp = MapMagic.instance.gameObject.AddComponent<ReliefTerrain>();

								//filling empty splats
								Texture2D emptyTex = TextureExtensions.ColorTexture(4,4,new Color(0.5f, 0.5f, 0.5f, 1f));
								emptyTex.name = "Empty";
								rtp.globalSettingsHolder.splats = new Texture2D[] { emptyTex,emptyTex,emptyTex,emptyTex };
							}
							MapMagic.instance.OnSettingsChanged();
						}
					}
					UI.Empty(Size.LinePixels(5));
				}
				#endif
			}
Beispiel #19
0
            protected override void CustomizeThumbnail(Image image)
            {
                base.CustomizeThumbnail(image);

                // Combine textures
                using (var thumbnailBuilderHelper = new ThumbnailBuildHelper())
                    using (var generatedThumbnail = Texture.New(thumbnailBuilderHelper.GraphicsDevice, image))
                    {
                        // Set color space
                        var oldColorSpace = thumbnailBuilderHelper.GraphicsDevice.ColorSpace;
                        thumbnailBuilderHelper.GraphicsDevice.ColorSpace = Parameters.ColorSpace;

                        // Load animation default thumbnail
                        if (animationPreviewTexture == null)
                        {
                            animationPreviewTexture = TextureExtensions.FromFileData(thumbnailBuilderHelper.GraphicsDevice, StaticThumbnails.AnimationThumbnail);
                        }

                        thumbnailBuilderHelper.InitializeRenderTargets(PixelFormat.R8G8B8A8_UNorm_SRgb, animationPreviewTexture.Width, animationPreviewTexture.Height);

                        // Generate thumbnail with status icon
                        // Clear (transparent)
                        thumbnailBuilderHelper.GraphicsContext.CommandList.Clear(thumbnailBuilderHelper.RenderTarget, new Color4());
                        thumbnailBuilderHelper.GraphicsContext.CommandList.SetRenderTargetAndViewport(null, thumbnailBuilderHelper.RenderTarget);

                        // Render thumbnail and status sprite
                        thumbnailBuilderHelper.SpriteBatch.Begin(thumbnailBuilderHelper.GraphicsContext);
                        thumbnailBuilderHelper.SpriteBatch.Draw(animationPreviewTexture, Vector2.Zero, new Color(0xFF, 0xFF, 0xFF, 0x20));
                        thumbnailBuilderHelper.SpriteBatch.Draw(generatedThumbnail, Vector2.Zero);
                        thumbnailBuilderHelper.SpriteBatch.End();

                        thumbnailBuilderHelper.GraphicsDevice.ColorSpace = oldColorSpace;

                        // Read back result to image
                        thumbnailBuilderHelper.RenderTarget.GetData(thumbnailBuilderHelper.GraphicsContext.CommandList, thumbnailBuilderHelper.RenderTargetStaging, new DataPointer(image.PixelBuffer[0].DataPointer, image.PixelBuffer[0].BufferStride));
                        image.Description.Format = thumbnailBuilderHelper.RenderTarget.Format; // In case channels are swapped
                    }
            }
Beispiel #20
0
        protected override Task LoadContent()
        {
            // Set dependency properties test values.
            TextBlock.TextColorPropertyKey.DefaultValueMetadata     = DefaultValueMetadata.Static(Color.LightGray);
            EditText.TextColorPropertyKey.DefaultValueMetadata      = DefaultValueMetadata.Static(Color.LightGray);
            EditText.SelectionColorPropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(Color.FromAbgr(0x623574FF));
            EditText.CaretColorPropertyKey.DefaultValueMetadata     = DefaultValueMetadata.Static(Color.FromAbgr(0xF0F0F0FF));
            var buttonPressedTexture    = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.ButtonPressed);
            var buttonNotPressedTexture = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.ButtonNotPressed);
            var buttonOverredTexture    = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.ButtonOverred);

            Button.PressedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test button pressed design", buttonPressedTexture)
            {
                Borders = 8 * Vector4.One
            });
            Button.NotPressedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test button not pressed design", buttonNotPressedTexture)
            {
                Borders = 8 * Vector4.One
            });
            Button.MouseOverImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test button overred design", buttonOverredTexture)
            {
                Borders = 8 * Vector4.One
            });
            var editActiveTexture   = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.EditTextActive);
            var editInactiveTexture = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.EditTextInactive);
            var editOverredTexture  = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.EditTextOverred);

            EditText.ActiveImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test edit active design", editActiveTexture)
            {
                Borders = 12 * Vector4.One
            });
            EditText.InactiveImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test edit inactive design", editInactiveTexture)
            {
                Borders = 12 * Vector4.One
            });
            EditText.MouseOverImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test edit overred design", editOverredTexture)
            {
                Borders = 12 * Vector4.One
            });
            var toggleButtonChecked       = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonChecked);
            var toggleButtonUnchecked     = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonUnchecked);
            var toggleButtonIndeterminate = TextureExtensions.CreateTextureFromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonIndeterminate);

            ToggleButton.CheckedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test toggle button checked design", toggleButtonChecked)
            {
                Borders = 8 * Vector4.One
            });
            ToggleButton.UncheckedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test toggle button unchecked design", toggleButtonUnchecked)
            {
                Borders = 8 * Vector4.One
            });
            ToggleButton.IndeterminateImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new UIImage("Test toggle button indeterminate design", toggleButtonIndeterminate)
            {
                Borders = 8 * Vector4.One
            });

            Window.IsMouseVisible = true;
            UI.VirtualResolution  = new Vector3(1000, 500, 500);

            CreatePipeline();

            return(base.LoadContent());
        }
Beispiel #21
0
        public override void OnGUI(Rect rect)
        {
            //showing window next frame
            Action tmp = nextFrameShow;

            nextFrameShow = null;                     //because we can't null it after it has been called (new window will be started)
            tmp?.Invoke();

            //preparing textures
            if (background == null)
            {
                background = new Texture2D(1, 1, TextureFormat.RGBA32, false);
                background.SetPixel(0, 0, new Color(0.98f, 0.98f, 0.98f));
                background.Apply();
            }

            if (highlight == null)
            {
                highlight = new Texture2D(1, 1, TextureFormat.RGBA32, false);
                highlight.SetPixel(0, 0, new Color(0.6f, 0.7f, 0.9f));
                highlight.Apply();
            }

            Vector2 size = GetWindowSize();
            Vector2 pos  = new Vector2(0, verticalOffset);

            //background
            //if (Event.current.type == EventType.repaint) GUI.skin.box.Draw(fullRect, false, true, true, false);
            UnityEngine.GUI.DrawTexture(new Rect(pos, size), background, ScaleMode.StretchToFill);

            //list
            float currentHeight = verticalOffsetTmp;
            int   itemsCount    = items.Count;

            for (int i = 0; i < itemsCount; i++)
            {
                Item currentItem = items[i];

                //rects
                Rect lineRect = new Rect(1, currentHeight + 1, size.x - 2, currentItem.height - 2);
                currentHeight += currentItem.height;

                Rect offsetRect = new Rect(lineRect.x, lineRect.y, Item.lineHeight * currentItem.offset, lineRect.height);
                Rect labelRect  = new Rect(lineRect.x + offsetRect.width + 3, lineRect.y + 1, lineRect.width - offsetRect.width - 3, lineRect.height - 1);

                //background
                bool highlighted = lineRect.Contains(Event.current.mousePosition);
                if (currentItem.disabled)
                {
                    highlighted = false;
                }
                if (highlighted)
                {
                    UnityEngine.GUI.DrawTexture(lineRect, highlight);
                }

                /*{
                 *      //GUIStyle style = texturesCache.GetElementStyle(tex);
                 *      //if (Event.current.type == EventType.Repaint) style.Draw(leftRect, false, false, false ,false);
                 *
                 *      GUIStyle style = new GUIStyle();
                 *      style.normal.background = highlight;
                 *      style.border = new RectOffset(highlight.width/2, highlight.width/2, highlight.height/2, highlight.height/2);
                 *
                 *      if (Event.current.type == EventType.Repaint) style.Draw(lineRect, false, false, false ,false);
                 * }*/

                //clicking
                bool clicked = Event.current.rawType == EventType.MouseUp && Event.current.button == 0;
                if (highlighted && clicked && currentItem.onClick != null)
                {
                    currentItem.onClick();
                    CloseRecursive();
                    Event.current.Use();
                }

                //label
                UnityEditor.EditorGUI.BeginDisabledGroup(currentItem.disabled);
                //if (blackLabel == null) { blackLabel = new GUIStyle(UnityEditor.EditorStyles.label); blackLabel.normal.textColor = Color.black; }
                if (currentItem.onDraw != null)
                {
                    currentItem.onDraw(currentItem, lineRect);
                }
                else
                {
                    EditorGUI.LabelField(labelRect, currentItem.name);
                }
                UnityEditor.EditorGUI.EndDisabledGroup();

                //separator
                if (currentItem.isSeparator)
                {
                    if (currentItem.onDraw == null)
                    {
                        Rect separatorRect = new Rect(lineRect.x + 3, lineRect.y, lineRect.width - 6, 1);
                        if (separator == null)
                        {
                            separator = TextureExtensions.ColorTexture(2, 2, new Color(0.3f, 0.3f, 0.3f, 1));
                        }
                        UnityEngine.GUI.DrawTexture(separatorRect, separator, ScaleMode.ScaleAndCrop);
                    }
                    else
                    {
                        currentItem.onDraw(currentItem, lineRect);
                    }
                }

                //chevron
                if (currentItem.hasSubs)
                {
                    Rect rightRect = lineRect; rightRect.width = 10; rightRect.height = 10;
                    rightRect.x = lineRect.x + lineRect.width - rightRect.width; rightRect.y = lineRect.y + lineRect.height / 2 - rightRect.height / 2;
                    //UnityEditor.EditorGUI.LabelField(rightRect, "\u25B6");
                    //	if (triangle == null) triangle = Resources.Load("DPUI/Chevrons/SmallRight") as Texture2D;
                    //	UnityEngine.GUI.DrawTexture(GetIconRect(rightRect, triangle), triangle, ScaleMode.ScaleAndCrop);

                    //opening subsmenus
                    if (highlighted)
                    {
                        //starting timer on selected item change
                        if (currentItem != lastItem)
                        {
                            lastTimestart = System.DateTime.Now;
                            lastItem      = currentItem;
                        }

                        //when holding for too long
                        double highlightTime = (System.DateTime.Now - lastTimestart).TotalMilliseconds;
                        if ((highlightTime > 150 && expandedItem != currentItem) || clicked)
                        {
                            //re-opening expanded window
                            if (expandedWindow != null && expandedWindow.editorWindow != null)
                            {
                                expandedWindow.editorWindow.Close();
                            }

                            expandedWindow = new PopupMenu()
                            {
                                items    = currentItem.subItems,
                                minWidth = minWidth,
                                parent   = this
                            };
                            expandedItem = currentItem;

                            //nextFrameShow = () => expandedWindow.Show(lineRect.max-new Vector2(0,currentItem.height));
                            expandedWindow.Show(lineRect.max - new Vector2(0, currentItem.height));
                            editorWindow.Focus();

                            //if (currentItem.subItems != null) PopupWindow.Show(new Rect(lineRect.max-new Vector2(0,currentItem.height), Vector2.zero), expandedWindow);
                        }
                    }
                }
            }

            //#if (!UNITY_EDITOR_LINUX)
            this.editorWindow.Repaint();
            //#endif
        }
Beispiel #22
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            // Default styles
            // Note: this is temporary and should be replaced with default template of UI elements
            textBlockTextColor = Color.LightGray;

            scrollingTextTextColor = Color.LightGray;

            var buttonPressedTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonPressed);
            var buttonNotPressedTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonNotPressed);
            var buttonOverredTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonOverred);

            buttonPressedImage = (SpriteFromTexture) new Sprite("Test button pressed design", buttonPressedTexture)
            {
                Borders = 8 * Vector4.One
            };
            buttonNotPressedImage = (SpriteFromTexture) new Sprite("Test button not pressed design", buttonNotPressedTexture)
            {
                Borders = 8 * Vector4.One
            };
            buttonMouseOverImage = (SpriteFromTexture) new Sprite("Test button overred design", buttonOverredTexture)
            {
                Borders = 8 * Vector4.One
            };

            var editActiveTexture   = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextActive);
            var editInactiveTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextInactive);
            var editOverredTexture  = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextOverred);

            editTextTextColor      = Color.LightGray;
            editTextSelectionColor = Color.FromAbgr(0x623574FF);
            editTextCaretColor     = Color.FromAbgr(0xF0F0F0FF);
            editTextActiveImage    = (SpriteFromTexture) new Sprite("Test edit active design", editActiveTexture)
            {
                Borders = 12 * Vector4.One
            };
            editTextInactiveImage = (SpriteFromTexture) new Sprite("Test edit inactive design", editInactiveTexture)
            {
                Borders = 12 * Vector4.One
            };
            editTextMouseOverImage = (SpriteFromTexture) new Sprite("Test edit overred design", editOverredTexture)
            {
                Borders = 12 * Vector4.One
            };

            var toggleButtonChecked       = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonChecked);
            var toggleButtonUnchecked     = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonUnchecked);
            var toggleButtonIndeterminate = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonIndeterminate);

            toggleButtonCheckedImage = (SpriteFromTexture) new Sprite("Test toggle button checked design", toggleButtonChecked)
            {
                Borders = 8 * Vector4.One
            };
            toggleButtonUncheckedImage = (SpriteFromTexture) new Sprite("Test toggle button unchecked design", toggleButtonUnchecked)
            {
                Borders = 8 * Vector4.One
            };
            toggleButtonIndeterminateImage = (SpriteFromTexture) new Sprite("Test toggle button indeterminate design", toggleButtonIndeterminate)
            {
                Borders = 8 * Vector4.One
            };

            var designsTexture = TextureExtensions.FromFileData(GraphicsDevice, DefaultDesigns.Designs);

            sliderTrackBackgroundImage = (SpriteFromTexture) new Sprite("Default slider track background design", designsTexture)
            {
                Borders = 14 * Vector4.One, Region = new RectangleF(207, 3, 32, 32)
            };
            sliderTrackForegroundImage = (SpriteFromTexture) new Sprite("Default slider track foreground design", designsTexture)
            {
                Borders = 0 * Vector4.One, Region = new RectangleF(3, 37, 32, 32)
            };
            sliderThumbImage = (SpriteFromTexture) new Sprite("Default slider thumb design", designsTexture)
            {
                Borders = 4 * Vector4.One, Region = new RectangleF(37, 37, 16, 32)
            };
            sliderMouseOverThumbImage = (SpriteFromTexture) new Sprite("Default slider thumb overred design", designsTexture)
            {
                Borders = 4 * Vector4.One, Region = new RectangleF(71, 37, 16, 32)
            };
            sliderTickImage = (SpriteFromTexture) new Sprite("Default slider track foreground design", designsTexture)
            {
                Region = new RectangleF(245, 3, 3, 6)
            };
            sliderTickOffset           = 13f;
            sliderTrackStartingOffsets = new Vector2(3);

            Window.IsMouseVisible = true;

            SceneSystem.SceneInstance = new SceneInstance(Services, Scene);
        }
Beispiel #23
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            SceneSystem.GraphicsCompositor = Content.Load <GraphicsCompositor>("GraphicsCompositor");

            StopOnFrameCount = -1;

            Scene = new Scene();

            UIRoot = new Entity("Root entity of camera UI")
            {
                new UIComponent()
            };
            UIComponent.IsFullScreen      = true;
            UIComponent.Resolution        = new Vector3(1000, 500, 500);
            UIComponent.ResolutionStretch = ResolutionStretch.FixedWidthFixedHeight;
            Scene.Entities.Add(UIRoot);

            UI = Services.GetService <UISystem>();
            if (UI == null)
            {
                UI = new UISystem(Services);
                Services.AddService(UI);
                GameSystems.Add(UI);
            }

            Camera = new Entity("Scene camera")
            {
                new CameraComponent {
                    Slot = SceneSystem.GraphicsCompositor.Cameras[0].ToSlotId()
                }
            };
            Camera.Transform.Position = new Vector3(0, 0, 1000);
            Scene.Entities.Add(Camera);

            // Default styles
            // Note: this is temporary and should be replaced with default template of UI elements
            textBlockTextColor = Color.LightGray;

            scrollingTextTextColor = Color.LightGray;

            var buttonPressedTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonPressed);
            var buttonNotPressedTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonNotPressed);
            var buttonOverredTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonOverred);

            buttonPressedImage = (SpriteFromTexture) new Sprite("Test button pressed design", buttonPressedTexture)
            {
                Borders = 8 * Vector4.One
            };
            buttonNotPressedImage = (SpriteFromTexture) new Sprite("Test button not pressed design", buttonNotPressedTexture)
            {
                Borders = 8 * Vector4.One
            };
            buttonMouseOverImage = (SpriteFromTexture) new Sprite("Test button overred design", buttonOverredTexture)
            {
                Borders = 8 * Vector4.One
            };

            var editActiveTexture   = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextActive);
            var editInactiveTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextInactive);
            var editOverredTexture  = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextOverred);

            editTextTextColor      = Color.LightGray;
            editTextSelectionColor = Color.FromAbgr(0x623574FF);
            editTextCaretColor     = Color.FromAbgr(0xF0F0F0FF);
            editTextActiveImage    = (SpriteFromTexture) new Sprite("Test edit active design", editActiveTexture)
            {
                Borders = 12 * Vector4.One
            };
            editTextInactiveImage = (SpriteFromTexture) new Sprite("Test edit inactive design", editInactiveTexture)
            {
                Borders = 12 * Vector4.One
            };
            editTextMouseOverImage = (SpriteFromTexture) new Sprite("Test edit overred design", editOverredTexture)
            {
                Borders = 12 * Vector4.One
            };

            var toggleButtonChecked       = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonChecked);
            var toggleButtonUnchecked     = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonUnchecked);
            var toggleButtonIndeterminate = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonIndeterminate);

            toggleButtonCheckedImage = (SpriteFromTexture) new Sprite("Test toggle button checked design", toggleButtonChecked)
            {
                Borders = 8 * Vector4.One
            };
            toggleButtonUncheckedImage = (SpriteFromTexture) new Sprite("Test toggle button unchecked design", toggleButtonUnchecked)
            {
                Borders = 8 * Vector4.One
            };
            toggleButtonIndeterminateImage = (SpriteFromTexture) new Sprite("Test toggle button indeterminate design", toggleButtonIndeterminate)
            {
                Borders = 8 * Vector4.One
            };

            var designsTexture = TextureExtensions.FromFileData(GraphicsDevice, DefaultDesigns.Designs);

            sliderTrackBackgroundImage = (SpriteFromTexture) new Sprite("Default slider track background design", designsTexture)
            {
                Borders = 14 * Vector4.One, Region = new RectangleF(207, 3, 32, 32)
            };
            sliderTrackForegroundImage = (SpriteFromTexture) new Sprite("Default slider track foreground design", designsTexture)
            {
                Borders = 0 * Vector4.One, Region = new RectangleF(3, 37, 32, 32)
            };
            sliderThumbImage = (SpriteFromTexture) new Sprite("Default slider thumb design", designsTexture)
            {
                Borders = 4 * Vector4.One, Region = new RectangleF(37, 37, 16, 32)
            };
            sliderMouseOverThumbImage = (SpriteFromTexture) new Sprite("Default slider thumb overred design", designsTexture)
            {
                Borders = 4 * Vector4.One, Region = new RectangleF(71, 37, 16, 32)
            };
            sliderTickImage = (SpriteFromTexture) new Sprite("Default slider track foreground design", designsTexture)
            {
                Region = new RectangleF(245, 3, 3, 6)
            };
            sliderTickOffset           = 13f;
            sliderTrackStartingOffsets = new Vector2(3);

            Window.IsMouseVisible = true;

            SceneSystem.SceneInstance = new SceneInstance(Services, Scene);
        }
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            object existingStyle;

            // Set dependency properties test values.
            UI.DefaultResourceDictionary.TryGetValue(typeof(TextBlock), out existingStyle);
            UI.DefaultResourceDictionary[typeof(TextBlock)] = new Style(typeof(TextBlock), (Style)existingStyle)
            {
                Setters =
                {
                    new Setter <Color>(TextBlock.TextColorPropertyKey, Color.LightGray),
                }
            };

            UI.DefaultResourceDictionary.TryGetValue(typeof(ScrollingText), out existingStyle);
            UI.DefaultResourceDictionary[typeof(ScrollingText)] = new Style(typeof(ScrollingText), (Style)existingStyle)
            {
                Setters =
                {
                    new Setter <Color>(TextBlock.TextColorPropertyKey, Color.LightGray),
                }
            };

            var buttonPressedTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonPressed);
            var buttonNotPressedTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonNotPressed);
            var buttonOverredTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonOverred);

            UI.DefaultResourceDictionary.TryGetValue(typeof(Button), out existingStyle);
            UI.DefaultResourceDictionary[typeof(Button)] = new Style(typeof(Button), (Style)existingStyle)
            {
                Setters =
                {
                    new Setter <Sprite>(Button.PressedImagePropertyKey,    new Sprite("Test button pressed design", buttonPressedTexture)
                    {
                        Borders = 8 * Vector4.One
                    }),
                    new Setter <Sprite>(Button.NotPressedImagePropertyKey, new Sprite("Test button not pressed design", buttonNotPressedTexture)
                    {
                        Borders = 8 * Vector4.One
                    }),
                    new Setter <Sprite>(Button.MouseOverImagePropertyKey,  new Sprite("Test button overred design", buttonOverredTexture)
                    {
                        Borders = 8 * Vector4.One
                    }),
                }
            };

            var editActiveTexture   = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextActive);
            var editInactiveTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextInactive);
            var editOverredTexture  = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextOverred);

            UI.DefaultResourceDictionary.TryGetValue(typeof(EditText), out existingStyle);
            UI.DefaultResourceDictionary[typeof(EditText)] = new Style(typeof(EditText), (Style)existingStyle)
            {
                Setters =
                {
                    new Setter <Color>(EditText.TextColorPropertyKey,       Color.LightGray),
                    new Setter <Color>(EditText.SelectionColorPropertyKey,  Color.FromAbgr(0x623574FF)),
                    new Setter <Color>(EditText.CaretColorPropertyKey,      Color.FromAbgr(0xF0F0F0FF)),
                    new Setter <Sprite>(EditText.ActiveImagePropertyKey,    new Sprite("Test edit active design", editActiveTexture)
                    {
                        Borders = 12 * Vector4.One
                    }),
                    new Setter <Sprite>(EditText.InactiveImagePropertyKey,  new Sprite("Test edit inactive design", editInactiveTexture)
                    {
                        Borders = 12 * Vector4.One
                    }),
                    new Setter <Sprite>(EditText.MouseOverImagePropertyKey, new Sprite("Test edit overred design", editOverredTexture)
                    {
                        Borders = 12 * Vector4.One
                    }),
                }
            };

            var toggleButtonChecked       = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonChecked);
            var toggleButtonUnchecked     = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonUnchecked);
            var toggleButtonIndeterminate = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonIndeterminate);

            UI.DefaultResourceDictionary.TryGetValue(typeof(ToggleButton), out existingStyle);
            UI.DefaultResourceDictionary[typeof(ToggleButton)] = new Style(typeof(ToggleButton), (Style)existingStyle)
            {
                Setters =
                {
                    new Setter <Sprite>(ToggleButton.CheckedImagePropertyKey,       new Sprite("Test toggle button checked design", toggleButtonChecked)
                    {
                        Borders = 8 * Vector4.One
                    }),
                    new Setter <Sprite>(ToggleButton.UncheckedImagePropertyKey,     new Sprite("Test toggle button unchecked design", toggleButtonUnchecked)
                    {
                        Borders = 8 * Vector4.One
                    }),
                    new Setter <Sprite>(ToggleButton.IndeterminateImagePropertyKey, new Sprite("Test toggle button indeterminate design", toggleButtonIndeterminate)
                    {
                        Borders = 8 * Vector4.One
                    }),
                }
            };

            Window.IsMouseVisible = true;

            SceneSystem.SceneInstance = new SceneInstance(Services, Scene);
        }
Beispiel #25
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            // Set dependency properties test values.
            TextBlock.TextColorPropertyKey.DefaultValueMetadata     = DefaultValueMetadata.Static(Color.LightGray);
            EditText.TextColorPropertyKey.DefaultValueMetadata      = DefaultValueMetadata.Static(Color.LightGray);
            EditText.SelectionColorPropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(Color.FromAbgr(0x623574FF));
            EditText.CaretColorPropertyKey.DefaultValueMetadata     = DefaultValueMetadata.Static(Color.FromAbgr(0xF0F0F0FF));
            var buttonPressedTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonPressed);
            var buttonNotPressedTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonNotPressed);
            var buttonOverredTexture    = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ButtonOverred);

            Button.PressedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test button pressed design", buttonPressedTexture)
            {
                Borders = 8 * Vector4.One
            });
            Button.NotPressedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test button not pressed design", buttonNotPressedTexture)
            {
                Borders = 8 * Vector4.One
            });
            Button.MouseOverImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test button overred design", buttonOverredTexture)
            {
                Borders = 8 * Vector4.One
            });
            var editActiveTexture   = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextActive);
            var editInactiveTexture = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextInactive);
            var editOverredTexture  = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.EditTextOverred);

            EditText.ActiveImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test edit active design", editActiveTexture)
            {
                Borders = 12 * Vector4.One
            });
            EditText.InactiveImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test edit inactive design", editInactiveTexture)
            {
                Borders = 12 * Vector4.One
            });
            EditText.MouseOverImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test edit overred design", editOverredTexture)
            {
                Borders = 12 * Vector4.One
            });
            var toggleButtonChecked       = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonChecked);
            var toggleButtonUnchecked     = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonUnchecked);
            var toggleButtonIndeterminate = TextureExtensions.FromFileData(GraphicsDevice, ElementTestDesigns.ToggleButtonIndeterminate);

            ToggleButton.CheckedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test toggle button checked design", toggleButtonChecked)
            {
                Borders = 8 * Vector4.One
            });
            ToggleButton.UncheckedImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test toggle button unchecked design", toggleButtonUnchecked)
            {
                Borders = 8 * Vector4.One
            });
            ToggleButton.IndeterminateImagePropertyKey.DefaultValueMetadata = DefaultValueMetadata.Static(new Sprite("Test toggle button indeterminate design", toggleButtonIndeterminate)
            {
                Borders = 8 * Vector4.One
            });

            Window.IsMouseVisible = true;

            SceneSystem.SceneInstance = new SceneInstance(Services, Scene);
        }
Beispiel #26
0
        private void OnTextChanged(bool update)
        {
            float  num1 = 2f;
            string str  = this.textString;

            this.textString = this.originalString;
            SpriteFont spriteFont = this.Font == SpeechFont.Pixel ? this.FontManager.Big : this.zuishFont;

            if (this.Font == SpeechFont.Zuish)
            {
                this.textString = this.textString.Replace(" ", "  ");
            }
            float scale = !Culture.IsCJK || this.Font != SpeechFont.Pixel ? 1f : this.FontManager.SmallFactor;
            bool  flag1 = this.GraphicsDevice.DisplayMode.Width < 1280 && this.Font == SpeechFont.Pixel;
            float num2  = 0.0f;

            if (this.Font != SpeechFont.Zuish)
            {
                float num3 = update ? 0.9f : 0.85f;
                num2 = FezMath.Dot(this.Origin - this.CameraManager.InterpolatedCenter, FezMath.RightVector(this.CameraManager.Viewpoint));
                float val1 = flag1 ? Math.Max((float)(-(double)num2 * 16.0 * (double)this.CameraManager.PixelsPerTrixel + 640.0 * (double)num3), 50f) * 0.6666667f : Math.Max((float)(-(double)num2 * 16.0 * (double)this.CameraManager.PixelsPerTrixel + 640.0 * (double)num3), 50f) / (this.CameraManager.PixelsPerTrixel / 2f);
                if (this.GameState.InMap)
                {
                    val1 = 500f;
                }
                float num4 = Math.Max(val1, 70f);
                List <GlyphTextRenderer.FilledInGlyph> glyphLocations;
                string text = this.GTR.FillInGlyphs(this.textString, out glyphLocations);
                if (Culture.IsCJK)
                {
                    scale /= 2f;
                }
                StringBuilder stringBuilder = new StringBuilder(WordWrap.Split(text, spriteFont, num4 / scale));
                if (Culture.IsCJK)
                {
                    scale *= 2f;
                }
                bool flag2  = true;
                int  index1 = 0;
                for (int index2 = 0; index2 < stringBuilder.Length; ++index2)
                {
                    if (flag2 && (int)stringBuilder[index2] == 94)
                    {
                        for (int startIndex = index2; startIndex < index2 + glyphLocations[index1].Length; ++startIndex)
                        {
                            if ((int)stringBuilder[startIndex] == 13 || (int)stringBuilder[startIndex] == 10)
                            {
                                stringBuilder.Remove(startIndex, 1);
                                --startIndex;
                            }
                        }
                        stringBuilder.Remove(index2, glyphLocations[index1].Length);
                        stringBuilder.Insert(index2, glyphLocations[index1].OriginalGlyph);
                        ++index1;
                    }
                    else
                    {
                        flag2 = (int)stringBuilder[index2] == 32 || (int)stringBuilder[index2] == 13 || (int)stringBuilder[index2] == 10;
                    }
                }
                this.textString = ((object)stringBuilder).ToString();
                if (!update)
                {
                    this.distanceFromCenterAtTextChange = num2;
                }
            }
            if (update && (str == this.textString || (double)Math.Abs(this.distanceFromCenterAtTextChange - num2) < 1.5))
            {
                this.textString = str;
            }
            else
            {
                if (Culture.IsCJK && this.Font == SpeechFont.Pixel)
                {
                    if ((double)SettingsManager.GetViewScale(this.GraphicsDevice) < 1.5)
                    {
                        spriteFont = this.FontManager.Small;
                    }
                    else
                    {
                        spriteFont = this.FontManager.Big;
                        scale     /= 2f;
                    }
                    scale *= num1;
                }
                bool    multilineGlyphs;
                Vector2 vector2_1 = this.GTR.MeasureWithGlyphs(spriteFont, this.textString, scale, out multilineGlyphs);
                if (!Culture.IsCJK && multilineGlyphs)
                {
                    spriteFont.LineSpacing += 8;
                    bool flag2 = multilineGlyphs;
                    vector2_1       = this.GTR.MeasureWithGlyphs(spriteFont, this.textString, scale, out multilineGlyphs);
                    multilineGlyphs = flag2;
                }
                float num3 = 1f;
                if (Culture.IsCJK && this.Font == SpeechFont.Pixel)
                {
                    num3 = num1;
                }
                this.scalableMiddleSize = vector2_1 + Vector2.One * 4f * 2f * num3 + Vector2.UnitX * 4f * 2f * num3;
                if (this.Font == SpeechFont.Zuish)
                {
                    this.scalableMiddleSize += Vector2.UnitY * 2f;
                }
                int width  = (int)this.scalableMiddleSize.X;
                int height = (int)this.scalableMiddleSize.Y;
                if (Culture.IsCJK && this.Font == SpeechFont.Pixel)
                {
                    scale  *= 2f;
                    width  *= 2;
                    height *= 2;
                }
                Vector2 vector2_2 = this.scalableMiddleSize;
                if (this.text != null)
                {
                    TextureExtensions.Unhook((Texture)this.text);
                    this.text.Dispose();
                }
                this.text = new RenderTarget2D(this.GraphicsDevice, width, height, false, this.GraphicsDevice.PresentationParameters.BackBufferFormat, this.GraphicsDevice.PresentationParameters.DepthStencilFormat, this.GraphicsDevice.PresentationParameters.MultiSampleCount, RenderTargetUsage.PreserveContents);
                this.GraphicsDevice.SetRenderTarget(this.text);
                GraphicsDeviceExtensions.PrepareDraw(this.GraphicsDevice);
                this.GraphicsDevice.Clear(ClearOptions.Target, ColorEx.TransparentWhite, 1f, 0);
                Vector2 vector2_3 = Culture.IsCJK ? new Vector2(4f * num1) : Vector2.Zero;
                if (Culture.IsCJK)
                {
                    GraphicsDeviceExtensions.BeginLinear(this.spriteBatch);
                }
                else
                {
                    GraphicsDeviceExtensions.BeginPoint(this.spriteBatch);
                }
                if (this.Font == SpeechFont.Pixel)
                {
                    this.GTR.DrawString(this.spriteBatch, spriteFont, this.textString, FezMath.Round(vector2_2 / 2f - vector2_1 / 2f + vector2_3), this.TextColor, scale);
                }
                else
                {
                    this.spriteBatch.DrawString(spriteFont, this.textString, vector2_2 / 2f - vector2_1 / 2f, this.TextColor, 0.0f, Vector2.Zero, this.scalableMiddleSize / vector2_2, SpriteEffects.None, 0.0f);
                }
                this.spriteBatch.End();
                this.GraphicsDevice.SetRenderTarget((RenderTarget2D)null);
                if (this.Font == SpeechFont.Zuish)
                {
                    float num4 = this.scalableMiddleSize.X;
                    this.scalableMiddleSize.X = this.scalableMiddleSize.Y;
                    this.scalableMiddleSize.Y = num4;
                }
                if (Culture.IsCJK && this.Font == SpeechFont.Pixel)
                {
                    this.scalableMiddleSize /= num1;
                }
                this.scalableMiddleSize   /= 16f;
                this.scalableMiddleSize   -= Vector2.One;
                this.textMesh.SamplerState = !Culture.IsCJK || this.Font != SpeechFont.Pixel ? SamplerState.PointClamp : SamplerState.AnisotropicClamp;
                this.textGroup.Texture     = (Texture)this.text;
                this.oldCamPos             = this.CameraManager.InterpolatedCenter;
                this.lastUsedOrigin        = this.Origin;
                if (Culture.IsCJK || !multilineGlyphs)
                {
                    return;
                }
                spriteFont.LineSpacing -= 8;
            }
        }
Beispiel #27
0
        protected override void LoadContent()
        {
            base.LoadContent();

            // create effect and geometric primitives
            Batch = new UIBatch(GraphicsDevice);

            // create depth stencil states
            var depthStencilDescription = new DepthStencilStateDescription(true, true)
            {
                StencilEnable = true,
                FrontFace     = new DepthStencilStencilOpDescription
                {
                    StencilDepthBufferFail = StencilOperation.Keep,
                    StencilFail            = StencilOperation.Keep,
                    StencilPass            = StencilOperation.Keep,
                    StencilFunction        = CompareFunction.Equal
                },
                BackFace = new DepthStencilStencilOpDescription
                {
                    StencilDepthBufferFail = StencilOperation.Keep,
                    StencilFail            = StencilOperation.Keep,
                    StencilPass            = StencilOperation.Keep,
                    StencilFunction        = CompareFunction.Equal
                },
            };

            KeepStencilValueState = depthStencilDescription;

            depthStencilDescription.FrontFace.StencilPass = StencilOperation.Increment;
            depthStencilDescription.BackFace.StencilPass  = StencilOperation.Increment;
            IncreaseStencilValueState = depthStencilDescription;

            depthStencilDescription.FrontFace.StencilPass = StencilOperation.Decrement;
            depthStencilDescription.BackFace.StencilPass  = StencilOperation.Decrement;
            DecreaseStencilValueState = depthStencilDescription;

            // set the default design of the UI elements.
            var designsTexture = TextureExtensions.FromFileData(GraphicsDevice, DefaultDesigns.Designs);

            DefaultResourceDictionary = new ResourceDictionary
            {
                [typeof(Button)] = new Style(typeof(Button))
                {
                    Setters =
                    {
                        new Setter <ISpriteProvider>(Button.PressedImagePropertyKey,    (SpriteFromTexture) new Sprite("Default button pressed design",     designsTexture)
                        {
                            Borders = 8 * Vector4.One,                                  Region = new RectangleF(71,                                         3, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(Button.NotPressedImagePropertyKey, (SpriteFromTexture) new Sprite("Default button not pressed design", designsTexture)
                        {
                            Borders = 8 * Vector4.One,                                  Region = new RectangleF(3,                                          3, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(Button.MouseOverImagePropertyKey,  (SpriteFromTexture) new Sprite("Default button overred design",     designsTexture)
                        {
                            Borders = 8 * Vector4.One,                                  Region = new RectangleF(37,                                         3, 32, 32)
                        }),
                    }
                },

                [typeof(EditText)] = new Style(typeof(EditText))
                {
                    Setters =
                    {
                        new Setter <ISpriteProvider>(EditText.ActiveImagePropertyKey,    (SpriteFromTexture) new Sprite("Default edit active design",   designsTexture)
                        {
                            Borders = 12 * Vector4.One,                                  Region = new RectangleF(105,                                   3, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(EditText.InactiveImagePropertyKey,  (SpriteFromTexture) new Sprite("Default edit inactive design", designsTexture)
                        {
                            Borders = 12 * Vector4.One,                                  Region = new RectangleF(139,                                   3, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(EditText.MouseOverImagePropertyKey, (SpriteFromTexture) new Sprite("Default edit overred design",  designsTexture)
                        {
                            Borders = 12 * Vector4.One,                                  Region = new RectangleF(173,                                   3, 32, 32)
                        }),
                    }
                },

                [typeof(ToggleButton)] = new Style(typeof(ToggleButton))
                {
                    Setters =
                    {
                        new Setter <ISpriteProvider>(ToggleButton.CheckedImagePropertyKey,       (SpriteFromTexture) new Sprite("Default toggle button checked design",       designsTexture)
                        {
                            Borders = 8 * Vector4.One,                                           Region = new RectangleF(71,                                                  3, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(ToggleButton.UncheckedImagePropertyKey,     (SpriteFromTexture) new Sprite("Default toggle button unchecked design",     designsTexture)
                        {
                            Borders = 8 * Vector4.One,                                           Region = new RectangleF(3,                                                   3, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(ToggleButton.IndeterminateImagePropertyKey, (SpriteFromTexture) new Sprite("Default toggle button indeterminate design", designsTexture)
                        {
                            Borders = 8 * Vector4.One,                                           Region = new RectangleF(37,                                                  3, 32, 32)
                        }),
                    }
                },

                [typeof(Slider)] = new Style(typeof(Slider))
                {
                    Setters =
                    {
                        new Setter <ISpriteProvider>(Slider.TrackBackgroundImagePropertyKey, (SpriteFromTexture) new Sprite("Default slider track background design", designsTexture)
                        {
                            Borders = 14 * Vector4.One,                                      Region = new RectangleF(207,                                              3, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(Slider.TrackForegroundImagePropertyKey, (SpriteFromTexture) new Sprite("Default slider track foreground design", designsTexture)
                        {
                            Borders = 0 * Vector4.One,                                       Region = new RectangleF(3,                                               37, 32, 32)
                        }),
                        new Setter <ISpriteProvider>(Slider.ThumbImagePropertyKey,           (SpriteFromTexture) new Sprite("Default slider thumb design",            designsTexture)
                        {
                            Borders = 4 * Vector4.One,                                       Region = new RectangleF(37,                                              37, 16, 32)
                        }),
                        new Setter <ISpriteProvider>(Slider.MouseOverThumbImagePropertyKey,  (SpriteFromTexture) new Sprite("Default slider thumb overred design",    designsTexture)
                        {
                            Borders = 4 * Vector4.One,                                       Region = new RectangleF(71,                                              37, 16, 32)
                        }),
                        new Setter <ISpriteProvider>(Slider.TickImagePropertyKey,            (SpriteFromTexture) new Sprite("Default slider track foreground design", designsTexture)
                        {
                            Region = new RectangleF(245,                                                                                                           3,  3,                                                                  6)
                        }),
                        new Setter <float>(Slider.TickOffsetPropertyKey,                                                                                        13f),
                        new Setter <Vector2>(Slider.TrackStartingOffsetsrPropertyKey,        new Vector2(3)),
                    }
                },
            };
        }
Beispiel #28
0
        public static ObjectMesh FromWad2(GraphicsDevice device, WadMesh msh, Func <WadTexture, VectorInt2> allocateTexture)
        {
            Console.WriteLine(msh.Name);
            // Initialize the mesh
            var mesh = new ObjectMesh(device, msh.Name);

            // Prepare materials
            var materialOpaque                      = new Material(Material.Material_Opaque + "_0_0_0_0", null, false, false, 0);
            var materialOpaqueDoubleSided           = new Material(Material.Material_OpaqueDoubleSided + "_0_0_1_0", null, false, true, 0);
            var materialAdditiveBlending            = new Material(Material.Material_AdditiveBlending + "_0_1_0_0", null, true, false, 0);
            var materialAdditiveBlendingDoubleSided = new Material(Material.Material_AdditiveBlendingDoubleSided + "_0_1_1_0", null, true, true, 0);

            mesh.Materials = new List <Material>();
            mesh.Materials.Add(materialOpaque);
            mesh.Materials.Add(materialOpaqueDoubleSided);
            mesh.Materials.Add(materialAdditiveBlending);
            mesh.Materials.Add(materialAdditiveBlendingDoubleSided);

            mesh.Submeshes.Add(materialOpaque, new Submesh(materialOpaque));
            mesh.Submeshes.Add(materialOpaqueDoubleSided, new Submesh(materialOpaqueDoubleSided));
            mesh.Submeshes.Add(materialAdditiveBlending, new Submesh(materialAdditiveBlending));
            mesh.Submeshes.Add(materialAdditiveBlendingDoubleSided, new Submesh(materialAdditiveBlendingDoubleSided));

            mesh.BoundingBox    = msh.BoundingBox;
            mesh.BoundingSphere = msh.BoundingSphere;

            // For some reason, wad meshes sometimes may have position count desynced from color count, so we check that too.
            var hasShades = msh.VerticesShades.Count != 0 && msh.VerticesPositions.Count == msh.VerticesShades.Count;

            for (int j = 0; j < msh.Polys.Count; j++)
            {
                WadPolygon poly = msh.Polys[j];
                Vector2    positionInPackedTexture = allocateTexture((WadTexture)poly.Texture.Texture);

                // Get the right submesh
                var submesh = mesh.Submeshes[materialOpaque];
                if (poly.Texture.BlendMode == BlendMode.Additive)
                {
                    if (poly.Texture.DoubleSided)
                    {
                        submesh = mesh.Submeshes[materialAdditiveBlendingDoubleSided];
                    }
                    else
                    {
                        submesh = mesh.Submeshes[materialAdditiveBlending];
                    }
                }
                else
                {
                    if (poly.Texture.DoubleSided)
                    {
                        submesh = mesh.Submeshes[materialOpaqueDoubleSided];
                    }
                }

                // Do half-pixel correction on texture to prevent bleeding
                var coords = poly.Texture.TexCoords;
                var shape  = (int)TextureExtensions.GetTextureShapeType(poly.Texture.TexCoords, poly.Shape == WadPolygonShape.Triangle);

                for (int i = 0; i < (poly.Shape == WadPolygonShape.Triangle /*poly.Texture.TextureIsTriangle*/ ? 3 : 4); i++)
                {
                    if (poly.Shape == WadPolygonShape.Triangle /*poly.Texture.TextureIsTriangle*/)
                    {
                        coords[i] += TextureExtensions.CompensationTris[shape, i];
                    }
                    else
                    {
                        coords[i] += TextureExtensions.CompensationQuads[shape, i];
                    }
                }

                if (poly.Shape == WadPolygonShape.Triangle)
                {
                    int v1 = poly.Index0;
                    int v2 = poly.Index1;
                    int v3 = poly.Index2;

                    PutObjectVertexAndIndex(msh.VerticesPositions[v1], msh.VerticesNormals[v1], mesh, submesh,
                                            coords[0], 0, (short)(hasShades ? msh.VerticesShades[v1] : 0),
                                            positionInPackedTexture);
                    PutObjectVertexAndIndex(msh.VerticesPositions[v2], msh.VerticesNormals[v2], mesh, submesh,
                                            coords[1], 0, (short)(hasShades ? msh.VerticesShades[v2] : 0),
                                            positionInPackedTexture);
                    PutObjectVertexAndIndex(msh.VerticesPositions[v3], msh.VerticesNormals[v3], mesh, submesh,
                                            coords[2], 0, (short)(hasShades ? msh.VerticesShades[v3] : 0),
                                            positionInPackedTexture);
                }
                else
                {
                    int v1 = poly.Index0;
                    int v2 = poly.Index1;
                    int v3 = poly.Index2;
                    int v4 = poly.Index3;

                    PutObjectVertexAndIndex(msh.VerticesPositions[v1], msh.VerticesNormals[v1], mesh, submesh,
                                            coords[0], 0, (short)(hasShades ? msh.VerticesShades[v1] : 0),
                                            positionInPackedTexture);
                    PutObjectVertexAndIndex(msh.VerticesPositions[v2], msh.VerticesNormals[v2], mesh, submesh,
                                            coords[1], 0, (short)(hasShades ? msh.VerticesShades[v2] : 0),
                                            positionInPackedTexture);
                    PutObjectVertexAndIndex(msh.VerticesPositions[v4], msh.VerticesNormals[v4], mesh, submesh,
                                            coords[3], 0, (short)(hasShades ? msh.VerticesShades[v4] : 0),
                                            positionInPackedTexture);

                    PutObjectVertexAndIndex(msh.VerticesPositions[v4], msh.VerticesNormals[v4], mesh, submesh,
                                            coords[3], 0, (short)(hasShades ? msh.VerticesShades[v4] : 0),
                                            positionInPackedTexture);
                    PutObjectVertexAndIndex(msh.VerticesPositions[v2], msh.VerticesNormals[v2], mesh, submesh,
                                            coords[1], 0, (short)(hasShades ? msh.VerticesShades[v2] : 0),
                                            positionInPackedTexture);
                    PutObjectVertexAndIndex(msh.VerticesPositions[v3], msh.VerticesNormals[v3], mesh, submesh,
                                            coords[2], 0, (short)(hasShades ? msh.VerticesShades[v3] : 0),
                                            positionInPackedTexture);
                }
            }

            mesh.UpdateBuffers();

            return(mesh);
        }
Beispiel #29
0
        private static void DrawTexturesLayer(Generator tgen, int num)
        {
            TexturesOutput200 texOut = (TexturesOutput200)tgen;

            TexturesOutput200.TextureLayer layer = texOut.layers[num];
            if (layer == null)
            {
                return;
            }

            Cell.EmptyLinePx(3);
            using (Cell.LinePx(28))
            {
                if (num != 0)
                {
                    using (Cell.RowPx(0)) GeneratorDraw.DrawInlet(layer, texOut);
                }
                else
                //disconnecting last layer inlet
                if (GraphWindow.current.graph.IsLinked(layer))
                {
                    GraphWindow.current.graph.UnlinkInlet(layer);
                }

                Cell.EmptyRowPx(10);

                Texture2D tex = layer.prototype != null ? layer.prototype.diffuseTexture : UI.current.textures.GetTexture("DPUI/Backgrounds/Empty");
                using (Cell.RowPx(28)) Draw.TextureIcon(tex);

                using (Cell.Row)
                {
                    Cell.current.trackChange = false;
                    Draw.EditableLabel(ref layer.name);
                }

                using (Cell.RowPx(20))
                {
                    Cell.current.trackChange = false;
                    Draw.LayerChevron(num, ref texOut.guiExpanded);
                }

                Cell.EmptyRowPx(10);
                using (Cell.RowPx(0)) GeneratorDraw.DrawOutlet(layer);
            }
            Cell.EmptyLinePx(2);

            if (texOut.guiExpanded == num)
            {
                using (Cell.Line)
                {
                    Cell.EmptyRowPx(2);

                    using (Cell.Row)
                    {
                        using (Cell.LinePx(0))
                            using (Cell.Padded(1, 0, 0, 0))
                            {
                                //using (Cell.LineStd) layer.Opacity = Draw.Field(layer.Opacity, "Opacity");
                                //using (Cell.LineStd) Draw.ObjectField(ref layer.prototype, "Layer");

                                Draw.Class(layer, "Layer", addFieldsToCellObjs: true);
                                //this will add terrainlayer to exposed

                                if (layer.name == "Layer" && layer.prototype != null)
                                {
                                    layer.name = layer.prototype.name;
                                }
                            }

                        if (layer.prototype != null)
                        {
                            Cell.EmptyLinePx(2);

                            using (Cell.LineStd)
                                using (new Draw.FoldoutGroup(ref layer.guiProperties, "Properties"))
                                    if (layer.guiProperties)
                                    {
                                        //textures
                                        using (Cell.LineStd)
                                        {
                                            Texture2D tex = layer.prototype.diffuseTexture;
                                            Draw.Field(ref tex, "Diffuse");
                                            if (Cell.current.valChanged)
                                            {
                                                if (layer.prototype.diffuseTexture.name == "WrColorPlaceholder2x2")
                                                {
                                                    GameObject.DestroyImmediate(layer.prototype.diffuseTexture);                             // removing temporary color texture if assigned
                                                }
                                                layer.prototype.diffuseTexture = tex;
                                            }
                                        }

                                        using (Cell.LineStd)
                                        {
                                            Texture2D tex = layer.prototype.normalMapTexture;
                                            Draw.Field(ref tex, "Normal");
                                            if (Cell.current.valChanged)
                                            {
                                                layer.prototype.normalMapTexture = tex;
                                            }
                                        }

                                        using (Cell.LineStd)
                                        {
                                            Texture2D tex = layer.prototype.maskMapTexture;
                                            Draw.Field(ref tex, "Mask");
                                            if (Cell.current.valChanged)
                                            {
                                                layer.prototype.maskMapTexture = tex;
                                            }
                                        }

                                        //color (after texture)
                                        if (layer.prototype.diffuseTexture == null)
                                        {
                                            layer.prototype.diffuseTexture      = TextureExtensions.ColorTexture(2, 2, layer.color);
                                            layer.prototype.diffuseTexture.name = "WrColorPlaceholder2x2";
                                        }

                                        if (layer.prototype.diffuseTexture.name == "WrColorPlaceholder2x2")
                                        {
                                            using (Cell.LineStd)
                                            {
                                                using (Cell.LineStd) Draw.Field(ref layer.color, "Color");
                                                if (Cell.current.valChanged)
                                                {
                                                    layer.prototype.diffuseTexture.Colorize(layer.color);
                                                }
                                            }
                                        }


                                        using (Cell.LineStd) layer.prototype.specular = Draw.Field(layer.prototype.specular, "Specular");
                                        using (Cell.LineStd) layer.prototype.smoothness = Draw.Field(layer.prototype.smoothness, "Smooth");
                                        using (Cell.LineStd) layer.prototype.metallic = Draw.Field(layer.prototype.metallic, "Metallic");
                                        using (Cell.LineStd) layer.prototype.normalScale = Draw.Field(layer.prototype.normalScale, "N. Scale");
                                    }

                            using (Cell.LineStd)
                                using (new Draw.FoldoutGroup(ref layer.guiTileSettings, "Tile Settings"))
                                    if (layer.guiTileSettings)
                                    {
                                        using (Cell.LineStd) layer.prototype.tileSize = Draw.Field(layer.prototype.tileSize, "Size");
                                        using (Cell.LineStd) layer.prototype.tileOffset = Draw.Field(layer.prototype.tileOffset, "Offset");
                                    }

                            if (layer.guiTileSettings)
                            {
                                Cell.EmptyLinePx(3);
                            }
                        }
                    }

                    /*using (UI.FoldoutGroup(ref layer.guiRemapping, "Remapping", inspectorOffset:0, margins:0))
                     * if (layer.guiTileSettings)
                     * {
                     *      using (Cell.LineStd)
                     *      {
                     *              Draw.Label("Red", cell:UI.Empty(Size.row));
                     *              layer.prototype.diffuseRemapMin.x = Draw.Field(layer.prototype.diffuseRemapMin.x, cell:UI.Empty(Size.row));
                     *      }
                     * }*/

                    Cell.EmptyRowPx(2);
                }
            }
        }