Skip to content

Commit

Permalink
Add drawLine(const Mat3& modelview, Vec2 end, Rgba color) overload
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Feb 1, 2025
1 parent a6d63e1 commit 430614e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/jngl/shapes.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012-2024 Jan Niklas Hasse <[email protected]>
// Copyright 2012-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
/// Functions for drawing shapes
/// @file
Expand Down Expand Up @@ -59,6 +59,8 @@ void drawLine(Mat3 modelview, Vec2 start, Vec2 end);
/// Draws a line from (0, 0) to \a end
void drawLine(const Mat3& modelview, Vec2 end);

/// Draws a line from (0, 0) to \a end in \a color
void drawLine(const Mat3& modelview, Vec2 end, Rgba color);

[[deprecated("Use drawEllipse(Mat3, float, float, float) instead")]]
/// \deprecated Use drawEllipse(Mat3, float, float, float) instead
Expand Down
12 changes: 8 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2007-2024 Jan Niklas Hasse <[email protected]>
// Copyright 2007-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt

#include "main.hpp"
Expand Down Expand Up @@ -514,15 +514,19 @@ void drawLine(const double xstart, const double ystart, const double xend, const
}

void drawLine(const Vec2 start, const Vec2 end) {
pWindow->drawLine(jngl::modelview().translate(start), end - start);
pWindow->drawLine(jngl::modelview().translate(start), end - start, gShapeColor);
}

void drawLine(Mat3 modelview, const Vec2 start, const Vec2 end) {
pWindow->drawLine(modelview.translate(start), end - start);
pWindow->drawLine(modelview.translate(start), end - start, gShapeColor);
}

void drawLine(const Mat3& modelview, const Vec2 end) {
pWindow->drawLine(modelview, end);
pWindow->drawLine(modelview, end, gShapeColor);
}

void drawLine(const Mat3& modelview, const Vec2 end, Rgba color) {
pWindow->drawLine(modelview, end, color);
}

void drawPoint(const double x, const double y) {
Expand Down
8 changes: 4 additions & 4 deletions src/window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2007-2024 Jan Niklas Hasse <[email protected]>
// Copyright 2007-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
#include "window.hpp"

Expand Down Expand Up @@ -582,10 +582,10 @@ void Window::drawTriangle(Mat3 modelview, Rgba color) {
glDrawArrays(GL_TRIANGLES, 0, 3);
}

void Window::drawLine(Mat3 modelview, const Vec2 b) const {
void Window::drawLine(Mat3 modelview, const Vec2 b, const Rgba color) const {
glBindVertexArray(vaoLine);
auto tmp = ShaderCache::handle().useSimpleShaderProgram(modelview.scale(b * getScaleFactor()),
gShapeColor);
auto tmp =
ShaderCache::handle().useSimpleShaderProgram(modelview.scale(b * getScaleFactor()), color);
glDrawArrays(GL_LINES, 0, 2);
}

Expand Down
4 changes: 2 additions & 2 deletions src/window.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2007-2024 Jan Niklas Hasse <[email protected]>
// Copyright 2007-2025 Jan Niklas Hasse <[email protected]>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
#pragma once

Expand Down Expand Up @@ -113,7 +113,7 @@ class Window {
void initGlObjects();
static void drawTriangle(Vec2 a, Vec2 b, Vec2 c);
static void drawTriangle(Mat3 modelview, Rgba color);
void drawLine(Mat3 modelview, Vec2 b) const;
void drawLine(Mat3 modelview, Vec2 b, Rgba color) const;
void drawSquare(Mat3 modelview, Rgba color) const;
void onControllerChanged(std::function<void()>);

Expand Down

0 comments on commit 430614e

Please sign in to comment.