CairoGraphicsContext.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 17 Jul 2018 19:50:23 +0200
changeset 86 e434bd07e403
parent 85 ac8d41172b87
child 88 9d51db2ba641
permissions -rw-r--r--
Refactored `CairoGraphicsContext` finalization to avoid code duplication
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/libcairo' }"
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
     3
"{ NameSpace: Smalltalk }"
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
     5
DeviceGraphicsContext subclass:#CairoGraphicsContext
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
     6
	instanceVariableNames:'cr'
60
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
     7
	classVariableNames:''
46
e624554ca9a3 CairoGraphicsContext: fixed drawing/filling of lines and rectangles to match DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 45
diff changeset
     8
	poolDictionaries:'Cairo::FontSlant Cairo::FontWeight Cairo::Format Cairo::Status
64
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
     9
		Cairo::Antialias Cairo::Extend'
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
    10
	category:'Cairo-Compatibility'
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
!
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
    13
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    14
!CairoGraphicsContext class methodsFor:'instance creation'!
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    15
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    16
onDeviceGraphicsContext: dGC
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    17
    | cGC |
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    18
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
    19
    cGC := self basicNew.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
    20
    1 to: DeviceGraphicsContext instSize do:[:i |
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
    21
        cGC instVarAt: i put: (dGC instVarAt: i).
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    22
    ].
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    23
    ^ cGC
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    24
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    25
    "Created: / 15-02-2016 / 21:20:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
86
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
    26
    "Modified (format): / 17-07-2018 / 22:52:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    27
! !
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
    28
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
    29
!CairoGraphicsContext class methodsFor:'accessing'!
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
12
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    31
dllPath
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    32
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    33
    OperatingSystem isMSWINDOWSlike ifTrue:[
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    34
        ^ #( 'C:\Windows' 'C:\Windows\System32' "Wild guess, should not harm" )
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    35
    ].
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    36
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    37
    OperatingSystem isUNIXlike ifTrue:[
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    38
        OperatingSystem getSystemType == #linux ifTrue:[
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    39
            | path |
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    40
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    41
            path := #( '/lib' '/usr/lib' '/usr/local/lib' ).
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    42
            (OperatingSystem getSystemInfo at:#machine) = 'x86_64' ifTrue:[
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    43
                "If the machine is 64bit, prepend standard path for 32bit libs.
20
18a3e6b5f310 Added const modifier to FFI specs (required by recent STX)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17
diff changeset
    44
                 Leave standard paths at the end, as the system might be completely
12
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    45
                 32bit but running on 64bit-capable CPU.
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    46
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    47
                CAVEAT: This is bit dangerous, as on 64bit OS, if ia32 libs are
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    48
                not installed byt 64bit sqlite libs are, then 64bit libs are found
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    49
                and when a function is called, segfault will occur!!
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    50
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    51
                Q: Is there a way how to figure out if the OS itself is 32bit,
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    52
                regardles on CPU?"
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    53
                path := #( '/lib32' '/usr/lib32' '/usr/local/lib32' ) , path.
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    54
            ].
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    55
            ^path
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    56
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    57
        ].
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    58
    ].
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    59
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    60
    self error:'Unsupported operating system'
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    61
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    62
    "
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    63
        SqliteLibrary dllPath
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    64
    "
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    65
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    66
    "Created: / 31-08-2011 / 18:02:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    67
!
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    68
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
libraryName
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    71
    OperatingSystem isUNIXlike ifTrue:[^'libcairo.so.2'].
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    73
    OperatingSystem isMSWINDOWSlike ifTrue:[^'cairo.dll'].
12
e5f0c18af8a9 - Cairo::Format
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 11
diff changeset
    74
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    75
    self error:'Library name for host OS is not known'
6
c1f387b40e3a regenerated using newer version of CFace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 5
diff changeset
    76
!
c1f387b40e3a regenerated using newer version of CFace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 5
diff changeset
    77
26
7f07a8c31e6d Fixed flickring of Cairo::ClockView by rendering into an off-screen image.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 23
diff changeset
    78
sizeof
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    79
    "Returns size of undelaying structure in bytes"
6
c1f387b40e3a regenerated using newer version of CFace
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 5
diff changeset
    80
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    81
    ^0
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
! !
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
    84
!CairoGraphicsContext class methodsFor:'examples'!
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    85
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    86
rectangleOnTranscript
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    87
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    88
    "
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    89
        Cairo::GraphicsContext rectangleOnTranscript
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    90
    "
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    91
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    92
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    93
    | gc |
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    94
    gc := Transcript cairo.
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    95
    gc paint: Color black.
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    96
    gc moveToX: 30 y: 50.
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    97
    gc paint: (Color red alpha: 0.5).
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    98
    gc rectangleX: 10 y: 15 width: 150 height: 60.
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
    99
    gc fill.
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   100
    gc paint: (Color red alpha: 0.75).
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   101
    gc rectangleX: 10 y: 15 width: 150 height: 60.
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   102
    gc stroke.
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   103
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   104
    "Created: / 23-04-2009 / 17:33:57 / Jan Vrany <vranyj1@fel.cvut.cz>"
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   105
! !
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   106
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   107
!CairoGraphicsContext methodsFor:'accessing'!
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   108
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   109
atX:x y:y
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   110
    "return the pixel at the coordinate given by x/y"
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   111
    cr notNil ifTrue:[ 
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   112
        cr surface flush.
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   113
    ].
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   114
    ^ device getPixelX:x y:y from:drawableId with:gcId
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   115
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   116
    "Created: / 16-03-2016 / 18:27:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   117
!
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   118
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   119
basicFont:aFont
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   120
    (aFont ~~ font) ifTrue:[     
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   121
        super basicFont: aFont.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   122
        font notNil ifTrue:[ 
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   123
            font := CairoScaledFont fromFontDescription: font onDevice: device.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   124
            cr notNil ifTrue:[ 
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   125
                cr font: font scaledFont.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   126
            ].
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   127
        ].
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   128
    ].
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   129
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   130
    "Created: / 16-02-2016 / 15:37:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
44
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   131
    "Modified: / 23-02-2016 / 14:46:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   132
    "Modified: / 21-02-2016 / 15:38:52 / jv"
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   133
!
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   134
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   135
cairo
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   136
    "Return a Cairo context for drawing onto this GC" 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   137
    | ncr |
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   138
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   139
    ncr := Cairo::GraphicsContext onSurface: super cairoSurface.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   140
    ^ ncr.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   141
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   142
    "Created: / 31-03-2016 / 00:13:07 / jv"
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   143
!
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   144
48
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   145
cairoSurface
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   146
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   147
        self initCR.
48
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   148
    ].
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   149
    cr isNil ifTrue:[ 
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   150
        ^ super cairoSurface
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   151
    ].
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   152
    ^ cr surface
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   153
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   154
    "Created: / 25-02-2016 / 10:46:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   155
