Skip to content

Commit

Permalink
Merge pull request #64 from pharo-graphics/62-Add-pathRotate-method-i…
Browse files Browse the repository at this point in the history
…n-AeCanvas

AeCanvas: add pathRotateByRadians: and pathRotateByRadians:about:
  • Loading branch information
tinchodias authored Oct 16, 2024
2 parents 676a97b + 094ee05 commit 6e95ac1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Alexandrie-Cairo/AeCairoContext.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,19 @@ AeCairoContext >> rotateByRadians: angle [
double angle ) )
]

{ #category : #'API - matrix' }
AeCairoContext >> rotateByRadians: angle aboutX: centerX y: centerY [
"Modifies the current transformation matrix (CTM) by rotating the user-space axes by angle radians about a center received as argument.
See: https://www.cairographics.org/cookbook/transform_about_point/
See: https://www.cairographics.org/cookbook/matrix_conventions/"

self
translateByX: centerX y: centerY;
rotateByRadians: angle;
translateByX: centerX negated y: centerY negated
]

{ #category : #'API - path' }
AeCairoContext >> roundedRectangleLeft: l top: t right: r bottom: b tl: tlR tr: trR br: brR bl: blR [
"Append the path of a rounded rectangle.
Expand Down
42 changes: 42 additions & 0 deletions src/Alexandrie-Canvas-Tests/AeCanvasTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,48 @@ AeCanvasTest >> renderOpenFigure [
^ aeCanvas
]

{ #category : #tests }
AeCanvasTest >> renderWithRotation [

| aeCanvas extent |
extent := 40 @ 30.
aeCanvas := AeCanvas extent: extent.

aeCanvas pathRotateByRadians: 15 degreesToRadians.

aeCanvas pathFactory: [ :cairoContext |
cairoContext rectangleTo: extent / 2 ].

aeCanvas setBackgroundWith: [
aeCanvas setSourceColor: Color purple ].
aeCanvas setBorderOff.
aeCanvas drawFigure.

^ aeCanvas
]

{ #category : #tests }
AeCanvasTest >> renderWithRotationAboutCenter [

| aeCanvas extent |
extent := 40 @ 30.
aeCanvas := AeCanvas extent: extent.

aeCanvas
pathRotateByRadians: 45 degreesToRadians
about: extent / 2.

aeCanvas pathFactory: [ :cairoContext |
cairoContext rectangleTo: extent ].

aeCanvas setBackgroundWith: [
aeCanvas setSourceColor: Color cyan ].
aeCanvas setBorderOff.
aeCanvas drawFigure.

^ aeCanvas
]

{ #category : #tests }
AeCanvasTest >> renderZWJEmojiWithHarfbuzz [

Expand Down
14 changes: 14 additions & 0 deletions src/Alexandrie-Canvas/AeCanvas.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,20 @@ AeCanvas >> pathFactory: aUnaryBlock [
borderPathBlock := nil.
]

{ #category : #'API - transformations' }
AeCanvas >> pathRotateByRadians: angle [
"Rotate by an angle, expressed in radians, about 0@0."

cairoContext rotateByRadians: angle
]

{ #category : #'API - transformations' }
AeCanvas >> pathRotateByRadians: angle about: aPoint [
"Rotate by an angle, expressed in radians, about aPoint."

cairoContext rotateByRadians: angle aboutX: aPoint x y: aPoint y
]

{ #category : #'API - transformations' }
AeCanvas >> pathScale: aPoint [

Expand Down
Binary file added tests/canvas/renderWithRotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/canvas/renderWithRotationAboutCenter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6e95ac1

Please sign in to comment.