ImgEditV.st
author tz
Thu, 29 Jan 1998 19:44:04 +0100
changeset 526 7a4749b25748
parent 386 71766a2845ab
permissions -rw-r--r--
style revised
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
386
71766a2845ab intitial checkin
tz
parents:
diff changeset
     1
"
71766a2845ab intitial checkin
tz
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
71766a2845ab intitial checkin
tz
parents:
diff changeset
     3
	      All Rights Reserved
71766a2845ab intitial checkin
tz
parents:
diff changeset
     4
71766a2845ab intitial checkin
tz
parents:
diff changeset
     5
 This software is furnished under a license and may be used
71766a2845ab intitial checkin
tz
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
71766a2845ab intitial checkin
tz
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
71766a2845ab intitial checkin
tz
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
71766a2845ab intitial checkin
tz
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
71766a2845ab intitial checkin
tz
parents:
diff changeset
    10
 hereby transferred.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    11
"
71766a2845ab intitial checkin
tz
parents:
diff changeset
    12
71766a2845ab intitial checkin
tz
parents:
diff changeset
    13
ImageView subclass:#ImageEditView
71766a2845ab intitial checkin
tz
parents:
diff changeset
    14
	instanceVariableNames:'magnification gridMagnification selectColors imageReaderClass
71766a2845ab intitial checkin
tz
parents:
diff changeset
    15
		resourceClass resourceSelector editMode mouseKeyColorMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
    16
		undoImage modified coordInfoBlock'
71766a2845ab intitial checkin
tz
parents:
diff changeset
    17
	classVariableNames:'Clipboard'
71766a2845ab intitial checkin
tz
parents:
diff changeset
    18
	poolDictionaries:''
71766a2845ab intitial checkin
tz
parents:
diff changeset
    19
	category:'Views-Misc'
71766a2845ab intitial checkin
tz
parents:
diff changeset
    20
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    21
71766a2845ab intitial checkin
tz
parents:
diff changeset
    22
!ImageEditView class methodsFor:'documentation'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    23
71766a2845ab intitial checkin
tz
parents:
diff changeset
    24
copyright
71766a2845ab intitial checkin
tz
parents:
diff changeset
    25
"
71766a2845ab intitial checkin
tz
parents:
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
71766a2845ab intitial checkin
tz
parents:
diff changeset
    27
	      All Rights Reserved
71766a2845ab intitial checkin
tz
parents:
diff changeset
    28
71766a2845ab intitial checkin
tz
parents:
diff changeset
    29
 This software is furnished under a license and may be used
71766a2845ab intitial checkin
tz
parents:
diff changeset
    30
 only in accordance with the terms of that license and with the
71766a2845ab intitial checkin
tz
parents:
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
71766a2845ab intitial checkin
tz
parents:
diff changeset
    32
 be provided or otherwise made available to, or used by, any
71766a2845ab intitial checkin
tz
parents:
diff changeset
    33
 other person.  No title to or ownership of the software is
71766a2845ab intitial checkin
tz
parents:
diff changeset
    34
 hereby transferred.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    35
"
71766a2845ab intitial checkin
tz
parents:
diff changeset
    36
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    37
71766a2845ab intitial checkin
tz
parents:
diff changeset
    38
documentation
71766a2845ab intitial checkin
tz
parents:
diff changeset
    39
"
71766a2845ab intitial checkin
tz
parents:
diff changeset
    40
    This View will eventually be able to edit bitmap images.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    41
    For now, it is not.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    42
71766a2845ab intitial checkin
tz
parents:
diff changeset
    43
    [author:]
71766a2845ab intitial checkin
tz
parents:
diff changeset
    44
        Claus Gittinger
71766a2845ab intitial checkin
tz
parents:
diff changeset
    45
71766a2845ab intitial checkin
tz
parents:
diff changeset
    46
    [see also:]
71766a2845ab intitial checkin
tz
parents:
diff changeset
    47
        Image Form
71766a2845ab intitial checkin
tz
parents:
diff changeset
    48
71766a2845ab intitial checkin
tz
parents:
diff changeset
    49
    [start with:]
71766a2845ab intitial checkin
tz
parents:
diff changeset
    50
        ImageEditView openOn:'bitmaps/gifImages/garfield.gif'
71766a2845ab intitial checkin
tz
parents:
diff changeset
    51
        ImageEditView openOnImage:(Image fromFile:'bitmaps/gifImages/garfield.gif')
71766a2845ab intitial checkin
tz
parents:
diff changeset
    52
"
71766a2845ab intitial checkin
tz
parents:
diff changeset
    53
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
    54
71766a2845ab intitial checkin
tz
parents:
diff changeset
    55
!ImageEditView methodsFor:'accessing'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    56
71766a2845ab intitial checkin
tz
parents:
diff changeset
    57
coordInfoBlock: aBlock
71766a2845ab intitial checkin
tz
parents:
diff changeset
    58
71766a2845ab intitial checkin
tz
parents:
diff changeset
    59
    coordInfoBlock := aBlock
71766a2845ab intitial checkin
tz
parents:
diff changeset
    60
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    61
71766a2845ab intitial checkin
tz
parents:
diff changeset
    62
gridMagnification: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
    63
71766a2845ab intitial checkin
tz
parents:
diff changeset
    64
    gridMagnification := aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
    65
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    66
71766a2845ab intitial checkin
tz
parents:
diff changeset
    67
imageReaderClass
71766a2845ab intitial checkin
tz
parents:
diff changeset
    68
71766a2845ab intitial checkin
tz
parents:
diff changeset
    69
    ^imageReaderClass
71766a2845ab intitial checkin
tz
parents:
diff changeset
    70
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    71
71766a2845ab intitial checkin
tz
parents:
diff changeset
    72
magnification
71766a2845ab intitial checkin
tz
parents:
diff changeset
    73
71766a2845ab intitial checkin
tz
parents:
diff changeset
    74
    ^magnification
71766a2845ab intitial checkin
tz
parents:
diff changeset
    75
71766a2845ab intitial checkin
tz
parents:
diff changeset
    76
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    77
71766a2845ab intitial checkin
tz
parents:
diff changeset
    78
