Skip to content

feat: ImageElement can rotate the image#3039

Open
laske185 wants to merge 9 commits intostride3d:masterfrom
laske185:feature/rotate-images
Open

feat: ImageElement can rotate the image#3039
laske185 wants to merge 9 commits intostride3d:masterfrom
laske185:feature/rotate-images

Conversation

@laske185
Copy link
Contributor

PR Details

The UI-element ImageElement has a new property Rotate that allows the image to be rotated. This internal changes the LocalMatrix of the element to rotate it. The property expects the angle in radians.

The GameStudio has a new editor control that allows the user to set the angle in degrees.

image

Related Issue

No issue created.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

Add a rotation property to the ImageElement that allows to rotate the image in radians.

Introduce AngleEditor control for editing rotation properties in degrees while storing values in radians.
Comment on lines 153 to 163
private void UpdateLocalMatrix()
{
if (Math.Abs(Rotation) < float.Epsilon)
{
LocalMatrix = Matrix.Identity;
}
else
{
LocalMatrix = Matrix.RotationZ(Rotation);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In this one however, I think the bot is wrong in supposing the local offset is lost,
The local matrix is taken in UIElement.UpdateWorldMatrix(), where the offsets are applied, and the result is used to compute the world-space matrix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The local position is stored in the RenderOffsets property of the UIElement. The world matrix is calculated in the UpdateWorldMatrix method that adds the local matrix with the render offsets and size.

So I agree that the bot comment is not valid.

Corrected a spelling error in method names across multiple files,
renaming UpateValueFromFloat to UpdateValueFromFloat. Updated all
declarations, overrides, and usages to improve code clarity and
consistency. No functional changes were made.
@Ethereal77
Copy link
Contributor

Looks good to me. Good job!

As the renaming was done in the editor and presentation parts, I think that doesn't merit an [Obsolete], but let's wait on other opinions on the matter.

@laske185 laske185 marked this pull request as draft January 29, 2026 17:21
@laske185
Copy link
Contributor Author

I found one issue with the UI property editor I want to fix.

…general template provider

Replaced the custom RotationFloatPropertyTemplateProvider with a new, reusable TypeNameMatchTemplateProvider that matches both type and property name. Updated XAML to use this provider for "Rotation" float properties, simplifying and generalizing the approach for property-specific editors. This makes it easier to add similar editors in the future without extra provider classes.
@laske185
Copy link
Contributor Author

I moved the registration of the property editor from DefaultPropertyTemplateProviders.xaml to the UIPropertyTemplates.xml because it wasn't working reliably before.
And I replaced the custom RotationFloatPropertyTemplateProvider with a new, reusable TypeNameMatchTemplateProvider that matches both type and property name.

@laske185 laske185 marked this pull request as ready for review January 29, 2026 18:52
Copy link
Collaborator

@Eideren Eideren left a comment

Choose a reason for hiding this comment

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

Cool stuff, some very minor issues.
I would like to have @Kryptos-FR look at this too, to let us know whether there's anything we should be careful wrt UI logic and the avalonia refactor

@Eideren Eideren requested a review from Kryptos-FR February 1, 2026 20:45
Replaces TypeNameMatchTemplateProvider with TypeAndPropertyNameMatchTemplateProvider in both XAML and C# to clarify that matching is based on both type and property name, not just type and name. Updates all relevant usages and class definitions accordingly.
Refactored the Rotation property and UpdateLocalMatrix method to use direct equality checks (==) instead of Math.Abs(... - ...) < float.Epsilon. This streamlines the code but may affect floating-point precision handling.
Refactored GetDisplayValue to remove special handling for negative zero and instead round the degree value to four decimal places for cleaner display.
</Grid.ColumnDefinitions>
<Border Grid.Column="0" CornerRadius="4" Background="{StaticResource NormalBrush}" BorderThickness="1" BorderBrush="{StaticResource NormalBorderBrush}">
<DockPanel>
<TextBlock Text="°" Margin="0,0,3,0" MinWidth="12" VerticalAlignment="Center" TextAlignment="Center" Foreground="{StaticResource TextBrush}" />
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about that part. We have other places where angles can be edited (e.g. the transform component) but we don't display the ° symbol there. So it's not consistent.

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 removed it for consistency reasons, but I thought it would be good to show the user which unit is being acquired.

Image

Copy link
Member

@Kryptos-FR Kryptos-FR Feb 9, 2026

Choose a reason for hiding this comment

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

It's a good idea. But maybe we can discuss it on another PR after this one is merged. And propose a similar change for the RotationEditor (quaternion).

- Remove reference to "Silicon Studio Corp." in file headers.
- Add notice about MIT license distribution and link to LICENSE.md.
- Clarify licensing information; no functional code changes made.
- Update Rotation setter to use floating-point tolerance comparison.
- Prevent unnecessary updates when new value is nearly equal to current.
- Address floating-point precision issues for more reliable property changes.
- Removed Grid, Border, DockPanel, and degree symbol from the template.
- Now uses only a NumericTextBox for a cleaner and more minimal UI.
- Adjusted NumericTextBox margin from "3,0" to "2,0" for improved spacing.
- Streamlines the AngleEditor appearance and reduces unnecessary elements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants