Ejemplo n.º 1
0
        protected override void DispatchDraw(Canvas canvas)
        {
            if (!_isFoldPrepared || FloatNearlyEqual(_foldFactor, 0))
            {
                base.DispatchDraw(canvas);
                return;
            }

            if (!_shouldDraw)
                return;

            for (var x = 0; x < _numberOfFolds; x++)
            {
                var src = _foldRectArray[x];

                canvas.Save();

                canvas.Concat(_matrix[x]);

                if (Build.VERSION.SdkInt == BuildVersionCodes.JellyBeanMr2)
                {
                    _dstRect.Set(0, 0, src.Width(), src.Height());
                    canvas.DrawBitmap(_fullBitmap, src, _dstRect, null);
                }
                else
                {
                    canvas.ClipRect(0, 0, src.Right - src.Left, src.Bottom - src.Top);

                    if (_isHorizontal)
                        canvas.Translate(-src.Left, 0);
                    else
                        canvas.Translate(0, -src.Top);

                    base.DispatchDraw(canvas);

                    if (_isHorizontal)
                        canvas.Translate(src.Left, 0);
                    else
                        canvas.Translate(0, src.Top);
                }

                canvas.DrawRect(0, 0, _foldDrawWidth, _foldDrawHeight, x % 2 == 0 ? _solidShadow : _gradientShadow);

                canvas.Restore();
            }
        }
Ejemplo n.º 2
0
        protected override void DispatchDraw(Canvas canvas)
        {
            // do zoom

            zoom = Lerp(Bias(zoom, smoothZoom, 0.05f), smoothZoom, 0.2f);
            smoothZoomX = Clamp(0.5f * Width / smoothZoom, smoothZoomX, Width - 0.5f * Width / smoothZoom);
            smoothZoomY = Clamp(0.5f * Height / smoothZoom, smoothZoomY, Height - 0.5f * Height / smoothZoom);

            zoomX = Lerp(Bias(zoomX, smoothZoomX, 0.1f), smoothZoomX, 0.35f);
            zoomY = Lerp(Bias(zoomY, smoothZoomY, 0.1f), smoothZoomY, 0.35f);
            if (zoom != smoothZoom && listener != null)
            {
                listener.onZooming(zoom, zoomX, zoomY);
            }

            bool animating = Math.Abs(zoom - smoothZoom) > 0.0000001f
                             || Math.Abs(zoomX - smoothZoomX) > 0.0000001f || Math.Abs(zoomY - smoothZoomY) > 0.0000001f;

            // nothing to draw
            if (ChildCount == 0)
            {
                return;
            }

            // prepare matrix
            matrix.SetTranslate(0.5f * Width, 0.5f * Height);
            matrix.PreScale(zoom, zoom);
            matrix.PreTranslate(-Clamp(0.5f * Width / zoom, zoomX, Width - 0.5f * Width / zoom),
                -Clamp(0.5f * Height / zoom, zoomY, Height - 0.5f * Height / zoom));

            // get view
            View v = GetChildAt(0);
            matrix.PreTranslate(v.Left, v.Top);

            // get drawing cache if available
            if (animating && ch == null)
            {
                v.SetLayerType(LayerType.Hardware, paint);
                v.DrawingCacheEnabled = true;
                ch = v.DrawingCache;
            }

            // draw using cache while animating
            if (animating && ch != null && !ch.IsRecycled)
            {
                paint.Color = new Color(unchecked((int)0xffffffff));
                canvas.DrawBitmap(ch, matrix, paint);
            }
            else
            { // zoomed or cache unavailable
                ch = null;
                canvas.Save();
                canvas.Concat(matrix);
                v.Draw(canvas);
                canvas.Restore();
            }

            // draw minimap
            if (ShowMiniMap)
            {
                if (Map.Height < 0)
                {
                    Map.Height = Height / 4;
                }

                canvas.Translate(10.0f, 10.0f);
                paint.Color = new Color((int)(0x80000000 | 0x00ffffff & Map.Color));
                float w = Map.Height * (float)Width / Height;
                float h = Map.Height;
                canvas.DrawRect(0.0f, 0.0f, w, h, paint);

                if (!string.IsNullOrEmpty(Map.Caption))
                {
                    paint.TextSize = Map.CaptionSize;
                    paint.Color = Map.CaptionColor;
                    paint.AntiAlias = true;
                    canvas.DrawText(Map.Caption, 10.0f, 10.0f + Map.CaptionSize, paint);
                    paint.AntiAlias = false;
                }

                paint.Color = new Color((int)(0x80000000 | 0x00ffffff & Map.CaptionColor));
                float dx = w * zoomX / Width;
                float dy = h * zoomY / Height;
                canvas.DrawRect(dx - 0.5f * w / zoom, dy - 0.5f * h / zoom, dx + 0.5f * w / zoom, dy + 0.5f * h / zoom, paint);

                canvas.Translate(-10.0f, -10.0f);
            }

            // redraw
            if (animating)
            {
                RootView.Invalidate();
                Invalidate();
            }
        }