magnification:aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
    79
71766a2845ab intitial checkin
tz
parents:
diff changeset
    80
    magnification ~= aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
    81
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
    82
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
    83
        magnification := aPoint asPoint.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    84
        self scrollToTopLeft.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    85
        self contentsChanged.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    86
        self invalidate.
71766a2845ab intitial checkin
tz
parents:
diff changeset
    87
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
    88
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    89
71766a2845ab intitial checkin
tz
parents:
diff changeset
    90
resourceClass
71766a2845ab intitial checkin
tz
parents:
diff changeset
    91
71766a2845ab intitial checkin
tz
parents:
diff changeset
    92
    ^resourceClass
71766a2845ab intitial checkin
tz
parents:
diff changeset
    93
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
    94
71766a2845ab intitial checkin
tz
parents:
diff changeset
    95
resourceClass: aClassOrSymbol
71766a2845ab intitial checkin
tz
parents:
diff changeset
    96
71766a2845ab intitial checkin
tz
parents:
diff changeset
    97
    resourceClass := aClassOrSymbol isClass ifTrue: [aClassOrSymbol name] ifFalse: [aClassOrSymbol asSymbol].
71766a2845ab intitial checkin
tz
parents:
diff changeset
    98
71766a2845ab intitial checkin
tz
parents:
diff changeset
    99
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   100
71766a2845ab intitial checkin
tz
parents:
diff changeset
   101
resourceMessage
71766a2845ab intitial checkin
tz
parents:
diff changeset
   102
71766a2845ab intitial checkin
tz
parents:
diff changeset
   103
    ^resourceClass, ' ', resourceSelector
71766a2845ab intitial checkin
tz
parents:
diff changeset
   104
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   105
71766a2845ab intitial checkin
tz
parents:
diff changeset
   106
resourceMessage: aMessage
71766a2845ab intitial checkin
tz
parents:
diff changeset
   107
71766a2845ab intitial checkin
tz
parents:
diff changeset
   108
    (aMessage notNil and: [aMessage trimBlanks size > 0])
71766a2845ab intitial checkin
tz
parents:
diff changeset
   109
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   110
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   111
        resourceClass := aMessage readStream nextWord asSymbol.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   112
        resourceSelector := aMessage reversed readStream nextWord reverse asSymbol.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   113
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   114
    ifFalse:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   115
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   116
        ^nil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   117
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   118
71766a2845ab intitial checkin
tz
parents:
diff changeset
   119
    ^self resourceClass: resourceClass selector: resourceSelector
71766a2845ab intitial checkin
tz
parents:
diff changeset
   120
71766a2845ab intitial checkin
tz
parents:
diff changeset
   121
   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   122
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   123
71766a2845ab intitial checkin
tz
parents:
diff changeset
   124
resourceSelector
71766a2845ab intitial checkin
tz
parents:
diff changeset
   125
71766a2845ab intitial checkin
tz
parents:
diff changeset
   126
    ^resourceSelector
71766a2845ab intitial checkin
tz
parents:
diff changeset
   127
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   128
71766a2845ab intitial checkin
tz
parents:
diff changeset
   129
resourceSelector: aStringOrSymbol
71766a2845ab intitial checkin
tz
parents:
diff changeset
   130
71766a2845ab intitial checkin
tz
parents:
diff changeset
   131
    resourceSelector := aStringOrSymbol asSymbol
71766a2845ab intitial checkin
tz
parents:
diff changeset
   132
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   133
71766a2845ab intitial checkin
tz
parents:
diff changeset
   134
selectedColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   135
71766a2845ab intitial checkin
tz
parents:
diff changeset
   136
   ^selectColors at: mouseKeyColorMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
   137
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   138
71766a2845ab intitial checkin
tz
parents:
diff changeset
   139
selectedColor: aColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   140
71766a2845ab intitial checkin
tz
parents:
diff changeset
   141
    selectColors at: mouseKeyColorMode put: aColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   142
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   143
71766a2845ab intitial checkin
tz
parents:
diff changeset
   144
!ImageEditView methodsFor:'drawing'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   145
71766a2845ab intitial checkin
tz
parents:
diff changeset
   146
redrawImageX:x y:y width:w height:h
71766a2845ab intitial checkin
tz
parents:
diff changeset
   147
    |ih iw dotW dotH minX maxX minY maxY color last lastY runW x0 xI yI maskColor|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   148
71766a2845ab intitial checkin
tz
parents:
diff changeset
   149
    ih := image height.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   150
    iw := image width.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   151
    dotW := magnification x.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   152
    dotH := magnification y.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   153