!
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   156
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   157
clippingBounds:aRectangleOrNil
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   158
    "set the clipping rectangle for drawing (in logical coordinates);
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   159
     a nil argument turn off clipping (i.e. whole view is drawable)"    
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   160
70
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   161
    super clippingBounds:aRectangleOrNil.
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   162
    cr notNil ifTrue:[ 
75
e3ca2f982493 Fixed a baad bug in CairoGraphicsContext>>clippingBounds:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 74
diff changeset
   163
        cr clipReset.
e3ca2f982493 Fixed a baad bug in CairoGraphicsContext>>clippingBounds:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 74
diff changeset
   164
        aRectangleOrNil notNil ifTrue:[ 
70
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   165
            cr rectangleX: aRectangleOrNil left
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   166
                        y: aRectangleOrNil top
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   167
                    width: aRectangleOrNil width
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   168
                   height: aRectangleOrNil height.
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   169
            cr clip.
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   170
        ].
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   171
    ].
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   172
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   173
    "Created: / 15-02-2016 / 21:38:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
70
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   174
    "Modified: / 25-03-2016 / 06:58:26 / jv"
75
e3ca2f982493 Fixed a baad bug in CairoGraphicsContext>>clippingBounds:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 74
diff changeset
   175
    "Modified: / 04-04-2016 / 21:01:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
70
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   176
!
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   177
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   178
deviceClippingBounds:aRectangleOrNil
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   179
    "set the clipping rectangle for drawing (in device coordinates);
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   180
     a nil argument turns off clipping (i.e. whole view is drawable - incl. margins)"
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   181
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   182
    super deviceClippingBounds: aRectangleOrNil.
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   183
    self deviceCoordinatesDo:[
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   184
        cr notNil ifTrue:[ 
77
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   185
            cr clipReset.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   186
            aRectangleOrNil notNil ifTrue:[
70
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   187
                cr rectangleX: aRectangleOrNil left
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   188
                            y: aRectangleOrNil top
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   189
                        width: aRectangleOrNil width
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   190
                       height: aRectangleOrNil height.
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   191
                cr clip.
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   192
            ].
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   193
        ].
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   194
    ].
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   195
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
   196
    "Created: / 27-03-2016 / 00:09:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
77
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   197
    "Modified: / 05-04-2016 / 16:42:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   198
!
34
97705b5a9411 Use Cairo's toy text API for text rendering.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 33
diff changeset
   199
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   200
function:aFunctionSymbol
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   201
    "set the drawing function"
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   202
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   203
    #todo.
48
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   204
    ^ super function:aFunctionSymbol
2a66aee0a9b3 Added support for creating surfaces for X11 pixmaps
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 47
diff changeset
   205
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   206
    "Modified: / 27-02-2016 / 15:21:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   207
!
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   208
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   209
lineWidth: w
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   210
    super lineWidth: w. 
44
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   211
    cr notNil ifTrue:[
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   212
        cr lineWidth: (w == 0 ifTrue:[ 1 ] ifFalse:[ w ]).
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   213
    ].
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   214
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   215
    "Created: / 17-06-2012 / 21:55:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
44
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   216
    "Modified: / 23-02-2016 / 11:29:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   217
!
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   218
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   219
mask:aForm
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   220
    "set the drawing mask"
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   221
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   222
    super mask: aForm.
64
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   223
    cr notNil ifTrue:[ 
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   224
        self maskSet.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   225
    ].
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   226
64
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   227
    "Modified (format): / 08-03-2016 / 21:22:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   228
!
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   229
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   230
maskOrigin:aPoint
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   231
    "set the origin of the mask-pattern"
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   232
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   233
    super maskOrigin: aPoint.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   234
    gcId notNil ifTrue:[
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   235
        mask notNil ifTrue:[   
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   236
            self maskSet.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   237
        ].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   238
    ].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   239
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
   240
    "Created: / 08-03-2016 / 21:23:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   241
!
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   242
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   243
paint: aColor
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   244
    super paint: aColor.
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
   245
    cr notNil ifTrue:[
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
   246
        cr source: paint.
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
   247
    ].
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   248
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   249
    "Created: / 10-07-2008 / 11:18:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   250
    "Modified: / 23-04-2009 / 17:31:33 / Jan Vrany <vranyj1@fel.cvut.cz>"
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
   251
    "Modified: / 18-02-2016 / 22:56:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
62
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   252
!
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   253
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   254
paint:fgColor on:bgColor
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   255
    "Set the paint and background-paint color.
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   256
     The bg-paint is used in opaque-draw operations"
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   257
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   258
    super paint: fgColor on: bgColor.
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   259
    cr notNil ifTrue:[ 
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   260
        cr source: paint.        
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   261
    ].
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   262
a1280a796155 CairoGraphicsContext: oops, fixed #paint:on:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 60
diff changeset
   263
    "Created: / 05-03-2016 / 16:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   264
!
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   265
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   266
width: width height: height
76
f3deda9cea3e Oops, fixed CairoGraphicsContext>>width:height:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 75
diff changeset
   267
    cr notNil ifTrue:[
f3deda9cea3e Oops, fixed CairoGraphicsContext>>width:height:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 75
diff changeset
   268
        device isX11Platform ifTrue:[ 
f3deda9cea3e Oops, fixed CairoGraphicsContext>>width:height:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 75
diff changeset
   269
            cr surface width: width height: height 
f3deda9cea3e Oops, fixed CairoGraphicsContext>>width:height:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 75
diff changeset
   270
        ] ifFalse:[ 
f3deda9cea3e Oops, fixed CairoGraphicsContext>>width:height:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 75
diff changeset
   271
            self destroyCR.
f3deda9cea3e Oops, fixed CairoGraphicsContext>>width:height:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 75
diff changeset
   272
        ].
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   273
    ].
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   274
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   275
    "Created: / 02-04-2016 / 15:37:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   276
    "Modified: / 02-04-2016 / 15:55:29 / jv"
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   277
! !
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   278
77
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   279
!CairoGraphicsContext methodsFor:'accessing-internals'!
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   280
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   281
foreground:aColor
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   282
    <resource: #obsolete>
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   283
    "set the internal foreground color for drawing - aColor must be a real color.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   284
     OBSOLETE: this method will vanish; use #paint: / #paint:on:"
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   285
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   286
    (aColor ~~ foreground) ifTrue:[
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   287
        aColor notNil ifTrue:[
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   288
            super foreground:aColor.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   289
            cr notNil ifTrue:[ 
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   290
                cr source: paint.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   291
            ].
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   292
        ]
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   293
    ]
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   294
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   295
    "Created: / 05-04-2016 / 16:59:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   296
