Skip to content

Apply application of world renderer canvas scale factor in #physicalSize on BlMorphicHostSpace to Pharo 12#537

Merged
tinchodias merged 1 commit intopharo-graphics:Pharo12from
Rinzwind:pharo12-blmorphichost-scaling
Jul 3, 2024
Merged

Apply application of world renderer canvas scale factor in #physicalSize on BlMorphicHostSpace to Pharo 12#537
tinchodias merged 1 commit intopharo-graphics:Pharo12from
Rinzwind:pharo12-blmorphichost-scaling

Conversation

@Rinzwind
Copy link
Contributor

This pull request applies the changes of pull request #465 to the ‘Pharo12’ branch. The two SystemVersion checks could presumably be dropped, but I kept them to not deviate from the implementation in the ‘dev’ branch.

…ze on BlMorphicHostSpace apply the world renderer canvas scale factor”) to Pharo 12.
@Rinzwind
Copy link
Contributor Author

The checkout for the tests used commit 5fa5f0c which is a merge with the ‘dev’ branch, presumably because I had forgotten to change the base branch to ‘Pharo12’ when opening this pull request.

@Rinzwind Rinzwind closed this Jun 18, 2024
@Rinzwind Rinzwind reopened this Jun 18, 2024
@Rinzwind
Copy link
Contributor Author

I closed and reopened, the checkout for the tests now used commit f6a7a23 which is a merge with the ‘Pharo12’ branch as expected.

aClippedCanvas drawImage: spaceForm at: self position ] ]
SystemVersion current major >= 12 ifTrue: [
| formSet |
formSet := (Smalltalk at: #FormSet) extent: self extent depth: spaceForm depth forms: { spaceForm }.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was FormSet introduced in Pharo 12?

In any case, I have doubts about Smalltalk at: #FormSet. I think Pharo moves towards moving to use self class environment classNamed: #FormSet instead of it. @tesonep should now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced FormSet in Pharo 12 in Pharo pull request #14998.

It seemed better to keep the implementation the same as in the ‘dev’ branch. I don’t know whether the ‘dev’ branch is supposed to still be usable with Pharo 11 or even older versions though. If not, I could drop the SystemVersion checks and the use of Smalltalk in the ‘dev’ branch first and update this pull request accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have opened pull request #544 to remove support for Pharo 11.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for your work @Rinzwind, and I apologise for not answering fast to your comment and PR. I talked with @tesonep and, as @plantec wrote in the PR, we will keep support for P11. I will check how to merge your contribution, because it's great and we want it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks, I will close pull request #544 then.

| canvasScaleFactor |

canvasScaleFactor := SystemVersion current major >= 12
ifTrue: [ (Smalltalk at: #OSWorldRenderer) canvasScaleFactor ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think OSWorldRenderer existed in Pharo for several years, in which case the "Smalltalk at:" would not be needed... or is it a new class name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the class through Smalltalk like this avoids an ‘unknown variable’ error in versions of Pharo that don’t have the class, which is probably not really relevant here as OSWorldRenderer exists since Pharo 8, but it also avoids a match of ReSendsUnknownMessageToGlobalRule in Pharo 11.

@tinchodias
Copy link
Collaborator

(A bit OFFTOPIC:) @Rinzwind do you have an opinion on BlPhysicalDisplaySize? I doubt about its existence... I'm not clear why not using 'Point'.

As an exercise I rewrote a method in this PR as:

	^ SystemVersion current major >= 12
		ifTrue: [
			| canvasScaleFactor |
			canvasScaleFactor := OSWorldRenderer canvasScaleFactor.
			BlPhysicalDisplaySize
				width: (spaceHostMorph width * canvasScaleFactor)
				height: (spaceHostMorph height * canvasScaleFactor) ]
		ifFalse: [
			BlPhysicalDisplaySize
				width: spaceHostMorph width
				height: spaceHostMorph height ]

... at the end, BlPhysicalDisplaySize is the same as Point.

@Rinzwind
Copy link
Contributor Author

I’m not entirely sure I understand the question about BlPhysicalDisplaySize, I tried just removing the send of #asPhysicalSize from #physicalSize on BlMorphicHostSpace so that it answers a Point instead of a BlPhysicalDisplaySize, but that causes an error when opening the Bloc Demo Browser (“Instance of Point did not understand #width” in #scaleFactor on BlMorphicHostSpace).

@tinchodias
Copy link
Collaborator

Some context. At some moment of the history of Bloc (that I ignore) this hierarchy was introduced:
Screenshot 2024-07-01 at 14 21 37
It provides API to convert values with scale factors. So, @Rinzwind is in the domain of the problem you attacked with this feature, both in Pharo morphic and now in Bloc.

But I find not much sense on these classes, and I wonder if we remove them. Or we improve so they start to make sense. I asked your opinion because maybe you had some comments either in favor or against these classes.

@tinchodias
Copy link
Collaborator

tinchodias commented Jul 1, 2024

This test shows its usage (BlDisplayPositionsTest>>#testAsPhysical):

testAsPhysical

	| aLogicalPosition aPhysicalPosition |
	aLogicalPosition := BlLogicalDisplayPosition fromPoint: 100 @ 200.
	aPhysicalPosition := aLogicalPosition asPhysical: 2.
	self assert: aPhysicalPosition asPoint equals: 200 @ 400.

e.g.:
There is a logical point (100, 200) but the physical device has a scale factor 2, then the API helps converting to (200, 400)... but do we need this help?

Maybe if the physical device is modeled as a new class BlPhysicalDevice, that has the scale factor inside. And the BlPhysicalPositions can have a reference to the device. Then the knowledge about what is the scale factor can be into an object that models a physical device. There can be also a subscription API so you receive a message when the device changes the scale factor and you act in consequence (e.g. refresh the BlSpace).

@Rinzwind
Copy link
Contributor Author

Rinzwind commented Jul 2, 2024

I’m not sure I can really help answer this question, but I can see benefit to having different classes for representing a position versus a size, and representing a scaled position or size versus one that is not scaled. When all four are represented as a plain Point, it can get confusing to keep track of which is which, especially when one can’t easily tell from the name of the variable the Point is contained in. Looking at the number of references to the classes and the senders of #asLogical: and #asPhysical: it however seems these distinctions aren’t used all that much so I can also see why you might prefer to drop them altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants