Skip to content

Commit

Permalink
Comment renderer and viewer class
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAugust12 committed Dec 10, 2023
1 parent 260a30d commit 3df3e84
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 11 deletions.
104 changes: 102 additions & 2 deletions src/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,129 @@

// clang-format on
#include <Graphics.hpp>

/**
* @brief Singleton class responsible for rendering shapes using GDI+.
*
* The Renderer class provides a singleton instance for drawing SVGElement-based
* shapes using Gdiplus::Graphics. It supports various shapes such as lines,
* rectangles, circles, ellipses, text, polygons, polylines, and paths. The
* shapes are drawn in a polymorphic manner using the draw function, which takes
* a Gdiplus::Graphics context and an SVGElement. The draw function dynamically
* determines the type of the shape and invokes the corresponding draw method to
* render the shape with all necessary details. The detailed information for
* each shape is obtained from an SVG file and processed through the draw
* function in a polymorphic way.
*/
class Renderer {
public:
/**
* @brief Gets the singleton instance of the Renderer class.
*
* @return The singleton instance of the Renderer class.
*/
static Renderer* getInstance();

/**
* @brief Deleted copy constructor to enforce the singleton pattern.
*/
Renderer(const Renderer&) = delete;

/**
* @brief Deleted copy assignment operator to enforce the singleton pattern.
*/
void operator=(const Renderer&) = delete;

/**
* @brief Draws a shape using Gdiplus::Graphics based on its type.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param shape The SVGElement representing the shape to be drawn.
*/
void draw(Gdiplus::Graphics& graphics, Group* group) const;

private:
/**
* @brief Utility function to apply a series of transformations to the
* graphics context.
*
* @param transform_order The order in which transformations should be
* applied.
* @param graphics The Gdiplus::Graphics context to apply transformations
* to.
*/
void applyTransform(std::vector< std::string > transform_order,
Gdiplus::Graphics& graphics) const;

/**
* @brief Draws a line shape using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param line The Line object representing the line to be drawn.
*/
void drawLine(Gdiplus::Graphics& graphics, Line* line) const;

/**
* @brief Draws a rectangle shape using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param rectangle The Rect object representing the rectangle to be drawn.
*/
void drawRectangle(Gdiplus::Graphics& graphics, Rect* rectangle) const;

/**
* @brief Draws a circle shape using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param circle The Circle object representing the circle to be drawn.
*/
void drawCircle(Gdiplus::Graphics& graphics, Circle* circle) const;

/**
* @brief Draws an ellipse shape using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param ellipse The Ell object representing the ellipse to be drawn.
*/
void drawEllipse(Gdiplus::Graphics& graphics, Ell* ellipse) const;

/**
* @brief Draws a polygon shape using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param polygon The Plygon object representing the polygon to be drawn.
*/
void drawPolygon(Gdiplus::Graphics& graphics, Plygon* polygon) const;

/**
* @brief Draws text using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param text The Text object representing the text to be drawn.
*/
void drawText(Gdiplus::Graphics& graphics, Text* text) const;

/**
* @brief Draws a polyline shape using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param polyline The Plyline object representing the polyline to be drawn.
*/
void drawPolyline(Gdiplus::Graphics& graphics, Plyline* polyline) const;

/**
* @brief Draws a path shape using Gdiplus::Graphics.
*
* @param graphics The Gdiplus::Graphics context for drawing.
* @param path The Path object representing the path to be drawn.
*/
void drawPath(Gdiplus::Graphics& graphics, Path* path) const;

/**
* @brief Private constructor for the Renderer class.
*/
Renderer();
static Renderer* instance;

static Renderer* instance; ///< Singleton instance of the Renderer class
};

#endif
93 changes: 84 additions & 9 deletions src/Viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,109 @@

#include "Renderer.hpp"

/**
* @brief Represents a viewer for rendering and interacting with a scene.
*
*
* The viewer supports the following interactions:
* - Rotation: Press 'Q' to rotate the view counterclockwise and 'E' to rotate
* clockwise.
* - Zooming: Use the scroll wheel to zoom in and out of the scene.
* - Translation: Click and drag the left mouse button to translate the view.
*/
class Viewer {
public:
float offsetX;
float offsetY;
float zoomFactor;
float rotateAngle;
bool needsRepaint;
float offsetX; ///< X-coordinate offset of the viewer
float offsetY; ///< Y-coordinate offset of the viewer
float zoomFactor; ///< Zoom factor for scaling the view
float rotateAngle; ///< Rotation angle of the view
bool needsRepaint; ///< Flag indicating whether the view needs to be
///< repainted

/**
* @brief Gets the singleton instance of the Viewer class.
*
* @return The singleton instance of the Viewer class.
*/
static Viewer* getInstance();

/**
* @brief Destructor for the Viewer class.
*/
~Viewer();

/**
* @brief Handles mouse events, such as wheel, move, left button down, and
* left button up.
*
* @param message The Windows message identifier.
* @param wParam The WPARAM parameter of the message.
* @param lParam The LPARAM parameter of the message.
*/
void handleMouseEvent(UINT message, WPARAM wParam, LPARAM lParam);

/**
* @brief Handles keyboard events.
*
* @param wParam The WPARAM parameter of the message.
*/
void handleKeyEvent(WPARAM wParam);

private:
static Viewer* instance;
static Viewer* instance; ///< Singleton instance of the Viewer class

/**
* @brief Private constructor for the Viewer class.
*/
Viewer();

/**
* @brief Copy constructor for the Viewer class (deleted to enforce
* singleton pattern).
*/
Viewer(const Viewer&) = delete;

/**
* @brief Copy assignment operator for the Viewer class (deleted to enforce
* singleton pattern).
*/
void operator=(const Viewer&) = delete;

bool isDragging;
POINT lastMousePos;
bool isDragging; ///< Flag indicating whether the mouse is being dragged
POINT lastMousePos; ///< Last recorded mouse position

/**
* @brief Handles the mouse wheel event for zooming.
*
* @param wParam The WPARAM parameter of the message.
*/
void handleMouseWheel(WPARAM wParam);

/**
* @brief Handles the mouse move event for panning.
*
* @param lParam The LPARAM parameter of the message.
*/
void handleMouseMove(LPARAM lParam);

/**
* @brief Handles the left button down event for initiating dragging.
*
* @param lParam The LPARAM parameter of the message.
*/
void handleLeftButtonDown(LPARAM lParam);

/**
* @brief Handles the left button up event for ending dragging.
*/
void handleLeftButtonUp();

/**
* @brief Handles the key down event for rotating.
*
* @param wParam The WPARAM parameter of the message.
*/
void handleKeyDown(WPARAM wParam);
};

#endif // VIEWER_HPP_
#endif // VIEWER_HPP_

0 comments on commit 3df3e84

Please sign in to comment.