!
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   297
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   298
foreground:fgColor background:bgColor
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   299
    <resource: #obsolete>
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   300
    "set both internal foreground and internal background colors
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   301
     - these must be real colors.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   302
     OBSOLETE: this method will vanish; use #paint: / #paint:on:"
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   303
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   304
    ((fgColor ~~ foreground) or:[bgColor ~~ background]) ifTrue:[
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   305
        super foreground:fgColor background:bgColor.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   306
        cr notNil ifTrue:[ 
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   307
            cr source: paint.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   308
        ].  
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   309
    ]
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   310
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   311
    "Created: / 05-04-2016 / 17:00:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   312
!
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   313
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   314
foreground:aColor function:fun
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   315
    <resource: #obsolete>
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   316
    "set the foreground color and function for drawing.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   317
     OBSOLETE: this method will vanish; use #paint: / #paint:on:"
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   318
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   319
    ((aColor ~~ foreground) or:[fun ~~ function]) ifTrue:[
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   320
        super foreground:aColor function:fun.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   321
        cr notNil ifTrue:[ 
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   322
            cr source: paint.
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   323
        ].
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   324
    ]
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   325
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   326
    "Created: / 05-04-2016 / 17:01:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   327
! !
cdf856e78998 CairoGraphicsContext: Fixed paint setting
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 76
diff changeset
   328
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   329
!CairoGraphicsContext methodsFor:'accessing-transformation'!
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   330
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   331
transformation:aTransformation 
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   332
    "set the transformation"
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   333
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   334
    super transformation: aTransformation.
44
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   335
    cr notNil ifTrue:[
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   336
        cr matrixReset.
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   337
        transformation notNil ifTrue:[ 
44
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   338
            cr
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   339
                scale: transformation scale;
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   340
                translate: transformation translation.
44
ffe4882eb977 Avoid excessive font object creation by cacheing in device
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 42
diff changeset
   341
        ]
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   342
    ]
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   343
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   344
    "Created: / 01-01-2015 / 12:07:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   345
    "Modified: / 16-03-2016 / 22:26:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   346
! !
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   347
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   348
!CairoGraphicsContext methodsFor:'basic drawing'!
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   349
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   350
displayArcX:x y:y width:w height:h from:start angle:angle
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   351
    | angle1 angle2 |
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   352
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   353
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   354
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   355
    ]. 
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   356
    cr save.  
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   357
    [
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   358
        w ~~ h ifTrue:[
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   359
            self notYetImplemented
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   360
        ].
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   361
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   362
        angle1 := (360 - start) .
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   363
        angle2 := (360 - (start + angle)) \\ 360.
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   364
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   365
        (angle2 < angle1) ifTrue:[
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   366
            cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle1 * (Float pi / 180) to: angle2 * (Float pi / 180).
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   367
        ] ifFalse:[ 
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   368
            cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle2 * (Float pi / 180) to: angle1 * (Float pi / 180).
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   369
        ].
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   370
        cr stroke.
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   371
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   372
        w ~~ h ifTrue:[
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   373
            self notYetImplemented
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   374
        ].
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   375
    ] ensure:[ 
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   376
        cr restore.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   377
    ]
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   378
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   379
    "Modified: / 13-02-2016 / 20:05:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   380
    "Modified: / 21-02-2016 / 15:34:08 / jv"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   381
!
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   382
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   383
displayLineFromX:x0 y:y0 toX:x1 y:y1
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   384
    "draw a line from x0/y0 to x1/y1"
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   385
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   386
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   387
    ].
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   388
    x0 = x1 ifTrue:[
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   389
        cr moveToX: x0 + 0.5 y: y0.
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   390
        cr lineToX: x1 + 0.5 y: y1.
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   391
    ] ifFalse:[ 
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   392
        y0 = y1 ifTrue:[ 
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   393
            cr moveToX: x0 y: y0 + 0.5.
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   394
            cr lineToX: x1 y: y1 + 0.5.
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   395
        ] ifFalse:[ 
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   396
            cr moveToX: x0 y: y0.
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   397
            cr lineToX: x1 y: y1.
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   398
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   399
        ].
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   400
    ].
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   401
    cr stroke.
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   402
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   403
    "Modified: / 21-02-2016 / 15:24:52 / jv"
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   404
    "Modified: / 16-03-2016 / 22:40:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   405
!
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   406
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   407
displayPolygon:points
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   408
    "draw a polygon
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   409
     - this could be recoded to draw using displayLine"
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   410
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   411
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   412
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   413
    ]. 
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   414
    cr moveToX: points first x asFloat y: points first y asFloat.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   415
    2 to: points size do:[:i |  
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   416
        cr lineToX: (points at: i) x asFloat  y: (points at: i) y asFloat
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   417
    ].
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   418
    cr closePath.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   419
    cr stroke.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   420
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   421
    "Modified: / 13-02-2016 / 20:04:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   422
    "Modified: / 21-02-2016 / 15:34:19 / jv"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   423
!
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   424
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   425
displayRectangleX:x y:y width:w height:h
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   426
    "draw a rectangle
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   427
     - this could be recoded to draw using displayLine"
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   428
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   429
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   430
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   431
    ]. 
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   432
    (w > 0 and:[h > 0]) ifTrue:[
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   433
        cr rectangleX: x + 0.5 y: y + 0.5 width: w - 0.5 height: h - 0.5.
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   434
        cr stroke.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   435
    ]
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   436
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   437
    "Modified: / 21-02-2016 / 15:34:34 / jv"
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
   438
    "Modified: / 16-03-2016 / 22:42:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   439
!
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   440
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   441
displayString:string from:index1 to:index2 x:x y:y opaque:opaqueArg maxWidth:maxWidth
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   442
    "draw a substring at the coordinate x/y - draw foreground pixels in
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   443
     paint-color and (if opaque is true), background pixels in bgPaint-color.
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   444
     If the transformation involves scaling, the font's point-size is scaled as appropriate.
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   445
     Assuming that device can only draw in device colors, we have to handle
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   446
     the case where paint and/or bgPaint are dithered colors.
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   447
     maxWidth is the maximum width of the string in pixels or nil if unknown."    
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   448
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   449
    | opaque |
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   450
    "
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   451
     if backgroundPaint color is nil, we assume
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   452
     this is a non-opaque draw
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   453
    "
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   454
    opaque := opaqueArg ? false.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   455
    bgPaint isNil ifTrue:[
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   456
        opaque := false.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   457
    ].
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   458
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   459
    cr isNil ifTrue:[
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   460
        self initGC
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   461
    ]. 
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   462
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   463
    (string isString not or:[string isText]) ifTrue:[
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   464
        "
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   465
         hook for non-strings (i.e. attributed text)
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   466
         that 'thing' should know how to display itself ...
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   467
        "
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   468
        string displayOn:self x:x y:y from:index1 to:index2 opaque:opaque.
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   469
        ^ self
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   470
    ].   
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   471
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   472
    font class == CairoScaledFont ifTrue:[ 
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   473
        font displayString:string from:index1 to:index2 x:x y:y cr:cr fg: paint bg: bgPaint opaque:opaque
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   474
    ] ifFalse:[ 
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   475
        Logger warning:'Drawing text using non-Cairo font (%1 )on CairoGraphicsContext' with: font class name.
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   476
        cr surface flush.
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   477
        super displayString:string from:index1 to:index2 x:x y:y opaque:opaqueArg maxWidth:maxWidth.
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   478
        cr surface markDirty.
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   479
    ].
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   480
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   481
    "Created: / 16-02-2016 / 10:51:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   482
    "Modified: / 19-02-2016 / 21:04:49 / jv"
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   483
    "Modified: / 24-02-2016 / 17:14:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   484
