-
Notifications
You must be signed in to change notification settings - Fork 0
/
CairoMorphic.pck.st
676 lines (531 loc) · 20.5 KB
/
CairoMorphic.pck.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
'From Cuis 6.0 [latest update: #5067] on 11 February 2022 at 1:30:27 pm'!
'Description An implementation of MorphicCanvas using Cairo FFI.'!
!provides: 'CairoMorphic' 1 93!
!requires: 'Cairo' 1 46 nil!
SystemOrganization addCategory: 'CairoMorphic'!
!classDefinition: #CairoDisplayScreen category: 'CairoMorphic'!
DisplayScreen subclass: #CairoDisplayScreen
instanceVariableNames: 'canvas'
classVariableNames: ''
poolDictionaries: ''
category: 'CairoMorphic'!
!classDefinition: 'CairoDisplayScreen class' category: 'CairoMorphic'!
CairoDisplayScreen class
instanceVariableNames: ''!
!classDefinition: #CairoBoxedMorph category: 'CairoMorphic'!
BoxedMorph subclass: #CairoBoxedMorph
instanceVariableNames: 'rotation'
classVariableNames: ''
poolDictionaries: ''
category: 'CairoMorphic'!
!classDefinition: 'CairoBoxedMorph class' category: 'CairoMorphic'!
CairoBoxedMorph class
instanceVariableNames: ''!
!classDefinition: #CairoMorph category: 'CairoMorphic'!
BoxedMorph subclass: #CairoMorph
instanceVariableNames: 'rotation scale'
classVariableNames: ''
poolDictionaries: ''
category: 'CairoMorphic'!
!classDefinition: 'CairoMorph class' category: 'CairoMorphic'!
CairoMorph class
instanceVariableNames: ''!
!classDefinition: #CairoMorphExample category: 'CairoMorphic'!
CairoMorph subclass: #CairoMorphExample
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'CairoMorphic'!
!classDefinition: 'CairoMorphExample class' category: 'CairoMorphic'!
CairoMorphExample class
instanceVariableNames: ''!
!classDefinition: #CairoCanvas category: 'CairoMorphic'!
BitBltCanvas subclass: #CairoCanvas
instanceVariableNames: 'surface cairo images'
classVariableNames: ''
poolDictionaries: ''
category: 'CairoMorphic'!
!classDefinition: 'CairoCanvas class' category: 'CairoMorphic'!
CairoCanvas class
instanceVariableNames: ''!
!CairoDisplayScreen commentStamp: '<historical>' prior: 0!
Display screen using Cairo FFI.
To install:
CairoDisplayScreen install.!
!CairoMorph commentStamp: '<historical>' prior: 0!
Morph that draws on a CairoCanvas.!
!CairoCanvas commentStamp: '<historical>' prior: 0!
A Canvas that renders with Cairo FFI.
Tests:
CairoCanvas displayWorld.
CairoCanvas displayWorldScaled: [email protected].
CairoCanvas displayWorldRotated: -10!
!CairoDisplayScreen methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 12:48:41'!
forceToScreen: aRectangle
(BitBlt toForm: self)
copy: aRectangle
from: aRectangle origin in: canvas form.
super forceToScreen: aRectangle.! !
!CairoDisplayScreen methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 18:48:31'!
getCanvas
"Return a Canvas that can be used to draw onto the receiver"
^ canvas! !
!CairoDisplayScreen methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 18:23:12'!
initialize
super initialize.
canvas _ CairoCanvas withExtent: DisplayScreen actualScreenSize! !
!CairoDisplayScreen class methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 18:45:07'!
install
| d |
d _ CairoDisplayScreen new.
d beDisplay.
Smalltalk at: #Display put: d.
DisplayScreen startUp.
Display forceToScreen.! !
!CairoDisplayScreen class methodsFor: 'as yet unclassified' stamp: 'MM 10/13/2019 09:01:12'!
uninstall
| d |
d _ DisplayScreen new.
d beDisplay.
Smalltalk at: #Display put: d.
DisplayScreen startUp.
Display forceToScreen.! !
!CairoBoxedMorph methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 19:13:40'!
clippedSubmorph
^ false! !
!CairoBoxedMorph methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 17:20:44'!
rotatedBy: angle
rotation _ angle! !
!CairoBoxedMorph methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 19:19:41'!
rotation
^ rotation! !
!CairoMorph methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 17:34:36'!
drawMorphOn: aCanvas
! !
!CairoMorph methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 22:13:52'!
drawOn: aCanvas
|cairoCanvas|
cairoCanvas _ CairoCanvas withExtent: self morphExtent.
scale = 1 ifFalse: [
cairoCanvas scale: scale@scale].
self visible ifTrue: [self drawMorphOn: cairoCanvas].
self submorphsDo: [:m |
cairoCanvas fullDraw: m].
aCanvas image: cairoCanvas form at: 0@0.
cairoCanvas release.! !
!CairoMorph methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 18:39:54'!
hasSubmorphs
"We return false here so that we can handle submorphs drawing ourselves, instead of MorphicCanvas>>fullDraw:"
^ false! !
!CairoMorph methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 21:56:28'!
initialize
super initialize.
rotation _ 0.
scale _ 1.! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 19:24:54'!
drawMorphOn: aCanvas
aCanvas fillRectangle: self localBounds color: Color white.
aCanvas cairo setLineWidth: 5;
setSourceColor: Color blue;
curveTo: 300@300 control1: 0@100 control2: 0@200;
stroke. ! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 22:11:31'!
handlesMouseDown: anEvent
^ true! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/18/2019 13:46:48'!
handlesMouseOver: anEvent
^ true! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 21:52:41'!
handlesMouseScroll: anEvent
^ true! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/13/2019 11:16:44'!
initialize
super initialize.
self addMorph: (CairoBoxedMorph new
morphExtent: 50@50;
morphPosition: 50@50;
rotatedBy: -20;
color: Color red;
borderWidth: 5;
borderColor: Color black;
yourself).
self addMorphBack: (CairoBoxedMorph new
morphExtent: 100@100;
morphPosition: 50@50;
rotatedBy: 20;
color: (Color green alpha: 0.5);
borderWidth: 5;
borderColor: Color black;
yourself).
self addMorph: PluggableButtonMorph example position: 200@100.
self morphExtent: 500@500! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 22:12:05'!
mouseButton1Down: aMouseButtonEvent localPosition: localEventPosition
self zoomIn! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 22:12:11'!
mouseButton2Down: aMouseButtonEvent localPosition: localEventPosition
self zoomOut! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/18/2019 13:45:19'!
mouseEnter: anEvent
self activeHand newKeyboardFocus: self.! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/18/2019 13:47:05'!
mouseScroll: aMouseEvent localPosition: localEventPosition
aMouseEvent direction
caseOf: {
[ #up ] -> [ self zoomOut ].
[ #down ] -> [ self zoomIn ].
[ #left ] -> [ self zoomOut ].
[ #right ] -> [ self zoomIn ] }! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 21:59:59'!
zoomIn
scale _ scale + 0.1.
self redrawNeeded! !
!CairoMorphExample methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 22:00:06'!
zoomOut
scale _ scale - 0.1.
self redrawNeeded! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 10/26/2019 11:02:28'!
fillColor: aFillColor do: aBlock
"Prepare parameters for drawing stroke, fill, or both."
cairo setSourceColor: aFillColor.
^ aBlock value
! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 11/2/2019 13:41:49'!
fillPolygon: points color: aColor
cairo newPath;
moveTo: points first.
points allButFirst do: [:aPoint |
cairo lineTo: aPoint].
cairo closePath;
setSourceColor: aColor;
fill.! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 10/26/2019 11:01:57'!
multiCurveTo: coordinatesAreRelative toPoints: toPoints control1Points: control1Points control2Points: control2Points
| c1 c2 to |
coordinatesAreRelative
ifFalse: [
1 to: toPoints size do: [ :i |
to _ toPoints at: i.
c1 _ control1Points at: i.
c2 _ control2Points at: i.
cairo curveTo: to control1: c1 control2: c2 ]]
ifTrue: [
1 to: toPoints size do: [ :i |
to _ toPoints at: i.
c1 _ control1Points at: i.
c2 _ control2Points at: i.
cairo curveTo: to control1: c1 control2: c2 ]].
cairo stroke! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 10/26/2019 11:01:48'!
multiLineTo: coordinatesAreRelative points: toPoints
| to |
coordinatesAreRelative
ifFalse: [
1 to: toPoints size do: [ :i |
to _ toPoints at: i.
cairo lineTo: to ]]
ifTrue: [
1 to: toPoints size do: [ :i |
to _ toPoints at: i.
cairo lineTo: to ]].
cairo stroke! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 10/26/2019 11:02:46'!
multiMoveTo: coordinatesAreRelative points: points
| isFirst |
isFirst _ true.
coordinatesAreRelative
ifFalse: [
points do: [ :p |
isFirst
ifTrue: [ cairo moveTo: p x @ (p y) ]
ifFalse: [ cairo lineTo: p x @ (p y) ].
isFirst _ false ]]
ifTrue: [
points do: [ :p |
isFirst
ifTrue: [ cairo moveTo: p x @ (p y) ]
ifFalse: [ cairo lineTo: p x @ (p y) ].
isFirst _ false ]].
cairo stroke! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 10/26/2019 11:01:39'!
polyLine: points
| p |
p _ points first.
cairo moveTo: p.
2 to: points size do: [ :i |
p _ points at: i.
cairo lineTo: p ].
cairo stroke.! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 10/26/2019 11:00:47'!
strokeWidth: aNumber color: color fillColor: fillColor do: aBlock
color ifNotNil: [cairo setSourceColor: color].
fillColor ifNotNil: [cairo setSourceColor: fillColor].
cairo setLineWidth: aNumber.
^ aBlock value! !
!CairoCanvas methodsFor: 'api' stamp: 'MM 10/20/2019 10:34:57'!
withCairoDo: aBlock
"Give direct access to cairo context"
aBlock value: cairo! !
!CairoCanvas methodsFor: 'accessing' stamp: 'MM 10/8/2019 19:19:07'!
cairo
^ cairo! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/26/2019 10:35:23'!
closePath
cairo closePath! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/31/2019 13:18:21'!
createImageSurface: aForm
|stride externalForm ptr surf |
externalForm := ExternalForm extent: aForm extent depth: 32.
ptr := ExternalAddress gcallocate: (aForm extent x * aForm extent y * 4).
externalForm setManualSurfacePointer: ptr.
(BitBlt toForm: externalForm)
copy: aForm boundingBox
from: 0@0 in: aForm.
stride _ Cairo formatStrideForWidth: Cairo CairoFormatARGB32 width: aForm extent x.
surf _ Cairo imageSurfaceCreateForData: ptr format: Cairo CairoFormatARGB32 width: aForm extent x height: aForm extent y stride: stride.
"We need to keep the externalForm alive. Otherwise the surface gets invalid when the form memory is relased because of gc."
^ CairoSurface new surface: surf; externalForm: externalForm; yourself! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 1/26/2022 17:26:06'!
drawButtonIconFromCurrentMorph
"We assume that we are drawing a PluggableButtonMorph,
or some morph that conforms the required protocol.
Answer true if we were able to draw it."
currentMorph magnifiedIcon ifNotNil: [ :theIcon |
self
image: theIcon
multipliedBy: currentMorph color
at: (currentMorph morphExtent - theIcon extent //2).
^true ].
^false! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 6/14/2020 14:29:28'!
drawString: aString at: aPoint font: fontOrNil color: aColor
|font fw slant fsize str|
font _ fontOrNil ifNil: [FontFamily defaultFamilyAndPointSize].
fw _ font isBold ifTrue: [Cairo CairoFontWeightBold]
ifFalse: [Cairo CairoFontWeightNormal ].
slant _ font isItalic ifTrue: [Cairo CairoFontSlantItalic ]
ifFalse: [Cairo CairoFontSlantNormal ].
fsize _ font lineSpacing - 2. "<-- I'm doing this arbitrarily :( "
cairo setSourceColor: aColor.
cairo selectFontFace: font name
slant: slant
weight: fw.
cairo setFontSize: fsize; moveTo: aPoint x @ (aPoint y + fsize).
"Cairo printDebug: 'TEXT: ', aString."
str _ aString reject: [:aCharacter | {Character newLineCharacter. Character tab} includes: aCharacter].
cairo showText: str.
^ nil! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 21:30:33'!
drawString: aString from: firstIndex to: lastIndex at: aPoint font: fontOrNil color: aColor
^ self drawString: (aString copyFrom: firstIndex to: lastIndex) at: aPoint font: fontOrNil color: aColor! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 18:23:23'!
fillRectangle: aRectangle color: aColor
cairo setSourceColor: aColor;
rectangle: aRectangle;
fill.
! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 18:29:56'!
fillRectangle: aRectangle color: aColor borderWidth: borderWidth borderStyleSymbol: aSymbol baseColorForBorder: baseColorForBorder
cairo setSourceColor: aColor;
rectangle: aRectangle;
fill.
cairo setLineWidth: borderWidth;
setSourceColor: baseColorForBorder;
moveTo: aRectangle origin;
lineTo: aRectangle topRight;
lineTo: aRectangle bottomRight;
lineTo: aRectangle bottomLeft;
lineTo: aRectangle topLeft;
stroke! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 00:44:15'!
frameAndFillRectangle: r fillColor: fillColor borderWidth: borderWidth borderColor: borderColor
self frameRectangle: r borderWidth: borderWidth color: fillColor! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 11:09:27'!
frameRectangle: r borderWidth: borderWidth color: aColor
cairo roundedRectangle: r radius: 5;
setLineWidth: borderWidth;
setSourceColor: aColor;
stroke.! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 11:11:42'!
frameRectangle: r color: aColor borderWidth: borderWidth borderStyleSymbol: aSymbol
"
Display getCanvas fillRectangle: (10@10 extent: 300@200) color: Color white. Display forceToScreen.
Display getCanvas
frameRectangle: (10@10 extent: 300@200)
color: Color green
borderWidth: 10
borderStyleSymbol: #raised.
Display forceToScreen.
"
| displayRectangle bw |
bw _ (currentTransformation externalizeScalar: borderWidth) rounded.
aSymbol == #raised ifTrue: [
displayRectangle _ (currentTransformation externalizeRectangle: r) rounded.
^ self
frameRectangle: displayRectangle
borderWidth: bw
topLeftColor: aColor quiteWhiter
bottomRightColor: aColor quiteBlacker ].
aSymbol == #inset ifTrue: [
displayRectangle _ (currentTransformation externalizeRectangle: r) rounded.
^ self
frameRectangle: displayRectangle
borderWidth: bw
topLeftColor: aColor quiteBlacker
bottomRightColor: aColor quiteWhiter ].
"Unrecognized border style. Draw some border..."
self frameRectangle: r borderWidth: bw color: aColor! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/12/2019 14:10:05'!
image: aForm at: aPoint
|img|
img _ images at: aForm ifAbsent: [|im|
im _ self createImageSurface: aForm.
images at: aForm put: im.
im].
cairo setSourceSurface: img surface at: aPoint.
"cairo setOperator: 5."
cairo paint! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 19:49:41'!
image: aForm multipliedBy: aColor at: aPoint
self image: aForm at: aPoint! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 1/26/2022 17:27:51'!
into: aMorph
super into: aMorph.
cairo save; translate: aMorph morphPosition.
aMorph rotation isZero ifFalse: [
cairo translate: aMorph localBounds center;
rotate: aMorph rotation degreesToRadians;
translate: 0 - aMorph localBounds center].
cairo rectangle: (0@0 extent: aMorph morphExtent) ; clip.
! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 20:57:27'!
isCurrentMorphVisible
^ currentMorph visible! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 21:04:33'!
line: fromPoint to: toPoint width: width color: aColor
cairo setLineWidth: width;
setSourceColor: aColor;
moveTo: fromPoint;
lineTo: toPoint;
stroke.! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 12:48:52'!
outOfMorph
super outOfMorph.
cairo restore.
! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/12/2019 13:58:26'!
release
cairo destroy.
Cairo surfaceDestroy: surface.
images values do: [:img |
img release]! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 18:47:40'!
rotate: angle
cairo rotate: angle degreesToRadians ! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 19:09:55'!
rotatedBy: angle at: aPoint do: aBlock
cairo save;
translate: aPoint;
rotate: angle degreesToRadians;
translate: 0 - aPoint.
aBlock value.
cairo restore.
! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/22/2019 22:26:30'!
roundRect: aRectangle color: aColor radius: radius
cairo setSourceColor: aColor;
roundedRectangle: aRectangle radius: radius ;
fill.! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 22:13:11'!
scale: aPoint
cairo scale: aPoint! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/31/2019 19:12:55'!
spline: fromPoint to: toPoint control1: c1 control2: c2 width: width color: aColor
cairo moveTo: fromPoint;
setSourceColor: aColor;
setLineWidth: width;
curveTo: toPoint control1: c1 control2: c2 ;
stroke! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/9/2019 18:47:23'!
translate: aPoint
cairo translate: aPoint! !
!CairoCanvas methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 11:03:33'!
windowFrame: aRectangle color: aColor radius: r border: bw labelHeight: lh gradientTop: topFactor gradientBottom: bottomFactor insideColor: insideColor
cairo setSourceColor: aColor;
roundedRectangle: aRectangle radius: 10;
fill! !
!CairoCanvas methodsFor: 'initialization' stamp: 'MM 1/26/2022 17:23:32'!
initializeWithTranslation: aPoint
|stride |
super initializeWithTranslation: aPoint.
images _ WeakKeyDictionary new.
stride _ Cairo formatStrideForWidth: Cairo CairoFormatARGB32 width: form extent x.
surface _ Cairo imageSurfaceCreateForData: form pointer getHandle format: Cairo CairoFormatARGB32 width: form extent x height: form extent y stride: stride.
cairo _ CairoContext on: (Cairo create: surface).! !
!CairoCanvas class methodsFor: 'examples' stamp: 'MM 11/2/2019 15:05:31'!
fillPolygonExample
"self fillPolygonExample"
CairoCanvas withExtent: 500@500
draw: [:canvas |
canvas fillRectangle: (0@0 corner: 500@500) color: Color white.
canvas fillPolygon: {100@100. 150@200. 50@200} color: Color red.
canvas fillPolygon: {0@20. 20@0. 40@20. 20@40} color: Color blue ]! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 18:26:36'!
display: aMorph
^ self withExtent: aMorph morphExtent display: aMorph! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 19:23:00'!
displayWorld
Display restoreAfter: [CairoCanvas display: self runningWorld]! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 19:22:03'!
displayWorldRotated: angle
Display restoreAfter: [ |canvas morph|
morph _ self runningWorld.
canvas _ CairoCanvas withExtent: morph morphExtent.
canvas cairo rotate: angle degreesToRadians .
canvas fullDraw: morph.
canvas form displayAt: 0@0]! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 10/8/2019 19:20:27'!
displayWorldScaled: scale
Display restoreAfter: [ |canvas morph|
morph _ self runningWorld.
canvas _ CairoCanvas withExtent: morph morphExtent.
canvas cairo scale: scale.
canvas fullDraw: morph.
canvas form displayAt: 0@0]! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 18:12:51'!
withExtent: extent
^ self withExtent: extent depth: 32! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 19:35:07'!
withExtent: extent depth: depth
|form ptr|
form := ExternalForm extent: extent depth: depth.
ptr := ExternalAddress gcallocate: (extent x * extent y * 4) asInteger.
form setManualSurfacePointer: ptr.
^ self onForm: form! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 10/7/2019 21:01:04'!
withExtent: extent display: aMorph
"For testing purposes"
|canvas|
[canvas _ self withExtent: extent.
canvas fullDraw: aMorph.
canvas form displayAt: 0@0]
ensure: [canvas release]! !
!CairoCanvas class methodsFor: 'as yet unclassified' stamp: 'MM 11/2/2019 13:38:23'!
withExtent: extent draw: aBlock
"For testing purposes"
|canvas|
[canvas _ self withExtent: extent.
aBlock value: canvas.
canvas form displayAt: 0@0]
ensure: [canvas release]! !
!CodeProvider methodsFor: '*CairoMorphic' stamp: 'MM 10/12/2019 14:47:13'!
annotationSeparator
"Answer the separator to be used between annotations"
"cairo_show_text fails with the normal special character used here"
^ '. '! !
!Morph methodsFor: '*CairoMorphic' stamp: 'MM 10/7/2019 21:45:46'!
displayInCairo
CairoCanvas display: self! !
!Morph methodsFor: '*CairoMorphic' stamp: 'MM 10/9/2019 19:16:15'!
rotation
^ 0! !