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
2bf41704
Commit
2bf41704
authored
6 years ago
by
Karishma Chadha
Browse files
Options
Downloads
Patches
Plain Diff
Add bitmap support to backdrop upload button.
parent
4c50363a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/stage-selector/stage-selector.jsx
+1
-1
1 addition, 1 deletion
src/components/stage-selector/stage-selector.jsx
src/containers/stage-selector.jsx
+30
-12
30 additions, 12 deletions
src/containers/stage-selector.jsx
with
31 additions
and
13 deletions
src/components/stage-selector/stage-selector.jsx
+
1
−
1
View file @
2bf41704
...
...
@@ -86,7 +86,7 @@ const StageSelector = props => {
title
:
intl
.
formatMessage
(
messages
.
addBackdropFromFile
),
img
:
fileUploadIcon
,
onClick
:
onBackdropFileUploadClick
,
fileAccept
:
'
.svg
'
,
// Bitmap coming soon
fileAccept
:
'
.svg
, .png, .jpg, .jpeg
'
,
// Bitmap coming soon
fileChange
:
onBackdropFileUpload
,
fileInput
:
fileInputRef
},
{
...
...
This diff is collapsed.
Click to expand it.
src/containers/stage-selector.jsx
+
30
−
12
View file @
2bf41704
...
...
@@ -10,6 +10,8 @@ import StageSelectorComponent from '../components/stage-selector/stage-selector.
import
backdropLibraryContent
from
'
../lib/libraries/backdrops.json
'
;
import
costumeLibraryContent
from
'
../lib/libraries/costumes.json
'
;
import
{
importBitmap
}
from
'
scratch-svg-renderer
'
;
import
log
from
'
../lib/log.js
'
;
class
StageSelector
extends
React
.
Component
{
constructor
(
props
)
{
...
...
@@ -63,7 +65,6 @@ class StageSelector extends React.Component {
// if they choose
thisFileInput
.
value
=
null
;
// Cache the image in storage
const
backdropBuffer
=
reader
.
result
;
const
storage
=
this
.
props
.
vm
.
runtime
.
storage
;
const
fileType
=
thisFile
.
type
;
// check what the browser thinks this is
// Only handling png and svg right now
...
...
@@ -75,26 +76,43 @@ class StageSelector extends React.Component {
}
else
if
(
fileType
===
'
image/jpeg
'
)
{
backdropFormat
=
storage
.
DataFormat
.
JPG
;
assetType
=
storage
.
AssetType
.
ImageBitmap
;
}
else
{
}
else
if
(
fileType
===
'
image/png
'
)
{
backdropFormat
=
storage
.
DataFormat
.
PNG
;
assetType
=
storage
.
AssetType
.
ImageBitmap
;
}
if
(
!
backdropFormat
)
return
;
const
md5
=
storage
.
builtinHelper
.
cache
(
assetType
,
backdropFormat
,
new
Uint8Array
(
backdropBuffer
));
const
addBackdropFromBuffer
=
(
function
(
error
,
backdropBuffer
)
{
if
(
error
)
{
log
.
warn
(
`An error occurred while trying to extract image data:
${
error
}
`
);
return
;
}
const
md5Ext
=
`
${
md5
}
.
${
backdropFormat
}
`
;
const
md5
=
storage
.
builtinHelper
.
cache
(
assetType
,
backdropFormat
,
backdropBuffer
);
const
vmBackdrop
=
{
name
:
'
backdrop1
'
,
dataFormat
:
backdropFormat
,
md5
:
`
${
md5Ext
}
`
};
const
md5Ext
=
`
${
md5
}
.
${
backdropFormat
}
`
;
this
.
props
.
vm
.
addBackdrop
(
md5Ext
,
vmBackdrop
);
const
vmBackdrop
=
{
name
:
'
backdrop1
'
,
dataFormat
:
backdropFormat
,
md5
:
`
${
md5Ext
}
`
};
this
.
props
.
onActivateTab
(
COSTUMES_TAB_INDEX
);
this
.
props
.
vm
.
addBackdrop
(
md5Ext
,
vmBackdrop
);
this
.
props
.
onActivateTab
(
COSTUMES_TAB_INDEX
);
}).
bind
(
this
);
if
(
backdropFormat
===
storage
.
DataFormat
.
SVG
)
{
// Must pass in file data as a Uint8Array,
// passing in an array buffer causes the sprite/costume
// thumbnails to not display because the data URI for the costume
// is invalid
addBackdropFromBuffer
(
null
,
new
Uint8Array
(
reader
.
result
));
}
else
{
// otherwise it's a bitmap
importBitmap
(
reader
.
result
,
addBackdropFromBuffer
);
}
};
if
(
thisFileInput
.
files
)
{
thisFile
=
thisFileInput
.
files
[
0
];
...
...
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