! !
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   485
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   486
!CairoGraphicsContext methodsFor:'basic filling'!
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   487
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   488
fillArcX:x y:y width:w height:h from:start angle:angle
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   489
    | angle1 angle2 |
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   490
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   491
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   492
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   493
    ].
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   494
    cr save. 
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   495
    [
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   496
        w ~~ h ifTrue:[
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   497
            self notYetImplemented
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   498
        ].
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   499
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   500
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   501
        angle1 := (360 - start) .
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   502
        angle2 := (360 - (start + angle)) \\ 360.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   503
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   504
        cr moveToX: (x + (w / 2)) y: (y + (h / 2)).
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   505
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   506
        (angle2 < angle1) ifTrue:[
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   507
            cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle1 * (Float pi / 180) to: angle2 * (Float pi / 180).
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   508
        ] ifFalse:[ 
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   509
            cr arcNegativeX: (x + (w / 2)) y: (y + (h / 2)) radius: w / 2 from: angle2 * (Float pi / 180) to: angle1 * (Float pi / 180).
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   510
        ].
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   511
        cr closePath.
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   512
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   513
        cr strokeAndPreserve.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   514
        cr fill.
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   515
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   516
        w ~~ h ifTrue:[
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   517
            self notYetImplemented        
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   518
        ].
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   519
    ] ensure:[ 
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   520
        cr restore.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   521
    ]
32
fb983be8d2c0 To fold - support for display/fillArc...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   522
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   523
    "Modified: / 13-02-2016 / 20:03:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   524
    "Modified: / 21-02-2016 / 15:34:47 / jv"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   525
!
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   526
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   527
fillPolygon:points
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   528
    "fill a polygon with current paint color"
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   529
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   530
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   531
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   532
    ].
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   533
    cr moveToX: points first x asFloat y: points first y asFloat.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   534
    2 to: points size do:[:i |  
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   535
        cr lineToX: (points at: i) x asFloat  y: (points at: i) y asFloat
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   536
    ].
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   537
    cr closePath.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   538
    cr strokeAndPreserve.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   539
    cr fill.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   540
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   541
    "Modified: / 13-02-2016 / 20:01:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   542
    "Modified: / 21-02-2016 / 15:34:52 / jv"
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   543
!
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   544
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   545
fillRectangleX:x y:y width:w height:h
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   546
    "fill a rectangle with current paint color"
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   547
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   548
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   549
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   550
    ].
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   551
    (w > 0 and:[h > 0]) ifTrue:[
54
209a2b0b721a CairoGraphicsContext: adjustments to displayRectangle / fillRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 51
diff changeset
   552
        | savedWidth |
209a2b0b721a CairoGraphicsContext: adjustments to displayRectangle / fillRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 51
diff changeset
   553
209a2b0b721a CairoGraphicsContext: adjustments to displayRectangle / fillRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 51
diff changeset
   554
        savedWidth := cr lineWidth.
209a2b0b721a CairoGraphicsContext: adjustments to displayRectangle / fillRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 51
diff changeset
   555
        cr lineWidth: 1.  
78
75a8daa0f8a6 Issue #1: Oops, must adjust coordinates also when filling a rectangle.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 77
diff changeset
   556
        cr rectangleX: x + 0.5 y: y + 0.5 width: w - 0.5 height: h - 0.5.
46
e624554ca9a3 CairoGraphicsContext: fixed drawing/filling of lines and rectangles to match DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 45
diff changeset
   557
        cr strokeAndPreserve.
54
209a2b0b721a CairoGraphicsContext: adjustments to displayRectangle / fillRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 51
diff changeset
   558
        cr lineWidth: savedWidth.  
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   559
        cr fill.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   560
    ].
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   561
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   562
"/    cr save.
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   563
"/    cr rectangleX: x y: y width: w height: h. 
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   564
"/    cr sourceR: 1 G: 0 B: 0.
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   565
"/    cr lineWidth: 1.  
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   566
"/    cr stroke.
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   567
"/    cr restore.
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   568
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   569
    "Modified: / 21-02-2016 / 15:34:56 / jv"
78
75a8daa0f8a6 Issue #1: Oops, must adjust coordinates also when filling a rectangle.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 77
diff changeset
   570
    "Modified: / 05-04-2016 / 21:55:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   571
