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 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)
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)

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

View file

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

View file

@ -1,13 +1,13 @@
#include "Line.h"
Line::Line(const Point& start, const std::vector<Point>& points)
: mStartPoint(start),
mPoints(points)
Line::Line(const Point& start, const PointCollection& points)
: mStartPoint(start),
mPoints(points)
{
}
const std::vector<Point>& 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;
}

View file

@ -1,15 +1,16 @@
#pragma once
#include "PathElement.h"
#include "PointCollection.h"
#include <vector>
class Line : public PathElement
{
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;
@ -21,5 +22,5 @@ public:
private:
Point mStartPoint;
std::vector<Point> mPoints;
PointCollection mPoints;
};

View file

@ -13,3 +13,20 @@ 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;
}

View file

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

View file

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

View file

@ -1,6 +1,7 @@
#pragma once
#include "Point.h"
#include "Transform.h"
#include <unordered_map>
#include <string>
@ -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<std::string, std::vector<double> > mVectorAttributes;
std::size_t mIndex{0};