DeviceGraphicsContext.st
changeset 1085 3513a4cae87b
parent 1064 2d0783c97f32
child 1092 1b6391f333de
equal deleted inserted replaced
1084:9c433066e960 1085:3513a4cae87b
    15 	classVariableNames:'CachedScaledForms CachedScales Lobby'
    15 	classVariableNames:'CachedScaledForms CachedScales Lobby'
    16 	poolDictionaries:''
    16 	poolDictionaries:''
    17 	category:'Graphics-Support'
    17 	category:'Graphics-Support'
    18 !
    18 !
    19 
    19 
    20 !DeviceGraphicsContext  class methodsFor:'documentation'!
    20 !DeviceGraphicsContext class methodsFor:'documentation'!
    21 
    21 
    22 copyright
    22 copyright
    23 "
    23 "
    24  COPYRIGHT (c) 1992 by Claus Gittinger
    24  COPYRIGHT (c) 1992 by Claus Gittinger
    25 	      All Rights Reserved
    25 	      All Rights Reserved
    73 	Claus Gittinger
    73 	Claus Gittinger
    74 
    74 
    75 "
    75 "
    76 ! !
    76 ! !
    77 
    77 
    78 !DeviceGraphicsContext  class methodsFor:'initialization'!
    78 !DeviceGraphicsContext class methodsFor:'initialization'!
    79 
    79 
    80 initialize
    80 initialize
    81     Lobby isNil ifTrue:[
    81     Lobby isNil ifTrue:[
    82 	Lobby := Registry new.
    82 	Lobby := Registry new.
    83     ]
    83     ]
    84 ! !
    84 ! !
    85 
    85 
    86 !DeviceGraphicsContext  class methodsFor:'instance creation'!
    86 !DeviceGraphicsContext class methodsFor:'instance creation'!
    87 
    87 
    88 new
    88 new
    89     "create a new drawable - take the current display as
    89     "create a new drawable - take the current display as
    90      its device (for now, this may be changed until the view is
    90      its device (for now, this may be changed until the view is
    91      physically created)"
    91      physically created)"
   118     newDrawable initialize.
   118     newDrawable initialize.
   119     Lobby register:newDrawable.
   119     Lobby register:newDrawable.
   120     ^ newDrawable
   120     ^ newDrawable
   121 ! !
   121 ! !
   122 
   122 
   123 !DeviceGraphicsContext  class methodsFor:'cleanup'!
   123 !DeviceGraphicsContext class methodsFor:'cleanup'!
   124 
   124 
   125 lowSpaceCleanup
   125 lowSpaceCleanup
   126     CachedScaledForms := CachedScales := nil
   126     CachedScaledForms := CachedScales := nil
   127 ! !
   127 ! !
   128 
   128 
  1843 
  1843 
  1844     deviceForm := aForm asFormOn:device.
  1844     deviceForm := aForm asFormOn:device.
  1845     id := deviceForm id.
  1845     id := deviceForm id.
  1846 
  1846 
  1847     id isNil ifTrue:[
  1847     id isNil ifTrue:[
  1848 	deviceForm := aForm asFormOn:device.
  1848         deviceForm := aForm asFormOn:device.
  1849 	id := deviceForm id.
  1849         id := deviceForm id.
  1850 	id isNil ifTrue:[
  1850         id isNil ifTrue:[
  1851 	    'DEVGC: invalid form draw - ignored' errorPrintNL.
  1851             'DEVGC: invalid form draw - ignored' errorPrintNL.
  1852 	    ^ self
  1852             ^ self
  1853 	].
  1853         ].
  1854     ].
  1854     ].
  1855     gcId isNil ifTrue:[
  1855     gcId isNil ifTrue:[
  1856 	self initGC
  1856         self initGC
  1857     ].
  1857     ].
  1858 
  1858 
  1859     "
  1859     "
  1860      a deep form ignores paint/bgPaint settings
  1860      a deep form ignores paint/bgPaint settings
  1861     "
  1861     "
  1862     (aForm depth ~~ 1) ifTrue:[
  1862     mask := aForm mask.
  1863 	(mask := aForm mask) notNil ifTrue:[
  1863 
  1864 	    mask depth == 1 ifFalse:[
  1864     ((aForm depth ~~ 1) 
  1865 		'DEVGC: alpha channel not yet supported' errorPrintCR.
  1865     or:[mask notNil]) ifTrue:[
  1866 	    ] ifTrue:[
  1866         mask notNil ifTrue:[
  1867 		deviceMask := mask asFormOn:device.
  1867             mask depth == 1 ifFalse:[
  1868 		maskId := deviceMask id.
  1868                 'DEVGC: alpha channel not yet supported' errorPrintCR.
  1869 		maskId notNil ifTrue:[
  1869             ] ifTrue:[
  1870 		    "
  1870                 deviceMask := mask asFormOn:device.
  1871 		     create temp-form;
  1871                 maskId := deviceMask id.
  1872 		    "
  1872                 maskId notNil ifTrue:[
  1873 		    tmpForm := Form width:w height:h depth:device depth on:device.
  1873                     "
  1874 		    tmpForm initGC.
  1874                      create temp-form;
  1875 
  1875                     "
  1876 		    "
  1876                     tmpForm := Form width:w height:h depth:device depth on:device.
  1877 		     fill tempform with image
  1877                     tmpForm initGC.
  1878 		    "
  1878 
  1879 		    device
  1879                     "
  1880 			copyFromId:id
  1880                      fill tempform with image
  1881 				 x:0 y:0 gc:gcId
  1881                     "
  1882 				to:tmpForm id
  1882                     aForm depth == 1 ifTrue:[
  1883 				 x:0 y:0 gc:(tmpForm gcId)
  1883                         aForm colorMap notNil ifTrue:[
  1884 			     width:w height:h.
  1884                             device 
  1885 
  1885                                 setForeground:((aForm colorMap at:2) on:device) colorId 
  1886 		    allColor := Color allColor.
  1886                                 background:((aForm colorMap at:1) on:device) colorId 
  1887 		    allBits := allColor colorId.
  1887                                 in:tmpForm gcId.
  1888 
  1888                         ].
  1889 		    "
  1889                         device
  1890 		     stamp out mask in temp form
  1890                             copyPlaneFromId:id
  1891 		    "
  1891                                           x:0 y:0 gc:gcId
  1892 		    device setForeground:allBits background:0 in:tmpForm gcId.
  1892                                          to:tmpForm id
  1893 		    device setFunction:#and in:tmpForm gcId.
  1893                                           x:0 y:0 gc:tmpForm gcId
  1894 		    device
  1894                                       width:w height:h.
  1895 			copyPlaneFromId:maskId
  1895                     ] ifFalse:[
  1896 				      x:0 y:0 gc:(deviceMask gcId)
  1896                         device
  1897 				     to:tmpForm id
  1897                             copyFromId:id
  1898 				      x:0 y:0 gc:tmpForm gcId
  1898                                      x:0 y:0 gc:gcId
  1899 				  width:w height:h.
  1899                                     to:tmpForm id
  1900 
  1900                                      x:0 y:0 gc:(tmpForm gcId)
  1901 
  1901                                  width:w height:h.
  1902 		    "
  1902                     ].
  1903 		     stamp out mask in destination
  1903 
  1904 		    "
  1904                     allColor := Color allColor.
  1905 		    device setForeground:0 background:allBits in:gcId.
  1905                     allBits := allColor colorId.
  1906 		    device setFunction:#and in:gcId.
  1906 
  1907 		    device
  1907                     "
  1908 			copyPlaneFromId:maskId
  1908                      stamp out mask in temp form
  1909 				      x:0 y:0 gc:(deviceMask gcId)
  1909                     "
  1910 				     to:drawableId
  1910                     device setForeground:allBits background:0 in:tmpForm gcId.
  1911 				      x:pX y:pY gc:gcId
  1911                     device setFunction:#and in:tmpForm gcId.
  1912 				  width:w height:h.
  1912                     device
       
  1913                         copyPlaneFromId:maskId
       
  1914                                       x:0 y:0 gc:(deviceMask gcId)
       
  1915                                      to:tmpForm id
       
  1916                                       x:0 y:0 gc:tmpForm gcId
       
  1917                                   width:w height:h.
       
  1918 
       
  1919 
       
  1920                     "
       
  1921                      stamp out mask in destination
       
  1922                     "
       
  1923                     device setForeground:0 background:allBits in:gcId.
       
  1924                     device setFunction:#and in:gcId.
       
  1925                     device
       
  1926                         copyPlaneFromId:maskId
       
  1927                                       x:0 y:0 gc:(deviceMask gcId)
       
  1928                                      to:drawableId
       
  1929                                       x:pX y:pY gc:gcId
       
  1930                                   width:w height:h.
  1913     "/ Delay waitForSeconds:3.
  1931     "/ Delay waitForSeconds:3.
  1914 		    "
  1932                     "
  1915 		     or-in tempform-bits ...
  1933                      or-in tempform-bits ...
  1916 		    "
  1934                     "
  1917 		    device setFunction:#or in:gcId.
  1935                     device setFunction:#or in:gcId.
  1918 		    device
  1936                     device
  1919 			copyFromId:tmpForm id
  1937                         copyFromId:tmpForm id
  1920 				 x:0 y:0 gc:tmpForm gcId
  1938                                  x:0 y:0 gc:tmpForm gcId
  1921 				to:drawableId
  1939                                 to:drawableId
  1922 				 x:pX y:pY gc:gcId
  1940                                  x:pX y:pY gc:gcId
  1923 			     width:w height:h.
  1941                              width:w height:h.
  1924 
  1942 
  1925 		    foreground notNil ifTrue:[
  1943                     foreground notNil ifTrue:[
  1926 			device setForeground:foreground colorId in:gcId.
  1944                         device setForeground:foreground colorId in:gcId.
  1927 		    ].
  1945                     ].
  1928 		    background notNil ifTrue:[
  1946                     background notNil ifTrue:[
  1929 			device setBackground:background colorId in:gcId.
  1947                         device setBackground:background colorId in:gcId.
  1930 		    ].
  1948                     ].
  1931 		    device setFunction:function in:gcId.
  1949                     device setFunction:function in:gcId.
  1932 		    ^ self
  1950                     ^ self
  1933 		]
  1951                 ]
  1934 	    ]
  1952             ]
  1935 	].
  1953         ].
  1936 
  1954 
  1937 	device
  1955         device
  1938 	    copyFromId:id
  1956             copyFromId:id
  1939 		     x:0 y:0 gc:deviceForm gcId
  1957                      x:0 y:0 gc:deviceForm gcId
  1940 		    to:drawableId
  1958                     to:drawableId
  1941 		     x:pX y:pY gc:gcId
  1959                      x:pX y:pY gc:gcId
  1942 		 width:w height:h.
  1960                  width:w height:h.
  1943 	^ self
  1961         ^ self
  1944     ].
  1962     ].
  1945 
  1963 
  1946     "
  1964     "
  1947      the following code is somewhat complicated, since it has to deal
  1965      the following code is somewhat complicated, since it has to deal
  1948      with dithered paint colors, which cannot be done directly on most
  1966      with dithered paint colors, which cannot be done directly on most
  1953     "
  1971     "
  1954      if paint is not a real color, we have to do it the hard way ...
  1972      if paint is not a real color, we have to do it the hard way ...
  1955     "
  1973     "
  1956     easy := (function == #copy).
  1974     easy := (function == #copy).
  1957     easy ifTrue:[
  1975     easy ifTrue:[
  1958 	paint isColor ifFalse:[
  1976         paint isColor ifFalse:[
  1959 	    paintDither := paint.
  1977             paintDither := paint.
  1960 	    easy := false
  1978             easy := false
  1961 	] ifTrue:[
  1979         ] ifTrue:[
  1962 	    paintDither := paint ditherForm.
  1980             paintDither := paint ditherForm.
  1963 	    paintDither notNil ifTrue:[
  1981             paintDither notNil ifTrue:[
  1964 		easy := false.
  1982                 easy := false.
  1965 	    ]
  1983             ]
  1966 	].
  1984         ].
  1967     ].
  1985     ].
  1968 
  1986 
  1969     allColor := Color allColor.
  1987     allColor := Color allColor.
  1970     allBits := allColor colorId.
  1988     allBits := allColor colorId.
  1971 
  1989 
  1972     easy ifTrue:[
  1990     easy ifTrue:[
  1973 	"
  1991         "
  1974 	 paint is a real color
  1992          paint is a real color
  1975 	"
  1993         "
  1976 
  1994 
  1977 	"
  1995         "
  1978 	 if paint color is all-0 or all-1's, we can do it in one
  1996          if paint color is all-0 or all-1's, we can do it in one
  1979 	 operation ...
  1997          operation ...
  1980 	"
  1998         "
  1981 	fgId := paint colorId.
  1999         fgId := paint colorId.
  1982 
  2000 
  1983 	((fgId ~~ ((1 bitShift:device depth)-1))
  2001         ((fgId ~~ ((1 bitShift:device depth)-1))
  1984 	and:[fgId ~~ allBits]) ifTrue:[
  2002         and:[fgId ~~ allBits]) ifTrue:[
  1985 	    "
  2003             "
  1986 	     clear fg-bits ...
  2004              clear fg-bits ...
  1987 	    "
  2005             "
  1988 	    device setForeground:0 background:allBits in:gcId.
  2006             device setForeground:0 background:allBits in:gcId.
  1989 	    device setFunction:#and in:gcId.
  2007             device setFunction:#and in:gcId.
  1990 	    device
  2008             device
  1991 		copyPlaneFromId:id
  2009                 copyPlaneFromId:id
  1992 			      x:0 y:0 gc:(deviceForm gcId)
  2010                               x:0 y:0 gc:(deviceForm gcId)
  1993 			     to:drawableId
  2011                              to:drawableId
  1994 			      x:pX y:pY gc:gcId
  2012                               x:pX y:pY gc:gcId
  1995 			  width:w height:h.
  2013                           width:w height:h.
  1996 	].
  2014         ].
  1997 
  2015 
  1998 	fgId ~~ 0 ifTrue:[
  2016         fgId ~~ 0 ifTrue:[
  1999 	    "
  2017             "
  2000 	     or-in fg-bits ...
  2018              or-in fg-bits ...
  2001 	    "
  2019             "
  2002 	    device setForeground:fgId background:0 in:gcId.
  2020             device setForeground:fgId background:0 in:gcId.
  2003 	    device setFunction:#or in:gcId.
  2021             device setFunction:#or in:gcId.
  2004 	    device
  2022             device
  2005 		copyPlaneFromId:id
  2023                 copyPlaneFromId:id
  2006 			      x:0 y:0 gc:(deviceForm gcId)
  2024                               x:0 y:0 gc:(deviceForm gcId)
  2007 			     to:drawableId
  2025                              to:drawableId
  2008 			      x:pX y:pY gc:gcId
  2026                               x:pX y:pY gc:gcId
  2009 			  width:w height:h
  2027                           width:w height:h
  2010 	].
  2028         ].
  2011 	"
  2029         "
  2012 	 flush foreground/background cache
  2030          flush foreground/background cache
  2013 	"
  2031         "
  2014 	foreground := nil.
  2032         foreground := nil.
  2015 	background := nil.
  2033         background := nil.
  2016 	device setFunction:function in:gcId.
  2034         device setFunction:function in:gcId.
  2017 	^ self
  2035         ^ self
  2018     ].
  2036     ].
  2019 
  2037 
  2020 
  2038 
  2021     "
  2039     "
  2022      hard case; paint is a dithered color
  2040      hard case; paint is a dithered color
  2043      stamp out foreground from destination
  2061      stamp out foreground from destination
  2044     "
  2062     "
  2045     device setForeground:0 background:allBits in:gcId.
  2063     device setForeground:0 background:allBits in:gcId.
  2046     device setFunction:#and in:gcId.
  2064     device setFunction:#and in:gcId.
  2047     device
  2065     device
  2048 	copyPlaneFromId:id
  2066         copyPlaneFromId:id
  2049 		      x:0 y:0 gc:(deviceForm gcId)
  2067                       x:0 y:0 gc:(deviceForm gcId)
  2050 		     to:drawableId
  2068                      to:drawableId
  2051 		      x:pX y:pY gc:gcId
  2069                       x:pX y:pY gc:gcId
  2052 		  width:w height:h.
  2070                   width:w height:h.
  2053     "
  2071     "
  2054      or-in temp into destination
  2072      or-in temp into destination
  2055     "
  2073     "
  2056     device setForeground:allBits background:0 in:gcId.
  2074     device setForeground:allBits background:0 in:gcId.
  2057     device setFunction:#or in:gcId.
  2075     device setFunction:#or in:gcId.
  2058 
  2076 
  2059     device
  2077     device
  2060 	copyFromId:tmpForm id
  2078         copyFromId:tmpForm id
  2061 		 x:0 y:0 gc:tmpForm gcId
  2079                  x:0 y:0 gc:tmpForm gcId
  2062 		to:drawableId
  2080                 to:drawableId
  2063 		 x:pX y:pY gc:gcId
  2081                  x:pX y:pY gc:gcId
  2064 	     width:w height:h.
  2082              width:w height:h.
  2065     "
  2083     "
  2066      flush foreground/background cache
  2084      flush foreground/background cache
  2067     "
  2085     "
  2068     foreground := nil.
  2086     foreground := nil.
  2069     background := nil.
  2087     background := nil.
  2070     device setFunction:function in:gcId.
  2088     device setFunction:function in:gcId.
  2071 
  2089 
  2072     "Modified: 5.7.1996 / 17:57:02 / cg"
  2090     "Modified: 22.10.1996 / 16:55:29 / cg"
  2073 !
  2091 !
  2074 
  2092 
  2075 displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1
  2093 displayDeviceLineFromX:x0 y:y0 toX:x1 y:y1
  2076     "draw a line (with current paint-color) in device coordinate space.
  2094     "draw a line (with current paint-color) in device coordinate space.
  2077      This ignores any transformations. The coordinates must be integers."
  2095      This ignores any transformations. The coordinates must be integers."
  2107     id := deviceForm id.
  2125     id := deviceForm id.
  2108 
  2126 
  2109     "temporary ..."
  2127     "temporary ..."
  2110     (id isNil 
  2128     (id isNil 
  2111     or:[aForm graphicsDevice ~~ device]) ifTrue:[
  2129     or:[aForm graphicsDevice ~~ device]) ifTrue:[
  2112 	deviceForm := deviceForm asFormOn:device.
  2130         deviceForm := deviceForm asFormOn:device.
  2113 	id := deviceForm id.
  2131         id := deviceForm id.
  2114 	id isNil ifTrue:[
  2132         id isNil ifTrue:[
  2115 	    'DEVGC: invalid form draw - ignored' errorPrintNL.
  2133             'DEVGC: invalid form draw - ignored' errorPrintNL.
  2116 	    ^ self
  2134             ^ self
  2117 	].
  2135         ].
  2118     ].
  2136     ].
  2119 
  2137 
  2120     gcId isNil ifTrue:[
  2138     gcId isNil ifTrue:[
  2121 	self initGC
  2139         self initGC
  2122     ].
  2140     ].
  2123 
  2141 
  2124     "
  2142     "
  2125      a deep form ignores paint/bgPaint settings
  2143      a deep form ignores paint/bgPaint settings
  2126      and is always drawn opaque.
  2144      and is always drawn opaque.
  2127     "
  2145     "
  2128     (aForm depth ~~ 1) ifTrue:[
  2146     (aForm depth ~~ 1) ifTrue:[
  2129 	device
  2147         device
  2130 	    copyFromId:id
  2148             copyFromId:id
  2131 		     x:0 y:0 gc:deviceForm gcId
  2149                      x:0 y:0 gc:deviceForm gcId
  2132 		    to:drawableId
  2150                     to:drawableId
  2133 		     x:pX y:pY gc:gcId
  2151                      x:pX y:pY gc:gcId
  2134 		 width:w height:h.
  2152                  width:w height:h.
  2135 	^ self
  2153         ^ self
  2136     ].
  2154     ].
  2137 
  2155 
  2138     "/ if no bgPaint is set, this is a non-opaque draw
  2156     "/ if no bgPaint is set, this is a non-opaque draw
  2139 
  2157 
  2140     bgPaint isNil ifTrue:[
  2158     bgPaint isNil ifTrue:[
  2141 	self displayDeviceForm:aForm x:x y:y.
  2159         self displayDeviceForm:aForm x:x y:y.
  2142 	^ self
  2160         ^ self
  2143     ].
  2161     ].
  2144 
  2162 
  2145     "the following code is somewhat complicated, since it has to deal
  2163     "the following code is somewhat complicated, since it has to deal
  2146      with dithered fg/bg colors, which cannot be done directly on most
  2164      with dithered fg/bg colors, which cannot be done directly on most
  2147      devices (actually, a test for the devices capabilities has to be added here)
  2165      devices (actually, a test for the devices capabilities has to be added here)
  2151     "
  2169     "
  2152      if bgPaint or paint is not a real color, we have to do it the hard way ...
  2170      if bgPaint or paint is not a real color, we have to do it the hard way ...
  2153     "
  2171     "
  2154     easy := true.
  2172     easy := true.
  2155     paint isColor ifFalse:[
  2173     paint isColor ifFalse:[
  2156 	easy := false
  2174         easy := false
  2157     ] ifTrue:[
  2175     ] ifTrue:[
  2158 	fgId := paint colorId.
  2176         fgId := paint colorId.
  2159 	fgId isNil ifTrue:[
  2177         fgId isNil ifTrue:[
  2160 	    easy := false
  2178             easy := false
  2161 	]
  2179         ]
  2162     ].
  2180     ].
  2163     bgPaint isColor ifFalse:[
  2181     bgPaint isColor ifFalse:[
  2164 	easy := false
  2182         easy := false
  2165     ] ifTrue:[
  2183     ] ifTrue:[
  2166 	bgId := bgPaint colorId.
  2184         bgId := bgPaint colorId.
  2167 	bgId isNil ifTrue:[
  2185         bgId isNil ifTrue:[
  2168 	    easy := false
  2186             easy := false
  2169 	]
  2187         ]
  2170     ].
  2188     ].
  2171 
  2189 
  2172     easy ifTrue:[
  2190     easy ifTrue:[
  2173 	"
  2191         "
  2174 	 easy: both paint and bgPaint are real colors
  2192          easy: both paint and bgPaint are real colors
  2175 	"
  2193         "
  2176 	((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[
  2194         ((foreground ~~ paint) or:[background ~~ bgPaint]) ifTrue:[
  2177 	    device setForeground:fgId background:bgId in:gcId.
  2195             device setForeground:fgId background:bgId in:gcId.
  2178 	    foreground := paint.
  2196             foreground := paint.
  2179 	    background := bgPaint.
  2197             background := bgPaint.
  2180 	].
  2198         ].
  2181 	device
  2199         device
  2182 	    copyPlaneFromId:id
  2200             copyPlaneFromId:id
  2183 			  x:0 y:0 gc:(deviceForm gcId)
  2201                           x:0 y:0 gc:(deviceForm gcId)
  2184 			 to:drawableId
  2202                          to:drawableId
  2185 			  x:pX y:pY gc:gcId
  2203                           x:pX y:pY gc:gcId
  2186 		      width:w height:h.
  2204                       width:w height:h.
  2187 	^ self
  2205         ^ self
  2188     ].
  2206     ].
  2189 
  2207 
  2190     "
  2208     "
  2191      hard case: paint and/or bgPaint are dithered or patterns
  2209      hard case: paint and/or bgPaint are dithered or patterns
  2192     "
  2210     "
  2193     allColor := Color allColor.
  2211     allColor := Color allColor.
  2194     allBits := allColor colorId.
  2212     allBits := allColor colorId.
  2195     deviceDepth := device depth.
  2213     deviceDepth := device depth.
  2196 
  2214 
  2197     (fgId notNil and:[function == #copy]) ifTrue:[
  2215     (fgId notNil and:[function == #copy]) ifTrue:[
  2198 	"
  2216         "
  2199 	 only bg is dithered; fill with bg first ...
  2217          only bg is dithered; fill with bg first ...
  2200 	"
  2218         "
  2201 	savedPaint := paint.
  2219         savedPaint := paint.
  2202 	self paint:bgPaint.
  2220         self paint:bgPaint.
  2203 	self fillDeviceRectangleX:pX y:pY width:w height:h.
  2221         self fillDeviceRectangleX:pX y:pY width:w height:h.
  2204 	self paint:savedPaint.
  2222         self paint:savedPaint.
  2205 
  2223 
  2206 	"
  2224         "
  2207 	 if paint color is all-0 or all-1's, we can do it in one
  2225          if paint color is all-0 or all-1's, we can do it in one
  2208 	 operation ...
  2226          operation ...
  2209 	"
  2227         "
  2210 	((fgId ~~ ((1 bitShift:deviceDepth)-1))
  2228         ((fgId ~~ ((1 bitShift:deviceDepth)-1))
  2211 	and:[fgId ~~ allBits]) ifTrue:[
  2229         and:[fgId ~~ allBits]) ifTrue:[
  2212 	    "
  2230             "
  2213 	     clear fg-bits ...
  2231              clear fg-bits ...
  2214 	    "
  2232             "
  2215 	    device setForeground:0 background:allBits in:gcId.
  2233             device setForeground:0 background:allBits in:gcId.
  2216 	    device setFunction:#and in:gcId.
  2234             device setFunction:#and in:gcId.
  2217 	    device
  2235             device
  2218 		copyPlaneFromId:id
  2236                 copyPlaneFromId:id
  2219 			      x:0 y:0 gc:(deviceForm gcId)
  2237                               x:0 y:0 gc:(deviceForm gcId)
  2220 			     to:drawableId
  2238                              to:drawableId
  2221 			      x:pX y:pY gc:gcId
  2239                               x:pX y:pY gc:gcId
  2222 			  width:w height:h
  2240                           width:w height:h
  2223 	].
  2241         ].
  2224 
  2242 
  2225 	fgId ~~ 0 ifTrue:[
  2243         fgId ~~ 0 ifTrue:[
  2226 	    "
  2244             "
  2227 	     or-in fg-bits ...
  2245              or-in fg-bits ...
  2228 	    "
  2246             "
  2229 	    device setForeground:fgId background:0 in:gcId.
  2247             device setForeground:fgId background:0 in:gcId.
  2230 	    device setFunction:#or in:gcId.
  2248             device setFunction:#or in:gcId.
  2231 	    device
  2249             device
  2232 		copyPlaneFromId:id
  2250                 copyPlaneFromId:id
  2233 			      x:0 y:0 gc:(deviceForm gcId)
  2251                               x:0 y:0 gc:(deviceForm gcId)
  2234 			     to:drawableId
  2252                              to:drawableId
  2235 			      x:pX y:pY gc:gcId
  2253                               x:pX y:pY gc:gcId
  2236 			  width:w height:h
  2254                           width:w height:h
  2237 	].
  2255         ].
  2238 	"
  2256         "
  2239 	 flush foreground/background cache
  2257          flush foreground/background cache
  2240 	"
  2258         "
  2241 	foreground := nil.
  2259         foreground := nil.
  2242 	background := nil.
  2260         background := nil.
  2243 	device setFunction:function in:gcId.
  2261         device setFunction:function in:gcId.
  2244 	^ self
  2262         ^ self
  2245     ].
  2263     ].
  2246 
  2264 
  2247     (bgId notNil and:[function == #copy]) ifTrue:[
  2265     (bgId notNil and:[function == #copy]) ifTrue:[
  2248 	"
  2266         "
  2249 	 only fg is dithered; fill with fg first ...
  2267          only fg is dithered; fill with fg first ...
  2250 	"
  2268         "
  2251 	self fillDeviceRectangleX:pX y:pY width:w height:h.
  2269         self fillDeviceRectangleX:pX y:pY width:w height:h.
  2252 
  2270 
  2253 	"
  2271         "
  2254 	 if paint color is all-0 or all-1's, we can do it in one
  2272          if paint color is all-0 or all-1's, we can do it in one
  2255 	 operation ...
  2273          operation ...
  2256 	"
  2274         "
  2257 	((bgId ~~ ((1 bitShift:deviceDepth)-1))
  2275         ((bgId ~~ ((1 bitShift:deviceDepth)-1))
  2258 	and:[bgId ~~ allBits]) ifTrue:[
  2276         and:[bgId ~~ allBits]) ifTrue:[
  2259 	    "
  2277             "
  2260 	     clear bg-bits ...
  2278              clear bg-bits ...
  2261 	    "
  2279             "
  2262 	    device setForeground:allBits background:0 in:gcId.
  2280             device setForeground:allBits background:0 in:gcId.
  2263 	    device setFunction:#and in:gcId.
  2281             device setFunction:#and in:gcId.
  2264 	    device
  2282             device
  2265 		copyPlaneFromId:id
  2283                 copyPlaneFromId:id
  2266 			      x:0 y:0 gc:(deviceForm gcId)
  2284                               x:0 y:0 gc:(deviceForm gcId)
  2267 			     to:drawableId
  2285                              to:drawableId
  2268 			      x:pX y:pY gc:gcId
  2286                               x:pX y:pY gc:gcId
  2269 			  width:w height:h
  2287                           width:w height:h
  2270 	].
  2288         ].
  2271 
  2289 
  2272 	"
  2290         "
  2273 	 or-in bg-bits ...
  2291          or-in bg-bits ...
  2274 	"
  2292         "
  2275 	bgId ~~ 0 ifTrue:[
  2293         bgId ~~ 0 ifTrue:[
  2276 	    device setForeground:0 background:bgId in:gcId.
  2294             device setForeground:0 background:bgId in:gcId.
  2277 	    device setFunction:#or in:gcId.
  2295             device setFunction:#or in:gcId.
  2278 	    device
  2296             device
  2279 		copyPlaneFromId:id
  2297                 copyPlaneFromId:id
  2280 			      x:0 y:0 gc:(deviceForm gcId)
  2298                               x:0 y:0 gc:(deviceForm gcId)
  2281 			     to:drawableId
  2299                              to:drawableId
  2282 			      x:pX y:pY gc:gcId
  2300                               x:pX y:pY gc:gcId
  2283 			  width:w height:h
  2301                           width:w height:h
  2284 	].
  2302         ].
  2285 	"
  2303         "
  2286 	 flush foreground/background cache
  2304          flush foreground/background cache
  2287 	"
  2305         "
  2288 	foreground := nil.
  2306         foreground := nil.
  2289 	background := nil.
  2307         background := nil.
  2290 	device setFunction:function in:gcId.
  2308         device setFunction:function in:gcId.
  2291 	^ self
  2309         ^ self
  2292     ].
  2310     ].
  2293 
  2311 
  2294     "
  2312     "
  2295      very hard case; both fg and bg are dithered colors
  2313      very hard case; both fg and bg are dithered colors
  2296     "
  2314     "
  2306     "
  2324     "
  2307      fill
  2325      fill
  2308     "
  2326     "
  2309     dx := dy := 0.
  2327     dx := dy := 0.
  2310     maskOrigin notNil ifTrue:[
  2328     maskOrigin notNil ifTrue:[
  2311 	dx := maskOrigin x.
  2329         dx := maskOrigin x.
  2312 	dy := maskOrigin y
  2330         dy := maskOrigin y
  2313     ].
  2331     ].
  2314 
  2332 
  2315     bgForm paint:bgPaint.
  2333     bgForm paint:bgPaint.
  2316     bgForm setMaskOriginX:(x negated + dx) y:(y negated + dy).
  2334     bgForm setMaskOriginX:(x negated + dx) y:(y negated + dy).
  2317     bgForm fillRectangleX:0 y:0 width:w height:h.
  2335     bgForm fillRectangleX:0 y:0 width:w height:h.
  2350     "
  2368     "
  2351      finally, draw it
  2369      finally, draw it
  2352     "
  2370     "
  2353     device setForeground:0 background:allBits in:gcId.
  2371     device setForeground:0 background:allBits in:gcId.
  2354     device
  2372     device
  2355 	copyFromId:tmpForm id
  2373         copyFromId:tmpForm id
  2356 		 x:0 y:0 gc:tmpForm gcId
  2374                  x:0 y:0 gc:tmpForm gcId
  2357 		to:drawableId
  2375                 to:drawableId
  2358 		 x:pX y:pY gc:gcId
  2376                  x:pX y:pY gc:gcId
  2359 	     width:w height:h.
  2377              width:w height:h.
  2360     "
  2378     "
  2361      flush foreground/background cache
  2379      flush foreground/background cache
  2362     "
  2380     "
  2363     foreground := nil.
  2381     foreground := nil.
  2364     background := nil.
  2382     background := nil.
  2365 
  2383 
  2366     "Modified: 22.6.1996 / 16:45:35 / cg"
  2384     "Modified: 22.10.1996 / 16:48:32 / cg"
  2367 !
  2385 !
  2368 
  2386 
  2369 displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
  2387 displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
  2370     "draw a substring at the coordinate x/y - draw foreground pixels in
  2388     "draw a substring at the coordinate x/y - draw foreground pixels in
  2371      paint-color and background pixels in bgPaint-color.
  2389      paint-color and background pixels in bgPaint-color.
  3324     "return the number of pixels (not rounded) for millis millimeter"
  3342     "return the number of pixels (not rounded) for millis millimeter"
  3325 
  3343 
  3326     ^ device verticalPixelPerMillimeter * millis
  3344     ^ device verticalPixelPerMillimeter * millis
  3327 ! !
  3345 ! !
  3328 
  3346 
  3329 !DeviceGraphicsContext  class methodsFor:'documentation'!
  3347 !DeviceGraphicsContext class methodsFor:'documentation'!
  3330 
  3348 
  3331 version
  3349 version
  3332     ^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.19 1996-10-01 17:41:57 cg Exp $'
  3350     ^ '$Header: /cvs/stx/stx/libview/DeviceGraphicsContext.st,v 1.20 1996-10-22 15:56:44 cg Exp $'
  3333 ! !
  3351 ! !
  3334 DeviceGraphicsContext initialize!
  3352 DeviceGraphicsContext initialize!