[Pkg] The Trunk: Graphics-nice.267.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Oct 11 23:13:50 UTC 2013


Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.267.mcz

==================== Summary ====================

Name: Graphics-nice.267
Author: nice
Time: 12 October 2013, 1:12:49.473 am
UUID: 476960ef-de6b-4ca0-812b-eb3d36614b42
Ancestors: Graphics-nice.266

Make DisplayScanner abstract - part 2:
Remove BitBlt stuff from DisplayScanner and prepare some displaying subclassResponsibility.
Adopt CanvasCharacterScanner inst var name defaultTextColor in replacement of MVC tainted paragraphColor.
Fix the factory to avoid sending recursive new when hooking the concrete subclasses.

=============== Diff against Graphics-nice.266 ===============

Item was changed:
  CharacterScanner subclass: #BitBltDisplayScanner
+ 	instanceVariableNames: 'bitBlt lineY foregroundColor backgroundColor fillBlt defaultTextColor paragraphColor morphicOffset ignoreColorChanges lastDisplayableIndex stopConditionsMustBeReset'
- 	instanceVariableNames: 'bitBlt lineY foregroundColor backgroundColor fillBlt paragraphColor morphicOffset ignoreColorChanges lastDisplayableIndex stopConditionsMustBeReset'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Graphics-Text'!
  
  !BitBltDisplayScanner commentStamp: 'nice 10/9/2013 23:56' prior: 0!
  A BitBltDisplayScanner displays characters on Screen or other Form with help of a BitBlt.
  
  Instance Variables
  	backgroundColor:		<Color>
  	bitBlt:		<BitBlt>
  	fillBlt:		<BitBlt>
  	foregroundColor:		<Color>
  	ignoreColorChanges:		<Boolean>
  	lastDisplayableIndex:		<Integer>
  	lineY:		<Number>
  	morphicOffset:		<Point>
  	paragraphColor:		<Color>
  	stopConditionsMustBeReset:		<Boolean>
  
  backgroundColor
  	- the background color for displaying text.
  	Note that this can be set to Color transparent, in which case no background is displayed.
  
  bitBlt
  	- the object which knows how to copy bits from one Form (the font glyph data) to another (the destination Form)
  
  fillBlt
  	- another object for copying form bits, initialized for displaying the background.
  
  foregroundColor
  	- the foreground color for displaying text
  
  ignoreColorChanges
  	- indicates that any change of color specified in text attributes shall be ignored.
  	This is used for displaying text in a shadow mode, when dragging text for example.
  
  lastDisplayableIndex
  	- the index of last character to be displayed.
  	A different index than lastIndex is required in order to avoid display of control characters.
  	This variable must be updated by the stop condition at each inner scan loop.
  
  lineY
  	- the distance between destination form top and current line top
  
  morphicOffset
  	- an offset for positionning the embedded morphs.
  	THE EXACT SPECIFICATION YET REMAINS TO BE WRITTEN
  
  paragraphColor
  	- the default foreground color for displaying text in absence of other text attributes specification 
  
  stopConditionsMustBeReset
  	- indicates that it's necessary to call setStopConditions in next scan loop.
  
  Notes:
  In order to correctly set the lastDisplayableIndex, the display scanner performs the stopCondition BEFORE displaying the string being scanned.
  This explains why the stopCondition must not reset the font immediately, but differ this reset AFTER the display, thanks to stopConditionsMustBeReset.
  !

Item was added:
+ ----- Method: BitBltDisplayScanner>>defaultTextColor (in category 'private') -----
+ defaultTextColor
+ 	defaultTextColor ifNil:[defaultTextColor := Color black].
+ 	^defaultTextColor!

Item was added:
+ ----- Method: BitBltDisplayScanner>>displayAnchoredMorph: (in category 'displaying') -----
+ displayAnchoredMorph: aMorph
+ 	aMorph 
+ 		displayOn: bitBlt destForm 
+ 		at: destX @ destY
+ 		clippingBox: bitBlt clipRect!

