From 2f259bdd5a527d17e06ca03e3366b8e21f7f106e Mon Sep 17 00:00:00 2001 From: JonasAugust12 <111167499+JonasAugust12@users.noreply.github.com> Date: Sun, 10 Dec 2023 22:26:37 +0700 Subject: [PATCH] Refactor variable names to snake_case convention --- src/Viewer.cpp | 48 ++++++++++++++++++++++++------------------------ src/Viewer.hpp | 16 ++++++++-------- src/main.cpp | 10 +++++----- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Viewer.cpp b/src/Viewer.cpp index a82d3b74..7225e86a 100644 --- a/src/Viewer.cpp +++ b/src/Viewer.cpp @@ -9,11 +9,11 @@ Viewer* Viewer::getInstance() { } Viewer::Viewer() { - isDragging = false; - zoomFactor = 1.0f; - rotateAngle = 0.0f; - offsetX = 0.0f; - offsetY = 0.0f; + is_dragging = false; + zoom_factor = 1.0f; + rotate_angle = 0.0f; + offset_x = 0.0f; + offset_y = 0.0f; } Viewer::~Viewer() { @@ -48,42 +48,42 @@ void Viewer::handleKeyEvent(WPARAM wParam) { handleKeyDown(wParam); } void Viewer::handleMouseWheel(WPARAM wParam) { if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) { - zoomFactor *= 1.1f; - needsRepaint = true; + zoom_factor *= 1.1f; + needs_repaint = true; } else { - zoomFactor /= 1.1f; - needsRepaint = true; + zoom_factor /= 1.1f; + needs_repaint = true; } } void Viewer::handleMouseMove(LPARAM lParam) { - if (isDragging) { + if (is_dragging) { int x = static_cast< int >(LOWORD(lParam)); int y = static_cast< int >(HIWORD(lParam)); - if (x != lastMousePos.x || y != lastMousePos.y) { - offsetX += (x - lastMousePos.x) * zoomFactor; - offsetY += (y - lastMousePos.y) * zoomFactor; - lastMousePos.x = x; - lastMousePos.y = y; - needsRepaint = true; + if (x != last_mouse_pos.x || y != last_mouse_pos.y) { + offset_x += (x - last_mouse_pos.x) * zoom_factor; + offset_y += (y - last_mouse_pos.y) * zoom_factor; + last_mouse_pos.x = x; + last_mouse_pos.y = y; + needs_repaint = true; } } } void Viewer::handleLeftButtonDown(LPARAM lParam) { - isDragging = true; - lastMousePos.x = static_cast< int >(LOWORD(lParam)); - lastMousePos.y = static_cast< int >(HIWORD(lParam)); + is_dragging = true; + last_mouse_pos.x = static_cast< int >(LOWORD(lParam)); + last_mouse_pos.y = static_cast< int >(HIWORD(lParam)); SetCapture(GetActiveWindow()); } void Viewer::handleLeftButtonUp() { - isDragging = false; + is_dragging = false; ReleaseCapture(); - if (needsRepaint) { - needsRepaint = false; + if (needs_repaint) { + needs_repaint = false; } } @@ -91,11 +91,11 @@ void Viewer::handleKeyDown(WPARAM wParam) { char key = static_cast< char >(wParam); switch (tolower(key)) { case 'q': - rotateAngle -= 1.0f; + rotate_angle -= 1.0f; break; case 'e': - rotateAngle += 1.0f; + rotate_angle += 1.0f; break; } } \ No newline at end of file diff --git a/src/Viewer.hpp b/src/Viewer.hpp index d1510012..ade5fa45 100644 --- a/src/Viewer.hpp +++ b/src/Viewer.hpp @@ -15,12 +15,12 @@ */ class Viewer { public: - 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 + float offset_x; ///< X-coordinate offset of the viewer + float offset_y; ///< Y-coordinate offset of the viewer + float zoom_factor; ///< Zoom factor for scaling the view + float rotate_angle; ///< Rotation angle of the view + bool needs_repaint; ///< Flag indicating whether the view needs to be + ///< repainted /** * @brief Gets the singleton instance of the Viewer class. @@ -71,8 +71,8 @@ class Viewer { */ void operator=(const Viewer&) = delete; - bool isDragging; ///< Flag indicating whether the mouse is being dragged - POINT lastMousePos; ///< Last recorded mouse position + bool is_dragging; ///< Flag indicating whether the mouse is being dragged + POINT last_mouse_pos; ///< Last recorded mouse position /** * @brief Handles the mouse wheel event for zooming. diff --git a/src/main.cpp b/src/main.cpp index ba2be2fc..21e3784c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,9 +17,9 @@ void OnPaint(HDC hdc, const std::string& filePath, Viewer& viewer) { if (!parser) { parser = Parser::getInstance(filePath); } - graphics.RotateTransform(viewer.rotateAngle); - graphics.ScaleTransform(viewer.zoomFactor, viewer.zoomFactor); - graphics.TranslateTransform(viewer.offsetX, viewer.offsetY); + graphics.RotateTransform(viewer.rotate_angle); + graphics.ScaleTransform(viewer.zoom_factor, viewer.zoom_factor); + graphics.TranslateTransform(viewer.offset_x, viewer.offset_y); graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias8x8); graphics.SetTextContrast(100); graphics.SetCompositingMode(Gdiplus::CompositingModeSourceOver); @@ -100,9 +100,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, case WM_LBUTTONDOWN: case WM_LBUTTONUP: viewer->handleMouseEvent(message, wParam, lParam); - if (viewer->needsRepaint) { + if (viewer->needs_repaint) { InvalidateRect(hWnd, NULL, TRUE); - viewer->needsRepaint = false; + viewer->needs_repaint = false; } return 0; case WM_KEYDOWN: