#DOCUMENTATION by cg
authorClaus Gittinger <cg@exept.de>
Thu, 31 Aug 2017 11:45:30 +0200
changeset 8138 7633000935c0
parent 8137 4d18d8b42894
child 8139 cd6862cfe1d7
#DOCUMENTATION by cg class: Form added: #flip: changed: #darkened #flipHorizontal #flipVertical #lightened class: Form class comment/format in: #documentation
Form.st
--- a/Form.st	Thu Aug 31 10:38:52 2017 +0200
+++ b/Form.st	Thu Aug 31 11:45:30 2017 +0200
@@ -47,35 +47,39 @@
 
 documentation
 "
-    Instances of this class represent forms (i.e. bit- and pixmaps)
-    which can be created on a drawing device.
-    In X, these device resources are XPixmaps.
-    Not all devices will support forms.
+    NOTICE:
+        Not for public use.
+
+        the Form class is a historic leftover and now only used for real
+        device forms (i.e. on devices which support downloading bitmaps).
 
-    NOTICE:
-	the Form class is a historic leftover and now only used for real
-	device forms (i.e. on devices which support downloading bitmaps).
+        In your application, you should always use Image, both for compatibility
+        with ST-80 and for device independence, since not all Form depths are supported
+        by all devices, whereas Image contains all the rewuired code to convert as
+        required.
 
-	In your application, you should always use Image, both for compatibility
-	with ST-80 and for device independence, since Form may not be supported
-	by all devices.
+    
+    Instances of this class represent forms (i.e. bit- and pixmaps)
+    which are present on a drawing device.
+    
+    In X, these are XPixmaps; on Windows, these are bitmaps.
 
     WARNING:
-	Forms created on some device may not be recreatable, when an
-	image is restarted on a display with different display capabilities.
-	For example, a 24bit truecolor form will be lost when the image is
-	saved and restarted in an 8bit or monochrome display.
-	Worse: the information is completely lost.
+        Forms created on some device may not be recreatable, when an
+        image is restarted on a display with different display capabilities.
+        For example, a 24bit truecolor form will be lost when the image is
+        saved and restarted in an 8bit or monochrome display.
+        Worse: the information is completely lost.
 
-	With images, the original information is always preserved, although
-	the display may be with less resolution, dithered or otherwise
-	approximated.
+        With images, the original information is always preserved, although
+        the display may be with less resolution, dithered or otherwise
+        approximated.
 
     [See also:]
-	Image DeviceDrawable
+        Image DeviceDrawable
 
     [author:]
-	Claus Gittinger
+        Claus Gittinger
 "
 ! !
 
@@ -1116,7 +1120,6 @@
 ! !
 
 
-
 !Form methodsFor:'converting'!
 
 asForm
@@ -1293,9 +1296,10 @@
      Here, the receiver is returned as a kludge
      - actually should return a darkened image (or Color black ?) .."
 
+    'Form [warning]: ignored lightened request' infoPrintCR.
     ^ self
 
-    "Modified: 23.4.1996 / 10:19:52 / cg"
+    "Modified: / 31-08-2017 / 11:42:15 / cg"
 !
 
 easyMagnifiedBy:extent into: newForm
@@ -1351,22 +1355,25 @@
     "
 !
 
-flipHorizontal
-    "return a new form flipped vertically"
+flip:how
+    "return a new form flipped horizontally or vertically"
 
-    |dstX newForm |
+    |dstX dstY newForm |
 
     newForm := (self class onDevice:device)
-                                width:width
-                                height:height
-                                depth:depth.
-    dstX := width - 1.
-    0 to:dstX do:[:srcX |
-        newForm copyFrom:self
-                       x:srcX y:0
-                     toX:dstX y:0
-                   width:1 height:height.
-        dstX := dstX - 1
+                    width:width height:height depth:depth.
+    how == #horizontal ifTrue:[
+        dstX := width - 1.
+        0 to:dstX do:[:srcX |
+            newForm copyFrom:self x:srcX y:0 toX:dstX y:0 width:1 height:height.
+            dstX := dstX - 1
+        ].
+    ] ifFalse:[    
+        dstY := height - 1.
+        0 to:dstY do:[:srcY |
+            newForm copyFrom:self x:0 y:srcY toX:0 y:dstY width:width height:1.
+            dstY := dstY - 1
+        ].
     ].
     newForm colorMap:localColorMap.
     ^ newForm
@@ -1388,30 +1395,46 @@
                         2r11111111)
                     offset: 0@0.
      testForm inspect.
+     (testForm flip:#vertical) inspect.
+     (testForm flip:#horizontal) inspect.
+    "
+
+    "Created: / 31-08-2017 / 11:38:16 / cg"
+!
+
+flipHorizontal
+    "return a new form flipped vertically"
+
+    ^ self flip:#horizontal
+
+    "
+     |testForm|
+
+     testForm := Form
+                    extent: 8@8
+                    depth: 1
+                    fromArray:
+                     #( 2r10000000
+                        2r11000000
+                        2r11100000
+                        2r11110000
+                        2r11111000
+                        2r11111100
+                        2r11111110
+                        2r11111111)
+                    offset: 0@0.
+     testForm inspect.
      testForm flipVertical inspect.
      testForm flipHorizontal inspect.
     "
+
+    "Modified: / 31-08-2017 / 11:41:46 / cg"
 !
 
 flipVertical
     "return a new form flipped horizontally"
 
-    |dstY newForm |
-
-    newForm := (self class onDevice:device)
-                                width:width
-                                height:height
-                                depth:depth.
-    dstY := height - 1.
-    0 to:dstY do:[:srcY |
-        newForm copyFrom:self
-                       x:0 y:srcY
-                     toX:0 y:dstY
-                   width:width height:1.
-        dstY := dstY - 1
-    ].
-    newForm colorMap:localColorMap.
-    ^ newForm
+    ^ self flip:#vertical
 
     "
      |testForm|
@@ -1433,6 +1456,8 @@
      testForm flipVertical inspect.
      testForm flipHorizontal inspect.
     "
+
+    "Modified: / 31-08-2017 / 11:41:54 / cg"
 !
 
 hardMagnifiedBy:extent
@@ -1455,12 +1480,13 @@
 lightened
     "return a lightened version of the receiver.
      Added for protocol compatibility with Color and Image.
-     Here, the receiver is returned as a kludge
+     Here, the receiver is returned unchanged as a kludge
      - actually should return a lightened image (or Color white ?) .."
 
+    'Form [warning]: ignored lightened request' infoPrintCR.
     ^ self
 
-    "Modified: 23.4.1996 / 10:20:14 / cg"
+    "Modified: / 31-08-2017 / 11:36:32 / cg"
 !
 
 magnifiedBy:extent