help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
cpp-shape-drawer
/
include
RSK World
cpp-shape-drawer
C++ Shape Drawer - Advanced Graphics Application + Raylib + OOP Design + Shape Tools + Transformation + Export + Educational Design
include
  • Circle.hpp2 KB
  • DrawingCanvas.hpp7.3 KB
  • PatternGenerator.hpp1.6 KB
  • Polygon.hpp2.3 KB
  • RectangleShape.hpp2.7 KB
  • Shape.hpp4.2 KB
  • Star.hpp2.8 KB
  • TextShape.hpp2 KB
  • Triangle.hpp2.5 KB
RectangleShape.hpp
include/RectangleShape.hpp
Raw Download
Find: Go to:
/**
 * @file RectangleShape.hpp
 * @brief Rectangle shape implementation.
 * 
 * Part of the C++ Shape Drawer Project.
 * 
 * @author Molla Samser (Founder of RSK World)
 * @designer Rima Khatun
 * @website https://rskworld.in
 * @email hello@rskworld.in
 * @phone +91 93305 39277
 * @location Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
 * @year 2026
 */

#ifndef RECTANGLE_SHAPE_HPP
#define RECTANGLE_SHAPE_HPP

#include "Shape.hpp"

class RectangleShape : public Shape {
private:
    float width;
    float height;

public:
    RectangleShape(Vector2 pos, float w, float h, Color col, bool filled = true)
        : Shape(pos, col, filled), width(w), height(h) {}

    void draw() const override {
        float finalWidth = width * getEffectiveScale();
        float finalHeight = height * getEffectiveScale();
        Vector2 pos = getEffectivePosition();
        Rectangle rect = { pos.x, pos.y, finalWidth, finalHeight };
        Vector2 origin = { finalWidth / 2, finalHeight / 2 };
        Color c1 = getEffectiveColor();
        Color c2 = getEffectiveColor(true);
        
        if (useGradient && isFilled) {
            DrawRectangleGradientEx(rect, c1, c2, c2, c1);
        } else if (isFilled) {
            DrawRectanglePro(rect, origin, rotation, c1);
        } else {
            DrawRectangleLinesEx(rect, borderThickness, c1);
        }
    }

    bool contains(Vector2 point) const override {
        // Simple AABB check if not rotated, or OBB check if rotated
        if (rotation == 0.0f) {
            Rectangle rect = { position.x - (width * scale / 2), position.y - (height * scale / 2), width * scale, height * scale };
            return CheckCollisionPointRec(point, rect);
        } else {
            return CheckCollisionPointCircle(point, position, (width > height ? width : height) * scale / 2);
        }
    }

    std::string serialize() const override {
        return "RECT," + std::to_string(position.x) + "," + std::to_string(position.y) + "," +
               std::to_string(width) + "," + std::to_string(height) + "," +
               std::to_string(color.r) + "," + std::to_string(color.g) + "," +
               std::to_string(color.b) + "," + std::to_string(alpha) + "," + (isFilled ? "1" : "0") + "," +
               std::to_string(rotation) + "," + std::to_string(scale) + "," + (useGradient ? "1" : "0") + "," +
               std::to_string(secondaryColor.r) + "," + std::to_string(secondaryColor.g) + "," +
               std::to_string(secondaryColor.b) + "," + std::to_string((int)animType);
    }

    std::string getType() const override { return "Rectangle"; }
};

#endif // RECTANGLE_SHAPE_HPP
72 lines•2.7 KB
cpp

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer