'From Squeak6.0alpha of 30 December 2021 [latest update: #20934] on 30 December 2021 at 5:57:26 pm'!

!DisplayScreen methodsFor: 'scale factor' stamp: 'mt 12/30/2021 17:13'!
uiScaleFactor: aFloat
	"Sets the effective scale factor for the user interface, i.e., all widgets, tools, and windows. The user can override the CurrentScaleFactor recommended by the platform."

	| oldFactor newFactor |
	(UserInterfaceTheme current canFakeScaleFactor: aFloat) ifTrue: [
		self flag: #isTTCBased.
		^ UserInterfaceTheme current applyScaled: aFloat].
	
	oldFactor := RealEstateAgent scaleFactor. "Use effective, pixel-based factor to account for rounding errors. See #isTTCBased and #uiScaleFactor."
	newFactor := aFloat max: 0.75.
	newFactor = oldFactor ifTrue: [^ self].
	
	TextStyle pixelsPerInch: 96.0 * aFloat.
	newFactor := RealEstateAgent resetScaleFactor; scaleFactor. "Again, account for rounding errors."
	Project current ifNotNil: [:p | p displayScaleChangedFrom: oldFactor to: newFactor].! !


!DockingBarMorph methodsFor: 'construction' stamp: 'mt 12/30/2021 17:55'!
addSpacer
	"Add a new spacer to the receiver. 
	 
	Spacer are objects that try to use as much space as they can"
	self addMorphBack: (Morph new
		color: Color transparent;
		hResizing: #spaceFill;
		vResizing: #spaceFill;
		spaceFillWeight: (Preferences tinyDisplay ifTrue: [0.1] ifFalse: [1]);
		extent: 1@1).! !


!Preferences class methodsFor: 'updating - system' stamp: 'mt 12/30/2021 17:18'!
displaySizeChanged

	self tinyDisplay
		ifTrue: [self enable: #scrollBarsNarrow]
		ifFalse: [self disable: #scrollBarsNarrow].
	self tinyDisplay 
		ifTrue:[self disable: #biggerHandles] 
		ifFalse:[self enable: #biggerHandles].
	self tinyDisplay
		ifTrue: [Display uiScaleFactor: 0.75]
		ifFalse: [Display uiScaleFactor: Display platformScaleFactor].! !


!TheWorldMainDockingBar methodsFor: 'submenu - extras' stamp: 'mt 12/30/2021 17:16'!
scaleFactorsOn: menu

	| presets currentScaleFactor currentPlatformScaleFactor |
	currentScaleFactor := (Display relativeUiScaleFactor * 100) rounded.
	currentPlatformScaleFactor := Display platformScaleFactorKnown
		ifTrue: [(Display platformScaleFactor * 100) rounded].
	presets := 75 to: 300 by: 25.
	
	presets do: [:scale |
		scale = 100 ifTrue: [menu addLine]. "Normal scales."
		scale = 175 ifTrue: [menu addLine]. "TTCFont used after this line..."
		menu addItem: [:item|
			item
				contents: ('{1}{2}%{3}{4}' format: {
					currentScaleFactor = scale ifTrue: ['<yes>'] ifFalse: ['<no>'].
					scale.
					DisplayScreen relativeScaleFactorEnabled
						ifTrue: ['' "macOS"] ifFalse: [
							scale = currentPlatformScaleFactor
								ifTrue: [' (recommended)'] ifFalse: ['']].
					scale = 75 ifTrue: [' (low ppi)'] ifFalse: ['']
					});
				target: Display;
				selector: #relativeUiScaleFactor:;
				arguments: {scale / 100}]].
		
	menu addLine.
	menu addItem: [:item |
		item
			contents: ((presets includes: currentScaleFactor) not ifTrue: ['<yes> Custom: ', currentScaleFactor, '% ...'] ifFalse: ['<no>Other scale factor...']);
			target: self;
			selector: #chooseCustomScaleFactor].! !


!UserInterfaceTheme methodsFor: 'private - display scale' stamp: 'mt 12/30/2021 17:12'!
canFakeScaleFactor: aFloat
	"Answer whether we can fake the given scale factor with pre-rendered fonts."

	self isTTCBased ifFalse: [^ true "Need to #makeTTCBased anyway."].
	(self lookupScaleFactor: 1.0) ifNil: [^ false "Without a fake 100%, we go all-in with TrueType fonts."].

	aFloat = 0.75 ifTrue: [^ true].
	aFloat = 1.0 ifTrue: [^ true].
	aFloat = 1.25 ifTrue: [^ true].
	aFloat = 1.5 ifTrue: [^ true].
	
	^ false! !

!UserInterfaceTheme methodsFor: 'private - display scale' stamp: 'mt 12/30/2021 17:11'!
doScale075
	"Private. Use #applyScaled:. This is actually about 71% because of which font sizes we have available."
	
	self flag: #hack. "mt: A different scale factor should not result in different point sizes being selected BUT the same point size resulting in a different pixel height."
	
	self setFonts: #(
		standardSystemFont 7.5
		standardFixedFont 7.5

		standardCodeFont 7.5
		standardListFont 7.5
		standardButtonFont 7.5
		standardMenuFont 7.5
		standardFlapFont 7.5
			
		windowTitleFont 7.5
		balloonHelpFont 7.5
		haloLabelFont 7.5
		
		wizardStandardFont 10.5
		wizardButtonFont 10.5
		wizardHelpFont 7.5
		wizardTitleFont 16.5) forceTTC: false.

	self apply.
	TextStyle pixelsPerInch: 96.0. "Restore Squeak's default PPI for 100%."! !

!UserInterfaceTheme methodsFor: 'private - display scale' stamp: 'mt 12/30/2021 17:38'!
setScaleFactor: aFloat
	"Private. Use #applyScaled:. In the receiver, change the fonts to have a scale of aFloat. Change all fonts to be TrueType fonts if no pre-rendered fonts exist. Never change the 100% reference theme but make a copy. Apply the receiver to the system."

	(self isTTCBased not and: [aFloat = self localScaleFactor])
		ifTrue: [self apply. ^ self].

	(self isTTCBased not and: [self localScaleFactor = 1.0]) "!!!! Never change the reference theme !!!!"
		ifTrue: [^ self lookupSimilar ifNil: [self copyWithScaleFactor: aFloat] ifNotNil: [:other | other setScaleFactorPreApply: aFloat]].
	
	aFloat = 0.75 ifTrue: [^ self doScale075].
	aFloat = 1.0 ifTrue: [^ self doScale100].
	aFloat = 1.25 ifTrue: [^ self doScale125].
	aFloat = 1.5 ifTrue: [^ self doScale150].

	"And now transition from the pre-rendered world into the TrueType world. Or re-use an existing TrueType-based theme with new values. See #lookupSimilar above."
	TextStyle pixelsPerInch: 96.0 * RealEstateAgent scaleFactor "current, based on pixels".
	self makeTTCBased.
	self applyAfter: [TextStyle pixelsPerInch: 96.0 * aFloat "new, not rounded"].! !

