Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/pyro/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace Pyro

enum class GraphicsMode
{
CAIRO
CAIRO,
PYRO3D
};

class Graphics : public Image
Expand Down
19 changes: 19 additions & 0 deletions include/pyro/graphics_pyro3d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "graphics.h"

namespace Pyro
{
class GraphicsPyro3D : public Graphics
{
public:
GraphicsPyro3D(const GraphicsPyro3D &in);
GraphicsPyro3D(unsigned int width, unsigned int height, unsigned int channels, unsigned int dpi);
~GraphicsPyro3D();

GraphicsPyro3D &operator=(const GraphicsPyro3D &in);

void point(float x0, float y0);
void line(float x0, float y0, float x1, float y1, Unit unit = Unit::current);
};
}
Empty file.
2 changes: 1 addition & 1 deletion screenshot-tests/test-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static inline std::string const actual_folder = "./screenshots/expected/";
static inline std::string const current_folder = "./screenshots/current/";
constexpr static inline Pyro::GraphicsMode testmode = Pyro::GraphicsMode::CAIRO;
constexpr static inline Pyro::GraphicsMode testmode = Pyro::GraphicsMode::PYRO3D;

class ImageMatch : public Catch::MatcherBase<std::string>
{
Expand Down
3 changes: 3 additions & 0 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "pyro/graphics.h"
#include "pyro/graphics_cairo.h"
#include "pyro/graphics_pyro3d.h"
#include "pyro/utils.h"

#include <iostream>
Expand Down Expand Up @@ -32,6 +33,8 @@ namespace Pyro
height = unit2pixels(height, unit, dpi);
switch (mode)
{
case GraphicsMode::PYRO3D:
return new GraphicsPyro3D(width, height, ARGB, dpi);
case GraphicsMode::CAIRO:
default:
return new GraphicsCairo(width, height, ARGB, dpi);
Expand Down
59 changes: 59 additions & 0 deletions src/graphics_pyro3d.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "pyro/graphics_pyro3d.h"

namespace Pyro
{

float interpolate(float i0, float d0, float i1, float d1)
{
if (i0 == i1)
{
return {d0};
}
}

GraphicsPyro3D::GraphicsPyro3D(unsigned int width, unsigned int height, unsigned int format, unsigned int dpi) : Graphics(width, height, format, dpi)
{
}

GraphicsPyro3D::~GraphicsPyro3D()
{
}

void GraphicsPyro3D::point(float x, float y)
{
this->set(int(x), int(y), this->stroke_color.to_uint());
}

void GraphicsPyro3D::line(float x0, float y0, float x1, float y1, Unit unit)
{
if (this->stroke_enable)
{
if (abs(x1 - x0) > (y1 - y0))
{
// Horizontal-ish
}
else
{
// Vertical-ish
}
if (x0 > x1)
{
float t = x1;
x1 = x0;
x0 = t;
t = y1;
y1 = y0;
y0 = t;
}

float a = (y1 - y0) / (x1 - x0);
float y = y0;
for (unsigned int x = int(x0); x <= x1; x++)
{
this->set(x, int(y), this->stroke_color.to_uint());
y += a;
}
}
}

}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pyro_sources = ['pyro.cpp',
'font_impl.cpp',
'graphics.cpp',
'graphics_cairo.cpp',
'graphics_pyro3d.cpp',
'image.cpp',
'math.cpp',
'shape.cpp',
Expand Down
3 changes: 2 additions & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test_sources = ['test-main.cpp',
'test-pyro.cpp',
'test-vector.cpp',
'test-string.cpp',
'test-transformer2d.cpp']
'test-transformer2d.cpp',
'test-engine.cpp']

testexe = executable('unit-tests', test_sources,
include_directories: inc_dir,
Expand Down
33 changes: 33 additions & 0 deletions tests/test-engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <catch2/catch.hpp>

#include "pyro/graphics.h"

TEST_CASE("Graphics objects can be initialized with different engines", "[graphics]")
{
SECTION("Create a graphics object with default engine")
{
Pyro::Graphics *graphics = Pyro::Graphics::create(400, 300);

REQUIRE(graphics != nullptr);
REQUIRE(graphics->width() == 400);
REQUIRE(graphics->height() == 300);
}

SECTION("Create a graphics object with cairo engine")
{
Pyro::Graphics *graphics = Pyro::Graphics::create(400, 300, Pyro::GraphicsMode::CAIRO);

REQUIRE(graphics != nullptr);
REQUIRE(graphics->width() == 400);
REQUIRE(graphics->height() == 300);
}

SECTION("Create a graphics object with 3d engine")
{
Pyro::Graphics *graphics = Pyro::Graphics::create(400, 300, Pyro::GraphicsMode::PYRO3D);

REQUIRE(graphics != nullptr);
REQUIRE(graphics->width() == 400);
REQUIRE(graphics->height() == 300);
}
}