Cairo__ClockView.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 12 Feb 2016 16:36:39 +0000
changeset 35 395689a88b32
parent 31 26070c1e480e
child 36 9b680e54aa94
permissions -rw-r--r--
Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext This allows using Cairo's GraphicsContext in views as *the* graphics context so the whole view is then rendered by Cairo.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/libcairo' }"
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     2
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     3
"{ NameSpace: Cairo }"
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     4
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     5
SimpleView subclass:#ClockView
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
     6
	instanceVariableNames:'updater'
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     7
	classVariableNames:''
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     8
	poolDictionaries:''
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
     9
	category:'Cairo-Examples'
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    10
!
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    11
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    12
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    13
!ClockView methodsFor:'accessing-dimensions'!
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    14
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    15
preferredExtent
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    16
18
fae6edf1bdbd - Cairo::TextExampleView
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17
diff changeset
    17
    ^400 @ 400
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    18
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    19
    "Created: / 17-06-2012 / 22:37:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    20
! !
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    21
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    22
!ClockView methodsFor:'event handling'!
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    23
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    24
destroy
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    25
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    26
    updater notNil ifTrue:[updater terminate].
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    27
    super destroy.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    28
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    29
    "Created: / 17-06-2012 / 22:41:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    30
!
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    31
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    32
mapped
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    33
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    34
    updater isNil ifTrue:[
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    35
        updater := [ [ Delay waitForSeconds: 1. self invalidate ] loop ] newProcess.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    36
        updater resume.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    37
    ].
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    38
    super mapped.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    39
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    40
    "Created: / 17-06-2012 / 22:40:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    41
    "Modified: / 12-02-2016 / 16:40:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    42
!
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    43
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    44
unmapped
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    45
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    46
    updater notNil ifTrue:[updater terminate].
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    47
    super unmapped.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    48
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    49
    "Created: / 17-06-2012 / 22:42:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    50
    "Modified: / 12-02-2016 / 16:40:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    51
! !
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    52
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    53
!ClockView methodsFor:'initialization & release'!
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    54
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    55
initializeForDevice:aDevice
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    56
    "allocate a GraphicsContext for a device"
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    57
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    58
    aDevice notNil ifTrue:[
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    59
        gc := Cairo::GraphicsContext onDevice: aDevice  
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    60
    ] ifFalse:[
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    61
        "should not be reached"
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    62
        GraphicsMedium superclass == DeviceGraphicsContext ifTrue:[
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    63
            gc := self.
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    64
            super device:aDevice.
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    65
        ].
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    66
    ].
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    67
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    68
    self initialize.
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    69
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
    70
    "Created: / 12-02-2016 / 16:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    71
! !
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    72
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
!ClockView methodsFor:'redrawing'!
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
redraw
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 28
diff changeset
    76
    self redrawWithCairoBuffered
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    78
    "Created: / 16-06-2012 / 23:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 28
diff changeset
    79
    "Modified: / 28-12-2014 / 22:17:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    80
!
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    81
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    82
redrawX: x y: y width: w height: h
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 28
diff changeset
    83
    self redrawWithCairoBufferedX: x y: y width: w height: h
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    84
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    85
    "Created: / 17-06-2012 / 21:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 28
diff changeset
    86
    "Modified: / 28-12-2014 / 22:18:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    87
! !
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    88
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    89
!ClockView methodsFor:'redrawing - cairo'!
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    90
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    91
redrawWithCairo: cr
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    92
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    93
    |   time hours mins secs |
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    94
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    95
    "/ scale to unit square and translate (0, 0) to be (0.5, 0.5), i.e.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
    96
    "/ the center of the window
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    97
    cr save.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
    98
    cr scale: self extent.
