Further cleaning.

This commit is contained in:
jmsgrogan 2023-01-13 15:03:07 +00:00
parent cb4212d972
commit 4fbe6279d1
12 changed files with 141 additions and 89 deletions

View file

@ -49,6 +49,6 @@ void CanvasDrawingArea::onMyMouseEvent(const MouseEvent* event)
auto client_loc = event->GetClientLocation(); auto client_loc = event->GetClientLocation();
auto screen_loc = event->GetScreenLocation(); auto screen_loc = event->GetScreenLocation();
addShapeAt(client_loc.GetX(), client_loc.GetY()); addShapeAt(client_loc.getX(), client_loc.getY());
} }
} }

View file

@ -1,9 +1,9 @@
set(MODULE_NAME fonts) set(MODULE_NAME fonts)
message(STATUS "Checking dependencies for module: " ${MODULE_NAME}) 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 FontReader.cpp
TrueTypeFont.cpp TrueTypeFont.cpp
FontsManager.cpp FontsManager.cpp
@ -16,16 +16,18 @@ list(APPEND fonts_LIB_INCLUDES
IFontEngine.h IFontEngine.h
BasicFontEngine.h BasicFontEngine.h
BasicFontEngine.cpp BasicFontEngine.cpp
FontItem.h
FontItem.cpp
) )
if(UNIX) if(UNIX)
find_package(Freetype QUIET) find_package(Freetype QUIET)
if(Freetype_FOUND) if(Freetype_FOUND)
list(APPEND fonts_LIB_INCLUDES list(APPEND LIB_INCLUDES
FreeTypeFontEngine.cpp FreeTypeFontEngine.cpp
) )
list(APPEND fonts_LIB_DEPENDS list(APPEND LIB_DEPENDS
Freetype::Freetype Freetype::Freetype
) )
list(APPEND DEFINES "HAS_FREETYPE") list(APPEND DEFINES "HAS_FREETYPE")
@ -33,25 +35,25 @@ if(UNIX)
message(STATUS "Freetype not found - skipping support") message(STATUS "Freetype not found - skipping support")
endif() endif()
else() else()
list(APPEND fonts_LIB_INCLUDES list(APPEND LIB_INCLUDES
directx/DirectWriteFontEngine.h directx/DirectWriteFontEngine.h
directx/DirectWriteHelpers.h directx/DirectWriteHelpers.h
directx/DirectWriteFontEngine.cpp directx/DirectWriteFontEngine.cpp
directx/DirectWriteHelpers.cpp directx/DirectWriteHelpers.cpp
) )
list(APPEND fonts_LIB_DEPENDS list(APPEND LIB_DEPENDS
Dwrite.lib D2d1.lib uuid.lib Dwrite.lib D2d1.lib uuid.lib
) )
endif() endif()
add_library(${MODULE_NAME} SHARED ${fonts_LIB_INCLUDES}) add_library(${MODULE_NAME} SHARED ${LIB_INCLUDES})
target_include_directories(${MODULE_NAME} PUBLIC target_include_directories(${MODULE_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/directx ${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}) target_compile_definitions(${MODULE_NAME} PRIVATE ${DEFINES})
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src) set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src)

View file

@ -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;
}

View file

@ -3,40 +3,22 @@
#include <filesystem> #include <filesystem>
#include <string> #include <string>
using Path = std::filesystem::path;
class FontItem class FontItem
{ {
public: public:
FontItem(const std::string& faceName = "Arial", unsigned size = 16) FontItem(const std::string& faceName = "Arial", float size = 16);
: mFaceName(faceName),
mSize(size)
{
} const Path& getPath() const;
bool hasPath() const const std::string& getFaceName() const;
{
return !mPath.empty();
}
const std::filesystem::path& getPath() const float getSize() const;
{
return mPath;
}
void setPath(std::filesystem::path path) void setPath(const Path& path);
{
mPath = path;
}
const std::string& getFaceName() const bool hasPath() const;
{
return mFaceName;
}
unsigned getSize() const
{
return mSize;
}
bool operator==(const FontItem& rhs) const bool operator==(const FontItem& rhs) const
{ {
@ -50,7 +32,7 @@ public:
} }
private: private:
unsigned mSize{24}; float mSize{24};
std::string mFaceName; std::string mFaceName;
std::filesystem::path mPath; Path mPath;
}; };

View file

@ -18,4 +18,46 @@ struct Bounds
double mMaxY{ 0.0 }; double mMaxY{ 0.0 };
double mMinZ{ 0.0 }; double mMinZ{ 0.0 };
double mMaxZ{ 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;
}
}
}; };