Item was added:
+ ----- Method: BitBltDisplayScanner>>displayString:from:to:at: (in category 'displaying') -----
+ displayString: string from: startIndex to: stopIndex at: aPoint
+ 	font displayString: string on: bitBlt 
+ 		from: startIndex 
+ 		to: stopIndex 
+ 		at: aPoint kern: kern!

Item was added:
+ ----- Method: BitBltDisplayScanner>>fillTextBackground (in category 'displaying') -----
+ fillTextBackground
+ 	fillBlt == nil ifFalse:
+ 		["Not right"
+ 		fillBlt destX: line left destY: lineY
+ 			width: line width left height: line lineHeight; copyBits].!

Item was changed:
  ----- Method: BitBltDisplayScanner>>setFont (in category 'private') -----
  setFont 
+ 	foregroundColor := self defaultTextColor.
- 	foregroundColor := paragraphColor.
  	super setFont.  "Sets font and emphasis bits, and maybe foregroundColor"
  	font installOn: bitBlt foregroundColor: foregroundColor backgroundColor: Color transparent.
  	text ifNotNil:[destY := lineY + line baseline - font ascent]!

Item was changed:
  ----- Method: BitBltDisplayScanner>>text:textStyle:foreground:background:fillBlt:ignoreColorChanges: (in category 'private') -----
  text: t textStyle: ts foreground: foreColor background: backColor fillBlt: blt ignoreColorChanges: shadowMode
  	text := t.
  	textStyle := ts. 
+ 	foregroundColor := defaultTextColor := paragraphColor := foreColor.
- 	foregroundColor := paragraphColor := foreColor.
  	(backgroundColor := backColor) isTransparent ifFalse:
  		[fillBlt := blt.
  		fillBlt fillColor: backgroundColor].
  	ignoreColorChanges := shadowMode!

Item was changed:
  CharacterScanner subclass: #DisplayScanner
+ 	instanceVariableNames: 'lineY foregroundColor backgroundColor defaultTextColor paragraphColor morphicOffset ignoreColorChanges lastDisplayableIndex stopConditionsMustBeReset'
- 	instanceVariableNames: 'bitBlt lineY foregroundColor backgroundColor fillBlt paragraphColor morphicOffset ignoreColorChanges lastDisplayableIndex stopConditionsMustBeReset'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Graphics-Text'!
  
+ !DisplayScanner commentStamp: 'nice 10/11/2013 23:45' prior: 0!
+ A DisplayScanner is an abstract class for displaying characters.
+ It is splitting text into elementary chunks of displayable String/Font pairs (see scanning protocol).
+ Subclasses responsibility is to handle the effective rendering of these chunks on various backends.
- !DisplayScanner commentStamp: 'nice 10/9/2013 23:56' prior: 0!
- A DisplayScanner displays characters on Screen or other Form with help of a BitBlt.
  
  Instance Variables
  	backgroundColor:		<Color>
+ 	defaultTextColor:		<Color>
- 	bitBlt:		<BitBlt>
- 	fillBlt:		<BitBlt>
  	foregroundColor:		<Color>
  	ignoreColorChanges:		<Boolean>
  	lastDisplayableIndex:		<Integer>
  	lineY:		<Number>
  	morphicOffset:		<Point>
- 	paragraphColor:		<Color>
  	stopConditionsMustBeReset:		<Boolean>
  
  backgroundColor
+ 	- the background color for displaying next chunk of text.
- 	- the background color for displaying text.
  	Note that this can be set to Color transparent, in which case no background is displayed.
  
+ defaultTextColor
+ 	- the default foreground color for displaying text in absence of other text attributes specification 
- bitBlt
- 	- the object which knows how to copy bits from one Form (the font glyph data) to another (the destination Form)
  
- fillBlt
- 	- another object for copying form bits, initialized for displaying the background.
- 
  foregroundColor
