Esempio n. 1
0
        /// <summary>
        /// Checks command-line arguments
        /// </summary>
        /// <param name="arguments">Arguments</param>
        protected virtual void CheckArguments(IReadOnlyList <string> arguments)
        {
            if (arguments is null)
            {
                return;
            }

            int i = 0;

            while (i < arguments.Count - 1)
            {
                switch (arguments[i])
                {
                case ThemeOption when Enum.TryParse(arguments[i + 1], true, out ColorTheme buffer):
                    _theme = buffer;

                    RespondsThemeChanged = false;
                    i++;
                    break;

                case TextureOption when Enum.TryParse(arguments[i + 1], true, out BackgroundTexture buffer):
                    _texture = buffer;

                    i++;
                    break;

                case CornerOption when Enum.TryParse(arguments[i + 1], true, out CornerPreference buffer):
                    _corner = buffer;

                    i++;
                    break;
                }
                i++;
            }
        }
Esempio n. 2
0
        public static IEnumerable <float> GuiBackground(BackgroundTexture texture, float width, float height)
        {
            var innerWidth  = width - texture.PaddingLeft - texture.PaddingRight;
            var innerHeight = height - texture.PaddingTop - texture.PaddingBottom;

            var points = TexturedRect(new Vector2(0, 0), innerWidth, innerHeight, texture.CenterTexture).ToList();

            if (texture.PaddingLeft > 0)
            {
                points.AddRange(TexturedRect(new Vector2(-width / 2 + texture.PaddingLeft / 2, 0), texture.PaddingLeft, innerHeight, texture.LeftTexture));
            }
            if (texture.PaddingRight > 0)
            {
                points.AddRange(TexturedRect(new Vector2(width / 2 - texture.PaddingRight / 2, 0), texture.PaddingRight, innerHeight, texture.RightTexture));
            }
            if (texture.PaddingTop > 0)
            {
                points.AddRange(TexturedRect(new Vector2(0, height / 2 - texture.PaddingTop / 2), innerWidth, texture.PaddingTop, texture.TopTexture));
            }
            if (texture.PaddingBottom > 0)
            {
                points.AddRange(TexturedRect(new Vector2(0, -height / 2 + texture.PaddingTop / 2), innerWidth, texture.PaddingBottom, texture.BottomTexture));
            }

            if (texture.PaddingLeft > 0 && texture.PaddingTop > 0)
            {
                points.AddRange(TexturedRect(
                                    new Vector2(-width / 2 + texture.PaddingLeft / 2, height / 2 - texture.PaddingTop / 2),
                                    texture.PaddingLeft, texture.PaddingTop, texture.TopLeftTexture
                                    ));
            }
            if (texture.PaddingRight > 0 && texture.PaddingTop > 0)
            {
                points.AddRange(TexturedRect(
                                    new Vector2(width / 2 - texture.PaddingRight / 2, height / 2 - texture.PaddingTop / 2),
                                    texture.PaddingRight, texture.PaddingTop, texture.TopRigthTexture
                                    ));
            }
            if (texture.PaddingLeft > 0 && texture.PaddingBottom > 0)
            {
                points.AddRange(TexturedRect(
                                    new Vector2(-width / 2 + texture.PaddingLeft / 2, -height / 2 + texture.PaddingBottom / 2),
                                    texture.PaddingLeft, texture.PaddingBottom, texture.BottomLeftTexture
                                    ));
            }
            if (texture.PaddingRight > 0 && texture.PaddingBottom > 0)
            {
                points.AddRange(TexturedRect(
                                    new Vector2(width / 2 - texture.PaddingRight / 2, -height / 2 + texture.PaddingBottom / 2),
                                    texture.PaddingRight, texture.PaddingBottom, texture.BottomRigthTexture
                                    ));
            }

            return(points.SelectMany(v => new[] { v.X, v.Y }));
        }
Esempio n. 3
0
        public void SetCameraTextureName()
        {
            int id = ARUnityHelper.Instance.GetTextureId();

            m_ndkSession.SessionAdapter.SetCameraTextureName(id);
            if (BackgroundTexture == null)
            {
                BackgroundTexture = Texture2D.CreateExternalTexture(0, 0, TextureFormat.ARGB32, false,
                                                                    false, new IntPtr(id));
                return;
            }
            BackgroundTexture.UpdateExternalTexture(new IntPtr(id));
        }