! !
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   572
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   573
!CairoGraphicsContext methodsFor:'bit blitting'!
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   574
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   575
copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth padding:pad width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   576
    "copy bits from a smalltalk byteArray.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   577
     The bits found there are supposed to be in the devices native format (i.e.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   578
     translated to allocated color indices on pseudoColor devices and padded as required.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   579
     The byteOrder is MSB and will be converted as appropriate by the underlying devices
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   580
     method to whatever the device needs."
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   581
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   582
    cr notNil ifTrue:[ 
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   583
        cr surface flush
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   584
    ].
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   585
    super copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth padding:pad width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY.
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   586
    cr notNil ifTrue:[ 
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   587
        cr surface markDirty
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   588
    ].
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   589
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   590
    "Created: / 18-02-2016 / 20:16:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   591
    "Modified: / 24-02-2016 / 18:19:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   592
!
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   593
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   594
copyFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h async:async
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   595
    "copy from aDrawable into the receiver;
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   596
     the source may be the receiver as well - in this case its a scroll.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   597
     All coordinates are in device coordinates.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   598
     If the receiver is a view AND async is true, the call returns immediately
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   599
     - otherwise, it returns when the scroll operation is finished.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   600
     (not all devices care for this).
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   601
     If the receiver is a pixmap, the call always returns immediately."
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   602
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   603
    cr notNil ifTrue:[ 
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   604
        cr surface flush
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   605
    ].
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   606
    super copyFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h async:async.
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   607
    cr notNil ifTrue:[ 
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   608
        cr surface markDirty
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   609
    ].
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   610
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   611
    "Created: / 18-02-2016 / 20:17:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   612
    "Modified: / 24-02-2016 / 18:19:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   613
!
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   614
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   615
copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   616
    "copy one plane from aDrawable into the receiver. 0's are drawn in
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   617
     background, while 1's are drawn with foreground color.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   618
     The depth of aDrawable must (should) be 1.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   619
     The drawable must have been allocated on the same device.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   620
     All coordinates are in device coordinates."
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   621
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   622
    cr notNil ifTrue:[ 
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   623
        cr surface flush
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   624
    ].
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   625
    super copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h.
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   626
    cr notNil ifTrue:[ 
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   627
        cr surface markDirty
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   628
    ].
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   629
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   630
    "Created: / 18-02-2016 / 20:17:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   631
    "Modified (format): / 21-02-2016 / 15:35:11 / jv"
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   632
    "Modified: / 24-02-2016 / 18:19:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
10
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   633
! !
dd5fece7c8d2 Few hacks before presentation at Smalltalk Jihlava 2009
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 8
diff changeset
   634
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   635
!CairoGraphicsContext methodsFor:'change & update'!
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   636
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   637
update: aspect with: param from: sender
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   638
    aspect == #sizeOfView  ifTrue:[
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   639
        self updateCR.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   640
        ^ self.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   641
    ].
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   642
    super update: aspect with: param from: sender
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   643
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   644
    "Created: / 29-03-2016 / 23:00:56 / jv"
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   645
!
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   646
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   647
updateCR
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   648
    "Called when view associated with given context
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   649
     changes its size"
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   650
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   651
    cr notNil ifTrue:[        
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   652
        device isWindowsPlatform ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   653
            | surface blocked |
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   654
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   655
            blocked := OperatingSystem blockInterrupts.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   656
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   657
            surface := cr surface.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   658
            cr release.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   659
            surface release.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   660
            device dcUnlockForGC: gcId.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   661
            cr := nil.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   662
            blocked ifFalse:[
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   663
                OperatingSystem unblockInterrupts.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   664
            ]
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   665
        ]].
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   666
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   667
    "Created: / 29-03-2016 / 22:58:49 / jv"
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   668
    "Modified: / 31-03-2016 / 00:39:48 / jv"
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   669
    "Modified: / 02-04-2016 / 15:38:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   670
! !
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   671
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   672
!CairoGraphicsContext methodsFor:'drawing'!
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   673
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   674
displayForm:aFormOrImage x:x y:y
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   675
    "draw a form (or image) at x/y; 
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   676
     if the form has depth 1, 1's in the form are
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   677
     drawn in current paint color, 0's are ignored.
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   678
     If the form has depth ~~ 1, the current fg color setting is ignored."
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   679
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   680
    | image width height imageSurface |
39
8af34937e1ec More work for using CairoGrahicsContext for rendering views
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 36
diff changeset
   681
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   682
    image := aFormOrImage asImage.
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   683
    (image mask isNil or:[ image mask depth == 1 ]) ifTrue:[ 
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   684
        cr notNil ifTrue:[ 
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   685
            cr surface flush.
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   686
        ].
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   687
        super displayForm:aFormOrImage x:x y:y.
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   688
        cr notNil ifTrue:[ 
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   689
            cr surface markDirty.
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   690
        ].
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   691
        ^ self.
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   692
    ].
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   693
    width := image width.
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   694
    height := image height.
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   695
    imageSurface := Cairo::Surface newImageWithFormat: CAIRO_FORMAT_ARGB32  width: width height: height similarTo: cr surface.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   696
    [
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   697
        image bitsARGB32Into: imageSurface data startingAt: 1 stride: imageSurface stride.
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   698
        imageSurface markDirty.
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   699
        cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   700
            self initCR.
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   701
        ].
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   702
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   703
        cr sourceSurface: imageSurface x: x y: y.
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   704
        cr paint.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   705
    ] ensure:[ 
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   706
        imageSurface release.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   707
    ].
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   708
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 30
diff changeset
   709
    "Created: / 31-12-2014 / 12:08:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
51
5293f2b851ab CairGraphicsContext: added support for displaying images with alpha channel
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 50
diff changeset
   710
    "Modified: / 27-02-2016 / 19:16:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   711
!
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   712
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   713
displayLineFrom:p0 to:p1
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   714
    "draw a line (with current paint-color); apply transformation if nonNil"
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   715
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   716
    ^ self displayLineFromX: p0 x y: p0 y toX: p1 x y: p1 y
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   717
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   718
    "Created: / 18-02-2016 / 20:27:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   719
!
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   720
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   721
displayLineFromX:xStart y:yStart toX:xEnd y:yEnd brush:aForm
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   722
    "draw a line using a brush.
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   723
     Here, a slow fallback is used, drawing into a 
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   724
     temporary bitmap first, which is then displayed"
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   725
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   726
    cr notNil ifTrue:[ 
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   727
        cr surface flush
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   728
    ].
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   729
    super displayLineFromX:xStart y:yStart toX:xEnd y:yEnd brush:aForm.
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   730
    cr notNil ifTrue:[ 
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   731
        cr surface markDirty
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   732
    ].
40
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   733
28dfc583beb5 #displayString: in CairoGraphicsContext revamped
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 39
diff changeset
   734
    "Created: / 18-02-2016 / 20:28:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
47
061f23d91383 CairoScaledFont: fixed drawing of CairoScaledFont on plain old DeviceGraphicsContext.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 46
diff changeset
   735
    "Modified: / 24-02-2016 / 18:19:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   736
