1124 self listOfColors isEmpty |
1124 self listOfColors isEmpty |
1125 ifTrue: |
1125 ifTrue: |
1126 [ |
1126 [ |
1127 self colorMapMode: colorMapMode value: nil |
1127 self colorMapMode: colorMapMode value: nil |
1128 ]. |
1128 ]. |
1129 self imageEditView selectColors: (Array with: (self listOfColors at: 1) with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1])). |
1129 imageEditView selectColors: (Array with: (self listOfColors at: 1) with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1])). |
1130 |
1130 |
1131 self image mask notNil |
1131 self image mask notNil |
1132 ifTrue: |
1132 ifTrue: |
1133 [ |
1133 [ |
1134 colorMapMode := colorMapMode, ' + mask'. |
1134 colorMapMode := colorMapMode, ' + mask'. |
1135 (self listOfColors detect: [:clr| clr = (Color basicNew setColorId:0)] ifNone: nil) isNil |
1135 (self listOfColors detect: [:clr| clr = (Color basicNew setColorId:0)] ifNone: nil) isNil |
1136 ifTrue: |
1136 ifTrue: |
1137 [ |
1137 [ |
1138 self listOfColors addFirst: (Color basicNew setColorId:0). |
1138 self listOfColors addFirst: (Color basicNew setColorId:0). |
1139 self imageEditView selectColors: (Array with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1]) with: (self listOfColors at: 1)). |
1139 imageEditView selectColors: (Array with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1]) with: (self listOfColors at: 1)). |
1140 ] |
1140 ] |
1141 ]. |
1141 ]. |
1142 self selectionOfColor value: 0. |
1142 self selectionOfColor value: 0. |
1143 self selectionOfColor value: (self listOfColors indexOf: self imageEditView selectedColor). |
1143 self selectionOfColor value: (self listOfColors indexOf: imageEditView selectedColor). |
1144 ! |
1144 ! |
1145 |
1145 |
1146 updateForNoneImage |
1146 updateForNoneImage |
1147 "updates channels and view, if image is loaded" |
1147 "updates channels and view, if image is loaded" |
1148 |
1148 |
1162 |
1162 |
1163 self image isNil ifTrue: [^nil]. |
1163 self image isNil ifTrue: [^nil]. |
1164 |
1164 |
1165 self updateInfoLabel. |
1165 self updateInfoLabel. |
1166 |
1166 |
1167 self imageEditView resourceMessage asCollectionOfWords size = 2 |
1167 imageEditView resourceMessage asCollectionOfWords size = 2 |
1168 ifTrue: [self addToHistory: self imageEditView resourceMessage -> #loadFromMessage:]. |
1168 ifTrue: [self addToHistory: imageEditView resourceMessage -> #loadFromMessage:]. |
1169 |
1169 |
1170 self image fileName notNil |
1170 self image fileName notNil |
1171 ifTrue: [self addToHistory: self image fileName -> #loadFromFile:]. |
1171 ifTrue: [self addToHistory: self image fileName -> #loadFromFile:]. |
1172 |
1172 |
1173 |
1173 |
1177 !ImageEditor methodsFor:'help'! |
1177 !ImageEditor methodsFor:'help'! |
1178 |
1178 |
1179 defaultInfoLabel |
1179 defaultInfoLabel |
1180 "returns the default info label" |
1180 "returns the default info label" |
1181 |
1181 |
1182 (self imageEditView resourceClass isSymbol and: [(Smalltalk at: self imageEditView resourceClass) isClass]) |
1182 (imageEditView resourceClass isSymbol and: [(Smalltalk at: imageEditView resourceClass) isClass]) |
1183 ifTrue: |
1183 ifTrue: |
1184 [ |
1184 [ |
1185 ^self imageEditView resourceClass, ' >> ', self imageEditView resourceSelector |
1185 ^imageEditView resourceClass, ' >> ', imageEditView resourceSelector |
1186 ]. |
1186 ]. |
1187 ^'No class and selector defined.' |
1187 ^'No class and selector defined.' |
1188 ! |
1188 ! |
1189 |
1189 |
1190 openDocumentation |
1190 openDocumentation |
1272 loadFromOrPrepareForMessage: aMessage |
1272 loadFromOrPrepareForMessage: aMessage |
1273 "loads an image by evaluating aMessage; |
1273 "loads an image by evaluating aMessage; |
1274 if no image could extract from aMessage; do set the class and the selector from |
1274 if no image could extract from aMessage; do set the class and the selector from |
1275 the aMessage for a saving at the end of editing" |
1275 the aMessage for a saving at the end of editing" |
1276 |
1276 |
1277 (self imageEditView loadFromMessage: aMessage) notNil |
1277 (imageEditView loadFromMessage: aMessage) notNil |
1278 ifTrue: |
1278 ifTrue: |
1279 [ |
1279 [ |
1280 self listOfColors contents: self image usedColors asSet asOrderedCollection. |
1280 self listOfColors contents: self image usedColors asSet asOrderedCollection. |
1281 self findColorMapMode. |
1281 self findColorMapMode. |
1282 ] |
1282 ] |
1283 ifFalse: |
1283 ifFalse: |
1284 [ |
1284 [ |
1285 self imageEditView resourceMessage: aMessage. |
1285 imageEditView resourceMessage: aMessage. |
1286 ]. |
1286 ]. |
1287 self updateLabelsAndHistory. |
1287 self updateLabelsAndHistory. |
1288 ! ! |
1288 ! ! |
1289 |
1289 |
1290 !ImageEditor methodsFor:'menu modes'! |
1290 !ImageEditor methodsFor:'menu modes'! |
1298 colorMapMode: aMode value: aValue |
1298 colorMapMode: aMode value: aValue |
1299 "calculates a new color map for the image from aMode" |
1299 "calculates a new color map for the image from aMode" |
1300 |
1300 |
1301 |depth newColorMap newImage image newColors realColorMap oldFileName| |
1301 |depth newColorMap newImage image newColors realColorMap oldFileName| |
1302 |
1302 |
1303 self imageEditView makeUndo. |
1303 imageEditView makeUndo. |
1304 |
1304 |
1305 newColorMap := self class listOfColorMaps at: aMode. |
1305 newColorMap := self class listOfColorMaps at: aMode. |
1306 depth := (newColorMap size log: 2) asInteger. |
1306 depth := (newColorMap size log: 2) asInteger. |
1307 newImage := (Image implementorForDepth: depth) new. |
1307 newImage := (Image implementorForDepth: depth) new. |
1308 oldFileName := self image fileName. |
1308 oldFileName := self image fileName. |
1309 |
1309 |
1310 Object errorSignal handle: |
1310 Object errorSignal handle: |
1311 [:ex| |
1311 [:ex| |
1312 Object errorSignal handle: |
1312 Object errorSignal handle: |
1313 [:ex| |
1313 [:ex| |
|
1314 imageEditView undo. |
1314 ^self warn: 'Convertation failed!!' |
1315 ^self warn: 'Convertation failed!!' |
1315 ] |
1316 ] |
1316 do: |
1317 do: |
1317 [ |
1318 [ |
1318 self image colorsFromX:0 y:0 toX:(self image width-1) y:(self image height-1) do: |
1319 self image colorsFromX:0 y:0 toX:(self image width-1) y:(self image height-1) do: |
1356 newColors add: clr |
1357 newColors add: clr |
1357 ] |
1358 ] |
1358 ]. |
1359 ]. |
1359 image colorMap: newColors. |
1360 image colorMap: newColors. |
1360 colorMapMode := aMode. |
1361 colorMapMode := aMode. |
1361 (self imageEditView image: image) notNil |
1362 (imageEditView image: image) notNil |
1362 ifTrue: |
1363 ifTrue: |
1363 [ |
1364 [ |
1364 self image fileName: oldFileName. |
1365 self image fileName: oldFileName. |
1365 self listOfColors contents: image colorMap. |
1366 self listOfColors contents: image colorMap. |
1366 self findColorMapMode. |
1367 self findColorMapMode. |
1369 ! |
1370 ! |
1370 |
1371 |
1371 editMode: aMode |
1372 editMode: aMode |
1372 "returns whether editMode is equal to aMode" |
1373 "returns whether editMode is equal to aMode" |
1373 |
1374 |
1374 ^self imageEditView editMode = aMode |
1375 ^imageEditView editMode = aMode |
1375 ! |
1376 ! |
1376 |
1377 |
1377 editMode: aMode value: aValue |
1378 editMode: aMode value: aValue |
1378 "sets the editMode to aMode" |
1379 "sets the editMode to aMode" |
1379 |
1380 |
1380 self imageEditView editMode: aMode |
1381 imageEditView editMode: aMode |
1381 ! |
1382 ! |
1382 |
1383 |
1383 mouseKeyColorMode: aMode |
1384 mouseKeyColorMode: aMode |
1384 "sets the mouseKeyColorMode to aMode" |
1385 "sets the mouseKeyColorMode to aMode" |
1385 |
1386 |
1386 ^self imageEditView mouseKeyColorMode = aMode |
1387 ^imageEditView mouseKeyColorMode = aMode |
1387 ! |
1388 ! |
1388 |
1389 |
1389 mouseKeyColorMode: aMode value: aValue |
1390 mouseKeyColorMode: aMode value: aValue |
1390 "sets the mouseKeyColorMode to aMode" |
1391 "sets the mouseKeyColorMode to aMode" |
1391 |
1392 |
1392 self imageEditView mouseKeyColorMode: aMode. |
1393 imageEditView mouseKeyColorMode: aMode. |
1393 |
1394 |
1394 self selectionOfColor value: (self listOfColors indexOf: self imageEditView selectedColor). |
1395 self selectionOfColor value: (self listOfColors indexOf: imageEditView selectedColor). |
1395 ! ! |
1396 ! ! |
1396 |
1397 |
1397 !ImageEditor methodsFor:'queries'! |
1398 !ImageEditor methodsFor:'queries'! |
1398 |
1399 |
1399 preferredExtent |
1400 preferredExtent |
1407 !ImageEditor methodsFor:'selection'! |
1408 !ImageEditor methodsFor:'selection'! |
1408 |
1409 |
1409 magnification |
1410 magnification |
1410 "returns the magnification of the image" |
1411 "returns the magnification of the image" |
1411 |
1412 |
1412 (builder componentAt: #imageEditView) isNil ifTrue: [^1]. |
1413 self imageEditView isNil ifTrue: [^1]. |
1413 ^self imageEditView magnification x |
1414 ^imageEditView magnification x |
1414 ! |
1415 ! |
1415 |
1416 |
1416 magnification: aValue |
1417 magnification: aValue |
1417 "sets the magnification of the image" |
1418 "sets the magnification of the image" |
1418 |
1419 |
1419 |magnification| |
1420 |magnification| |
1420 magnification := (aValue ? 1) asPoint. |
1421 magnification := (aValue ? 1) asPoint. |
1421 (magnification = self imageEditView magnification or: [magnification = (0@0)]) ifTrue: [^nil]. |
1422 (magnification = imageEditView magnification or: [magnification = (0@0)]) ifTrue: [^nil]. |
1422 self imageEditView magnification: magnification |
1423 imageEditView magnification: magnification |
1423 ! |
1424 ! |
1424 |
1425 |
1425 selectedColorIndex |
1426 selectedColorIndex |
1426 "returns the index of the selected color" |
1427 "returns the index of the selected color" |
1427 |
1428 |
1430 |
1431 |
1431 selectedColorIndex: anIndex |
1432 selectedColorIndex: anIndex |
1432 "sets the index of the selected color" |
1433 "sets the index of the selected color" |
1433 |
1434 |
1434 selectedColorIndex := anIndex. |
1435 selectedColorIndex := anIndex. |
1435 self imageEditView selectedColor: (self listOfColors at: anIndex ifAbsent: [^nil]) |
1436 imageEditView selectedColor: (self listOfColors at: anIndex ifAbsent: [^nil]) |
1436 |
1437 |
1437 ! ! |
1438 ! ! |
1438 |
1439 |
1439 !ImageEditor methodsFor:'startup / release'! |
1440 !ImageEditor methodsFor:'startup / release'! |
1440 |
1441 |
1441 closeRequest |
1442 closeRequest |
1442 "close request" |
1443 "close request" |
1443 |
1444 |
1444 self imageEditView checkModified ifTrue:[super closeRequest] |
1445 imageEditView checkModified ifTrue:[super closeRequest] |
1445 |
1446 |
1446 ! |
1447 ! |
1447 |
1448 |
1448 open |
1449 open |
1449 "after opening, sets the masterApplication of the imageEditView to self" |
1450 "after opening, sets the masterApplication of the imageEditView to self" |
1450 |
1451 |
1451 super open. |
1452 super open. |
1452 |
1453 |
1453 self imageEditView masterApplication: self |
1454 imageEditView := (builder componentAt: #imageEditView) subViews first. |
|
1455 imageEditView masterApplication: self |
1454 ! |
1456 ! |
1455 |
1457 |
1456 postOpenWith:aBuilder |
1458 postOpenWith:aBuilder |
1457 "after opening, sets the masterApplication of the imageEditView to self; |
1459 "after opening, sets the masterApplication of the imageEditView to self; |
1458 evaluate the postOpenAction" |
1460 evaluate the postOpenAction" |
1459 |
1461 |
1460 self imageEditView masterApplication: self. |
1462 imageEditView masterApplication: self. |
1461 postOpenAction notNil ifTrue: [postOpenAction value]. |
1463 postOpenAction notNil ifTrue: [postOpenAction value]. |
1462 |
1464 |
1463 super postOpenWith:aBuilder |
1465 super postOpenWith:aBuilder |
1464 ! ! |
1466 ! ! |
1465 |
1467 |
1466 !ImageEditor methodsFor:'user actions - editing'! |
1468 !ImageEditor methodsFor:'user actions - editing'! |
1467 |
1469 |
1468 doBrowseClass |
1470 doBrowseClass |
1469 "opens a System Browser on the resourceClass and the resourceSelector" |
1471 "opens a System Browser on the resourceClass and the resourceSelector" |
1470 |
1472 |
1471 SystemBrowser openInClass: (Smalltalk at: self imageEditView resourceClass ifAbsent: [^nil]) class selector: self imageEditView resourceSelector |
1473 SystemBrowser openInClass: (Smalltalk at: imageEditView resourceClass ifAbsent: [^nil]) class selector: imageEditView resourceSelector |
1472 ! |
1474 ! |
1473 |
1475 |
1474 doChangeGridMagnification |
1476 doChangeGridMagnification |
1475 "change grid magnification" |
1477 "change grid magnification" |
1476 |
1478 |
1477 self imageEditView changeGridMagnification |
1479 imageEditView changeGridMagnification |
1478 ! |
1480 ! |
1479 |
1481 |
1480 doFlipHorizontal |
1482 doFlipHorizontal |
1481 "flips horizontally current image" |
1483 "flips horizontally current image" |
1482 |
1484 |
1483 self imageEditView flipHorizontal |
1485 imageEditView flipHorizontal |
1484 ! |
1486 ! |
1485 |
1487 |
1486 doFlipVertical |
1488 doFlipVertical |
1487 "flips vertically current image" |
1489 "flips vertically current image" |
1488 |
1490 |
1489 self imageEditView flipVertical |
1491 imageEditView flipVertical |
1490 ! |
1492 ! |
1491 |
1493 |
1492 doMagnifyDown |
1494 doMagnifyDown |
1493 "magnifies current image one step down" |
1495 "magnifies current image one step down" |
1494 |
1496 |
1517 ! |
1519 ! |
1518 |
1520 |
1519 doNegativeImage |
1521 doNegativeImage |
1520 "negates current image by negating the color map" |
1522 "negates current image by negating the color map" |
1521 |
1523 |
1522 self imageEditView negativeImage. |
1524 imageEditView negativeImage. |
1523 self listOfColors removeAll. |
1525 self listOfColors removeAll. |
1524 self findColorMapMode. |
1526 self findColorMapMode. |
1525 self imageEditView undoImages removeLast |
1527 imageEditView undoImages removeLast |
1526 ! |
1528 ! |
1527 |
1529 |
1528 doResizeImage |
1530 doResizeImage |
1529 "resizes current image" |
1531 "resizes current image" |
1530 |
1532 |
1531 self imageEditView resizeImage. |
1533 imageEditView resizeImage. |
1532 self updateInfoLabel |
1534 self updateInfoLabel |
1533 ! |
1535 ! |
1534 |
1536 |
1535 doRotateImage |
1537 doRotateImage |
1536 "rotates current image" |
1538 "rotates current image" |
1537 |
1539 |
1538 self imageEditView rotateImage. |
1540 imageEditView rotateImage. |
1539 self updateInfoLabel |
1541 self updateInfoLabel |
1540 ! |
1542 ! |
1541 |
1543 |
1542 doUndo |
1544 doUndo |
1543 "reverses last edit action" |
1545 "reverses last edit action" |
1544 |
1546 |
1545 self imageEditView undo |
1547 imageEditView undo |
1546 ! ! |
1548 ! ! |
1547 |
1549 |
1548 !ImageEditor methodsFor:'user actions - loading'! |
1550 !ImageEditor methodsFor:'user actions - loading'! |
1549 |
1551 |
1550 doLoadFromClass |
1552 doLoadFromClass |
1551 "opens a dialog for loading an image from class and a (resource-) selector" |
1553 "opens a dialog for loading an image from class and a (resource-) selector" |
1552 |
1554 |
1553 (self imageEditView loadFromClass) notNil |
1555 (imageEditView loadFromClass) notNil |
1554 ifTrue: |
1556 ifTrue: |
1555 [ |
1557 [ |
1556 self image notNil |
1558 self image notNil |
1557 ifTrue: |
1559 ifTrue: |
1558 [ |
1560 [ |
1606 [ |
1608 [ |
1607 image mask: (Depth1Image width: width height: height depth: 1 fromArray: (ByteArray new: width*height)) clearMaskedPixels |
1609 image mask: (Depth1Image width: width height: height depth: 1 fromArray: (ByteArray new: width*height)) clearMaskedPixels |
1608 ]. |
1610 ]. |
1609 image colorMap: cMap. |
1611 image colorMap: cMap. |
1610 image fillRectangleX:0 y:0 width:width height:height with:Color white. |
1612 image fillRectangleX:0 y:0 width:width height:height with:Color white. |
1611 (self imageEditView image: image) notNil |
1613 (imageEditView image: image) notNil |
1612 ifTrue: |
1614 ifTrue: |
1613 [ |
1615 [ |
1614 self listOfColors contents: cMap. |
1616 self listOfColors contents: cMap. |
1615 self findColorMapMode. |
1617 self findColorMapMode. |
1616 self updateLabelsAndHistory |
1618 self updateLabelsAndHistory |
1621 !ImageEditor methodsFor:'user actions - saving'! |
1623 !ImageEditor methodsFor:'user actions - saving'! |
1622 |
1624 |
1623 doPrint |
1625 doPrint |
1624 "prints current image on the current printer" |
1626 "prints current image on the current printer" |
1625 |
1627 |
1626 self imageEditView print |
1628 imageEditView print |
1627 ! |
1629 ! |
1628 |
1630 |
1629 doSaveImageFile |
1631 doSaveImageFile |
1630 "saves current image to current file" |
1632 "saves current image to current file" |
1631 |
1633 |
1632 self imageEditView save |
1634 imageEditView save |
1633 ! |
1635 ! |
1634 |
1636 |
1635 doSaveImageFileAs |
1637 doSaveImageFileAs |
1636 "opens a dialog for saving current image to a file" |
1638 "opens a dialog for saving current image to a file" |
1637 |
1639 |
1638 self imageEditView saveImageFileAs. |
1640 imageEditView saveImageFileAs. |
1639 self updateLabelsAndHistory |
1641 self updateLabelsAndHistory |
1640 ! |
1642 ! |
1641 |
1643 |
1642 doSaveImageMaskFileAs |
1644 doSaveImageMaskFileAs |
1643 "opens a dialog for saving mask of current image to a file" |
1645 "opens a dialog for saving mask of current image to a file" |
1644 |
1646 |
1645 self imageEditView saveImageMaskFileAs |
1647 imageEditView saveImageMaskFileAs |
1646 ! |
1648 ! |
1647 |
1649 |
1648 doSaveMethod |
1650 doSaveMethod |
1649 "saves current image on current class and selector" |
1651 "saves current image on current class and selector" |
1650 |
1652 |
1651 self imageEditView saveMethod notNil |
1653 imageEditView saveMethod notNil |
1652 ifTrue: |
1654 ifTrue: |
1653 [ |
1655 [ |
1654 self updateLabelsAndHistory |
1656 self updateLabelsAndHistory |
1655 ] |
1657 ] |
1656 ! |
1658 ! |
1657 |
1659 |
1658 doSaveMethodAs |
1660 doSaveMethodAs |
1659 "opens a dialog for saving current image on a class and a selector" |
1661 "opens a dialog for saving current image on a class and a selector" |
1660 |
1662 |
1661 self imageEditView saveMethodAs notNil |
1663 imageEditView saveMethodAs notNil |
1662 ifTrue: |
1664 ifTrue: |
1663 [ |
1665 [ |
1664 self updateLabelsAndHistory |
1666 self updateLabelsAndHistory |
1665 ] |
1667 ] |
1666 ! ! |
1668 ! ! |