override public void Draw(PaintEventArgs e, int height, int width, int x, int y) { if (e.ClipRectangle.Contains(x, y)) { Graphics g = e.Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // make a bounding rectangle for the piece Rectangle r = new Rectangle(x, y, width, height); // make a brush to draw a filled ellipse Brush b1 = new SolidBrush(m_ColorofPiece); // draw the ellipse that represents the piece g.FillEllipse(b1, r); // Dynamically calculate a thickness based on the size of the board float thickness = ((float)width + (float)height) / 50; // Create a pen of that thickness with adjust color and draw the ellipse Pen p = new Pen(ColorFunctions.AdjustBrightness(m_ColorofPiece, .5), thickness * 2); g.DrawEllipse(p, r); p = new Pen(ColorFunctions.AdjustBrightness(m_ColorofPiece, 1.35), thickness); g.DrawEllipse(p, r); // if the piece is a king if (isKing) { Brush b2 = new SolidBrush(ColorFunctions.AdjustBrightness(m_ColorofPiece, .5)); // position the crown one fouth the width to the right int x_crown = x + (width / 4); // position the crown one third the way down the height int y_top_crown = y + (height / 3); // position the base of the crown one third the way down of the position of the whole crown int y_base_crown = y_top_crown + (height / 9); // crown width and height int crown_width = width / 2; int crown_base_height = (2 * height) / 9; int crown_top_height = height / 9; // draw the base of the crown g.FillRectangle(b2, x_crown, y_base_crown, crown_width, crown_base_height); // put the spikes on top of the crown g.FillRectangle(b2, x_crown, y_top_crown, crown_width / 6, crown_top_height); g.FillRectangle(b2, x_crown + ((float)crown_width / 6) * 2, y_top_crown, crown_width / 3, crown_top_height); g.FillRectangle(b2, x_crown + ((float)crown_width / 6) * 5, y_top_crown, crown_width / 6, crown_top_height); } } }
public void Draw(PaintEventArgs e, int x, int y, int width, int height) { // get the graphics object Graphics g = e.Graphics; // make it draw smooth edges g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // dynamically change the thickness of the lines drawn at the edge of each piece int thickness = (width + height) / 75; Point top_left = new Point(x, y); Point top_right = new Point(x + width - thickness, y); Point bottom_left = new Point(x, y + height - thickness); Point bottom_right = new Point(x + width - thickness, y + height - thickness); // if the current space is selected, use brighter colors to make it stand out if (m_isSelected) { Brush b = new SolidBrush(ColorFunctions.AdjustBrightness(m_background, 1.25)); g.FillRectangle(b, x, y, width, height); } // otherwise use the normal background color else { Brush b = new SolidBrush(m_background); g.FillRectangle(b, x, y, width, height); } // get a pen in a brighter shade of the background color and // highlight the top and left edges of the boardspace Pen p = new Pen(ColorFunctions.AdjustBrightness(m_background, 1.5), thickness); e.Graphics.DrawLine(p, bottom_left, top_left); e.Graphics.DrawLine(p, top_left, top_right); // go ahead and adjust the color to a darker shade of the background color // and have the pen draw lowlights on the bottom and right edge of the space p.Color = ColorFunctions.AdjustBrightness(m_background, 0.6); e.Graphics.DrawLine(p, bottom_left, bottom_right); e.Graphics.DrawLine(p, bottom_right, top_right); // if there is a piece in this space, tell it to draw if (!this.Empty()) { // calculate the pieces location and size int p_height = (2 * height) / 3; int p_width = (2 * width) / 3; int p_x = x + width / 6; int p_y = y + height / 6; // draw the piece m_occupyingpiece.Draw(e, p_height, p_width, p_x, p_y); } }