Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RSAthensMorph apply the world renderer canvas scale factor #56

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/Roassal/RSAthensMorph.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Class {
#instVars : [
'renderer',
'session',
'surfaceScale',
'surface',
'isDrawing',
'roassalCanvas',
Expand Down Expand Up @@ -60,7 +61,7 @@ RSAthensMorph >> checkSession [

{ #category : #'surface management' }
RSAthensMorph >> createSurface [
surface := AthensCairoSurface extent: self extent asIntegerPoint.
surface := AthensCairoSurface extent: self extent asIntegerPoint * surfaceScale.
session := Smalltalk session.
roassalCanvas ifNotNil: [ roassalCanvas invalidate ]
]
Expand All @@ -72,7 +73,7 @@ RSAthensMorph >> drawOn: aCanvas [
isDrawing := true.
[
self checkSession.
self recreateSurfaceIfNecessary.
self recreateSurfaceIfNecessary: aCanvas scale.
aCanvas
fillRectangle: self bounds
fillStyle: roassalCanvas color
Expand All @@ -83,10 +84,10 @@ RSAthensMorph >> drawOn: aCanvas [
surface hasBeenFreed
ifTrue: [ self createSurface ].
[ aCanvas
image: surface asForm
formSet: (FormSet extent: self extent asIntegerPoint depth: 32 forms: { surface asForm })
at: self bounds origin asIntegerPoint
sourceRect: (0 @ 0 extent: surface extent)
rule: 34 ]
rule: Form blendAlphaScaled ]
on: Exception
do: [ :ex | ex traceCr ]
] ensure: [ isDrawing := false ]
Expand Down Expand Up @@ -118,7 +119,8 @@ RSAthensMorph >> drawShapes [
surface drawDuring: [ :athensCanvas |
renderer
surface: surface;
canvas: athensCanvas.
canvas: athensCanvas;
scale: surfaceScale.
roassalCanvas accept: renderer.
]
]
Expand All @@ -138,7 +140,7 @@ RSAthensMorph >> fullDrawOnAthensCanvas: aCanvas [
isDrawing := true.
[
self checkSession.
self recreateSurfaceIfNecessary.
self recreateSurfaceIfNecessary: 1.

aCanvas setPaint: roassalCanvas color.
aCanvas drawShape: (bounds translateBy: bounds origin negated).
Expand Down Expand Up @@ -217,6 +219,7 @@ RSAthensMorph >> hasFocus [
RSAthensMorph >> initialize [
super initialize.
self eventProcessor: RSEventProcessor new.
surfaceScale := 0.
self createSurface.
session := Smalltalk session.
isDrawing := false
Expand Down Expand Up @@ -293,10 +296,11 @@ RSAthensMorph >> mouseWheel: evt [
]

{ #category : #'session management' }
RSAthensMorph >> recreateSurfaceIfNecessary [
RSAthensMorph >> recreateSurfaceIfNecessary: scale [
surface
ifNotNil: [ self extent asIntegerPoint ~= surface extent
ifTrue: [ self createSurface.
ifNotNil: [ (surfaceScale ~= scale or: [ self extent asIntegerPoint * surfaceScale ~= surface extent ])
ifTrue: [ surfaceScale := scale.
self createSurface.
roassalCanvas extent: self extent ] ]
]

Expand Down
38 changes: 33 additions & 5 deletions src/Roassal/RSAthensRenderer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Class {
'showRectangles',
'originMatrix',
'surface',
'scale',
'dirtyRectangle'
],
#category : 'Roassal-Rendering'
Expand Down Expand Up @@ -580,6 +581,32 @@ RSAthensRenderer >> paintFor: shape form: form [
paint ]
]

{ #category : #'visiting - helpers' }
RSAthensRenderer >> pathTransformLoadMatrix [

athensCanvas pathTransform loadAffineTransform:
(AthensAffineTransform new
x: matrix x * scale;
y: matrix y * scale;
sx: matrix sx * scale;
sy: matrix sy * scale;
shx: matrix shx * scale;
shy: matrix shy * scale;
yourself)
]

{ #category : #accessing }
RSAthensRenderer >> scale [

^ scale
]

{ #category : #accessing }
RSAthensRenderer >> scale: anObject [

scale := anObject
]

{ #category : #'visiting - helpers' }
RSAthensRenderer >> showEncompassingRectangleForLineIfNecessary: line [
showRectangles ifFalse: [ ^ self ].
Expand Down Expand Up @@ -630,7 +657,7 @@ RSAthensRenderer >> visitBorderIfNecessary: shape [
RSAthensRenderer >> visitBoundingShape: shape [
self visitShapeIfNecessary: shape block: [
| path paint |
athensCanvas pathTransform loadAffineTransform: matrix.
self pathTransformLoadMatrix.
path := self getOrCreatePathOf: shape.
paint := shape paintOn: self.
paint ifNotNil: [
Expand Down Expand Up @@ -666,6 +693,7 @@ RSAthensRenderer >> visitCanvas: aRSCanvas [
athensCanvas setAA: aRSCanvas host antialiasing.
aRSCanvas camera accept: self.
transformeDirtyRectangle := self transform: dirtyRectangle.
athensCanvas pathTransform loadIdentity scaleBy: scale.
aRSCanvas shouldClearBackground ifTrue: [
self clearRectangle: transformeDirtyRectangle ].
modifiedDirtyRectangle := self inverseTransform: transformeDirtyRectangle.
Expand All @@ -674,14 +702,14 @@ RSAthensRenderer >> visitCanvas: aRSCanvas [
dirtyRectangle := transformeDirtyRectangle.
matrix loadIdentity.
originMatrix loadIdentity.
athensCanvas pathTransform loadIdentity.
athensCanvas pathTransform loadIdentity scaleBy: scale.
athensCanvas clipBy: transformeDirtyRectangle during: [
(aRSCanvas fixedShapes entriesAtRectangle: dirtyRectangle) do: [ :each | each accept: self ] ].
aRSCanvas resetDirtyRectangle.

aRSCanvas shouldShowDirtyRectangle ifFalse: [ ^ self ].

athensCanvas pathTransform loadIdentity.
athensCanvas pathTransform loadIdentity scaleBy: scale.
matrix loadIdentity.
originMatrix loadIdentity.
aRSCanvas camera accept: self.
Expand Down Expand Up @@ -718,7 +746,7 @@ RSAthensRenderer >> visitLabel: label [
| lbtranslation |
lbtranslation := label textExtents translationPoint asFloatPoint.
matrix translateBy: lbtranslation.
athensCanvas pathTransform loadAffineTransform: matrix.
self pathTransformLoadMatrix.
label hasBorder
ifTrue: [ self drawPathLabel: label ]
ifFalse: [ self drawSimpleLabel: label ].
Expand Down Expand Up @@ -752,7 +780,7 @@ RSAthensRenderer >> visitLabelDecoratorsIfNecessary: label [
RSAthensRenderer >> visitLine: line [
| path paint |
(line intersects: dirtyRectangle) ifFalse: [ ^ self ].
athensCanvas pathTransform loadAffineTransform: matrix.
self pathTransformLoadMatrix.
path := self getOrCreatePathOf: line.
paint := line paintOn: self.

Expand Down
Loading