Skip to content

Refactor ImageMorph to support more than one Form depicting the same image at different scales#14998

Merged
jecisc merged 6 commits intopharo-project:Pharo12from
Rinzwind:imagemorph-formset
Oct 23, 2023
Merged

Refactor ImageMorph to support more than one Form depicting the same image at different scales#14998
jecisc merged 6 commits intopharo-project:Pharo12from
Rinzwind:imagemorph-formset

Conversation

@Rinzwind
Copy link
Copy Markdown
Contributor

This pull request:

  • Introduces a class FormSet for representing images for which there can be more than one Form depicting the same image at different scales
  • Adds methods to Canvas for drawing a FormSet
  • Refactors the ImageMorph hierarchy to replace instance variables that hold a Form by ones that hold a FormSet instead
  • Makes ScrollBarMorph use FormSet for the arrows on the buttons at scale 1 and 2

The distinction between FormSet and Form is akin to that between NSImage and NSImageRep in macOS’s AppKit. A similar concept is that of an <img> element with a ‘srcset’ attribute in HTML.

I initially used ‘Image’ as the name for the class but found that that got confusing as ‘image’ is already used in many selectors and variable names as a synonym for ‘form’. Once FormSet is used more and ‘image’ becomes more of a synonym for ‘form set’, the class could still be renamed to ‘Image’ as well.

The handling of the ‘none’ case in FormSet>>#asFormWithExtent: could be improved by scaling the Form that most closely matches the given extent rather than just the first Form, and the result should perhaps be cached, but there’s no need for either of that at the moment.

Note that loading these changes into an existing Pharo image probably requires using headless mode.

…ToSize: in that it does not maintain the aspect ratio).
…more than one Form depicting the same image at different scales.
…ld a Form by ones that hold a FormSet (except for ‘cachedForm’ in AlphaImageMorph).
… for the corresponding arrow at scale 1 and 2.
@Rinzwind
Copy link
Copy Markdown
Contributor Author

I applied this to the ‘Retina display’ scaling experiment from earlier pull requests: commits 482bcd7 and a7e272b (these commits are not included in this pull request, the branch is ‘scaling-canvas-tryout-10’).

In the extra world opened by OSWorldRendererScalingCanvas example, previously the buttons of scrollbars looked a little blurry as they still used a scale one Form for the arrow, that has now been fixed:

ScalingCanvas still uses its ‘FormMapping’ for remapping other forms from the UITheme and ThemeIcons, that should be dropped by using FormSet for those as well.

Copy link
Copy Markdown
Member

@jecisc jecisc left a comment

Choose a reason for hiding this comment

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

This seems ok but it's the first time I see most of the code edited so if someone else wants to take a look I would prefer it

@Ducasse
Copy link
Copy Markdown
Member

Ducasse commented Oct 14, 2023

This is a nice design.
Could you have some tests and comments on FormSet? for example to illustrate how the extent of a set is computed and how a FormSet is created (for example betteer comment in forms: method).
a test showing how the right form of the formset is selected would be nice too.

@Rinzwind
Copy link
Copy Markdown
Contributor Author

I added FormSetTest and extended the comment on FormSet.

@Ducasse
Copy link
Copy Markdown
Member

Ducasse commented Oct 23, 2023

Coool!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants