Small rendering cleanup.
This commit is contained in:
parent
d269cc8482
commit
fc44c4c623
13 changed files with 171 additions and 37 deletions
|
@ -20,3 +20,21 @@ std::vector<Path> Directory::getFilesWithExtension(const Path& path, const std::
|
|||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
void Directory::createIfNotExisting(const Path& path)
|
||||
{
|
||||
Path working_path;
|
||||
if (std::filesystem::is_directory(path))
|
||||
{
|
||||
working_path = path;
|
||||
}
|
||||
else
|
||||
{
|
||||
working_path = path.parent_path();
|
||||
}
|
||||
|
||||
if (!std::filesystem::exists(working_path))
|
||||
{
|
||||
std::filesystem::create_directories(working_path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using Path = std::filesystem::path;
|
|||
class Directory
|
||||
{
|
||||
public:
|
||||
static void createIfNotExisting(const Path& path);
|
||||
|
||||
static std::vector<Path> getFilesWithExtension(const Path& path, const std::string& extension, bool recursive=false);
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Win32WicInterface.h"
|
||||
#include "Win32WicImage.h"
|
||||
#include "StringUtils.h"
|
||||
#include "Directory.h"
|
||||
|
||||
#include <wincodec.h>
|
||||
#include <wrl.h>
|
||||
|
@ -16,6 +17,8 @@ Win32WicImageWriter::Win32WicImageWriter(ImgFormat format)
|
|||
|
||||
void Win32WicImageWriter::write(const Path& path, Image* image)
|
||||
{
|
||||
Directory::createIfNotExisting(path);
|
||||
|
||||
Win32WicInterface wic_interface;
|
||||
|
||||
Microsoft::WRL::ComPtr<IWICStream> pStream;
|
||||
|
|
|
@ -57,6 +57,10 @@ void DirectX2dPainter::paint(SceneModel* model)
|
|||
{
|
||||
paintPath(model);
|
||||
}
|
||||
else if (model->getGeometry()->getType() == AbstractGeometricItem::Type::LINE)
|
||||
{
|
||||
paintLine(model);
|
||||
}
|
||||
}
|
||||
|
||||
void DirectX2dPainter::paintRect(SceneModel* model)
|
||||
|
@ -107,8 +111,6 @@ void DirectX2dPainter::paintRect(SceneModel* model)
|
|||
|
||||
void DirectX2dPainter::paintCircle(SceneModel* model)
|
||||
{
|
||||
auto rt = mD2dInterface->getRenderTarget();
|
||||
|
||||
const auto loc = model->getTransform().getLocation();
|
||||
const auto scale_x = model->getTransform().getScaleX();
|
||||
const auto scale_y = model->getTransform().getScaleY();
|
||||
|
@ -120,6 +122,7 @@ void DirectX2dPainter::paintCircle(SceneModel* model)
|
|||
D2D1_POINT_2F d2d_centre{ static_cast<float>(loc.getX()), static_cast<float>(loc.getY()) };
|
||||
D2D1_ELLIPSE ellipse{ d2d_centre, static_cast<float>(radius), static_cast<float>(radiusy) };
|
||||
|
||||
auto rt = mD2dInterface->getRenderTarget();
|
||||
if (model->hasFillColor())
|
||||
{
|
||||
mSolidBrush->SetColor(toD2dColor(model->getFillColor()));
|
||||
|
@ -137,6 +140,44 @@ D2D_POINT_2F DirectX2dPainter::toD2dPoint(const Point& point)
|
|||
return D2D1::Point2F(static_cast<float>(point.getX()), static_cast<float>(point.getY()));
|
||||
}
|
||||
|
||||
void DirectX2dPainter::paintLine(SceneModel* model)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ID2D1PathGeometry> path_geom;
|
||||
mD2dInterface->getFactory()->CreatePathGeometry(&path_geom);
|
||||
|
||||
Microsoft::WRL::ComPtr<ID2D1GeometrySink> path_sink;
|
||||
|
||||
path_geom->Open(&path_sink);
|
||||
|
||||
auto line = dynamic_cast<Line*>(model->getGeometry());
|
||||
|
||||
path_sink->BeginFigure(toD2dPoint(line->getFirstPoint()), D2D1_FIGURE_BEGIN_FILLED);
|
||||
|
||||
onLine(line, path_sink.Get());
|
||||
|
||||
path_sink->EndFigure(D2D1_FIGURE_END_CLOSED);
|
||||
path_sink->Close();
|
||||
|
||||
auto rt = mD2dInterface->getRenderTarget();
|
||||
|
||||
const auto loc = model->getTransform().getLocation();
|
||||
D2D1_MATRIX_3X2_F translation = D2D1::Matrix3x2F::Translation(static_cast<float>(loc.getX()), static_cast<float>(loc.getY()));
|
||||
rt->SetTransform(translation);
|
||||
|
||||
if (model->hasFillColor())
|
||||
{
|
||||
mSolidBrush->SetColor(toD2dColor(model->getFillColor()));
|
||||
rt->FillGeometry(path_geom.Get(), mSolidBrush.Get());
|
||||
}
|
||||
if (model->hasOutlineColor())
|
||||
{
|
||||
mSolidBrush->SetColor(toD2dColor(model->getOutlineColor()));
|
||||
rt->DrawGeometry(path_geom.Get(), mSolidBrush.Get(), 1.0f);
|
||||
}
|
||||
|
||||
rt->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
}
|
||||
|
||||
void DirectX2dPainter::paintPath(SceneModel* model)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<ID2D1PathGeometry> path_geom;
|
||||
|
@ -185,6 +226,11 @@ void DirectX2dPainter::paintPath(SceneModel* model)
|
|||
path_sink->Close();
|
||||
|
||||
auto rt = mD2dInterface->getRenderTarget();
|
||||
|
||||
const auto loc = model->getTransform().getLocation();
|
||||
D2D1_MATRIX_3X2_F translation = D2D1::Matrix3x2F::Translation(static_cast<float>(loc.getX()), static_cast<float>(loc.getY()));
|
||||
rt->SetTransform(translation);
|
||||
|
||||
if (model->hasFillColor())
|
||||
{
|
||||
mSolidBrush->SetColor(toD2dColor(model->getFillColor()));
|
||||
|
@ -195,6 +241,8 @@ void DirectX2dPainter::paintPath(SceneModel* model)
|
|||
mSolidBrush->SetColor(toD2dColor(model->getOutlineColor()));
|
||||
rt->DrawGeometry(path_geom.Get(), mSolidBrush.Get(), 1.0f);
|
||||
}
|
||||
|
||||
rt->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
}
|
||||
|
||||
void DirectX2dPainter::onArc(Curve* element, ID2D1GeometrySink* sink)
|
||||
|
|
|
@ -50,6 +50,8 @@ private:
|
|||
|
||||
void paintPath(SceneModel* model);
|
||||
|
||||
void paintLine(SceneModel* model);
|
||||
|
||||
static D2D1::ColorF toD2dColor(const Color& color);
|
||||
|
||||
static D2D_POINT_2F toD2dPoint(const Point& point);
|
||||
|
|
0
src/rendering/visual_elements/BasicMaterial.cpp
Normal file
0
src/rendering/visual_elements/BasicMaterial.cpp
Normal file
0
src/rendering/visual_elements/BasicMaterial.h
Normal file
0
src/rendering/visual_elements/BasicMaterial.h
Normal file
|
@ -50,6 +50,9 @@ list(APPEND visual_elements_LIB_INCLUDES
|
|||
nodes/GeometryNode.cpp
|
||||
nodes/AbstractVisualNode.h
|
||||
nodes/AbstractVisualNode.cpp
|
||||
Material.h
|
||||
BasicMaterial.h
|
||||
BasicMaterial.cpp
|
||||
Texture.cpp
|
||||
)
|
||||
|
||||
|
|
0
src/rendering/visual_elements/Material.h
Normal file
0
src/rendering/visual_elements/Material.h
Normal file
Loading…
Add table
Add a link
Reference in a new issue