/* * public float pegarAlturaTela() { * float altura; * if (this.Width > this.Height) { * altura = Resources.DisplayMetrics.HeightPixels; * } else { * altura = Resources.DisplayMetrics.HeightPixels; * } * * return altura; * } * public float pegarLarguraTela() { * float largura; * if (this.Width > this.Height) { * largura = Resources.DisplayMetrics.WidthPixels; * } else { * largura = Resources.DisplayMetrics.WidthPixels; * } * * return largura; * } */ public void desenharPonteiro(RetanguloInfo rect, PonteiroCorEnum cor) { var strokePaint = new Paint(PaintFlags.AntiAlias); strokePaint.SetStyle(Paint.Style.Stroke); strokePaint.StrokeWidth = 6; //strokePaint.StrokeCap = Paint.Cap.Round; //strokePaint.Color = Color.Blue; switch (cor) { case PonteiroCorEnum.Verde: strokePaint.Color = EstiloUtils.Velocimentro.PonteiroCor.Verde.ToAndroid(); break; case PonteiroCorEnum.Vermelho: strokePaint.Color = EstiloUtils.Velocimentro.PonteiroCor.Vermelho.ToAndroid(); break; case PonteiroCorEnum.CinzaClaro: strokePaint.Color = EstiloUtils.Velocimentro.PonteiroCor.CinzaClaro.ToAndroid(); break; default: strokePaint.Color = EstiloUtils.Velocimentro.PonteiroCor.Padrao.ToAndroid(); break; } _canvas.DrawLine( rect.Left, rect.Top, rect.Right, rect.Bottom, strokePaint ); }
public void desenharTextoVelocidade(string Texto, float x, float y, PonteiroCorEnum cor) { var strokePaint = new Paint(PaintFlags.AntiAlias); strokePaint.SetStyle(Paint.Style.Fill); strokePaint.StrokeWidth = 3; float tamanhoTexto = 0; strokePaint.Color = pegarCor(cor); if (TelaAndroid.Largura > TelaAndroid.Altura) { float testTextSize = 5.3f; float desiredTextSize = (float)(TelaAndroid.Altura * 45 / 100) / testTextSize; strokePaint.TextSize = desiredTextSize; tamanhoTexto = strokePaint.MeasureText(Texto); } else { float testTextSize = 4f; float desiredTextSize = (float)(TelaAndroid.Largura * 45 / 100) / testTextSize; strokePaint.TextSize = desiredTextSize; tamanhoTexto = strokePaint.MeasureText(Texto); } if (this.Width > this.Height) { _canvas.DrawText(Texto, (TelaAndroid.Altura - tamanhoTexto) / 2, y, strokePaint); } else { _canvas.DrawText(Texto, (TelaAndroid.Largura - tamanhoTexto) / 2, y, strokePaint); } }
public void desenharPonteiro(RetanguloInfo rect, PonteiroCorEnum cor) { var currentContext2 = UIGraphics.GetCurrentContext(); currentContext2.SetLineWidth(3); currentContext2.SetFillColor(pegarCor(cor)); //currentContext2.SetStrokeColor(UIColor.Red.CGColor); currentContext2.SetStrokeColor(pegarCor(cor)); currentContext2.MoveTo(rect.Top, rect.Left); currentContext2.AddLineToPoint(rect.Bottom, rect.Right); currentContext2.DrawPath(CoreGraphics.CGPathDrawingMode.FillStroke); }
public void desenharTextoLabel(string Texto, float x, float y, PonteiroCorEnum cor) { var currentContext = UIGraphics.GetCurrentContext(); currentContext.SelectFont("Arial", 22f, CGTextEncoding.MacRoman); currentContext.SetTextDrawingMode(CGTextDrawingMode.Fill); currentContext.SetFillColor(pegarCor(cor)); var nsText = new NSString(Texto); var boundSize = new SizeF((float)x, float.MaxValue); var options = NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin; var attributes = new UIStringAttributes { Font = UIFont.FromName("Arial", (float)22) }; var sizeF = nsText.GetBoundingRect(boundSize, options, attributes, null).Size; if (TelaUtils.Orientacao == "LandscapeLeft" || TelaUtils.Orientacao == "LandscapeRight") { if (TelaUtils.Dispositivo == "Pad") { currentContext.ShowTextAtPoint((this.pegarLarguraTela() - sizeF.Width) / 3, y - 60, Texto); } else { currentContext.ShowTextAtPoint((this.pegarLarguraTela() - sizeF.Width) / 3, y - 65, Texto); } } else { if (TelaUtils.Dispositivo == "Pad") { currentContext.ShowTextAtPoint((this.pegarLarguraTela() - sizeF.Width) / 2, y - 300, Texto); } else { currentContext.ShowTextAtPoint((this.pegarLarguraTela() - sizeF.Width) / 2, y - 35, Texto); } } currentContext.DrawPath(CoreGraphics.CGPathDrawingMode.FillStroke); }
public void desenharTexto(string Texto, float x, float y, PonteiroCorEnum cor) { var currentContext = UIGraphics.GetCurrentContext(); currentContext.SelectFont("Arial", 16f, CGTextEncoding.MacRoman); currentContext.SetTextDrawingMode(CGTextDrawingMode.Fill); //currentContext.SetFillColor(UIColor.Red.CGColor); currentContext.SetFillColor(pegarCor(cor)); if (TelaUtils.Orientacao == "LandscapeLeft" || TelaUtils.Orientacao == "LandscapeRight") { currentContext.ShowTextAtPoint(y - 10, x, Texto); } else { currentContext.ShowTextAtPoint(y - 10, x + 15, Texto); } currentContext.DrawPath(CoreGraphics.CGPathDrawingMode.FillStroke); }
public void desenharTexto(string Texto, float x, float y, PonteiroCorEnum cor) { var strokePaint = new Paint(PaintFlags.AntiAlias); strokePaint.SetStyle(Paint.Style.Fill); strokePaint.StrokeWidth = 3; strokePaint.Color = pegarCor(cor); if (TelaAndroid.Largura > TelaAndroid.Altura) { float testTextSize = 7f; float desiredTextSize = (float)(TelaAndroid.Altura * 30 / 100) / testTextSize; strokePaint.TextSize = desiredTextSize; } else { float testTextSize = 5f; float desiredTextSize = (float)(TelaAndroid.Largura * 30 / 100) / testTextSize; strokePaint.TextSize = desiredTextSize; } _canvas.DrawText(Texto, x, y, strokePaint); }
private Color pegarCor(PonteiroCorEnum cor) { Color retorno; switch (cor) { case PonteiroCorEnum.Verde: retorno = EstiloUtils.Velocimentro.TextoCor.Verde.ToAndroid(); break; case PonteiroCorEnum.Vermelho: retorno = EstiloUtils.Velocimentro.TextoCor.Vermelho.ToAndroid(); break; case PonteiroCorEnum.CinzaClaro: retorno = EstiloUtils.Velocimentro.TextoCor.CinzaClaro.ToAndroid(); break; default: retorno = EstiloUtils.Velocimentro.TextoCor.Padrao.ToAndroid(); break; } return(retorno); }
private CGColor pegarCor(PonteiroCorEnum cor) { CGColor retorno; switch (cor) { case PonteiroCorEnum.Verde: retorno = UIColor.Green.CGColor; break; case PonteiroCorEnum.Vermelho: retorno = UIColor.Red.CGColor; break; case PonteiroCorEnum.CinzaClaro: retorno = UIColor.LightGray.CGColor; break; default: retorno = UIColor.Gray.CGColor; break; } return(retorno); }
public void desenhar() { PonteiroCorEnum textoCor = PonteiroCorEnum.Verde; if (VelocidadeRadar > 0 && VelocidadeAtual > VelocidadeRadar) { textoCor = PonteiroCorEnum.Vermelho; } if (TelaUtils.Largura > TelaUtils.Altura) { desenharTextoLabel("km/h", TelaUtils.Largura / 4.3F, TelaUtils.Altura / 1.7F, textoCor); if (Math.Floor(VelocidadeAtual) < 0) { desenharTextoVelocidade("0", TelaUtils.Largura / 4F, TelaUtils.Altura / 2F, textoCor); } else { desenharTextoVelocidade(Math.Floor(VelocidadeAtual).ToString(), TelaUtils.Largura / 4F, TelaUtils.Altura / 2F, textoCor); } } else { desenharTextoLabel("km/h", TelaUtils.Largura / 2.5F, TelaUtils.Altura / 3F, textoCor); desenharTextoVelocidade(Math.Floor(VelocidadeAtual).ToString(), TelaUtils.Largura / 2.3F, TelaUtils.Altura / 3.5F, textoCor); } //int contadorTexto = 0; if (Device.OS == TargetPlatform.iOS) { _loopInicio = 50; _loopFim = 110; } /* * for (var loop = _loopInicio; loop <= _loopFim; loop++) * { * float tamX = 0; * float tamY = 0; * PonteiroCorEnum cor = PonteiroCorEnum.Cinza; * if (loop % 5 == 0) * { * * if (TelaUtils.Largura > TelaUtils.Altura) * { * tamX = (TelaUtils.Largura / 3.8F) + (float)Math.Floor(((TelaUtils.Largura * 25 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); * tamY = (TelaUtils.Altura / 2F) + (float)Math.Floor(((TelaUtils.Largura * 25 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); * * } * else { * tamX = (TelaUtils.Largura / 2.2F) + (float)Math.Floor(((TelaUtils.Altura * 23 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); * tamY = (TelaUtils.Altura / 3.4F) + (float)Math.Floor(((TelaUtils.Altura * 23 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); * * } * * if (contadorTexto <= (int)VelocidadeAtual / 2) * { * cor = PonteiroCorEnum.Cinza; * } * else { * cor = PonteiroCorEnum.Verde; * } * * if (contadorTexto == (int)VelocidadeRadar / 2) * { * cor = PonteiroCorEnum.Vermelho; * } * * if (contadorTexto > (int)VelocidadeRadar / 2) * { * cor = PonteiroCorEnum.CinzaClaro; * } * * desenharTexto(num.ToString(), tamX, tamY, cor); * num = num + 10; * } * contadorTexto++; * * * } */ int count = 0; //, num = 120; if (Device.OS == TargetPlatform.iOS) { _loopInicio = 10; _loopFim = 70; } float tamX = 0, tamY = 0; int velocidade = 120; //for (var loop = _loopInicio - 20; loop <= _loopFim - 20; loop++) for (var loop = _loopFim - 20; loop >= _loopInicio - 20; loop--) { RetanguloInfo rect = new RetanguloInfo(); velocidade = count * 2; PonteiroCorEnum cor = pegarCor(velocidade); if (loop % 5 == 0) { //int posicao = loop + 20; int posicao = 100 - loop; if (TelaUtils.Largura > TelaUtils.Altura) { if (TelaUtils.Dispositivo == "Pad" || TelaUtils.Dispositivo == "Phone") { rect.Left = (int)Math.Floor((TelaUtils.Largura / 3.5F) + (float)((TelaUtils.Largura * 40 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 3.5F + (float)((TelaUtils.Largura * 40 / 100) / 1.90F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 2F) + (float)((TelaUtils.Largura * 40 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 2F + (float)((TelaUtils.Largura * 40 / 100) / 1.90 * Math.Cos(loop * 6 * Math.PI / 240))); tamX = (TelaUtils.Largura / 3.8F) + (float)Math.Floor(((TelaUtils.Largura * 25 / 100) / 1.50F * Math.Cos(posicao * 6 * Math.PI / 240))); tamY = (TelaUtils.Altura / 2F) + (float)Math.Floor(((TelaUtils.Largura * 25 / 100) / 1.50F * Math.Sin(posicao * 6 * Math.PI / 240))); } else { rect.Left = (int)Math.Floor((TelaUtils.Largura / 3.5F) + (float)((TelaUtils.Largura * 30 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 3.5F + (float)((TelaUtils.Largura * 30 / 100) / 1.90F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 2F) + (float)((TelaUtils.Largura * 30 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 2F + (float)((TelaUtils.Largura * 30 / 100) / 1.90 * Math.Cos(loop * 6 * Math.PI / 240))); tamX = (TelaUtils.Largura / 3.8F) + (float)Math.Floor(((TelaUtils.Largura * 20 / 100) / 1.50F * Math.Cos(posicao * 6 * Math.PI / 240))); tamY = (TelaUtils.Altura / 2F) + (float)Math.Floor(((TelaUtils.Largura * 20 / 100) / 1.50F * Math.Sin(posicao * 6 * Math.PI / 240))); } } else { rect.Left = (int)Math.Floor((TelaUtils.Largura / 2F) + (float)((TelaUtils.Largura * 60 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 2F + (float)((TelaUtils.Largura * 60 / 100) / 1.90F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 3.5F) + (float)((TelaUtils.Largura * 60 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 3.5F + (float)((TelaUtils.Largura * 60 / 100) / 1.90 * Math.Cos(loop * 6 * Math.PI / 240))); tamX = (TelaUtils.Largura / 2.2F) + (float)Math.Floor(((TelaUtils.Altura * 23 / 100) / 1.50F * Math.Cos(posicao * 6 * Math.PI / 240))); tamY = (TelaUtils.Altura / 3.4F) + (float)Math.Floor(((TelaUtils.Altura * 23 / 100) / 1.50F * Math.Sin(posicao * 6 * Math.PI / 240))); if (TelaUtils.Orientacao == "LandscapeLeft" || TelaUtils.Orientacao == "LandscapeRight") { rect.Left = (int)Math.Floor((TelaUtils.Largura / 2F) + (float)((TelaUtils.Largura * 50 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 2F + (float)((TelaUtils.Largura * 50 / 100) / 1.90F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 3F) + (float)((TelaUtils.Largura * 50 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 3F + (float)((TelaUtils.Largura * 50 / 100) / 1.90 * Math.Cos(loop * 6 * Math.PI / 240))); if (TelaUtils.Dispositivo == "Pad") { tamX = (TelaUtils.Largura / 2F) + (float)Math.Floor(((TelaUtils.Altura * 24 / 100) / 1.50F * Math.Cos(posicao * 6 * Math.PI / 240))); tamY = (TelaUtils.Altura / 3F) + (float)Math.Floor(((TelaUtils.Altura * 24 / 100) / 1.50F * Math.Sin(posicao * 6 * Math.PI / 240))); } else { tamX = (TelaUtils.Largura / 2F) + (float)Math.Floor(((TelaUtils.Altura * 18 / 100) / 1.50F * Math.Cos(posicao * 6 * Math.PI / 240))); tamY = (TelaUtils.Altura / 3F) + (float)Math.Floor(((TelaUtils.Altura * 18 / 100) / 1.50F * Math.Sin(posicao * 6 * Math.PI / 240))); } } } /* * if (count <= (120 - (int)VelocidadeAtual) / 2 - 2) * { * cor = PonteiroCorEnum.Verde; * } * * if (count < (120 - (int)VelocidadeRadar) / 2 + 2) * { * cor = PonteiroCorEnum.CinzaClaro; * } * * if (count == radarVelocidade()) * { * cor = PonteiroCorEnum.Vermelho; * } */ //desenharPonteiro(rect, cor); //if (loop < (_loopFim - 40)) //{ desenharTexto(velocidade.ToString(), tamX, tamY, cor); //num = num - 10; //} } else { if (TelaUtils.Largura > TelaUtils.Altura) { if (TelaUtils.Dispositivo == "Pad" || TelaUtils.Dispositivo == "Phone") { rect.Left = (int)Math.Floor((TelaUtils.Largura / 3.5F) + (float)((TelaUtils.Largura * 40 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 3.5F + (float)((TelaUtils.Largura * 40 / 100) / 1.70F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 2F) + (float)((TelaUtils.Largura * 40 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 2F + (float)((TelaUtils.Largura * 40 / 100) / 1.70 * Math.Cos(loop * 6 * Math.PI / 240))); } else { rect.Left = (int)Math.Floor((TelaUtils.Largura / 3.5F) + (float)((TelaUtils.Largura * 30 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 3.5F + (float)((TelaUtils.Largura * 30 / 100) / 1.70F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 2F) + (float)((TelaUtils.Largura * 30 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 2F + (float)((TelaUtils.Largura * 30 / 100) / 1.70 * Math.Cos(loop * 6 * Math.PI / 240))); } } else { rect.Left = (int)Math.Floor((TelaUtils.Largura / 2F) + (float)((TelaUtils.Largura * 60 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 2F + (float)((TelaUtils.Largura * 60 / 100) / 1.70F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 3.5F) + (float)((TelaUtils.Largura * 60 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 3.5F + (float)((TelaUtils.Largura * 60 / 100) / 1.70 * Math.Cos(loop * 6 * Math.PI / 240))); if (TelaUtils.Orientacao == "LandscapeLeft" || TelaUtils.Orientacao == "LandscapeRight") { rect.Left = (int)Math.Floor((TelaUtils.Largura / 2F) + (float)((TelaUtils.Largura * 50 / 100) / 1.50F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Right = (int)Math.Floor(TelaUtils.Largura / 2F + (float)((TelaUtils.Largura * 50 / 100) / 1.70F * Math.Sin(loop * 6 * Math.PI / 240))); rect.Top = (int)Math.Floor((TelaUtils.Altura / 3F) + (float)((TelaUtils.Largura * 50 / 100) / 1.50F * Math.Cos(loop * 6 * Math.PI / 240))); rect.Bottom = (int)Math.Floor(TelaUtils.Altura / 3F + (float)((TelaUtils.Largura * 50 / 100) / 1.70 * Math.Cos(loop * 6 * Math.PI / 240))); } } /* * if (count <= (120 - (int)VelocidadeAtual) / 2) * { * cor = PonteiroCorEnum.Verde; * } * * if (count < (120 - (int)VelocidadeRadar) / 2) * { * cor = PonteiroCorEnum.CinzaClaro; * } */ //desenharPonteiro(rect, cor); } /* * * if (count <= (120 - (int)VelocidadeAtual) / 2 - 2) * cor = PonteiroCorEnum.Verde; * * if (count < (120 - (int)VelocidadeRadar) / 2 + 2) * cor = PonteiroCorEnum.CinzaClaro; * * if (count == radarVelocidade()) * cor = PonteiroCorEnum.Vermelho; */ desenharPonteiro(rect, cor); count++; } }