コード例 #1
0
        private Path CreateFishPath(float fishCenterX, float fishCenterY)
        {
            Path path = new Path();

            float fishHeadX = fishCenterX;
            float fishHeadY = fishCenterY - mFishHeight / 2.0f;

            //the head of the fish
            path.MoveTo(fishHeadX, fishHeadY);
            //the left body of the fish
            path.QuadTo(fishHeadX - mFishWidth * 0.333f, fishHeadY + mFishHeight * 0.222f, fishHeadX - mFishWidth * 0.333f, fishHeadY + mFishHeight * 0.444f);
            path.LineTo(fishHeadX - mFishWidth * 0.333f, fishHeadY + mFishHeight * 0.666f);
            path.LineTo(fishHeadX - mFishWidth * 0.5f, fishHeadY + mFishHeight * 0.8f);
            path.LineTo(fishHeadX - mFishWidth * 0.5f, fishHeadY + mFishHeight);

            //the tail of the fish
            path.LineTo(fishHeadX, fishHeadY + mFishHeight * 0.9f);

            //the right body of the fish
            path.LineTo(fishHeadX + mFishWidth * 0.5f, fishHeadY + mFishHeight);
            path.LineTo(fishHeadX + mFishWidth * 0.5f, fishHeadY + mFishHeight * 0.8f);
            path.LineTo(fishHeadX + mFishWidth * 0.333f, fishHeadY + mFishHeight * 0.666f);
            path.LineTo(fishHeadX + mFishWidth * 0.333f, fishHeadY + mFishHeight * 0.444f);
            path.QuadTo(fishHeadX + mFishWidth * 0.333f, fishHeadY + mFishHeight * 0.222f, fishHeadX, fishHeadY);

            path.Close();

            return(path);
        }
コード例 #2
0
		void UpdateShape()
		{
			if (_points != null && _points.Count > 1)
			{
				APath path = new APath();
				path.SetFillType(_fillMode ? FillType.Winding : FillType.EvenOdd);

				path.MoveTo(_density * (float)_points[0].X, _density * (float)_points[0].Y);

				for (int index = 1; index < _points.Count; index++)
					path.LineTo(_density * (float)_points[index].X, _density * (float)_points[index].Y);

				path.Close();

				UpdateShape(path);
			}
		}
コード例 #3
0
        public override Carto.Graphics.Bitmap OnDrawPopup(PopupDrawInfo popupDrawInfo)
        {
            PopupStyle style = popupDrawInfo.Popup.Style;

            // Calculate scaled dimensions
            float DPToPX = popupDrawInfo.DPToPX;
            float PXTODP = 1 / DPToPX;

            if (style.ScaleWithDPI)
            {
                DPToPX = 1;
            }
            else
            {
                PXTODP = 1;
            }

            float screenWidth  = popupDrawInfo.ScreenBounds.GetWidth() * PXTODP;
            float screenHeight = popupDrawInfo.ScreenBounds.GetHeight() * PXTODP;

            // Update sizes based on scale (uses extension method, cf. Shared/Extensions
            int fontSize = FontSize.Update(DPToPX);

            int triangleWidth  = TriangleSize.Update(DPToPX);
            int triangleHeight = TriangleSize.Update(DPToPX);

            int strokeWidth   = StrokeWidth.Update(DPToPX);
            int screenPadding = ScreenPadding.Update(DPToPX);

            // Set font
            var font = Android.Graphics.Typeface.Create("HelveticaNeue-Light", Android.Graphics.TypefaceStyle.Normal);

            // Calculate the maximum popup size, adjust with dpi
            int maxPopupWidth = (int)(Math.Min(screenWidth, screenHeight));

            float halfStrokeWidth = strokeWidth * 0.5f;
            int   maxTextWidth    = maxPopupWidth - (2 * screenPadding + strokeWidth);

            // Measure text
            TextPaint textPaint = new TextPaint {
                Color = TextColor, TextSize = fontSize
            };

            textPaint.SetTypeface(font);

            var textLayout = new StaticLayout(text, textPaint, maxTextWidth, Layout.Alignment.AlignNormal, 1, 0, false);

            int textX = (int)Math.Min(textPaint.MeasureText(text), textLayout.Width);
            int textY = textLayout.Height;

            int popupWidth  = textX + (2 * PopupPadding + strokeWidth + triangleWidth);
            int popupHeight = textY + (2 * PopupPadding + strokeWidth);

            var bitmap = Android.Graphics.Bitmap.CreateBitmap(popupWidth, popupHeight, Android.Graphics.Bitmap.Config.Argb8888);
            var canvas = new Android.Graphics.Canvas(bitmap);

            var trianglePath = new Android.Graphics.Path();

            trianglePath.MoveTo(triangleWidth, 0);
            trianglePath.LineTo(halfStrokeWidth, triangleHeight * 0.5f);
            trianglePath.LineTo(triangleWidth, triangleHeight);
            trianglePath.Close();

            int triangleOffsetX = 0;
            int triangleOffsetY = (popupHeight - triangleHeight) / 2;

            // Create paint object
            var paint = new Android.Graphics.Paint();

            paint.AntiAlias = true;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.StrokeWidth = strokeWidth;
            paint.Color       = StrokeColor;

            // Stroke background
            var background = new Android.Graphics.RectF();

            background.Left   = triangleWidth;
            background.Top    = halfStrokeWidth;
            background.Right  = popupWidth - strokeWidth;
            background.Bottom = popupHeight - strokeWidth;
            canvas.DrawRect(background, paint);

            // Stroke triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            // Fill background
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = BackgroundColor;
            canvas.DrawRect(background, paint);

            // Fill triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            if (textLayout != null)
            {
                // Draw text
                canvas.Save();
                canvas.Translate(halfStrokeWidth + triangleWidth + PopupPadding, halfStrokeWidth + PopupPadding);
                textLayout.Draw(canvas);
                canvas.Restore();
            }

            return(BitmapUtils.CreateBitmapFromAndroidBitmap(bitmap));
        }