!
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   737
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   738
displayRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   739
    | r pi |
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   740
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   741
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   742
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   743
    ].
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   744
    wCorn ~~ hCorn ifTrue:[ 
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   745
        self notYetImplemented.
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   746
    ].
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   747
    r := wCorn / 2.
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   748
    pi := Float pi.
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   749
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   750
    "/ top-left arc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   751
    cr arcX: x + r     y: y + r     radius: r from:         pi to: (3/2) * pi.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   752
    "/ top-right atc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   753
    cr arcX: x + w - r y: y + r     radius: r from: (3/2) * pi to: 0.0.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   754
    "/ bottom-right atc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   755
    cr arcX: x + w - r y: y + h - r radius: r from: 0.0        to: (1/2) * pi.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   756
    "/ bottom-left atc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   757
    cr arcX: x + r     y: y + h - r radius: r from: (1/2) * pi to:         pi.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   758
    cr closePath.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   759
    cr stroke.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   760
    
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   761
    "
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   762
     |v|
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   763
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   764
     (v := View new) extent:200@200; openAndWait.
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   765
     v cairo 
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   766
            lineWidth: 5;
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   767
            displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20;
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   768
            release
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   769
    "
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   770
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   771
    "Created: / 07-01-2015 / 20:41:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   772
    "Modified: / 13-02-2016 / 20:00:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   773
    "Modified: / 21-02-2016 / 15:35:35 / jv"
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   774
! !
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   775
49
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   776
!CairoGraphicsContext methodsFor:'drawing in device coordinates'!
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   777
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   778
displayDeviceForm:aForm x:x y:y
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   779
    "draw a form or image non opaque (i.e. only foreground color is drawn);
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   780
     If its a 1-plane bitmap, 1-bits are drawn in the
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   781
     current paint-color, leaving pixels with 0-bits unchanged
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   782
     (i.e. only 1-bits are drawn from the form).
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   783
     If its a deep form (i.e. a pixmap) the current paint
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   784
     settings are ignored and the form is drawn as-is;
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   785
     however, the mask is applied if present.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   786
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   787
     The form should must have been allocated on the same device,
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   788
     otherwise its converted here, which slows down the draw.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   789
     No transformation or scaling is done.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   790
     Care must be taken, that the paint color is correctly allocated
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   791
     (by sending #on: to the color) before doing so.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   792
     Using functions other than #copy only makes sense if you are
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   793
     certain, that the colors are real colors (actually, only for
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   794
     noColor or allColor)."
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   795
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   796
    cr notNil ifTrue:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   797
        cr surface flush.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   798
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   799
    super displayDeviceForm:aForm x:x y:y.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   800
    cr notNil ifTrue:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   801
        cr surface markDirty.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   802
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   803
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   804
    "Created: / 26-02-2016 / 10:47:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   805
!
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   806
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   807
displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   808
    "draw a line (with current paint-color) in device coordinate space.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   809
     This ignores any transformations. The coordinates must be integers."
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   810
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   811
    self deviceCoordinatesDo:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   812
        self displayLineFromX:x0 y:y0 toX:x1 y:y1
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   813
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   814
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   815
    "Created: / 26-02-2016 / 10:32:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   816
!
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   817
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   818
displayDeviceOpaqueForm:aForm x:x y:y
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   819
    "draw a form or image opaque (i.e. both fg and bg is drawn);
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   820
     If its a 1-plane bitmap, 1-bits are drawn in the
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   821
     current paint-color and 0-bits in the bgPaint color.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   822
     If its a deep form (i.e. a pixmap) the current paint/bgPaint
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   823
     settings are ignored and the form drawn as-is.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   824
     Any mask is ignored.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   825
     In the 1-plane case, special care must be taken if paint and/or bgPaint
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   826
     dithered colors or patterns, since are that the colors are correctly allocated (by sending #on:
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   827
     to the colors) before doing so.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   828
     The form should have been allocated on the same device; otherwise,
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   829
     its converted here, which slows down the draw.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   830
     Drawing is in device coordinates; no scaling is done."
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   831
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   832
    cr notNil ifTrue:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   833
        cr surface flush.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   834
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   835
    super displayDeviceOpaqueForm:aForm x:x y:y.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   836
    cr notNil ifTrue:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   837
        cr surface markDirty.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   838
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   839
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   840
    "Created: / 26-02-2016 / 10:47:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   841
!
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   842
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   843
displayDeviceOpaqueString:aString from:index1 to:index2 in:fontToUse x:x y:y
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   844
    "draw a substring at the coordinate x/y - draw foreground pixels in
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   845
     paint-color and background pixels in bgPaint-color.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   846
     Assuming that device can only draw in device colors, we have to handle
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   847
     the case where paint and/or bgPaint are dithered colors.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   848
     No translation or scaling is done."
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   849
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   850
    | savedFont |
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   851
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   852
    "
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   853
     if backgroundPaint color is nil, we assume
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   854
     this is a non-opaque draw
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   855
    "
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   856
    bgPaint isNil ifTrue:[
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   857
        self displayDeviceString:aString from:index1 to:index2 x:x y:y.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   858
        ^ self
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   859
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   860
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   861
    aString isPlainString ifFalse:[
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   862
        "
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   863
         hook for non-strings (i.e. attributed text)
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   864
         that 'thing' should know how to display itself ...
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   865
        "
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   866
        aString displayOpaqueOn:self x:x y:y from:index1 to:index2.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   867
        ^ self
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   868
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   869
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   870
    self deviceCoordinatesDo:[
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   871
        savedFont := self font.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   872
        [  
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   873
            self font:fontToUse.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   874
            self displayOpaqueString:aString from:index1 to:index2 x:x y:y
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   875
        ] ensure:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   876
            self font: savedFont
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   877
        ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   878
    ]
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   879
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   880
    "Created: / 26-02-2016 / 10:44:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   881
!
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   882
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   883
displayDeviceString:aString from:index1 to:index2 in:fontToUse x:x y:y
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   884
    "draw a substring at the coordinate x/y -
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   885
     draw foreground-pixels only (in current paint-color), leaving background as-is.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   886
     No translation or scaling is done"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   887
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   888
    | savedFont |
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   889
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   890
    "
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   891
     hook for non-strings (i.e. attributed text)
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   892
    "
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   893
    aString isPlainString ifFalse:[
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   894
        ^ aString displayOn:self x:x y:y from:index1 to:index2
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   895
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   896
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   897
    self deviceCoordinatesDo:[
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   898
        savedFont := self font.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   899
        [  
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   900
            self font:fontToUse.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   901
            self displayString:aString from:index1 to:index2 x:x y:y
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   902
        ] ensure:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   903
            self font: savedFont
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   904
        ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   905
    ]
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   906
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   907
    "Created: / 26-02-2016 / 10:45:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   908
!
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   909
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   910
fillDeviceRectangleX:x y:y width:w height:h
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   911
    "draw a filled rectangle in device coordinate space.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   912
     This ignores any transformations. The coordinates must be integers."
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   913
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   914
    self deviceCoordinatesDo:[ 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   915
        self fillRectangleX:x y:y width:w height:h
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   916
    ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   917
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   918
    "Created: / 26-02-2016 / 10:29:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   919
! !
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
   920
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   921
!CairoGraphicsContext methodsFor:'filling'!
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   922
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   923
fillRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   924
    | r pi |
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   925
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   926
    cr isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
   927
        self initCR.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   928
    ].
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   929
    wCorn ~~ hCorn ifTrue:[ 
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   930
        self notYetImplemented.
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   931
    ].
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   932
    r := wCorn / 2.
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   933
    pi := Float pi.
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   934
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   935
    "/ top-left arc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   936
    cr arcX: x + r     y: y + r     radius: r from:         pi to: (3/2) * pi.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   937
    "/ top-right atc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   938
    cr arcX: x + w - r y: y + r     radius: r from: (3/2) * pi to: 0.0.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   939
    "/ bottom-right atc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   940
    cr arcX: x + w - r y: y + h - r radius: r from: 0.0        to: (1/2) * pi.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   941
    "/ bottom-left atc
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   942
    cr arcX: x + r     y: y + h - r radius: r from: (1/2) * pi to:         pi.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   943
    cr closePath.
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   944
    cr fill.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   945
    
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   946
    "
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   947
     |v|
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   948
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   949
     (v := View new) extent:200@200; openAndWait.
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   950
     v cairoify 
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   951
            lineWidth: 5;
42
475e93b10c8f CairoGraphicsContext: Make sure native GC and Cairo context is initialized
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 41
diff changeset
   952
            displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20.
33
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   953
    "
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   954
8a2e438b4363 To fold - better display/fill RoundedRectangle...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   955
    "Created: / 07-01-2015 / 21:33:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   956
    "Modified: / 13-02-2016 / 20:00:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
45
8ee53c41a084 Win32: Initial support for Cairo under Windows
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 44
diff changeset
   957
    "Modified (comment): / 21-02-2016 / 15:58:59 / jv"
1
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   958
! !
2439fb18f3dc Initial commit.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   959
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   960
!CairoGraphicsContext methodsFor:'finalization'!
34
97705b5a9411 Use Cairo's toy text API for text rendering.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 33
diff changeset
   961
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   962
executor
86
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
   963
    ^ CairoGraphicsContextHandle basicNew setDeviceHandle: super executor cairo: cr
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   964
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   965
    "Created: / 12-02-2016 / 17:04:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
86
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
   966
    "Modified: / 17-07-2018 / 19:44:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
34
97705b5a9411 Use Cairo's toy text API for text rendering.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 33
diff changeset
   967
! !
97705b5a9411 Use Cairo's toy text API for text rendering.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 33
diff changeset
   968
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   969
!CairoGraphicsContext methodsFor:'initialization & release'!
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   970
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   971
createCR
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   972
    "Physically create a Cairo graphics context"
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   973
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
   974
    cr := self cairo.
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   975
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   976
    "Created: / 12-02-2016 / 16:59:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
   977
    "Modified: / 18-02-2016 / 22:53:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   978
!
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
   979
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   980
createGC
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   981
    "physically create a device GC.
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   982
     Since we do not need a gc-object for the drawable until something is
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   983
     really drawn, none is created up to the first draw.
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
   984
     This method is sent, when the first drawing happens"      
60
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   985
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   986
    "/ Here, we cannot simply do
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   987
    "/ 
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   988
    "/   super createGC.
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   989
    "/   self createCR.
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   990
    "/ 
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   991
    "/ As we need to tell the finalization lobby to register change
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   992
    "/ after we create Cairo context. Of course, we could just call
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   993
    "/ 
85
ac8d41172b87 Fixed `CairoGraphicsContext >> #initCR` and `#createGC` to work with recent `stx:libvuew`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 78
diff changeset
   994
    "/   device registerGraphicsContext: self
60
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   995
    "/ 
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   996
    "/ in createCR, but then we'd call it twice which is not what we want.
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   997
    "/ Therefore this ugly code duplication...sigh.
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   998
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
   999
    drawableType == #window ifTrue:[
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1000
        gcId := device gcFor:drawableId.
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1001
    ] ifFalse:[
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1002
        gcId := device gcForBitmap:drawableId.
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1003
    ].
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1004
    self createCR.
85
ac8d41172b87 Fixed `CairoGraphicsContext >> #initCR` and `#createGC` to work with recent `stx:libvuew`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 78
diff changeset
  1005
    device registerGraphicsContext: self
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1006
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1007
    "Created: / 12-02-2016 / 16:58:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
85
ac8d41172b87 Fixed `CairoGraphicsContext >> #initCR` and `#createGC` to work with recent `stx:libvuew`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 78
diff changeset
  1008
    "Modified: / 16-07-2018 / 22:46:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1009
!
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1010
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1011
destroyCR
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1012
    "Tell Cairo library to destroy the corresponding C object.
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1013
     Remember that object is physically destroyed only if internal
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1014
     refcounter goes to zero. However, after calling destroy,
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1015
     this instance should be treated as invalid."
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1016
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
  1017
    cr notNil ifTrue:[
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1018
        | wasBlocked surfaceToDestroy crToDestroy |
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1019
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1020
        wasBlocked := OperatingSystem unblockInterrupts.
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
  1021
50
239120c68187 Added classes with examples and example viewers
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 49
diff changeset
  1022
        crToDestroy := cr.
239120c68187 Added classes with examples and example viewers
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 49
diff changeset
  1023
        surfaceToDestroy := cr surface.
239120c68187 Added classes with examples and example viewers
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 49
diff changeset
  1024
        cr := nil.
239120c68187 Added classes with examples and example viewers
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 49
diff changeset
  1025
        crToDestroy release.
239120c68187 Added classes with examples and example viewers
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 49
diff changeset
  1026
        surfaceToDestroy release.
74
94902e358396 Oops, fixed slip in CairoGraphicsContext>>destroyCR
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 72
diff changeset
  1027
        device isWindowsPlatform ifTrue:[
94902e358396 Oops, fixed slip in CairoGraphicsContext>>destroyCR
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 72
diff changeset
  1028
            device dcUnlockForGC: gcId.
94902e358396 Oops, fixed slip in CairoGraphicsContext>>destroyCR
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 72
diff changeset
  1029
        ].
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1030
        wasBlocked ifFalse:[
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1031
            OperatingSystem unblockInterrupts.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1032
        ]    
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1033
    ].
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1034
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1035
    "Created: / 12-02-2016 / 16:59:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1036
    "Modified (format): / 02-04-2016 / 16:07:22 / jv"
74
94902e358396 Oops, fixed slip in CairoGraphicsContext>>destroyCR
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 72
diff changeset
  1037
    "Modified: / 04-04-2016 / 18:45:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1038
!
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1039
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1040
destroyGC
60
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1041
    drawableId notNil ifTrue:[
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1042
        Logger debug: 'Destroying GC/CR for drawable %1' with: drawableId.
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1043
    ].
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1044
    self destroyCR.
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1045
    super destroyGC
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1046
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1047
    "Created: / 12-02-2016 / 17:01:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
60
9bc47734215d CairoGraphicsContext: fixed finalization
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 57
diff changeset
  1048
    "Modified: / 03-03-2016 / 23:52:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1049
!
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1050
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1051
initCR
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1052
    | view f |
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1053
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1054
    gcId isNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1055
        self initGC.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1056
    ].
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1057
    cr isNil ifTrue:[ 
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1058
        self createCR.
85
ac8d41172b87 Fixed `CairoGraphicsContext >> #initCR` and `#createGC` to work with recent `stx:libvuew`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 78
diff changeset
  1059
        "/ Need to re-register for we need a new executor
ac8d41172b87 Fixed `CairoGraphicsContext >> #initCR` and `#createGC` to work with recent `stx:libvuew`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 78
diff changeset
  1060
        "/ with Cairo graphics context.
86
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
  1061
        device graphicsContexts registerChange:self.  
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1062
    ].
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1063
    device isWindowsPlatform ifTrue:[
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1064
        view := cr surface view.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1065
        view notNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1066
            view addDependent: self.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1067
            view container notNil ifTrue:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1068
                view container addDependent: self.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1069
            ].
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1070
        ].
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1071
    ].
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1072
46
e624554ca9a3 CairoGraphicsContext: fixed drawing/filling of lines and rectangles to match DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 45
diff changeset
  1073
    cr antialias: CAIRO_ANTIALIAS_NONE.
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1074
    cr lineWidth: (lineWidth == 0 ifTrue:[ 1 ] ifFalse:[ lineWidth ]).
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1075
    cr source: paint.
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1076
    cr matrixReset.
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
  1077
    self transformation: transformation.