+ 	- the foreground color for displaying next chunk of text
- 	- the foreground color for displaying text
  
  ignoreColorChanges
  	- indicates that any change of color specified in text attributes shall be ignored.
  	This is used for displaying text in a shadow mode, when dragging text for example.
  
  lastDisplayableIndex
  	- the index of last character to be displayed.
  	A different index than lastIndex is required in order to avoid display of control characters.
  	This variable must be updated by the stop condition at each inner scan loop.
  
  lineY
  	- the distance between destination form top and current line top
  
  morphicOffset
  	- an offset for positionning the embedded morphs.
  	THE EXACT SPECIFICATION YET REMAINS TO BE WRITTEN
  
- paragraphColor
- 	- the default foreground color for displaying text in absence of other text attributes specification 
- 
  stopConditionsMustBeReset
  	- indicates that it's necessary to call setStopConditions in next scan loop.
  
  Notes:
  In order to correctly set the lastDisplayableIndex, the display scanner performs the stopCondition BEFORE displaying the string being scanned.
  This explains why the stopCondition must not reset the font immediately, but differ this reset AFTER the display, thanks to stopConditionsMustBeReset.
  !

Item was changed:
  ----- Method: DisplayScanner class>>new (in category 'instance creation') -----
  new
  	"Use default concrete class"
+ 	^BitBltDisplayScanner basicNew initialize!
- 	^BitBltDisplayScanner new!

Item was added:
+ ----- Method: DisplayScanner>>defaultTextColor (in category 'private') -----
+ defaultTextColor
+ 	defaultTextColor ifNil:[defaultTextColor := Color black].
+ 	^defaultTextColor!

Item was added:
+ ----- Method: DisplayScanner>>defaultTextColor: (in category 'private') -----
+ defaultTextColor: color
+ 	defaultTextColor := color.!

Item was added:
+ ----- Method: DisplayScanner>>displayAnchoredMorph: (in category 'displaying') -----
+ displayAnchoredMorph: aMorph
+ 	self subclassResponsibility!

Item was changed:
  ----- Method: DisplayScanner>>displayLine:offset:leftInRun: (in category 'scanning') -----
  displayLine: textLine offset: offset leftInRun: leftInRun
  	"The call on the primitive (scanCharactersFrom:to:in:rightX:) will be interrupted according to an array of stop conditions passed to the scanner at which time the code to handle the stop condition is run and the call on the primitive continued until a stop condition returns true (which means the line has terminated).  leftInRun is the # of characters left to scan in the current run; when 0, it is time to call setStopConditions."
  	| stopCondition nowLeftInRun startIndex string lastPos lineHeight stop |
  	line := textLine.
  	morphicOffset := offset.
  	lineY := line top + offset y.
  	lineHeight := line lineHeight.
  	rightMargin := line rightMargin + offset x.
  	lastIndex := line first.
  	leftInRun <= 0 ifTrue: [self setStopConditions].
  	leftMargin := (line leftMarginForAlignment: alignment) + offset x.
  	destX := leftMargin.
+ 	self fillTextBackground.
- 	fillBlt == nil ifFalse:
- 		["Not right"
- 		fillBlt destX: line left destY: lineY
- 			width: line width left height: lineHeight; copyBits].
  	lastDisplayableIndex := lastIndex := line first.
  	leftInRun <= 0
  		ifTrue: [nowLeftInRun := text runLengthFor: lastIndex]
  		ifFalse: [nowLeftInRun := leftInRun].
  	destY := lineY + line baseline - font ascent.
  	runStopIndex := lastIndex + (nowLeftInRun - 1) min: line last.
  	spaceCount := 0.
  	string := text string.
  	[
  		"remember where this portion of the line starts"
  		startIndex := lastIndex.
  		lastPos := destX at destY.
  		
  		"reset the stopping conditions of this displaying loop, and also the font."
  		stopConditionsMustBeReset
  			ifTrue:[self setStopConditions].
  		
  		"find the end of this portion of the line"
  		stopCondition := self scanCharactersFrom: lastIndex to: runStopIndex
  						in: string rightX: rightMargin stopConditions: stopConditions
  						kern: kern.
  		"handle the stop condition - this will also set lastDisplayableIndex"
  		stop := self perform: stopCondition.
  		
  		"display that portion of the line"
  		lastDisplayableIndex >= startIndex ifTrue:[
+ 			self displayString: string
- 			font displayString: string on: bitBlt 
  				from: startIndex 
  				to: lastDisplayableIndex 
+ 				at: lastPos].
- 				at: lastPos kern: kern].
  		
  		"if the stop condition were true, stop the loop"
  		stop
  	] whileFalse.
  	^ runStopIndex - lastIndex   "Number of characters remaining in the current run"!