Esempio n. 4
0
 private void Awake()
 {
     if (thisBackground == null)
     {
         thisBackground = this;
         videoPlayer    = GetComponent <VideoPlayer>();
         DontDestroyOnLoad(this);
     }
     else
     {
         Destroy(this.gameObject);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Function to draw the interface for the content editor.
        /// </summary>
        public override void Draw()
        {
            Renderer.Target = _swap;

            Renderer.Drawing.TextureSampler.HorizontalWrapping = TextureAddressing.Wrap;
            Renderer.Drawing.TextureSampler.VerticalWrapping   = TextureAddressing.Wrap;

            Renderer.Drawing.Blit(BackgroundTexture, _panel.ClientRectangle, BackgroundTexture.ToTexel(_panel.ClientRectangle));

            _panel.Draw();

            Renderer.Render(1);
        }
Esempio n. 6
0
        private void PrepareRenderData(int width, int height)
        {
            if (ForegroundTexture != null)
            {
                ForegroundTexture.Dispose();
            }
            ForegroundTexture = new RenderTarget2D(Game.GraphicsDevice, width, height);

            if (BackgroundTexture != null)
            {
                BackgroundTexture.Dispose();
            }
            BackgroundTexture = new RenderTarget2D(Game.GraphicsDevice, width, height);
        }
        public void TestBuilder()
        {
            LevelBuilder levelBuilder = new LevelBuilder();
            //Setup brick
            int         x          = 4;
            int         y          = 4;
            BrickStatus state      = BrickStatus.destructible;
            int         durability = 1;
            //Setup variable of level
            string            levelName  = "level1";
            PersonalSounds    music      = new PersonalSounds("musicPath", "musicTheme");
            BackgroundTexture background = new BackgroundTexture("backgroundPath", "backgroundTheme");
            BallTexture       ball       = new BallTexture("ballPath", "ballTheme");
            PaddleTexture     paddle     = new PaddleTexture("paddlePath", "paddleTheme");

            //Create level with levelBuilder
            levelBuilder.brickSelected(x, y, state, durability);
            levelBuilder.setLevelName(levelName);
            levelBuilder.SetMusic(music.GetMusicPath(), music.GetMusicTheme());
            levelBuilder.SetBackGround(background.GetBackgroundPath(), background.GetBackgroundTheme());
            levelBuilder.SetBall(ball.GetBallPath(), ball.GetBallTheme());
            levelBuilder.setPaddle(paddle.GetPaddlePath(), paddle.GetPaddleTheme());
            Level level = levelBuilder.Build();

            //Create level with classic constructor
            int height = 1, width = 1;
            ISet <BrickBasic> brick = new HashSet <BrickBasic>();

            brick.Add(new BrickBasic(new Position(x - 1, y - 1), height, width, state, durability, BrickBasic.GetDefaultBrickTexturePath()));
            Level levelTest         = new Level(levelName, brick, music, background, ball, paddle);

            //Check if all parameters are the same
            Assert.AreEqual(levelTest.GetLevelName(), level.GetLevelName());

            Assert.AreEqual(levelTest.GetBackground().GetBackgroundPath(), level.GetBackground().GetBackgroundPath());
            Assert.AreEqual(levelTest.GetBackground().GetBackgroundTheme(), level.GetBackground().GetBackgroundTheme());

            Assert.AreEqual(levelTest.GetMusic().GetMusicPath(), level.GetMusic().GetMusicPath());
            Assert.AreEqual(levelTest.GetMusic().GetMusicTheme(), level.GetMusic().GetMusicTheme());

            Assert.AreEqual(levelTest.GetBallTexture().GetBallPath(), level.GetBallTexture().GetBallPath());
            Assert.AreEqual(levelTest.GetBallTexture().GetBallTheme(), level.GetBallTexture().GetBallTheme());

            Assert.AreEqual(levelTest.GetPaddleTexture().GetPaddlePath(), level.GetPaddleTexture().GetPaddlePath());
            Assert.AreEqual(levelTest.GetPaddleTexture().GetPaddleTheme(), level.GetPaddleTexture().GetPaddleTheme());
            //Check if levels are equals
            Assert.IsTrue(levelTest.EqualLevel(level));
        }
Esempio n. 8
0
        private void _UpdateTextureIfNeeded()
        {
            // If running in editor, updates background texture from Instant Preview only.
            Texture2D previewBackgroundTexture = BackgroundTexture;

            if (InstantPreviewManager.UpdateBackgroundTextureIfNeeded(ref previewBackgroundTexture))
            {
                BackgroundTexture = previewBackgroundTexture;
                return;
            }

            IntPtr frameHandle = IntPtr.Zero;

            ExternApi.ArPresto_getFrame(ref frameHandle);

            int backgroundTextureId = ExternApi.ArCoreUnity_getBackgroundTextureId();

            if (frameHandle == IntPtr.Zero)
            {
                // This prevents using a texture that has not been filled out by ARCore.
                return;
            }
            else if (backgroundTextureId == -1)
            {
                return;
            }
            else if (BackgroundTexture != null &&
                     BackgroundTexture.GetNativeTexturePtr().ToInt32() == backgroundTextureId)
            {
                return;
            }
            else if (BackgroundTexture == null)
            {
                // The Unity-cached size and format of the texture (0x0, ARGB) is not the
                // actual format of the texture. This is okay because the texture is not
                // accessed by pixels, it is accessed with UV coordinates.
                BackgroundTexture = Texture2D.CreateExternalTexture(0, 0, TextureFormat.ARGB32, false,
                                                                    false, new IntPtr(backgroundTextureId));
                return;
            }

            BackgroundTexture.UpdateExternalTexture(new IntPtr(backgroundTextureId));
        }
Esempio n. 9
0
        public static IEnumerable <float> GuiBackground(BackgroundTexture texture, float width, float height)
        {
            var polygonPoints     = texture.SlicePolygon(width, height).ToList();
            var texturePoints     = texture.SliceTexture().ToList();
            var points            = new List <Vector2>();
            var spriteTextureSize = TextureUtils.TextureSize(texture.Sprite.Id);

            for (int i = 0; i < polygonPoints.Count; i += 4)
            {
                var textureMin  = texturePoints[i + 0];
                var textureMax  = texturePoints[i + 2];
                var textureSize = textureMax - textureMin;
                var polygonSize = polygonPoints[i + 2] - polygonPoints[i + 0];

                var textureCenter = (textureMax + textureMin) / 2;
                var widthDir      = new Vector2(Math.Min(polygonSize.X, textureSize.X * spriteTextureSize.X) / spriteTextureSize.X, 0);
                var heightDir     = new Vector2(0, Math.Min(polygonSize.Y, textureSize.Y * spriteTextureSize.Y) / spriteTextureSize.Y);

                points.Add(polygonPoints[i + 3]);
                points.Add(textureCenter - widthDir / 2 + heightDir / 2);

                points.Add(polygonPoints[i + 2]);
                points.Add(textureCenter + widthDir / 2 + heightDir / 2);

                points.Add(polygonPoints[i + 1]);
                points.Add(textureCenter + widthDir / 2 - heightDir / 2);


                points.Add(polygonPoints[i + 1]);
                points.Add(textureCenter + widthDir / 2 - heightDir / 2);

                points.Add(polygonPoints[i + 0]);
                points.Add(textureCenter - widthDir / 2 - heightDir / 2);

                points.Add(polygonPoints[i + 3]);
                points.Add(textureCenter - widthDir / 2 + heightDir / 2);
            }

            return(points.SelectMany(v => new[] { v.X, v.Y }));
        }
Esempio n. 10
0
        private void InitializeTextures()
        {
            BackgroundTexture.SetPixel(0, 0, Colors.WindowBackground);
            BackgroundTexture.Apply();

            ResizeHandleNormalTexture.SetPixel(0, 0, Colors.WindowBorder);
            ResizeHandleNormalTexture.Apply();

            ResizeHandleHoverTexture.SetPixel(0, 0, Colors.WindowBorderHovered);
            ResizeHandleHoverTexture.Apply();

            CloseButtonNormalTexture.SetPixel(0, 0, Colors.CloseButton);
            CloseButtonNormalTexture.Apply();

            CloseButtonHoverTexture.SetPixel(0, 0, Colors.CloseButtonHovered);
            CloseButtonHoverTexture.Apply();

            WindowBorderNormalTexture.SetPixel(0, 0, Colors.WindowBorder);
            WindowBorderNormalTexture.Apply();

            WindowBorderHoverTexture.SetPixel(0, 0, Colors.WindowBorderHovered);
            WindowBorderHoverTexture.Apply();
        }
Esempio n. 11
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    GorgonSpriteEditorPlugIn.Settings.Save();

                    // Clear any external dependencies.
                    EditorFile = null;

                    if (BackgroundTexture != null)
                    {
                        BackgroundTexture.Dispose();
                    }

                    if (_swap != null)
                    {
                        _swap.Dispose();
                    }

                    if (Renderer != null)
                    {
                        Renderer.Dispose();
                    }
                }
            }

            _disposed         = true;
            Texture           = null;
            BackgroundTexture = null;
            Renderer          = null;
            _swap             = null;

            base.Dispose(disposing);
        }
 public override void Draw(float transitionAlpha, float backgroundTransitionAlpha)
 {
     BackgroundTexture.Draw(GetPositionAbsoluteTopLeft(), Size, ApplyColorMaskModifiers(ColorMask, Enabled, backgroundTransitionAlpha));
     DrawBorder(transitionAlpha);
 }
