public ViewportBoundingBoxes(IViewport viewport)
 {
     IsDirty                   = true;
     _viewport                 = viewport;
     BoundingBoxes             = new AGSBoundingBoxes();
     viewport.PropertyChanged += onViewportChanged;
 }
Example #2
0
 public void CopyFrom(AGSBoundingBoxes boxes)
 {
     RenderBox        = boxes.RenderBox;
     HitTestBox       = boxes.HitTestBox;
     PreCropRenderBox = boxes.PreCropRenderBox;
     TextureBox       = boxes.TextureBox;
 }
Example #3
0
        public AGSTextComponent(IRenderPipeline pipeline, IBoundingBoxBuilder boundingBoxBuilder,
                                IGLTextureRenderer textureRenderer, BitmapPool bitmapPool,
                                AGSBoundingBoxes labelBoundingBoxes, AGSBoundingBoxes textBoundingBoxes,
                                IGLUtils glUtils, IGraphicsBackend graphics, IFontFactory fonts,
                                IRuntimeSettings settings, IRenderMessagePump messagePump, IGameState state, IGameEvents events)
        {
            _pipeline = pipeline;
            _afterCropTextBoundingBoxes = new AGSBoundingBoxes();
            _state                       = state;
            _events                      = events;
            Width                        = 1f;
            Height                       = 1f;
            _matricesPool                = new GLMatrices[3];
            _messagePump                 = messagePump;
            OnLabelSizeChanged           = new AGSEvent();
            _graphics                    = graphics;
            _fonts                       = fonts;
            _bitmapPool                  = bitmapPool;
            _labelBoundingBoxes          = labelBoundingBoxes;
            _textBoundingBoxes           = textBoundingBoxes;
            _boundingBoxBuilder          = boundingBoxBuilder;
            _virtualResolution           = settings.VirtualResolution;
            _settings                    = settings;
            _labelBoundingBoxFakeBuilder = new BoundingBoxesEmptyBuilder();

            _instructionPool = new ObjectPool <Instruction>(pool => new Instruction(pool, glUtils, textureRenderer, _glTextHitTest), 0);

            TextVisible = true;

            subscribeTextConfigChanges();
            PropertyChanged           += onPropertyChanged;
            _shouldUpdateBoundingBoxes = true;
        }
Example #4
0
 public void CopyFrom(AGSBoundingBoxes boxes)
 {
     ViewportBox        = boxes.ViewportBox;
     WorldBox           = boxes.WorldBox;
     PreCropViewportBox = boxes.PreCropViewportBox;
     TextureBox         = boxes.TextureBox;
 }
Example #5
0
 public bool Equals(AGSBoundingBoxes boxes)
 {
     if (this == boxes)
     {
         return(true);
     }
     if (boxes == null)
     {
         return(false);
     }
     if (TextureBox == null && boxes.TextureBox != null)
     {
         return(false);
     }
     if (TextureBox != null && boxes.TextureBox == null)
     {
         return(false);
     }
     if (TextureBox != null && !TextureBox.Equals(boxes.TextureBox))
     {
         return(false);
     }
     return(RenderBox.Equals(boxes.RenderBox) && HitTestBox.Equals(boxes.HitTestBox) &&
            PreCropRenderBox.Equals(boxes.PreCropRenderBox));
 }
Example #6
0
 public bool Equals(AGSBoundingBoxes boxes)
 {
     if (this == boxes)
     {
         return(true);
     }
     if (boxes == null)
     {
         return(false);
     }
     if (TextureBox == null && boxes.TextureBox != null)
     {
         return(false);
     }
     if (TextureBox != null && boxes.TextureBox == null)
     {
         return(false);
     }
     if (TextureBox != null && !TextureBox.Equals(boxes.TextureBox))
     {
         return(false);
     }
     return(ViewportBox.Equals(boxes.ViewportBox) && WorldBox.Equals(boxes.WorldBox) &&
            PreCropViewportBox.Equals(boxes.PreCropViewportBox));
 }
