Skip to content

Commit

Permalink
Refactor variable names to snake_case convention
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAugust12 committed Dec 10, 2023
1 parent 3df3e84 commit 2f259bd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
48 changes: 24 additions & 24 deletions src/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -48,54 +48,54 @@ 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;
}
}

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;
}
}
16 changes: 8 additions & 8 deletions src/Viewer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2f259bd

Please sign in to comment.