public static Color GetColorWithOpacity(this Activity activity, int normalColor, int opacityColor) { var bitmap = Bitmap.CreateBitmap(1, 1, Bitmap.Config.Argb8888); //make a 1-pixel Bitmap var canvas = new Canvas(bitmap); canvas.DrawColor(activity.Resources.GetColor(normalColor)); //color we want to apply filter to canvas.DrawColor(activity.Resources.GetColor(opacityColor), PorterDuff.Mode.SrcAtop); //apply filter var index = bitmap.GetPixel(0, 0); return Color.Argb(index, index, index, index); }
void PancakeViewOnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName || e.PropertyName == PancakeView.CornerRadiusProperty.PropertyName || e.PropertyName == PancakeView.BackgroundGradientAngleProperty.PropertyName || e.PropertyName == PancakeView.BackgroundGradientStartColorProperty.PropertyName || e.PropertyName == PancakeView.BackgroundGradientEndColorProperty.PropertyName || e.PropertyName == PancakeView.BackgroundGradientStopsProperty.PropertyName || e.PropertyName == PancakeView.SidesProperty.PropertyName || e.PropertyName == PancakeView.OffsetAngleProperty.PropertyName) { if (_normalBitmap == null) { return; } using (var canvas = new ACanvas(_normalBitmap)) { int width = Bounds.Width(); int height = Bounds.Height(); canvas.DrawColor(global::Android.Graphics.Color.Black, PorterDuff.Mode.Clear); DrawCanvas(canvas, width, height, false); } InvalidateSelf(); } }
private void FrameOnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName || e.PropertyName == Frame.BorderColorProperty.PropertyName || e.PropertyName == Frame.CornerRadiusProperty.PropertyName || e.PropertyName == ExtendedFrame.StrokeThicknessProperty.PropertyName || e.PropertyName == ExtendedFrame.StrokeDashLengthProperty.PropertyName || e.PropertyName == ExtendedFrame.StrokeDashGapProperty.PropertyName || e.PropertyName == ExtendedFrame.CornersProperty.PropertyName) { if (_normalBitmap == null) { return; } using (var canvas = new ACanvas(_normalBitmap)) { var width = Bounds.Width(); var height = Bounds.Height(); canvas.DrawColor(global::Android.Graphics.Color.Black, PorterDuff.Mode.Clear); DrawCanvas(canvas, width, height, false); } InvalidateSelf(); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw (canvas); if (mBlurredView != null) { if (prepare()) { // If the background of the blurred view is a color drawable, we use it to clear // the blurring canvas, which ensures that edges of the child views are blurred // as well; otherwise we clear the blurring canvas with a transparent color. if (mBlurredView.Background != null && mBlurredView.Background is ColorDrawable){ mBitmapToBlur.EraseColor(((ColorDrawable) mBlurredView.Background).Color); }else { mBitmapToBlur.EraseColor(Color.Transparent); } mBlurredView.Draw(mBlurringCanvas); blur(); canvas.Save(); canvas.Translate(mBlurredView.GetX() - GetX(), mBlurredView.GetY() - GetY()); canvas.Scale(mDownsampleFactor, mDownsampleFactor); canvas.DrawBitmap(mBlurredBitmap, 0, 0, null); canvas.Restore(); } canvas.DrawColor(mOverlayColor); } }
private void drawPorcentajeOnCanvas(Canvas canvas) { base.OnDraw (canvas); canvas.Save (); canvas.DrawColor(Android.Graphics.Color.White); //Obtenemos el centro de nuesto canvas float x = this.MeasuredWidth / 2; float y = this.MeasuredHeight / 2; //Obtenemos el radio R1 //Obtenemos el radio R2 float R1 = 0; float R2 = 0; //if (canvas.Width < canvas.Height) { if (this.MeasuredWidth < this.MeasuredHeight) { R1 = x;//Obtenemos el radio R1 R2 = x-(x*por_rango/100); } else { R1 = y ;//Obtenemos el radio R1 R2 = y-(y *por_rango/100);//Obtenemos el radio R2 que dejamos un 20% de margen } //Dibujamos el fondo de nuestro grafico que va ir creciendo de acuerdo al porcentaje descargado RectF rectF2 = new RectF(x-R1, y-R1,x+R1, y+R1); mPaintFondo.Color= Android.Graphics.Color.Rgb(19,184,213); int grados = 0; grados = 360 * porcentaje / 100; canvas.DrawArc(rectF2, 270, grados, true, mPaintFondo); //Fondo superior de nuestro texto mPaintSuperior.Color= Android.Graphics.Color.Rgb(50,58,69); canvas.DrawCircle(x,y , R2, mPaintSuperior); //Texto que nos indica el procentaje descargado mPaintTexto.SetTypeface (mFace); mPaintTexto.Color = Color.White; //Obtenemos el 30 % de radio de nuestro circulo de fondo, el cual sera el tamaño de letra utilzar; float MYTEXTSIZE = R2 *30/100; // Get the screen's density scale float scale = Application.Context.Resources.DisplayMetrics.Density; //Convert the dps to pixels, based on density scale int textSizePx = (int) (MYTEXTSIZE * scale + 0.5f); mPaintTexto.TextSize = textSizePx; //Obtenemos la posicion para centrar adecuadamente nuesto texto int xPos = (this.MeasuredWidth / 2); int yPos = (int) ((this.MeasuredHeight / 2) - ((mPaintTexto.Descent() + mPaintTexto.Ascent()) / 2)) ; string Texto_Porcentaje =porcentaje.ToString(); canvas.DrawText (Texto_Porcentaje+" %", xPos,yPos, mPaintTexto); canvas.Restore(); }
public override void Draw (Canvas canvas) { var bounds = Bounds; if (alpha != 255) { paint.Alpha = 255; if (SecondBitmap != null) { if (shader1 == null) shader1 = new BitmapShader (FirstBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp); shader1.SetLocalMatrix (matrix); paint.SetShader (shader1); canvas.DrawRect (bounds, paint); } else canvas.DrawColor (defaultColor.ToAndroidColor()); } if (alpha != 0) { paint.Alpha = alpha; if (FirstBitmap != null) { if (shader2 == null) shader2 = new BitmapShader (SecondBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp); shader2.SetLocalMatrix (matrix); paint.SetShader (shader2); canvas.DrawRect (bounds, paint); } else canvas.DrawColor (defaultColor.ToAndroidColor()); } }
public void DrawMask(View target, Canvas maskCanvas, Color maskColor, Point position, int radius, Animator animator) { // draw solid background maskCanvas.DrawColor(maskColor); // erase focus area maskCanvas.DrawCircle(position.X, position.Y, radius, eraserPaint); }
protected override void OnDraw(Canvas canvas) { canvas.DrawColor (Color.White); mPaint.SetTypeface (null); canvas.DrawText ("Default", 10, 100, mPaint); mPaint.SetTypeface (mFace); canvas.DrawText ("Custom", 10, 200, mPaint); }
private void ShowPath(Canvas canvas, int x, int y, Path.FillType ft, Paint paint) { canvas.Save(); canvas.Translate(x, y); canvas.ClipRect(0, 0, 120, 120); canvas.DrawColor(Color.White); mPath.SetFillType(ft); canvas.DrawPath(mPath, paint); canvas.Restore(); }
private File CreateImage() { using (var b = Bitmap.CreateBitmap(100, 100, Bitmap.Config.Argb8888)) using (Canvas c = new Canvas(b)) { var color = Color.Argb(255, rnd.Next(256), rnd.Next(256), rnd.Next(256)); c.DrawColor(color); return SaveBitmap(b); } }
public void DrawMask(View target, Canvas maskCanvas, Color maskColor, Point position, int radius, Animator animator) { var valueAnimator = animator as ValueAnimator; var bounce = valueAnimator != null ? (float)valueAnimator.AnimatedValue : target.Alpha; // draw solid background maskCanvas.DrawColor(maskColor); // erase focus area maskCanvas.DrawCircle(position.X, position.Y, radius * bouncy.GetInterpolation(bounce), eraserPaint); }
protected override void OnDraw(Canvas canvas) { Paint paint = mPaint; canvas.DrawColor(Color.Argb(255, 204, 204, 204)); canvas.Translate(20, 20); paint.AntiAlias = true; ShowPath(canvas, 0, 0, Path.FillType.Winding, paint); ShowPath(canvas, 160, 0, Path.FillType.EvenOdd, paint); ShowPath(canvas, 0, 160, Path.FillType.InverseWinding, paint); ShowPath(canvas, 160, 160, Path.FillType.InverseEvenOdd, paint); }
void FrameOnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName || e.PropertyName == Frame.OutlineColorProperty.PropertyName) { using (var canvas = new ACanvas(_normalBitmap)) { int width = Bounds.Width(); int height = Bounds.Height(); canvas.DrawColor(global::Android.Graphics.Color.Black, PorterDuff.Mode.Clear); DrawBackground(canvas, width, height, false); DrawOutline(canvas, width, height); } InvalidateSelf(); } }
protected override void OnDraw(Canvas canvas) { canvas.DrawColor (Color.White); Paint p = new Paint (); float y = 10; p.Color = Color.Red; canvas.DrawBitmap (mBitmap, 10, y, p); y += mBitmap.Height + 10; canvas.DrawBitmap (mBitmap2, 10, y, p); y += mBitmap2.Height + 10; p.SetShader (mShader); canvas.DrawBitmap (mBitmap3, 10, y, p); }
protected override void OnDraw (Canvas canvas) { canvas.DrawColor (Color.White); canvas.Translate (10, 10); canvas.SaveLayerAlpha (0, 0, 200, 200, 0x88, SaveFlags.All); mPaint.Color = Color.Red; canvas.DrawCircle (75, 75, 75, mPaint); mPaint.Color = Color.Blue; canvas.DrawCircle (125, 125, 75, mPaint); canvas.Restore (); }
protected override void DispatchDraw(Android.Graphics.Canvas canvas) { // Draw interior shadow canvas.Save(); canvas.ClipRect(0, 0, Width, Height); canvas.DrawPaint(shadow); canvas.Restore(); base.DispatchDraw(canvas); // Draw custom list separator canvas.Save(); canvas.ClipRect(0, Height - 2, Width, Height); canvas.DrawColor(Android.Graphics.Color.Rgb(LightTone, LightTone, LightTone)); canvas.Restore(); }
private void DoDraw(Canvas canvas, double stepFactor) { double width = canvas.GetWidth(); double height = canvas.GetHeight(); double x = width/2; double y = height/2; x += xOrientation * stepFactor; y += yOrientation * stepFactor; // Set background color canvas.DrawColor(Color.BLUE); var paint = new Paint(); paint.TextAlign =(Paint.Align.CENTER); // Draw a circle paint.Color =(Color.ParseColor("#ffd700")); canvas.DrawCircle((float) x, (float) y, 30, paint); }
void CorneredContentViewOnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName || e.PropertyName == CorneredContentView.CornerRadiusProperty.PropertyName) { if (this._normalBitmap == null) { return; } using (ACanvas canvas = new ACanvas(this._normalBitmap)) { int width = this.Bounds.Width(); int height = this.Bounds.Height(); canvas.DrawColor(global::Android.Graphics.Color.Black, PorterDuff.Mode.Clear); this.DrawCanvas(canvas, width, height, false); } this.InvalidateSelf(); } }
private void PolygonFramePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName || e.PropertyName == PolygonFrame.CornerRadiusProperty.PropertyName) { if (_normalBitmap == null) { return; } using (var canvas = new ACanvas(_normalBitmap)) { int width = Bounds.Width(); int height = Bounds.Height(); canvas.DrawColor(global::Android.Graphics.Color.Black, PorterDuff.Mode.Clear); DrawCanvas(canvas, width, height, false); } InvalidateSelf(); } }
protected override void Draw(Canvas canvas, Rect bounds) { int SaveCount = canvas.Save(); RectF arcBounds = mCurrentBounds; arcBounds.Set(bounds); //Draw background canvas.DrawColor(new Color(mCurrentBackgroundColor)); //Draw reveal circle if (mRevealCircleRadius > 0) { mPaint.Color = new Color(mCurrentBackgroundColor == mBackgroundColor ? mBackgroundDeepColor : mBackgroundColor); canvas.DrawCircle(arcBounds.CenterX(), arcBounds.CenterY(), mRevealCircleRadius, mPaint); } //Draw mother oval mPaint.Color = new Color(mCurrentOvalColor); int motherSaveCount = canvas.Save(); canvas.Rotate(mRotateDegrees, mMotherPosition[0], mMotherPosition[1]); canvas.DrawPath(CreateMotherPath(), mPaint); canvas.DrawPath(CreateLinkPath(), mPaint); canvas.RestoreToCount(motherSaveCount); int childSaveCount = canvas.Save(); canvas.Rotate(mRotateDegrees, mChildPosition[0], mChildPosition[1]); canvas.DrawPath(CreateChildPath(), mPaint); canvas.RestoreToCount(childSaveCount); canvas.RestoreToCount(SaveCount); // canvas.DrawPath(mMotherMovePath, mPaint); // canvas.DrawPath(mChildMovePath, mPaint); // canvas.DrawLine(mMotherPosition[0], mMotherPosition[1], mChildPosition[0], mChildPosition[1], mPaint); }
//private int Width; //private int Height; public SampleView(Context context) : base(context) { Log.Debug(tag, "Start view"); Focusable = true; //foreach (var item in DataClass.Drawables) // item.Visible = false; mPaint = new Paint(); mPaint.AntiAlias = true; IWindowManager wm = context.GetSystemService(WindowService).JavaCast<IWindowManager>(); Display dsp = wm.DefaultDisplay; Width = dsp.Width; Height = dsp.Height; mBmp = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888); canvasBitmap = new Canvas(mBmp); canvasBitmap.DrawColor(Color.Black); Log.Debug(tag, String.Format("Client W:{0}, H:{1}", Width, Height)); }
public Size GetCharData(char c, out UInt32[] cdata) { float height=(fontsize * 1.25f); int ih = (int)height; if ((height - ih) > 0) ih++; float width = paint.MeasureText(c.ToString()); int iw = (int)width; if ((width - iw) > 0) iw++; //canvas.Restore(); Bitmap bitmap = Bitmap.CreateBitmap(iw, ih, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); canvas.DrawColor(Android.Graphics.Color.Transparent); canvas.DrawText(c.ToString(), 0, fontsize, paint); cdata = new UInt32[iw * ih]; int[] data = new int[iw * ih]; bitmap.GetPixels(data, 0, iw, 0, 0, iw, ih); for (int i = 0; i < data.Length; i++) { cdata[i] = (uint)data[i]; } return new Size(iw, ih); }
private void DoDraw(Canvas canvas) { // Increment / reset size += delta; if (size > 250) { delta = -1; } else if (size < 30) { delta = 1; } // Set background color canvas.DrawColor(Color.BLUE); var paint = new Paint(); paint.TextAlign =(Paint.Align.CENTER); // Draw some lines canvas.DrawLine(mX, mY, mY + 33, mX + 100, paint); paint.Color =(Color.RED); paint.StrokeWidth = (10); canvas.DrawLine(87, 0, 75, 100, paint); paint.Color =(Color.GREEN); paint.StrokeWidth = (5); for (int y = 30, alpha = 128; alpha > 2; alpha >>= 1, y += 10) { paint.Alpha = (alpha); canvas.DrawLine(mY, y, mY + 100, y, paint); } // Draw a red rectangle paint.Color =(Color.RED); var rect = new Rect(); rect.Set(size + 120, 130, size + 156, 156); canvas.DrawRect(rect, paint); // Draw a circle paint.Color =(Color.ParseColor("#ffd700")); canvas.DrawCircle(size * 2, 220, 30, paint); //faster circle // Draw red'ish rectangle paint.Color =(Color.Rgb(128, 20, 20)); canvas.DrawRect(size, 67, 68, 45, paint); // Draw green circle paint.Color =(Color.GREEN); canvas.DrawCircle(size, 140.0f - size / 3, 45.0f, paint); //move circle across screen paint.Color =(Color.RED); canvas.DrawText("Dot42", size, 140.0f - size / 3, paint); // Draw magenta circle paint.Color =(Color.MAGENTA); canvas.DrawCircle(mX, mY, size / 4.0f, paint); //move circle down screen paint.Color =(Color.GREEN); canvas.DrawText("is", mX, mY, paint); // Draw yellow rectangle paint.Alpha = (64); paint.Color =(Color.YELLOW); canvas.DrawRect(size, size, size + 45, size + 45, paint); // Draw text on rectangle paint.Alpha = (255); paint.Color =(Color.DKGRAY); canvas.DrawText("fun!", size + 45 / 2, size + 45 / 2, paint); }
private void DrawStrokesOnCanvas (Canvas canvas, Color strokeColor, Color fillColor, bool shouldCrop, RectF croppedRectangle = null) { canvas.DrawColor (fillColor); paint.Color = strokeColor; foreach (var path in paths) { var tempPath = path; if (shouldCrop) { tempPath = new Path (path); var translate = new Matrix (); translate.SetTranslate (-croppedRectangle.Left, -croppedRectangle.Top); tempPath.Transform (translate); } canvas.DrawPath (tempPath, paint); tempPath = null; } paint.Color = this.strokeColor; }
protected override void OnDraw(Canvas canvas) { Paint paint = mPaint; canvas.DrawColor (Color.White); paint.AntiAlias = true; paint.Color = Color.Black; paint.SetStyle (Paint.Style.Fill); int w = canvas.Width; int h = canvas.Height; int cx = w / 2; int cy = h / 2; canvas.Translate (cx, cy); if (compass.mValues != null) canvas.Rotate (-compass.mValues[0]); canvas.DrawPath (mPath, mPaint); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); canvas.DrawColor(Color.White); this.rootCanvas.SetTarget(canvas); using (var bounds = new Rect()) { canvas.GetClipBounds(bounds); rootCanvas.DrawRectangle(new RectF(bounds.Left, bounds.Top, bounds.Width(), bounds.Height()), Color.Red, Color.Transparent, 0); } }
/// <summary> /// Draws the content of the control. /// </summary> /// <param name="canvas">The canvas to draw on.</param> protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); var actualModel = this.ActualModel; if (actualModel == null) { return; } if (!actualModel.Background.IsUndefined()) { canvas.DrawColor(actualModel.Background.ToColor()); } else { // Use white as default background color canvas.DrawColor(Color.White); } lock (this.invalidateLock) { if (this.isModelInvalidated) { ((IPlotModel)actualModel).Update(this.updateDataFlag); this.updateDataFlag = false; this.isModelInvalidated = false; } } lock (this.renderingLock) { if (this.rc == null) { this.rc = new CanvasRenderContext(Scale); } this.rc.SetTarget(canvas); using (var bounds = new Rect()) { canvas.GetClipBounds(bounds); var width = bounds.Right - bounds.Left; var height = bounds.Bottom - bounds.Top; ((IPlotModel)actualModel).Render(this.rc, width / Scale, height / Scale); } } }
protected override void OnDraw(Canvas canvas) { canvas.DrawColor(Color.Transparent); Paint p = new Paint(); p.AntiAlias = true; SetLayerType(LayerType.Software, p); long now = Android.OS.SystemClock.UptimeMillis(); if (movieStart == 0) { // first time movieStart = now; } if (movie != null) { int dur = movie.Duration(); if (dur == 0) { dur = 1000; } var relTime = (int)((now - movieStart) % dur); movie.SetTime(relTime); var movieWidth = (float)movie.Width(); var movieHeight = (float)movie.Height(); var scale = 1.0f; if (movieWidth > movieHeight) { scale = this.Width/movieWidth; if (scale*movieHeight > Height) scale = Height/movieHeight; } else { scale = this.Height/movieHeight; if (scale*movieWidth > Width) scale = Height/movieWidth; } canvas.Scale(scale, scale); try { movie.Draw(canvas, 0, 0, p); }catch(Exception ex) { } if(playing) Invalidate(); } }
private void DrawBitmap(Canvas c, Bitmap bmp) { var sc = c.Save(); this.Degree = this.Degree % 360 + DEGREE_STEP; //Ҫ����ת����ͼ����Ч�� c.Rotate(this.Degree, c.Width / 2, c.Height / 2); //���ĵ� var cx = c.Width / 2; var cy = c.Height / 2; //����ʾ��Χ, ָ���뾶��Բ var path = new Path(); path.AddCircle(cx, cy, this.BitmapRadius, Path.Direction.Cw); c.ClipPath(path); c.DrawColor(Color.White); //ͼƬ�Ļ��Ʒ�Χ var w = (this.ShowType == ShowTypes.Inner ? this.IWH : this.OWH) / 2; var rect = new Rect(cx - w, cy - w, cx + w, cy + w); //����ͼƬ var paint = new Paint(); //srcΪnull, ��������ͼƬ��ΪԴ c.DrawBitmap(bmp, null, rect, paint); c.RestoreToCount(sc); }
public FontRenderer( string font, int width, int height ) { string tmp; int location; if( Display.FileExists( font, out location ) ) { ttf = new TrueTypeFont( Display.FileReadAllBytes( location, font ), 0 ); } else if( Display.FileExists( tmp = ("c:/windows/fonts/" + font), out location ) ) ttf = new TrueTypeFont( Display.FileReadAllBytes( location, tmp ), 0 ); else if( Display.FileExists( tmp = ("Content/fonts/" + font), out location ) ) ttf = new TrueTypeFont( Display.FileReadAllBytes( location, tmp ), 0 ); else if( Display.FileExists( tmp = ( "/usr/share/fonts/TTF/" + font ), out location ) ) ttf = new TrueTypeFont( Display.FileReadAllBytes( location, tmp ), 0 ); else throw new Exception( "Font not found:" + font ); scalex = ttf.GetScaleForPixelHeight( width ); scaley = ttf.GetScaleForPixelHeight( height ); int lineGap; ttf.GetFontVMetrics( out ascent, out descent, out lineGap ); line_height = (int)Math.Ceiling( ( lineGap + ( ascent - descent ) ) * scaley ); ascent = (int)( ascent * scaley ); descent = (int)( descent * scaley ); fontrect = new Rectangle( 0, 0, 256, 256 ); #if !USE_GLES2 fontmap = new Bitmap( 256, 256 ); Graphics g = Graphics.FromImage( fontmap ); Brush b = new SolidBrush( Color.FromArgb( 0 ) ); g.FillRectangle( b, fontrect ); g.Dispose(); #else fontmap = Bitmap.CreateBitmap( 256, 256, Bitmap.Config.Argb8888 ); Canvas canvas = new Canvas( fontmap ); canvas.DrawColor( Android.Graphics.Color.Transparent ); canvas.Dispose(); #endif charmap = new Dictionary<uint, FontCharacter>(); line_heights = new List<int>(); line_heights.Add( -1 ); line_offsets = new List<int>(); line_offsets.Add( 0 ); Display.OnInvalidate += Display_OnInvalidate; }
void DrawFace(Canvas canvas, Rect bounds) { var width = bounds.Width(); var height = bounds.Height(); // Draw the background, scaled to fit. if (backgroundScaledBitmap == null || backgroundScaledBitmap.Width != width || backgroundScaledBitmap.Height != height) { backgroundScaledBitmap = Bitmap.CreateScaledBitmap(backgroundBitmap, width, height, true /* filter */); } canvas.DrawColor(Color.Black); canvas.DrawBitmap(backgroundScaledBitmap, 0, 0, null); var centerX = width / 2.0f; var centerY = height / 2.0f; // Draw the ticks. var innerTickRadius = centerX - 10; var outerTickRadius = centerX; for (var tickIndex = 0; tickIndex < 12; tickIndex++) { var tickRot = (float)(tickIndex * Math.PI * 2 / 12); var innerX = (float)Math.Sin(tickRot) * innerTickRadius; var innerY = (float)-Math.Cos(tickRot) * innerTickRadius; var outerX = (float)Math.Sin(tickRot) * outerTickRadius; var outerY = (float)-Math.Cos(tickRot) * outerTickRadius; canvas.DrawLine(centerX + innerX, centerY + innerY, centerX + outerX, centerY + outerY, tickPaint); } }
public Size GetCharDataDC(char c, out UInt32[] cdata, Microsoft.Xna.Framework.Color fill, Microsoft.Xna.Framework.Color border) { float height = (fontsize * 1.25f); int ih = (int)height; if ((height - ih) > 0) ih++; float width = paint.MeasureText(c.ToString()); int iw = (int)width; if ((width - iw) > 0) iw++; iw += 2; //canvas.Restore(); Bitmap bitmap = Bitmap.CreateBitmap(iw, ih, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bitmap); canvas.DrawColor(Android.Graphics.Color.Transparent); var pb = new Paint(paint); pb.Color = new Android.Graphics.Color(border.R, border.G, border.B, border.A); canvas.DrawText(c.ToString(), 0, fontsize-1, pb); canvas.DrawText(c.ToString(), 1, fontsize-1, pb); canvas.DrawText(c.ToString(), 2, fontsize-1, pb); canvas.DrawText(c.ToString(), 0, fontsize, pb); //canvas.DrawText(c.ToString(), 1, fontsize, pb); canvas.DrawText(c.ToString(), 2, fontsize, pb); canvas.DrawText(c.ToString(), 0, fontsize + 1, pb); canvas.DrawText(c.ToString(), 1, fontsize + 1, pb); canvas.DrawText(c.ToString(), 2, fontsize + 1, pb); var pf = new Paint(paint); pf.Color = new Android.Graphics.Color(fill.R, fill.G, fill.B, fill.A); canvas.DrawText(c.ToString(), 1, fontsize, pf); cdata = new UInt32[iw * ih]; int[] data = new int[iw * ih]; bitmap.GetPixels(data, 0, iw, 0, 0, iw, ih); for (int i = 0; i < data.Length; i++) { cdata[i] = (uint)data[i]; } return new Size(iw, ih); }
//Actual Draw of analogue niddle in Canvas which will show in watch surface public override void OnDraw(Canvas canvas, Rect bounds) { time.SetToNow (); int width = bounds.Width (); int height = bounds.Height (); // Draw the background, scaled to fit. if (backgroundScaledBitmap == null || backgroundScaledBitmap.Width != width || backgroundScaledBitmap.Height != height) { backgroundScaledBitmap = Bitmap.CreateScaledBitmap (backgroundBitmap, width, height, true /* filter */); } canvas.DrawColor (Color.Black); canvas.DrawBitmap (backgroundScaledBitmap, 0, 0, null); float centerX = width / 2.0f; float centerY = height / 2.0f; // Draw the ticks. float innerTickRadius = centerX - 10; float outerTickRadius = centerX; for (int tickIndex = 0; tickIndex < 12; tickIndex++) { float tickRot = (float)(tickIndex * Math.PI * 2 / 12); float innerX = (float)Math.Sin (tickRot) * innerTickRadius; float innerY = (float)-Math.Cos (tickRot) * innerTickRadius; float outerX = (float)Math.Sin (tickRot) * outerTickRadius; float outerY = (float)-Math.Cos (tickRot) * outerTickRadius; canvas.DrawLine (centerX + innerX, centerY + innerY, centerX + outerX, centerY + outerY, tickPaint); } float secRot = time.Second / 30f * (float)Math.PI; int minutes = time.Minute; float minRot = minutes / 30f * (float)Math.PI; float hrRot = ((time.Hour + (minutes / 60f)) / 6f) * (float)Math.PI; float secLength = centerX - 20; float minLength = centerX - 40; float hrLength = centerX - 80; if (!IsInAmbientMode) { float secX = (float)Math.Sin (secRot) * secLength; float secY = (float)-Math.Cos (secRot) * secLength; canvas.DrawLine (centerX, centerY, centerX + secX, centerY + secY, secondPaint); } float minX = (float)Math.Sin (minRot) * minLength; float minY = (float)-Math.Cos (minRot) * minLength; canvas.DrawLine (centerX, centerY, centerX + minX, centerY + minY, minutePaint); float hrX = (float)Math.Sin (hrRot) * hrLength; float hrY = (float)-Math.Cos (hrRot) * hrLength; canvas.DrawLine (centerX, centerY, centerX + hrX, centerY + hrY, hourPaint); }
protected override void OnDraw(Canvas canvas) { canvas.DrawColor(Color.Transparent); paint.Reset(); paint.AntiAlias = true; float midX, midY, radius, innerRadius; path.Reset(); float currentAngle = 270; float currentSweep; float totalValue = 0; float padding = 2; midX = Width / 2; midY = Height/2; if (midX < midY){ radius = midX; } else { radius = midY; } radius -= padding; innerRadius = radius - thickness; foreach (PieSlice slice in slices) { totalValue += slice.getValue(); } int count = 0; foreach (PieSlice slice in slices) { Path p = new Path(); paint.Color = slice.getColor (); currentSweep = (slice.getValue()/totalValue)*(360); p.ArcTo(new RectF(midX-radius, midY-radius, midX+radius, midY+radius), currentAngle+padding, currentSweep - padding); p.ArcTo(new RectF(midX-innerRadius, midY-innerRadius, midX+innerRadius, midY+innerRadius), (currentAngle+padding) + (currentSweep - padding), -(currentSweep-padding)); p.Close (); slice.setPath(p); slice.setRegion(new Region((int)(midX-radius), (int)(midY-radius), (int)(midX+radius), (int)(midY+radius))); canvas.DrawPath(p, paint); if (indexSelected == count && listener != null){ path.Reset(); paint.Color = slice.getColor (); paint.Color = Color.ParseColor ("#33B5E5"); paint.Alpha=100; if (slices.Count > 1) { path.ArcTo(new RectF(midX-radius-(padding*2), midY-radius-(padding*2), midX+radius+(padding*2), midY+radius+(padding*2)), currentAngle, currentSweep+padding); path.ArcTo(new RectF(midX-innerRadius+(padding*2), midY-innerRadius+(padding*2), midX+innerRadius-(padding*2), midY+innerRadius-(padding*2)), currentAngle + currentSweep + padding, -(currentSweep + padding)); path.Close(); } else { path.AddCircle(midX, midY, radius+padding, Android.Graphics.Path.Direction.Cw); } canvas.DrawPath(path, paint); paint.Alpha=255; } currentAngle = currentAngle+currentSweep; count++; } }
protected override void OnDraw (Canvas canvas) { int offset = Width / 2 - Height / 2; //draw background canvas.DrawColor (Color.Black); canvas.DrawRect (0, 0, Width, Height, background_paint); //draw brake/gas indicators if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_BRAKE)] > 0.0f) { gradient_paint.Alpha = ((int)(axes[AxesMapping.OrdinalValue(AxesMapping.AXIS_BRAKE)]*100)+155); canvas.DrawBitmap (gradient_bitmap, offset + left_gradient [0] * Height, left_gradient [1] * Height, gradient_paint); } if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_GAS)] > 0.0f) { gradient_paint.Alpha = ((int)(axes[AxesMapping.OrdinalValue(AxesMapping.AXIS_GAS)]*100)+155); canvas.DrawBitmap (gradient_bitmap, offset + right_gradient [0] * Height, right_gradient [1] * Height, gradient_paint); } //draw the paddles canvas.DrawColor (Color.Transparent); if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_R1)] == 0) { canvas.DrawBitmap (right_paddle_bitmap, offset + right_paddle [0] * Height, right_paddle [1] * Height, image_paint); } else if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_R1)] == 1) { canvas.DrawBitmap (right_paddle_bitmap, offset+ right_paddle_pressed [0] * Height, right_paddle_pressed [1] * Height, image_paint); } if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_L1)] == 0) { canvas.DrawBitmap (left_paddle_bitmap, offset + left_paddle [0] * Height, left_paddle [1] * Height, image_paint); } else if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_L1)] == 1) { canvas.DrawBitmap (left_paddle_bitmap, offset + left_paddle_pressed [0] * Height, left_paddle_pressed [1] * Height, image_paint); } //draw the controller body canvas.DrawBitmap (controller_bitmap, offset, 0, image_paint); //draw axes axis_leftX = offset + left_axis [0] * Height; axis_leftY = left_axis [1] * Height; axis_rightX = offset + right_axis [0] * Height; axis_rightY = right_axis [1] * Height; if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_X)] != 0.0f) { axis_leftX = axis_leftX + left_axis [3] * Height * axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_X)]; } if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_Y)] != 0.0f) { axis_leftY = axis_leftY + left_axis [3] * Height * axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_Y)]; } //Android Gamepad:AXIS_Z and AXIS_RZ respectively //Xbox Gamepad:AXIS_RX and AXIX_RZ respectively if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_RX)] != 0.0f) { axis_rightX = axis_rightX + right_axis [3] * Height * axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_RX)]; } if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_RY)] != 0.0f) { axis_rightY = axis_rightY + right_axis [3] * Height * axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_RY)]; } canvas.DrawBitmap (axis_bitmap, axis_rightX, axis_rightY, image_paint); canvas.DrawBitmap (axis_bitmap, axis_leftX, axis_leftY, image_paint); //Draw the LED light if (current_controller_number > 0 && current_controller_number <= MAX_CONTROLLERS) { canvas.DrawBitmap (blue_led_bitmap, offset + led_buttons [2 * current_controller_number - 2] * Height, led_buttons [2 * current_controller_number - 1] * Height, led_paint); } //Draw the directional buttons if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_HAT_X)] == 1.0f) { canvas.DrawBitmap (right_directional_bitmap, offset + right_directional_button [0] * Height,right_directional_button [1] * Height, directional_paint); } if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_HAT_Y)] == -1.0f) { canvas.DrawBitmap (top_directional_bitmap, offset + top_directional_button [0] * Height,top_directional_button [1] * Height, directional_paint); } if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_HAT_X)] == -1.0f) { canvas.DrawBitmap (left_directional_bitmap, offset + left_directional_button [0] * Height,left_directional_button [1] * Height, directional_paint); } if (axes [AxesMapping.OrdinalValue (AxesMapping.AXIS_HAT_Y)] == 1.0f) { canvas.DrawBitmap (bottom_directional_bitmap, offset + bottom_directional_button [0] * Height,bottom_directional_button [1] * Height, directional_paint); } //draw the A/B/X/Y buttons canvas.DrawColor (Color.Transparent); circle_paint.Color = Resources.GetColor (Resource.Color.transparent_black); if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_Y)] == 1) { canvas.DrawCircle (offset + y_button [0] * Height, y_button [1] * Height, y_button [2] * Height, circle_paint); } if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_X)] == 1) { canvas.DrawCircle (offset + x_button [0] * Height, x_button [1] * Height, x_button [2] * Height, circle_paint); } if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_B)] == 1) { canvas.DrawCircle (offset + b_button [0] * Height, b_button [1] * Height, b_button [2] * Height, circle_paint); } if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_A)] == 1) { canvas.DrawCircle (offset + a_button [0] * Height, a_button [1] * Height, a_button [2] * Height, circle_paint); } //draw the center buttons if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.POWER)] == 1) { canvas.DrawCircle (offset + power_button [0] * Height, power_button [1] * Height, power_button [2] * Height, circle_paint); } if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_START)] == 1) { canvas.DrawCircle (offset + home_button [0] * Height, home_button [1] * Height, home_button [2] * Height, circle_paint); } //Android Gamepad: BUTTON_BACK, Xbox Gamepad: BUTTON_SELECT if (buttons [ButtonMapping.OrdinalValue (ButtonMapping.BUTTON_SELECT)] == 1) { canvas.DrawCircle (offset + back_button [0] * Height, back_button [1] * Height, back_button [2] * Height, circle_paint); } // Draw the axes if (buttons[ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_THUMBL)] == 1) { canvas.DrawCircle(left_axis_button[2] * Height + axis_leftX, left_axis_button[2] * Height + axis_leftY, left_axis_button[2] * Height, circle_paint); } if (buttons[ButtonMapping.OrdinalValue(ButtonMapping.BUTTON_THUMBR)] == 1) { canvas.DrawCircle(right_axis_button[2] * Height + axis_rightX, right_axis_button[2] * Height + axis_rightY, right_axis_button[2] * Height, circle_paint); } }
public override void OnDraw(Canvas canvas, Rect bounds) { if (Log.IsLoggable (Tag, LogPriority.Debug)) { Log.Debug (Tag, "onDraw"); } long now = Java.Lang.JavaSystem.CurrentTimeMillis (); time.Set (now); int milliseconds = (int)(now % 1000); int width = bounds.Width (); int height = bounds.Height (); // Draw the background, scaled to fit. if (backgroundScaledBitmap == null || backgroundScaledBitmap.Width != width || backgroundScaledBitmap.Height != height) { backgroundScaledBitmap = Bitmap.CreateScaledBitmap (backgroundBitmap, width, height, true /* filter */); } canvas.DrawColor (Color.Black); canvas.DrawBitmap (backgroundScaledBitmap, 0, 0, null); float centerX = width / 2.0f; float centerY = height / 2.0f; // Draw the ticks. float innerTickRadius = centerX - 10; float outerTickRadius = centerX; for (int tickIndex = 0; tickIndex < 12; tickIndex++) { float tickRot = (float)(tickIndex * Math.PI * 2 / 12); float innerX = (float)Math.Sin (tickRot) * innerTickRadius; float innerY = (float)-Math.Cos (tickRot) * innerTickRadius; float outerX = (float)Math.Sin (tickRot) * outerTickRadius; float outerY = (float)-Math.Cos (tickRot) * outerTickRadius; canvas.DrawLine (centerX + innerX, centerY + innerY, centerX + outerX, centerY + outerY, tickPaint); } float seconds = time.Second + milliseconds / 1000f; float secRot = seconds / 30f * (float)Math.PI; int minutes = time.Minute; float minRot = minutes / 30f * (float)Math.PI; float hrRot = ((time.Hour + (minutes / 60f)) / 6f) * (float)Math.PI; float secLength = centerX - 20; float minLength = centerX - 40; float hrLength = centerX - 80; if (!IsInAmbientMode) { float secX = (float)Math.Sin (secRot) * secLength; float secY = (float)-Math.Cos (secRot) * secLength; canvas.DrawLine (centerX, centerY, centerX + secX, centerY + secY, secondPaint); } float minX = (float)Math.Sin (minRot) * minLength; float minY = (float)-Math.Cos (minRot) * minLength; canvas.DrawLine (centerX, centerY, centerX + minX, centerY + minY, minutePaint); float hrX = (float)Math.Sin (hrRot) * hrLength; float hrY = (float)-Math.Cos (hrRot) * hrLength; canvas.DrawLine (centerX, centerY, centerX + hrX, centerY + hrY, hourPaint); if (IsVisible && !IsInAmbientMode) { Invalidate (); } }
protected override void OnDraw(Canvas canvas) { canvas.DrawColor(Color.Transparent); var p = new Paint() { AntiAlias = true }; SetLayerType(LayerType.Software, p); var now = SystemClock.UptimeMillis(); if (movieStart == 0) movieStart = now; if (movie != null) { int dur = movie.Duration(); if (dur == 0) dur = 1000; var relTime = (int)((now - movieStart) % dur); movie.SetTime(relTime); var movieWidth = (float)movie.Width(); var movieHeight = (float)movie.Height(); var scale = 1.0f; if (movieWidth > movieHeight) { scale = Width / movieWidth; if (scale * movieHeight > Height) scale = Height / movieHeight; } else { scale = Height / movieHeight; if (scale * movieWidth > Width) scale = Height / movieWidth; } canvas.Scale(scale, scale); try { movie.Draw(canvas, 0, 0, p); } catch (Exception ex) { Console.WriteLine("Exception thrown in OnDraw : {0}--{1}", ex.Message, ex.StackTrace); } if (playing) Invalidate(); } }