70
4f58f5ed77b3 Added support for clipping
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 65
diff changeset
  1078
    self clippingBounds: clipRect.
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1079
    f := font.
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1080
    font := nil.
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1081
    self basicFont: f.
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1082
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1083
    "Created: / 18-02-2016 / 22:48:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1084
    "Modified: / 29-03-2016 / 23:57:30 / jv"
86
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
  1085
    "Modified: / 17-07-2018 / 19:48:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
41
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1086
!
17bc740cbc2a Fixed (lazy) initialization of CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 40
diff changeset
  1087
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1088
releaseCR
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1089
    self destroyCR
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1090
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1091
    "Created: / 12-02-2016 / 17:02:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1092
!
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1093
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1094
releaseGC
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1095
    "destroy the associated device GC resource - can be done to be nice to the
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1096
     display if you know that you are done with a drawable."
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1097
86
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
  1098
    [
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
  1099
        self releaseCR.
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
  1100
        super releaseGC.
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
  1101
    ] valueUninterruptably
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1102
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 34
diff changeset
  1103
    "Created: / 12-02-2016 / 17:03:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
86
e434bd07e403 Refactored `CairoGraphicsContext` finalization to avoid code duplication
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 85
diff changeset
  1104
    "Modified: / 17-07-2018 / 22:29:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
