Skip to content

Commit fb825cb

Browse files
committed
Use bitmap resolution in costume dimensions
1 parent c16df87 commit fb825cb

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/scratch/costume.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ double Costume::bitmapResolution() const
2626
/*! Sets the reciprocal of the costume scaling factor for bitmap costumes. */
2727
void Costume::setBitmapResolution(double newBitmapResolution)
2828
{
29+
if (impl->bitmapResolution == newBitmapResolution)
30+
return;
31+
2932
impl->bitmapResolution = newBitmapResolution;
33+
impl->updateImage();
3034
}
3135

3236
/*! Returns the x-coordinate of the rotation center. */
@@ -56,13 +60,13 @@ void Costume::setRotationCenterY(int newRotationCenterY)
5660
/*! Returns the costume width. */
5761
unsigned int Costume::width() const
5862
{
59-
return impl->image->width() * impl->scale;
63+
return impl->image->width() * impl->scale / impl->bitmapResolution;
6064
}
6165

6266
/*! Returns the costume height. */
6367
unsigned int Costume::height() const
6468
{
65-
return impl->image->height() * impl->scale;
69+
return impl->image->height() * impl->scale / impl->bitmapResolution;
6670
}
6771

6872
/*! Returns the image scale. */

src/scratch/costume_p.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,30 @@ CostumePrivate::~CostumePrivate()
1616

1717
void CostumePrivate::updateImage()
1818
{
19-
unsigned int scaledWidth = image->width() * scale;
20-
unsigned int scaledHeight = image->height() * scale;
19+
unsigned int scaledWidth = image->width() * scale / bitmapResolution;
20+
unsigned int scaledHeight = image->height() * scale / bitmapResolution;
2121

2222
if (scaledWidth == 0 || scaledHeight == 0) {
2323
freeImage();
2424
return;
2525
}
2626

27-
if (!bitmap || (scale != oldScale)) {
27+
if (!bitmap || (scale != oldScale) || (bitmapResolution != oldBitmapResolution)) {
2828
freeImage();
2929
bitmap = static_cast<Rgb **>(malloc(sizeof(Rgb *) * scaledHeight));
3030

3131
for (unsigned int i = 0; i < scaledHeight; i++)
3232
bitmap[i] = static_cast<Rgb *>(malloc(sizeof(Rgb) * scaledWidth));
3333

3434
oldScale = scale;
35+
oldBitmapResolution = bitmapResolution;
3536
oldWidth = scaledWidth;
3637
oldHeight = scaledHeight;
3738
}
3839

3940
for (unsigned int i = 0; i < scaledHeight; i++) {
4041
for (unsigned int j = 0; j < scaledWidth; j++) {
41-
Rgb color = image->colorAt(mirrorHorizontally ? (scaledWidth - 1 - j) : j, i, scale);
42+
Rgb color = image->colorAt(mirrorHorizontally ? (scaledWidth - 1 - j) : j, i, scale / bitmapResolution);
4243

4344
// TODO: Apply graphics effects here
4445

src/scratch/costume_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct CostumePrivate
1919
void updateImage();
2020
void freeImage();
2121

22+
double oldBitmapResolution = 1;
2223
double bitmapResolution = 1;
2324
int rotationCenterX = 0;
2425
int rotationCenterY = 0;

0 commit comments

Comments
 (0)