ImageEditView.st
author tz
Fri, 23 Jan 1998 14:58:30 +0100
changeset 678 9afa8810a8be
parent 676 fd7918a3e6e6
child 686 33833bcbb5cd
permissions -rw-r--r--
image must not be nil after load failure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
636
d53428252193 revised version
tz
parents: 633
diff changeset
     1
"
d53428252193 revised version
tz
parents: 633
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG / Thomas Zwick
d53428252193 revised version
tz
parents: 633
diff changeset
     3
              All Rights Reserved
d53428252193 revised version
tz
parents: 633
diff changeset
     4
d53428252193 revised version
tz
parents: 633
diff changeset
     5
 This software is furnished under a license and may be used
d53428252193 revised version
tz
parents: 633
diff changeset
     6
 only in accordance with the terms of that license and with the
d53428252193 revised version
tz
parents: 633
diff changeset
     7
 inclusion of the above copyright notice. This software may not
d53428252193 revised version
tz
parents: 633
diff changeset
     8
 be provided or otherwise made available to, or used by, any
d53428252193 revised version
tz
parents: 633
diff changeset
     9
 other person. No title to or ownership of the software is
d53428252193 revised version
tz
parents: 633
diff changeset
    10
 hereby transferred.
d53428252193 revised version
tz
parents: 633
diff changeset
    11
"
d53428252193 revised version
tz
parents: 633
diff changeset
    12
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    13
ImageView subclass:#ImageEditView
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    14
	instanceVariableNames:'magnification gridMagnification selectColors imageReaderClass
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    15
		resourceClass resourceSelector editMode mouseKeyColorMode
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
    16
		undoImage modified coordInfoBlock masterApplication'
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    17
	classVariableNames:'Clipboard'
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    18
	poolDictionaries:''
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    19
	category:'Views-Misc'
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    20
!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
    21
636
d53428252193 revised version
tz
parents: 633
diff changeset
    22
!ImageEditView class methodsFor:'documentation'!
d53428252193 revised version
tz
parents: 633
diff changeset
    23
d53428252193 revised version
tz
parents: 633
diff changeset
    24
copyright
d53428252193 revised version
tz
parents: 633
diff changeset
    25
"
d53428252193 revised version
tz
parents: 633
diff changeset
    26
 COPYRIGHT (c) 1997 by eXept Software AG / Thomas Zwick
d53428252193 revised version
tz
parents: 633
diff changeset
    27
              All Rights Reserved
d53428252193 revised version
tz
parents: 633
diff changeset
    28
d53428252193 revised version
tz
parents: 633
diff changeset
    29
 This software is furnished under a license and may be used
d53428252193 revised version
tz
parents: 633
diff changeset
    30
 only in accordance with the terms of that license and with the
d53428252193 revised version
tz
parents: 633
diff changeset
    31
 inclusion of the above copyright notice. This software may not
d53428252193 revised version
tz
parents: 633
diff changeset
    32
 be provided or otherwise made available to, or used by, any
d53428252193 revised version
tz
parents: 633
diff changeset
    33
 other person. No title to or ownership of the software is
d53428252193 revised version
tz
parents: 633
diff changeset
    34
 hereby transferred.
d53428252193 revised version
tz
parents: 633
diff changeset
    35
"
d53428252193 revised version
tz
parents: 633
diff changeset
    36
!
d53428252193 revised version
tz
parents: 633
diff changeset
    37
d53428252193 revised version
tz
parents: 633
diff changeset
    38
documentation
d53428252193 revised version
tz
parents: 633
diff changeset
    39
"
d53428252193 revised version
tz
parents: 633
diff changeset
    40
    The ImageEditView is a view class which can be used by applications
d53428252193 revised version
tz
parents: 633
diff changeset
    41
    like the Image Editor for modifying or inspecting images.
d53428252193 revised version
tz
parents: 633
diff changeset
    42
d53428252193 revised version
tz
parents: 633
diff changeset
    43
    [see also:]
d53428252193 revised version
tz
parents: 633
diff changeset
    44
        ImageEditor Image
d53428252193 revised version
tz
parents: 633
diff changeset
    45
d53428252193 revised version
tz
parents: 633
diff changeset
    46
    [author:]
d53428252193 revised version
tz
parents: 633
diff changeset
    47
        Thomas Zwick
d53428252193 revised version
tz
parents: 633
diff changeset
    48
"
d53428252193 revised version
tz
parents: 633
diff changeset
    49
! !
353
0442fc169b82 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 322
diff changeset
    50
7
19b36b78ee01 *** empty log message ***
claus
parents: 5
diff changeset
    51
!ImageEditView methodsFor:'accessing'!
19b36b78ee01 *** empty log message ***
claus
parents: 5
diff changeset
    52
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    53
coordInfoBlock: aBlock
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    54
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    55
    coordInfoBlock := aBlock
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    56
!
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    57
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    58
gridMagnification: aPoint
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    59
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    60
    gridMagnification := aPoint
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    61
!
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    62
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    63
imageReaderClass
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    64
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    65
    ^imageReaderClass
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    66
!
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    67
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    68
magnification
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    69
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    70
    ^magnification
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    71
255
1dfa8deddaef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    72
!
1dfa8deddaef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    73
636
d53428252193 revised version
tz
parents: 633
diff changeset
    74
magnification: aPoint
255
1dfa8deddaef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    75
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    76
    magnification ~= aPoint
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    77
    ifTrue:
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    78
    [
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    79
        magnification := aPoint asPoint.
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    80
        self scrollToTopLeft.
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    81
        self contentsChanged.
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    82
        self invalidate.
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    83
    ].
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
    84
!
255
1dfa8deddaef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    85
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
    86
masterApplication
61b7601829ea with modal support
tz
parents: 636
diff changeset
    87
61b7601829ea with modal support
tz
parents: 636
diff changeset
    88
    ^masterApplication
61b7601829ea with modal support
tz
parents: 636
diff changeset
    89
!
61b7601829ea with modal support
tz
parents: 636
diff changeset
    90
61b7601829ea with modal support
tz
parents: 636
diff changeset
    91
masterApplication: anApplicationModel
61b7601829ea with modal support
tz
parents: 636
diff changeset
    92
61b7601829ea with modal support
tz
parents: 636
diff changeset
    93
    masterApplication := anApplicationModel
61b7601829ea with modal support
tz
parents: 636
diff changeset
    94
!
61b7601829ea with modal support
tz
parents: 636
diff changeset
    95
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    96
resourceClass
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    97
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    98
    ^resourceClass
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
    99
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   100
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   101
resourceClass: aClassOrSymbol
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   102
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   103
    resourceClass := aClassOrSymbol isClass ifTrue: [aClassOrSymbol name] ifFalse: [aClassOrSymbol asSymbol].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   104
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   105
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   106
resourceMessage
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   107
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   108
    ^resourceClass, ' ', resourceSelector
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   109
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   110
636
d53428252193 revised version
tz
parents: 633
diff changeset
   111
