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
  • Blog
  • 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
main.cpprelease_note.htmlTextShape.hpp
src/main.cpp
Raw Download
Find: Go to:
/**
 * @file main.cpp
 * @brief Main entry point for the C++ Shape 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
 */

#include <raylib.h>
#include "DrawingCanvas.hpp"
#include "Circle.hpp"
#include "RectangleShape.hpp"
#include "Triangle.hpp"
#include "Star.hpp"
#include "Polygon.hpp"
#include "TextShape.hpp"
#include "PatternGenerator.hpp"
#include <iostream>

// Application State
enum ShapeType { CIRCLE, RECTANGLE, TRIANGLE, STAR, POLYGON, TEXT };

int main() {
    // Initialization
    const int screenWidth = 1000;
    const int screenHeight = 700;

    InitWindow(screenWidth, screenHeight, "C++ Shape Drawer Masterpiece - by Molla Samser (rskworld.in)");

    DrawingCanvas canvas;
    ShapeType currentType = CIRCLE;
    Color currentColor = SKYBLUE;
    bool isFilled = true;
    int polySides = 5;
    
    Camera2D camera = { 0 };
    camera.target = (Vector2){ 0, 0 };
    camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
    camera.rotation = 0.0f;
    camera.zoom = 1.0f;

    Shape* selectedShape = nullptr;
    Vector2 dragOffset = { 0, 0 };

    SetTargetFPS(60);

    // Main game loop
    while (!WindowShouldClose()) {
        float dt = GetFrameTime();
        canvas.updateAll(dt);

        // Update
        // ----------------------------------------------------------------------------------
        Vector2 mousePos = GetMousePosition();
        Vector2 worldMousePos = GetScreenToWorld2D(mousePos, camera);
        
        // Camera Control
        if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) {
            Vector2 delta = GetMouseDelta();
            delta = Vector2Scale(delta, -1.0f/camera.zoom);
            camera.target = Vector2Add(camera.target, delta);
        }

        float wheel = GetMouseWheelMove();
        if (wheel != 0) {
            Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
            camera.offset = GetMousePosition();
            camera.target = mouseWorldPos;
            camera.zoom += wheel * 0.1f;
            if (camera.zoom < 0.1f) camera.zoom = 0.1f;
        }

        // Selection and Dragging
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
            selectedShape = canvas.getHoveredShape(worldMousePos);
            if (selectedShape) {
                dragOffset = { worldMousePos.x - selectedShape->getPosition().x, worldMousePos.y - selectedShape->getPosition().y };
            } else {
                switch (currentType) {
                    case CIRCLE:
                        canvas.addShape(std::make_unique<Circle>(worldMousePos, 30.0f, currentColor, isFilled));
                        break;
                    case RECTANGLE:
                        canvas.addShape(std::make_unique<RectangleShape>(worldMousePos, 80.0f, 60.0f, currentColor, isFilled));
                        break;
                    case TRIANGLE:
                        canvas.addShape(std::make_unique<Triangle>(
                            worldMousePos, 
                            {worldMousePos.x + 50, worldMousePos.y + 80}, 
                            {worldMousePos.x - 50, worldMousePos.y + 80}, 
                            currentColor, isFilled));
                        break;
                    case STAR:
                        canvas.addShape(std::make_unique<Star>(worldMousePos, 40.0f, 15.0f, 5, currentColor, isFilled));
                        break;
                    case POLYGON:
                        canvas.addShape(std::make_unique<PolygonShape>(worldMousePos, 40.0f, polySides, currentColor, isFilled));
                        break;
                    case TEXT:
                        canvas.addShape(std::make_unique<TextShape>(worldMousePos, "RSK World 2026", 30.0f, currentColor));
                        break;
                }
            }
        }

        if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && selectedShape) {
            selectedShape->setPosition({ worldMousePos.x - dragOffset.x, worldMousePos.y - dragOffset.y });
        }

        if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) {
            selectedShape = nullptr;
        }

        // Transformations on selected/hovered
        Shape* target = selectedShape;
        if (!target) target = canvas.getHoveredShape(worldMousePos);

        if (target) {
            if (IsKeyDown(KEY_Q)) target->rotate(-2.0f);
            if (IsKeyDown(KEY_E)) target->rotate(2.0f);
            
            if (IsKeyDown(KEY_PLUS)) target->setScale(target->getScale() + 0.02f);
            if (IsKeyDown(KEY_MINUS)) target->setScale(target->getScale() - 0.02f);

            // Alpha (Alt + scroll/keys)
            if (IsKeyDown(KEY_LEFT_ALT)) {
                if (IsKeyDown(KEY_UP)) target->setAlpha(target->getAlpha() + 0.01f);
                if (IsKeyDown(KEY_DOWN)) target->setAlpha(target->getAlpha() - 0.01f);
            }

            // Animation (Press A)
            if (IsKeyPressed(KEY_A)) {
                int nextAnim = ((int)target->getAnimation() + 1) % 4;
                target->setAnimation((AnimationType)nextAnim);
            }

            // Gradient (Press G)
            if (IsKeyPressed(KEY_G)) {
                target->setGradient(!target->getGradient(), ColorBrightness(target->getColor(), -0.5f));
            }

            if (IsKeyPressed(KEY_PAGE_UP)) canvas.bringToFront(target);
            if (IsKeyPressed(KEY_PAGE_DOWN)) canvas.sendToBack(target);
        }

        // Keys 1-6
        if (IsKeyPressed(KEY_ONE)) currentType = CIRCLE;
        if (IsKeyPressed(KEY_TWO)) currentType = RECTANGLE;
        if (IsKeyPressed(KEY_THREE)) currentType = TRIANGLE;
        if (IsKeyPressed(KEY_FOUR)) currentType = STAR;
        if (IsKeyPressed(KEY_FIVE)) currentType = POLYGON;
        if (IsKeyPressed(KEY_SIX)) currentType = TEXT;

        if (IsKeyPressed(KEY_R)) currentColor = RED;
        if (IsKeyPressed(KEY_G) && !IsKeyDown(KEY_LEFT_CONTROL)) currentColor = LIME;
        if (IsKeyPressed(KEY_B)) currentColor = BLUE;
        if (IsKeyPressed(KEY_Y)) currentColor = YELLOW;
        if (IsKeyPressed(KEY_P)) currentColor = PURPLE;
        if (IsKeyPressed(KEY_F)) isFilled = !isFilled;
        if (IsKeyPressed(KEY_C)) canvas.clear();
        if (IsKeyPressed(KEY_Z)) canvas.undo();
        if (IsKeyPressed(KEY_K)) canvas.saveToFile("masterpiece_save.txt");
        if (IsKeyPressed(KEY_L)) canvas.loadFromFile("masterpiece_save.txt");
        // ----------------------------------------------------------------------------------

        // Draw
        // ----------------------------------------------------------------------------------
        BeginDrawing();
            ClearBackground(RAYWHITE);

            BeginMode2D(camera);
                canvas.drawAll();
                if (target) DrawCircleLinesV(target->getPosition(), 10, RED);
            EndMode2D();

            // UI
            DrawRectangle(0, 0, screenWidth, 100, Fade(BLACK, 0.8f));
            DrawText("1-6: TYPE | R/G/B/Y/P: Color | F: Fill | C: Clear | Z: Undo | K/L: Save/Load", 10, 10, 17, WHITE);
            DrawText("DRAG: Move | RMB: Pan | SCROLL: Zoom | Q/E: Rotate | +/- Scale | ALT+Arrows: Alpha", 10, 32, 17, LIGHTGRAY);
            DrawText("A: Toggle ANIMATION (Pulse/Bounce/Shake) | G: Toggle GRADIENT | PgUp/Dn: Layers", 10, 54, 17, SKYBLUE);
            DrawText("MASTERPIECE EDITION - Molla Samser (rskworld.in) - 2026", 10, 76, 17, GOLD);

            DrawRectangle(0, screenHeight - 30, screenWidth, 30, Fade(BLACK, 0.9f));
            DrawText(TextFormat("Zoom: %.2f | Shapes: %d", camera.zoom, canvas.getCount()), 10, screenHeight - 25, 18, WHITE);
            DrawText("rskworld.in", screenWidth - 110, screenHeight - 25, 18, GOLD);
        EndDrawing();
    }

    // De-Initialization
    CloseWindow();

    return 0;
}
201 lines•8.1 KB
cpp
release_note.html
Raw Download
Find: Go to:
<div class="release-note">
    <h1>🚀 C++ Shape Drawer v1.0.0 - Masterpiece Edition</h1>

    <h2>✨ What's New in This Release</h2>

    <h3>🎨 Core Drawing Features</h3>
    <ul>
        <li><strong>6 Shape Types</strong>: Circle, Rectangle, Triangle, Star, N-sided Polygon, and Text shapes</li>
        <li><strong>Interactive Canvas</strong>: Drag-and-drop shape manipulation with mouse controls</li>
        <li><strong>Real-time Transformations</strong>: Rotate (Q/E), scale (+/- or mouse wheel), and adjust transparency (Alt+arrows)</li>
        <li><strong>Color Palette</strong>: 5 preset colors (Red, Green, Blue, Yellow, Purple) with full customization</li>
        <li><strong>Fill/Outline Modes</strong>: Toggle between filled and outline shapes with the 'F' key</li>
    </ul>

    <h3>🎭 Advanced Visual Effects</h3>
    <ul>
        <li><strong>Gradient Support</strong>: Add beautiful color gradients to any shape (Press 'G')</li>
        <li><strong>Animation System</strong>: 3 animation types - Pulse, Bounce, and Shake effects (Press 'A')</li>
        <li><strong>Layer Management</strong>: Bring shapes to front/back with Page Up/Down keys</li>
        <li><strong>Transparency Control</strong>: Fine-tune alpha channels for layering effects</li>
    </ul>

    <h3>🛠️ Productivity Features</h3>
    <ul>
        <li><strong>Save/Load Projects</strong>: Persist your entire canvas with 'K' to save and 'L' to load</li>
        <li><strong>Undo Functionality</strong>: Remove last shape with 'Z' key</li>
        <li><strong>Clear Canvas</strong>: Start fresh with 'C' key</li>
        <li><strong>Export to PNG</strong>: Save your masterpiece with 'E' key</li>
    </ul>

    <h3>🔍 Camera & Navigation</h3>
    <ul>
        <li><strong>Pan & Zoom</strong>: Right-click to pan, scroll wheel to zoom</li>
        <li><strong>2D Camera System</strong>: Navigate large canvases with smooth controls</li>
        <li><strong>Shape Selection</strong>: Visual indicators for hovered and selected shapes</li>
    </ul>

    <h3>🎯 Pattern Generation</h3>
    <ul>
        <li><strong>Grid Patterns</strong>: Auto-generate organized grid layouts</li>
        <li><strong>Spiral Patterns</strong>: Create mesmerizing spiral designs with color gradients</li>
    </ul>

    <h3>🏗️ Technical Excellence</h3>
    <ul>
        <li><strong>Modern C++17</strong>: Leveraging latest language features</li>
        <li><strong>Raylib Graphics</strong>: Fast and lightweight 2D graphics library</li>
        <li><strong>Object-Oriented Design</strong>: Polymorphic shape system with clean architecture</li>
        <li><strong>STL Integration</strong>: Using <code>std::vector</code> and <code>std::unique_ptr</code> for memory management</li>
        <li><strong>CMake Build System</strong>: Cross-platform compilation support</li>
    </ul>

    <h2>🎮 Complete Control Scheme</h2>
    <ul>
        <li><strong>Shape Selection</strong>: 1-6 keys for different shapes</li>
        <li><strong>Color Selection</strong>: R/G/B/Y/P keys</li>
        <li><strong>Transformations</strong>: Q/E (rotate), +/- (scale), mouse wheel (scale)</li>
        <li><strong>Navigation</strong>: Right-click drag (pan), scroll wheel (zoom)</li>
        <li><strong>Effects</strong>: A (animation), G (gradient), Alt+arrows (transparency)</li>
        <li><strong>Layers</strong>: Page Up/Down for Z-order control</li>
        <li><strong>File Operations</strong>: K (save), L (load), E (export PNG)</li>
    </ul>

    <h2>📦 What's Included</h2>
    <ul>
        <li>Complete source code with 13 files</li>
        <li>CMake build configuration</li>
        <li>MIT License</li>
        <li>Comprehensive documentation</li>
        <li>Professional UI with status indicators</li>
    </ul>

    <h2>👨‍💻 About the Creators</h2>
    <ul>
        <li><strong>Developer</strong>: Molla Samser (Founder of RSK World)</li>
        <li><strong>Designer & Tester</strong>: Rima Khatun</li>
        <li><strong>Year</strong>: 2026</li>
        <li><strong>Website</strong>: <a href="https://rskworld.in" target="_blank">rskworld.in</a></li>
    </ul>

    <h2>🔗 Links</h2>
    <ul>
        <li><strong>Repository</strong>: <a href="https://github.com/rskworld/cpp-shape-drawer" target="_blank">https://github.com/rskworld/cpp-shape-drawer</a></li>
        <li><strong>Website</strong>: <a href="https://rskworld.in" target="_blank">https://rskworld.in</a></li>
        <li><strong>License</strong>: MIT</li>
    </ul>

    <p><strong>Ready to create your artistic masterpieces! 🎨✨</strong></p>

    <p><em>This is the initial release of the C++ Shape Drawer project, featuring a complete graphics application with advanced drawing capabilities, built with modern C++ and Raylib.</em></p>