Example #7
0
        private void updateBoundingBoxes(GLText glText, AutoFit autoFit, IGLMatrices textMatrices, IGLMatrices labelMatrices, PointF textScaleUp, PointF textScaleDown, PointF labelResolutionFactor, bool buildRenderBox, bool buildHitTestBox)
        {
            switch (autoFit)
            {
            case AutoFit.NoFitting:
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, BaseSize.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(glText, buildRenderBox, BaseSize, textScaleUp, textScaleDown, int.MaxValue);
                build(_textBoundingBoxes, glText.BitmapWidth, glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldWrapAndLabelShouldFitHeight:
                build(_textBoundingBoxes, glText.BitmapWidth, glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, glText.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldFitLabel:
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, BaseSize.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(glText, buildRenderBox, glText.Width > BaseSize.Width ? new SizeF(0f, BaseSize.Height) : BaseSize, textScaleUp, textScaleDown, int.MaxValue);

                float textWidth  = glText.Width < BaseSize.Width ? glText.BitmapWidth : MathUtils.Lerp(0f, 0f, glText.Width, BaseSize.Width, glText.BitmapWidth);
                float textHeight = glText.Height < BaseSize.Height ? glText.BitmapHeight : MathUtils.Lerp(0f, 0f, glText.Height, BaseSize.Height, glText.BitmapHeight);

                build(_textBoundingBoxes, textWidth, textHeight, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.LabelShouldFitText:
                build(_textBoundingBoxes, glText.BitmapWidth, glText.BitmapHeight, textMatrices, buildRenderBox, buildHitTestBox);
                build(_labelBoundingBoxes, glText.Width / labelResolutionFactor.X, glText.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            case AutoFit.TextShouldCrop:
                build(_labelBoundingBoxes, BaseSize.Width / labelResolutionFactor.X, BaseSize.Height / labelResolutionFactor.Y, labelMatrices, buildRenderBox, buildHitTestBox);
                updateText(glText, buildRenderBox, glText.Width > BaseSize.Width ? GLText.EmptySize : new SizeF(BaseSize.Width, GLText.EmptySize.Height), textScaleUp, textScaleDown, (int)BaseSize.Width, true);

                float heightOfText = glText.Height < BaseSize.Height ? glText.BitmapHeight : MathUtils.Lerp(0f, 0f, glText.Height, BaseSize.Height, glText.BitmapHeight);

                build(_textBoundingBoxes, glText.BitmapWidth, heightOfText, textMatrices, buildRenderBox, buildHitTestBox);

                _usedLabelBoundingBoxes = _labelBoundingBoxes;
                _usedTextBoundingBoxes  = _textBoundingBoxes;
                break;

            default:
                throw new NotSupportedException(autoFit.ToString());
            }
        }
Example #8
0
        private float getSliderValue(float handlePos, AGSBoundingBoxes boundingBoxes)
        {
            float min = isReverse() ? MaxValue : MinValue;
            float max = isReverse() ? MinValue : MaxValue;

            return(MathUtils.Lerp(0f, min, isHorizontal() ?
                                  boundingBoxes.HitTestBox.Width : boundingBoxes.HitTestBox.Height,
                                  max, handlePos));
        }
        private static void setProportionalTextureSize(AGSBoundingBoxes boundingBoxes,
                                                       IImage image, float width, float height, PointF textureOffset)
        {
            float left   = textureOffset.X;
            float top    = textureOffset.Y;
            float right  = width / image.Width + textureOffset.X;
            float bottom = height / image.Height + textureOffset.Y;

            boundingBoxes.TextureBox = new FourCorners <Vector2>(new Vector2(left, bottom), new Vector2(right, bottom),
                                                                 new Vector2(left, top), new Vector2(right, top));
        }
Example #10
0
 public void Render(int texture, AGSBoundingBoxes boundingBoxes, IGLColor color)
 {
     if (boundingBoxes.TextureBox == null)
     {
         _glUtils.DrawQuad(texture, boundingBoxes.RenderBox, color.R, color.G, color.B, color.A);
     }
     else
     {
         _glUtils.DrawQuad(texture, boundingBoxes.RenderBox, color, boundingBoxes.TextureBox);
     }
 }
Example #11
0
#pragma warning restore CS0067

        public GLLabelRenderer(Dictionary <string, ITexture> textures,
                               IBoundingBoxBuilder boundingBoxBuilder, IGLColorBuilder colorBuilder,
                               IGLTextureRenderer textureRenderer, BitmapPool bitmapPool, IGLViewportMatrixFactory viewportMatrix,
                               AGSBoundingBoxes labelBoundingBoxes, AGSBoundingBoxes textBoundingBoxes, IGraphicsFactory graphicsFactory,
                               IGLUtils glUtils, IGraphicsBackend graphics, IBitmapLoader bitmapLoader, IFontLoader fonts,
                               IRuntimeSettings settings, IRenderMessagePump messagePump, IGameState state, IGameEvents events)
        {
            _bindings = new List <IComponentBinding>();
            _afterCropTextBoundingBoxes = new AGSBoundingBoxes();
            _state                       = state;
            _events                      = events;
            Width                        = 1f;
            Height                       = 1f;
            _matricesPool                = new GLMatrices[3];
            _messagePump                 = messagePump;
            OnLabelSizeChanged           = new AGSEvent();
            _glUtils                     = glUtils;
            _graphics                    = graphics;
            _fonts                       = fonts;
            _bitmapPool                  = bitmapPool;
            _viewport                    = viewportMatrix;
            _textureRenderer             = textureRenderer;
            _labelBoundingBoxes          = labelBoundingBoxes;
            _textBoundingBoxes           = textBoundingBoxes;
            _boundingBoxBuilder          = boundingBoxBuilder;
            _virtualResolution           = settings.VirtualResolution;
            _settings                    = settings;
            _labelBoundingBoxFakeBuilder = new BoundingBoxesEmptyBuilder();
            _bgRenderer                  = new GLImageRenderer(textures,
                                                               colorBuilder, _textureRenderer, graphicsFactory, glUtils, bitmapLoader);

            _colorBuilder = colorBuilder;

            TextVisible           = true;
            TextBackgroundVisible = true;

            subscribeTextConfigChanges();
            PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(TextBackgroundVisible))
                {
                    return;
                }
                onBoundingBoxShouldChange();
                if (e.PropertyName == nameof(Config))
                {
                    subscribeTextConfigChanges();
                }
            };
            _shouldUpdateBoundingBoxes = true;
        }
Example #12
0
        private void build(AGSBoundingBoxes boxes, float width, float height, IGLMatrices matrices, bool buildRenderBox, bool buildHitTestBox)
        {
            var modelMatrix     = matrices.ModelMatrix;
            var intermediateBox = _boundingBoxBuilder.BuildIntermediateBox(width, height, ref modelMatrix);

            if (buildHitTestBox)
            {
                boxes.HitTestBox = _boundingBoxBuilder.BuildHitTestBox(ref intermediateBox);
            }
            if (buildRenderBox)
            {
                PointF scale;
                var    viewportMatrix = matrices.ViewportMatrix;
                boxes.RenderBox = _boundingBoxBuilder.BuildRenderBox(ref intermediateBox, ref viewportMatrix, out scale);
            }
        }