I am trying to convert a C# game to Android and need some help with
the graphics stuff.

Can anyone show me how to convert this to Java?

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace MyGame
{
 public partial class MyButton : Button
 {
   GraphicsPath path;
   GraphicsPath innerPath;

   private bool _clicked = false;
   public bool Clicked
   {
     get { return _clicked; }
     set
     {
       _clicked = value;
       Invalidate();
     }
   }

   public MyButton()
   {
     InitializeComponent();
   }

   protected override void OnPaint(PaintEventArgs pevent)
   {
     Graphics g = pevent.Graphics;
     g.SmoothingMode = SmoothingMode.AntiAlias;

     // Create painting objects
     Brush b = new SolidBrush(this.ForeColor);

     // Create Rectangle To Limit brush area.
     Rectangle rect = new Rectangle(0, 0, 150, 150);

     LinearGradientBrush linearBrush =
       new LinearGradientBrush(rect,
       Color.FromArgb(20,20,20),
       this.ForeColor,
       225);

     path = new GraphicsPath();
     innerPath = new GraphicsPath();

     path.AddArc(0, 0, 270, 270, 180, 90);
     path.AddArc(120, 0, 30, 30, 270, 90);
     path.AddLine(150, 0, 150, 85);
     path.AddArc(100, 100, 100, 100, -90, -90);
     path.AddLine(100, 150, 0, 150);
     path.AddArc(0, 120, 30, 30, 90, 90);

     innerPath.AddArc(10, 10, 250, 250, 180, 90);
     innerPath.AddArc(130, 10, 10, 10, 270, 90);
     innerPath.AddLine(140, 0, 140, 90);
     innerPath.AddArc(90, 90, 100, 100, -90, -90);
     innerPath.AddLine(90, 140, 10, 140);
     innerPath.AddArc(10, 130, 10, 10, 90, 90);

     this.Region = new Region(path);

     PathGradientBrush pgbrush = new PathGradientBrush(innerPath);
     pgbrush.CenterPoint = new Point(75, 75);
     pgbrush.CenterColor = Color.White;
     pgbrush.SurroundColors = new Color[] {
                            Color.FromArgb(250,this.ForeColor) };

     if (_clicked == false)
     {
       g.FillPath(linearBrush, path);
       g.FillPath(b, innerPath);
     }
     else
     {
       g.FillPath(linearBrush, path);
       g.FillPath(pgbrush, innerPath);
     }

     // Dispose of painting objects
     b.Dispose();
     pgbrush.Dispose();
     linearBrush.Dispose();
   }

   protected override void OnMouseEnter(EventArgs e)
   {
     this.Cursor = Cursors.Hand;
     base.OnMouseEnter(e);
   }

   protected override void OnMouseLeave(EventArgs e)
   {
     this.Cursor = Cursors.Arrow;
     base.OnMouseLeave(e);
   }

   protected override void OnMouseDown(MouseEventArgs mevent)
   {
     _clicked = true;
     base.OnMouseDown(mevent);
   }

   protected override void OnMouseUp(MouseEventArgs mevent)
   {
     _clicked = false;
     base.OnMouseUp(mevent);
   }
 }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

To unsubscribe from this group, send email to 
android-beginners+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to