31
26070c1e480e GraphicsContext refactoring (part 2)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 29
diff changeset
    99
    cr translateBy: (0.5 @ 0.5).
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   100
    cr lineWidth: 0.05.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   101
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   102
    cr paint: (Color red: 33 green: 61 blue: 11).
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   103
    cr paint.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   104
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   105
    cr arcX: 0 y: 0 radius: 0.42 from: 0 to: (2 * (Float pi)).
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   106
    cr paint: Color white.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   107
    cr fillAndPreserve.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   108
    cr paint: Color black.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   109
    cr strokeAndPreserve.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   110
    cr clip.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   111
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   112
    "Now, clock ticks"
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   113
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   114
    0 to: 11 do:[:i|
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   115
        | inset |
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   116
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   117
        inset := 0.05.
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   118
        cr save.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   119
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 28
diff changeset
   120
        cr lineCap: Cairo::LineCap CAIRO_LINE_CAP_ROUND.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   121
        (i \\ 3) ~~ 0 ifTrue:[
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   122
            inset := inset * 0.8.
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   123
            cr lineWidth: 0.03.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   124
        ].
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   125
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   126
        cr moveToX: (0.42 - inset) * ( i * (Float pi / 6)) cos
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   127
                 y: (0.42 - inset) * ( i * (Float pi / 6)) sin.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   128
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   129
        cr lineToX: (0.42 ) * ( i * (Float pi / 6)) cos
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   130
                 y: (0.42 ) * ( i * (Float pi / 6)) sin.
16
a810555a635c - Cairo::Surface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   131
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   132
        cr stroke.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   133
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   134
        cr restore.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   135
    ].
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   136
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   137
    "/ Not, the current time"
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   138
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   139
    time := Time now.
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   140
    hours := (time hours > 12 ifTrue:[time hours - 12] ifFalse:[time hours])
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   141
                * (Float pi / 6).
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   142
    mins := time minutes * (Float pi / 30).
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   143
    secs := time seconds * (Float pi / 30).
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   144
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   145
    cr save.
29
6ba06265e543 Bindinge updated to recent Cairo version.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 28
diff changeset
   146
    cr lineCap: Cairo::LineCap CAIRO_LINE_CAP_ROUND.
16
a810555a635c - Cairo::Surface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   147
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   148
    "/ draw the seconds hand
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   149
    cr save.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   150
    cr lineWidth: 0.016.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   151
    cr paint: ((Color red: 70 green: 70 blue: 70) alpha: 0.8).
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   152
    cr moveToX: 0.0 y: 0.0.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   153
    cr lineToX: (secs sin * (0.42 * 0.9))
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   154
             y: (-1 *  (secs cos * (0.42 * 0.9))).
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   155
    cr stroke.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   156
    cr restore.
16
a810555a635c - Cairo::Surface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   157
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   158
    "/ draw th minutes
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   159
    cr paint: ((Color red: 11 green: 33 blue: 61) alpha: 0.7).
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   160
    cr moveToX: 0.0 y: 0.0.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   161
    cr lineToX: ((mins + (secs / 60)) sin * (0.42 * 0.8))
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   162
             y: (-1 * ((mins + (secs / 60)) cos * (0.42 * 0.8))).
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   163
    cr stroke.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   164
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   165
    "/ draw the hours hand
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   166
    cr paint: ((Color red: 33 green: 61 blue: 11) alpha: 0.6).
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   167
    cr moveToX: 0.0 y: 0.0.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   168
    cr lineToX: ((hours + (mins / 12)) sin * (0.42 * 0.5))
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   169
             y: (-1 * ((hours + (mins / 12)) cos * (0.42 * 0.5))).
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   170
    cr stroke.
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   171
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   172
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   173
    cr restore.
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   174
    cr arcX: 0 y: 0 radius: 0.01 from: 0 to: (2 * (Float pi)).
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   175
    cr fill.
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   176
16
a810555a635c - Cairo::Surface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   177
a810555a635c - Cairo::Surface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   178
17
5f943c05c028 - Cairo::GraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16
diff changeset
   179
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   180
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   181
    cr restore.
16
a810555a635c - Cairo::Surface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
   182
28
1bd3d147cd77 Added utility methods to SimpleView...
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 26
diff changeset
   183
    "Created: / 27-12-2014 / 00:00:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
35
395689a88b32 Make Cairo::GraphicsContext to inherit from DeviceGraphicsContext
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 31
diff changeset
   184
    "Modified: / 12-02-2016 / 16:45:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   185
! !
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   186
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   187
!ClockView class methodsFor:'documentation'!
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   188
23
38ee47dbd976 Added version_HG to make Mercurial happy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18
diff changeset
   189
version_HG
38ee47dbd976 Added version_HG to make Mercurial happy
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 18
diff changeset
   190
    ^ '$Changeset: <not expanded> $'
15
c1db2c8aa2ed - stx_goodies_libcairo
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   191
! !
26
7f07a8c31e6d Fixed flickring of Cairo::ClockView by rendering into an off-screen image.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 24
diff changeset
   192