30
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1105
! !
c8fe298c8cc7 GraphicsContext refactoring (part 1)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
  1106
49
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1107
!CairoGraphicsContext methodsFor:'private'!
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1108
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1109
deviceCoordinatesDo: aBlock
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1110
    "Evaluate a block using device coordinates (device 
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1111
     space using Cairo terminology)"
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1112
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1113
    | savedTransformation |
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1114
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1115
    savedTransformation := transformation.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1116
    self transformation: nil.
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1117
    aBlock ensure:[ self transformation: savedTransformation ].
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1118
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1119
    "Created: / 26-02-2016 / 09:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
64
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1120
!
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1121
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1122
maskSet
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1123
    "Either mask or markOrigin changed. Update Cairo's source pattern"
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1124
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1125
    | maskImage w h maskSurface maskPattern sourceSurface sourceContext sourcePattern |
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1126
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1127
    mask isNil ifTrue:[ 
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1128
        cr source: paint.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1129
        ^ self.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1130
    ].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1131
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1132
    maskImage := mask asImage.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1133
    w := maskImage width.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1134
    h := maskImage height.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1135
    [
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1136
        sourceSurface := Cairo::Surface newImageWithFormat: CAIRO_FORMAT_ARGB32 width: w height: h similarTo: cr surface.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1137
        maskImage depth == 1 ifTrue:[
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1138
            maskSurface := maskImage asSurfaceWithFormat: CAIRO_FORMAT_A1 similarTo: sourceSurface.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1139
            maskPattern := Cairo::Pattern surface: maskSurface.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1140
            maskPattern extend: CAIRO_EXTEND_REPEAT.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1141
        ] ifFalse:[ 
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1142
            self error: 'Not yet supported'
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1143
        ].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1144
        sourceContext := sourceSurface cairo.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1145
        maskOrigin notNil ifTrue:[ 
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1146
            maskPattern matrix: (Cairo::Matrix translate: maskOrigin negated).
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1147
        ].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1148
        sourceContext source: cr source.               
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1149
        sourceContext mask: maskPattern.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1150
    ] ensure:[
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1151
        sourceContext notNil ifTrue:[sourceContext release].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1152
        maskPattern notNil ifTrue:[maskPattern release].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1153
        maskSurface notNil ifTrue:[maskSurface release].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1154
    ].
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1155
    sourcePattern := Cairo::Pattern surface: sourceSurface.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1156
    sourcePattern extend: CAIRO_EXTEND_REPEAT.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1157
    cr source: sourcePattern.
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1158
6e9458bb0697 CairoGraphicsContext: Added support for #mask: and #maskOrigin:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 62
diff changeset
  1159
    "Created: / 08-03-2016 / 21:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
72
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1160
!
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1161
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1162
subViewChangedSizeOrOrigin
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1163
    "Internal. Called whenever one of the owner's
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1164
     subview changes size or origin (i.e., when moved)    
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1165
     See SimpleView>>pixelOrigin:extent:.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1166
     Can be used to adjust internal state."
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1167
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1168
    device isX11Platform ifFalse:[ 
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1169
        self destroyGC.
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1170
    ].
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1171
    "/ Nothing by default
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1172
3eabcca278cd Cairo context and surface management for CairoGraphicsContext reworked to work under Win32
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 70
diff changeset
  1173
    "Created: / 02-04-2016 / 16:04:55 / jv"
49
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1174
! !
5218b606b6cf DeviceGraphicsContext: fixed routines using device coordinates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 48
diff changeset
  1175
36
9b680e54aa94 Take a step back: separate Cairo's GraphicsContext (cairo_t) and Smalltalk/X's graphics context
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 35
diff changeset
  1176
!CairoGraphicsContext class methodsFor:'documentation'!
7
392289f92fab - DLL path is set automatically.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6
diff changeset
  1177
392289f92fab - DLL path is set automatically.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6
diff changeset
  1178
version
392289f92fab - DLL path is set automatically.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 6
diff changeset
  1179
    ^'$Id$'
11
fdc697f4f190 - Cairo::SvgVersion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
  1180
!
fdc697f4f190 - Cairo::SvgVersion
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 10
diff changeset
  1181
23
38ee47dbd976 Added version_HG to make Mercurial happy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20
diff changeset
  1182
version_HG
38ee47dbd976 Added version_HG to make Mercurial happy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20
diff changeset
  1183
    ^ '$Changeset: <not expanded> $'
65
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
  1184
! !
dcb2eb06e759 Issue #1: Adjust coordinates for lines/rectangles when drawing using through CairoGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 64
diff changeset
  1185