diff --git a/src/geometry/AbstractGeometricItem.h b/src/geometry/AbstractGeometricItem.h index 354261c..25a963e 100644 --- a/src/geometry/AbstractGeometricItem.h +++ b/src/geometry/AbstractGeometricItem.h @@ -10,6 +10,16 @@ class AbstractGeometricItem { public: + enum class Type + { + LINE, + RECTANGLE, + TRIANGLE, + POINT, + PATH, + UNKNOWN + }; + struct Bounds { Bounds(double width, double height) @@ -30,4 +40,6 @@ public: virtual const Point& getLocation() const = 0; virtual void sample(Grid* grid) const = 0; + + virtual Type getType() const { return Type::UNKNOWN; }; }; diff --git a/src/geometry/Grid.cpp b/src/geometry/Grid.cpp index 59a808c..f5260aa 100644 --- a/src/geometry/Grid.cpp +++ b/src/geometry/Grid.cpp @@ -1,14 +1,14 @@ #include "Grid.h" template -Grid::Grid(const Rectangle& bounds) +Grid::Grid(const ntk::Rectangle& bounds) : mBounds(bounds) { mValues = std::vector(mNumX*mNumY, T()); } template -const Rectangle& Grid::getBounds() const +const ntk::Rectangle& Grid::getBounds() const { return mBounds; } @@ -32,7 +32,7 @@ const std::vector& Grid::getValues() const } template -void Grid::resetBounds(const Rectangle& bounds) +void Grid::resetBounds(const ntk::Rectangle& bounds) { mBounds = bounds; mValues = std::vector(mNumX*mNumY, T()); diff --git a/src/geometry/Grid.h b/src/geometry/Grid.h index b114dcb..0edc9cf 100644 --- a/src/geometry/Grid.h +++ b/src/geometry/Grid.h @@ -7,10 +7,9 @@ template class Grid { public: + Grid(const ntk::Rectangle& bounds); - Grid(const Rectangle& bounds); - - const Rectangle& getBounds() const; + const ntk::Rectangle& getBounds() const; double getXSpacing() const; @@ -18,12 +17,12 @@ public: const std::vector& getValues() const; - void resetBounds(const Rectangle& bounds); + void resetBounds(const ntk::Rectangle& bounds); void setValues(const std::vector& indices, T value); private: - Rectangle mBounds; + ntk::Rectangle mBounds; std::vector mValues; unsigned mNumX{5}; unsigned mNumY{5}; diff --git a/src/geometry/Rectangle.cpp b/src/geometry/Rectangle.cpp index 25d20e1..8e3fac8 100644 --- a/src/geometry/Rectangle.cpp +++ b/src/geometry/Rectangle.cpp @@ -1,46 +1,48 @@ #include "Rectangle.h" -Rectangle::Rectangle(const Point& bottomLeft, const Point& topRight) - : mBottomLeft(bottomLeft) -{ - mHeight = mBottomLeft.getDeltaY(topRight); - mWidth = mBottomLeft.getDeltaX(topRight); -} - -Rectangle::Rectangle(const Point& bottomLeft, double width, double height) - : mBottomLeft(bottomLeft), - mHeight(height), - mWidth(width) -{ - -} - -Rectangle Rectangle::getBounds() const -{ - return Rectangle(mBottomLeft, Point(mBottomLeft, mWidth, mHeight)); -} - -void Rectangle::sample(Grid* grid) const -{ - -} - -double Rectangle::getHeight() const -{ - return mHeight; -} - -double Rectangle::getWidth() const -{ - return mWidth; -} - -const Point& Rectangle::getLocation() const -{ - return mBottomLeft; -} - -Rectangle::Bounds Rectangle::getSize() const -{ - return {mWidth, mHeight}; +namespace ntk { + Rectangle::Rectangle(const Point& bottomLeft, const Point& topRight) + : mBottomLeft(bottomLeft) + { + mHeight = mBottomLeft.getDeltaY(topRight); + mWidth = mBottomLeft.getDeltaX(topRight); + } + + Rectangle::Rectangle(const Point& bottomLeft, double width, double height) + : mBottomLeft(bottomLeft), + mHeight(height), + mWidth(width) + { + + } + + Rectangle Rectangle::getBounds() const + { + return Rectangle(mBottomLeft, Point(mBottomLeft, mWidth, mHeight)); + } + + void Rectangle::sample(Grid* grid) const + { + + } + + double Rectangle::getHeight() const + { + return mHeight; + } + + double Rectangle::getWidth() const + { + return mWidth; + } + + const Point& Rectangle::getLocation() const + { + return mBottomLeft; + } + + Rectangle::Bounds Rectangle::getSize() const + { + return { mWidth, mHeight }; + } } diff --git a/src/geometry/Rectangle.h b/src/geometry/Rectangle.h index 5e12fc7..e821d32 100644 --- a/src/geometry/Rectangle.h +++ b/src/geometry/Rectangle.h @@ -6,10 +6,10 @@ template class Grid; +namespace ntk{ class Rectangle : public AbstractGeometricItem { public: - Rectangle(const Point& bottomLeft, const Point& topRight); Rectangle(const Point& bottomLeft, double width, double height); @@ -23,6 +23,11 @@ public: Rectangle getBounds() const; + Type getType() const + { + return AbstractGeometricItem::Type::RECTANGLE; + } + void sample(Grid* grid) const override; private: @@ -30,3 +35,5 @@ private: double mWidth{0}; double mHeight{0}; }; + +} diff --git a/src/graphics/RasterPainter.cpp b/src/graphics/RasterPainter.cpp index 2ad5ea4..174ca48 100644 --- a/src/graphics/RasterPainter.cpp +++ b/src/graphics/RasterPainter.cpp @@ -6,7 +6,7 @@ RasterPainter::RasterPainter(DrawingContext* context) : AbstractPainter(context), - mGrid(std::make_unique >(Rectangle(Point(0, 0), Point(100, 100)))) + mGrid(std::make_unique >(ntk::Rectangle(Point(0, 0), Point(100, 100)))) { } @@ -15,7 +15,7 @@ void RasterPainter::paint() { const auto width = mDrawingContext->getSurface()->getWidth(); const auto height = mDrawingContext->getSurface()->getHeight(); - mGrid->resetBounds(Rectangle(Point(0, 0), Point(width, height))); + mGrid->resetBounds(ntk::Rectangle(Point(0, 0), Point(width, height))); /* for (unsigned idx=0; idx< context->getNumItems(); idx++) diff --git a/src/graphics/directx/DirectX2dPainter.cpp b/src/graphics/directx/DirectX2dPainter.cpp index 84f92dd..c1f928c 100644 --- a/src/graphics/directx/DirectX2dPainter.cpp +++ b/src/graphics/directx/DirectX2dPainter.cpp @@ -1,10 +1,42 @@ #include "DirectX2dPainter.h" #include "DirectX2dInterface.h" +#include "AbstractGeometricItem.h" +#include "Rectangle.h" +#include "SceneModel.h" -void DirectX2dPainter::paint(AbstractGeometricItem* item) +void DirectX2dPainter::startDrawing() { + mD2dInterface->getRenderTarget()->BeginDraw(); +} +void DirectX2dPainter::finishDrawing() +{ + mD2dInterface->getRenderTarget()->EndDraw(); +} + +void DirectX2dPainter::clearBackground() +{ + mD2dInterface->getRenderTarget()->Clear(D2D1::ColorF(D2D1::ColorF::White)); +} + +void DirectX2dPainter::paint(SceneModel* model) +{ + auto rt = mD2dInterface->getRenderTarget(); + + auto hr = rt->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &mWorkingBrush); + + if (model->getGeometry()->getType() == AbstractGeometricItem::Type::RECTANGLE) + { + auto rect = dynamic_cast(model->getGeometry()); + const auto loc = rect->getLocation(); + const auto width = rect->getWidth(); + const auto height = rect->getHeight(); + + D2D1_RECT_F d2d_rect{ static_cast(loc.getX()), static_cast(loc.getY() + height), static_cast(loc.getX() + width), static_cast(loc.getY()) }; + + rt->FillRectangle(d2d_rect, mWorkingBrush.Get()); + } } void DirectX2dPainter::setD2dInterface(DirectX2dInterface* d2dIterface) diff --git a/src/graphics/directx/DirectX2dPainter.h b/src/graphics/directx/DirectX2dPainter.h index be46954..055ffc1 100644 --- a/src/graphics/directx/DirectX2dPainter.h +++ b/src/graphics/directx/DirectX2dPainter.h @@ -1,15 +1,29 @@ #pragma once -class AbstractGeometricItem; +#include + +class SceneModel; class DirectX2dInterface; +struct ID2D1SolidColorBrush; + class DirectX2dPainter { public: - void paint(AbstractGeometricItem* item); + void startDrawing(); + + void clearBackground(); + + void finishDrawing(); + + void paint(SceneModel* model); void setD2dInterface(DirectX2dInterface* d2dIterface); private: + void createRectangle(); + + Microsoft::WRL::ComPtr mWorkingBrush; + DirectX2dInterface* mD2dInterface{ nullptr }; }; \ No newline at end of file diff --git a/src/graphics/directx/DirectXPainter.cpp b/src/graphics/directx/DirectXPainter.cpp index 5f8fd71..ea84a10 100644 --- a/src/graphics/directx/DirectXPainter.cpp +++ b/src/graphics/directx/DirectXPainter.cpp @@ -109,6 +109,10 @@ void DirectXPainter::paint() } auto scene = mDrawingContext->getSurface()->getScene(); + + m2dPainter->startDrawing(); + m2dPainter->clearBackground(); + for (const auto item : scene->getItems()) { if (item->getType() == SceneItem::Type::MODEL && item->isVisible()) @@ -116,10 +120,12 @@ void DirectXPainter::paint() auto model = dynamic_cast(item); if (model->getGeometry()) { - m2dPainter->paint(model->getGeometry()); + m2dPainter->paint(model); } } } + + m2dPainter->finishDrawing(); } void DirectXPainter::paintBackground(const D3D12_CPU_DESCRIPTOR_HANDLE& rtvHandle, ID3D12GraphicsCommandList* commandList)