Skip to content

Commit b54f4b5

Browse files
committed
inline documentation and more addImage functions
1 parent 82e2d6d commit b54f4b5

File tree

2 files changed

+102
-132
lines changed

2 files changed

+102
-132
lines changed

addons/ofxSvg/src/ofxSvg.cpp

Lines changed: 13 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,16 +2330,25 @@ std::shared_ptr<ofxSvgEllipse> ofxSvg::addEllipse( const float& ax, const float&
23302330

23312331
//--------------------------------------------------------------
23322332
std::shared_ptr<ofxSvgImage> ofxSvg::addImage( const of::filesystem::path& apath, const ofTexture& atex ) {
2333-
return addImage(glm::vec2(0.f, 0.f), apath, atex );
2333+
return addImage(glm::vec2(0.f, 0.f), apath, atex.getWidth(), atex.getHeight() );
23342334
}
23352335

23362336
//--------------------------------------------------------------
23372337
std::shared_ptr<ofxSvgImage> ofxSvg::addImage( const glm::vec2& apos, const of::filesystem::path& apath, const ofTexture& atex ) {
2338+
return addImage( apos, apath, atex.getWidth(), atex.getHeight() );
2339+
}
2340+
2341+
//--------------------------------------------------------------
2342+
std::shared_ptr<ofxSvgImage> ofxSvg::addImage( const of::filesystem::path& apath, const float& awidth, const float& aheight ) {
2343+
return addImage(glm::vec2(0.f, 0.f), apath, awidth, aheight );
2344+
}
2345+
2346+
//--------------------------------------------------------------
2347+
std::shared_ptr<ofxSvgImage> ofxSvg::addImage( const glm::vec2& apos, const of::filesystem::path& apath, const float& awidth, const float& aheight ) {
23382348
auto img = std::make_shared<ofxSvgImage>();
23392349
img->filepath = apath;
2340-
img->width = atex.getWidth();
2341-
img->height = atex.getHeight();
2342-
// _applyModelMatrixToElement( img, apos );
2350+
img->width = awidth;
2351+
img->height = aheight;
23432352
img->setPosition(apos.x, apos.y, 0.0f);
23442353
_getPushedGroup()->add(img);
23452354
recalculateLayers();
@@ -2359,64 +2368,6 @@ std::shared_ptr<ofxSvgImage> ofxSvg::addEmbeddedImage(const glm::vec2& apos, con
23592368
return img;
23602369
}
23612370

2362-
////----------------------------------------------------------
2363-
//void ofxSvg::pushMatrix() {
2364-
// mModelMatrixStack.push(mModelMatrix);
2365-
//}
2366-
//
2367-
////----------------------------------------------------------
2368-
//bool ofxSvg::popMatrix() {
2369-
// if( !mModelMatrixStack.empty() ) {
2370-
// mModelMatrix = mModelMatrixStack.top();
2371-
// mModelMatrixStack.pop();
2372-
// return true;
2373-
// } else {
2374-
// loadIdentityMatrix();
2375-
// }
2376-
// return false;
2377-
//}
2378-
//
2379-
////----------------------------------------------------------
2380-
//void ofxSvg::translate(const glm::vec2 & p) {
2381-
// translate(p.x, p.y);
2382-
//}
2383-
//
2384-
////----------------------------------------------------------
2385-
//void ofxSvg::translate(float x, float y) {
2386-
// mModelMatrix = glm::translate(mModelMatrix, glm::vec3(x, y, 0.0f));
2387-
//}
2388-
//
2389-
////----------------------------------------------------------
2390-
//void ofxSvg::scale(float xAmnt, float yAmnt) {
2391-
// mModelMatrix = glm::scale(mModelMatrix, glm::vec3(xAmnt, yAmnt, 1.f));
2392-
//}
2393-
//
2394-
////----------------------------------------------------------
2395-
//void ofxSvg::rotateRadians(float aradians) {
2396-
// mModelMatrix = glm::rotate(mModelMatrix, aradians, glm::vec3(0.f, 0.f, 1.f));
2397-
//}
2398-
//
2399-
////----------------------------------------------------------
2400-
//void ofxSvg::rotateDegrees(float adegrees) {
2401-
// rotateRadians( ofDegToRad(adegrees));
2402-
//}
2403-
//
2404-
////----------------------------------------------------------
2405-
//void ofxSvg::multMatrix(const glm::mat4 & m) {
2406-
// mModelMatrix = mModelMatrix * m;
2407-
//}
2408-
//
2409-
////----------------------------------------------------------
2410-
//void ofxSvg::loadMatrix(const glm::mat4 & m) {
2411-
// mModelMatrix = m;
2412-
//}
2413-
//
2414-
////----------------------------------------------------------
2415-
//void ofxSvg::loadIdentityMatrix() {
2416-
// mModelMatrix = glm::mat4(1.f);
2417-
//}
2418-
2419-
24202371
//--------------------------------------------------------------
24212372
void ofxSvg::drawDebug() {
24222373
// Group::draw();
@@ -2466,56 +2417,6 @@ ofxSvgGroup* ofxSvg::_getPushedGroup() {
24662417
return this;
24672418
}
24682419

2469-
////--------------------------------------------------------------
2470-
//bool ofxSvg::_hasPushedMatrix() {
2471-
// return mModelMatrix != glm::mat4(1.0f);
2472-
//}
2473-
2474-
//--------------------------------------------------------------
2475-
// TODO: CHECK ON THIS AFTER ofNode is implemented
2476-
//void ofxSvg::_applyModelMatrixToElement( std::shared_ptr<ofxSvgElement> aele, glm::vec2 aDefaultPos ) {
2477-
// if(_hasPushedMatrix() ) {
2478-
//// aele->pos = aDefaultPos;
2479-
//// aele->mModelPos = _getPos2d(mModelMatrix);
2480-
//// aele->rotation = glm::degrees(_getZRotationRadians(mModelMatrix));
2481-
//// aele->scale = _getScale2d(mModelMatrix);
2482-
//
2483-
// } else {
2484-
//// aele->mModelPos = glm::vec2(0.f, 0.f);
2485-
//// aele->pos = aDefaultPos;
2486-
// }
2487-
//}
2488-
2489-
////--------------------------------------------------------------
2490-
//glm::vec2 ofxSvg::_getPos2d(const glm::mat4& amat) {
2491-
// // Extract translation (position)
2492-
// return glm::vec2(amat[3][0], amat[3][1]);
2493-
//}
2494-
//
2495-
////--------------------------------------------------------------
2496-
//glm::vec2 ofxSvg::_getScale2d(const glm::mat4& amat) {
2497-
// // Extract scale (length of column vectors)
2498-
// return glm::vec2(glm::length(glm::vec2(amat[0][0], amat[0][1])), // Length of first column
2499-
// glm::length(glm::vec2(amat[1][0], amat[1][1])) // Length of second column
2500-
// );
2501-
//}
2502-
//
2503-
//// Function to extract Z-axis rotation (in degrees) from a glm::mat4
2504-
////--------------------------------------------------------------
2505-
//float ofxSvg::_getZRotationRadians(const glm::mat4& amat) {
2506-
// // Normalize the first column (remove scale effect)
2507-
// glm::vec2 xAxis = glm::vec2(amat[0][0], amat[0][1]);
2508-
// if( glm::length2(xAxis) > 0.0f ) {
2509-
// xAxis = glm::normalize(xAxis);
2510-
// } else {
2511-
// return 0.0f;
2512-
// }
2513-
//
2514-
// // Compute rotation angle using atan2
2515-
// float angleRadians = atan2f(xAxis.y, xAxis.x);
2516-
// return angleRadians;
2517-
//}
2518-
25192420
//--------------------------------------------------------------
25202421
ofxSvgCssClass& ofxSvg::_addCssClassFromPath( std::shared_ptr<ofxSvgPath> aSvgPath ) {
25212422
ofxSvgCssClass tcss;

addons/ofxSvg/src/ofxSvg.h

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,47 +174,121 @@ class ofxSvg : public ofxSvgGroup {
174174
ofxSvgCssClass& getCurrentCss() { return mCurrentCss;}
175175

176176
ofxSvgCssStyleSheet& getCssStyleSheet() {return mSvgCss; }
177-
/// \brief Add a group to the document. This will also push back the group as current.
177+
/// \brief Add a ofxSvgGroup to the document. This will also push back the group as current.
178178
/// \param aname is the name of the group.
179179
/// \return std::shared_ptr<ofxSvgGroup> as the group that was created.
180180
std::shared_ptr<ofxSvgGroup> addGroup(std::string aname);
181181

182+
/// \brief Add a ofxSvgPath to the document. The ofxSvgPath will be added to the current group.
183+
/// \param ofPath apath is the path to be added.
184+
/// \return std::shared_ptr<ofxSvgPath> as the path that was created and added to the document.
182185
std::shared_ptr<ofxSvgPath> add( const ofPath& apath );
186+
/// \brief Add multiple ofxSvgPaths to the document. The ofxSvgPaths will be added to the current group.
187+
/// \param std::vector<ofPath> apaths are the paths to be added.
188+
/// \return std::vector< std::shared_ptr<ofxSvgPath> > the paths that were created and added to the document.
183189
std::vector< std::shared_ptr<ofxSvgPath> > add( const std::vector<ofPath>& apaths );
184-
190+
/// \brief Add a ofxSvgPath to the document. The ofxSvgPath will be added to the current group.
191+
/// \param ofPolyline apoly is the polyline that will create an ofxSvgPath and added.
192+
/// \return std::shared_ptr<ofxSvgPath> as the path that was created and added to the document.
185193
std::shared_ptr<ofxSvgPath> add( const ofPolyline& apoly );
194+
/// \brief Add multiple ofxSvgPaths to the document. The ofxSvgPaths will be added to the current group.
195+
/// \param std::vector<ofPolyline> apolys are the polylines used to create and add ofxSvgPaths to the document.
196+
/// \return std::vector< std::shared_ptr<ofxSvgPath> > the paths that were created and added to the document.
186197
std::vector< std::shared_ptr<ofxSvgPath> > add( const std::vector<ofPolyline>& apolys );
187198

199+
/// \brief Add a ofxSvgRectangle to the document. The ofxSvgRectangle will be added to the current group.
200+
/// \param ofRectangle arect is the rectangle that will create an ofxSvgRectangle.
201+
/// \return std::shared_ptr<ofxSvgRectangle> as the rectangle that was created and added to the document.
188202
std::shared_ptr<ofxSvgRectangle> add( const ofRectangle& arect );
203+
/// \brief Add a ofxSvgRectangle to the document. The ofxSvgRectangle will be added to the current group.
204+
/// \param ofRectangle arect is the rectangle that will create an ofxSvgRectangle.
205+
/// \param float aRoundRadius is the corner radius used to round the corners.
206+
/// \return std::shared_ptr<ofxSvgRectangle> as the rectangle that was created and added to the document.
189207
std::shared_ptr<ofxSvgRectangle> add( const ofRectangle& arect, float aRoundRadius );
190208

209+
/// \brief Add a ofxSvgCircle to the document. The ofxSvgCircle will be added to the current group.
210+
/// The default position is 0,0. Use the returned ofxSvgCircle to set properties directly.
211+
/// \param float aradius is the radius used to create an ofxSvgCircle.
212+
/// \return std::shared_ptr<ofxSvgCircle> as the circle that was created and added to the document.
191213
std::shared_ptr<ofxSvgCircle> addCircle( float aradius );
214+
/// \brief Add a ofxSvgCircle to the document. The ofxSvgCircle will be added to the current group.
215+
/// \param glm::vec2 apos is the center position of the circle.
216+
/// \param float aradius is the radius used to create an ofxSvgCircle.
217+
/// \return std::shared_ptr<ofxSvgCircle> as the circle that was created and added to the document.
192218
std::shared_ptr<ofxSvgCircle> addCircle( const glm::vec2& apos, float aradius );
219+
/// \brief Add a ofxSvgCircle to the document. The ofxSvgCircle will be added to the current group.
220+
/// \param glm::vec3 apos is the center position of the circle. Note: z is not used.
221+
/// \param float aradius is the radius used to create an ofxSvgCircle.
222+
/// \return std::shared_ptr<ofxSvgCircle> as the circle that was created and added to the document.
193223
std::shared_ptr<ofxSvgCircle> addCircle( const glm::vec3& apos, float aradius );
224+
/// \brief Add a ofxSvgCircle to the document. The ofxSvgCircle will be added to the current group.
225+
/// \param float ax is the x center position of the circle.
226+
/// \param float ay is the y center position of the circle.
227+
/// \param float aradius is the radius used to create an ofxSvgCircle.
228+
/// \return std::shared_ptr<ofxSvgCircle> as the circle that was created and added to the document.
194229
std::shared_ptr<ofxSvgCircle> addCircle( const float& ax, const float& ay, float aradius );
195230

231+
/// \brief Add a ofxSvgEllipse to the document. The ofxSvgEllipse will be added to the current group.
232+
/// The default position is 0,0. Use the returned ofxSvgEllipse to set properties directly.
233+
/// \param float aradiusX is the horizontal radius used to create an ofxSvgEllipse.
234+
/// \param float aradiusY is the vertical radius used to create an ofxSvgEllipse.
235+
/// \return std::shared_ptr<ofxSvgEllipse> as the ellipse that was created and added to the document.
196236
std::shared_ptr<ofxSvgEllipse> addEllipse( float aradiusX, float aradiusY );
237+
/// \brief Add a ofxSvgEllipse to the document. The ofxSvgEllipse will be added to the current group.
238+
/// The default position is 0,0. Use the returned ofxSvgEllipse to set properties directly.
239+
/// \param glm::vec2 apos is the center position of the ellipse.
240+
/// \param float aradiusX is the horizontal radius used to create an ofxSvgEllipse.
241+
/// \param float aradiusY is the vertical radius used to create an ofxSvgEllipse.
242+
/// \return std::shared_ptr<ofxSvgEllipse> as the ellipse that was created and added to the document.
197243
std::shared_ptr<ofxSvgEllipse> addEllipse( const glm::vec2& apos, float aradiusX, float aradiusY );
244+
/// \brief Add a ofxSvgEllipse to the document. The ofxSvgEllipse will be added to the current group.
245+
/// The default position is 0,0. Use the returned ofxSvgEllipse to set properties directly.
246+
/// \param glm::vec3 apos is the center position of the ellipse. Note: z is not used.
247+
/// \param float aradiusX is the horizontal radius used to create an ofxSvgEllipse.
248+
/// \param float aradiusY is the vertical radius used to create an ofxSvgEllipse.
249+
/// \return std::shared_ptr<ofxSvgEllipse> as the ellipse that was created and added to the document.
198250
std::shared_ptr<ofxSvgEllipse> addEllipse( const glm::vec3& apos, float aradiusX, float aradiusY );
251+
/// \brief Add a ofxSvgEllipse to the document. The ofxSvgEllipse will be added to the current group.
252+
/// The default position is 0,0. Use the returned ofxSvgEllipse to set properties directly.
253+
/// \param float ax is the x center position of the ellipse.
254+
/// \param float ay is the y center position of the ellipse.
255+
/// \param float aradiusX is the horizontal radius used to create an ofxSvgEllipse.
256+
/// \param float aradiusY is the vertical radius used to create an ofxSvgEllipse.
257+
/// \return std::shared_ptr<ofxSvgEllipse> as the ellipse that was created and added to the document.
199258
std::shared_ptr<ofxSvgEllipse> addEllipse( const float& ax, const float& ay, float aradiusX, float aradiusY );
200259

260+
/// \brief Add a ofxSvgImage to the document. The ofxSvgImage will be added to the current group.
261+
/// The default position is 0,0. Use the returned ofxSvgImage to set properties directly.
262+
/// \param of::filesystem::path apath is the path to the linked image file.
263+
/// \param ofTexture atex provides the width and height of the image.
264+
/// \return std::shared_ptr<ofxSvgImage> as the image that was created and added to the document.
201265
std::shared_ptr<ofxSvgImage> addImage( const of::filesystem::path& apath, const ofTexture& atex );
266+
/// \brief Add a ofxSvgImage to the document. The ofxSvgImage will be added to the current group.
267+
/// \param glm::vec2 apos is the position; anchored to the top left.
268+
/// \param of::filesystem::path apath is the path to the linked image file.
269+
/// \param ofTexture atex provides the width and height of the image.
270+
/// \return std::shared_ptr<ofxSvgImage> as the image that was created and added to the document.
202271
std::shared_ptr<ofxSvgImage> addImage( const glm::vec2& apos, const of::filesystem::path& apath, const ofTexture& atex );
272+
/// \brief Add a ofxSvgImage to the document. The ofxSvgImage will be added to the current group.
273+
/// \param of::filesystem::path apath is the path to the linked image file.
274+
/// \param float awidth provides the width of the image.
275+
/// \param float aheight provides the height of the image.
276+
/// \return std::shared_ptr<ofxSvgImage> as the image that was created and added to the document.
277+
std::shared_ptr<ofxSvgImage> addImage( const of::filesystem::path& apath, const float& awidth, const float& aheight );
278+
/// \brief Add a ofxSvgImage to the document. The ofxSvgImage will be added to the current group.
279+
/// \param glm::vec2 apos is the position; anchored to the top left.
280+
/// \param of::filesystem::path apath is the path to the linked image file.
281+
/// \param float awidth provides the width of the image.
282+
/// \param float aheight provides the height of the image.
283+
/// \return std::shared_ptr<ofxSvgImage> as the image that was created and added to the document.
284+
std::shared_ptr<ofxSvgImage> addImage( const glm::vec2& apos, const of::filesystem::path& apath, const float& awidth, const float& aheight );
285+
/// \brief Add a ofxSvgImage to the document. The ofxSvgImage will be added to the current group.
286+
/// \param glm::vec2 apos is the position; anchored to the top left.
287+
/// \param ofPixels apixels is the pixels to embed in the svg document. Note: This can increase file size dramatically.
288+
/// \return std::shared_ptr<ofxSvgImage> as the image that was created and added to the document.
203289
std::shared_ptr<ofxSvgImage> addEmbeddedImage( const glm::vec2& apos, const ofPixels& apixels );
204290

205-
// adapted from ofGLProgrammableRenderer for some sort of conformity
206-
// this will be handled by the ofNode functionality
207-
// void pushMatrix();
208-
// bool popMatrix();
209-
// void translate(float x, float y);
210-
// void translate(const glm::vec2 & p);
211-
// void scale(float xAmnt, float yAmnt);
212-
// void rotateRadians(float radians);
213-
// void rotateDegrees(float adegrees);
214-
// void multMatrix(const glm::mat4 & m);
215-
// void loadMatrix(const glm::mat4 & m);
216-
// void loadIdentityMatrix();
217-
291+
/// \brief Used for development to provide insight into anchor point / control point placements.
218292
virtual void drawDebug();
219293

220294
protected:
@@ -243,11 +317,6 @@ class ofxSvg : public ofxSvgGroup {
243317
void _setNodeParentGroupStack( std::shared_ptr<ofxSvgElement> aele );
244318

245319
ofxSvgGroup* _getPushedGroup();
246-
// bool _hasPushedMatrix();
247-
// void _applyModelMatrixToElement( std::shared_ptr<ofxSvgElement> aele, glm::vec2 aDefaultPos );
248-
// glm::vec2 _getPos2d(const glm::mat4& amat);
249-
// glm::vec2 _getScale2d(const glm::mat4& amat);
250-
// float _getZRotationRadians( const glm::mat4& amat );
251320

252321
ofxSvgCssClass& _addCssClassFromPath( std::shared_ptr<ofxSvgPath> aSvgPath );
253322
void _addCssClassFromPath( std::shared_ptr<ofxSvgPath> aSvgPath, ofXml& anode );

0 commit comments

Comments
 (0)