public void DrawString(string text, Font font, Brush brush, int x, int y) { APaint.Color = brush.Color.AColor(); APaint.TextSize = APixels(font.Size); APaint.SetTypeface(Android.Graphics.Typeface.Default);//TODO //Android.Graphics.TypefaceStyle APaint.SetStyle(Android.Graphics.Paint.Style.Fill); APaint.Flags = Android.Graphics.PaintFlags.AntiAlias; using (var fm = APaint.GetFontMetricsInt()) { var height = -fm.Top; ACanvas.DrawText(text, x, y + height, APaint); } }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mCurrentBounds; arcBounds.Set(bounds); //draw bottle mPaint.SetStyle(Paint.Style.Stroke); mPaint.Color = new Color(mBottleColor); canvas.DrawPath(CreateBottlePath(mBottleBounds), mPaint); //draw water mPaint.SetStyle(Paint.Style.FillAndStroke); mPaint.Color = new Color(mWaterColor); canvas.DrawPath(CreateWaterPath(mWaterBounds, mProgress), mPaint); //draw water drop mPaint.SetStyle(Paint.Style.Fill); mPaint.Color = new Color(mWaterColor); foreach (WaterDropHolder waterDropHolder in mWaterDropHolders) { if (waterDropHolder.mNeedDraw) { canvas.DrawCircle(waterDropHolder.mInitX, waterDropHolder.mCurrentY, waterDropHolder.mRadius, mPaint); } } //draw loading text mPaint.Color = new Color(mBottleColor); canvas.DrawText(LOADING_TEXT, mBottleBounds.CenterX() - mLoadingBounds.Width() / 2.0f, mBottleBounds.Bottom + mBottleBounds.Height() * 0.2f, mPaint); canvas.RestoreToCount(saveCount); }
public override VectorElement BuildClusterElement(MapPos pos, VectorElementVector elements) { MarkerStyle style = null; // Try to reuse existing marker styles if (markerStyles.ContainsKey(elements.Count)) { style = markerStyles[elements.Count]; } if (elements.Count == 1) { style = (elements[0] as Marker).Style; } if (style == null) { Android.Graphics.Bitmap canvasBitmap = markerBitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true); Android.Graphics.Canvas canvas = new Android.Graphics.Canvas(canvasBitmap); Android.Graphics.Paint paint = new Android.Graphics.Paint(Android.Graphics.PaintFlags.AntiAlias); paint.TextAlign = (Android.Graphics.Paint.Align.Center); paint.TextSize = 12; paint.Color = Android.Graphics.Color.Argb(255, 0, 0, 0); float x = markerBitmap.Width / 2; float y = markerBitmap.Height / 2 - 5; canvas.DrawText(elements.Count.ToString(), x, y, paint); MarkerStyleBuilder styleBuilder = new MarkerStyleBuilder(); styleBuilder.Bitmap = BitmapUtils.CreateBitmapFromAndroidBitmap(canvasBitmap); styleBuilder.Size = 30; styleBuilder.PlacementPriority = -elements.Count; style = styleBuilder.BuildStyle(); markerStyles.Add(elements.Count, style); } // Create marker for the cluster Marker marker = new Marker(pos, style); return(marker); }
protected override void OnDraw(Android.Graphics.Canvas canvas) { base.OnDraw(canvas); lock (this) { Image <Bgr, byte> image = _bgrBuffers.GetBuffer(0); if (image != null && !_imageSize.IsEmpty && canvas != null) { Stopwatch w = Stopwatch.StartNew(); if ((_bmpImage != null) && (!_imageSize.Equals(_bmpImage.Size))) { _bmpImage.Dispose(); _bmpImage = null; _bmp.Dispose(); _bmp = null; } if (_bmpImage == null) { _bmp = Android.Graphics.Bitmap.CreateBitmap(_imageSize.Width, _imageSize.Height, Android.Graphics.Bitmap.Config.Rgb565); _bmpImage = new BitmapRgb565Image(_bmp); } _bmpImage.ConvertFrom(image); canvas.DrawBitmap(_bmp, 0, 0, _paint); w.Stop(); _watch.Stop(); #if DEBUG canvas.DrawText(String.Format("{0:F2} FPS; {1}x{2}; Render Time: {3} ms", 1.0 / _watch.ElapsedMilliseconds * 1000, _imageSize.Width, _imageSize.Height, w.ElapsedMilliseconds), 20, 20, _paint); #endif _watch.Reset(); _watch.Start(); } } }
override protected void OnDraw(Android.Graphics.Canvas canvas) { int baseline = Baseline; for (int i = 0; i < LineCount; i++) { int number = i + 1; string text = " "; if (number < 10) { text += "0"; } text += "" + (i + 1); canvas.DrawText(text, rect.Left, baseline, paint); baseline += LineHeight; } base.OnDraw(canvas); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mTempBounds; arcBounds.Set(bounds); arcBounds.Inset(mStrokeXInset, mStrokeYInset); mCurrentProgressBounds.Set(arcBounds.Left, arcBounds.Bottom - 2 * mCenterRadius, arcBounds.Right, arcBounds.Bottom); //Draw loading Drawable mLoadingDrawable.SetBounds((int)arcBounds.CenterX() - mLoadingDrawable.IntrinsicWidth / 2, 0, (int)arcBounds.CenterX() + mLoadingDrawable.IntrinsicWidth / 2, mLoadingDrawable.IntrinsicHeight); mLoadingDrawable.Draw(canvas); //Draw progress background float progressInset = mCenterRadius - mProgressCenterRadius; RectF progressRect = new RectF(mCurrentProgressBounds); //sub DEFAULT_STROKE_INTERVAL, otherwise will have a interval between progress background and progress outline progressRect.Inset(progressInset - DEFAULT_STROKE_INTERVAL, progressInset - DEFAULT_STROKE_INTERVAL); mPaint.Color = new Color(mProgressBgColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawRoundRect(progressRect, mProgressCenterRadius, mProgressCenterRadius, mPaint); //Draw progress mPaint.Color = new Color(mProgressColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawPath(CreateProgressPath(mProgress, mProgressCenterRadius, progressRect), mPaint); //Draw leaves for (int i = 0; i < mLeafHolders.Count; i++) { int leafSaveCount = canvas.Save(); LeafHolder leafHolder = mLeafHolders[i]; Rect leafBounds = leafHolder.mLeafRect; canvas.Rotate(leafHolder.mLeafRotation, leafBounds.CenterX(), leafBounds.CenterY()); mLeafDrawable.Bounds = leafBounds; mLeafDrawable.Draw(canvas); canvas.RestoreToCount(leafSaveCount); } //Draw progress background outline, //after Drawing the leaves and then Draw the outline of the progress background can //prevent the leaves from flying to the outside RectF progressOutlineRect = new RectF(mCurrentProgressBounds); float progressOutlineStrokeInset = (mCenterRadius - mProgressCenterRadius) / 2.0f; progressOutlineRect.Inset(progressOutlineStrokeInset, progressOutlineStrokeInset); mPaint.SetStyle(Paint.Style.Stroke); mPaint.Color = new Color(mProgressBgColor); mPaint.StrokeWidth = mCenterRadius - mProgressCenterRadius; canvas.DrawRoundRect(progressOutlineRect, mCenterRadius, mCenterRadius, mPaint); //Draw electric fan outline float electricFanCenterX = arcBounds.Right - mCenterRadius; float electricFanCenterY = arcBounds.Bottom - mCenterRadius; mPaint.Color = new Color(mElectricFanOutlineColor); mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeWidth = mStrokeWidth; canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth / 2.0f, mPaint); //Draw electric background mPaint.Color = new Color(mElectricFanBgColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth + DEFAULT_STROKE_INTERVAL, mPaint); //Draw electric fan int rotateSaveCount = canvas.Save(); canvas.Rotate(mRotation, electricFanCenterX, electricFanCenterY); mElectricFanDrawable.SetBounds((int)(electricFanCenterX - mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY - mElectricFanDrawable.IntrinsicHeight / 2 * mScale), (int)(electricFanCenterX + mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY + mElectricFanDrawable.IntrinsicHeight / 2 * mScale)); mElectricFanDrawable.Draw(canvas); canvas.RestoreToCount(rotateSaveCount); //Draw 100% text if (mScale < 1.0f) { mPaint.TextSize = mTextSize * (1 - mScale); mPaint.Color = new Color(mElectricFanOutlineColor); Rect textRect = new Rect(); mPaint.GetTextBounds(PERCENTAGE_100, 0, PERCENTAGE_100.Length, textRect); canvas.DrawText(PERCENTAGE_100, electricFanCenterX - textRect.Width() / 2.0f, electricFanCenterY + textRect.Height() / 2.0f, mPaint); } canvas.RestoreToCount(saveCount); }