Esempio n. 13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="device"></param>
 public override void Draw()
 {
     BackgroundTexture.Blit(GameBase.Window.Rectangle, BackgroundTexture.Bounds);
 }
Esempio n. 14
0
 /// <summary>
 ///
 /// </summary>
 public override void LoadContent()
 {
     BackgroundTexture = GameBase.Device.CreateTexture();
     BackgroundTexture.LoadImage("background.png");
 }
Esempio n. 15
0
        /// <summary>
        /// Function to draw the magnification window.
        /// </summary>
        public void Draw()
        {
            var texturePosition = new Vector2(Position.X - _zoomSize.X * 0.5f, Position.Y - _zoomSize.Y * 0.5f);
            var clientRect      = new RectangleF(ZoomWindowLocation.X + 1,
                                                 ZoomWindowLocation.Y + _captionHeight,
                                                 _sprite.Size.X,
                                                 _sprite.Size.Y);

            _renderer.Drawing.BlendingMode = BlendingMode.Modulate;

            _renderer.Drawing.FilledRectangle(new RectangleF(ZoomWindowLocation, _windowSize), GorgonColor.Black);

            if (BackgroundTexture != null)
            {
                _renderer.Drawing.FilledRectangle(clientRect,
                                                  GorgonColor.White,
                                                  BackgroundTexture,
                                                  new RectangleF(Vector2.Zero, BackgroundTexture.ToTexel(ZoomWindowSize)));

                // Only draw the overlay if it's in view of the clip region.
                var overlayRegion = new RectangleF(-texturePosition.X * _zoom + clientRect.X,
                                                   -texturePosition.Y * _zoom + clientRect.Y,
                                                   _texture.Settings.Width * _zoom,
                                                   _texture.Settings.Height * _zoom);

                if (overlayRegion.IntersectsWith(clientRect))
                {
                    overlayRegion = RectangleF.Intersect(overlayRegion, clientRect);

                    _renderer.Drawing.FilledRectangle(overlayRegion, new GorgonColor(0, 0, 0, 0.25f));
                }
            }

            _renderer.Drawing.FilledRectangle(new RectangleF(ZoomWindowLocation.X + 1, ZoomWindowLocation.Y + 1, _windowSize.X - 2, _captionHeight - 2), GorgonColor.White);
            _renderer.Drawing.DrawString(ZoomWindowFont ?? _renderer.Graphics.Fonts.DefaultFont,
                                         string.Format("{0}: {1:0.0}x", ZoomWindowText, _zoom),
                                         (Point)ZoomWindowLocation,
                                         GorgonColor.Black);

            _sprite.TextureOffset = _texture.ToTexel(texturePosition);
            _sprite.Position      = clientRect.Location;
            _sprite.Draw();

            BlendingMode prevBlend = _renderer.Drawing.BlendingMode;

            _renderer.Drawing.BlendingMode = BlendingMode.Inverted;

            var halfWindow = new Vector2((clientRect.Width * 0.5f) + clientRect.Left, (clientRect.Height * 0.5f) + clientRect.Top);

            _renderer.Drawing.DrawLine(new Vector2(halfWindow.X, clientRect.Top), new Vector2(halfWindow.X, clientRect.Bottom), GorgonColor.White);
            _renderer.Drawing.DrawLine(new Vector2(clientRect.Left, halfWindow.Y), new Vector2(clientRect.Right, halfWindow.Y), GorgonColor.White);

            _renderer.Drawing.BlendingMode = prevBlend;

            if (Clipper == null)
            {
                return;
            }

            var clipArea = new RectangleF((Clipper.ClipRegion.X - texturePosition.X) * _zoom + clientRect.X,
                                          (Clipper.ClipRegion.Y - texturePosition.Y) * _zoom + clientRect.Y,
                                          Clipper.ClipRegion.Width * _zoom,
                                          Clipper.ClipRegion.Height * _zoom);

            // Only draw the clip area if it intersects with the client area.
            if (!clipArea.IntersectsWith(clientRect))
            {
                return;
            }

            Vector2 prevPosition = Clipper.SelectionSprite.Position;
            Vector2 prevSize     = Clipper.SelectionSprite.Size;

            clipArea = RectangleF.Intersect(clipArea, clientRect);

            Clipper.SelectionSprite.Size     = clipArea.Size;
            Clipper.SelectionSprite.Position = clipArea.Location;
            Clipper.SelectionSprite.Draw();

            _renderer.Drawing.DrawRectangle(new RectangleF(clipArea.X, clipArea.Y, clipArea.Width, clipArea.Height - 1),
                                            new GorgonColor(Clipper.SelectorColor, 1.0f));

            Clipper.SelectionSprite.Size     = prevSize;
            Clipper.SelectionSprite.Position = prevPosition;
        }