GraphicsMedium.st
branchjv
changeset 7541 39940e2446a5
parent 7318 83b501bbf3b0
parent 7485 24a3795170f1
child 7542 9e125aa140f9
equal deleted inserted replaced
7540:69b0ea8c4b30 7541:39940e2446a5
    12 "{ Package: 'stx:libview' }"
    12 "{ Package: 'stx:libview' }"
    13 
    13 
    14 "{ NameSpace: Smalltalk }"
    14 "{ NameSpace: Smalltalk }"
    15 
    15 
    16 Object subclass:#GraphicsMedium
    16 Object subclass:#GraphicsMedium
    17 	instanceVariableNames:'gc device width height realized'
    17 	instanceVariableNames:'device gc width height realized'
    18 	classVariableNames:''
    18 	classVariableNames:''
    19 	poolDictionaries:''
    19 	poolDictionaries:''
    20 	category:'Graphics-Support'
    20 	category:'Graphics-Support'
    21 !
    21 !
    22 
    22 
   252 
   252 
   253     "Modified: 28.5.1996 / 20:22:29 / cg"
   253     "Modified: 28.5.1996 / 20:22:29 / cg"
   254 !
   254 !
   255 
   255 
   256 key
   256 key
   257     ^ self id
   257     ^ self drawableId
   258 !
   258 !
   259 
   259 
   260 phase
   260 phase
   261     "return the origin within the mask (used to draw with patterns).
   261     "return the origin within the mask (used to draw with patterns).
   262      This is an alias for ST/X's #maskOrigin"
   262      This is an alias for ST/X's #maskOrigin"
   297 
   297 
   298 widthOfString:aString
   298 widthOfString:aString
   299     "given a string, return its width in pixels if
   299     "given a string, return its width in pixels if
   300      drawn on the receivers device."
   300      drawn on the receivers device."
   301 
   301 
   302     gc == self ifTrue:[
       
   303         ^ super widthOfString:aString.
       
   304     ].
       
   305     ^ gc widthOfString:aString.
   302     ^ gc widthOfString:aString.
   306 
   303 
   307     "Modified: 28.5.1996 / 20:22:22 / cg"
   304     "Modified: 28.5.1996 / 20:22:22 / cg"
   308 !
   305 !
   309 
   306 
   310 widthOfString:aString from:start to:stop
   307 widthOfString:aString from:start to:stop
   311     "given a string, return the width in pixels if
   308     "given a string, return the width in pixels if
   312      a substring is drawn on the receivers device."
   309      a substring is drawn on the receivers device."
   313 
   310 
   314     gc == self ifTrue:[
       
   315         ^ super widthOfString:aString from:start to:stop.
       
   316     ].
       
   317     ^ gc widthOfString:aString from:start to:stop.
   311     ^ gc widthOfString:aString from:start to:stop.
   318 
   312 
   319     "Modified: 28.5.1996 / 20:22:18 / cg"
   313     "Modified: 28.5.1996 / 20:22:18 / cg"
   320 ! !
   314 ! !
   321 
   315 
   323 
   317 
   324 copyBits:aRectangle from:aForm at:srcOrigin clippingBox:clippingBox rule:rule fillColor:fillColor
   318 copyBits:aRectangle from:aForm at:srcOrigin clippingBox:clippingBox rule:rule fillColor:fillColor
   325     |f oldClip oldFunction|
   319     |f oldClip oldFunction|
   326 
   320 
   327     (f := rule) isInteger ifTrue:[
   321     (f := rule) isInteger ifTrue:[
   328 	"/ ST-80 compatibility: numeric rule
   322         "/ ST-80 compatibility: numeric rule
   329 	f := #(clear and andReverse  copy andInverted noop xor or nor equiv invert orInverted copyInverted
   323         f := #(clear and andReverse  copy andInverted noop xor or nor equiv invert orInverted copyInverted
   330 	       orReverse nand set) at:(rule + 1).
   324                orReverse nand set) at:(rule + 1).
   331     ].
   325     ].
   332 
   326 
   333     oldFunction := gc function.
   327     oldFunction := gc function.
   334     oldClip := gc clippingRectangleOrNil.
   328     oldClip := gc clippingBoundsOrNil.
   335 
   329 
   336     gc clippingRectangle:clippingBox.
   330     gc clippingBounds:clippingBox.
   337     gc function:f.
   331     gc function:f.
   338 
   332 
   339     gc
   333     gc
   340 	copyFrom:aForm
   334         copyFrom:aForm
   341 	x:srcOrigin x y:srcOrigin y
   335         x:srcOrigin x y:srcOrigin y
   342 	toX:aRectangle left y:aRectangle top
   336         toX:aRectangle left y:aRectangle top
   343 	width:aRectangle width height:aRectangle height.
   337         width:aRectangle width height:aRectangle height.
   344 
   338 
   345     gc clippingRectangle:oldClip.
   339     gc clippingBounds:oldClip.
   346     gc function:oldFunction.
   340     gc function:oldFunction.
   347 
   341 
   348     "
   342     "
   349       |dst src|
   343       |dst src|
   350 
   344 
   351       dst := Form width:8 height:8 fromArray:#[
   345       dst := Form width:8 height:8 fromArray:#[
   352 					      2r00000000
   346                                               2r00000000
   353 					      2r00000000
   347                                               2r00000000
   354 					      2r00000000
   348                                               2r00000000
   355 					      2r00000000
   349                                               2r00000000
   356 					      2r11111111
   350                                               2r11111111
   357 					      2r11111111
   351                                               2r11111111
   358 					      2r11111111
   352                                               2r11111111
   359 					      2r11111111
   353                                               2r11111111
   360 					     ].
   354                                              ].
   361       src := Form width:8 height:8 fromArray:#[
   355       src := Form width:8 height:8 fromArray:#[
   362 					      2r00001111
   356                                               2r00001111
   363 					      2r00001111
   357                                               2r00001111
   364 					      2r00001111
   358                                               2r00001111
   365 					      2r00001111
   359                                               2r00001111
   366 					      2r00001111
   360                                               2r00001111
   367 					      2r00001111
   361                                               2r00001111
   368 					      2r00001111
   362                                               2r00001111
   369 					      2r00001111
   363                                               2r00001111
   370 					     ].
   364                                              ].
   371 
   365 
   372     dst copyBits:(0@0 corner:8@8) from:src at:0@0 clippingBox:(0@0 corner:8@8) rule:15 fillColor:Color black.
   366     dst copyBits:(0@0 corner:8@8) from:src at:0@0 clippingBox:(0@0 corner:8@8) rule:15 fillColor:Color black.
   373     dst inspect
   367     dst inspect
   374 
   368 
   375     "
   369     "
   378 
   372 
   379     "
   373     "
   380       |dst src|
   374       |dst src|
   381 
   375 
   382       dst := Form width:8 height:8 fromArray:#[
   376       dst := Form width:8 height:8 fromArray:#[
   383 					      2r00000000
   377                                               2r00000000
   384 					      2r00000000
   378                                               2r00000000
   385 					      2r00000000
   379                                               2r00000000
   386 					      2r00000000
   380                                               2r00000000
   387 					      2r11111111
   381                                               2r11111111
   388 					      2r11111111
   382                                               2r11111111
   389 					      2r11111111
   383                                               2r11111111
   390 					      2r11111111
   384                                               2r11111111
   391 					     ].
   385                                              ].
   392       src := Form width:8 height:8 fromArray:#[
   386       src := Form width:8 height:8 fromArray:#[
   393 					      2r00001111
   387                                               2r00001111
   394 					      2r00001111
   388                                               2r00001111
   395 					      2r00001111
   389                                               2r00001111
   396 					      2r00001111
   390                                               2r00001111
   397 					      2r00001111
   391                                               2r00001111
   398 					      2r00001111
   392                                               2r00001111
   399 					      2r00001111
   393                                               2r00001111
   400 					      2r00001111
   394                                               2r00001111
   401 					     ].
   395                                              ].
   402 
   396 
   403     dst copyBits:(0@0 corner:8@8) from:src at:0@0 clippingBox:(0@0 corner:8@8) rule:15 fillColor:Color black.
   397     dst copyBits:(0@0 corner:8@8) from:src at:0@0 clippingBox:(0@0 corner:8@8) rule:15 fillColor:Color black.
   404     dst inspect
   398     dst inspect
   405 
   399 
   406     "
   400     "
   409 !
   403 !
   410 
   404 
   411 fill:aRectangle fillColor:aColor
   405 fill:aRectangle fillColor:aColor
   412     "fill the rectangular area specified by aRectangle with the black color"
   406     "fill the rectangular area specified by aRectangle with the black color"
   413 
   407 
   414     gc == self ifTrue:[
       
   415 	super fill:aRectangle fillColor:aColor.
       
   416 	^ self.
       
   417     ].
       
   418     gc fill:aRectangle fillColor:aColor
   408     gc fill:aRectangle fillColor:aColor
   419 !
   409 !
   420 
   410 
   421 fillBlack:aRectangle
   411 fillBlack:aRectangle
   422     "fill the rectangular area specified by aRectangle with the black color"
   412     "fill the rectangular area specified by aRectangle with the black color"
   423 
   413 
   424     self fill:aRectangle fillColor:Color black
   414     self fill:aRectangle fillColor:self blackColor
   425 !
   415 !
   426 
   416 
   427 fillColor:something
   417 fillColor:something
   428     "fill the receiver with something;
   418     "fill the receiver with something;
   429      something may be a Form, Color or colorIndex"
   419      something may be a Form, Color or colorIndex"
   432 !
   422 !
   433 
   423 
   434 fillRectangle:aRectangle color:aColor
   424 fillRectangle:aRectangle color:aColor
   435     "fill a rectangle with the given paint color"
   425     "fill a rectangle with the given paint color"
   436 
   426 
   437     gc == self ifTrue:[
       
   438 	super fillRectangle:aRectangle color:aColor.
       
   439 	^ self.
       
   440     ].
       
   441     gc fillRectangle:aRectangle color:aColor
   427     gc fillRectangle:aRectangle color:aColor
   442 !
   428 !
   443 
   429 
   444 fillWhite
   430 fillWhite
   445     "fill all of the receiver with the white color"
   431     "fill all of the receiver with the white color"
   446 
   432 
   447     self fill:Color white
   433     self fill:self whiteColor
   448 !
   434 !
   449 
   435 
   450 fillWhite:aRectangle
   436 fillWhite:aRectangle
   451     "fill the rectangular area specified by aRectangle with the white color"
   437     "fill the rectangular area specified by aRectangle with the white color"
   452 
   438 
   453     self fill:aRectangle fillColor:Color white
   439     self fill:aRectangle fillColor:self whiteColor
   454 ! !
   440 ! !
   455 
   441 
   456 !GraphicsMedium methodsFor:'Compatibility-VW'!
   442 !GraphicsMedium methodsFor:'Compatibility-VW'!
   457 
   443 
   458 displayBackgroundIfNeededOn: aGraphicsContext
   444 displayBackgroundIfNeededOn: aGraphicsContext
   509 !
   495 !
   510 
   496 
   511 atX:x y:y
   497 atX:x y:y
   512     "return the pixel at the coordinate given by x/y"
   498     "return the pixel at the coordinate given by x/y"
   513 
   499 
   514     gc == self ifTrue:[
       
   515 	^ super atX:x y:y
       
   516     ].
       
   517     ^ gc atX:x y:y
   500     ^ gc atX:x y:y
   518 !
   501 !
   519 
   502 
   520 atX:x y:y put:aPixelColor
   503 atX:x y:y put:aPixelColor
   521     "set a pixel"
   504     "set a pixel"
   522 
   505 
   523     gc == self ifTrue:[
       
   524 	super atX:x y:y put:aPixelColor.
       
   525 	^ self.
       
   526     ].
       
   527     gc atX:x y:y put:aPixelColor.
   506     gc atX:x y:y put:aPixelColor.
   528 !
   507 !
   529 
   508 
   530 backgroundPaint
   509 backgroundPaint
   531     "return the background paint color.
   510     "return the background paint color.
   532      (used for opaqueForms and opaqueStrings)"
   511      (used for opaqueForms and opaqueStrings)"
   533 
   512 
   534     gc == self ifTrue:[
       
   535 	^ super backgroundPaint.
       
   536     ].
       
   537     ^ gc backgroundPaint
   513     ^ gc backgroundPaint
   538 !
   514 !
   539 
   515 
   540 backgroundPaint:aColor
   516 backgroundPaint:aColor
   541     "set the background-paint color; this is used in opaque-draw
   517     "set the background-paint color; this is used in opaque-draw
   542      operations"
   518      operations"
   543 
   519 
   544     gc == self ifTrue:[
       
   545 	super backgroundPaint:aColor.
       
   546 	^ self.
       
   547     ].
       
   548     gc backgroundPaint:aColor
   520     gc backgroundPaint:aColor
   549 !
   521 !
   550 
   522 
   551 basicFont
   523 basicFont
   552     "return the font for drawing"
   524     "return the font for drawing"
   553 
   525 
   554     gc == self ifTrue:[
       
   555 	^ super basicFont.
       
   556     ].
       
   557     ^ gc basicFont
   526     ^ gc basicFont
   558 !
   527 !
   559 
   528 
   560 basicFont:aFont
   529 basicFont:aFont
   561     "set the font for drawing if it has changed.
   530     "set the font for drawing if it has changed.
   562      This is a low level entry, which is not to be redefined
   531      This is a low level entry, which is not to be redefined
   563      (i.e. it must not imply a redraw operation)"
   532      (i.e. it must not imply a redraw operation)"
   564 
   533 
   565     gc == self ifTrue:[
       
   566 	super basicFont:aFont.
       
   567 	^ self.
       
   568     ].
       
   569     gc basicFont:aFont
   534     gc basicFont:aFont
   570 !
   535 !
   571 
   536 
   572 blackColor
   537 blackColor
   573     gc isNil ifTrue:[
   538     gc isNil ifTrue:[
   574         ^ Color black.
   539         ^ Color black.
   575     ].
   540     ].
   576     gc == self ifTrue:[
   541     ^ gc blackColor
   577         ^ super device blackColor.
       
   578     ].
       
   579     ^ gc device blackColor
       
   580 !
   542 !
   581 
   543 
   582 bottomCenter
   544 bottomCenter
   583     "return the topCenter point"
   545     "return the topCenter point"
   584 
   546 
   600 
   562 
   601 capStyle
   563 capStyle
   602     "return the current cap-style for line-drawing.
   564     "return the current cap-style for line-drawing.
   603      possible styles are: #notLast, #butt, #round, #projecting"
   565      possible styles are: #notLast, #butt, #round, #projecting"
   604 
   566 
   605     gc == self ifTrue:[
       
   606 	^ super capStyle.
       
   607     ].
       
   608     ^ gc capStyle
   567     ^ gc capStyle
   609 !
   568 !
   610 
   569 
   611 capStyle:aStyleSymbol
   570 capStyle:aStyleSymbol
   612     "set the cap-style for line-drawing;
   571     "set the cap-style for line-drawing;
   613      possible styles are: #notLast, #butt, #round, #projecting"
   572      possible styles are: #notLast, #butt, #round, #projecting"
   614 
   573 
   615     gc == self ifTrue:[
       
   616 	super capStyle:aStyleSymbol.
       
   617 	^ self.
       
   618     ].
       
   619     gc capStyle:aStyleSymbol
   574     gc capStyle:aStyleSymbol
   620 
   575 
   621     "Modified: 12.5.1996 / 22:24:30 / cg"
   576     "Modified: 12.5.1996 / 22:24:30 / cg"
   622 !
   577 !
   623 
   578 
   633      occur when drawing).
   588      occur when drawing).
   634      This is (currently) only passed down from the fileBrowser,
   589      This is (currently) only passed down from the fileBrowser,
   635      and required when japanese/chinese/korean text is edited.
   590      and required when japanese/chinese/korean text is edited.
   636      (encoding is something like #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc)"
   591      (encoding is something like #'iso8859-5' #euc, #sjis, #jis7, #gb, #big5 or #ksc)"
   637 
   592 
   638     gc == self ifTrue:[
       
   639 	^ super characterEncoding.
       
   640     ].
       
   641     ^ gc characterEncoding
   593     ^ gc characterEncoding
   642 !
   594 !
   643 
   595 
   644 characterEncoding:encodingArg
   596 characterEncoding:encodingArg
   645     "define how the contents is encoded internally.
   597     "define how the contents is encoded internally.
   648      The possibility to change the characterEncoding is provided as
   600      The possibility to change the characterEncoding is provided as
   649      a backward compatibility hook for programs which want to use
   601      a backward compatibility hook for programs which want to use
   650      another encoding internally. One such view is the CharacterSetView,
   602      another encoding internally. One such view is the CharacterSetView,
   651      which wants to show character as they are actually present in a font."
   603      which wants to show character as they are actually present in a font."
   652 
   604 
   653     gc == self ifTrue:[
       
   654 	super characterEncoding:encodingArg.
       
   655 	^ self.
       
   656     ].
       
   657     gc characterEncoding:encodingArg
   605     gc characterEncoding:encodingArg
   658 !
   606 !
   659 
   607 
   660 clipByChildren
   608 clipByChildren
   661     "drawing shall be done into my view only (default)"
   609     "drawing shall be done into my view only (default)"
   697      If on, a superview may draw 'over' its children.
   645      If on, a superview may draw 'over' its children.
   698      If off (the default), drawing is 'under' its children.
   646      If off (the default), drawing is 'under' its children.
   699      Only useful for the rootView, to draw over any visible views.
   647      Only useful for the rootView, to draw over any visible views.
   700      (for example, when dragging a rubber-line)"
   648      (for example, when dragging a rubber-line)"
   701 
   649 
   702     gc == self ifTrue:[
       
   703         super clippedByChildren:aBoolean.
       
   704         ^ self.
       
   705     ].
       
   706     gc clippedByChildren:aBoolean.
   650     gc clippedByChildren:aBoolean.
   707 
   651 
   708     "Created: 17.7.1996 / 13:25:16 / cg"
   652     "Created: 17.7.1996 / 13:25:16 / cg"
   709     "Modified: 29.4.1997 / 15:33:55 / dq"
   653     "Modified: 29.4.1997 / 15:33:55 / dq"
   710 !
   654 !
   711 
   655 
   712 clippingBounds
   656 clippingBounds
   713     "return the clipping rectangle for drawing, nil if there is none."
   657     "return the clipping rectangle for drawing, nil if there is none."
   714 
   658 
   715     gc == self ifTrue:[
       
   716         ^ super clippingBounds.
       
   717     ].
       
   718     ^ gc clippingBounds
   659     ^ gc clippingBounds
   719 !
   660 !
   720 
   661 
   721 clippingBounds:aRectangleOrNil
   662 clippingBounds:aRectangleOrNil
   722     "set the clipping rectangle for drawing (in logical coordinates);
   663     "set the clipping rectangle for drawing (in logical coordinates);
   723      a nil argument turn off clipping (i.e. whole view is drawable)"
   664      a nil argument turn off clipping (i.e. whole view is drawable)"
   724 
   665 
   725     gc == self ifTrue:[
       
   726         super clippingBounds:aRectangleOrNil.
       
   727         ^ self.
       
   728     ].
       
   729     gc clippingBounds:aRectangleOrNil
   666     gc clippingBounds:aRectangleOrNil
   730 !
   667 !
   731 
   668 
   732 clippingBoundsOrNil
   669 clippingBoundsOrNil
   733     "return the clipping rectangle for drawing, nil if there is none."
   670     "return the clipping rectangle for drawing, nil if there is none."
   734 
   671 
   735     gc == self ifTrue:[
       
   736         ^ super clippingBoundsOrNil.
       
   737     ].
       
   738     ^ gc clippingBoundsOrNil
   672     ^ gc clippingBoundsOrNil
   739 !
   673 !
   740 
   674 
   741 clippingRectangle:aRectangleOrNil
   675 clippingRectangle:aRectangleOrNil
   742     "set the clipping rectangle for drawing (in logical coordinates);
   676     "set the clipping rectangle for drawing (in logical coordinates);
   764 !
   698 !
   765 
   699 
   766 colorAtX:x y:y
   700 colorAtX:x y:y
   767     "return the color of the pixel at the coordinate given by aPoint"
   701     "return the color of the pixel at the coordinate given by aPoint"
   768 
   702 
   769     gc == self ifTrue:[
       
   770 	^ super colorAtX:x y:y.
       
   771     ].
       
   772     ^ gc colorAtX:x y:y
   703     ^ gc colorAtX:x y:y
   773 !
   704 !
   774 
   705 
   775 container
   706 container
   776     "return my container - for protocol compatibility"
   707     "return my container - for protocol compatibility"
   799      defines 4on-4off dashing;
   730      defines 4on-4off dashing;
   800      Setting it to [1 2 4 2] defines 1on-2off-4on-2off dashes.
   731      Setting it to [1 2 4 2] defines 1on-2off-4on-2off dashes.
   801      The dashOffset specifies where in the dashList the dashing starts.
   732      The dashOffset specifies where in the dashList the dashing starts.
   802      Ignored here - this may not be supported by all graphics devices."
   733      Ignored here - this may not be supported by all graphics devices."
   803 
   734 
   804     gc == self ifTrue:[
       
   805 	^ super dashStyle:aDashList offset:dashOffset.
       
   806     ].
       
   807     ^ gc dashStyle:aDashList offset:dashOffset
   735     ^ gc dashStyle:aDashList offset:dashOffset
       
   736 !
       
   737 
       
   738 depth
       
   739     ^ self subclassResponsibility
   808 !
   740 !
   809 
   741 
   810 device
   742 device
   811     "return the device, the receiver is associated with"
   743     "return the device, the receiver is associated with"
   812 
   744 
   813     gc == self ifTrue:[
   745     ^ device
   814         ^ super device.
       
   815     ].
       
   816     gc isNil ifTrue:[
       
   817         ^ nil.
       
   818     ].
       
   819     ^ gc device
       
   820 !
   746 !
   821 
   747 
   822 device:aDevice
   748 device:aDevice
   823     "set the device"
   749     "set the device"
   824 
   750 
   825     aDevice isNil ifTrue:[
   751     (aDevice isNil or:[device == aDevice]) ifTrue:[
   826         ^ self.
   752         ^ self.
   827     ].
   753     ].
   828 
   754 
   829     gc isNil ifTrue:[
   755     gc isNil ifTrue:[
   830         gc := aDevice newGraphicsContextFor:self.
   756         self initializeForDevice:aDevice.
   831         device := aDevice.
       
   832         ^ self.
   757         ^ self.
   833     ].
   758     ].
   834 
   759 
   835     gc device:aDevice.
       
   836     device := aDevice.
   760     device := aDevice.
   837 
   761     gc device:aDevice
   838     "Modified: / 03-04-2016 / 16:03:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   762 !
   839 !
   763 
   840 
   764 deviceClippingBounds:aRectangleOrNil
   841 deviceClippingRectangle:aRectangleOrNil
       
   842     "set the clipping rectangle for drawing (in device coordinates);
   765     "set the clipping rectangle for drawing (in device coordinates);
   843      a nil argument turns off clipping (i.e. whole view is drawable - incl. margins)"
   766      a nil argument turns off clipping (i.e. whole view is drawable - incl. margins)"
   844 
   767 
   845     gc == self ifTrue:[
   768     gc deviceClippingBounds:aRectangleOrNil
   846 	super deviceClippingRectangle:aRectangleOrNil.
   769 !
   847 	^ self.
   770 
   848     ].
   771 deviceClippingBoundsOrNil
   849     gc deviceClippingRectangle:aRectangleOrNil
   772     "return the clipping rectangle as physical coordinated for drawing, nil if there is none."
       
   773 
       
   774     ^ gc deviceClippingBoundsOrNil
       
   775 !
       
   776 
       
   777 deviceClippingRectangle:aRectangleOrNil
       
   778     <resource: #obsolete>
       
   779     "set the clipping rectangle for drawing (in device coordinates);
       
   780      a nil argument turns off clipping (i.e. whole view is drawable - incl. margins)"
       
   781 
       
   782     gc deviceClippingBounds:aRectangleOrNil
   850 !
   783 !
   851 
   784 
   852 drawableId
   785 drawableId
   853     "return the id of the drawable on the device"
   786     "return the id of the drawable on the device"
   854 
   787 
   855     gc == self ifTrue:[
       
   856         ^ super drawableId.
       
   857     ].
       
   858     gc isNil ifTrue:[
   788     gc isNil ifTrue:[
   859         ^ nil.
   789         ^ nil.
   860     ].
   790     ].
   861     ^ gc drawableId
   791     ^ gc drawableId
   862 !
   792 !
   876 !
   806 !
   877 
   807 
   878 font
   808 font
   879     "return the current drawing font"
   809     "return the current drawing font"
   880 
   810 
   881     gc == self ifTrue:[
       
   882 	^ super font.
       
   883     ].
       
   884     ^ gc font
   811     ^ gc font
   885 !
   812 !
   886 
   813 
   887 font:aFont
   814 font:aFont
   888     "set the font for drawing if it has changed.
   815     "set the font for drawing if it has changed.
   889      This should be redefined in some widget to perform an automatic
   816      This should be redefined in some widget to perform an automatic
   890      redraw. See also: #basicFont:"
   817      redraw. See also: #basicFont:"
   891 
   818 
   892     gc == self ifTrue:[
   819     gc font:aFont.
   893         super font:aFont.
       
   894     ] ifFalse:[
       
   895         gc font:aFont.
       
   896     ].
       
   897     self changed:#font.
   820     self changed:#font.
   898 !
   821 !
   899 
   822 
   900 function
   823 function
   901     "return the current drawing function"
   824     "return the current drawing function"
   902 
   825 
   903     gc == self ifTrue:[
       
   904 	^ super function.
       
   905     ].
       
   906     ^ gc function
   826     ^ gc function
   907 !
   827 !
   908 
   828 
   909 function:aSymbol
   829 function:aSymbol
   910     "set the drawing function if it has changed"
   830     "set the drawing function if it has changed"
   911 
   831 
   912     gc == self ifTrue:[
       
   913 	super function:aSymbol.
       
   914 	^ self.
       
   915     ].
       
   916     gc function:aSymbol
   832     gc function:aSymbol
   917 !
   833 !
   918 
   834 
   919 gcId
   835 gcId
   920     "return the receivers graphic context id on the device"
   836     "return the receivers graphic context id on the device"
   921 
   837 
   922     gc == self ifTrue:[
       
   923         ^ super gcId.
       
   924     ].
       
   925     gc isNil ifTrue:[
   838     gc isNil ifTrue:[
   926         ^ nil.
   839         ^ nil.
   927     ].
   840     ].
   928     ^ gc gcId.
   841     ^ gc gcId.
   929 !
   842 !
   930 
   843 
   931 graphicsContext
   844 graphicsContext
   932     "for ST-80 compatibility"
       
   933 
       
   934     ^ gc
   845     ^ gc
       
   846 !
       
   847 
       
   848 graphicsContext:newGc
       
   849     "set the graphics context"
       
   850 
       
   851     gc == newGc ifTrue:[
       
   852         ^ self.
       
   853     ].
       
   854     gc := newGc.
       
   855     device := newGc device.
   935 !
   856 !
   936 
   857 
   937 graphicsDevice
   858 graphicsDevice
   938     "same as #device, for ST-80 compatibility"
   859     "same as #device, for ST-80 compatibility"
   939 
   860 
   940     gc == self ifTrue:[
   861     ^ device
   941         ^ super graphicsDevice.
       
   942     ].
       
   943     gc isNil ifTrue:[
       
   944         ^ nil.
       
   945     ].
       
   946     ^ gc graphicsDevice
       
   947 !
   862 !
   948 
   863 
   949 height
   864 height
   950     "return the height of the receiver"
   865     "return the height of the receiver"
   951 
   866 
   966 
   881 
   967 joinStyle
   882 joinStyle
   968     "return the current join-style for polygon-drawing.
   883     "return the current join-style for polygon-drawing.
   969      possible styles are: #miter, #bevel, #round"
   884      possible styles are: #miter, #bevel, #round"
   970 
   885 
   971     gc == self ifTrue:[
       
   972 	^ super joinStyle.
       
   973     ].
       
   974     ^ gc joinStyle
   886     ^ gc joinStyle
   975 !
   887 !
   976 
   888 
   977 joinStyle:aStyleSymbol
   889 joinStyle:aStyleSymbol
   978     "set the join-style of lines in polygon-drawing;
   890     "set the join-style of lines in polygon-drawing;
   979      possible styles are: #miter, #bevel, #round"
   891      possible styles are: #miter, #bevel, #round"
   980 
   892 
   981     gc == self ifTrue:[
       
   982 	super joinStyle:aStyleSymbol.
       
   983 	^ self.
       
   984     ].
       
   985     gc joinStyle:aStyleSymbol
   893     gc joinStyle:aStyleSymbol
   986 !
   894 !
   987 
   895 
   988 left
   896 left
   989     "return the left i.e. x-coordinate of top-left of the receiver"
   897     "return the left i.e. x-coordinate of top-left of the receiver"
  1000 lineStyle
   908 lineStyle
  1001     "return the current line-drawing-style.
   909     "return the current line-drawing-style.
  1002      possible styles are: #solid, #dashed, #doubleDashed,
   910      possible styles are: #solid, #dashed, #doubleDashed,
  1003      #dotted, #dashDot or #dashDotDot."
   911      #dotted, #dashDot or #dashDotDot."
  1004 
   912 
  1005     gc == self ifTrue:[
       
  1006 	^ super lineStyle.
       
  1007     ].
       
  1008     ^ gc lineStyle
   913     ^ gc lineStyle
  1009 !
   914 !
  1010 
   915 
  1011 lineStyle:aStyleSymbol
   916 lineStyle:aStyleSymbol
  1012     "set the line-drawing-style;
   917     "set the line-drawing-style;
  1013      possible styles are: #solid, #dashed, #doubleDashed,
   918      possible styles are: #solid, #dashed, #doubleDashed,
  1014      #dotted, #dashDot or #dashDotDot."
   919      #dotted, #dashDot or #dashDotDot."
  1015 
   920 
  1016     gc == self ifTrue:[
       
  1017 	super lineStyle:aStyleSymbol.
       
  1018 	^ self.
       
  1019     ].
       
  1020     gc lineStyle:aStyleSymbol
   921     gc lineStyle:aStyleSymbol
  1021 !
   922 !
  1022 
   923 
  1023 lineWidth
   924 lineWidth
  1024     "return the current drawing linewidth"
   925     "return the current drawing linewidth"
  1025 
   926 
  1026     gc == self ifTrue:[
       
  1027 	^ super lineWidth.
       
  1028     ].
       
  1029     ^ gc lineWidth
   927     ^ gc lineWidth
  1030 !
   928 !
  1031 
   929 
  1032 lineWidth:aNumber
   930 lineWidth:aNumber
  1033     "set the line drawing width in pixels"
   931     "set the line drawing width in pixels"
  1034 
   932 
  1035     gc == self ifTrue:[
       
  1036 	super lineWidth:aNumber.
       
  1037 	^ self.
       
  1038     ].
       
  1039     gc lineWidth:aNumber
   933     gc lineWidth:aNumber
  1040 !
   934 !
  1041 
   935 
  1042 mask
   936 mask
  1043     "return the current drawing mask"
   937     "return the current drawing mask"
  1044 
   938 
  1045     gc == self ifTrue:[
       
  1046 	^ super mask.
       
  1047     ].
       
  1048     ^ gc mask
   939     ^ gc mask
  1049 !
   940 !
  1050 
   941 
  1051 mask:aForm
   942 mask:aForm
  1052     "set the drawing mask"
   943     "set the drawing mask"
  1053 
   944 
  1054     gc == self ifTrue:[
       
  1055 	super mask:aForm.
       
  1056 	^ self.
       
  1057     ].
       
  1058     gc mask:aForm
   945     gc mask:aForm
  1059 !
   946 !
  1060 
   947 
  1061 maskOrigin
   948 maskOrigin
  1062     "return the origin within the mask (used to draw with patterns).
   949     "return the origin within the mask (used to draw with patterns).
  1063      Should be redefined in classes which support it.
   950      Should be redefined in classes which support it.
  1064      This is an alias for ST-80's #phase"
   951      This is an alias for ST-80's #phase"
  1065 
   952 
  1066     gc == self ifTrue:[
       
  1067 	^ super maskOrigin.
       
  1068     ].
       
  1069     ^ gc maskOrigin
   953     ^ gc maskOrigin
  1070 !
   954 !
  1071 
   955 
  1072 maskOrigin:aPoint
   956 maskOrigin:aPoint
  1073     "set the origin within the mask (used to draw with patterns).
   957     "set the origin within the mask (used to draw with patterns).
  1074      Should be redefined in classes which support it.
   958      Should be redefined in classes which support it.
  1075      This is an alias for ST-80's #phase:"
   959      This is an alias for ST-80's #phase:"
  1076 
   960 
  1077     gc == self ifTrue:[
       
  1078 	super maskOrigin:aPoint.
       
  1079 	^ self.
       
  1080     ].
       
  1081     gc maskOrigin:aPoint
   961     gc maskOrigin:aPoint
  1082 !
   962 !
  1083 
   963 
  1084 maskOriginX:x y:y
   964 maskOriginX:x y:y
  1085     "set the origin within the mask (used to draw with patterns).
   965     "set the origin within the mask (used to draw with patterns).
  1090 !
   970 !
  1091 
   971 
  1092 medium
   972 medium
  1093     "return the destination medium i.e. the underlying graphics device"
   973     "return the destination medium i.e. the underlying graphics device"
  1094 
   974 
  1095     gc == self ifTrue:[
       
  1096         ^ super graphicsDevice.
       
  1097     ].
       
  1098     ^ gc graphicsDevice
   975     ^ gc graphicsDevice
  1099 !
   976 !
  1100 
   977 
  1101 noClipByChildren
   978 noClipByChildren
  1102     "drawing shall also be done into subviews"
   979     "drawing shall also be done into subviews"
  1116 !
   993 !
  1117 
   994 
  1118 paint
   995 paint
  1119     "return the current paint drawing color"
   996     "return the current paint drawing color"
  1120 
   997 
  1121     gc == self ifTrue:[
       
  1122 	^ super paint.
       
  1123     ].
       
  1124     ^ gc paint
   998     ^ gc paint
  1125 !
   999 !
  1126 
  1000 
  1127 paint:aColor
  1001 paint:aColor
  1128     "set the drawing painting color, aColor can be a dithered one"
  1002     "set the drawing painting color, aColor can be a dithered one"
  1129 
  1003 
  1130     gc == self ifTrue:[
       
  1131 	super paint:aColor.
       
  1132 	^ self.
       
  1133     ].
       
  1134     gc paint:aColor
  1004     gc paint:aColor
  1135 !
  1005 !
  1136 
  1006 
  1137 paint:fgColor on:bgColor
  1007 paint:fgColor on:bgColor
  1138     "set the paint and backgroundPaint, used for text and bitmaps.
  1008     "set the paint and backgroundPaint, used for text and bitmaps.
  1139      Both colors may be dithered colors"
  1009      Both colors may be dithered colors"
  1140 
  1010 
  1141     gc == self ifTrue:[
       
  1142 	super paint:fgColor on:bgColor.
       
  1143 	^ self.
       
  1144     ].
       
  1145     gc paint:fgColor on:bgColor
  1011     gc paint:fgColor on:bgColor
  1146 !
  1012 !
  1147 
  1013 
  1148 paint:fgColor on:bgColor function:f
  1014 paint:fgColor on:bgColor function:f
  1149     "set paint, background-paint and function"
  1015     "set paint, background-paint and function"
  1175 
  1041 
  1176     ^ (self left + width - 1) @ (self top + (height // 2) - 1)
  1042     ^ (self left + width - 1) @ (self top + (height // 2) - 1)
  1177 !
  1043 !
  1178 
  1044 
  1179 setClippingBounds:aRectangleOrNil
  1045 setClippingBounds:aRectangleOrNil
  1180     gc == self ifTrue:[
       
  1181         super setClippingBounds:aRectangleOrNil.
       
  1182         ^ self.
       
  1183     ].
       
  1184     gc setClippingBounds:aRectangleOrNil
  1046     gc setClippingBounds:aRectangleOrNil
  1185 !
  1047 !
  1186 
  1048 
  1187 setGraphicsExposures:aBoolean
  1049 setGraphicsExposures:aBoolean
  1188     "want to if aBoolean is true - or don't want to be notified
  1050     "want to if aBoolean is true - or don't want to be notified
  1189      of graphics exposures"
  1051      of graphics exposures"
  1190 
  1052 
  1191     gc == self ifTrue:[
       
  1192 	super setGraphicsExposures:aBoolean.
       
  1193 	^ self.
       
  1194     ].
       
  1195     gc setGraphicsExposures:aBoolean
  1053     gc setGraphicsExposures:aBoolean
  1196 !
  1054 !
  1197 
  1055 
  1198 setMaskOrigin:aPoint
  1056 setMaskOrigin:aPoint
  1199     <resource: #obsolete>
  1057     <resource: #obsolete>
  1254 
  1112 
  1255 whiteColor
  1113 whiteColor
  1256     gc isNil ifTrue:[
  1114     gc isNil ifTrue:[
  1257         ^ Color white.
  1115         ^ Color white.
  1258     ].
  1116     ].
  1259     gc == self ifTrue:[
  1117     ^ gc whiteColor
  1260         ^ super graphicsDevice whiteColor.
       
  1261     ].
       
  1262     ^ gc graphicsDevice whiteColor
       
  1263 !
  1118 !
  1264 
  1119 
  1265 width
  1120 width
  1266     "return the width of the receiver"
  1121     "return the width of the receiver"
  1267 
  1122 
  1286 background
  1141 background
  1287     <resource: #obsolete>
  1142     <resource: #obsolete>
  1288     "return the current background drawing color.
  1143     "return the current background drawing color.
  1289      OBSOLETE: use #paint: / #backgroundPaint: / #paint:on:"
  1144      OBSOLETE: use #paint: / #backgroundPaint: / #paint:on:"
  1290 
  1145 
  1291     gc == self ifTrue:[
       
  1292 	^ super background.
       
  1293     ].
       
  1294     ^ gc background
  1146     ^ gc background
  1295 
  1147 
  1296     "Modified: 12.5.1996 / 22:28:09 / cg"
  1148     "Modified: 12.5.1996 / 22:28:09 / cg"
  1297 !
  1149 !
  1298 
  1150 
  1299 background:aColor
  1151 background:aColor
  1300     <resource: #obsolete>
  1152     <resource: #obsolete>
  1301     "set the internal background color for drawing - aColor must be a real color.
  1153     "set the internal background color for drawing - aColor must be a real color.
  1302      OBSOLETE: this method will vanish; use #paint: / #backgroundPaint: / #paint:on:"
  1154      OBSOLETE: this method will vanish; use #paint: / #backgroundPaint: / #paint:on:"
  1303 
  1155 
  1304     gc == self ifTrue:[
       
  1305 	super background:aColor.
       
  1306 	^ self.
       
  1307     ].
       
  1308     gc background:aColor
  1156     gc background:aColor
  1309 !
  1157 !
  1310 
  1158 
  1311 foreground
  1159 foreground
  1312     <resource: #obsolete>
  1160     <resource: #obsolete>
  1313     "return the current foreground drawing color.
  1161     "return the current foreground drawing color.
  1314      OBSOLETE: use #paint: / #paint:on:"
  1162      OBSOLETE: use #paint: / #paint:on:"
  1315 
  1163 
  1316     gc == self ifTrue:[
       
  1317 	^ super foreground.
       
  1318     ].
       
  1319     ^ gc foreground
  1164     ^ gc foreground
  1320 !
  1165 !
  1321 
  1166 
  1322 foreground:aColor
  1167 foreground:aColor
  1323     <resource: #obsolete>
  1168     <resource: #obsolete>
  1324     "set the internal foreground color for drawing - aColor must be a real color.
  1169     "set the internal foreground color for drawing - aColor must be a real color.
  1325      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1170      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1326 
  1171 
  1327     gc == self ifTrue:[
       
  1328 	super foreground:aColor.
       
  1329 	^ self.
       
  1330     ].
       
  1331     gc foreground:aColor
  1172     gc foreground:aColor
  1332 !
  1173 !
  1333 
  1174 
  1334 foreground:fgColor background:bgColor
  1175 foreground:fgColor background:bgColor
  1335     <resource: #obsolete>
  1176     <resource: #obsolete>
  1336     "set both internal foreground and internal background colors
  1177     "set both internal foreground and internal background colors
  1337      - these must be real colors.
  1178      - these must be real colors.
  1338      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1179      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1339 
  1180 
  1340     gc == self ifTrue:[
       
  1341 	super foreground:fgColor background:bgColor.
       
  1342 	^ self.
       
  1343     ].
       
  1344     gc foreground:fgColor background:bgColor
  1181     gc foreground:fgColor background:bgColor
  1345 !
  1182 !
  1346 
  1183 
  1347 foreground:fgColor background:bgColor function:fun
  1184 foreground:fgColor background:bgColor function:fun
  1348     <resource: #obsolete>
  1185     <resource: #obsolete>
  1349     "set foreground, background colors and function.
  1186     "set foreground, background colors and function.
  1350      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1187      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1351 
  1188 
  1352     self foreground:fgColor background:bgColor.
  1189     gc foreground:fgColor background:bgColor.
  1353     self function:fun
  1190     gc function:fun
  1354 
  1191 
  1355     "Modified: 12.5.1996 / 22:28:34 / cg"
  1192     "Modified: 12.5.1996 / 22:28:34 / cg"
  1356 !
  1193 !
  1357 
  1194 
  1358 foreground:aColor function:fun
  1195 foreground:aColor function:fun
  1359     <resource: #obsolete>
  1196     <resource: #obsolete>
  1360     "set the foreground color and function for drawing.
  1197     "set the foreground color and function for drawing.
  1361      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1198      OBSOLETE: this method will vanish; use #paint: / #paint:on:"
  1362 
  1199 
  1363     gc == self ifTrue:[
       
  1364 	super foreground:aColor function:fun.
       
  1365 	^ self.
       
  1366     ].
       
  1367     gc foreground:aColor function:fun
  1200     gc foreground:aColor function:fun
  1368 !
  1201 !
  1369 
  1202 
  1370 setRealized:aBoolean
  1203 setRealized:aBoolean
  1371     "low level special interface to manipulate the realized state.
  1204     "low level special interface to manipulate the realized state.
  1378 !GraphicsMedium methodsFor:'accessing-transformation'!
  1211 !GraphicsMedium methodsFor:'accessing-transformation'!
  1379 
  1212 
  1380 scale
  1213 scale
  1381     "return the scale factor (as point) of the transformation"
  1214     "return the scale factor (as point) of the transformation"
  1382 
  1215 
  1383     gc == self ifTrue:[
       
  1384         ^ super scale.
       
  1385     ].
       
  1386     ^ gc scale
  1216     ^ gc scale
  1387 !
  1217 !
  1388 
  1218 
  1389 scale:aPoint
  1219 scale:aPoint
  1390     "set the scale factor of the transformation"
  1220     "set the scale factor of the transformation"
  1391 
  1221 
  1392     gc == self ifTrue:[
       
  1393         super scale:aPoint.
       
  1394         ^ self.
       
  1395     ].
       
  1396     ^ gc scale:aPoint
  1222     ^ gc scale:aPoint
  1397 !
  1223 !
  1398 
  1224 
  1399 transformation
  1225 transformation
  1400     "return the transformation"
  1226     "return the transformation"
  1401 
  1227 
  1402     gc == self ifTrue:[
       
  1403         ^ super transformation.
       
  1404     ].
       
  1405     ^ gc transformation
  1228     ^ gc transformation
  1406 !
  1229 !
  1407 
  1230 
  1408 transformation:aTransformation
  1231 transformation:aTransformation
  1409     "set the transformation"
  1232     "set the transformation"
  1410 
  1233 
  1411     gc == self ifTrue:[
       
  1412         super transformation:aTransformation.
       
  1413         ^ self.
       
  1414     ].
       
  1415     ^ gc transformation:aTransformation
  1234     ^ gc transformation:aTransformation
  1416 !
  1235 !
  1417 
  1236 
  1418 translateBy:aPoint
  1237 translateBy:aPoint
  1419     "add to the translation offset of the transformation"
  1238     "add to the translation offset of the transformation"
  1420 
  1239 
  1421     gc == self ifTrue:[
       
  1422         super translateBy:aPoint.
       
  1423         ^ self.
       
  1424     ].
       
  1425     ^ gc translateBy:aPoint
  1240     ^ gc translateBy:aPoint
  1426 !
  1241 !
  1427 
  1242 
  1428 translation
  1243 translation
  1429     "return the translation factor (as point) of the transformation"
  1244     "return the translation factor (as point) of the transformation"
  1430 
  1245 
  1431     gc == self ifTrue:[
       
  1432         ^ super translation.
       
  1433     ].
       
  1434     ^ gc translation
  1246     ^ gc translation
  1435 !
  1247 !
  1436 
  1248 
  1437 translation:aPoint
  1249 translation:aPoint
  1438     "set the translation offset of the transformation"
  1250     "set the translation offset of the transformation"
  1439 
  1251 
  1440     gc == self ifTrue:[
       
  1441         super translation:aPoint.
       
  1442         ^ self.
       
  1443     ].
       
  1444     ^ gc translation:aPoint
  1252     ^ gc translation:aPoint
  1445 ! !
  1253 ! !
  1446 
  1254 
  1447 !GraphicsMedium methodsFor:'basic drawing'!
  1255 !GraphicsMedium methodsFor:'basic drawing'!
  1448 
  1256 
  1449 displayArcX:x y:y width:width height:height from:startAngle angle:angle
  1257 displayArcX:x y:y width:width height:height from:startAngle angle:angle
  1450     "draw an arc in a box
  1258     "draw an arc in a box
  1451      - this could be recoded to draw using displayLine"
  1259      - this could be recoded to draw using displayLine"
  1452 
  1260 
  1453     gc == self ifTrue:[
       
  1454 	super displayArcX:x y:y width:width height:height from:startAngle angle:angle.
       
  1455 	^ self.
       
  1456     ].
       
  1457     gc displayArcX:x y:y width:width height:height from:startAngle angle:angle
  1261     gc displayArcX:x y:y width:width height:height from:startAngle angle:angle
  1458 !
  1262 !
  1459 
  1263 
  1460 displayDottedRectangleX:x y:y width:w height:h
  1264 displayDottedRectangleX:x y:y width:w height:h
  1461     "draw a dotted-line rectangle
  1265     "draw a dotted-line rectangle
  1462      A general implementation is found here; deviceGC's
  1266      A general implementation is found here; deviceGC's
  1463      may reimplement this if directly supported by the device"
  1267      may reimplement this if directly supported by the device"
  1464 
  1268 
  1465     gc == self ifTrue:[
       
  1466 	super displayDottedRectangleX:x y:y width:w height:h.
       
  1467 	^ self.
       
  1468     ].
       
  1469     gc displayDottedRectangleX:x y:y width:w height:h
  1269     gc displayDottedRectangleX:x y:y width:w height:h
  1470 !
  1270 !
  1471 
  1271 
  1472 displayHorizontalWavelineFromX:x0 y:y0 toX:x1
  1272 displayHorizontalWavelineFromX:x0 y:y0 toX:x1
  1473     "draw a horizontal wave-line from x0/y0 to x1/y0"
  1273     "draw a horizontal wave-line from x0/y0 to x1/y0"
  1474 
  1274 
  1475     gc == self ifTrue:[
       
  1476 	super displayHorizontalWavelineFromX:x0 y:y0 toX:x1.
       
  1477 	^ self.
       
  1478     ].
       
  1479     gc displayHorizontalWavelineFromX:x0 y:y0 toX:x1
  1275     gc displayHorizontalWavelineFromX:x0 y:y0 toX:x1
  1480 !
  1276 !
  1481 
  1277 
  1482 displayLineFromX:x0 y:y0 toX:x1 y:y1
  1278 displayLineFromX:x0 y:y0 toX:x1 y:y1
  1483     "draw a line from x0/y0 to x1/y1"
  1279     "draw a line from x0/y0 to x1/y1"
  1484 
  1280 
  1485     gc == self ifTrue:[
       
  1486 	super displayLineFromX:x0 y:y0 toX:x1 y:y1.
       
  1487 	^ self.
       
  1488     ].
       
  1489     gc displayLineFromX:x0 y:y0 toX:x1 y:y1
  1281     gc displayLineFromX:x0 y:y0 toX:x1 y:y1
  1490 !
  1282 !
  1491 
  1283 
  1492 displayOpaqueForm:aForm x:x y:y
  1284 displayOpaqueForm:aForm x:x y:y
  1493     "draw a form at x/y; if the form has depth 1, 1's in the form are
  1285     "draw a form at x/y; if the form has depth 1, 1's in the form are
  1494      drawn in current fg, 0's in current bg color.
  1286      drawn in current fg, 0's in current bg color.
  1495      If the form has depth ~~ 1, it is copied as is onto the receiver"
  1287      If the form has depth ~~ 1, it is copied as is onto the receiver"
  1496 
  1288 
  1497     gc == self ifTrue:[
       
  1498 	super displayOpaqueForm:aForm x:x y:y.
       
  1499 	^ self.
       
  1500     ].
       
  1501     gc displayOpaqueForm:aForm x:x y:y
  1289     gc displayOpaqueForm:aForm x:x y:y
  1502 !
  1290 !
  1503 
  1291 
  1504 displayOpaqueString:aString from:index1 to:index2 x:x y:y
  1292 displayOpaqueString:aString from:index1 to:index2 x:x y:y
  1505     "draw part of a string with both fg and bg at x/y in current font"
  1293     "draw part of a string with both fg and bg at x/y in current font"
  1506 
  1294 
  1507     gc == self ifTrue:[
       
  1508         super displayString:aString from:index1 to:index2 x:x y:y opaque:true maxWidth:self width.
       
  1509         ^ self.
       
  1510     ].
       
  1511     gc displayString:aString from:index1 to:index2 x:x y:y opaque:true maxWidth:self width
  1295     gc displayString:aString from:index1 to:index2 x:x y:y opaque:true maxWidth:self width
  1512 !
  1296 !
  1513 
  1297 
  1514 displayPolygon:aPolygon
  1298 displayPolygon:aPolygon
  1515     "draw a polygon
  1299     "draw a polygon
  1516      - this could be recoded to draw using displayLine"
  1300      - this could be recoded to draw using displayLine"
  1517 
  1301 
  1518     gc == self ifTrue:[
       
  1519 	super displayPolygon:aPolygon.
       
  1520 	^ self.
       
  1521     ].
       
  1522     gc displayPolygon:aPolygon
  1302     gc displayPolygon:aPolygon
  1523 !
  1303 !
  1524 
  1304 
  1525 displayRectangleX:x y:y width:w height:h
  1305 displayRectangleX:x y:y width:w height:h
  1526     "draw a rectangle
  1306     "draw a rectangle
  1527      - this could be recoded to draw using displayLine"
  1307      - this could be recoded to draw using displayLine"
  1528 
  1308 
  1529     gc == self ifTrue:[
       
  1530 	super displayRectangleX:x y:y width:w height:h.
       
  1531 	^ self.
       
  1532     ].
       
  1533     gc displayRectangleX:x y:y width:w height:h
  1309     gc displayRectangleX:x y:y width:w height:h
  1534 !
  1310 !
  1535 
  1311 
  1536 displayString:aString from:index1 to:index2 x:x y:y
  1312 displayString:aString from:index1 to:index2 x:x y:y
  1537     "draw part of a string with fg at x/y in current font"
  1313     "draw part of a string with fg at x/y in current font"
  1546 !
  1322 !
  1547 
  1323 
  1548 displayString:aString from:index1 to:index2 x:x y:y opaque:opaque maxWidth:maxWidth
  1324 displayString:aString from:index1 to:index2 x:x y:y opaque:opaque maxWidth:maxWidth
  1549     "draw part of a string with both fg and bg at x/y in current font"
  1325     "draw part of a string with both fg and bg at x/y in current font"
  1550 
  1326 
  1551     gc == self ifTrue:[
       
  1552         super displayString:aString from:index1 to:index2 x:x y:y opaque:opaque maxWidth:maxWidth.
       
  1553         ^ self.
       
  1554     ].
       
  1555     gc displayString:aString from:index1 to:index2 x:x y:y opaque:opaque maxWidth:maxWidth
  1327     gc displayString:aString from:index1 to:index2 x:x y:y opaque:opaque maxWidth:maxWidth
  1556 ! !
  1328 ! !
  1557 
  1329 
  1558 !GraphicsMedium methodsFor:'basic filling'!
  1330 !GraphicsMedium methodsFor:'basic filling'!
  1559 
  1331 
  1560 fillArcX:x y:y width:w height:h from:start angle:angle
  1332 fillArcX:x y:y width:w height:h from:start angle:angle
  1561     "fill an arc with current paint color"
  1333     "fill an arc with current paint color"
  1562 
  1334 
  1563     gc == self ifTrue:[
       
  1564 	super fillArcX:x y:y width:w height:h from:start angle:angle.
       
  1565 	^ self.
       
  1566     ].
       
  1567     gc fillArcX:x y:y width:w height:h from:start angle:angle
  1335     gc fillArcX:x y:y width:w height:h from:start angle:angle
  1568 !
  1336 !
  1569 
  1337 
  1570 fillPolygon:points
  1338 fillPolygon:points
  1571     "fill a polygon with current paint color"
  1339     "fill a polygon with current paint color"
  1572 
  1340 
  1573     gc == self ifTrue:[
       
  1574 	super fillPolygon:points.
       
  1575 	^ self.
       
  1576     ].
       
  1577     gc fillPolygon:points
  1341     gc fillPolygon:points
  1578 !
  1342 !
  1579 
  1343 
  1580 fillRectangleX:x y:y width:w height:h
  1344 fillRectangleX:x y:y width:w height:h
  1581     "fill a rectangle with current paint color"
  1345     "fill a rectangle with current paint color"
  1582 
  1346 
  1583     gc == self ifTrue:[
       
  1584 	super fillRectangleX:x y:y width:w height:h.
       
  1585 	^ self.
       
  1586     ].
       
  1587     gc fillRectangleX:x y:y width:w height:h
  1347     gc fillRectangleX:x y:y width:w height:h
  1588 !
  1348 !
  1589 
  1349 
  1590 fillRectangleX:x y:y width:w height:h color:aColor
  1350 fillRectangleX:x y:y width:w height:h color:aColor
  1591     "fill a rectangle with given color"
  1351     "fill a rectangle with given color"
  1592 
  1352 
  1593     gc == self ifTrue:[
       
  1594 	super fillRectangleX:x y:y width:w height:h color:aColor.
       
  1595 	^ self.
       
  1596     ].
       
  1597     gc fillRectangleX:x y:y width:w height:h color:aColor
  1353     gc fillRectangleX:x y:y width:w height:h color:aColor
  1598 ! !
  1354 ! !
  1599 
  1355 
  1600 !GraphicsMedium methodsFor:'bit blitting'!
  1356 !GraphicsMedium methodsFor:'bit blitting'!
  1601 
  1357 
  1604      The bits found there are supposed to be in the devices native format (i.e.
  1360      The bits found there are supposed to be in the devices native format (i.e.
  1605      translated to allocated color indices on pseudoColor devices and padded as required.
  1361      translated to allocated color indices on pseudoColor devices and padded as required.
  1606      The byteOrder is MSB and will be converted as appropriate by the underlying devices
  1362      The byteOrder is MSB and will be converted as appropriate by the underlying devices
  1607      method to whatever the device needs."
  1363      method to whatever the device needs."
  1608 
  1364 
  1609     gc == self ifTrue:[
       
  1610 	super copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth padding:pad width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY.
       
  1611 	^ self.
       
  1612     ].
       
  1613     gc copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth padding:pad width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY
  1365     gc copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth padding:pad width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY
  1614 !
       
  1615 
       
  1616 copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY
       
  1617     "copy bits from a smalltalk byteArray.
       
  1618      The bits found there are supposed to be in the devices native format (i.e.
       
  1619      translated to allocated color indices on pseudoColor devices and padded as required.
       
  1620      The byteOrder is MSB and will be converted as appropriate by the underlying devices
       
  1621      method to whatever the device needs.
       
  1622      Assumes the source bits are in ST/X's natural padding (i.e. 8-bit padded)"
       
  1623 
       
  1624     gc == self ifTrue:[
       
  1625 	super copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY.
       
  1626 	^ self.
       
  1627     ].
       
  1628     gc copyBitsFrom:aByteArray bitsPerPixel:bpp depth:depth width:srcW height:srcH x:srcX y:srcY toX:dstX y:dstY
       
  1629 !
  1366 !
  1630 
  1367 
  1631 copyFrom:aGC toX:dstX y:dstY
  1368 copyFrom:aGC toX:dstX y:dstY
  1632     "copy from a drawable - maybe self"
  1369     "copy from a drawable - maybe self"
  1633 
  1370 
  1634     gc == self ifTrue:[
  1371     self copyFrom:aGC x:0 y:0 toX:dstX y:dstY width:aGC width height:aGC height async:false
  1635 	super copyFrom:aGC toX:dstX y:dstY.
       
  1636 	^ self.
       
  1637     ].
       
  1638     gc copyFrom:aGC toX:dstX y:dstY
       
  1639 !
  1372 !
  1640 
  1373 
  1641 copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h
  1374 copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h
  1642     "copy from a drawable - maybe self"
  1375     "copy from a drawable - maybe self"
  1643 
  1376 
  1644     gc == self ifTrue:[
  1377     self copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h async:false
  1645 	super copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h.
       
  1646 	^ self.
       
  1647     ].
       
  1648     gc copyFrom:aGC x:srcX y:srcY toX:dstX y:dstY width:w height:h
       
  1649 !
  1378 !
  1650 
  1379 
  1651 copyFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h async:async
  1380 copyFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h async:async
  1652     "copy from aDrawable into the receiver;
  1381     "copy from aDrawable into the receiver;
  1653      the source may be the receiver as well - in this case its a scroll.
  1382      the source may be the receiver as well - in this case its a scroll.
  1655      If the receiver is a view AND async is true, the call returns immediately
  1384      If the receiver is a view AND async is true, the call returns immediately
  1656      - otherwise, it returns when the scroll operation is finished.
  1385      - otherwise, it returns when the scroll operation is finished.
  1657      (not all devices care for this).
  1386      (not all devices care for this).
  1658      If the receiver is a pixmap, the call always returns immediately."
  1387      If the receiver is a pixmap, the call always returns immediately."
  1659 
  1388 
  1660     |myDevice deviceDrawable asy|
  1389     |deviceDrawable mustWait|
  1661 
  1390 
  1662     myDevice := gc graphicsDevice.
  1391     ((aDrawable graphicsDevice ~~ device)
  1663 
       
  1664     ((aDrawable graphicsDevice ~~ myDevice)
       
  1665      or:[aDrawable isImage]) ifTrue:[
  1392      or:[aDrawable isImage]) ifTrue:[
  1666         deviceDrawable := aDrawable asFormOn:myDevice.
  1393         deviceDrawable := aDrawable asFormOn:device.
  1667     ] ifFalse:[
  1394     ] ifFalse:[
  1668         deviceDrawable := aDrawable
  1395         deviceDrawable := aDrawable
  1669     ].
  1396     ].
  1670     asy := async or:[self isView not or:[ deviceDrawable isForm ]].
  1397     mustWait := async not and:[deviceDrawable isView and:[((deviceDrawable depth ~~ 1) or:[device depth == 1])]].
  1671     asy ifFalse:[
  1398     mustWait ifTrue:[
  1672         self catchExpose
  1399         mustWait := self catchExpose.
  1673     ].
  1400     ].
  1674     gc == self ifTrue:[
  1401     gc copyFrom:deviceDrawable graphicsContext x:srcX y:srcY toX:dstX y:dstY width:w height:h depth:self depth.
  1675         super copyFrom:deviceDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h async:true.
  1402     mustWait ifTrue:[
  1676     ] ifFalse:[
       
  1677         gc copyFrom:deviceDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h async:true.
       
  1678     ].
       
  1679     asy ifFalse:[
       
  1680         myDevice flush.
       
  1681         self waitForExpose
  1403         self waitForExpose
  1682     ]
  1404     ]
  1683 
       
  1684     "Modified: / 26-04-2016 / 20:30:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  1685 !
  1405 !
  1686 
  1406 
  1687 copyFrom:aGC x:dstX y:dstY width:w height:h
  1407 copyFrom:aGC x:dstX y:dstY width:w height:h
  1688     "copy from a drawable - maybe self"
  1408     "copy from a drawable - maybe self"
  1689 
  1409 
  1690     gc == self ifTrue:[
  1410     self copyFrom:aGC x:0 y:0 toX:dstX y:dstY width:w height:h async:false
  1691 	super copyFrom:aGC x:dstX y:dstY width:w height:h.
       
  1692 	^ self.
       
  1693     ].
       
  1694     gc copyFrom:aGC x:dstX y:dstY width:w height:h
       
  1695 !
  1411 !
  1696 
  1412 
  1697 copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h
  1413 copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h
  1698     "copy one plane from aDrawable into the receiver. 0's are drawn in
  1414     "copy one plane from aDrawable into the receiver. 0's are drawn in
  1699      background, while 1's are drawn with foreground color.
  1415      background, while 1's are drawn with foreground color.
  1700      The depth of aDrawable must (should) be 1.
  1416      The depth of aDrawable must (should) be 1.
  1701      The drawable must have been allocated on the same device.
  1417      The drawable must have been allocated on the same device.
  1702      All coordinates are in device coordinates."
  1418      All coordinates are in device coordinates."
  1703 
  1419 
  1704     gc == self ifTrue:[
  1420     |deviceDrawable|
  1705 	super copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h.
  1421 
  1706 	^ self.
  1422     ((aDrawable graphicsDevice ~~ device)
  1707     ].
  1423     or:[aDrawable isImage]) ifTrue:[
  1708     gc copyPlaneFrom:aDrawable x:srcX y:srcY toX:dstX y:dstY width:w height:h
  1424         deviceDrawable := aDrawable asFormOn:device.
       
  1425     ] ifFalse:[
       
  1426         deviceDrawable := aDrawable
       
  1427     ].
       
  1428 
       
  1429     gc copyPlaneFrom:deviceDrawable graphicsContext x:srcX y:srcY toX:dstX y:dstY width:w height:h
  1709 ! !
  1430 ! !
  1710 
  1431 
  1711 !GraphicsMedium methodsFor:'copying'!
  1432 !GraphicsMedium methodsFor:'copying'!
  1712 
  1433 
  1713 postCopy
  1434 postCopy
  1776 !
  1497 !
  1777 
  1498 
  1778 displayCircle:aPoint radius:r
  1499 displayCircle:aPoint radius:r
  1779     "draw a circle around a center point"
  1500     "draw a circle around a center point"
  1780 
  1501 
  1781     gc == self ifTrue:[
       
  1782 	super displayCircleX:(aPoint x) y:(aPoint y) radius:r.
       
  1783 	^ self.
       
  1784     ].
       
  1785     gc displayCircleX:(aPoint x) y:(aPoint y) radius:r
  1502     gc displayCircleX:(aPoint x) y:(aPoint y) radius:r
  1786 !
  1503 !
  1787 
  1504 
  1788 displayCircleIn:aRectangle
  1505 displayCircleIn:aRectangle
  1789     "draw a circle in a box"
  1506     "draw a circle in a box"
  1816 !
  1533 !
  1817 
  1534 
  1818 displayForm:aFormOrImage
  1535 displayForm:aFormOrImage
  1819     "draw a form (or image) at the origin"
  1536     "draw a form (or image) at the origin"
  1820 
  1537 
  1821     gc == self ifTrue:[
       
  1822 	super displayForm:aFormOrImage x:0 y:0.
       
  1823 	^ self.
       
  1824     ].
       
  1825     gc displayForm:aFormOrImage x:0 y:0
  1538     gc displayForm:aFormOrImage x:0 y:0
  1826 
  1539 
  1827     "Modified: / 24.4.1997 / 16:00:11 / cg"
  1540     "Modified: / 24.4.1997 / 16:00:11 / cg"
  1828     "Created: / 9.11.1997 / 00:50:52 / cg"
  1541     "Created: / 9.11.1997 / 00:50:52 / cg"
  1829 !
  1542 !
  1830 
  1543 
  1831 displayForm:aFormOrImage at:aPoint
  1544 displayForm:aFormOrImage at:aPoint
  1832     "draw a form (or image)"
  1545     "draw a form (or image)"
  1833 
  1546 
  1834     gc == self ifTrue:[
       
  1835 	super displayForm:aFormOrImage x:(aPoint x) y:(aPoint y).
       
  1836 	^ self.
       
  1837     ].
       
  1838     gc displayForm:aFormOrImage x:(aPoint x) y:(aPoint y)
  1547     gc displayForm:aFormOrImage x:(aPoint x) y:(aPoint y)
  1839 
  1548 
  1840     "Modified: 24.4.1997 / 16:00:11 / cg"
  1549     "Modified: 24.4.1997 / 16:00:11 / cg"
  1841 !
  1550 !
  1842 
  1551 
  1851      (by sending #on: to the color) before doing so.
  1560      (by sending #on: to the color) before doing so.
  1852      Using functions other than #copy only makes sense if you are
  1561      Using functions other than #copy only makes sense if you are
  1853      certain, that the colors are real colors (actually, only for
  1562      certain, that the colors are real colors (actually, only for
  1854      noColor or allColor)."
  1563      noColor or allColor)."
  1855 
  1564 
  1856     gc == self ifTrue:[
       
  1857 	super displayForm:formToDraw x:x y:y.
       
  1858 	^ self.
       
  1859     ].
       
  1860     gc displayForm:formToDraw x:x y:y
  1565     gc displayForm:formToDraw x:x y:y
  1861 !
  1566 !
  1862 
  1567 
  1863 displayForm:aFormOrImage x:x y:y opaque:opaque
  1568 displayForm:aFormOrImage x:x y:y opaque:opaque
  1864     "draw a form (or image) at x/y;
  1569     "draw a form (or image) at x/y;
  1876 displayImage:aFormOrImage
  1581 displayImage:aFormOrImage
  1877     "draw an image (or form).
  1582     "draw an image (or form).
  1878      Provided for ST-80 compatibilty;
  1583      Provided for ST-80 compatibilty;
  1879      in ST/X, images are also handled by #displayForm:"
  1584      in ST/X, images are also handled by #displayForm:"
  1880 
  1585 
  1881     gc == self ifTrue:[
       
  1882 	super displayForm:aFormOrImage x:0 y:0.
       
  1883 	^ self.
       
  1884     ].
       
  1885     gc displayForm:aFormOrImage x:0 y:0
  1586     gc displayForm:aFormOrImage x:0 y:0
  1886 !
  1587 !
  1887 
  1588 
  1888 displayImage:aFormOrImage at:aPoint
  1589 displayImage:aFormOrImage at:aPoint
  1889     "draw an image (or form).
  1590     "draw an image (or form).
  1890      Provided for ST-80 compatibilty;
  1591      Provided for ST-80 compatibilty;
  1891      in ST/X, images are also handled by #displayForm:"
  1592      in ST/X, images are also handled by #displayForm:"
  1892 
  1593 
  1893     gc == self ifTrue:[
       
  1894 	super displayForm:aFormOrImage x:(aPoint x) y:(aPoint y).
       
  1895 	^ self.
       
  1896     ].
       
  1897     gc displayForm:aFormOrImage x:(aPoint x) y:(aPoint y)
  1594     gc displayForm:aFormOrImage x:(aPoint x) y:(aPoint y)
  1898 
  1595 
  1899     "Modified: 24.4.1997 / 16:02:43 / cg"
  1596     "Modified: 24.4.1997 / 16:02:43 / cg"
  1900 !
  1597 !
  1901 
  1598 
  1902 displayImage:aFormOrImage x:x y:y
  1599 displayImage:aFormOrImage x:x y:y
  1903     "draw an image (or form).
  1600     "draw an image (or form).
  1904      Provided for ST-80 compatibilty;
  1601      Provided for ST-80 compatibilty;
  1905      in ST/X, images are also handled by #displayForm:"
  1602      in ST/X, images are also handled by #displayForm:"
  1906 
  1603 
  1907     gc == self ifTrue:[
       
  1908 	super displayForm:aFormOrImage x:x y:y.
       
  1909 	^ self.
       
  1910     ].
       
  1911     gc displayForm:aFormOrImage x:x y:y
  1604     gc displayForm:aFormOrImage x:x y:y
  1912 
  1605 
  1913     "Created: 24.4.1997 / 16:03:03 / cg"
  1606     "Created: 24.4.1997 / 16:03:03 / cg"
  1914 !
  1607 !
  1915 
  1608 
  1916 displayLineFrom:point1 to:point2
  1609 displayLineFrom:point1 to:point2
  1917     "draw a line"
  1610     "draw a line"
  1918 
  1611 
  1919     gc == self ifTrue:[
       
  1920 	super displayLineFromX:(point1 x) y:(point1 y)
       
  1921 		      toX:(point2 x) y:(point2 y).
       
  1922 	^ self.
       
  1923     ].
       
  1924     gc displayLineFromX:(point1 x) y:(point1 y)
  1612     gc displayLineFromX:(point1 x) y:(point1 y)
  1925 		      toX:(point2 x) y:(point2 y)
  1613                       toX:(point2 x) y:(point2 y)
  1926 !
  1614 !
  1927 
  1615 
  1928 displayLineFromX:xStart y:yStart toX:xEnd y:yEnd brush:aForm
  1616 displayLineFromX:xStart y:yStart toX:xEnd y:yEnd brush:aForm
  1929     "draw a line using a brush.
  1617     "draw a line using a brush.
  1930      Here, a slow fallback is used, drawing into a
  1618      Here, a slow fallback is used, drawing into a
  1932 
  1620 
  1933     |deltaX deltaY dx dy px py destX destY p tempForm
  1621     |deltaX deltaY dx dy px py destX destY p tempForm
  1934      xMin xMax yMin yMax x1 x2 y1 y2|
  1622      xMin xMax yMin yMax x1 x2 y1 y2|
  1935 
  1623 
  1936     xStart < xEnd ifTrue:[
  1624     xStart < xEnd ifTrue:[
  1937         xMin := xStart.
  1625 	xMin := xStart.
  1938         xMax := xEnd.
  1626 	xMax := xEnd.
  1939     ] ifFalse:[
  1627     ] ifFalse:[
  1940         xMin := xEnd.
  1628 	xMin := xEnd.
  1941         xMax := xStart
  1629 	xMax := xStart
  1942     ].
  1630     ].
  1943     yStart < yEnd ifTrue:[
  1631     yStart < yEnd ifTrue:[
  1944         yMin := yStart.
  1632 	yMin := yStart.
  1945         yMax := yEnd.
  1633 	yMax := yEnd.
  1946     ] ifFalse:[
  1634     ] ifFalse:[
  1947         yMin := yEnd.
  1635 	yMin := yEnd.
  1948         yMax := yStart
  1636 	yMax := yStart
  1949     ].
  1637     ].
  1950 
  1638 
  1951     tempForm := Form width:(xMax-xMin+1+aForm width)
  1639     tempForm := Form width:(xMax-xMin+1+aForm width)
  1952                      height:(yMax-yMin+1+aForm height)
  1640 		     height:(yMax-yMin+1+aForm height)
  1953                      depth:aForm depth
  1641 		     depth:aForm depth
  1954                      onDevice:device.
  1642 		     onDevice:self graphicsDevice.
  1955     tempForm clear.
  1643     tempForm clear.
  1956     tempForm paint:(Color colorId:1) on:(Color colorId:0).
  1644     tempForm paint:(Color colorId:1) on:(Color colorId:0).
  1957     tempForm function:#or.
  1645     tempForm function:#or.
  1958 
  1646 
  1959     ((yStart = yEnd and:[xStart < xEnd])
  1647     ((yStart = yEnd and:[xStart < xEnd])
  1960     or: [yStart < yEnd]) ifTrue:[
  1648     or: [yStart < yEnd]) ifTrue:[
  1961         x1 := xStart. y1 := yStart.
  1649 	x1 := xStart. y1 := yStart.
  1962         x2 := xEnd. y2 := yEnd.
  1650 	x2 := xEnd. y2 := yEnd.
  1963     ] ifFalse:[
  1651     ] ifFalse:[
  1964         x1 := xEnd. y1 := yEnd.
  1652 	x1 := xEnd. y1 := yEnd.
  1965         x2 := xStart. y2 := yStart.
  1653 	x2 := xStart. y2 := yStart.
  1966     ].
  1654     ].
  1967 
  1655 
  1968     x1 := x1 - xMin.  x2 := x2 - xMin.
  1656     x1 := x1 - xMin.  x2 := x2 - xMin.
  1969     y1 := y1 - yMin.  y2 := y2 - yMin.
  1657     y1 := y1 - yMin.  y2 := y2 - yMin.
  1970 
  1658 
  1982     py := deltaX abs.
  1670     py := deltaX abs.
  1983 
  1671 
  1984     tempForm displayForm:aForm x:destX y:destY.
  1672     tempForm displayForm:aForm x:destX y:destY.
  1985 
  1673 
  1986     py > px ifTrue:[
  1674     py > px ifTrue:[
  1987         "horizontal"
  1675 	"horizontal"
  1988         p := py // 2.
  1676 	p := py // 2.
  1989         py timesRepeat:[
  1677 	py timesRepeat:[
  1990             destX := destX + dx.
  1678 	    destX := destX + dx.
  1991             (p := p - px) < 0 ifTrue:[
  1679 	    (p := p - px) < 0 ifTrue:[
  1992                 destY := destY + dy.
  1680 		destY := destY + dy.
  1993                 p := p + py
  1681 		p := p + py
  1994             ].
  1682 	    ].
  1995             tempForm displayForm:aForm x:destX y:destY.
  1683 	    tempForm displayForm:aForm x:destX y:destY.
  1996         ]
  1684 	]
  1997     ] ifFalse:[
  1685     ] ifFalse:[
  1998         "vertical"
  1686 	"vertical"
  1999         p := px // 2.
  1687 	p := px // 2.
  2000         px timesRepeat:[
  1688 	px timesRepeat:[
  2001             destY := destY + dy.
  1689 	    destY := destY + dy.
  2002             (p := p - py) < 0 ifTrue:[
  1690 	    (p := p - py) < 0 ifTrue:[
  2003                 destX := destX + dx.
  1691 		destX := destX + dx.
  2004                 p := p + px
  1692 		p := p + px
  2005             ].
  1693 	    ].
  2006             tempForm displayForm:aForm x:destX y:destY
  1694 	    tempForm displayForm:aForm x:destX y:destY
  2007         ]
  1695 	]
  2008     ].
  1696     ].
  2009     self displayForm:tempForm
  1697     self displayForm:tempForm
  2010                    x:xMin-aForm offset x
  1698 		   x:xMin-aForm offset x
  2011                    y:yMin-aForm offset y.
  1699 		   y:yMin-aForm offset y.
  2012     tempForm close
  1700     tempForm close
  2013 
  1701 
  2014     "Modified: 1.4.1997 / 21:29:06 / cg"
  1702     "Modified: 1.4.1997 / 21:29:06 / cg"
  2015 !
  1703 !
  2016 
  1704 
  2017 displayOpaqueString:aString at:aPoint
  1705 displayOpaqueString:aString at:aPoint
  2018     "draw a string with both fg and bg"
  1706     "draw a string with both fg and bg"
  2019 
  1707 
  2020     gc == self ifTrue:[
       
  2021 	super displayOpaqueString:aString x:(aPoint x) y:(aPoint y).
       
  2022 	^ self.
       
  2023     ].
       
  2024     gc displayOpaqueString:aString x:(aPoint x) y:(aPoint y)
  1708     gc displayOpaqueString:aString x:(aPoint x) y:(aPoint y)
  2025 !
  1709 !
  2026 
  1710 
  2027 displayOpaqueString:aString from:start to:stop at:aPoint
  1711 displayOpaqueString:aString from:start to:stop at:aPoint
  2028     "draw part of a string - drawing both fg and bg"
  1712     "draw part of a string - drawing both fg and bg"
  2035      background pixels in bgPaint color. If the transformation involves scaling,
  1719      background pixels in bgPaint color. If the transformation involves scaling,
  2036      the fonts point-size is scaled as appropriate.
  1720      the fonts point-size is scaled as appropriate.
  2037      Assuming that device can only draw in device colors, we have to handle
  1721      Assuming that device can only draw in device colors, we have to handle
  2038      the case where paint and/or bgPaint are dithered colors or images."
  1722      the case where paint and/or bgPaint are dithered colors or images."
  2039 
  1723 
  2040     gc == self ifTrue:[
       
  2041 	super displayOpaqueString:aString x:x y:y.
       
  2042 	^ self.
       
  2043     ].
       
  2044     gc displayOpaqueString:aString x:x y:y
  1724     gc displayOpaqueString:aString x:x y:y
  2045 !
  1725 !
  2046 
  1726 
  2047 displayOpaqueString:aString x:x y:y angle:drawAngle
  1727 displayOpaqueString:aString x:x y:y angle:drawAngle
  2048     "draw a string along a (possibly non-horizontal) line,
  1728     "draw a string along a (possibly non-horizontal) line,
  2050      The angle is in degrees, clock-wise, starting with 0 for
  1730      The angle is in degrees, clock-wise, starting with 0 for
  2051      a horizontal draw.
  1731      a horizontal draw.
  2052      Drawing is done by first drawing the string into a temporary bitmap,
  1732      Drawing is done by first drawing the string into a temporary bitmap,
  2053      which is rotated and finally drawn as usual.
  1733      which is rotated and finally drawn as usual.
  2054      NOTICE: due to the rotation of the temporary bitmap, this is a slow
  1734      NOTICE: due to the rotation of the temporary bitmap, this is a slow
  2055 	     operation - not to be used with cillions of strings ..."
  1735              operation - not to be used with cillions of strings ..."
  2056 
  1736 
  2057     gc == self ifTrue:[
       
  2058 	super displayString:aString x:x y:y angle:drawAngle opaque:true.
       
  2059 	^ self.
       
  2060     ].
       
  2061     gc displayString:aString x:x y:y angle:drawAngle opaque:true
  1737     gc displayString:aString x:x y:y angle:drawAngle opaque:true
  2062 
  1738 
  2063     "
  1739     "
  2064      |v|
  1740      |v|
  2065 
  1741 
  2066      v := View new.
  1742      v := View new.
  2067      v extent:300@200.
  1743      v extent:300@200.
  2068      v openAndWait.
  1744      v openAndWait.
  2069      0 to:360 by:45 do:[:a |
  1745      0 to:360 by:45 do:[:a |
  2070 	 v paint:Color black on:Color red.
  1746          v paint:Color black on:Color red.
  2071 	 v displayOpaqueString:'hello world' x:100 y:100 angle:a.
  1747          v displayOpaqueString:'hello world' x:100 y:100 angle:a.
  2072      ].
  1748      ].
  2073     "
  1749     "
  2074 
  1750 
  2075     "in contrast to non-opaque draw:
  1751     "in contrast to non-opaque draw:
  2076      |v|
  1752      |v|
  2077 
  1753 
  2078      v := View new.
  1754      v := View new.
  2079      v extent:300@200.
  1755      v extent:300@200.
  2080      v openAndWait.
  1756      v openAndWait.
  2081      0 to:360 by:45 do:[:a |
  1757      0 to:360 by:45 do:[:a |
  2082 	 v paint:Color black on:Color red.
  1758          v paint:Color black on:Color red.
  2083 	 v displayString:'hello world' x:100 y:100 angle:a.
  1759          v displayString:'hello world' x:100 y:100 angle:a.
  2084      ].
  1760      ].
  2085     "
  1761     "
  2086 
  1762 
  2087     "Modified: 23.4.1997 / 17:50:23 / cg"
  1763     "Modified: 23.4.1997 / 17:50:23 / cg"
  2088 !
  1764 !
  2089 
  1765 
  2090 displayPoint:aPoint
  1766 displayPoint:aPoint
  2091     "draw a pixel"
  1767     "draw a pixel"
  2092 
  1768 
  2093     gc == self ifTrue:[
       
  2094 	super displayPointX:(aPoint x) y:(aPoint y).
       
  2095 	^ self.
       
  2096     ].
       
  2097     gc displayPointX:(aPoint x) y:(aPoint y)
  1769     gc displayPointX:(aPoint x) y:(aPoint y)
  2098 !
  1770 !
  2099 
  1771 
  2100 displayPointX:x y:y
  1772 displayPointX:x y:y
  2101     "draw a point (with current paint-color); apply transformation if nonNil"
  1773     "draw a point (with current paint-color); apply transformation if nonNil"
  2102 
  1774 
  2103     gc == self ifTrue:[
       
  2104 	super displayPointX:x y:y.
       
  2105 	^ self.
       
  2106     ].
       
  2107     gc displayPointX:x y:y
  1775     gc displayPointX:x y:y
  2108 !
  1776 !
  2109 
  1777 
  2110 displayRectangle:aRectangle
  1778 displayRectangle:aRectangle
  2111     "draw a rectangle"
  1779     "draw a rectangle"
  2134     self displayRectangleX:(origin x) y:(origin y)
  1802     self displayRectangleX:(origin x) y:(origin y)
  2135 		     width:(extent x)
  1803 		     width:(extent x)
  2136 		    height:(extent y)
  1804 		    height:(extent y)
  2137 !
  1805 !
  2138 
  1806 
  2139 displayRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
  1807 displayRoundRectangleX:left y:top width:width height:height wCorner:wCorn hCorner:hCorn
  2140     gc displayRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
  1808     |right bottom wC hC wHalf hHalf isWin32|
  2141 
  1809 
  2142     "Modified: / 07-01-2015 / 20:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  1810     "/ BIG KLUDGE WARNING HERE: the code below looks "good" on windows displays;
       
  1811     "/ (if you change anything under Unix, make it X-platform specific.
       
  1812     "/ (there seem to be drawing incompatibilities between Win- and XWorkstation)
       
  1813 
       
  1814     isWin32 := self device isWindowsPlatform.
       
  1815 
       
  1816     right := left + width-1.
       
  1817     bottom := top + height-1.
       
  1818 
       
  1819     wC := wCorn.
       
  1820     hC := hCorn.
       
  1821 
       
  1822     self scale = 1 ifTrue:[
       
  1823 	wHalf := wC // 2.
       
  1824 	hHalf := hC // 2.
       
  1825     ] ifFalse:[
       
  1826 	wHalf := wC / 2.
       
  1827 	hHalf := hC / 2.
       
  1828     ].
       
  1829 
       
  1830     "top left arc"
       
  1831     self displayArcX:left y:top width:wC height:hC from:90 angle:90.
       
  1832 
       
  1833     "top right arc"
       
  1834     self displayArcX:(right - wC) y:top width:wC height:hC from:0 angle:90.
       
  1835 
       
  1836     "bottom right arc"
       
  1837     (isWin32 and:[self scale = 1]) ifTrue:[
       
  1838 	self displayArcX:(right - wC+1) y:(bottom - hC+1) width:wC height:hC from:270 angle:90.
       
  1839     ] ifFalse:[
       
  1840 	self displayArcX:(right - wC) y:(bottom - hC) width:wC height:hC from:270 angle:90.
       
  1841     ].
       
  1842 
       
  1843     "bottom left arc"
       
  1844     self displayArcX:left y:(bottom - hC) width:wC height:hC from:180 angle:90.
       
  1845 
       
  1846     "top line"
       
  1847     self displayLineFromX:(left + wHalf) y:top toX:(right - wHalf-1) y:top.
       
  1848 
       
  1849     "left line"
       
  1850     self displayLineFromX:left y:(top + hHalf - 1) toX:left y:(bottom - hHalf - 2).
       
  1851 
       
  1852     "bottom line"
       
  1853     self displayLineFromX:(left + wHalf-1) y:bottom
       
  1854 		      toX:(right - wHalf ) y:bottom.
       
  1855 
       
  1856     "right line"
       
  1857     self displayLineFromX:right y:(top + hHalf) toX:right y:(bottom - hHalf).
       
  1858 
       
  1859 
       
  1860     "
       
  1861      |v|
       
  1862 
       
  1863      (v := View new) extent:200@200; openAndWait.
       
  1864      v displayRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20
       
  1865     "
  2143 !
  1866 !
  2144 
  1867 
  2145 displayString:aString at:aPoint
  1868 displayString:aString at:aPoint
  2146     "draw a string - drawing fg only"
  1869     "draw a string - drawing fg only"
  2147 
  1870 
  2249      The angle is in degrees, clock-wise, starting with 0 for
  1972      The angle is in degrees, clock-wise, starting with 0 for
  2250      a horizontal draw.
  1973      a horizontal draw.
  2251      Drawing is done by first drawing the string into a temporary bitmap,
  1974      Drawing is done by first drawing the string into a temporary bitmap,
  2252      which is rotated and finally drawn as usual.
  1975      which is rotated and finally drawn as usual.
  2253      NOTICE: due to the rotation of the temporary bitmap, this is a slow
  1976      NOTICE: due to the rotation of the temporary bitmap, this is a slow
  2254 	     operation - not to be used with cillions of strings ...
  1977              operation - not to be used with cillions of strings ...
  2255      CAVEAT: if the string is not a real string (i.e. a LabelAndIcon),
  1978      CAVEAT: if the string is not a real string (i.e. a LabelAndIcon),
  2256 	     this can (currently) only be done opaque"
  1979              this can (currently) only be done opaque"
  2257 
  1980 
  2258     gc == self ifTrue:[
       
  2259 	super displayString:aString x:x y:y angle:drawAngle opaque:opaque.
       
  2260 	^ self.
       
  2261     ].
       
  2262     gc displayString:aString x:x y:y angle:drawAngle opaque:opaque
  1981     gc displayString:aString x:x y:y angle:drawAngle opaque:opaque
  2263 !
  1982 !
  2264 
  1983 
  2265 displayUnscaledForm:formToDraw x:x y:y
  1984 displayUnscaledForm:formToDraw x:x y:y
  2266     "draw a form or image non opaque and unscaled;
  1985     "draw a form or image non opaque and unscaled;
  2274      Using functions other than #copy only makes sense if you are
  1993      Using functions other than #copy only makes sense if you are
  2275      certain, that the colors are real colors (actually, only for
  1994      certain, that the colors are real colors (actually, only for
  2276      noColor or allColor).
  1995      noColor or allColor).
  2277      The origins coordinate is transformed, but the image itself is unscaled."
  1996      The origins coordinate is transformed, but the image itself is unscaled."
  2278 
  1997 
  2279     gc == self ifTrue:[
       
  2280 	super displayUnscaledForm:formToDraw x:x y:y.
       
  2281 	^ self.
       
  2282     ].
       
  2283     gc displayUnscaledForm:formToDraw x:x y:y
  1998     gc displayUnscaledForm:formToDraw x:x y:y
  2284 !
  1999 !
  2285 
  2000 
  2286 displayUnscaledOpaqueForm:formToDraw x:x y:y
  2001 displayUnscaledOpaqueForm:formToDraw x:x y:y
  2287     "draw a form or image opaque and unscaled;
  2002     "draw a form or image opaque and unscaled;
  2289      current paint-color, 0 bits in background color.
  2004      current paint-color, 0 bits in background color.
  2290      If its a deep form (i.e. a pixmap) the current paint
  2005      If its a deep form (i.e. a pixmap) the current paint
  2291      settings are ignored and the form is drawn as-is (opaque).
  2006      settings are ignored and the form is drawn as-is (opaque).
  2292      The origins coordinate is transformed, but the image itself is unscaled."
  2007      The origins coordinate is transformed, but the image itself is unscaled."
  2293 
  2008 
  2294     gc == self ifTrue:[
       
  2295 	super displayUnscaledOpaqueForm:formToDraw x:x y:y.
       
  2296 	^ self.
       
  2297     ].
       
  2298     gc displayUnscaledOpaqueForm:formToDraw x:x y:y
  2009     gc displayUnscaledOpaqueForm:formToDraw x:x y:y
  2299 !
  2010 !
  2300 
  2011 
  2301 displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y
  2012 displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y
  2302     "draw a substring at the transformed coordinate x/y but do not scale the font.
  2013     "draw a substring at the transformed coordinate x/y but do not scale the font.
  2303      Draw foreground pixels in paint-color, background pixels in bgPaint color."
  2014      Draw foreground pixels in paint-color, background pixels in bgPaint color."
  2304 
  2015 
  2305     gc == self ifTrue:[
       
  2306 	super displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y.
       
  2307 	^ self.
       
  2308     ].
       
  2309     gc displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y
  2016     gc displayUnscaledOpaqueString:aString from:index1 to:index2 x:x y:y
  2310 !
  2017 !
  2311 
  2018 
  2312 displayUnscaledOpaqueString:aString x:x y:y
  2019 displayUnscaledOpaqueString:aString x:x y:y
  2313     "draw a string at the transformed coordinate x/y but do not scale the font.
  2020     "draw a string at the transformed coordinate x/y but do not scale the font.
  2314      Draw foreground pixels in paint-color, background pixels in bgPaint color."
  2021      Draw foreground pixels in paint-color, background pixels in bgPaint color."
  2315 
  2022 
  2316     gc == self ifTrue:[
       
  2317 	super displayUnscaledOpaqueString:aString x:x y:y.
       
  2318 	^ self.
       
  2319     ].
       
  2320     gc displayUnscaledOpaqueString:aString x:x y:y
  2023     gc displayUnscaledOpaqueString:aString x:x y:y
  2321 !
  2024 !
  2322 
  2025 
  2323 displayUnscaledString:aString from:index1 to:index2 x:x y:y
  2026 displayUnscaledString:aString from:index1 to:index2 x:x y:y
  2324     "draw a substring at the transformed coordinate x/y but do not scale the font.
  2027     "draw a substring at the transformed coordinate x/y but do not scale the font.
  2325      draw foreground-pixels only (in current paint-color), leaving background as-is."
  2028      draw foreground-pixels only (in current paint-color), leaving background as-is."
  2326 
  2029 
  2327     gc == self ifTrue:[
       
  2328 	super displayUnscaledString:aString from:index1 to:index2 x:x y:y.
       
  2329 	^ self.
       
  2330     ].
       
  2331     gc displayUnscaledString:aString from:index1 to:index2 x:x y:y
  2030     gc displayUnscaledString:aString from:index1 to:index2 x:x y:y
  2332 !
  2031 !
  2333 
  2032 
  2334 displayUnscaledString:aString x:x y:y
  2033 displayUnscaledString:aString x:x y:y
  2335     "draw a string at the transformed coordinate x/y but do not scale the font.
  2034     "draw a string at the transformed coordinate x/y but do not scale the font.
  2336      draw foreground-pixels only (in current paint-color), leaving background as-is."
  2035      draw foreground-pixels only (in current paint-color), leaving background as-is."
  2337 
  2036 
  2338     gc == self ifTrue:[
       
  2339 	super displayUnscaledString:aString x:x y:y.
       
  2340 	^ self.
       
  2341     ].
       
  2342     gc displayUnscaledString:aString x:x y:y
  2037     gc displayUnscaledString:aString x:x y:y
  2343 ! !
  2038 ! !
  2344 
  2039 
  2345 !GraphicsMedium methodsFor:'drawing in device coordinates'!
  2040 !GraphicsMedium methodsFor:'drawing in device coordinates'!
  2346 
  2041 
  2360      (by sending #on: to the color) before doing so.
  2055      (by sending #on: to the color) before doing so.
  2361      Using functions other than #copy only makes sense if you are
  2056      Using functions other than #copy only makes sense if you are
  2362      certain, that the colors are real colors (actually, only for
  2057      certain, that the colors are real colors (actually, only for
  2363      noColor or allColor)."
  2058      noColor or allColor)."
  2364 
  2059 
  2365     gc == self ifTrue:[
       
  2366 	super displayDeviceForm:aForm x:x y:y.
       
  2367 	^ self.
       
  2368     ].
       
  2369     gc displayDeviceForm:aForm x:x y:y
  2060     gc displayDeviceForm:aForm x:x y:y
  2370 !
  2061 !
  2371 
  2062 
  2372 displayDeviceLineFromX:x1 y:y1 toX:x2 y:y2
  2063 displayDeviceLineFromX:x1 y:y1 toX:x2 y:y2
  2373     "draw a line in device coordinates"
  2064     "draw a line in device coordinates"
  2374 
  2065 
  2375     gc == self ifTrue:[
       
  2376 	super displayDeviceLineFromX:x1 y:y1 toX:x2 y:y2.
       
  2377 	^ self.
       
  2378     ].
       
  2379     gc displayDeviceLineFromX:x1 y:y1 toX:x2 y:y2
  2066     gc displayDeviceLineFromX:x1 y:y1 toX:x2 y:y2
  2380 !
  2067 !
  2381 
  2068 
  2382 displayDeviceOpaqueForm:aForm x:x y:y
  2069 displayDeviceOpaqueForm:aForm x:x y:y
  2383     "draw a form or image opaque (i.e. both fg and bg is drawn);
  2070     "draw a form or image opaque (i.e. both fg and bg is drawn);
  2391      to the colors) before doing so.
  2078      to the colors) before doing so.
  2392      The form should have been allocated on the same device; otherwise,
  2079      The form should have been allocated on the same device; otherwise,
  2393      its converted here, which slows down the draw.
  2080      its converted here, which slows down the draw.
  2394      Drawing is in device coordinates; no scaling is done."
  2081      Drawing is in device coordinates; no scaling is done."
  2395 
  2082 
  2396     gc == self ifTrue:[
       
  2397 	super displayDeviceOpaqueForm:aForm x:x y:y.
       
  2398 	^ self.
       
  2399     ].
       
  2400     gc displayDeviceOpaqueForm:aForm x:x y:y
  2083     gc displayDeviceOpaqueForm:aForm x:x y:y
  2401 !
       
  2402 
       
  2403 displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
       
  2404     "draw a substring at the coordinate x/y - draw foreground pixels in
       
  2405      paint-color and background pixels in bgPaint-color.
       
  2406      Assuming that device can only draw in device colors, we have to handle
       
  2407      the case where paint and/or bgPaint are dithered colors.
       
  2408      No translation or scaling is done."
       
  2409 
       
  2410     gc == self ifTrue:[
       
  2411 	super displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y.
       
  2412 	^ self.
       
  2413     ].
       
  2414     gc displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
       
  2415 !
  2084 !
  2416 
  2085 
  2417 displayDeviceOpaqueString:aString from:index1 to:index2 x:x y:y
  2086 displayDeviceOpaqueString:aString from:index1 to:index2 x:x y:y
  2418     "draw a substring at the coordinate x/y - draw foreground pixels in
  2087     "draw a substring at the coordinate x/y - draw foreground pixels in
  2419      paint-color and background pixels in bgPaint-color.
  2088      paint-color and background pixels in bgPaint-color.
  2433 !
  2102 !
  2434 
  2103 
  2435 displayDeviceRectangleX:x y:y width:w height:h
  2104 displayDeviceRectangleX:x y:y width:w height:h
  2436     "draw a rectangle in device coordinates"
  2105     "draw a rectangle in device coordinates"
  2437 
  2106 
  2438     gc == self ifTrue:[
       
  2439 	super displayDeviceRectangleX:x y:y width:w height:h.
       
  2440 	^ self.
       
  2441     ].
       
  2442     gc displayDeviceRectangleX:x y:y width:w height:h
  2107     gc displayDeviceRectangleX:x y:y width:w height:h
  2443 !
  2108 !
  2444 
  2109 
  2445 displayDeviceString:aString from:index1 to:index2 in:font x:x y:y
  2110 displayDeviceString:aString from:index1 to:index2 in:font x:x y:y
  2446     "draw a substring at the coordinate x/y -
  2111     "draw a substring at the coordinate x/y -
  2447      draw foreground-pixels only (in current paint-color), leaving background as-is.
  2112      draw foreground-pixels only (in current paint-color), leaving background as-is.
  2448      No translation or scaling is done"
  2113      No translation or scaling is done"
  2449 
  2114 
  2450     gc == self ifTrue:[
       
  2451         super displayDeviceString:aString from:index1 to:index2 in:font x:x y:y.
       
  2452         ^ self.
       
  2453     ].
       
  2454     gc displayDeviceString:aString from:index1 to:index2 in:font x:x y:y
  2115     gc displayDeviceString:aString from:index1 to:index2 in:font x:x y:y
  2455 !
  2116 !
  2456 
  2117 
  2457 displayDeviceString:aString from:index1 to:index2 x:x y:y
  2118 displayDeviceString:aString from:index1 to:index2 x:x y:y
  2458     "draw a substring at the coordinate x/y -
  2119     "draw a substring at the coordinate x/y -
  2471 !
  2132 !
  2472 
  2133 
  2473 fillDeviceRectangleX:x y:y width:w height:h
  2134 fillDeviceRectangleX:x y:y width:w height:h
  2474     "fill a rectangle with current paint color (device coordinates)"
  2135     "fill a rectangle with current paint color (device coordinates)"
  2475 
  2136 
  2476     gc == self ifTrue:[
       
  2477 	super fillDeviceRectangleX:x y:y width:w height:h.
       
  2478 	^ self.
       
  2479     ].
       
  2480     gc fillDeviceRectangleX:x y:y width:w height:h
  2137     gc fillDeviceRectangleX:x y:y width:w height:h
  2481 ! !
  2138 ! !
  2482 
  2139 
  2483 !GraphicsMedium methodsFor:'edge drawing'!
  2140 !GraphicsMedium methodsFor:'edge drawing'!
  2484 
  2141 
  2485 drawEdgesForX:x y:y width:w height:h level:l
  2142 drawEdgesForX:x y:y width:w height:h level:l
  2486     "draw 3D edges into a rectangle"
  2143     "draw 3D edges into a rectangle"
  2487     self
  2144     self
  2488         drawEdgesForX:x y:y width:w height:h level:l
  2145 	drawEdgesForX:x y:y width:w height:h level:l
  2489         shadow:self blackColor light:self whiteColor
  2146 	shadow:self blackColor light:self whiteColor
  2490         halfShadow:nil halfLight:nil
  2147 	halfShadow:nil halfLight:nil
  2491         style:nil
  2148 	style:nil
  2492 !
  2149 !
  2493 
  2150 
  2494 drawEdgesForX:x y:y width:w height:h level:l
  2151 drawEdgesForX:x y:y width:w height:h level:l
  2495                 shadow:shadowColor light:lightColor
  2152 		shadow:shadowColor light:lightColor
  2496                 halfShadow:halfShadowColor halfLight:halfLightColor
  2153 		halfShadow:halfShadowColor halfLight:halfLightColor
  2497                 style:edgeStyle
  2154 		style:edgeStyle
  2498 
  2155 
  2499     "draw 3D edges into a rectangle"
  2156     "draw 3D edges into a rectangle"
  2500 
  2157 
  2501     |topLeftFg botRightFg topLeftHalfFg botRightHalfFg
  2158     |topLeftFg botRightFg topLeftHalfFg botRightHalfFg
  2502      count "{ Class: SmallInteger }"
  2159      count "{ Class: SmallInteger }"
  2506      yi    "{ Class: SmallInteger }"
  2163      yi    "{ Class: SmallInteger }"
  2507      run paint|
  2164      run paint|
  2508 
  2165 
  2509     count := l.
  2166     count := l.
  2510     (count < 0) ifTrue:[
  2167     (count < 0) ifTrue:[
  2511         topLeftFg := shadowColor.
  2168 	topLeftFg := shadowColor.
  2512         botRightFg := lightColor.
  2169 	botRightFg := lightColor.
  2513         topLeftHalfFg := halfShadowColor.
  2170 	topLeftHalfFg := halfShadowColor.
  2514         botRightHalfFg := halfLightColor.
  2171 	botRightHalfFg := halfLightColor.
  2515         count := count negated
  2172 	count := count negated
  2516     ] ifFalse:[
  2173     ] ifFalse:[
  2517         topLeftFg := lightColor.
  2174 	topLeftFg := lightColor.
  2518         botRightFg := shadowColor.
  2175 	botRightFg := shadowColor.
  2519         topLeftHalfFg := halfLightColor.
  2176 	topLeftHalfFg := halfLightColor.
  2520         botRightHalfFg := halfShadowColor.
  2177 	botRightHalfFg := halfShadowColor.
  2521     ].
  2178     ].
  2522     topLeftHalfFg isNil ifTrue:[
  2179     topLeftHalfFg isNil ifTrue:[
  2523         topLeftHalfFg := topLeftFg
  2180 	topLeftHalfFg := topLeftFg
  2524     ].
  2181     ].
  2525     botRightHalfFg isNil ifTrue:[
  2182     botRightHalfFg isNil ifTrue:[
  2526         botRightHalfFg := botRightFg
  2183 	botRightHalfFg := botRightFg
  2527     ].
  2184     ].
  2528 
  2185 
  2529     r := x + w - 1. "right"
  2186     r := x + w - 1. "right"
  2530     b := y + h - 1. "bottom"
  2187     b := y + h - 1. "bottom"
  2531 
  2188 
  2532     self lineWidth:0.
  2189     self lineWidth:0.
  2533 
  2190 
  2534     "top and left edges"
  2191     "top and left edges"
  2535     ((edgeStyle == #soft or:[edgeStyle == #softWin95]) and:["l" count > 0]) ifTrue:[
  2192     ((edgeStyle == #soft or:[edgeStyle == #softWin95]) and:["l" count > 0]) ifTrue:[
  2536         paint := topLeftHalfFg
  2193 	paint := topLeftHalfFg
  2537     ] ifFalse:[
  2194     ] ifFalse:[
  2538         paint := topLeftFg
  2195 	paint := topLeftFg
  2539     ].
  2196     ].
  2540     self paint:paint.
  2197     self paint:paint.
  2541 
  2198 
  2542     0 to:(count - 1) do:[:i |
  2199     0 to:(count - 1) do:[:i |
  2543         run := y + i.
  2200 	run := y + i.
  2544         run < b ifTrue:[
  2201 	run < b ifTrue:[
  2545             self displayDeviceLineFromX:x y:run toX:r y:run. "top"
  2202 	    self displayDeviceLineFromX:x y:run toX:r y:run. "top"
  2546         ].
  2203 	].
  2547         run := x + i.
  2204 	run := x + i.
  2548         self displayDeviceLineFromX:run y:y toX:run y:b  "left"
  2205 	self displayDeviceLineFromX:run y:y toX:run y:b  "left"
  2549     ].
  2206     ].
  2550     (edgeStyle == #soft or:[edgeStyle == #softWin95]) ifTrue:[
  2207     (edgeStyle == #soft or:[edgeStyle == #softWin95]) ifTrue:[
  2551 "
  2208 "
  2552         self paint:topLeftFg.
  2209 	self paint:topLeftFg.
  2553         self displayDeviceLineFromX:x y:y toX:r y:y.
  2210 	self displayDeviceLineFromX:x y:y toX:r y:y.
  2554         self displayDeviceLineFromX:x y:y toX:x y:b
  2211 	self displayDeviceLineFromX:x y:y toX:x y:b
  2555 "
  2212 "
  2556         (l > 1) ifTrue:[
  2213 	(l > 1) ifTrue:[
  2557             edgeStyle == #softWin95 ifTrue:[
  2214 	    edgeStyle == #softWin95 ifTrue:[
  2558                 self paint:(Color veryLightGrey).
  2215 		self paint:(Color veryLightGrey).
  2559             ] ifFalse:[
  2216 	    ] ifFalse:[
  2560                 (l > 2 and:[edgeStyle == #soft]) ifTrue:[
  2217 		(l > 2 and:[edgeStyle == #soft]) ifTrue:[
  2561                     self paint:(self device blackColor).
  2218 		    self paint:(self device blackColor).
  2562                 ] ifFalse:[
  2219 		] ifFalse:[
  2563                     self paint:halfLightColor.
  2220 		    self paint:halfLightColor.
  2564                 ]
  2221 		]
  2565             ].
  2222 	    ].
  2566             self displayDeviceLineFromX:x y:y toX:r y:y.
  2223 	    self displayDeviceLineFromX:x y:y toX:r y:y.
  2567             self displayDeviceLineFromX:x y:y toX:x y:b.
  2224 	    self displayDeviceLineFromX:x y:y toX:x y:b.
  2568         ]
  2225 	]
  2569     ].
  2226     ].
  2570 
  2227 
  2571     xi := x + 1.
  2228     xi := x + 1.
  2572     yi := y + 1.
  2229     yi := y + 1.
  2573 
  2230 
  2577 "/ ].
  2234 "/ ].
  2578 
  2235 
  2579     "bottom and right edges"
  2236     "bottom and right edges"
  2580     ((edgeStyle == #soft or:[edgeStyle == #softWin95])
  2237     ((edgeStyle == #soft or:[edgeStyle == #softWin95])
  2581     "new:" and:[count > 1]) ifTrue:[
  2238     "new:" and:[count > 1]) ifTrue:[
  2582         paint := botRightHalfFg
  2239 	paint := botRightHalfFg
  2583     ] ifFalse:[
  2240     ] ifFalse:[
  2584         paint := botRightFg
  2241 	paint := botRightFg
  2585     ].
  2242     ].
  2586 
  2243 
  2587     self paint:paint.
  2244     self paint:paint.
  2588     0 to:(count - 1) do:[:i |
  2245     0 to:(count - 1) do:[:i |
  2589         run := b - i.
  2246 	run := b - i.
  2590         run > y ifTrue:[
  2247 	run > y ifTrue:[
  2591             self displayDeviceLineFromX:xi-1 y:run toX:r y:run. "bottom"
  2248 	    self displayDeviceLineFromX:xi-1 y:run toX:r y:run. "bottom"
  2592         ].
  2249 	].
  2593         run := r - i.
  2250 	run := r - i.
  2594         self displayDeviceLineFromX:run y:yi-1 toX:run y:b.  "right"
  2251 	self displayDeviceLineFromX:run y:yi-1 toX:run y:b.  "right"
  2595         xi := xi + 1.
  2252 	xi := xi + 1.
  2596         yi := yi + 1
  2253 	yi := yi + 1
  2597     ].
  2254     ].
  2598     ((edgeStyle == #soft or:[edgeStyle == #softWin95])
  2255     ((edgeStyle == #soft or:[edgeStyle == #softWin95])
  2599     and:[l > 1]) ifTrue:[
  2256     and:[l > 1]) ifTrue:[
  2600         self paint:(self device blackColor) "shadowColor".
  2257 	self paint:(self device blackColor) "shadowColor".
  2601         self displayDeviceLineFromX:x y:b toX:r y:b.
  2258 	self displayDeviceLineFromX:x y:b toX:r y:b.
  2602         self displayDeviceLineFromX:r y:y toX:r y:b
  2259 	self displayDeviceLineFromX:r y:y toX:r y:b
  2603     ].
  2260     ].
  2604 
  2261 
  2605     self edgeDrawn:#all
  2262     self edgeDrawn:#all
  2606 
  2263 
  2607     "Modified: / 24.8.1998 / 18:23:02 / cg"
  2264     "Modified: / 24.8.1998 / 18:23:02 / cg"
  2619 
  2276 
  2620 reverseDo:aBlock
  2277 reverseDo:aBlock
  2621     "evaluate aBlock with foreground and background interchanged.
  2278     "evaluate aBlock with foreground and background interchanged.
  2622      This can be reimplemented here in a faster way."
  2279      This can be reimplemented here in a faster way."
  2623 
  2280 
  2624     gc == self ifTrue:[
       
  2625 	super reverseDo:aBlock.
       
  2626 	^ self.
       
  2627     ].
       
  2628     gc reverseDo:aBlock
  2281     gc reverseDo:aBlock
  2629 !
  2282 !
  2630 
  2283 
  2631 withBackground:fgColor do:aBlock
  2284 withBackground:fgColor do:aBlock
  2632     "evaluate aBlock with changed background."
  2285     "evaluate aBlock with changed background."
  2633 
  2286 
  2634     gc == self ifTrue:[
       
  2635 	super withBackground:fgColor do:aBlock.
       
  2636 	^ self.
       
  2637     ].
       
  2638     gc withBackground:fgColor do:aBlock
  2287     gc withBackground:fgColor do:aBlock
  2639 !
  2288 !
  2640 
  2289 
  2641 withForeground:fgColor background:bgColor do:aBlock
  2290 withForeground:fgColor background:bgColor do:aBlock
  2642     "evaluate aBlock with changed foreground and background."
  2291     "evaluate aBlock with changed foreground and background."
  2643 
  2292 
  2644     gc == self ifTrue:[
       
  2645 	super withForeground:fgColor background:bgColor do:aBlock.
       
  2646 	^ self.
       
  2647     ].
       
  2648     gc withForeground:fgColor background:bgColor do:aBlock
  2293     gc withForeground:fgColor background:bgColor do:aBlock
  2649 !
  2294 !
  2650 
  2295 
  2651 withForeground:fgColor background:bgColor function:aFunction do:aBlock
  2296 withForeground:fgColor background:bgColor function:aFunction do:aBlock
  2652     "evaluate aBlock with foreground, background and function"
  2297     "evaluate aBlock with foreground, background and function"
  2653 
  2298 
  2654     gc == self ifTrue:[
       
  2655 	super withForeground:fgColor background:bgColor function:aFunction do:aBlock.
       
  2656 	^ self.
       
  2657     ].
       
  2658     gc withForeground:fgColor background:bgColor function:aFunction do:aBlock
  2299     gc withForeground:fgColor background:bgColor function:aFunction do:aBlock
  2659 !
  2300 !
  2660 
  2301 
  2661 withForeground:fgColor background:bgColor mask:aMask do:aBlock
  2302 withForeground:fgColor background:bgColor mask:aMask do:aBlock
  2662     "evaluate aBlock with foreground, background and mask"
  2303     "evaluate aBlock with foreground, background and mask"
  2663 
  2304 
  2664     gc == self ifTrue:[
       
  2665 	super withForeground:fgColor background:bgColor mask:aMask do:aBlock.
       
  2666 	^ self.
       
  2667     ].
       
  2668     gc withForeground:fgColor background:bgColor mask:aMask do:aBlock
  2305     gc withForeground:fgColor background:bgColor mask:aMask do:aBlock
  2669 !
  2306 !
  2670 
  2307 
  2671 withForeground:fgColor do:aBlock
  2308 withForeground:fgColor do:aBlock
  2672     "evaluate aBlock with changed foreground."
  2309     "evaluate aBlock with changed foreground."
  2673 
  2310 
  2674     gc == self ifTrue:[
       
  2675 	super withForeground:fgColor do:aBlock.
       
  2676 	^ self.
       
  2677     ].
       
  2678     gc withForeground:fgColor do:aBlock
  2311     gc withForeground:fgColor do:aBlock
  2679 !
  2312 !
  2680 
  2313 
  2681 withForeground:fgColor function:aFunction do:aBlock
  2314 withForeground:fgColor function:aFunction do:aBlock
  2682     "evaluate aBlock with changed foreground and function."
  2315     "evaluate aBlock with changed foreground and function."
  2683 
  2316 
  2684     gc == self ifTrue:[
       
  2685 	super withForeground:fgColor function:aFunction do:aBlock.
       
  2686 	^ self.
       
  2687     ].
       
  2688     gc withForeground:fgColor function:aFunction do:aBlock
  2317     gc withForeground:fgColor function:aFunction do:aBlock
  2689 !
  2318 !
  2690 
  2319 
  2691 xoring:aBlock
  2320 xoring:aBlock
  2692     "evaluate aBlock with function xoring"
  2321     "evaluate aBlock with function xoring"
  2693 
  2322 
  2694     gc == self ifTrue:[
       
  2695 	super xoring:aBlock.
       
  2696 	^ self.
       
  2697     ].
       
  2698     gc xoring:aBlock
  2323     gc xoring:aBlock
  2699 ! !
  2324 ! !
  2700 
  2325 
       
  2326 !GraphicsMedium methodsFor:'event handling'!
       
  2327 
       
  2328 catchExpose
       
  2329     "expose event handling is only required for views."
       
  2330 
       
  2331     ^ false.
       
  2332 !
       
  2333 
       
  2334 waitForExpose
       
  2335     "expose event handling is only required for views."
       
  2336 
       
  2337     ^ self.
       
  2338 ! !
       
  2339 
  2701 !GraphicsMedium methodsFor:'filling'!
  2340 !GraphicsMedium methodsFor:'filling'!
  2702 
  2341 
  2703 black
  2342 black
  2704     "fill the receiver with black"
  2343     "fill the receiver with black"
  2705 
  2344 
  2711 
  2350 
  2712     self clearView.
  2351     self clearView.
  2713 !
  2352 !
  2714 
  2353 
  2715 clearDeviceRectangleX:x y:y width:w height:h
  2354 clearDeviceRectangleX:x y:y width:w height:h
  2716     "clear a rectangular area to viewBackground -
  2355     "clear a rectangular area to background"
  2717      redefined since GraphicsMedium fills with background
  2356 
  2718      - not viewBackground as we want here."
       
  2719 
       
  2720     gc == self ifTrue:[
       
  2721 	super clearDeviceRectangleX:x y:y width:w height:h.
       
  2722 	^ self.
       
  2723     ].
       
  2724     gc clearDeviceRectangleX:x y:y width:w height:h.
  2357     gc clearDeviceRectangleX:x y:y width:w height:h.
  2725 !
  2358 !
  2726 
  2359 
  2727 clearInside
  2360 clearInside
  2728     "clear the receiver with background - ST-80 compatibility"
  2361     "clear the receiver with background - ST-80 compatibility"
  2737 		       y:(aRectangle top)
  2370 		       y:(aRectangle top)
  2738 		   width:(aRectangle width)
  2371 		   width:(aRectangle width)
  2739 		  height:(aRectangle height)
  2372 		  height:(aRectangle height)
  2740 !
  2373 !
  2741 
  2374 
  2742 clearRectangleX:left y:top width:w height:h
  2375 clearRectangleX:x y:y width:w height:h
  2743     "clear the rectangular area in the receiver to background"
  2376     gc clearRectangleX:x y:y width:w height:h.
  2744 
       
  2745     |oldPaint|
       
  2746 
       
  2747     oldPaint := gc paint.
       
  2748     gc paint:gc backgroundPaint.
       
  2749     gc fillRectangleX:left y:top width:w height:h.
       
  2750     gc paint:oldPaint
       
  2751 
       
  2752     "Modified: 28.5.1996 / 20:14:11 / cg"
       
  2753 !
  2377 !
  2754 
  2378 
  2755 clearView
  2379 clearView
  2756     "clear the receiver with background"
  2380     "clear the receiver with background"
  2757 
  2381 
  2758     "currently need this kludge for form ..."
  2382 "/    "currently need this kludge for form ..."
  2759     gc transformation isNil ifTrue:[
  2383 "/    gc transformation isNil ifTrue:[
  2760 	self clearRectangleX:0 y:0 width:width height:height
  2384 "/        self clearRectangleX:0 y:0 width:width height:height
  2761     ] ifFalse:[
  2385 "/    ] ifFalse:[
  2762 	self clearDeviceRectangleX:0 y:0 width:width height:height
  2386         self clearDeviceRectangleX:0 y:0 width:width height:height
  2763     ]
  2387 "/    ]
  2764 !
  2388 !
  2765 
  2389 
  2766 fill:something
  2390 fill:something
  2767     "fill the receiver with something;
  2391     "fill the receiver with something;
  2768      something may be a Form, Color or colorIndex"
  2392      something may be a Form, Color or colorIndex"
  2769 
  2393 
  2770     |oldPaint|
  2394     gc fillRectangle:self boundingBox color:something
  2771 
       
  2772     oldPaint := self paint.
       
  2773     self paint:something.
       
  2774     self fillRectangleX:0 y:0 width:width height:height.
       
  2775     self paint:oldPaint
       
  2776 
       
  2777     "Modified: 28.5.1996 / 20:13:29 / cg"
       
  2778 !
  2395 !
  2779 
  2396 
  2780 fillArc:origin radius:r from:startAngle angle:angle
  2397 fillArc:origin radius:r from:startAngle angle:angle
  2781     "draw a filled arc around a point"
  2398     "draw a filled arc around a point"
  2782 
  2399 
  2926      Notice: the cornerPoint itself is NOT included"
  2543      Notice: the cornerPoint itself is NOT included"
  2927 
  2544 
  2928     self fillRectangleX:(origin x) y:(origin y) width:(extent x) height:(extent y)
  2545     self fillRectangleX:(origin x) y:(origin y) width:(extent x) height:(extent y)
  2929 !
  2546 !
  2930 
  2547 
  2931 fillRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
  2548 fillRoundRectangleX:left y:top width:width height:height wCorner:wCorn hCorner:hCorn
  2932     gc fillRoundRectangleX:x y:y width:w height:h wCorner:wCorn hCorner:hCorn
  2549     |right bottom wC hC wHalf hHalf|
  2933 
  2550 
  2934     "Modified: / 07-01-2015 / 20:18:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2551     right := left + width.
       
  2552     bottom := top + height.
       
  2553 
       
  2554     wC := wCorn.
       
  2555     hC := hCorn.
       
  2556 
       
  2557     wHalf := wC / 2.
       
  2558     hHalf := hC / 2.
       
  2559 
       
  2560     self device isWindowsPlatform ifTrue:[
       
  2561 	"/ bug workaround
       
  2562 	"top left arc"
       
  2563 	self fillArcX:left y:top width:wC height:hC from:90 angle:90.
       
  2564 	"top right arc"
       
  2565 	self fillArcX:(right - wC - 1) y:top width:wC height:hC from:0 angle:90.
       
  2566 	"bottom right arc"
       
  2567 	self fillArcX:(right - wC - 1) y:(bottom - hC - 1) width:wC height:hC from:270 angle:90.
       
  2568 	"bottom left arc"
       
  2569 	self fillArcX:left y:(bottom - hC) width:wC height:hC-1 from:180 angle:90.
       
  2570 
       
  2571 	"center rectangle"
       
  2572 	self fillRectangleX:(left + wHalf) y:top width:(width - wHalf - wHalf+1) height:height-1.
       
  2573 	"left partial rectangle"
       
  2574 	self fillRectangleX:left y:top+hHalf width:wHalf height:(height-hHalf-hHalf).
       
  2575 	"right partial rectangle"
       
  2576 	self fillRectangleX:right-wHalf y:top+hHalf width:wHalf-1 height:(height-hHalf-hHalf).
       
  2577     ] ifFalse:[
       
  2578 	"top left arc"
       
  2579 	self fillArcX:left y:top width:wC height:hC from:90 angle:90.
       
  2580 	"top right arc"
       
  2581 	self fillArcX:(right - wC) y:top width:wC height:hC from:0 angle:90.
       
  2582 	"bottom right arc"
       
  2583 	self fillArcX:(right - wC - 1) y:(bottom - hC) width:wC height:hC from:270 angle:90.
       
  2584 	"bottom left arc"
       
  2585 	self fillArcX:left y:(bottom - hC) width:wC height:hC from:180 angle:90.
       
  2586 
       
  2587 	"center rectangle"
       
  2588 	self fillRectangleX:(left + wHalf) y:top width:(width - wHalf - wHalf+1) height:height.
       
  2589 	"left partial rectangle"
       
  2590 	self fillRectangleX:left y:top+hHalf width:wHalf height:(height-hHalf-hHalf).
       
  2591 	"right partial rectangle"
       
  2592 	self fillRectangleX:right-wHalf y:top+hHalf width:wHalf height:(height-hHalf-hHalf).
       
  2593     ].
       
  2594 
       
  2595 
       
  2596     "
       
  2597      |v|
       
  2598 
       
  2599      (v := View new) extent:200@200; openAndWait.
       
  2600      v fillRoundRectangleX:10 y:10 width:100 height:100 wCorner:20 hCorner:20
       
  2601     "
  2935 !
  2602 !
  2936 
  2603 
  2937 invertRectangle:aRectangle
  2604 invertRectangle:aRectangle
  2938     "invert a rectangle in the receiver"
  2605     "invert a rectangle in the receiver"
  2939 
  2606 
  2943 !
  2610 !
  2944 
  2611 
  2945 white
  2612 white
  2946     "fill the receiver with white"
  2613     "fill the receiver with white"
  2947 
  2614 
  2948     self fill:Color white
  2615     self fill:self whiteColor
  2949 ! !
  2616 ! !
  2950 
  2617 
  2951 !GraphicsMedium methodsFor:'initialization & release'!
  2618 !GraphicsMedium methodsFor:'initialization & release'!
  2952 
  2619 
  2953 close
  2620 close
  2957 
  2624 
  2958     "Created: 2.4.1997 / 19:31:27 / cg"
  2625     "Created: 2.4.1997 / 19:31:27 / cg"
  2959 !
  2626 !
  2960 
  2627 
  2961 destroy
  2628 destroy
  2962     "destroy a medium - here the fc is completely destroyed"
  2629     "destroy a medium - here the gc is completely destroyed"
  2963 
  2630 
  2964     gc notNil ifTrue:[
  2631     gc notNil ifTrue:[
  2965         gc destroy.
  2632         gc destroy.
  2966     ].
  2633     ].
       
  2634     device := nil.
  2967     realized := false.
  2635     realized := false.
  2968 !
  2636 !
  2969 
  2637 
  2970 initGC
  2638 initGC
  2971     "since we do not need a gc-object for the drawable until something is
  2639     "since we do not need a gc-object for the drawable until something is
  2972      really drawn, none is created.
  2640      really drawn, none is created.
  2973      This method is sent, when the first drawing happens"
  2641      This method is sent, when the first drawing happens"
  2974 
  2642 
  2975     gc == self ifTrue:[
       
  2976 	super initGC.
       
  2977 	^ self.
       
  2978     ].
       
  2979     gc initGC
  2643     gc initGC
  2980 !
  2644 !
  2981 
  2645 
  2982 initialize
  2646 initialize
  2983     super initialize.
  2647     super initialize.
  2989 
  2653 
  2990 initializeForDevice:aDevice
  2654 initializeForDevice:aDevice
  2991     "allocate a GraphicsContext for a device"
  2655     "allocate a GraphicsContext for a device"
  2992 
  2656 
  2993     aDevice notNil ifTrue:[
  2657     aDevice notNil ifTrue:[
       
  2658         device := aDevice.
  2994         gc := aDevice newGraphicsContextFor:self.
  2659         gc := aDevice newGraphicsContextFor:self.
  2995         device := aDevice.
  2660         gc font:self class defaultFont.
  2996     ].
  2661     ].
  2997 
  2662 
  2998     self initialize.
  2663     self initialize.
  2999 
       
  3000     "Modified: / 03-04-2016 / 16:03:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
  3001 !
  2664 !
  3002 
  2665 
  3003 recreate
  2666 recreate
  3004     "reacreate a medium after snapIn"
  2667     "reacreate a medium after snapIn"
  3005 
  2668 
  3006     gc notNil ifTrue:[
  2669     gc notNil ifTrue:[
  3007         gc recreate.
  2670 	gc recreate.
  3008     ].
  2671     ].
  3009 !
  2672 !
  3010 
  2673 
  3011 releaseGC
  2674 releaseGC
  3012     "destroy the associated device GC resource - can be done to be nice to the
  2675     "destroy the associated device GC resource - can be done to be nice to the
  3013      display if you know that you are done with a drawable."
  2676      display if you know that you are done with a drawable."
  3014 
  2677 
  3015     gc == self ifTrue:[
       
  3016         super releaseGC.
       
  3017         ^ self.
       
  3018     ].
       
  3019     gc notNil ifTrue:[
  2678     gc notNil ifTrue:[
  3020         gc releaseGC.
  2679         gc releaseGC.
  3021     ].
  2680     ].
  3022 ! !
  2681 ! !
  3023 
  2682 
  3028 
  2687 
  3029     oldClip := gc deviceClippingBoundsOrNil.
  2688     oldClip := gc deviceClippingBoundsOrNil.
  3030     gc clippingBounds:aRectangle.
  2689     gc clippingBounds:aRectangle.
  3031 
  2690 
  3032     aBlock
  2691     aBlock
  3033         ensure:[
  2692 	ensure:[
  3034             gc deviceClippingBounds:oldClip
  2693 	    gc deviceClippingBounds:oldClip
  3035         ]
  2694 	]
  3036 !
  2695 !
  3037 
  2696 
  3038 flush
  2697 flush
  3039     "send all buffered drawing to the device."
  2698     "send all buffered drawing to the device."
  3040 
  2699 
  3041     gc == self ifTrue:[
       
  3042 	super flush.
       
  3043 	^ self.
       
  3044     ].
       
  3045     gc flush
  2700     gc flush
  3046 !
  2701 !
  3047 
  2702 
  3048 setDevice:aDevice id:aDrawbleId gcId:aGCId
  2703 setDevice:aDevice id:aDrawbleId gcId:aGCId
  3049     "private"
  2704     "private"
  3050 
  2705 
  3051     gc == self ifTrue:[
  2706     device := aDevice.
  3052         super setDevice:aDevice id:aDrawbleId gcId:aGCId.
       
  3053         ^ self.
       
  3054     ].
       
  3055     gc notNil ifTrue:[
  2707     gc notNil ifTrue:[
  3056         gc setDevice:aDevice id:aDrawbleId gcId:aGCId
  2708         gc setDevice:aDevice id:aDrawbleId gcId:aGCId
  3057     ].
  2709     ].
  3058     device := aDevice
       
  3059     
       
  3060 !
       
  3061 
       
  3062 setId:aDrawableId
       
  3063     "private"
       
  3064 
       
  3065     gc == self ifTrue:[
       
  3066         super setId:aDrawableId.
       
  3067         ^ self.
       
  3068     ].
       
  3069     gc setId:aDrawableId
       
  3070 !
  2710 !
  3071 
  2711 
  3072 setPaint:fgColor on:bgColor
  2712 setPaint:fgColor on:bgColor
  3073     "set the paint and background-paint color.
  2713     "set the paint and background-paint color.
  3074      The bg-paint is used in opaque-draw operations.
  2714      The bg-paint is used in opaque-draw operations.
  3075      Only set the variables, but do not send it to the device,
  2715      Only set the variables, but do not send it to the device,
  3076      Used on initialization."
  2716      Used on initialization."
  3077 
  2717 
  3078     gc == self ifTrue:[
       
  3079         super setPaint:fgColor on:bgColor.
       
  3080         ^ self.
       
  3081     ].
       
  3082     gc setPaint:fgColor on:bgColor
  2718     gc setPaint:fgColor on:bgColor
  3083 !
  2719 !
  3084 
  2720 
  3085 sync
  2721 sync
  3086     "send all buffered drawing to the device and wait until the device responds"
  2722     "send all buffered drawing to the device and wait until the device responds"
  3087 
  2723 
  3088     gc == self ifTrue:[
       
  3089         super sync.
       
  3090         ^ self.
       
  3091     ].
       
  3092     gc sync
  2724     gc sync
  3093 ! !
  2725 ! !
  3094 
  2726 
  3095 !GraphicsMedium methodsFor:'printing & storing'!
  2727 !GraphicsMedium methodsFor:'printing & storing'!
  3096 
  2728 
  3105 !GraphicsMedium methodsFor:'queries'!
  2737 !GraphicsMedium methodsFor:'queries'!
  3106 
  2738 
  3107 fontAscent
  2739 fontAscent
  3108     "answer the ascent of the current font on the current device"
  2740     "answer the ascent of the current font on the current device"
  3109 
  2741 
  3110     gc == self ifTrue:[
       
  3111 	^ super fontAscent.
       
  3112     ].
       
  3113     ^ gc fontAscent
  2742     ^ gc fontAscent
  3114 !
  2743 !
  3115 
  2744 
  3116 horizontalIntegerPixelPerMillimeter
  2745 horizontalIntegerPixelPerMillimeter
  3117     "return the (rounded) number of pixels per millimeter"
  2746     "return the (rounded) number of pixels per millimeter"
  3126 !
  2755 !
  3127 
  2756 
  3128 horizontalPixelPerMillimeter
  2757 horizontalPixelPerMillimeter
  3129     "return the number of pixels per millimeter (not rounded)"
  2758     "return the number of pixels per millimeter (not rounded)"
  3130 
  2759 
  3131     gc == self ifTrue:[
       
  3132 	^ super horizontalPixelPerMillimeter.
       
  3133     ].
       
  3134     ^ gc horizontalPixelPerMillimeter
  2760     ^ gc horizontalPixelPerMillimeter
  3135 !
  2761 !
  3136 
  2762 
  3137 horizontalPixelPerMillimeter:millis
  2763 horizontalPixelPerMillimeter:millis
  3138     "return the number of pixels (not rounded) for millis millimeter"
  2764     "return the number of pixels (not rounded) for millis millimeter"
  3141 !
  2767 !
  3142 
  2768 
  3143 resolution
  2769 resolution
  3144     "return a point consisting of pixel-per-inch horizontally and vertically."
  2770     "return a point consisting of pixel-per-inch horizontally and vertically."
  3145 
  2771 
  3146     gc == self ifTrue:[
       
  3147 	^ super resolution.
       
  3148     ].
       
  3149     ^ gc resolution
  2772     ^ gc resolution
  3150 !
  2773 !
  3151 
  2774 
  3152 verticalIntegerPixelPerMillimeter
  2775 verticalIntegerPixelPerMillimeter
  3153     "return the (rounded) number of pixels per millimeter"
  2776     "return the (rounded) number of pixels per millimeter"
  3162 !
  2785 !
  3163 
  2786 
  3164 verticalPixelPerMillimeter
  2787 verticalPixelPerMillimeter
  3165     "return the number of pixels per millimeter (not rounded)"
  2788     "return the number of pixels per millimeter (not rounded)"
  3166 
  2789 
  3167     gc == self ifTrue:[
       
  3168 	^ super verticalPixelPerMillimeter.
       
  3169     ].
       
  3170     ^ gc verticalPixelPerMillimeter
  2790     ^ gc verticalPixelPerMillimeter
  3171 !
  2791 !
  3172 
  2792 
  3173 verticalPixelPerMillimeter:millis
  2793 verticalPixelPerMillimeter:millis
  3174     "return the number of pixels (not rounded) for millis millimeter"
  2794     "return the number of pixels (not rounded) for millis millimeter"
  3179 !GraphicsMedium methodsFor:'view creation'!
  2799 !GraphicsMedium methodsFor:'view creation'!
  3180 
  2800 
  3181 createBitmapFromArray:data width:width height:height
  2801 createBitmapFromArray:data width:width height:height
  3182     "create a bitmap from data and set the drawableId"
  2802     "create a bitmap from data and set the drawableId"
  3183 
  2803 
  3184     gc == self ifTrue:[
       
  3185         super createBitmapFromArray:data width:width height:height.
       
  3186         ^ self.
       
  3187     ].
       
  3188     gc createBitmapFromArray:data width:width height:height
  2804     gc createBitmapFromArray:data width:width height:height
  3189 !
  2805 !
  3190 
  2806 
  3191 createPixmapWidth:w height:h depth:d
  2807 createPixmapWidth:w height:h depth:d
  3192     "create a pixmap and set the drawableId"
  2808     "create a pixmap and set the drawableId"
  3193 
  2809 
  3194     gc == self ifTrue:[
       
  3195         super createPixmapWidth:w height:h depth:d.
       
  3196         ^ self.
       
  3197     ].
       
  3198     gc createPixmapWidth:w height:h depth:d
  2810     gc createPixmapWidth:w height:h depth:d
  3199 !
  2811 !
  3200 
  2812 
  3201 createRootWindow
  2813 createRootWindow
  3202     gc == self ifTrue:[
       
  3203         super createRootWindowFor:self.
       
  3204         ^ self.
       
  3205     ].
       
  3206     gc createRootWindowFor:self
  2814     gc createRootWindowFor:self
  3207 !
  2815 !
  3208 
  2816 
  3209 createWindowFor:aView type:typeSymbol origin:org extent:ext minExtent:minE maxExtent:maxE borderWidth:bw subViewOf:sv style:styleSymbol inputOnly:inp label:label owner:owner icon:icn iconMask:icnM iconView:icnV
  2817 createWindowFor:aView type:typeSymbol origin:org extent:ext minExtent:minE maxExtent:maxE borderWidth:bw subViewOf:sv style:styleSymbol inputOnly:inp label:label owner:owner icon:icn iconMask:icnM iconView:icnV
  3210     "create a window and set the drawableId"
  2818     "create a window and set the drawableId"
  3211 
  2819 
  3212     gc == self ifTrue:[
       
  3213         super createWindowFor:aView type:typeSymbol origin:org extent:ext minExtent:minE maxExtent:maxE borderWidth:bw subViewOf:sv style:styleSymbol inputOnly:inp label:label owner:owner icon:icn iconMask:icnM iconView:icnV.
       
  3214         ^ self.
       
  3215     ].
       
  3216     gc createWindowFor:aView type:typeSymbol origin:org extent:ext minExtent:minE maxExtent:maxE borderWidth:bw subViewOf:sv style:styleSymbol inputOnly:inp label:label owner:owner icon:icn iconMask:icnM iconView:icnV
  2820     gc createWindowFor:aView type:typeSymbol origin:org extent:ext minExtent:minE maxExtent:maxE borderWidth:bw subViewOf:sv style:styleSymbol inputOnly:inp label:label owner:owner icon:icn iconMask:icnM iconView:icnV
  3217 ! !
  2821 ! !
  3218 
  2822 
  3219 !GraphicsMedium class methodsFor:'documentation'!
  2823 !GraphicsMedium class methodsFor:'documentation'!
  3220 
  2824 
  3221 version_CVS
  2825 version_CVS
  3222     ^ '$Header: /cvs/stx/stx/libview/GraphicsMedium.st,v 1.22.2.4 2014-09-26 09:48:32 stefan Exp $'
  2826     ^ '$Header$'
  3223 !
       
  3224 
       
  3225 version_HG
       
  3226 
       
  3227     ^ '$Changeset: <not expanded> $'
       
  3228 ! !
  2827 ! !
  3229 
  2828