ImageEditor.st
changeset 1480 43c18932d2e8
parent 1479 18f7b6cc2514
child 1481 32f1fd9d0f15
equal deleted inserted replaced
1479:18f7b6cc2514 1480:43c18932d2e8
    13 "{ Package: 'stx:libtool2' }"
    13 "{ Package: 'stx:libtool2' }"
    14 
    14 
    15 ToolApplicationModel subclass:#ImageEditor
    15 ToolApplicationModel subclass:#ImageEditor
    16 	instanceVariableNames:'imageEditView colorMapMode editMode mouseKeyColorMode
    16 	instanceVariableNames:'imageEditView colorMapMode editMode mouseKeyColorMode
    17 		selectedColorIndex postOpenAction imageSeqNr'
    17 		selectedColorIndex postOpenAction imageSeqNr'
    18 	classVariableNames:'LastDirectory'
    18 	classVariableNames:'LastDirectory MaskClipboard'
    19 	poolDictionaries:''
    19 	poolDictionaries:''
    20 	category:'Interface-UIPainter'
    20 	category:'Interface-UIPainter'
    21 !
    21 !
    22 
    22 
    23 !ImageEditor class methodsFor:'documentation'!
    23 !ImageEditor class methodsFor:'documentation'!
   501     ^ 
   501     ^ 
   502      #(#FullSpec
   502      #(#FullSpec
   503         #name: #gropDialogSpec
   503         #name: #gropDialogSpec
   504         #window: 
   504         #window: 
   505        #(#WindowSpec
   505        #(#WindowSpec
   506           #label: 'Crop Borders'
   506           #label: 'Crop Border(s)'
   507           #name: 'Crop Borders'
   507           #name: 'Crop Borders'
       
   508           #min: #(#Point 10 10)
       
   509           #max: #(#Point 800 478)
       
   510           #bounds: #(#Rectangle 16 46 261 229)
       
   511         )
       
   512         #component: 
       
   513        #(#SpecCollection
       
   514           #collection: #(
       
   515            #(#LabelSpec
       
   516               #label: 'Left:'
       
   517               #name: 'Label1'
       
   518               #layout: #(#LayoutFrame 14 0 21 0 90 0 43 0)
       
   519               #translateLabel: true
       
   520               #adjust: #right
       
   521             )
       
   522            #(#InputFieldSpec
       
   523               #name: 'EntryField1'
       
   524               #layout: #(#LayoutFrame 95 0 21 0 132 0 43 0)
       
   525               #model: #left
       
   526               #type: #number
       
   527               #acceptOnPointerLeave: false
       
   528             )
       
   529            #(#LabelSpec
       
   530               #label: 'Right:'
       
   531               #name: 'Label2'
       
   532               #layout: #(#LayoutFrame 14 0 51 0 90 0 73 0)
       
   533               #translateLabel: true
       
   534               #adjust: #right
       
   535             )
       
   536            #(#InputFieldSpec
       
   537               #name: 'EntryField2'
       
   538               #layout: #(#LayoutFrame 95 0 51 0 132 0 73 0)
       
   539               #model: #right
       
   540               #type: #number
       
   541               #acceptOnPointerLeave: false
       
   542             )
       
   543            #(#LabelSpec
       
   544               #label: 'Top:'
       
   545               #name: 'Label3'
       
   546               #layout: #(#LayoutFrame 14 0 81 0 90 0 103 0)
       
   547               #translateLabel: true
       
   548               #adjust: #right
       
   549             )
       
   550            #(#InputFieldSpec
       
   551               #name: 'EntryField3'
       
   552               #layout: #(#LayoutFrame 95 0 81 0 132 0 103 0)
       
   553               #model: #top
       
   554               #type: #number
       
   555               #acceptOnPointerLeave: false
       
   556             )
       
   557            #(#LabelSpec
       
   558               #label: 'Bottom:'
       
   559               #name: 'Label4'
       
   560               #layout: #(#LayoutFrame 14 0 111 0 90 0 133 0)
       
   561               #translateLabel: true
       
   562               #adjust: #right
       
   563             )
       
   564            #(#InputFieldSpec
       
   565               #name: 'EntryField4'
       
   566               #layout: #(#LayoutFrame 95 0 111 0 132 0 133 0)
       
   567               #model: #bottom
       
   568               #type: #number
       
   569               #acceptOnPointerLeave: false
       
   570             )
       
   571            #(#HorizontalPanelViewSpec
       
   572               #name: 'HorizontalPanel1'
       
   573               #layout: #(#LayoutFrame 0 0.0 -30 1 0 1.0 0 1)
       
   574               #horizontalLayout: #fitSpace
       
   575               #verticalLayout: #center
       
   576               #horizontalSpace: 3
       
   577               #verticalSpace: 3
       
   578               #reverseOrderIfOKAtLeft: true
       
   579               #component: 
       
   580              #(#SpecCollection
       
   581                 #collection: #(
       
   582                  #(#ActionButtonSpec
       
   583                     #label: 'Cancel'
       
   584                     #name: 'Button1'
       
   585                     #translateLabel: true
       
   586                     #model: #cancel
       
   587                     #extent: #(#Point 118 22)
       
   588                   )
       
   589                  #(#ActionButtonSpec
       
   590                     #label: 'OK'
       
   591                     #name: 'Button2'
       
   592                     #translateLabel: true
       
   593                     #model: #accept
       
   594                     #extent: #(#Point 118 22)
       
   595                   )
       
   596                  )
       
   597                
       
   598               )
       
   599             )
       
   600            )
       
   601          
       
   602         )
       
   603       )
       
   604 !
       
   605 
       
   606 ungropDialogSpec
       
   607     "This resource specification was automatically generated
       
   608      by the UIPainter of ST/X."
       
   609 
       
   610     "Do not manually edit this!! If it is corrupted,
       
   611      the UIPainter may not be able to read the specification."
       
   612 
       
   613     "
       
   614      UIPainter new openOnClass:ImageEditor andSelector:#ungropDialogSpec
       
   615      ImageEditor new openInterface:#ungropDialogSpec
       
   616     "
       
   617 
       
   618     <resource: #canvas>
       
   619 
       
   620     ^ 
       
   621      #(#FullSpec
       
   622         #name: #ungropDialogSpec
       
   623         #window: 
       
   624        #(#WindowSpec
       
   625           #label: 'Add Border(s)'
       
   626           #name: 'Add Borders'
   508           #min: #(#Point 10 10)
   627           #min: #(#Point 10 10)
   509           #max: #(#Point 800 478)
   628           #max: #(#Point 800 478)
   510           #bounds: #(#Rectangle 16 46 261 229)
   629           #bounds: #(#Rectangle 16 46 261 229)
   511         )
   630         )
   512         #component: 
   631         #component: 
  1135                      )
  1254                      )
  1136                     nil
  1255                     nil
  1137                     nil
  1256                     nil
  1138                   )
  1257                   )
  1139                 )
  1258                 )
       
  1259                 #(#MenuItem
       
  1260                    #label: 'Ungrop (Add Border)...'
       
  1261                    #translateLabel: true
       
  1262                    #value: #doUnCropManual
       
  1263                    #activeHelpKey: #uncropManual
       
  1264                  )
  1140                )
  1265                )
  1141               nil
  1266               nil
  1142               nil
  1267               nil
  1143             )
  1268             )
  1144           )
  1269           )
  1256                 )
  1381                 )
  1257                #(#MenuItem
  1382                #(#MenuItem
  1258                   #label: 'Make GrayScale Image'
  1383                   #label: 'Make GrayScale Image'
  1259                   #translateLabel: true
  1384                   #translateLabel: true
  1260                   #value: #makeGrayScale
  1385                   #value: #makeGrayScale
       
  1386                 )
       
  1387                #(#MenuItem
       
  1388                   #label: '-'
       
  1389                 )
       
  1390                #(#MenuItem
       
  1391                   #label: 'Copy mask'
       
  1392                   #translateLabel: true
       
  1393                   #value: #copyMask
       
  1394                   #activeHelpKey: #copyMask
       
  1395                   #enabled: #hasMask
       
  1396                 )
       
  1397                #(#MenuItem
       
  1398                   #label: 'Paste mask'
       
  1399                   #translateLabel: true
       
  1400                   #value: #pasteMask
       
  1401                   #activeHelpKey: #pasteMask
       
  1402                   #enabled: #hasMask
  1261                 )
  1403                 )
  1262                )
  1404                )
  1263               nil
  1405               nil
  1264               nil
  1406               nil
  1265             )
  1407             )
  2514 
  2656 
  2515     "Created: / 28.7.1998 / 20:03:11 / cg"
  2657     "Created: / 28.7.1998 / 20:03:11 / cg"
  2516     "Modified: / 15.9.1998 / 17:53:32 / cg"
  2658     "Modified: / 15.9.1998 / 17:53:32 / cg"
  2517 !
  2659 !
  2518 
  2660 
       
  2661 copyMask
       
  2662     |mask|
       
  2663 
       
  2664     mask := self image mask.
       
  2665     MaskClipboard := mask subImageIn: (0@0 extent:mask extent).
       
  2666 !
       
  2667 
  2519 fetchImageData
  2668 fetchImageData
  2520     |image|
  2669     |image|
  2521 
  2670 
  2522     (image := imageEditView image) notNil ifTrue:[
  2671     (image := imageEditView image) notNil ifTrue:[
  2523         self listOfColors contents:(image colorMap).
  2672         self listOfColors contents:(image colorMap).
  2610 "/        self updateLabelsAndHistory.
  2759 "/        self updateLabelsAndHistory.
  2611     ]
  2760     ]
  2612 
  2761 
  2613     "Created: / 12.3.1999 / 00:20:28 / cg"
  2762     "Created: / 12.3.1999 / 00:20:28 / cg"
  2614     "Modified: / 16.3.1999 / 21:57:26 / cg"
  2763     "Modified: / 16.3.1999 / 21:57:26 / cg"
       
  2764 !
       
  2765 
       
  2766 pasteMask
       
  2767     |img mask|
       
  2768 
       
  2769     imageEditView makeUndo.
       
  2770 
       
  2771     img := self image.
       
  2772     mask := img mask.
       
  2773 
       
  2774     mask 
       
  2775          copyFrom:MaskClipboard
       
  2776          x:0 y:0
       
  2777          toX:0 y:0 
       
  2778          width:(mask width min:MaskClipboard width)
       
  2779          height:(mask height min:MaskClipboard height).
       
  2780     img mask:mask.
       
  2781     (imageEditView image:img copy) notNil ifTrue:[
       
  2782         self fetchImageData.
       
  2783     ]
  2615 !
  2784 !
  2616 
  2785 
  2617 reduceNumberOfColors
  2786 reduceNumberOfColors
  2618     |s n anyChange img|
  2787     |s n anyChange img|
  2619 
  2788 
  2973         imageEditView rotateImageBy:rotation.
  3142         imageEditView rotateImageBy:rotation.
  2974         self updateInfoLabel
  3143         self updateInfoLabel
  2975     ].
  3144     ].
  2976 !
  3145 !
  2977 
  3146 
       
  3147 doUnCropManual
       
  3148     "let user specify borders and add them"
       
  3149 
       
  3150     |bindings left top right bottom img|
       
  3151 
       
  3152     bindings := IdentityDictionary new.
       
  3153     bindings at:#left put:(left := 0 asValue).
       
  3154     bindings at:#right put:(right := 0 asValue).
       
  3155     bindings at:#top put:(top := 0 asValue).
       
  3156     bindings at:#bottom put:(bottom := 0 asValue).
       
  3157     (self openDialogInterface:#ungropDialogSpec withBindings:bindings)
       
  3158     ifTrue:[
       
  3159         left := left value.
       
  3160         right := right value.
       
  3161         top := top value.
       
  3162         bottom := bottom value.
       
  3163         img := imageEditView image.
       
  3164 
       
  3165         imageEditView
       
  3166             makeBorderedImageX:left y:top 
       
  3167             width:(img width + left + right)
       
  3168             height:(img height + top + bottom).
       
  3169         self updateInfoLabel
       
  3170     ].
       
  3171 
       
  3172     "Created: / 7.9.1998 / 18:16:07 / cg"
       
  3173     "Modified: / 7.9.1998 / 18:20:42 / cg"
       
  3174 !
       
  3175 
  2978 doUndo
  3176 doUndo
  2979     "reverses last edit action"
  3177     "reverses last edit action"
  2980 
  3178 
  2981     imageEditView undo.
  3179     imageEditView undo.
  2982 ! !
  3180 ! !