diff --git a/apps/notes_tk/canvas/CanvasDrawingArea.cpp b/apps/notes_tk/canvas/CanvasDrawingArea.cpp index 65cb432..6b1c18f 100644 --- a/apps/notes_tk/canvas/CanvasDrawingArea.cpp +++ b/apps/notes_tk/canvas/CanvasDrawingArea.cpp @@ -49,6 +49,6 @@ void CanvasDrawingArea::onMyMouseEvent(const MouseEvent* event) auto client_loc = event->GetClientLocation(); auto screen_loc = event->GetScreenLocation(); - addShapeAt(client_loc.GetX(), client_loc.GetY()); + addShapeAt(client_loc.getX(), client_loc.getY()); } } diff --git a/src/fonts/CMakeLists.txt b/src/fonts/CMakeLists.txt index 2751084..ea5cba2 100644 --- a/src/fonts/CMakeLists.txt +++ b/src/fonts/CMakeLists.txt @@ -1,9 +1,9 @@ set(MODULE_NAME fonts) message(STATUS "Checking dependencies for module: " ${MODULE_NAME}) -set(fonts_LIB_DEPENDS "") +set(LIB_DEPENDS "") -list(APPEND fonts_LIB_INCLUDES +list(APPEND LIB_INCLUDES FontReader.cpp TrueTypeFont.cpp FontsManager.cpp @@ -16,16 +16,18 @@ list(APPEND fonts_LIB_INCLUDES IFontEngine.h BasicFontEngine.h BasicFontEngine.cpp + FontItem.h + FontItem.cpp ) if(UNIX) find_package(Freetype QUIET) if(Freetype_FOUND) - list(APPEND fonts_LIB_INCLUDES + list(APPEND LIB_INCLUDES FreeTypeFontEngine.cpp ) - list(APPEND fonts_LIB_DEPENDS + list(APPEND LIB_DEPENDS Freetype::Freetype ) list(APPEND DEFINES "HAS_FREETYPE") @@ -33,25 +35,25 @@ if(UNIX) message(STATUS "Freetype not found - skipping support") endif() else() - list(APPEND fonts_LIB_INCLUDES + list(APPEND LIB_INCLUDES directx/DirectWriteFontEngine.h directx/DirectWriteHelpers.h directx/DirectWriteFontEngine.cpp directx/DirectWriteHelpers.cpp ) - list(APPEND fonts_LIB_DEPENDS + list(APPEND LIB_DEPENDS Dwrite.lib D2d1.lib uuid.lib ) endif() -add_library(${MODULE_NAME} SHARED ${fonts_LIB_INCLUDES}) +add_library(${MODULE_NAME} SHARED ${LIB_INCLUDES}) target_include_directories(${MODULE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/directx ) -target_link_libraries(${MODULE_NAME} PUBLIC core geometry image ${fonts_LIB_DEPENDS}) +target_link_libraries(${MODULE_NAME} PUBLIC core geometry image ${LIB_DEPENDS}) target_compile_definitions(${MODULE_NAME} PRIVATE ${DEFINES}) set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src) diff --git a/src/fonts/FontItem.cpp b/src/fonts/FontItem.cpp index e69de29..4a088eb 100644 --- a/src/fonts/FontItem.cpp +++ b/src/fonts/FontItem.cpp @@ -0,0 +1,33 @@ +#include "FontItem.h" + +FontItem::FontItem(const std::string& faceName, float size) + : mFaceName(faceName), + mSize(size) +{ + +} + +bool FontItem::hasPath() const +{ + return !mPath.empty(); +} + +const Path& FontItem::getPath() const +{ + return mPath; +} + +void FontItem::setPath(const Path& path) +{ + mPath = path; +} + +const std::string& FontItem::getFaceName() const +{ + return mFaceName; +} + +float FontItem::getSize() const +{ + return mSize; +} \ No newline at end of file diff --git a/src/fonts/FontItem.h b/src/fonts/FontItem.h index 0083bbc..f6b8565 100644 --- a/src/fonts/FontItem.h +++ b/src/fonts/FontItem.h @@ -3,40 +3,22 @@ #include #include +using Path = std::filesystem::path; + class FontItem { public: - FontItem(const std::string& faceName = "Arial", unsigned size = 16) - : mFaceName(faceName), - mSize(size) - { + FontItem(const std::string& faceName = "Arial", float size = 16); - } + const Path& getPath() const; - bool hasPath() const - { - return !mPath.empty(); - } + const std::string& getFaceName() const; - const std::filesystem::path& getPath() const - { - return mPath; - } + float getSize() const; - void setPath(std::filesystem::path path) - { - mPath = path; - } + void setPath(const Path& path); - const std::string& getFaceName() const - { - return mFaceName; - } - - unsigned getSize() const - { - return mSize; - } + bool hasPath() const; bool operator==(const FontItem& rhs) const { @@ -50,7 +32,7 @@ public: } private: - unsigned mSize{24}; + float mSize{24}; std::string mFaceName; - std::filesystem::path mPath; + Path mPath; }; diff --git a/src/geometry/Bounds.h b/src/geometry/Bounds.h index 790e194..d954b7b 100644 --- a/src/geometry/Bounds.h +++ b/src/geometry/Bounds.h @@ -18,4 +18,46 @@ struct Bounds double mMaxY{ 0.0 }; double mMinZ{ 0.0 }; double mMaxZ{ 0.0 }; + + void intialize(double x, double y, double z = 0.0) + { + mMinX = x; + mMaxX = x; + + mMinY = y; + mMaxY = y; + + mMinZ = z; + mMaxZ = z; + } + + void includePoint(double x, double y, double z) + { + if (x < mMinX) + { + mMinX = x; + } + else if (x > mMaxX) + { + mMaxX = x; + } + + if (y < mMinY) + { + mMinY = y; + } + else if (y > mMaxY) + { + mMaxY = y; + } + + if (z < mMinZ) + { + mMinZ = z; + } + else if (z > mMaxZ) + { + mMaxZ = z; + } + } }; \ No newline at end of file diff --git a/src/geometry/path/Line.cpp b/src/geometry/path/Line.cpp index 7cedca2..d720399 100644 --- a/src/geometry/path/Line.cpp +++ b/src/geometry/path/Line.cpp @@ -1,13 +1,13 @@ #include "Line.h" -Line::Line(const Point& start, const std::vector& points) - : mStartPoint(start), - mPoints(points) +Line::Line(const Point& start, const PointCollection& points) + : mStartPoint(start), + mPoints(points) { } -const std::vector& Line::getPoints() const +const PointCollection& Line::getPoints() const { return mPoints; } @@ -24,30 +24,7 @@ const Point& Line::getLocation() const Bounds Line::getBounds() const { - double minX = mStartPoint.getX(); - double maxX = mStartPoint.getX(); - - double minY = mStartPoint.getY(); - double maxY = mStartPoint.getY(); - - for (const auto& point : mPoints) - { - if (point.getX() > maxX) - { - maxX = point.getX(); - } - if (point.getX() < minX) - { - minX = point.getX(); - } - if (point.getY() > maxY) - { - maxY = point.getX(); - } - if (point.getY() < minY) - { - minY = point.getY(); - } - } - return { minX, maxX, minY, maxY }; + auto bounds = mPoints.getBounds(); + bounds.includePoint(mStartPoint.getX(), mStartPoint.getY(), mStartPoint.getZ()); + return bounds; } \ No newline at end of file diff --git a/src/geometry/path/Line.h b/src/geometry/path/Line.h index b4f18f5..87812c8 100644 --- a/src/geometry/path/Line.h +++ b/src/geometry/path/Line.h @@ -1,15 +1,16 @@ #pragma once #include "PathElement.h" +#include "PointCollection.h" #include class Line : public PathElement { public: - Line(const Point& start, const std::vector& points); + Line(const Point& start, const PointCollection& points); - const std::vector& getPoints() const; + const PointCollection& getPoints() const; Line::Type getType() const override; @@ -21,5 +22,5 @@ public: private: Point mStartPoint; - std::vector mPoints; + PointCollection mPoints; }; \ No newline at end of file diff --git a/src/geometry/points/PointCollection.cpp b/src/geometry/points/PointCollection.cpp index 0be3812..2acdd79 100644 --- a/src/geometry/points/PointCollection.cpp +++ b/src/geometry/points/PointCollection.cpp @@ -12,4 +12,21 @@ void PointCollection::apply(const Transform& transform) { point.apply(transform); } +} + +Bounds PointCollection::getBounds() const +{ + Bounds bounds{0.0, 0.0, 0.0, 0.0}; + + if (mPoints.size() == 0) + { + return bounds; + } + + bounds.intialize(mPoints[0].getX(), mPoints[0].getY(), mPoints[0].getZ()); + for(const auto& point : mPoints) + { + bounds.includePoint(point.getX(), point.getY(), point.getZ()); + } + return bounds; } \ No newline at end of file diff --git a/src/geometry/points/PointCollection.h b/src/geometry/points/PointCollection.h index 8fea69a..0af4b20 100644 --- a/src/geometry/points/PointCollection.h +++ b/src/geometry/points/PointCollection.h @@ -2,6 +2,7 @@ #include "Point.h" #include "Transform.h" +#include "Bounds.h" class PointCollection { @@ -10,6 +11,8 @@ public: void apply(const Transform& transform); + Bounds getBounds() const; + private: std::vector mPoints; }; diff --git a/src/mesh/AbstractMesh.cpp b/src/mesh/AbstractMesh.cpp index d2eef54..d6c15e2 100644 --- a/src/mesh/AbstractMesh.cpp +++ b/src/mesh/AbstractMesh.cpp @@ -43,27 +43,28 @@ std::vector AbstractMesh::getVectorAttribute(const std::string& tag) con void AbstractMesh::scale(double scaleX, double scaleY) { + Transform transform({ 0.0, 0.0 }, scaleX, scaleY); + for (auto& node : mNodes) { - node->scale(scaleX, scaleY); + node->apply(transform); } } void AbstractMesh::transform(const Transform& transform) { - auto scaleX = transform.getScaleX(); - auto scaleY = transform.getScaleY(); - - scale(scaleX, scaleY); - - translate(transform.getLocation()); + for (auto& node : mNodes) + { + node->apply(transform); + } } void AbstractMesh::translate(double offsetX, double offsetY, double offsetZ) { + Transform transform({ -offsetX, -offsetY, -offsetZ }); for (auto& node : mNodes) { - node->translate(offsetX, offsetY, offsetZ); + node->apply(transform); } } diff --git a/src/mesh/Node.cpp b/src/mesh/Node.cpp index d90a7d8..8b1f6d9 100644 --- a/src/mesh/Node.cpp +++ b/src/mesh/Node.cpp @@ -47,14 +47,9 @@ const Point& Node::getPoint() const return mPoint; } -void Node::scale(double x, double y) +void Node::apply(const Transform& transform) { - mPoint.scale(x, y); -} - -void Node::translate(double x, double y, double z) -{ - mPoint.translate(x, y, z); + mPoint.apply(transform); } bool Node::isCoincident(Node* node) const diff --git a/src/mesh/Node.h b/src/mesh/Node.h index 30abc84..bf53841 100644 --- a/src/mesh/Node.h +++ b/src/mesh/Node.h @@ -1,6 +1,7 @@ #pragma once #include "Point.h" +#include "Transform.h" #include #include @@ -22,6 +23,8 @@ public: ~Node(); + void apply(const Transform& transform); + void associateEdge(std::size_t edgeId); void associateFace(std::size_t faceId); @@ -54,10 +57,6 @@ public: void updateIndex(std::size_t index); - void scale(double x, double y); - - void translate(double x, double y, double z = 0.0); - private: std::unordered_map > mVectorAttributes; std::size_t mIndex{0};