Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a transparent color for the transparent example #3048

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> Result<(), impl std::error::Error> {
..
} => control_flow.set_exit(),
Event::RedrawRequested(_) => {
fill::fill_window(&window);
fill::fill_window_with_color(&window, 0x33181818);
}
_ => (),
}
Expand Down
14 changes: 9 additions & 5 deletions examples/util/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

use winit::window::Window;

#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub(super) fn fill_window(window: &Window) {
// Fill a buffer with a solid color.
const DARK_GRAY: u32 = 0xFF181818;
fill_window_with_color(window, DARK_GRAY);
}

#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub(super) fn fill_window_with_color(window: &Window, color: u32) {
use softbuffer::{Context, Surface};
use std::cell::RefCell;
use std::collections::HashMap;
Expand Down Expand Up @@ -59,8 +65,6 @@ pub(super) fn fill_window(window: &Window) {
.get_or_insert_with(|| GraphicsContext::new(window))
.surface(window);

// Fill a buffer with a solid color.
const DARK_GRAY: u32 = 0xFF181818;
let size = window.inner_size();

surface
Expand All @@ -73,14 +77,14 @@ pub(super) fn fill_window(window: &Window) {
let mut buffer = surface
.buffer_mut()
.expect("Failed to get the softbuffer buffer");
buffer.fill(DARK_GRAY);
buffer.fill(color);
buffer
.present()
.expect("Failed to present the softbuffer buffer");
})
}

#[cfg(any(target_os = "android", target_os = "ios"))]
pub(super) fn fill_window(_window: &Window) {
pub(super) fn fill_window_with_color(_window: &Window, _color: u32) {
// No-op on mobile platforms.
}