View file

@ -1,13 +1,13 @@
#include "Line.h" #include "Line.h"
Line::Line(const Point& start, const std::vector<Point>& points) Line::Line(const Point& start, const PointCollection& points)
: mStartPoint(start), : mStartPoint(start),
mPoints(points) mPoints(points)
{ {
} }
const std::vector<Point>& Line::getPoints() const const PointCollection& Line::getPoints() const
{ {
return mPoints; return mPoints;
} }
@ -24,30 +24,7 @@ const Point& Line::getLocation() const
Bounds Line::getBounds() const Bounds Line::getBounds() const
{ {
double minX = mStartPoint.getX(); auto bounds = mPoints.getBounds();
double maxX = mStartPoint.getX(); bounds.includePoint(mStartPoint.getX(), mStartPoint.getY(), mStartPoint.getZ());
return bounds;
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 };
} }

View file

@ -1,15 +1,16 @@
#pragma once #pragma once
#include "PathElement.h" #include "PathElement.h"
#include "PointCollection.h"
#include <vector> #include <vector>
class Line : public PathElement class Line : public PathElement
{ {
public: public:
Line(const Point& start, const std::vector<Point>& points); Line(const Point& start, const PointCollection& points);
const std::vector<Point>& getPoints() const; const PointCollection& getPoints() const;
Line::Type getType() const override; Line::Type getType() const override;
@ -21,5 +22,5 @@ public:
private: private:
Point mStartPoint; Point mStartPoint;
std::vector<Point> mPoints; PointCollection mPoints;
}; };

View file

@ -13,3 +13,20 @@ void PointCollection::apply(const Transform& transform)
point.apply(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;
}

View file

@ -2,6 +2,7 @@
#include "Point.h" #include "Point.h"
#include "Transform.h" #include "Transform.h"
#include "Bounds.h"
class PointCollection class PointCollection
{ {
@ -10,6 +11,8 @@ public:
void apply(const Transform& transform); void apply(const Transform& transform);
Bounds getBounds() const;
private: private:
std::vector<Point> mPoints; std::vector<Point> mPoints;
}; };

View file

@ -43,27 +43,28 @@ std::vector<double> AbstractMesh::getVectorAttribute(const std::string& tag) con
void AbstractMesh::scale(double scaleX, double scaleY) void AbstractMesh::scale(double scaleX, double scaleY)
{ {
Transform transform({ 0.0, 0.0 }, scaleX, scaleY);
for (auto& node : mNodes) for (auto& node : mNodes)
{ {
node->scale(scaleX, scaleY); node->apply(transform);
} }
} }
void AbstractMesh::transform(const Transform& transform) void AbstractMesh::transform(const Transform& transform)
{ {
auto scaleX = transform.getScaleX(); for (auto& node : mNodes)
auto scaleY = transform.getScaleY(); {
node->apply(transform);
scale(scaleX, scaleY); }
translate(transform.getLocation());
} }
void AbstractMesh::translate(double offsetX, double offsetY, double offsetZ) void AbstractMesh::translate(double offsetX, double offsetY, double offsetZ)
{ {
Transform transform({ -offsetX, -offsetY, -offsetZ });
for (auto& node : mNodes) for (auto& node : mNodes)
{ {
node->translate(offsetX, offsetY, offsetZ); node->apply(transform);
} }
} }

View file

@ -47,14 +47,9 @@ const Point& Node::getPoint() const
return mPoint; return mPoint;
} }
void Node::scale(double x, double y) void Node::apply(const Transform& transform)
{ {
mPoint.scale(x, y); mPoint.apply(transform);
}
void Node::translate(double x, double y, double z)
{
mPoint.translate(x, y, z);
} }
bool Node::isCoincident(Node* node) const bool Node::isCoincident(Node* node) const

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Point.h" #include "Point.h"
#include "Transform.h"
#include <unordered_map> #include <unordered_map>
#include <string> #include <string>
@ -22,6 +23,8 @@ public:
~Node(); ~Node();
void apply(const Transform& transform);
void associateEdge(std::size_t edgeId); void associateEdge(std::size_t edgeId);
void associateFace(std::size_t faceId); void associateFace(std::size_t faceId);
@ -54,10 +57,6 @@ public:
void updateIndex(std::size_t index); void updateIndex(std::size_t index);
void scale(double x, double y);
void translate(double x, double y, double z = 0.0);
private: private:
std::unordered_map<std::string, std::vector<double> > mVectorAttributes; std::unordered_map<std::string, std::vector<double> > mVectorAttributes;
std::size_t mIndex{0}; std::size_t mIndex{0};