Lec18 - Lecture 18 Graphics Classes PIC 10C Todd Wittman...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lecture 18: Graphics Classes PIC 10C Todd Wittman Graphics Classes s So far the graphics we've used are just painted on the screen. s But what if we want to move our shape? Or resize it? Or change the drawing order? s In order to manipulate our graphics, we need to create classes to store our shapes. s Today I will show you a basic Rectangle shape class, but it could be extended to more interesting shapes.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The Shape10C Class s We will create an abstract Shape class. s The class won't do anything, but its children must override the abstract functions we specify. public abstract class Shape10C { protected Color shapeColor; public bool isVisible = false; public abstract void Move(int dx, int dy); public abstract void Draw(Graphics g); public abstract bool IsPointInside(Point p); public abstract void MouseDownCreating(Point p, Graphics g); public abstract void MouseMoveCreating(Point p, Graphics g); public Color Get_color(); public void Set_color(Color c); } The only common properties to all shapes are the color and whether we want to show the shape. The Rectangle10C Class public class Rectangle10C : Shape10C { protected Point upperLeftCorner; protected int width; protected int height; } public Rectangle10C(Color c) { isVisible = false; shapeColor = c; upperLeftCorner = new Point(0, 0); width = 0; height = 0; } s Using the Default constructor, we probably don't want to show the rectangle just yet. public Rectangle10C(Color c, Point p, int w, int h) { isVisible = true; shapeColor = c; upperLeftCorner = p; width = w; height = h; } s If we specify all parameters of the rectangle, then it's ready to be shown. width
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

Lec18 - Lecture 18 Graphics Classes PIC 10C Todd Wittman...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online