Item was added:
+ ----- Method: DisplayScanner>>displayString:from:to:at: (in category 'displaying') -----
+ displayString: string from: startIndex  to: stopIndex at: aPoint
+ 	self subclassResponsibility!

Item was added:
+ ----- Method: DisplayScanner>>fillTextBackground (in category 'displaying') -----
+ fillTextBackground
+ 	self subclassResponsibility!

Item was changed:
  ----- Method: DisplayScanner>>placeEmbeddedObject: (in category 'private') -----
  placeEmbeddedObject: anchoredMorph
  	anchoredMorph relativeTextAnchorPosition ifNotNil:[
  		anchoredMorph position: 
  			anchoredMorph relativeTextAnchorPosition +
  			(anchoredMorph owner textBounds origin x @ 0)
  			- (0 at morphicOffset y) + (0 at lineY).
  		^true
  	].
  	anchoredMorph relativeTextAnchorPosition ifNotNil:[^true].
  	(anchoredMorph isMorph or: [anchoredMorph isPrimitiveCostume]) ifTrue: [
  		anchoredMorph position: (destX at lineY) - morphicOffset
  	] ifFalse: [
  		destY := lineY.
+ 		self displayAnchoredMorph: anchoredMorph.
- 		anchoredMorph 
- 			displayOn: bitBlt destForm 
- 			at: destX @ destY
- 			clippingBox: bitBlt clipRect
  	].
  	destX := destX + anchoredMorph width + kern.
  	^ true!

Item was removed:
- ----- Method: DisplayScanner>>plainTab (in category 'stop conditions') -----
- plainTab
- 	| oldX |
- 	oldX := destX.
- 	super plainTab.
- 	fillBlt == nil ifFalse:
- 		[fillBlt destX: oldX destY: destY width: destX - oldX height: font height; copyBits]!

Item was removed:
- ----- Method: DisplayScanner>>setDestForm: (in category 'private') -----
- setDestForm: df
- 	bitBlt setDestForm: df.!

Item was changed:
  ----- Method: DisplayScanner>>setFont (in category 'private') -----
  setFont 
+ 	foregroundColor := self defaultTextColor.
- 	foregroundColor := paragraphColor.
  	super setFont.  "Sets font and emphasis bits, and maybe foregroundColor"
- 	font installOn: bitBlt foregroundColor: foregroundColor backgroundColor: Color transparent.
  	text ifNotNil:[destY := lineY + line baseline - font ascent]!

Item was removed:
- ----- Method: DisplayScanner>>setPort: (in category 'private') -----
- setPort: aBitBlt
- 	"Install the BitBlt to use"
- 	bitBlt := aBitBlt.
- 	bitBlt sourceX: 0; width: 0.	"Init BitBlt so that the first call to a primitive will not fail"
- 	bitBlt sourceForm: nil. "Make sure font installation won't be confused"
- !

Item was changed:
  ----- Method: DisplayScanner>>text:textStyle:foreground:background:fillBlt:ignoreColorChanges: (in category 'private') -----
  text: t textStyle: ts foreground: foreColor background: backColor fillBlt: blt ignoreColorChanges: shadowMode
  	text := t.
  	textStyle := ts. 
+ 	foregroundColor := defaultTextColor := paragraphColor := foreColor.
+ 	backgroundColor := backColor.
- 	foregroundColor := paragraphColor := foreColor.
- 	(backgroundColor := backColor) isTransparent ifFalse:
- 		[fillBlt := blt.
- 		fillBlt fillColor: backgroundColor].
  	ignoreColorChanges := shadowMode!



More information about the Packages mailing list