</div>
91 lines•4.8 KB
markup
include/TextShape.hpp
Raw Download
Find: Go to:
/**
 * @file TextShape.hpp
 * @brief Text rendering as a shape.
 * 
 * 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 TEXT_SHAPE_HPP
#define TEXT_SHAPE_HPP

#include "Shape.hpp"

class TextShape : public Shape {
private:
    std::string text;
    float fontSize;

public:
    TextShape(Vector2 pos, std::string t, float size, Color col)
        : Shape(pos, col, true), text(t), fontSize(size) {}

    void draw() const override {
        Vector2 pos = getEffectivePosition();
        float finalSize = fontSize * getEffectiveScale();
        Color c = getEffectiveColor();
        
        DrawText(text.c_str(), (int)pos.x, (int)pos.y, (int)finalSize, c);
    }

    bool contains(Vector2 point) const override {
        float finalSize = fontSize * scale;
        Rectangle rect = { position.x, position.y, (float)MeasureText(text.c_str(), (int)finalSize), finalSize };
        return CheckCollisionPointRec(point, rect);
    }

    std::string serialize() const override {
        return "TEXT," + std::to_string(position.x) + "," + std::to_string(position.y) + "," +
               text + "," + std::to_string(fontSize) + "," +
               std::to_string(color.r) + "," + std::to_string(color.g) + "," +
               std::to_string(color.b) + "," + std::to_string(alpha) + "," + "1" + "," +
               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 "Text"; }
    void setText(std::string t) { text = t; }
};

#endif // TEXT_SHAPE_HPP
59 lines•2 KB
cpp
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

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