Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
420bcabe
Commit
420bcabe
authored
Jul 18, 2012
by
hal
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #67 from klaverty/sprite-rotate-and-resize-fix
Allow ImageSprites to be resized when rotation is enabled.
parents
6bb811bb
03d65ad7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
appinventor/components/src/com/google/appinventor/components/runtime/ImageSprite.java
...om/google/appinventor/components/runtime/ImageSprite.java
+11
-2
No files found.
appinventor/components/src/com/google/appinventor/components/runtime/ImageSprite.java
View file @
420bcabe
...
@@ -59,6 +59,7 @@ public class ImageSprite extends Sprite {
...
@@ -59,6 +59,7 @@ public class ImageSprite extends Sprite {
private
Bitmap
unrotatedBitmap
;
private
Bitmap
unrotatedBitmap
;
private
Bitmap
rotatedBitmap
;
private
Bitmap
rotatedBitmap
;
private
Bitmap
scaledBitmap
;
private
BitmapDrawable
rotatedDrawable
;
private
BitmapDrawable
rotatedDrawable
;
private
double
cachedRotationHeading
;
private
double
cachedRotationHeading
;
...
@@ -95,15 +96,23 @@ public class ImageSprite extends Sprite {
...
@@ -95,15 +96,23 @@ public class ImageSprite extends Sprite {
// Rotate around the center of the sprite image (w/2, h/2)
// Rotate around the center of the sprite image (w/2, h/2)
// TODO(halabelson): Add a way for the user to specify the center of rotation.
// TODO(halabelson): Add a way for the user to specify the center of rotation.
mat
.
setRotate
((
float
)
-
Heading
(),
w
/
2
,
h
/
2
);
mat
.
setRotate
((
float
)
-
Heading
(),
w
/
2
,
h
/
2
);
// We must scale the unrotated Bitmap to be the user specified size before
// rotating.
if
(
w
!=
unrotatedBitmap
.
getWidth
()
||
h
!=
unrotatedBitmap
.
getHeight
())
{
scaledBitmap
=
Bitmap
.
createScaledBitmap
(
unrotatedBitmap
,
w
,
h
,
true
);
}
else
{
scaledBitmap
=
unrotatedBitmap
;
}
// Next create the rotated bitmap
// Next create the rotated bitmap
// Careful: We use getWidth and getHeight of the unrotated bitmap, rather than the
// Careful: We use getWidth and getHeight of the unrotated bitmap, rather than the
// Width and Height of the sprite. Doing the latter produces an illegal argument
// Width and Height of the sprite. Doing the latter produces an illegal argument
// exception in creating the bitmap, if the user sets the Width or Height of the
// exception in creating the bitmap, if the user sets the Width or Height of the
// sprite to be larger than the image size.
// sprite to be larger than the image size.
rotatedBitmap
=
Bitmap
.
createBitmap
(
rotatedBitmap
=
Bitmap
.
createBitmap
(
unrotat
edBitmap
,
scal
edBitmap
,
0
,
0
,
0
,
0
,
unrotatedBitmap
.
getWidth
(),
unrotat
edBitmap
.
getHeight
(),
scaledBitmap
.
getWidth
(),
scal
edBitmap
.
getHeight
(),
mat
,
true
);
mat
,
true
);
// make a drawable for the rotated image and cache the heading
// make a drawable for the rotated image and cache the heading
rotatedDrawable
=
new
BitmapDrawable
(
rotatedBitmap
);
rotatedDrawable
=
new
BitmapDrawable
(
rotatedBitmap
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment