The Shape Drawer project is a graphical application that allows users to draw, manipulate, and interact with various shapes on a canvas. This project is built using C# and leverages the SplashKitSDK library for graphical rendering and event handling. The application supports drawing rectangles, circles, and lines, with features such as shape selection, color changes, and background customization.
- Left-click on the canvas to draw a shape at the cursor’s position.
- Press
Rfor rectangles,Cfor circles, andLfor lines.
- Right-click on a shape to select it.
- Press
Escapeto change the shape's colour. - Press
BackspaceorDeleteto remove the selected shape.
- Press the
Spacekey to apply a random background colour.
- Supports drawing rectangles, circles, and lines.
- Shapes are placed on the canvas based on user input.
- Users can select individual shapes for modification.
- Selected shapes are visually highlighted.
- Shapes can change colour.
- Selected shapes can be deleted from the canvas.
- The canvas background can be modified.
- Various shortcuts enable quick interaction and modifications.
- The canvas updates dynamically to reflect changes.
This project is a great example of proper use of OOP principles:
- Encapsulation:
- Each shape class (
MyRectangle,MyCircle,MyLine) encapsulates its own properties (e.g., dimensions, position, color) and behavior (e.g., drawing, hit detection).
- Each shape class (
- Inheritance:
- All shape classes inherit from the abstract base class
Shape, which defines common properties and methods.
- All shape classes inherit from the abstract base class
- Polymorphism:
- The
Shapeclass defines abstract methods (Draw,DrawOutline,IsAt) that are overridden by the derived classes to provide shape-specific implementations.
- The
- Abstraction:
- The
Shapeclass abstracts the common functionality of all shapes, allowing the program to treat all shapes uniformly while delegating specific behavior to the derived classes.
- The
- Abstract Base Class (
Shape):- Defines common properties (
X,Y,Color,Selected) and methods (Draw,DrawOutline,IsAt) for all shapes.
- Defines common properties (
- Derived Classes:
MyRectangle: Implements rectangle-specific drawing and hit detection.MyCircle: Implements circle-specific drawing and hit detection.MyLine: Implements line-specific drawing and hit detection.
- Program Entry Point:
- The
Programclass contains theMainmethod, which handles user input, event processing, and rendering.
- The
- C#: The programming language used for the project.
- SplashKitSDK:
- A lightweight graphics library for rendering shapes, handling user input, and managing the application window.
- Provides methods like
FillRectangle,FillCircle,DrawLine, andPointInRectanglefor graphical operations.
- .NET 6.0: The runtime environment for executing the application. The integrated development environment (IDE) used for designing, coding, and debugging this project.
- Mouse Events:
- Left-click: Draws a new shape at the mouse position.
- Right-click: Selects a shape at the mouse position.
- Keyboard Events:
- Key presses are used to switch shape types, change colors, delete shapes, and modify the background.
- The
Drawingclass manages a collection of shapes and handles their rendering. - The
Drawmethod iterates through all shapes and calls their respectiveDrawmethods. - The
SelectedShapeAtmethod identifies and selects a shape based on the mouse position.
Below is a demonstration of the Shape Drawer in action:
This project is licensed under the Apache License.
