Example #1
0
        public WindowManager(Viewer viewer)
        {
            Viewer = viewer ?? throw new ArgumentNullException(nameof(viewer));

            WindowManagerMaterial      = new BasicBlendedMaterial(viewer, "WindowManager");
            PopupWindowMaterial        = (PopupWindowMaterial)Viewer.MaterialManager.Load("PopupWindow");
            TextManager                = new WindowTextManager();
            TextFontDefault            = TextManager.GetScaled("Arial", 10, System.Drawing.FontStyle.Regular);
            TextFontDefaultBold        = TextManager.GetScaled("Arial", 10, System.Drawing.FontStyle.Bold);
            TextFontDefaultOutlined    = TextManager.GetScaled("Arial", 10, System.Drawing.FontStyle.Regular, 1);
            TextFontMonoSpacedBold     = TextManager.GetScaled("Consolas", 11.29f, System.Drawing.FontStyle.Bold);
            TextFontMonoSpacedOutlined = TextManager.GetScaled("Consolas", 10, System.Drawing.FontStyle.Regular, 1);
            TextFontSmall              = TextManager.GetScaled("Arial", 8, System.Drawing.FontStyle.Regular);
            TextFontSmallOutlined      = TextManager.GetScaled("Arial", 8, System.Drawing.FontStyle.Regular, 1);

            SpriteBatch = new SpriteBatch(Viewer.RenderProcess.GraphicsDevice);

            if (WhiteTexture == null)
            {
                WhiteTexture = new Texture2D(Viewer.RenderProcess.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                WhiteTexture.SetData(new[] { Color.White });
            }
            if (FlushTexture == null)
            {
                FlushTexture = new Texture2D(Viewer.RenderProcess.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                FlushTexture.SetData(new[] { Color.Transparent });
            }
            if (ScrollbarTexture == null)
            {
                // TODO: This should happen on the loader thread.
                ScrollbarTexture = SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Viewer.ContentPath, "WindowScrollbar.png"));
            }
            if (LabelShadowTexture == null)
            {
                // TODO: This should happen on the loader thread.
                LabelShadowTexture = SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Viewer.ContentPath, "WindowLabelShadow.png"));
            }
            if (NoticeTexture == null)
            {
                var size         = 256;
                var background   = Color.Black * 0.5f;
                var borderRadius = size / 7;
                var data         = new Color[size * size * 2];

                // Rounded corner background.
                for (var y = 0; y < size; y++)
                {
                    for (var x = 0; x < size; x++)
                    {
                        if ((x > borderRadius && x < size - borderRadius) || (y > borderRadius && y < size - borderRadius) ||
                            (Math.Sqrt((x - borderRadius) * (x - borderRadius) + (y - borderRadius) * (y - borderRadius)) < borderRadius) ||
                            (Math.Sqrt((x - size + borderRadius) * (x - size + borderRadius) + (y - borderRadius) * (y - borderRadius)) < borderRadius) ||
                            (Math.Sqrt((x - borderRadius) * (x - borderRadius) + (y - size + borderRadius) * (y - size + borderRadius)) < borderRadius) ||
                            (Math.Sqrt((x - size + borderRadius) * (x - size + borderRadius) + (y - size + borderRadius) * (y - size + borderRadius)) < borderRadius))
                        {
                            data[y * size + x] = background;
                        }
                    }
                }

                // Notice texture is just the rounded corner background.
                NoticeTexture = new Texture2D(Viewer.RenderProcess.GraphicsDevice, size, size, false, SurfaceFormat.Color);
                NoticeTexture.SetData(data, 0, size * size);

                // Clone the background for pause texture (it has two states).
                Array.Copy(data, 0, data, size * size, size * size);

                // Play ">" symbol.
                for (var y = size / 7; y < size - size / 7; y++)
                {
                    for (var x = size / 7; x < size - size / 7 - 2 * Math.Abs(y - size / 2); x++)
                    {
                        data[y * size + x] = Color.White;
                    }
                }

                // Pause "||" symbol.
                for (var y = size + size / 7; y < 2 * size - size / 7; y++)
                {
                    for (var x = size * 2 / 7; x < size * 3 / 7; x++)
                    {
                        data[y * size + x] = Color.White;
                    }
                    for (var x = size * 4 / 7; x < size * 5 / 7; x++)
                    {
                        data[y * size + x] = Color.White;
                    }
                }

                PauseTexture = new Texture2D(Viewer.RenderProcess.GraphicsDevice, size, size * 2, false, SurfaceFormat.Color);
                PauseTexture.SetData(data);
            }

            viewer.UserCommandController.AddEvent(CommonUserCommand.PointerPressed, MouseClickedEvent);
            viewer.UserCommandController.AddEvent(CommonUserCommand.PointerDown, MouseDownEvent);
            viewer.UserCommandController.AddEvent(CommonUserCommand.PointerReleased, MouseReleasedEvent);
            viewer.UserCommandController.AddEvent(CommonUserCommand.PointerDragged, MouseDraggingEvent);
            viewer.UserCommandController.AddEvent(CommonUserCommand.VerticalScrollChanged, WindowScrollEvent);
        }
        public WindowManager(Viewer viewer)
        {
            Viewer = viewer;
            WindowManagerMaterial   = new BasicBlendedMaterial(viewer, "WindowManager");
            PopupWindowMaterial     = (PopupWindowMaterial)Viewer.MaterialManager.Load("PopupWindow");
            TextManager             = new WindowTextManager();
            TextFontDefault         = TextManager.GetScaled("Arial", 10, System.Drawing.FontStyle.Regular);
            TextFontDefaultOutlined = TextManager.GetScaled("Arial", 10, System.Drawing.FontStyle.Regular, 1);
            TextFontSmall           = TextManager.GetScaled("Arial", 8, System.Drawing.FontStyle.Regular);
            TextFontSmallOutlined   = TextManager.GetScaled("Arial", 8, System.Drawing.FontStyle.Regular, 1);

            SpriteBatch = new SpriteBatch(Viewer.GraphicsDevice);

            if (WhiteTexture == null)
            {
                WhiteTexture = new Texture2D(Viewer.GraphicsDevice, 1, 1, 1, TextureUsage.None, SurfaceFormat.Color);
                WhiteTexture.SetData(new[] { Color.White });
            }
            if (FlushTexture == null)
            {
                FlushTexture = new Texture2D(Viewer.GraphicsDevice, 1, 1, 1, TextureUsage.None, SurfaceFormat.Color);
                FlushTexture.SetData(new[] { Color.TransparentBlack });
            }
            if (ScrollbarTexture == null)
            {
                // TODO: This should happen on the loader thread.
                ScrollbarTexture = SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Viewer.ContentPath, "WindowScrollbar.png"));
            }
            if (LabelShadowTexture == null)
            {
                // TODO: This should happen on the loader thread.
                LabelShadowTexture = SharedTextureManager.Get(Viewer.RenderProcess.GraphicsDevice, System.IO.Path.Combine(Viewer.ContentPath, "WindowLabelShadow.png"));
            }
            if (NoticeTexture == null)
            {
                var size         = 256;
                var background   = new Color(Color.Black, 0.5f);
                var borderRadius = size / 7;
                var data         = new Color[size * size * 2];

                // Rounded corner background.
                for (var y = 0; y < size; y++)
                {
                    for (var x = 0; x < size; x++)
                    {
                        if ((x > borderRadius && x < size - borderRadius) || (y > borderRadius && y < size - borderRadius) ||
                            (Math.Sqrt((x - borderRadius) * (x - borderRadius) + (y - borderRadius) * (y - borderRadius)) < borderRadius) ||
                            (Math.Sqrt((x - size + borderRadius) * (x - size + borderRadius) + (y - borderRadius) * (y - borderRadius)) < borderRadius) ||
                            (Math.Sqrt((x - borderRadius) * (x - borderRadius) + (y - size + borderRadius) * (y - size + borderRadius)) < borderRadius) ||
                            (Math.Sqrt((x - size + borderRadius) * (x - size + borderRadius) + (y - size + borderRadius) * (y - size + borderRadius)) < borderRadius))
                        {
                            data[y * size + x] = background;
                        }
                    }
                }

                // Notice texture is just the rounded corner background.
                NoticeTexture = new Texture2D(Viewer.GraphicsDevice, size, size, 1, TextureUsage.None, SurfaceFormat.Color);
                NoticeTexture.SetData(data, 0, size * size, SetDataOptions.Discard);

                // Clone the background for pause texture (it has two states).
                Array.Copy(data, 0, data, size * size, size * size);

                // Play ">" symbol.
                for (var y = size / 7; y < size - size / 7; y++)
                {
                    for (var x = size / 7; x < size - size / 7 - 2 * Math.Abs(y - size / 2); x++)
                    {
                        data[y * size + x] = Color.White;
                    }
                }

                // Pause "||" symbol.
                for (var y = size + size / 7; y < 2 * size - size / 7; y++)
                {
                    for (var x = size * 2 / 7; x < size * 3 / 7; x++)
                    {
                        data[y * size + x] = Color.White;
                    }
                    for (var x = size * 4 / 7; x < size * 5 / 7; x++)
                    {
                        data[y * size + x] = Color.White;
                    }
                }

                PauseTexture = new Texture2D(Viewer.GraphicsDevice, size, size * 2, 1, TextureUsage.None, SurfaceFormat.Color);
                PauseTexture.SetData(data);
            }
        }