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
Shape.hpp
include/Shape.hpp
Raw Download
Find: Go to:
/**
 * @file Shape.hpp
 * @brief Base abstract class for all shapes in the drawer application.
 * 
 * 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 SHAPE_HPP
#define SHAPE_HPP

#include <raylib.h>
#include <string>

/**
 * @class Shape
 * @brief Abstract base class representing a geometric shape.
 */
enum AnimationType { NONE = 0, PULSE, BOUNCE, SHAKE };

class Shape {
protected:
    Vector2 position;
    Color color;
    bool isFilled;
    float borderThickness;
    float rotation; // In degrees
    float scale;
    float alpha;    // 0.0 to 1.0

    // Masterpiece Features
    bool useGradient;
    Color secondaryColor;
    AnimationType animType;
    float animTime;

public:
    Shape(Vector2 pos, Color col, bool filled = true, float thickness = 2.0f)
        : position(pos), color(col), isFilled(filled), borderThickness(thickness), 
          rotation(0.0f), scale(1.0f), alpha(col.a / 255.0f),
          useGradient(false), secondaryColor(col), animType(NONE), animTime(0.0f) {}

    virtual ~Shape() {}

    // Pure virtual function to be implemented by derived classes
    virtual void draw() const = 0;

    // Hit testing for selection
    virtual bool contains(Vector2 point) const = 0;

    // Serialization
    virtual std::string serialize() const = 0;

    // Update for animations
    virtual void update(float deltaTime) {
        if (animType != NONE) {
            animTime += deltaTime;
        }
    }

    // Masterpiece Getters/Setters
    void setGradient(bool active, Color second = WHITE) { useGradient = active; secondaryColor = second; }
    bool getGradient() const { return useGradient; }
    Color getSecondaryColor() const { return secondaryColor; }

    void setAnimation(AnimationType type) { animType = type; animTime = 0.0f; }
    AnimationType getAnimation() const { return animType; }

    // Unified color getter including alpha and animations
    Color getEffectiveColor(bool secondary = false) const {
        Color base = secondary ? secondaryColor : color;
        float finalAlpha = alpha;
        
        // Pulse animation affect alpha/scale but draw() needs to handle scale
        if (animType == PULSE) {
            finalAlpha *= (0.5f + 0.5f * sinf(animTime * 5.0f));
        }
        
        base.a = (unsigned char)(finalAlpha * 255);
        return base;
    }

    float getEffectiveScale() const {
        if (animType == PULSE) return scale * (1.0f + 0.1f * sinf(animTime * 5.0f));
        return scale;
    }

    Vector2 getEffectivePosition() const {
        Vector2 pos = position;
        if (animType == BOUNCE) pos.y -= fabsf(sinf(animTime * 10.0f)) * 50.0f * scale;
        if (animType == SHAKE) {
            pos.x += (float)GetRandomValue(-5, 5) * scale;
            pos.y += (float)GetRandomValue(-5, 5) * scale;
        }
        return pos;
    }

    // Movement
    virtual void move(Vector2 delta) {
        position.x += delta.x;
        position.y += delta.y;
    }

    // Common getters and setters
    virtual void setPosition(Vector2 pos) { position = pos; }
    virtual Vector2 getPosition() const { return position; }

    virtual void setColor(Color col) { color = col; alpha = col.a / 255.0f; }
    virtual Color getColor() const { 
        Color c = color;
        c.a = (unsigned char)(alpha * 255);
        return c;
    }

    virtual void setFilled(bool filled) { isFilled = filled; }
    virtual bool getFilled() const { return isFilled; }

    virtual void setRotation(float rot) { rotation = rot; }
    virtual float getRotation() const { return rotation; }
    virtual void rotate(float angle) { rotation += angle; }

    virtual void setScale(float s) { scale = s; }
    virtual float getScale() const { return scale; }

    virtual void setAlpha(float a) { alpha = a; if (alpha < 0) alpha = 0; if (alpha > 1) alpha = 1; }
    virtual float getAlpha() const { return alpha; }

    virtual std::string getType() const = 0;
};

#endif // SHAPE_HPP
139 lines•4.2 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