コード例 #4
0
        public override Carto.Graphics.Bitmap OnDrawPopup(PopupDrawInfo popupDrawInfo)
        {
            PopupStyle style = popupDrawInfo.Popup.Style;

            // Calculate scaled dimensions
            float DPToPX = popupDrawInfo.DPToPX;
            float PXTODP = 1 / DPToPX;

            if (style.ScaleWithDPI)
            {
                DPToPX = 1;
            }
            else
            {
                PXTODP = 1;
            }

            float screenWidth = popupDrawInfo.ScreenBounds.GetWidth() * PXTODP;
            float screenHeight = popupDrawInfo.ScreenBounds.GetHeight() * PXTODP;

            // Update sizes based on scale (uses extension method, cf. Shared/Extensions
            int fontSize = FontSize.Update(DPToPX);

            int triangleWidth = TriangleSize.Update(DPToPX);
            int triangleHeight = TriangleSize.Update(DPToPX);

            int strokeWidth = StrokeWidth.Update(DPToPX);
            int screenPadding = ScreenPadding.Update(DPToPX);

            // Set font
            var font = Android.Graphics.Typeface.Create("HelveticaNeue-Light", Android.Graphics.TypefaceStyle.Normal);

            // Calculate the maximum popup size, adjust with dpi
            int maxPopupWidth = (int)(Math.Min(screenWidth, screenHeight));

            float halfStrokeWidth = strokeWidth * 0.5f;
            int maxTextWidth = maxPopupWidth - (2 * screenPadding + strokeWidth);

            // Measure text
            TextPaint textPaint = new TextPaint { Color = TextColor, TextSize = fontSize };
            textPaint.SetTypeface(font);

            var textLayout = new StaticLayout(text, textPaint, maxTextWidth, Layout.Alignment.AlignNormal, 1, 0, false);

            int textX = (int)Math.Min(textPaint.MeasureText(text), textLayout.Width);
            int textY = textLayout.Height;

            int popupWidth = textX + (2 * PopupPadding + strokeWidth + triangleWidth);
            int popupHeight = textY + (2 * PopupPadding + strokeWidth);

            var bitmap = Android.Graphics.Bitmap.CreateBitmap(popupWidth, popupHeight, Android.Graphics.Bitmap.Config.Argb8888);
            var canvas = new Android.Graphics.Canvas(bitmap);

            var trianglePath = new Android.Graphics.Path();
            trianglePath.MoveTo(triangleWidth, 0);
            trianglePath.LineTo(halfStrokeWidth, triangleHeight * 0.5f);
            trianglePath.LineTo(triangleWidth, triangleHeight);
            trianglePath.Close();

            int triangleOffsetX = 0;
            int triangleOffsetY = (popupHeight - triangleHeight) / 2;

            // Create paint object
            var paint = new Android.Graphics.Paint();
            paint.AntiAlias = true;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.StrokeWidth = strokeWidth;
            paint.Color = StrokeColor;

            // Stroke background
            var background = new Android.Graphics.RectF();
            background.Left = triangleWidth;
            background.Top = halfStrokeWidth;
            background.Right = popupWidth - strokeWidth;
            background.Bottom = popupHeight - strokeWidth;
            canvas.DrawRect(background, paint);

            // Stroke triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            // Fill background
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = BackgroundColor;
            canvas.DrawRect(background, paint);

            // Fill triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            if (textLayout != null)
            {
                // Draw text
                canvas.Save();
                canvas.Translate(halfStrokeWidth + triangleWidth + PopupPadding, halfStrokeWidth + PopupPadding);
                textLayout.Draw(canvas);
                canvas.Restore();
            }

            return BitmapUtils.CreateBitmapFromAndroidBitmap(bitmap);
        }