Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bevy Cosmic Edit
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Microhacks
Bevy Forks
Bevy Cosmic Edit
Commits
6f5e97d0
Commit
6f5e97d0
authored
1 year ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
add image background example
parent
95c5912c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
assets/img/bevy_logo_light.png
+0
-0
0 additions, 0 deletions
assets/img/bevy_logo_light.png
examples/image_background.rs
+44
-0
44 additions, 0 deletions
examples/image_background.rs
src/lib.rs
+16
-13
16 additions, 13 deletions
src/lib.rs
with
60 additions
and
13 deletions
assets/img/bevy_logo_light.png
0 → 100644
+
0
−
0
View file @
6f5e97d0
14.8 KiB
This diff is collapsed.
Click to expand it.
examples/image_background.rs
0 → 100644
+
44
−
0
View file @
6f5e97d0
use
bevy
::
prelude
::
*
;
use
bevy_cosmic_edit
::{
change_active_editor_sprite
,
change_active_editor_ui
,
ActiveEditor
,
CosmicAttrs
,
CosmicBackground
,
CosmicEditPlugin
,
CosmicEditUiBundle
,
};
use
cosmic_text
::{
Attrs
,
AttrsOwned
};
fn
setup
(
mut
commands
:
Commands
,
asset_server
:
Res
<
AssetServer
>
)
{
commands
.spawn
(
Camera2dBundle
::
default
());
let
bg_image_handle
=
asset_server
.load
(
"img/bevy_logo_light.png"
);
let
editor
=
commands
.spawn
(
CosmicEditUiBundle
{
style
:
Style
{
// Size and position of text box
width
:
Val
::
Px
(
300.
),
height
:
Val
::
Px
(
50.
),
left
:
Val
::
Px
(
100.
),
top
:
Val
::
Px
(
100.
),
..
default
()
},
cosmic_attrs
:
CosmicAttrs
(
AttrsOwned
::
new
(
Attrs
::
new
()
.color
(
cosmic_text
::
Color
::
rgb
(
0
,
255
,
0
)),
)),
background_image
:
CosmicBackground
(
Some
(
bg_image_handle
)),
..
default
()
})
.id
();
commands
.insert_resource
(
ActiveEditor
{
entity
:
Some
(
editor
),
});
}
fn
main
()
{
App
::
new
()
.add_plugins
(
DefaultPlugins
)
.add_plugins
(
CosmicEditPlugin
::
default
())
.add_systems
(
Startup
,
setup
)
.add_systems
(
Update
,
change_active_editor_ui
)
.add_systems
(
Update
,
change_active_editor_sprite
)
.run
();
}
This diff is collapsed.
Click to expand it.
src/lib.rs
+
16
−
13
View file @
6f5e97d0
...
...
@@ -1046,19 +1046,22 @@ fn redraw_buffer_common(
let
mut
pixels
=
vec!
[
0
;
width
as
usize
*
height
as
usize
*
4
];
if
let
Some
(
bg_image
)
=
background_image
{
let
image
=
images
.get
(
&
bg_image
)
.unwrap
();
let
mut
dynamic_image
=
image
.clone
()
.try_into_dynamic
()
.unwrap
();
if
image
.size
()
.x
!=
width
||
image
.size
()
.y
!=
height
{
dynamic_image
=
dynamic_image
.resize_to_fill
(
width
as
u32
,
height
as
u32
,
FilterType
::
Triangle
);
}
for
(
i
,
(
_
,
_
,
rgba
))
in
dynamic_image
.pixels
()
.enumerate
()
{
if
let
Some
(
p
)
=
pixels
.get_mut
(
i
*
4
..
(
i
+
1
)
*
4
)
{
p
[
0
]
=
rgba
[
0
];
p
[
1
]
=
rgba
[
1
];
p
[
2
]
=
rgba
[
2
];
p
[
3
]
=
rgba
[
3
];
if
let
Some
(
image
)
=
images
.get
(
&
bg_image
)
{
let
mut
dynamic_image
=
image
.clone
()
.try_into_dynamic
()
.unwrap
();
if
image
.size
()
.x
!=
width
||
image
.size
()
.y
!=
height
{
dynamic_image
=
dynamic_image
.resize_to_fill
(
width
as
u32
,
height
as
u32
,
FilterType
::
Triangle
,
);
}
for
(
i
,
(
_
,
_
,
rgba
))
in
dynamic_image
.pixels
()
.enumerate
()
{
if
let
Some
(
p
)
=
pixels
.get_mut
(
i
*
4
..
(
i
+
1
)
*
4
)
{
p
[
0
]
=
rgba
[
0
];
p
[
1
]
=
rgba
[
1
];
p
[
2
]
=
rgba
[
2
];
p
[
3
]
=
rgba
[
3
];
}
}
}
}
else
{
...
...
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