[Cuis-dev] Nostalgia (I-Beam Text-Cursor)

Gerald Klix cuis.01 at klix.ch
Tue Dec 1 00:38:01 PST 2020


Hi all,

If there's anyone around, who wants the old
Smalltalk/V 1.2 I-Beam text-cursor back,
here is a small patch.


Best Regards,

Gerald
-------------- next part --------------
'From Cuis 5.0 [latest update: #4482] on 1 December 2020 at 9:24:00 am'!

!TextComposition methodsFor: 'display' stamp: 'KLG 12/1/2020 09:23:39'!
displayTextCursorAtX: x top: top bottom: bottom emphasis: emphasis on: aCanvas textLeft: textLeft
	"x, top, bottom, textLeft are relative to the morph currently being drawn."

	| textCursorColor x1 isBold isItalic x0 h w halfW r d extraW corner origin
	  finalStart finalEnd 
	  flangeHeight flangeWidth |
	isBold _ emphasis allMask: 1.
	isItalic _ emphasis allMask: 2.
	textCursorColor _ Theme current textCursor.
	h _ bottom - top.
	w _ isBold
		ifTrue: [ h // 25 + 2 ]
		ifFalse: [ h // 30 + 1 ].
	halfW _ w // 2.
	isItalic
		ifTrue: [	
			"Keep tweaking if needed!! For italics with descenders (i.e. p), cursor shows a bit to the left..."
			d _ isBold ifTrue: [ h // 8 ] ifFalse: [ h // 9].
			x0 _ x- (h*5//24) + d.
			x1 _ x + d ]
		ifFalse: [
			x0 _ x - halfW.
			x1 _ x - halfW].
	x0-textLeft < -1 ifTrue: [
		x1 _ x1 - x0 + textLeft.
		x0 _ textLeft ].
	r _ extentForComposing x-halfW-1.
	r < (x1-textLeft) ifTrue: [
		x0 _ x0 + r - x1+textLeft.
		x1 _ r +textLeft].
	extraW _ isBold
		ifTrue: [ 3 ]
		ifFalse: [ 2 ].
	origin _ x0-halfW@ top.
	corner _ x1+halfW+extraW @ (bottom+2).
	flangeHeight _ 1.
	flangeWidth _ 5.
	lastTextCursorRect
		ifNil: [ lastTextCursorRect _ origin corner: corner ]
		ifNotNil: [lastTextCursorRect
			setOrigin: (lastTextCursorRect origin min: origin)
			corner: (lastTextCursorRect corner max: corner)].
	lastTextCursorRect _
		lastTextCursorRect expandBy: (flangeWidth @ flangeHeight).
	aCanvas
		line: (finalStart _ (x0+halfW@(bottom-w-w+halfW) - (0 @ flangeHeight)))
		 	to: (finalEnd _ (x1+halfW at top) + (0 @ flangeHeight))
			width: w color: textCursorColor;
		line: finalEnd - (flangeWidth @ flangeHeight) to: finalEnd
			width:  w color: textCursorColor;
		line: finalEnd to: finalEnd + (flangeWidth @ flangeHeight negated)
			width:  w color: textCursorColor;
		line: finalStart + (flangeWidth @ flangeHeight) to: finalStart
			width:  w  color: textCursorColor;
		line: finalStart to: finalStart - (flangeWidth @ flangeHeight negated)
			width:  w  color: textCursorColor
! !


More information about the Cuis-dev mailing list