resourceMessage: aString
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   112
636
d53428252193 revised version
tz
parents: 633
diff changeset
   113
    (aString isString and: [aString trimBlanks size > 0])
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   114
    ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   115
    [
636
d53428252193 revised version
tz
parents: 633
diff changeset
   116
        resourceClass := (aString readStream upTo: Character space) asSymbol.
d53428252193 revised version
tz
parents: 633
diff changeset
   117
        resourceSelector := (aString copy reverse readStream upTo: Character space) reverse asSymbol.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   118
    ]
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   119
    ifFalse:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   120
    [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   121
        ^nil
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   122
    ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   123
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   124
   
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   125
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   126
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   127
resourceSelector
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   128
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   129
    ^resourceSelector
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   130
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   131
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   132
resourceSelector: aStringOrSymbol
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   133
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   134
    resourceSelector := aStringOrSymbol asSymbol
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   135
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   136
633
594edef86630 revised version
tz
parents: 632
diff changeset
   137
selectColor: anArrayTwoColors
594edef86630 revised version
tz
parents: 632
diff changeset
   138
594edef86630 revised version
tz
parents: 632
diff changeset
   139
    selectColors := anArrayTwoColors
594edef86630 revised version
tz
parents: 632
diff changeset
   140
!
594edef86630 revised version
tz
parents: 632
diff changeset
   141
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   142
selectedColor
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   143
633
594edef86630 revised version
tz
parents: 632
diff changeset
   144
   ^selectColors at: mouseKeyColorMode
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   145
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   146
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   147
selectedColor: aColor
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   148
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   149
    selectColors at: mouseKeyColorMode put: aColor
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   150
! !
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   151
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   152
!ImageEditView methodsFor:'drawing'!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   153
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   154
fillFramedRectangle: aRectangle
61b7601829ea with modal support
tz
parents: 636
diff changeset
   155
61b7601829ea with modal support
tz
parents: 636
diff changeset
   156
    self fillRectangle: aRectangle.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   157
    self drawFramesIn: aRectangle
61b7601829ea with modal support
tz
parents: 636
diff changeset
   158
!
61b7601829ea with modal support
tz
parents: 636
diff changeset
   159
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   160
redrawImageX:x y:y width:w height:h
636
d53428252193 revised version
tz
parents: 633
diff changeset
   161
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   162
    |ih iw magX magY minX maxX minY maxY color lastColor lastY runW x0 xI yI maskColor sizeOfMaskPoint|
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   163
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   164
    ih := image height.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   165
    iw := image width.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   166
    magX := magnification x.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   167
    magY := magnification y.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   168
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   169
    minX := (x // magX - 1) max: 0.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   170
    minX >= iw ifTrue:[minX := iw - 1].
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   171
    minY := (y // magY - 1) max: 0.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   172
    minY >= ih ifTrue:[minY := ih - 1].
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   173
    maxX := (x + w) // magX + 1.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   174
    maxX > iw ifTrue:[maxX := iw].
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   175
    maxY := (y + h) // magY + 1.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   176
    maxY > ih ifTrue:[maxY := ih].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   177
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   178
    lastY := -1.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   179
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   180
    x0 := minX.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   181
    runW := 0.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   182
    maskColor := false.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   183
    sizeOfMaskPoint := magnification//3.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   184
    image colorsFromX: minX y: minY toX: maxX-1 y: maxY-1 do:
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   185
    [:xx :yy :color|
633
594edef86630 revised version
tz
parents: 632
diff changeset
   186
        yy ~~ lastY
594edef86630 revised version
tz
parents: 632
diff changeset
   187
        ifTrue:
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   188
        [
633
594edef86630 revised version
tz
parents: 632
diff changeset
   189
            runW ~~ 0
594edef86630 revised version
tz
parents: 632
diff changeset
   190
            ifTrue:
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   191
            [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   192
                |origin|
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   193
                origin := (x0 * magX + margin)@(lastY * magY + margin).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   194
                self fillFramedRectangle: (origin extent: (runW@magY)).                    
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   195
                maskColor ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   196
                [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   197
                    self xoring: [self fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   198
                ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   199
                runW := 0.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   200
            ]. 
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   201
            x0 := xx.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   202
            lastY := yy.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   203
        ]. 
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   204
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   205
        color ~~ lastColor
633
594edef86630 revised version
tz
parents: 632
diff changeset
   206
        ifTrue:
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   207
        [
633
594edef86630 revised version
tz
parents: 632
diff changeset
   208
            runW ~~ 0
594edef86630 revised version
tz
parents: 632
diff changeset
   209
            ifTrue:
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   210
            [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   211
                |origin|
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   212
                origin := (x0 * magX + margin)@(yy * magY + margin).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   213
                self fillFramedRectangle: (origin extent: (runW@magY)).
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   214
                maskColor ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   215
                [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   216
                    self xoring: [self fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   217
                ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   218
                runW := 0.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   219
            ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   220
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   221
            self paint: (lastColor := color).
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   222
            image mask notNil ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   223
            [  
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   224
                maskColor := false.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   225
                (image mask colorAt: xx@yy) = Color black ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   226
                [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   227
                    self paint: (lastColor := self viewBackground).
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   228
                    maskColor := true.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   229
                ].
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   230
                lastColor := nil.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   231
            ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   232
            runW := 0.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   233
            x0 := xx.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   234
        ].  
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   235
        runW := runW + magX
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   236
    ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   237
    runW ~~ 0 ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   238
    [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   239
        |origin|
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   240
        origin := (x0 * magX + margin)@(lastY * magY + margin).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   241
        self fillFramedRectangle: (origin extent: runW@magY).
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   242
        maskColor ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   243
        [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   244
            self xoring: [self fillRectangle: (origin + sizeOfMaskPoint extent: sizeOfMaskPoint)]
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   245
        ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   246
        runW := 0.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   247
    ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   248
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   249
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   250
redrawX:x y:y width:w height:h
636
d53428252193 revised version
tz
parents: 633
diff changeset
   251
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   252
    |ih iw xI yI|
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   253
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   254
    magnification = (1@1) ifTrue: [^super redrawX:x y:y width:w height:h].
61b7601829ea with modal support
tz
parents: 636
diff changeset
   255
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   256
    image isNil ifTrue:[^self].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   257
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   258
    self clippingRectangle: (x@y extent: w@h).
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   259
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   260
    self redrawImageX:x y:y width:w height:h.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   261
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   262
    "/ right of image ?
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   263
    adjust == #center ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   264
    [
633
594edef86630 revised version
tz
parents: 632
diff changeset
   265
        xI := (width - ih) // 2 - margin.
594edef86630 revised version
tz
parents: 632
diff changeset
   266
        yI := (height - iw) // 2 - margin.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   267
    ]
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   268
    ifFalse:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   269
    [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   270
        xI := yI := margin
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   271
    ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   272
    (x + w - 1) > (xI + (magnification x * image width)) ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   273
    [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   274
        self clearRectangleX:(xI + (magnification x * image width))
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   275
                           y:y
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   276
                       width:(x + w - (magnification x * image width) - xI)
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   277
                      height:h
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   278
    ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   279
    (y + h - 1) > (yI + (magnification y * image height)) ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   280
    [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   281
        self clearRectangleX:margin
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   282
                           y:(yI + (magnification y * image height))
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   283
                       width:w
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   284
                      height:(y + h - (magnification y * image height) - yI)  
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   285
    ].
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   286
    self drawFrame.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   287
    self clippingRectangle: nil.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   288
! !
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   289
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   290
!ImageEditView methodsFor:'edit modes'!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   291
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   292
editMode
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   293
636
d53428252193 revised version
tz
parents: 633
diff changeset
   294
    ^editMode ? (editMode := 'point')
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   295
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   296
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   297
editMode:aMode
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   298
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   299
    editMode := aMode
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   300
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   301
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   302
mouseKeyColorMode
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   303
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   304
    ^mouseKeyColorMode printString
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   305
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   306
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   307
mouseKeyColorMode:aMode
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   308
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   309
    mouseKeyColorMode := aMode asInteger
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   310
! !
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   311
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   312
!ImageEditView methodsFor:'event handling'!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   313
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   314
buttonMotion:state x:x y:y
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   315
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   316
    self drawCursorAt: x@y.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   317
    self selectedColor notNil & image notNil & (self imageContainsPoint: x@y) & (editMode = 'point')
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   318
        ifTrue: [^self pointAt: x@y].
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   319
!
255
1dfa8deddaef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   320
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   321
buttonPress:button x:x y:y
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   322
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   323
    self drawCursorAt: x@y.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   324
    self selectedColor notNil & image notNil & (self imageContainsPoint: x@y)
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   325
    ifTrue:
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   326
    [    
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   327
        undoImage := image copy.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   328
        mouseKeyColorMode := button.
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   329
        self perform: (editMode, 'At:') asSymbol with: x@y.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   330
    ].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   331
!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   332
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   333
buttonRelease:state x:x y:y
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   334
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   335
    Cursor normal show
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   336
! !
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   337
636
d53428252193 revised version
tz
parents: 633
diff changeset
   338
!ImageEditView methodsFor:'image editing'!
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   339
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   340
boxAt: aPoint
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   341
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   342
    |choosedBox imageBox|
636
d53428252193 revised version
tz
parents: 633
diff changeset
   343
    choosedBox := self drawRectangleStartingAt: aPoint emphasis: #box.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   344
    image rectangle: (imageBox := choosedBox origin//magnification extent: (choosedBox extent//magnification)) withColor: self selectedColor.
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   345
    image restored.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   346
    self redraw: (choosedBox expandedBy: 1).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   347
    masterApplication notNil
61b7601829ea with modal support
tz
parents: 636
diff changeset
   348
    ifTrue:
61b7601829ea with modal support
tz
parents: 636
diff changeset
   349
    [
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   350
        masterApplication imagePreView redraw: (imageBox expandedBy: 1)
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   351
    ].
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   352
    modified := true
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   353
!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   354
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   355
copyAt: aPoint
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   356
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   357
    |choosedBox|
636
d53428252193 revised version
tz
parents: 633
diff changeset
   358
    choosedBox := self drawRectangleStartingAt: aPoint emphasis: #inverseFilledBox.
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   359
    Clipboard := image subImageIn: (choosedBox origin//magnification extent: (choosedBox extent//magnification)).
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   360
    self redraw: (choosedBox expandedBy: 1)    
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   361
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   362
!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   363
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   364
fillAt: aPoint
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   365
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   366
    Cursor execute showWhile:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   367
    [
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   368
        |filledPoints|
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   369
        filledPoints := image floodFillAt: aPoint//magnification withColor: self selectedColor.
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   370
        image restored.
633
594edef86630 revised version
tz
parents: 632
diff changeset
   371
        filledPoints size < 300
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   372
        ifTrue:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   373
        [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   374
            filledPoints do: [:p| self redraw: ((p * magnification extent: magnification) expandedBy: 1)]
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   375
        ]
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   376
        ifFalse:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   377
        [
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   378
            self invalidate
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   379
        ].
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   380
        masterApplication notNil
61b7601829ea with modal support
tz
parents: 636
diff changeset
   381
        ifTrue:
61b7601829ea with modal support
tz
parents: 636
diff changeset
   382
        [
61b7601829ea with modal support
tz
parents: 636
diff changeset
   383
            masterApplication imagePreView invalidate
61b7601829ea with modal support
tz
parents: 636
diff changeset
   384
        ].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   385
        modified := true
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   386
    ]
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   387
!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   388
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   389
filledBoxAt: aPoint
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   390
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   391
    |choosedBox imageBox|
636
d53428252193 revised version
tz
parents: 633
diff changeset
   392
    choosedBox := self drawRectangleStartingAt: aPoint emphasis: #filledBox.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   393
    image fillRectangle: (imageBox := choosedBox origin//magnification extent: (choosedBox extent//magnification)) withColor: self selectedColor.
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   394
    image restored.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   395
    self redraw: (choosedBox expandedBy: 1).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   396
    masterApplication notNil
61b7601829ea with modal support
tz
parents: 636
diff changeset
   397
    ifTrue:
61b7601829ea with modal support
tz
parents: 636
diff changeset
   398
    [
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   399
        masterApplication imagePreView redraw: (imageBox expandedBy: 1)
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   400
61b7601829ea with modal support
tz
parents: 636
diff changeset
   401
    ].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   402
    modified := true.
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   403
!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   404
636
d53428252193 revised version
tz
parents: 633
diff changeset
   405
flipHorizontal
d53428252193 revised version
tz
parents: 633
diff changeset
   406
d53428252193 revised version
tz
parents: 633
diff changeset
   407
    undoImage := image copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   408
    self image: image flipHorizontal
d53428252193 revised version
tz
parents: 633
diff changeset
   409
d53428252193 revised version
tz
parents: 633
diff changeset
   410
!
d53428252193 revised version
tz
parents: 633
diff changeset
   411
d53428252193 revised version
tz
parents: 633
diff changeset
   412
flipVertical
d53428252193 revised version
tz
parents: 633
diff changeset
   413
d53428252193 revised version
tz
parents: 633
diff changeset
   414
    undoImage := image copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   415
    self image: image flipVertical
d53428252193 revised version
tz
parents: 633
diff changeset
   416
d53428252193 revised version
tz
parents: 633
diff changeset
   417
!
d53428252193 revised version
tz
parents: 633
diff changeset
   418
d53428252193 revised version
tz
parents: 633
diff changeset
   419
magnifyImage
d53428252193 revised version
tz
parents: 633
diff changeset
   420
d53428252193 revised version
tz
parents: 633
diff changeset
   421
    |box newSize|
d53428252193 revised version
tz
parents: 633
diff changeset
   422
    box := EnterBox new.
d53428252193 revised version
tz
parents: 633
diff changeset
   423
    box title:'Image new size:'.
d53428252193 revised version
tz
parents: 633
diff changeset
   424
    box okText:'OK'.
d53428252193 revised version
tz
parents: 633
diff changeset
   425
    box abortText:'Cancel'.
d53428252193 revised version
tz
parents: 633
diff changeset
   426
    box initialText:image extent printString.
d53428252193 revised version
tz
parents: 633
diff changeset
   427
    box showAtPointer.
d53428252193 revised version
tz
parents: 633
diff changeset
   428
    (box accepted and: [(newSize := Object readFromString: box contents onError:nil) notNil])
d53428252193 revised version
tz
parents: 633
diff changeset
   429
    ifTrue:
d53428252193 revised version
tz
parents: 633
diff changeset
   430
    [
d53428252193 revised version
tz
parents: 633
diff changeset
   431
        undoImage := image copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   432
        self image: (image magnifiedBy: newSize/image extent)
d53428252193 revised version
tz
parents: 633
diff changeset
   433
    ].
d53428252193 revised version
tz
parents: 633
diff changeset
   434
!
d53428252193 revised version
tz
parents: 633
diff changeset
   435
d53428252193 revised version
tz
parents: 633
diff changeset
   436
negativeImage
d53428252193 revised version
tz
parents: 633
diff changeset
   437
d53428252193 revised version
tz
parents: 633
diff changeset
   438
    undoImage := image copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   439
    self image: image negative
d53428252193 revised version
tz
parents: 633
diff changeset
   440
d53428252193 revised version
tz
parents: 633
diff changeset
   441
!
d53428252193 revised version
tz
parents: 633
diff changeset
   442
d53428252193 revised version
tz
parents: 633
diff changeset
   443
pasteAt: aPoint
d53428252193 revised version
tz
parents: 633
diff changeset
   444
d53428252193 revised version
tz
parents: 633
diff changeset
   445
    Object errorSignal handle:
d53428252193 revised version
tz
parents: 633
diff changeset
   446
    [:ex|
d53428252193 revised version
tz
parents: 633
diff changeset
   447
        self warn: 'Pasting at selected point failed!!'
d53428252193 revised version
tz
parents: 633
diff changeset
   448
    ] 
d53428252193 revised version
tz
parents: 633
diff changeset
   449
    do:
d53428252193 revised version
tz
parents: 633
diff changeset
   450
    [   
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   451
        |imagePoint imageBox|
636
d53428252193 revised version
tz
parents: 633
diff changeset
   452
        imagePoint := aPoint//magnification.
d53428252193 revised version
tz
parents: 633
diff changeset
   453
        image copyFrom: Clipboard x:0 y:0 toX: imagePoint x y: imagePoint y width: Clipboard width height: Clipboard height.
d53428252193 revised version
tz
parents: 633
diff changeset
   454
        image restored.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   455
        self redraw: (imageBox := (imagePoint * magnification extent: (Clipboard extent * magnification)) expandedBy: 1@1).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   456
        masterApplication notNil
61b7601829ea with modal support
tz
parents: 636
diff changeset
   457
        ifTrue:
61b7601829ea with modal support
tz
parents: 636
diff changeset
   458
        [
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   459
            masterApplication imagePreView redraw: (imageBox expandedBy: 1)
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   460
        ].
636
d53428252193 revised version
tz
parents: 633
diff changeset
   461
        self drawLabel: imagePoint.
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   462
        modified := true
636
d53428252193 revised version
tz
parents: 633
diff changeset
   463
    ]
d53428252193 revised version
tz
parents: 633
diff changeset
   464
!
d53428252193 revised version
tz
parents: 633
diff changeset
   465
d53428252193 revised version
tz
parents: 633
diff changeset
   466
pointAt: aPoint
d53428252193 revised version
tz
parents: 633
diff changeset
   467
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   468
    |imagePoint imageBox|
636
d53428252193 revised version
tz
parents: 633
diff changeset
   469
    imagePoint := aPoint//magnification.
d53428252193 revised version
tz
parents: 633
diff changeset
   470
    image atImageAndMask: imagePoint put: self selectedColor.
d53428252193 revised version
tz
parents: 633
diff changeset
   471
    image restored.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   472
    self redraw: (imageBox := (imagePoint * magnification extent: magnification) expandedBy: 1).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   473
    masterApplication notNil
61b7601829ea with modal support
tz
parents: 636
diff changeset
   474
    ifTrue:
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   475
    [             
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   476
        masterApplication imagePreView redraw: ((imagePoint + 1) extent: 1@1)
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   477
    ].
636
d53428252193 revised version
tz
parents: 633
diff changeset
   478
    self drawLabel: imagePoint.
d53428252193 revised version
tz
parents: 633
diff changeset
   479
    modified := true.
d53428252193 revised version
tz
parents: 633
diff changeset
   480
!
d53428252193 revised version
tz
parents: 633
diff changeset
   481
d53428252193 revised version
tz
parents: 633
diff changeset
   482
resizeImage
d53428252193 revised version
tz
parents: 633
diff changeset
   483
d53428252193 revised version
tz
parents: 633
diff changeset
   484
    |box newSize|
d53428252193 revised version
tz
parents: 633
diff changeset
   485
    box := EnterBox new.
d53428252193 revised version
tz
parents: 633
diff changeset
   486
    box title:'Image new size:'.
d53428252193 revised version
tz
parents: 633
diff changeset
   487
    box okText:'OK'.
d53428252193 revised version
tz
parents: 633
diff changeset
   488
    box abortText:'Cancel'.
d53428252193 revised version
tz
parents: 633
diff changeset
   489
    box initialText:image extent printString.
d53428252193 revised version
tz
parents: 633
diff changeset
   490
    box showAtPointer.
d53428252193 revised version
tz
parents: 633
diff changeset
   491
    (box accepted and: [(newSize := Object readFromString: box contents onError:nil) notNil])
d53428252193 revised version
tz
parents: 633
diff changeset
   492
    ifTrue:
d53428252193 revised version
tz
parents: 633
diff changeset
   493
    [
d53428252193 revised version
tz
parents: 633
diff changeset
   494
        |newImage|
d53428252193 revised version
tz
parents: 633
diff changeset
   495
        undoImage := image copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   496
        newImage := image class width: newSize x height: newSize y depth: image depth.
d53428252193 revised version
tz
parents: 633
diff changeset
   497
        newImage photometric:image photometric.
d53428252193 revised version
tz
parents: 633
diff changeset
   498
        newImage colorMap:image colorMap copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   499
        newImage bits: (ByteArray new: newImage bytesPerRow * newSize y).
d53428252193 revised version
tz
parents: 633
diff changeset
   500
d53428252193 revised version
tz
parents: 633
diff changeset
   501
        image mask notNil
d53428252193 revised version
tz
parents: 633
diff changeset
   502
        ifTrue: 
d53428252193 revised version
tz
parents: 633
diff changeset
   503
        [
d53428252193 revised version
tz
parents: 633
diff changeset
   504
            |newMaskImage|
d53428252193 revised version
tz
parents: 633
diff changeset
   505
            newMaskImage := Depth1Image width: newSize x height: newSize y.
d53428252193 revised version
tz
parents: 633
diff changeset
   506
            newMaskImage photometric: image mask photometric.
d53428252193 revised version
tz
parents: 633
diff changeset
   507
            newMaskImage colorMap: image mask colorMap copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   508
            newMaskImage bits:(ByteArray new: newMaskImage bytesPerRow * newSize y).
d53428252193 revised version
tz
parents: 633
diff changeset
   509
            newImage mask: newMaskImage
d53428252193 revised version
tz
parents: 633
diff changeset
   510
        ].
d53428252193 revised version
tz
parents: 633
diff changeset
   511
d53428252193 revised version
tz
parents: 633
diff changeset
   512
        newImage copyFrom:image x:0 y:0 toX:0 y:0 width: (image width min:newSize x) height: (image height min:newSize y).
d53428252193 revised version
tz
parents: 633
diff changeset
   513
        self image: newImage
d53428252193 revised version
tz
parents: 633
diff changeset
   514
    ].
d53428252193 revised version
tz
parents: 633
diff changeset
   515
!
d53428252193 revised version
tz
parents: 633
diff changeset
   516
d53428252193 revised version
tz
parents: 633
diff changeset
   517
rotateImage
d53428252193 revised version
tz
parents: 633
diff changeset
   518
d53428252193 revised version
tz
parents: 633
diff changeset
   519
    |box rotation|
d53428252193 revised version
tz
parents: 633
diff changeset
   520
    box := EnterBox new.
d53428252193 revised version
tz
parents: 633
diff changeset
   521
    box title:'Image new rotation:'.
d53428252193 revised version
tz
parents: 633
diff changeset
   522
    box okText:'OK'.
d53428252193 revised version
tz
parents: 633
diff changeset
   523
    box abortText:'Cancel'.
d53428252193 revised version
tz
parents: 633
diff changeset
   524
    box initialText: '0'.
d53428252193 revised version
tz
parents: 633
diff changeset
   525
    box showAtPointer.
d53428252193 revised version
tz
parents: 633
diff changeset
   526
    (box accepted and: [(rotation := Object readFromString: box contents onError:nil) notNil])
d53428252193 revised version
tz
parents: 633
diff changeset
   527
    ifTrue:
d53428252193 revised version
tz
parents: 633
diff changeset
   528
    [   Object errorSignal handle:
d53428252193 revised version
tz
parents: 633
diff changeset
   529
        [:ex|
d53428252193 revised version
tz
parents: 633
diff changeset
   530
            self warn: 'Image rotation failed.\' withCRs, 'An increase of image depth could help.'.
d53428252193 revised version
tz
parents: 633
diff changeset
   531
        ] 
d53428252193 revised version
tz
parents: 633
diff changeset
   532
        do:
d53428252193 revised version
tz
parents: 633
diff changeset
   533
        [   
d53428252193 revised version
tz
parents: 633
diff changeset
   534
            undoImage := image copy.
d53428252193 revised version
tz
parents: 633
diff changeset
   535
            self image: (image hardRotated: rotation)
d53428252193 revised version
tz
parents: 633
diff changeset
   536
        ]
d53428252193 revised version
tz
parents: 633
diff changeset
   537
    ].
d53428252193 revised version
tz
parents: 633
diff changeset
   538
!
d53428252193 revised version
tz
parents: 633
diff changeset
   539
d53428252193 revised version
tz
parents: 633
diff changeset
   540
undo
d53428252193 revised version
tz
parents: 633
diff changeset
   541
d53428252193 revised version
tz
parents: 633
diff changeset
   542
    undoImage notNil
d53428252193 revised version
tz
parents: 633
diff changeset
   543
    ifTrue:
d53428252193 revised version
tz
parents: 633
diff changeset
   544
    [
d53428252193 revised version
tz
parents: 633
diff changeset
   545
        modified := false.
d53428252193 revised version
tz
parents: 633
diff changeset
   546
        self image: undoImage.
d53428252193 revised version
tz
parents: 633
diff changeset
   547
        self invalidate
d53428252193 revised version
tz
parents: 633
diff changeset
   548
    ]
d53428252193 revised version
tz
parents: 633
diff changeset
   549
! !
d53428252193 revised version
tz
parents: 633
diff changeset
   550
d53428252193 revised version
tz
parents: 633
diff changeset
   551
!ImageEditView methodsFor:'image emphasis'!
d53428252193 revised version
tz
parents: 633
diff changeset
   552
d53428252193 revised version
tz
parents: 633
diff changeset
   553
drawCursorAt: aPoint
d53428252193 revised version
tz
parents: 633
diff changeset
   554
d53428252193 revised version
tz
parents: 633
diff changeset
   555
    image isNil ifTrue: [^Cursor stop show].
d53428252193 revised version
tz
parents: 633
diff changeset
   556
    ((0@0 extent: image extent * magnification) containsPoint: aPoint)
d53428252193 revised version
tz
parents: 633
diff changeset
   557
         ifFalse:[Cursor stop show]
d53428252193 revised version
tz
parents: 633
diff changeset
   558
         ifTrue: [Cursor crossHair show].
d53428252193 revised version
tz
parents: 633
diff changeset
   559
d53428252193 revised version
tz
parents: 633
diff changeset
   560
!
d53428252193 revised version
tz
parents: 633
diff changeset
   561
d53428252193 revised version
tz
parents: 633
diff changeset
   562
drawFrame
d53428252193 revised version
tz
parents: 633
diff changeset
   563
d53428252193 revised version
tz
parents: 633
diff changeset
   564
    self paint:Color black.
d53428252193 revised version
tz
parents: 633
diff changeset
   565
    self lineWidth: (magnification x//3 min: 3).
d53428252193 revised version
tz
parents: 633
diff changeset
   566
    self displayRectangle: ((0@0) extent:(image extent * magnification) + 2).
d53428252193 revised version
tz
parents: 633
diff changeset
   567
    self lineWidth:1.
d53428252193 revised version
tz
parents: 633
diff changeset
   568
!
d53428252193 revised version
tz
parents: 633
diff changeset
   569
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   570
drawFramesIn: aRectangle
636
d53428252193 revised version
tz
parents: 633
diff changeset
   571
d53428252193 revised version
tz
parents: 633
diff changeset
   572
    magnification > gridMagnification
d53428252193 revised version
tz
parents: 633
diff changeset
   573
    ifTrue:
d53428252193 revised version
tz
parents: 633
diff changeset
   574
    [   
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   575
        |origin lineStartingPoint lineEndingPoint oldColor|
61b7601829ea with modal support
tz
parents: 636
diff changeset
   576
        origin := aRectangle origin - 1.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   577
        lineStartingPoint := origin + (0@magnification y).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   578
        lineEndingPoint   := lineStartingPoint + (aRectangle width@0).
636
d53428252193 revised version
tz
parents: 633
diff changeset
   579
        oldColor := self paint.
d53428252193 revised version
tz
parents: 633
diff changeset
   580
        self xoring:
d53428252193 revised version
tz
parents: 633
diff changeset
   581
        [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   582
            self displayLineFrom: lineStartingPoint to: lineEndingPoint.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   583
            lineStartingPoint x to: lineStartingPoint x + aRectangle width - magnification x by: magnification x do:
61b7601829ea with modal support
tz
parents: 636
diff changeset
   584
            [:x|   
61b7601829ea with modal support
tz
parents: 636
diff changeset
   585
                self displayLineFrom: x@(origin y) to: x@(origin y + magnification y)
61b7601829ea with modal support
tz
parents: 636
diff changeset
   586
            ].
636
d53428252193 revised version
tz
parents: 633
diff changeset
   587
        ].
d53428252193 revised version
tz
parents: 633
diff changeset
   588
        self paint: oldColor.
d53428252193 revised version
tz
parents: 633
diff changeset
   589
    ]
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   590
61b7601829ea with modal support
tz
parents: 636
diff changeset
   591
61b7601829ea with modal support
tz
parents: 636
diff changeset
   592
636
d53428252193 revised version
tz
parents: 633
diff changeset
   593
!
d53428252193 revised version
tz
parents: 633
diff changeset
   594
d53428252193 revised version
tz
parents: 633
diff changeset
   595
drawLabel: aLabel
d53428252193 revised version
tz
parents: 633
diff changeset
   596
d53428252193 revised version
tz
parents: 633
diff changeset
   597
    coordInfoBlock notNil
d53428252193 revised version
tz
parents: 633
diff changeset
   598
    ifTrue:
d53428252193 revised version
tz
parents: 633
diff changeset
   599
    [         
d53428252193 revised version
tz
parents: 633
diff changeset
   600
        coordInfoBlock value: aLabel printString
d53428252193 revised version
tz
parents: 633
diff changeset
   601
    ]
d53428252193 revised version
tz
parents: 633
diff changeset
   602
!
d53428252193 revised version
tz
parents: 633
diff changeset
   603
d53428252193 revised version
tz
parents: 633
diff changeset
   604
drawRectangleStartingAt: aPoint emphasis: emphasis
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   605
633
594edef86630 revised version
tz
parents: 632
diff changeset
   606
    |currentPoint currentExtent firstPoint lastCurrentPoint gridCorrection p|
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   607
    firstPoint := currentPoint := lastCurrentPoint := aPoint//magnification*magnification.
636
d53428252193 revised version
tz
parents: 633
diff changeset
   608
    magnification > gridMagnification ifFalse: [gridCorrection := 0] ifTrue: [gridCorrection := 1].
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   609
    [Display anyButtonPressed]
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   610
    whileTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   611
    [   
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   612
        currentPoint := (0@0) max: (image extent * magnification min: (p := self translation negated + (device translatePoint: self sensor mousePoint from:device rootView id to:self id))).
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   613
        currentPoint := currentPoint//magnification*magnification.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   614
        currentExtent := (firstPoint - currentPoint) abs.
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   615
        self drawCursorAt: p.
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   616
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   617
        currentPoint ~= lastCurrentPoint ifTrue:
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   618
        [          
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   619
            emphasis = #inverseFilledBox
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   620
            ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   621
            [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   622
                self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
633
594edef86630 revised version
tz
parents: 632
diff changeset
   623
                self xoring: [self fillRectangle: ((firstPoint min: currentPoint) + 1 extent: currentExtent - gridCorrection)]
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   624
            ].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   625
            emphasis = #box
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   626
            ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   627
            [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   628
                |origin extent lineWidthY lineWidthX|
61b7601829ea with modal support
tz
parents: 636
diff changeset
   629
                origin := (firstPoint min: lastCurrentPoint) - 1.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   630
                extent := (firstPoint - lastCurrentPoint) abs + 2.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   631
                lineWidthY := extent y min: (magnification y + 2).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   632
                lineWidthX := extent x min: (magnification x + 2).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   633
                self redraw: (origin extent: (extent x@lineWidthY)).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   634
                self redraw: ((origin x@(origin y + extent y - lineWidthY)) extent: (extent x@lineWidthY)).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   635
                self redraw: ((origin x@(origin y + lineWidthY)) extent: (lineWidthX@(0 max: (extent y - (lineWidthY * 2))))).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   636
                self redraw: (((origin x + extent x - lineWidthX)@(origin y + lineWidthY)) extent: (lineWidthX@(extent y - (lineWidthY * 2)))).
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   637
                self selectedColor ~= Color noColor
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   638
                    ifTrue: [self paint: self selectedColor]
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   639
                    ifFalse: [self paint: self viewBackground].
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   640
                origin := (firstPoint min: currentPoint) + 1.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   641
                extent := currentExtent - gridCorrection.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   642
                lineWidthY := extent y min: magnification y.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   643
                lineWidthX := extent x min: magnification x.
61b7601829ea with modal support
tz
parents: 636
diff changeset
   644
                (lineWidthY > 0) & (lineWidthX > 0)
61b7601829ea with modal support
tz
parents: 636
diff changeset
   645
                ifTrue:
61b7601829ea with modal support
tz
parents: 636
diff changeset
   646
                [
61b7601829ea with modal support
tz
parents: 636
diff changeset
   647
                    self fillRectangle: (origin extent: (extent x@lineWidthY)).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   648
                    self fillRectangle: ((origin x@(origin y + extent y - lineWidthY)) extent: (extent x@lineWidthY)).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   649
                    self fillRectangle: ((origin x@(origin y + lineWidthY)) extent: (lineWidthX@(0 max: (extent y - (lineWidthY * 2))))).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   650
                    self fillRectangle: (((origin x + extent x - lineWidthX)@(origin y + lineWidthY)) extent: (lineWidthX@(extent y - (lineWidthY * 2)))).
61b7601829ea with modal support
tz
parents: 636
diff changeset
   651
                ]
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   652
            ].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   653
            emphasis = #filledBox
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   654
            ifTrue:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   655
            [
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   656
                self redraw: ((firstPoint min: lastCurrentPoint) - 1 extent: (firstPoint - lastCurrentPoint) abs + 2).
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   657
                self selectedColor ~= Color noColor
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   658
                    ifTrue: [self paint: self selectedColor]
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   659
                    ifFalse: [self paint: self viewBackground].
633
594edef86630 revised version
tz
parents: 632
diff changeset
   660
                self fillRectangle: ((firstPoint min: currentPoint) + 1 extent: currentExtent - gridCorrection).
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   661
            ].
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   662
        ]. 
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   663
        self drawLabel: currentPoint//magnification.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   664
        lastCurrentPoint := currentPoint.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   665
    ].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   666
    Cursor normal show.
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   667
61b7601829ea with modal support
tz
parents: 636
diff changeset
   668
    ^((1@1) max: (firstPoint min: currentPoint)) extent: (firstPoint - currentPoint) abs
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   669
! !
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   670
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   671
!ImageEditView methodsFor:'image setting'!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   672
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   673
image:anImage
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   674
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   675
    (anImage isImage and: [image isNil or: [self checkModified]])
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   676
    ifTrue:
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   677
    [    
61b7601829ea with modal support
tz
parents: 636
diff changeset
   678
        masterApplication notNil ifTrue: [masterApplication imagePreView image: anImage].
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   679
        super image: anImage.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   680
        ^self
674
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   681
    ]
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   682
    ifFalse:
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   683
    [
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   684
        super image: nil.
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   685
        ^nil
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   686
    ]
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   687
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   688
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   689
loadFromFile: aFileName
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   690
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   691
    aFileName isNil ifTrue: [^nil].
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   692
    Object errorSignal handle:
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   693
    [:exeption|
674
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   694
        modified := false.
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   695
        self warn: exeption errorString.
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   696
        ^nil
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   697
    ] 
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   698
    do:
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   699
    [ 
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   700
        |imageFromFile|
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   701
        (imageFromFile := Image fromFile: aFileName) notNil
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   702
        ifTrue:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   703
        [
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   704
            self image: imageFromFile. 
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   705
            imageReaderClass := ImageReader allSubclasses
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   706
                detect: [:cls| cls isValidImageFile: aFileName]
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   707
                ifNone: [self error: 'Unknown image file format!!']
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   708
        ]
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   709
        ifFalse:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   710
        [
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   711
            self error: 'Image on file not found!!'
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   712
        ]
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   713
    ]
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   714
!
255
1dfa8deddaef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   715
633
594edef86630 revised version
tz
parents: 632
diff changeset
   716
loadFromMessage: aMessage
594edef86630 revised version
tz
parents: 632
diff changeset
   717
594edef86630 revised version
tz
parents: 632
diff changeset
   718
    (self resourceMessage: aMessage) isNil
594edef86630 revised version
tz
parents: 632
diff changeset
   719
    ifTrue:
594edef86630 revised version
tz
parents: 632
diff changeset
   720
    [
594edef86630 revised version
tz
parents: 632
diff changeset
   721
        ^nil
594edef86630 revised version
tz
parents: 632
diff changeset
   722
    ].
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   723
633
594edef86630 revised version
tz
parents: 632
diff changeset
   724
    ^self loadfromClass: resourceClass andSelector: resourceSelector
594edef86630 revised version
tz
parents: 632
diff changeset
   725
594edef86630 revised version
tz
parents: 632
diff changeset
   726
   
594edef86630 revised version
tz
parents: 632
diff changeset
   727
!
594edef86630 revised version
tz
parents: 632
diff changeset
   728
594edef86630 revised version
tz
parents: 632
diff changeset
   729
loadfromClass: aClassOrSymbol andSelector: aStringOrSymbol
594edef86630 revised version
tz
parents: 632
diff changeset
   730
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   731
    |aClass| 
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   732
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   733
    imageReaderClass := nil.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   734
    self resourceClass: aClassOrSymbol.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   735
    self resourceSelector: aStringOrSymbol.
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   736
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   737
    ((aClass := Smalltalk at: resourceClass) isClass and: 
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   738
    [aClass class implements: resourceSelector])
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   739
    ifTrue:
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   740
    [ 
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   741
        ^self image: (aClass perform: resourceSelector) copy
674
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   742
    ]
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   743
    ifFalse:
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   744
    [
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   745
        modified := false.
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   746
        ^nil
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   747
    ]
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   748
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   749
! !
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   750
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   751
!ImageEditView methodsFor:'initialization'!
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   752
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   753
initialize
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   754
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   755
    super initialize.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   756
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   757
    magnification := 1@1.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   758
    gridMagnification := 8@8.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   759
    modified := false.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   760
    mouseKeyColorMode := 1.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   761
    resourceClass := resourceSelector := ''.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   762
    selectColors := Array with: nil with: nil.
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   763
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   764
636
d53428252193 revised version
tz
parents: 633
diff changeset
   765
!ImageEditView methodsFor:'printing & storing'!
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   766
636
d53428252193 revised version
tz
parents: 633
diff changeset
   767
loadFromInClassesOf: aSuperclassOrSymbol
404
322e32d8f099 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 398
diff changeset
   768
676
fd7918a3e6e6 load + preview redraw errors removed
tz
parents: 674
diff changeset
   769
    ^self loadFromMessage: 
636
d53428252193 revised version
tz
parents: 633
diff changeset
   770
        (ResourceSelectionBrowser
662
61b7601829ea with modal support
tz
parents: 636
diff changeset
   771
            request: 'Load Image From Class'
636
d53428252193 revised version
tz
parents: 633
diff changeset
   772
            onSuperclass: aSuperclassOrSymbol
d53428252193 revised version
tz
parents: 633
diff changeset
   773
            andClass: self resourceClass
d53428252193 revised version
tz
parents: 633
diff changeset
   774
            andSelector: self resourceSelector
d53428252193 revised version
tz
parents: 633
diff changeset
   775
            withResourceTypes: #(image fileImage))
d53428252193 revised version
tz
parents: 633
diff changeset
   776
            
477
37f12d35c359 added #resize.
Claus Gittinger <cg@exept.de>
parents: 430
diff changeset
   777
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   778
!
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   779
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   780
print
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   781
636
d53428252193 revised version
tz
parents: 633
diff changeset
   782
    |stream|
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   783
    image isNil ifTrue: [^nil].
636
d53428252193 revised version
tz
parents: 633
diff changeset
   784
    Printer supportsPostscript ifFalse:
d53428252193 revised version
tz
parents: 633
diff changeset
   785
    [
d53428252193 revised version
tz
parents: 633
diff changeset
   786
        ^self warn:'No postscript printer detected!!'
362
c8d268d3f431 added 'print' item to menu
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   787
    ].
c8d268d3f431 added 'print' item to menu
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   788
    stream := Printer newNative.
636
d53428252193 revised version
tz
parents: 633
diff changeset
   789
    stream isNil ifTrue:
d53428252193 revised version
tz
parents: 633
diff changeset
   790
    [
d53428252193 revised version
tz
parents: 633
diff changeset
   791
        ^self warn:'Cannot open printer stream!!'.
362
c8d268d3f431 added 'print' item to menu
Claus Gittinger <cg@exept.de>
parents: 353
diff changeset
   792
    ].
636
d53428252193 revised version
tz
parents: 633
diff changeset
   793
    self withWaitCursorDo:
d53428252193 revised version
tz
parents: 633
diff changeset
   794
    [
d53428252193 revised version
tz
parents: 633
diff changeset
   795
        |psgc|
d53428252193 revised version
tz
parents: 633
diff changeset
   796
        psgc := PSGraphicsContext on:stream.
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   797
        psgc displayForm: (image magnifiedBy: magnification) x:0 y:0.
398
7b7255a4db0d show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents: 362
diff changeset
   798
        psgc close.
7b7255a4db0d show a wait cursor while printing
Claus Gittinger <cg@exept.de>
parents: 362
diff changeset
   799
    ]
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   800
!
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   801
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   802
save
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   803
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   804
    self saveImageOrMask: #image.
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   805
624
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   806
!
d98fe4700fc2 checkin from browser
tz
parents: 606
diff changeset
   807
297
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   808
saveAs
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   809
    "save contents into a file 
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   810
     - ask user for filename using a fileSelectionBox."
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   811
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   812
    self saveImageFileAs
297
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   813
!
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   814
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   815
saveImageFileAs
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   816
633
594edef86630 revised version
tz
parents: 632
diff changeset
   817
    self saveImageFileAs:
594edef86630 revised version
tz
parents: 632
diff changeset
   818
        (FileSelectionBrowser
636
d53428252193 revised version
tz
parents: 633
diff changeset
   819
            request: 'Save Image As'
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   820
            pathName: self image fileName
633
594edef86630 revised version
tz
parents: 632
diff changeset
   821
            fileFilters: FileSelectionBrowser saveImageFileNameFilters)
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   822
!
297
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   823
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   824
saveImageFileAs: aFileName
297
d733af1b0ffe better saving functions;
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   825
633
594edef86630 revised version
tz
parents: 632
diff changeset
   826
    aFileName isNil ifTrue: [^nil].
636
d53428252193 revised version
tz
parents: 633
diff changeset
   827
    image notNil
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   828
    ifTrue:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   829
    [
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   830
        image fileName: aFileName.
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   831
        self saveImageOrMask: #image
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   832
    ]
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   833
    ifFalse:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   834
    [
633
594edef86630 revised version
tz
parents: 632
diff changeset
   835
        self warn: 'No image or file name for saving detected!!'
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   836
    ]
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   837
!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   838
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   839
saveImageMaskFileAs
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   840
633
594edef86630 revised version
tz
parents: 632
diff changeset
   841
    self saveImageMaskFileAs:
636
d53428252193 revised version
tz
parents: 633
diff changeset
   842
        (FileSelectionBrowser
d53428252193 revised version
tz
parents: 633
diff changeset
   843
            request: 'Save Image Mask As'
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   844
            pathName: self image fileName 
633
594edef86630 revised version
tz
parents: 632
diff changeset
   845
            fileFilters: FileSelectionBrowser saveImageFileNameFilters)
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   846
!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   847
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   848
saveImageMaskFileAs: aFileName
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   849
633
594edef86630 revised version
tz
parents: 632
diff changeset
   850
    aFileName isNil ifTrue: [^nil].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   851
    (image notNil and: [image mask notNil])
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   852
    ifTrue:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   853
    [
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   854
        image mask fileName: aFileName.
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   855
        self saveImageOrMask: #mask
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   856
    ]
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   857
    ifFalse:
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   858
    [
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   859
        self warn: 'No image or image mask detected!!'
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   860
    ]
628
7f36d8a7735f popup menu starts image editor
tz
parents: 627
diff changeset
   861
!
7f36d8a7735f popup menu starts image editor
tz
parents: 627
diff changeset
   862
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   863
saveImageOrMask: what
628
7f36d8a7735f popup menu starts image editor
tz
parents: 627
diff changeset
   864
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   865
    Object errorSignal handle:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   866
    [:ex|
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   867
        self warn: ex errorString.
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   868
        ^nil                                 
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   869
    ] 
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   870
    do:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   871
    [   
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   872
        |fileName|
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   873
        image isNil ifTrue: [^self error: 'No image to save!!'].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   874
        what = #image
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   875
        ifTrue:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   876
        [   
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   877
            image fileName isNil ifTrue: [^self error: 'No file name for image detected!!'].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   878
            fileName := image fileName asFilename
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   879
        ].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   880
        what = #mask
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   881
        ifTrue:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   882
        [   
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   883
            image mask isNil ifTrue: [^self error: 'No image mask to save!!'].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   884
            image mask fileName isNil ifTrue: [^self error: 'No file name for image mask detected!!'].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   885
            fileName := image mask fileName asFilename
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   886
        ].
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   887
        fileName name size = 0 ifTrue: [^self error: 'No file name detected!!'].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   888
        (fileName suffix = 'tiff') | (fileName suffix = 'tif') ifTrue: [imageReaderClass := TIFFReader].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   889
        fileName suffix = 'xpm' ifTrue: [imageReaderClass := XPMReader].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   890
        fileName suffix = 'xbm' ifTrue: [imageReaderClass := XBMReader].
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   891
        fileName suffix = 'gif' ifTrue: [imageReaderClass := GIFReader].
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   892
        (fileName suffix = 'jpg') | (fileName suffix = 'jpeg') ifTrue: [imageReaderClass := JPEGReader].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   893
        imageReaderClass isNil ifTrue: [imageReaderClass := XPMReader. image fileName: image fileName, '.xpm'].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   894
        what = #image ifTrue: [image saveOn: image fileName using: imageReaderClass. modified := false].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   895
        what = #mask ifTrue: [image mask saveOn: image mask fileName using: imageReaderClass].
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   896
    ]   
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   897
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   898
       
633
594edef86630 revised version
tz
parents: 632
diff changeset
   899
!
594edef86630 revised version
tz
parents: 632
diff changeset
   900
594edef86630 revised version
tz
parents: 632
diff changeset
   901
saveMethod
594edef86630 revised version
tz
parents: 632
diff changeset
   902
594edef86630 revised version
tz
parents: 632
diff changeset
   903
    Object errorSignal handle:
594edef86630 revised version
tz
parents: 632
diff changeset
   904
    [:ex|
594edef86630 revised version
tz
parents: 632
diff changeset
   905
        self warn: ex errorString.
594edef86630 revised version
tz
parents: 632
diff changeset
   906
        ^nil                                 
594edef86630 revised version
tz
parents: 632
diff changeset
   907
    ] 
594edef86630 revised version
tz
parents: 632
diff changeset
   908
    do:
594edef86630 revised version
tz
parents: 632
diff changeset
   909
    [   
594edef86630 revised version
tz
parents: 632
diff changeset
   910
        |imageStoreStream cls|  
594edef86630 revised version
tz
parents: 632
diff changeset
   911
        (self resourceSelector trimBlanks size = 0) | (cls := Smalltalk at: self resourceClass) isClass not 
594edef86630 revised version
tz
parents: 632
diff changeset
   912
            ifTrue: [^self error: 'No class and selector for image detected!!'].
594edef86630 revised version
tz
parents: 632
diff changeset
   913
        self image storeOn: (imageStoreStream := WriteStream on: '').
594edef86630 revised version
tz
parents: 632
diff changeset
   914
        ByteCodeCompiler 
594edef86630 revised version
tz
parents: 632
diff changeset
   915
            compile: (self resourceSelector,
594edef86630 revised version
tz
parents: 632
diff changeset
   916
                '\' withCRs, '    "ImageEditor openOnClass:self andSelector:#', self resourceSelector, '"',
594edef86630 revised version
tz
parents: 632
diff changeset
   917
                '\\' withCRs, '    <resource: #image>\' withCRs, '    ^', imageStoreStream contents)
594edef86630 revised version
tz
parents: 632
diff changeset
   918
            forClass: cls class inCategory: 'resources'.
594edef86630 revised version
tz
parents: 632
diff changeset
   919
        modified := false.
594edef86630 revised version
tz
parents: 632
diff changeset
   920
    ]
594edef86630 revised version
tz
parents: 632
diff changeset
   921
!
594edef86630 revised version
tz
parents: 632
diff changeset
   922
594edef86630 revised version
tz
parents: 632
diff changeset
   923
saveMethodAs
594edef86630 revised version
tz
parents: 632
diff changeset
   924
636
d53428252193 revised version
tz
parents: 633
diff changeset
   925
    (self resourceMessage:
d53428252193 revised version
tz
parents: 633
diff changeset
   926
        (ResourceSelectionBrowser
d53428252193 revised version
tz
parents: 633
diff changeset
   927
            request: 'Save On Image Resource Selector'
d53428252193 revised version
tz
parents: 633
diff changeset
   928
            onSuperclass: #ApplicationModel
d53428252193 revised version
tz
parents: 633
diff changeset
   929
            andClass: self resourceClass
d53428252193 revised version
tz
parents: 633
diff changeset
   930
            andSelector: self resourceSelector
d53428252193 revised version
tz
parents: 633
diff changeset
   931
            withResourceTypes: #(image fileImage))) notNil
633
594edef86630 revised version
tz
parents: 632
diff changeset
   932
    ifTrue:
674
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   933
    [   
633
594edef86630 revised version
tz
parents: 632
diff changeset
   934
        ^self saveMethod
674
f24ca336b717 if none image found for loading clear image
tz
parents: 662
diff changeset
   935
    ].  
633
594edef86630 revised version
tz
parents: 632
diff changeset
   936
    ^nil
1
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   937
! !
c6ca7bfedf31 Initial revision
claus
parents:
diff changeset
   938
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   939
!ImageEditView methodsFor:'queries'!
5
be72e6ba4822 *** empty log message ***
claus
parents: 1
diff changeset
   940
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   941
heightOfContents
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   942
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   943
    image isNil ifTrue:[^ 0].
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   944
    ^ (image height * magnification y) rounded
5
be72e6ba4822 *** empty log message ***
claus
parents: 1
diff changeset
   945
!
be72e6ba4822 *** empty log message ***
claus
parents: 1
diff changeset
   946
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   947
imageContainsPoint: aPoint
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   948
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   949
    ^image notNil and:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   950
        [((0@0 corner:(image extent) - 1) containsPoint: (((aPoint - margin + 1) / magnification) floor))]
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   951
!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   952
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   953
widthOfContents
5
be72e6ba4822 *** empty log message ***
claus
parents: 1
diff changeset
   954
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   955
    image isNil ifTrue:[^ 0].
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   956
    ^ (image width * magnification x) rounded
5
be72e6ba4822 *** empty log message ***
claus
parents: 1
diff changeset
   957
! !
be72e6ba4822 *** empty log message ***
claus
parents: 1
diff changeset
   958
627
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   959
!ImageEditView methodsFor:'release'!
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   960
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   961
destroy
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   962
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   963
    undoImage := nil.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   964
    Clipboard := nil.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   965
    super destroy.
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   966
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   967
! !
e0bf28f61361 many many fixes/enhancements
tz
parents: 624
diff changeset
   968
632
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   969
!ImageEditView methodsFor:'testing'!
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   970
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   971
checkModified
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   972
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   973
    modified
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   974
    ifTrue:
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   975
    [
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   976
        ((YesNoBox title:'Image was modified!!')        
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   977
            noText:'Cancel';
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   978
            yesText:'Waste it and proceed';
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   979
            showAtPointer;
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   980
            accepted) ifFalse: [^false].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   981
        modified := false
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   982
    ].
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   983
    ^true
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   984
! !
be1ac8ea33a7 checkin from browser
tz
parents: 628
diff changeset
   985
255
1dfa8deddaef checkin from browser
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   986
!ImageEditView class methodsFor:'documentation'!
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   987
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   988
version
678
9afa8810a8be image must not be nil after load failure
tz
parents: 676
diff changeset
   989
    ^ '$Header: /cvs/stx/stx/libwidg2/ImageEditView.st,v 1.57 1998-01-23 13:58:30 tz Exp $'
161
5b6e284959a4 examples
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   990
! !