Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
93645ea7
Unverified
Commit
93645ea7
authored
8 years ago
by
Tim Mickel
Browse files
Options
Downloads
Patches
Plain Diff
CostumeCanvas nits
parent
7a675cd8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/costume-canvas.js
+13
-5
13 additions, 5 deletions
src/components/costume-canvas.js
with
13 additions
and
5 deletions
src/components/costume-canvas.js
+
13
−
5
View file @
93645ea7
...
...
@@ -10,11 +10,6 @@ const xhr = require('xhr');
*/
class
CostumeCanvas
extends
React
.
Component
{
render
()
{
return
<
canvas
ref
=
'
costumeCanvas
'
width
=
{
this
.
props
.
width
}
height
=
{
this
.
props
.
height
}
/>
;
}
componentDidMount
()
{
this
.
load
();
}
...
...
@@ -30,20 +25,27 @@ class CostumeCanvas extends React.Component {
}
}
draw
()
{
// Draw the costume to the rendered canvas.
const
img
=
this
.
img
;
const
context
=
this
.
refs
.
costumeCanvas
.
getContext
(
'
2d
'
);
// Scale to fit.
let
scale
;
// Choose the larger dimension to scale by.
if
(
img
.
width
>
img
.
height
)
{
scale
=
this
.
refs
.
costumeCanvas
.
width
/
img
.
width
;
}
else
{
scale
=
this
.
refs
.
costumeCanvas
.
height
/
img
.
height
;
}
// Rotate by the Scratch-value direction.
const
angle
=
(
-
90
+
this
.
props
.
direction
)
*
Math
.
PI
/
180
;
// Rotation origin point will be center of the canvas.
const
contextTranslateX
=
this
.
refs
.
costumeCanvas
.
width
/
2
;
const
contextTranslateY
=
this
.
refs
.
costumeCanvas
.
height
/
2
;
// First, clear the canvas.
context
.
clearRect
(
0
,
0
,
this
.
refs
.
costumeCanvas
.
width
,
this
.
refs
.
costumeCanvas
.
height
);
// Translate the context to the center of the canvas,
// then rotate canvas drawing by `angle`.
context
.
translate
(
contextTranslateX
,
contextTranslateY
);
context
.
rotate
(
angle
);
context
.
drawImage
(
img
,
...
...
@@ -51,6 +53,7 @@ class CostumeCanvas extends React.Component {
-
(
scale
*
img
.
width
/
2
),
-
(
scale
*
img
.
height
/
2
),
scale
*
img
.
width
,
scale
*
img
.
height
);
// Reset the canvas rotation and translation to 0, (0, 0).
context
.
rotate
(
-
angle
);
context
.
translate
(
-
contextTranslateX
,
-
contextTranslateY
);
}
...
...
@@ -86,6 +89,11 @@ class CostumeCanvas extends React.Component {
};
}
}
render
()
{
return
<
canvas
ref
=
'
costumeCanvas
'
width
=
{
this
.
props
.
width
}
height
=
{
this
.
props
.
height
}
/>
;
}
}
CostumeCanvas
.
defaultProps
=
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment