-
Couldn't load subscription status.
- Fork 1.1k
Optimize icon rendering: simplify logic and eliminate redundant calculations #13449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -269,123 +269,43 @@ public void Dispose() | |||||
| // object, but a graphics object generally has no idea how to render a given image. So, | ||||||
| // it passes the call to the actual image. This version crops the image to the given | ||||||
| // dimensions and allows the user to specify a rectangle within the image to draw. | ||||||
| private void DrawIcon(HDC hdc, Rectangle imageRect, Rectangle targetRect, bool stretch) | ||||||
| private void DrawIcon(Graphics graphics, Rectangle imageRect, Rectangle targetRect, bool stretch) | ||||||
| { | ||||||
| int imageX = 0; | ||||||
| int imageY = 0; | ||||||
| int imageWidth; | ||||||
| int imageHeight; | ||||||
| int targetX = 0; | ||||||
| int targetY = 0; | ||||||
| int targetWidth; | ||||||
| int targetHeight; | ||||||
|
|
||||||
| Size cursorSize = Size; | ||||||
|
|
||||||
| // Compute the dimensions of the icon if needed. | ||||||
| if (!imageRect.IsEmpty) | ||||||
| { | ||||||
| imageX = imageRect.X; | ||||||
| imageY = imageRect.Y; | ||||||
| imageWidth = imageRect.Width; | ||||||
| imageHeight = imageRect.Height; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| imageWidth = cursorSize.Width; | ||||||
| imageHeight = cursorSize.Height; | ||||||
| } | ||||||
| imageRect = imageRect.IsEmpty ? new Rectangle(Point.Empty, Size) : imageRect; | ||||||
| targetRect = targetRect.IsEmpty ? new Rectangle(Point.Empty, Size) : targetRect; | ||||||
|
|
||||||
| if (!targetRect.IsEmpty) | ||||||
| { | ||||||
| targetX = targetRect.X; | ||||||
| targetY = targetRect.Y; | ||||||
| targetWidth = targetRect.Width; | ||||||
| targetHeight = targetRect.Height; | ||||||
| } | ||||||
| else | ||||||
| { | ||||||
| targetWidth = cursorSize.Width; | ||||||
| targetHeight = cursorSize.Height; | ||||||
| } | ||||||
| imageRect.Inflate(stretch | ||||||
| ? new Size(targetRect.Width / imageRect.Width, targetRect.Height / imageRect.Height) | ||||||
| : new Size(0, 0)); | ||||||
|
|
||||||
| int drawWidth, drawHeight; | ||||||
| int clipWidth, clipHeight; | ||||||
| targetRect.Offset(Point.Round(graphics.Transform.Offset)); | ||||||
|
||||||
| targetRect.Offset(Point.Round(graphics.Transform.Offset)); | |
| targetRect.Offset(Point.Truncate(graphics.Transform.Offset)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Rectangle.Inflate with a scale factor (targetRect.Width / imageRect.Width) inflates the rectangle by pixel amounts rather than resizing it to the desired dimensions. This misuses Inflate for stretching logic and leads to incorrect sizing. Consider directly assigning imageRect.Size = targetRect.Size when stretch is true, or apply a proper scaling transformation.