71766a2845ab intitial checkin
tz
parents:
diff changeset
   154
    minX := (x // dotW).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   155
    minX >= iw ifTrue:[minX := iw - 1].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   156
    minY := (y // dotH).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   157
    minY >= ih ifTrue:[minY := ih - 1].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   158
    maxX := (x + w) // dotW + 1.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   159
    maxX > iw ifTrue:[maxX := iw].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   160
    maxY := (y + h) // dotH + 1.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   161
    maxY > ih ifTrue:[maxY := ih].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   162
71766a2845ab intitial checkin
tz
parents:
diff changeset
   163
    lastY := -1.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   164
71766a2845ab intitial checkin
tz
parents:
diff changeset
   165
    x0 := minX.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   166
    runW := 0.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   167
    maskColor := false.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   168
    image colorsFromX:minX y:minY toX:maxX-1 y:maxY-1 do:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   169
    [:xx :yy :color|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   170
71766a2845ab intitial checkin
tz
parents:
diff changeset
   171
        yy ~~ lastY ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   172
        [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   173
            runW ~~ 0 ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   174
            [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   175
                |origin|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   176
                origin := (x0 * dotW + margin)@(lastY * dotH + margin).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   177
                self fillRectangle: (origin extent: (runW@dotH)).                    
71766a2845ab intitial checkin
tz
parents:
diff changeset
   178
                0 to: runW by: dotW do: [:xxx| self drawFrameAt: ((origin x + xxx) @origin y)].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   179
                maskColor ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   180
                [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   181
                    self drawMaskPointAt: origin
71766a2845ab intitial checkin
tz
parents:
diff changeset
   182
                ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   183
                runW := 0.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   184
            ]. 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   185
            x0 := xx.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   186
            lastY := yy.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   187
        ]. 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   188
71766a2845ab intitial checkin
tz
parents:
diff changeset
   189
        color ~~ last ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   190
        [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   191
            runW ~~ 0 ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   192
            [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   193
                |origin|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   194
                origin := (x0 * dotW + margin)@(yy * dotH + margin).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   195
                self fillRectangle: (origin extent: (runW@dotH)).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   196
                0 to: runW by: dotW do: [:xxx| self drawFrameAt: ((origin x + xxx) @origin y)].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   197
                maskColor ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   198
                [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   199
                    self drawMaskPointAt: origin
71766a2845ab intitial checkin
tz
parents:
diff changeset
   200
                ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   201
                runW := 0.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   202
            ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   203
71766a2845ab intitial checkin
tz
parents:
diff changeset
   204
            self paint: (last := color).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   205
            image mask notNil ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   206
            [  
71766a2845ab intitial checkin
tz
parents:
diff changeset
   207
                maskColor := false.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   208
                (image mask colorAt: xx@yy) = Color black ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   209
                [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   210
                    self paint: (last := self viewBackground).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   211
                    maskColor := true.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   212
                ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   213
                last := nil.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   214
            ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   215
            runW := 0.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   216
            x0 := xx.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   217
        ].  
71766a2845ab intitial checkin
tz
parents:
diff changeset
   218
        runW := runW + dotW
71766a2845ab intitial checkin
tz
parents:
diff changeset
   219
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   220
    runW ~~ 0 ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   221
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   222
        |origin|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   223
        origin := (x0 * dotW + margin)@(lastY * dotH + margin).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   224
        self fillRectangle: (origin extent: runW@dotH).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   225
        0 to: runW by: dotW do: [:xxx| self drawFrameAt: ((origin x + xxx) @origin y)].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   226
        maskColor ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   227
        [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   228
            self drawMaskPointAt: origin.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   229
        ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   230
        runW := 0.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   231
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   232
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   233
71766a2845ab intitial checkin
tz
parents:
diff changeset
   234
redrawX:x y:y width:w height:h
71766a2845ab intitial checkin
tz
parents:
diff changeset
   235
    |ih iw xI yI|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   236
71766a2845ab intitial checkin
tz
parents:
diff changeset
   237
    image isNil ifTrue:[^self].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   238
71766a2845ab intitial checkin
tz
parents:
diff changeset
   239
    magnification = (1@1) ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   240
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   241
        super redrawX:x y:y width:w height:h.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   242
        self drawFrame.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   243
        ^ self
71766a2845ab intitial checkin
tz
parents:
diff changeset
   244
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   245
    self clippingRectangle: (x@y extent: w@h). 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   246
71766a2845ab intitial checkin
tz
parents:
diff changeset
   247
    self redrawImageX:x y:y width:w height:h.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   248
71766a2845ab intitial checkin
tz
parents:
diff changeset
   249
    "/ right of image ?
71766a2845ab intitial checkin
tz
parents:
diff changeset
   250
    adjust == #center ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   251
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   252
        xI := (width - (margin * 2) - ih) // 2.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   253
        yI := (height - (margin * 2) - iw) // 2.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   254
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   255
    ifFalse:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   256
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   257
        xI := yI := margin
71766a2845ab intitial checkin
tz
parents:
diff changeset
   258
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   259
    (x + w - 1) > (xI + (magnification x * image width)) ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   260
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   261
        self clearRectangleX:(xI + (magnification x * image width))
71766a2845ab intitial checkin
tz
parents:
diff changeset
   262
                           y:y
71766a2845ab intitial checkin
tz
parents:
diff changeset
   263
                       width:(x + w - (magnification x * image width) - xI)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   264
                      height:h
71766a2845ab intitial checkin
tz
parents:
diff changeset
   265
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   266
    (y + h - 1) > (yI + (magnification y * image height)) ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   267
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   268
        self clearRectangleX:margin
71766a2845ab intitial checkin
tz
parents:
diff changeset
   269
                           y:(yI + (magnification y * image height))
71766a2845ab intitial checkin
tz
parents:
diff changeset
   270
                       width:w
71766a2845ab intitial checkin
tz
parents:
diff changeset
   271
                      height:(y + h - (magnification y * image height) - yI)  
71766a2845ab intitial checkin
tz
parents:
diff changeset
   272
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   273
    self drawFrame.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   274
    self clippingRectangle: nil.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   275
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   276
71766a2845ab intitial checkin
tz
parents:
diff changeset
   277
!ImageEditView methodsFor:'edit modes'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   278
71766a2845ab intitial checkin
tz
parents:
diff changeset
   279
editMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
   280
71766a2845ab intitial checkin
tz
parents:
diff changeset
   281
    editMode isNil ifTrue: [editMode := 'point'].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   282
    ^editMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
   283
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   284
71766a2845ab intitial checkin
tz
parents:
diff changeset
   285
editMode:aMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
   286
71766a2845ab intitial checkin
tz
parents:
diff changeset
   287
    editMode := aMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
   288
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   289
71766a2845ab intitial checkin
tz
parents:
diff changeset
   290
mouseKeyColorMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
   291
71766a2845ab intitial checkin
tz
parents:
diff changeset
   292
    ^mouseKeyColorMode printString
71766a2845ab intitial checkin
tz
parents:
diff changeset
   293
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   294
71766a2845ab intitial checkin
tz
parents:
diff changeset
   295
mouseKeyColorMode:aMode
71766a2845ab intitial checkin
tz
parents:
diff changeset
   296
71766a2845ab intitial checkin
tz
parents:
diff changeset
   297
    mouseKeyColorMode := aMode asInteger
71766a2845ab intitial checkin
tz
parents:
diff changeset
   298
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   299
71766a2845ab intitial checkin
tz
parents:
diff changeset
   300
!ImageEditView methodsFor:'event handling'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   301
71766a2845ab intitial checkin
tz
parents:
diff changeset
   302
buttonMotion:state x:x y:y
71766a2845ab intitial checkin
tz
parents:
diff changeset
   303
71766a2845ab intitial checkin
tz
parents:
diff changeset
   304
    self selectedColor notNil & image notNil & (self imageContainsPoint: x@y) & (editMode = 'point')
71766a2845ab intitial checkin
tz
parents:
diff changeset
   305
        ifTrue: [^self pointAt: x@y].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   306
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   307
71766a2845ab intitial checkin
tz
parents:
diff changeset
   308
buttonPress:button x:x y:y
71766a2845ab intitial checkin
tz
parents:
diff changeset
   309
71766a2845ab intitial checkin
tz
parents:
diff changeset
   310
    self selectedColor notNil & image notNil & (self imageContainsPoint: x@y)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   311
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   312
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   313
        undoImage := image copy.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   314
        mouseKeyColorMode := button.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   315
        (editMode = 'point')   ifTrue: [self pointAt: x@y].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   316
        (editMode = 'replace') ifTrue: [self replaceAt: x@y].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   317
        (editMode = 'paste')   ifTrue: [self pasteAt: x@y].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   318
        (editMode = 'box') | (editMode = 'copy') ifTrue: [self boxAt: x@y].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   319
        ^self
71766a2845ab intitial checkin
tz
parents:
diff changeset
   320
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   321
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   322
71766a2845ab intitial checkin
tz
parents:
diff changeset
   323
!ImageEditView methodsFor:'image drawing'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   324
71766a2845ab intitial checkin
tz
parents:
diff changeset
   325
boxAt: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
   326
71766a2845ab intitial checkin
tz
parents:
diff changeset
   327
    |firstPoint currentPoint lastCurrentPoint currentExtent imageFirstPoint imageExtent|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   328
71766a2845ab intitial checkin
tz
parents:
diff changeset
   329
    firstPoint := lastCurrentPoint := aPoint//magnification*magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   330
    [Display anyButtonPressed]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   331
    whileTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   332
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   333
        currentPoint := (0@0) max: (image extent * magnification min: (self translation negated + (device translatePoint: self sensor mousePoint from:device rootView id to:self id))).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   334
        currentPoint := currentPoint//magnification*magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   335
        currentExtent := (firstPoint - currentPoint) abs.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   336
        currentPoint ~= lastCurrentPoint ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   337
        [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   338
            self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   339
            editMode = 'copy'
71766a2845ab intitial checkin
tz
parents:
diff changeset
   340
            ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   341
            [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   342
                self xoring: [self fillRectangle: ((firstPoint min: currentPoint) + 1 extent: currentExtent - 1)]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   343
            ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   344
            editMode = 'box'
71766a2845ab intitial checkin
tz
parents:
diff changeset
   345
            ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   346
            [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   347
                self selectedColor ~= Color noColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   348
                    ifTrue: [self paint: self selectedColor]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   349
                    ifFalse: [self paint: self viewBackground].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   350
                self fillRectangle: ((firstPoint min: currentPoint) + 1 extent: currentExtent - 1)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   351
            ]. 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   352
        ]. 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   353
        self drawLabel: currentPoint//magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   354
        lastCurrentPoint := currentPoint.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   355
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   356
71766a2845ab intitial checkin
tz
parents:
diff changeset
   357
    imageFirstPoint := (firstPoint min: currentPoint)//magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   358
    imageExtent := currentExtent//magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   359
    editMode = 'box'
71766a2845ab intitial checkin
tz
parents:
diff changeset
   360
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   361
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   362
        self selectedColor ~= Color noColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   363
        ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   364
        [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   365
            image mask notNil ifTrue: [image mask fillRectangleX: imageFirstPoint x y: imageFirstPoint y width: imageExtent x height: imageExtent y with:Color white].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   366
            image fillRectangleX: imageFirstPoint x y: imageFirstPoint y width: imageExtent x height: imageExtent y with: self selectedColor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   367
            self paint: self selectedColor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   368
        ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   369
        ifFalse:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   370
        [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   371
            image fillRectangleX: imageFirstPoint x y: imageFirstPoint y width: imageExtent x height: imageExtent y with: ((image colorMap includes: Color black) ifTrue: [Color black] ifFalse: [image colorMap first]).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   372
            image mask notNil ifTrue: [image mask fillRectangleX: imageFirstPoint x y: imageFirstPoint y width: imageExtent x height: imageExtent y with: Color black].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   373
            self paint: self viewBackground.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   374
        ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   375
        image restored.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   376
        modified := true.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   377
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   378
    editMode = 'copy'
71766a2845ab intitial checkin
tz
parents:
diff changeset
   379
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   380
    [      
71766a2845ab intitial checkin
tz
parents:
diff changeset
   381
        Clipboard := image subImageIn: (imageFirstPoint extent: imageExtent)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   382
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   383
    self redraw: ((firstPoint min: currentPoint) - 1 extent: (firstPoint - currentPoint) abs + 2).    
71766a2845ab intitial checkin
tz
parents:
diff changeset
   384
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   385
71766a2845ab intitial checkin
tz
parents:
diff changeset
   386
pasteAt: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
   387
71766a2845ab intitial checkin
tz
parents:
diff changeset
   388
    Object errorSignal handle:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   389
    [:ex|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   390
        WarningBox warn: 'Pasting into this image failed!!'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   391
    ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   392
    do:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   393
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   394
        |imagePoint|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   395
        imagePoint := aPoint//magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   396
        image copyFrom: Clipboard x:0 y:0 toX: imagePoint x y: imagePoint y width: Clipboard width height: Clipboard height.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   397
        self redraw: (imagePoint * magnification extent: (Clipboard extent * magnification)).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   398
        self drawLabel: imagePoint.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   399
        image restored.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   400
        modified := true.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   401
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   402
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   403
71766a2845ab intitial checkin
tz
parents:
diff changeset
   404
pointAt: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
   405
71766a2845ab intitial checkin
tz
parents:
diff changeset
   406
    |imagePoint|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   407
    imagePoint := aPoint//magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   408
    self selectedColor ~= Color noColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   409
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   410
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   411
        image mask notNil ifTrue: [image mask colorAt: imagePoint put: Color white].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   412
        image colorAt: imagePoint put: self selectedColor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   413
        self paint: self selectedColor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   414
    ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   415
    ifFalse:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   416
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   417
        image colorAt: imagePoint put: ((image colorMap includes: Color black) ifTrue: [Color black] ifFalse: [image colorMap first]).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   418
        image mask notNil ifTrue: [image mask colorAt: imagePoint put: Color black].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   419
        self paint:self viewBackground.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   420
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   421
71766a2845ab intitial checkin
tz
parents:
diff changeset
   422
    self fillRectangle: (imagePoint * magnification + 1 extent: magnification).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   423
    self selectedColor = Color noColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   424
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   425
    [       
71766a2845ab intitial checkin
tz
parents:
diff changeset
   426
        self drawMaskPointAt: imagePoint * magnification + 1.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   427
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   428
    self drawFrameAt: aPoint.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   429
    self drawLabel: imagePoint.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   430
    image restored.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   431
    modified := true.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   432
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   433
71766a2845ab intitial checkin
tz
parents:
diff changeset
   434
replaceAt: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
   435
71766a2845ab intitial checkin
tz
parents:
diff changeset
   436
    |imagePoint|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   437
    imagePoint := aPoint//magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   438
    self selectedColor ~= Color noColor
71766a2845ab intitial checkin
tz
parents:
diff changeset
   439
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   440
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   441
        image mask notNil ifTrue: [image mask fillAround: imagePoint withColor: Color white].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   442
        image fillAround: imagePoint withColor: self selectedColor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   443
        self paint: self selectedColor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   444
    ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   445
    ifFalse:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   446
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   447
        image mask notNil ifTrue: [image mask fillAround: imagePoint withColor: Color black].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   448
        self paint:self viewBackground.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   449
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   450
    self drawLabel: imagePoint.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   451
    self invalidate.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   452
    image restored.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   453
    modified := true.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   454
71766a2845ab intitial checkin
tz
parents:
diff changeset
   455
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   456
71766a2845ab intitial checkin
tz
parents:
diff changeset
   457
undo
71766a2845ab intitial checkin
tz
parents:
diff changeset
   458
71766a2845ab intitial checkin
tz
parents:
diff changeset
   459
    undoImage notNil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   460
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   461
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   462
        modified := false.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   463
        self image: undoImage.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   464
        self invalidate
71766a2845ab intitial checkin
tz
parents:
diff changeset
   465
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   466
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   467
71766a2845ab intitial checkin
tz
parents:
diff changeset
   468
!ImageEditView methodsFor:'image editing'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   469
71766a2845ab intitial checkin
tz
parents:
diff changeset
   470
flipHorizontal
71766a2845ab intitial checkin
tz
parents:
diff changeset
   471
71766a2845ab intitial checkin
tz
parents:
diff changeset
   472
    self image: image flipHorizontal.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   473
71766a2845ab intitial checkin
tz
parents:
diff changeset
   474
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   475
71766a2845ab intitial checkin
tz
parents:
diff changeset
   476
flipVertical
71766a2845ab intitial checkin
tz
parents:
diff changeset
   477
71766a2845ab intitial checkin
tz
parents:
diff changeset
   478
    self image: image flipVertical.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   479
71766a2845ab intitial checkin
tz
parents:
diff changeset
   480
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   481
71766a2845ab intitial checkin
tz
parents:
diff changeset
   482
negativeImage
71766a2845ab intitial checkin
tz
parents:
diff changeset
   483
71766a2845ab intitial checkin
tz
parents:
diff changeset
   484
    self image: image negative.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   485
71766a2845ab intitial checkin
tz
parents:
diff changeset
   486
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   487
71766a2845ab intitial checkin
tz
parents:
diff changeset
   488
resizeImage
71766a2845ab intitial checkin
tz
parents:
diff changeset
   489
71766a2845ab intitial checkin
tz
parents:
diff changeset
   490
    |b newSize|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   491
71766a2845ab intitial checkin
tz
parents:
diff changeset
   492
    b := EnterBox new.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   493
    b title:'resize image'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   494
    b okText:'apply'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   495
    b abortText:'abort'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   496
    b initialText:image extent printString.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   497
    b showAtPointer.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   498
    (newSize := Object readFromString: b contents onError:nil) notNil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   499
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   500
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   501
        self image: (image magnifiedBy: newSize/image extent)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   502
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   503
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   504
71766a2845ab intitial checkin
tz
parents:
diff changeset
   505
rotateImage
71766a2845ab intitial checkin
tz
parents:
diff changeset
   506
71766a2845ab intitial checkin
tz
parents:
diff changeset
   507
    |b rotation|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   508
71766a2845ab intitial checkin
tz
parents:
diff changeset
   509
    b := EnterBox new.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   510
    b title:'rotate image'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   511
    b okText:'apply'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   512
    b abortText:'abort'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   513
    b initialText: '0'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   514
    b showAtPointer.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   515
    (rotation := Object readFromString: b contents onError:nil) notNil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   516
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   517
    [   Object errorSignal handle:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   518
        [:ex|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   519
            WarningBox warn: 'Image rotation failed.\' withCRs, 'An increase of image depth could help.'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   520
        ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   521
        do:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   522
        [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   523
            self image: (image hardRotated: rotation)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   524
        ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   525
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   526
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   527
71766a2845ab intitial checkin
tz
parents:
diff changeset
   528
!ImageEditView methodsFor:'image emphasis'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   529
71766a2845ab intitial checkin
tz
parents:
diff changeset
   530
drawFrame
71766a2845ab intitial checkin
tz
parents:
diff changeset
   531
71766a2845ab intitial checkin
tz
parents:
diff changeset
   532
    self paint:Color black.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   533
    "self lineWidth: (magnification x//3 min: 3). "
71766a2845ab intitial checkin
tz
parents:
diff changeset
   534
    self displayRectangle: ((0@0) extent:(image extent * magnification) + 2).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   535
    self lineWidth:1.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   536
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   537
71766a2845ab intitial checkin
tz
parents:
diff changeset
   538
drawFrameAt: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
   539
71766a2845ab intitial checkin
tz
parents:
diff changeset
   540
    magnification > gridMagnification
71766a2845ab intitial checkin
tz
parents:
diff changeset
   541
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   542
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   543
        |lineStartingPoint lineEndingPoint oldColor|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   544
        lineStartingPoint := aPoint//magnification*magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   545
        lineEndingPoint   := aPoint//magnification*magnification + magnification.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   546
        oldColor := self paint.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   547
        self xoring:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   548
        [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   549
            self displayLineFrom: lineEndingPoint 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   550
                              to: (lineEndingPoint x)@(lineStartingPoint y).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   551
            self displayLineFrom: lineEndingPoint 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   552
                              to: (lineStartingPoint x)@(lineEndingPoint y).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   553
        ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   554
        self paint: oldColor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   555
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   556
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   557
71766a2845ab intitial checkin
tz
parents:
diff changeset
   558
drawLabel: aLabel
71766a2845ab intitial checkin
tz
parents:
diff changeset
   559
    coordInfoBlock notNil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   560
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   561
    [         
71766a2845ab intitial checkin
tz
parents:
diff changeset
   562
        coordInfoBlock value: aLabel printString
71766a2845ab intitial checkin
tz
parents:
diff changeset
   563
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   564
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   565
71766a2845ab intitial checkin
tz
parents:
diff changeset
   566
drawMaskPointAt: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
   567
71766a2845ab intitial checkin
tz
parents:
diff changeset
   568
    |sizeOfMaskPoint|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   569
    sizeOfMaskPoint := magnification//3.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   570
    self xoring: [self fillRectangle: (aPoint + sizeOfMaskPoint extent: sizeOfMaskPoint)].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   571
   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   572
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   573
71766a2845ab intitial checkin
tz
parents:
diff changeset
   574
!ImageEditView methodsFor:'image setting'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   575
71766a2845ab intitial checkin
tz
parents:
diff changeset
   576
image:anImage
71766a2845ab intitial checkin
tz
parents:
diff changeset
   577
71766a2845ab intitial checkin
tz
parents:
diff changeset
   578
    (anImage isImage and: [image isNil or: [self checkModified]])
71766a2845ab intitial checkin
tz
parents:
diff changeset
   579
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   580
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   581
        super image: anImage.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   582
        image photometric = #palette
71766a2845ab intitial checkin
tz
parents:
diff changeset
   583
        ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   584
        [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   585
            (image usedColors includes: selectColors first) ifFalse: [selectColors at: 1 put: nil].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   586
            (image usedColors includes: selectColors last) ifFalse: [selectColors at: 2 put: nil].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   587
        ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   588
        ^self
71766a2845ab intitial checkin
tz
parents:
diff changeset
   589
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   590
    ^nil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   591
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   592
71766a2845ab intitial checkin
tz
parents:
diff changeset
   593
loadFromFile: aFileName
71766a2845ab intitial checkin
tz
parents:
diff changeset
   594
71766a2845ab intitial checkin
tz
parents:
diff changeset
   595
    |fileName newImage|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   596
    fileName := aFileName asFilename.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   597
71766a2845ab intitial checkin
tz
parents:
diff changeset
   598
    Object errorSignal handle:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   599
    [:exeption|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   600
        WarningBox warn: exeption errorString.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   601
        ^nil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   602
    ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   603
    do:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   604
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   605
        newImage := Image fromFile: fileName name.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   606
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   607
71766a2845ab intitial checkin
tz
parents:
diff changeset
   608
    (self image: newImage) notNil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   609
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   610
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   611
        imageReaderClass := ImageReader allSubclasses detect: [:cls| cls isValidImageFile:fileName name] ifNone:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   612
            [WarningBox warn: 'Unknown image file format'. ^nil].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   613
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   614
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   615
71766a2845ab intitial checkin
tz
parents:
diff changeset
   616
resourceClass: aClassOrSymbol selector: aStringOrSymbol
71766a2845ab intitial checkin
tz
parents:
diff changeset
   617
71766a2845ab intitial checkin
tz
parents:
diff changeset
   618
    |aClass|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   619
    imageReaderClass := nil.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   620
    self resourceClass: aClassOrSymbol.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   621
    self resourceSelector: aStringOrSymbol.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   622
    aClass := Smalltalk at: resourceClass. 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   623
    (aClass isClass and: [aClass class implements: resourceSelector])
71766a2845ab intitial checkin
tz
parents:
diff changeset
   624
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   625
    [ 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   626
        ^self image: (aClass perform: resourceSelector) copy
71766a2845ab intitial checkin
tz
parents:
diff changeset
   627
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   628
    ^nil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   629
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   630
71766a2845ab intitial checkin
tz
parents:
diff changeset
   631
!ImageEditView methodsFor:'initialization'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   632
71766a2845ab intitial checkin
tz
parents:
diff changeset
   633
initialize
71766a2845ab intitial checkin
tz
parents:
diff changeset
   634
71766a2845ab intitial checkin
tz
parents:
diff changeset
   635
    super initialize.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   636
71766a2845ab intitial checkin
tz
parents:
diff changeset
   637
    magnification := 1@1.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   638
    gridMagnification := 8@8.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   639
    modified := false.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   640
    mouseKeyColorMode := 1.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   641
    resourceClass := resourceSelector := ''.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   642
    selectColors := Array with: nil with: nil.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   643
    self menuHolder:self; menuPerformer:self; menuMessage:#imageMenu. 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   644
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   645
71766a2845ab intitial checkin
tz
parents:
diff changeset
   646
!ImageEditView methodsFor:'menu actions'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   647
71766a2845ab intitial checkin
tz
parents:
diff changeset
   648
changeMagnification
71766a2845ab intitial checkin
tz
parents:
diff changeset
   649
    |b newMag|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   650
71766a2845ab intitial checkin
tz
parents:
diff changeset
   651
    b := EnterBox new.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   652
    b title:'magnification (magX @ magY)'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   653
    b okText:'apply'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   654
    b abortText:'abort'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   655
    b action:[:string | newMag := (Object readFromString:string onError:nil)].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   656
    b initialText:(magnification printString).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   657
    b showAtPointer.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   658
71766a2845ab intitial checkin
tz
parents:
diff changeset
   659
    newMag notNil ifTrue:[
71766a2845ab intitial checkin
tz
parents:
diff changeset
   660
        self magnification:newMag.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   661
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   662
71766a2845ab intitial checkin
tz
parents:
diff changeset
   663
    "Modified: 31.7.1997 / 11:43:12 / cg"
71766a2845ab intitial checkin
tz
parents:
diff changeset
   664
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   665
71766a2845ab intitial checkin
tz
parents:
diff changeset
   666
loadFromClass
71766a2845ab intitial checkin
tz
parents:
diff changeset
   667
71766a2845ab intitial checkin
tz
parents:
diff changeset
   668
    self resourceMessage: (ResourceSelectionBrowser
71766a2845ab intitial checkin
tz
parents:
diff changeset
   669
        openOnSuperclass: ApplicationModel
71766a2845ab intitial checkin
tz
parents:
diff changeset
   670
        class: self resourceClass
71766a2845ab intitial checkin
tz
parents:
diff changeset
   671
        selector: self resourceSelector
71766a2845ab intitial checkin
tz
parents:
diff changeset
   672
        resourceTypes: #(#image #fileImage))
71766a2845ab intitial checkin
tz
parents:
diff changeset
   673
        
71766a2845ab intitial checkin
tz
parents:
diff changeset
   674
71766a2845ab intitial checkin
tz
parents:
diff changeset
   675
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   676
71766a2845ab intitial checkin
tz
parents:
diff changeset
   677
loadFromUser
71766a2845ab intitial checkin
tz
parents:
diff changeset
   678
71766a2845ab intitial checkin
tz
parents:
diff changeset
   679
    self image: 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   680
        ((Image fromUser)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   681
            asDitheredTrueColor8FormOn: Display)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   682
71766a2845ab intitial checkin
tz
parents:
diff changeset
   683
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   684
71766a2845ab intitial checkin
tz
parents:
diff changeset
   685
print
71766a2845ab intitial checkin
tz
parents:
diff changeset
   686
    |stream psgc|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   687
71766a2845ab intitial checkin
tz
parents:
diff changeset
   688
    image isNil ifTrue: [^nil].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   689
71766a2845ab intitial checkin
tz
parents:
diff changeset
   690
    Printer supportsPostscript ifFalse:[
71766a2845ab intitial checkin
tz
parents:
diff changeset
   691
        self warn:'need a postscript printer'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   692
        ^ self
71766a2845ab intitial checkin
tz
parents:
diff changeset
   693
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   694
71766a2845ab intitial checkin
tz
parents:
diff changeset
   695
    stream := Printer newNative.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   696
    stream isNil ifTrue:[
71766a2845ab intitial checkin
tz
parents:
diff changeset
   697
        self warn:'cannot open printer stream'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   698
        ^ nil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   699
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   700
71766a2845ab intitial checkin
tz
parents:
diff changeset
   701
    self withWaitCursorDo:[
71766a2845ab intitial checkin
tz
parents:
diff changeset
   702
        psgc := PSGraphicsContext on:stream. "/  extent:(1.0 @ 1.0).
71766a2845ab intitial checkin
tz
parents:
diff changeset
   703
        psgc displayForm: (image magnifiedBy: magnification) x:0 y:0.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   704
        psgc close.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   705
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   706
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   707
71766a2845ab intitial checkin
tz
parents:
diff changeset
   708
save
71766a2845ab intitial checkin
tz
parents:
diff changeset
   709
71766a2845ab intitial checkin
tz
parents:
diff changeset
   710
    Object errorSignal handle:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   711
    [:ex|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   712
        WarningBox warn: ex errorString.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   713
        ^nil                                 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   714
    ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   715
    do:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   716
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   717
        |fileName|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   718
        image isNil ifTrue: [^self error: 'No image to save!!'].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   719
        image fileName isNil ifTrue: [^self error: 'No file name for image detected!!'].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   720
        fileName := image fileName asFilename.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   721
        (fileName suffix = 'tiff') | (fileName suffix = 'tif') ifTrue: [imageReaderClass := TIFFReader].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   722
        fileName suffix = 'xpm' ifTrue: [imageReaderClass := XPMReader].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   723
        fileName suffix = 'xbm' ifTrue: [imageReaderClass := XBMReader].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   724
        fileName suffix = 'gif' ifTrue: [imageReaderClass := GIFReader].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   725
        (fileName suffix = 'jpg') | (fileName suffix = 'jpeg') ifTrue: [imageReaderClass := JPEGReader].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   726
        imageReaderClass isNil ifTrue: [imageReaderClass := XPMReader. image fileName: image fileName, '.xpm'].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   727
        
71766a2845ab intitial checkin
tz
parents:
diff changeset
   728
        image saveOn: image fileName using: imageReaderClass.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   729
        modified := false.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   730
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   731
       
71766a2845ab intitial checkin
tz
parents:
diff changeset
   732
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   733
71766a2845ab intitial checkin
tz
parents:
diff changeset
   734
saveAs
71766a2845ab intitial checkin
tz
parents:
diff changeset
   735
    "save contents into a file 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   736
     - ask user for filename using a fileSelectionBox."
71766a2845ab intitial checkin
tz
parents:
diff changeset
   737
71766a2845ab intitial checkin
tz
parents:
diff changeset
   738
    self saveImageFileAs
71766a2845ab intitial checkin
tz
parents:
diff changeset
   739
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   740
71766a2845ab intitial checkin
tz
parents:
diff changeset
   741
saveAsMethod
71766a2845ab intitial checkin
tz
parents:
diff changeset
   742
71766a2845ab intitial checkin
tz
parents:
diff changeset
   743
    Object errorSignal handle:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   744
    [:ex|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   745
        WarningBox warn: ex errorString.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   746
        ^nil                                 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   747
    ] 
71766a2845ab intitial checkin
tz
parents:
diff changeset
   748
    do:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   749
    [   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   750
        |compileString stream aClass|  
71766a2845ab intitial checkin
tz
parents:
diff changeset
   751
        stream := WriteStream on: ''.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   752
        self resourceSelector trimBlanks size = 0 ifTrue: [^self error: 'No image selector detected'].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   753
        (aClass := Smalltalk at: self resourceClass) isClass ifFalse: [^self error: 'No class for image selector detected'].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   754
        self image storeOn: stream.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   755
        compileString :=
71766a2845ab intitial checkin
tz
parents:
diff changeset
   756
            self resourceSelector,
71766a2845ab intitial checkin
tz
parents:
diff changeset
   757
            '\\' withCRs,
71766a2845ab intitial checkin
tz
parents:
diff changeset
   758
            '    <resource: #image>\' withCRs,
71766a2845ab intitial checkin
tz
parents:
diff changeset
   759
            '    ^',
71766a2845ab intitial checkin
tz
parents:
diff changeset
   760
            stream contents.   
71766a2845ab intitial checkin
tz
parents:
diff changeset
   761
        ByteCodeCompiler compile: compileString forClass: aClass class inCategory: 'resources'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   762
        modified := false.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   763
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   764
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   765
71766a2845ab intitial checkin
tz
parents:
diff changeset
   766
saveImageFileAs
71766a2845ab intitial checkin
tz
parents:
diff changeset
   767
71766a2845ab intitial checkin
tz
parents:
diff changeset
   768
    |aFileName|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   769
71766a2845ab intitial checkin
tz
parents:
diff changeset
   770
    (aFileName := (FileBrowserView requestFileName: self image fileName fileFilters: #('*.xpm' '*.gif'))) notNil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   771
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   772
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   773
        self saveImageFileAs: aFileName
71766a2845ab intitial checkin
tz
parents:
diff changeset
   774
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   775
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   776
71766a2845ab intitial checkin
tz
parents:
diff changeset
   777
saveImageFileAs: aFileName
71766a2845ab intitial checkin
tz
parents:
diff changeset
   778
71766a2845ab intitial checkin
tz
parents:
diff changeset
   779
    image notNil
71766a2845ab intitial checkin
tz
parents:
diff changeset
   780
    ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   781
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   782
        image fileName: aFileName.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   783
        self save
71766a2845ab intitial checkin
tz
parents:
diff changeset
   784
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   785
    ifFalse:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   786
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   787
        WarningBox warn: 'No image detected'
71766a2845ab intitial checkin
tz
parents:
diff changeset
   788
    ]
71766a2845ab intitial checkin
tz
parents:
diff changeset
   789
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   790
71766a2845ab intitial checkin
tz
parents:
diff changeset
   791
!ImageEditView methodsFor:'queries'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   792
71766a2845ab intitial checkin
tz
parents:
diff changeset
   793
checkModified
71766a2845ab intitial checkin
tz
parents:
diff changeset
   794
71766a2845ab intitial checkin
tz
parents:
diff changeset
   795
    modified ifTrue:
71766a2845ab intitial checkin
tz
parents:
diff changeset
   796
    [
71766a2845ab intitial checkin
tz
parents:
diff changeset
   797
        |aBox|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   798
        aBox := YesNoBox title:'Image was modified'.        
71766a2845ab intitial checkin
tz
parents:
diff changeset
   799
        aBox noText:'abort'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   800
        aBox yesText:'ignore'.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   801
        aBox showAtPointer.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   802
        aBox accepted ifFalse: [^false].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   803
        modified := false
71766a2845ab intitial checkin
tz
parents:
diff changeset
   804
    ].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   805
    ^true
71766a2845ab intitial checkin
tz
parents:
diff changeset
   806
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   807
71766a2845ab intitial checkin
tz
parents:
diff changeset
   808
heightOfContents
71766a2845ab intitial checkin
tz
parents:
diff changeset
   809
    "return the images height"
71766a2845ab intitial checkin
tz
parents:
diff changeset
   810
71766a2845ab intitial checkin
tz
parents:
diff changeset
   811
    image isNil ifTrue:[^ 0].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   812
    ^ (image height * magnification y) rounded
71766a2845ab intitial checkin
tz
parents:
diff changeset
   813
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   814
71766a2845ab intitial checkin
tz
parents:
diff changeset
   815
imageContainsPoint: aPoint
71766a2845ab intitial checkin
tz
parents:
diff changeset
   816
    |pi|
71766a2845ab intitial checkin
tz
parents:
diff changeset
   817
    image isNil ifTrue: [^false].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   818
    pi := ((aPoint - margin + 1) / magnification) floor.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   819
    ^((0@0 corner:(image extent) - 1) containsPoint:pi)
71766a2845ab intitial checkin
tz
parents:
diff changeset
   820
!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   821
71766a2845ab intitial checkin
tz
parents:
diff changeset
   822
widthOfContents
71766a2845ab intitial checkin
tz
parents:
diff changeset
   823
    "return the images width"
71766a2845ab intitial checkin
tz
parents:
diff changeset
   824
71766a2845ab intitial checkin
tz
parents:
diff changeset
   825
    image isNil ifTrue:[^ 0].
71766a2845ab intitial checkin
tz
parents:
diff changeset
   826
    ^ (image width * magnification x) rounded
71766a2845ab intitial checkin
tz
parents:
diff changeset
   827
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   828
71766a2845ab intitial checkin
tz
parents:
diff changeset
   829
!ImageEditView methodsFor:'release'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   830
71766a2845ab intitial checkin
tz
parents:
diff changeset
   831
destroy
71766a2845ab intitial checkin
tz
parents:
diff changeset
   832
71766a2845ab intitial checkin
tz
parents:
diff changeset
   833
    undoImage := nil.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   834
    Clipboard := nil.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   835
    super destroy.
71766a2845ab intitial checkin
tz
parents:
diff changeset
   836
71766a2845ab intitial checkin
tz
parents:
diff changeset
   837
! !
71766a2845ab intitial checkin
tz
parents:
diff changeset
   838
71766a2845ab intitial checkin
tz
parents:
diff changeset
   839
!ImageEditView class methodsFor:'documentation'!
71766a2845ab intitial checkin
tz
parents:
diff changeset
   840
71766a2845ab intitial checkin
tz
parents:
diff changeset
   841
version
71766a2845ab intitial checkin
tz
parents:
diff changeset
   842
    ^ '$Header$'
71766a2845ab intitial checkin
tz
parents:
diff changeset
   843
! !