sdl2-wallpaper

Crates.iosdl2-wallpaper
lib.rssdl2-wallpaper
version0.1.0
sourcesrc
created_at2023-07-20 05:40:31.110216
updated_at2023-07-20 05:40:31.110216
descriptionUse SDL to actively render to the desktop background
homepage
repositoryhttps://github.com/Spencer1O1/sdl2-wallpaper/
max_upload_size
id920973
size6,877
Spencer Smith (Spencer1O1)

documentation

README

sdl2_wallpaper

Use SDL2 to actively render to the desktop background. Use simple functions to get access to either the desktop background window, or a Rust-SDL2 canvas bound to it. Then, you can render whatever you want for ultimate customization.

Note

As of now, only Windows is supported. sdl2_wallpaper has only been developed with Windows 10, so that is the only OS that is expected to work. I also haven't seen if the MinGW SDL2 development libraries work with this yet. For setting up Rust-SDL2 I've used both cargo-vcpkg and the "bundled" feature successfully.

Installation

Prerequisite: Make sure you have Rust-SDL2 installed, and that it is working.

There are two easy installation options for sdl2_wallpaper.

  1. Use Cargo from the terminal
cargo add sdl2_wallpaper
  1. Add the dependency to your Cargo.toml file
[dependencies]
sdl2_wallpaper = "0.1.0"

Usage

(Based on the Rust-SDL2 example)

use sdl2::pixels::Color;
use sdl2::event::Event;
use std::time::Duration;

fn main() {
    let sdl = sdl2::init().unwrap();
    let video_subsystem = sdl.video().unwrap();
    
    // The only real difference here from the Rust-SDL2 example is
    // how we get the window/canvas.

    let mut canvas = sdl2_wallpaper::get_canvas(video_subsystem).unwrap();
    
    // If you'd rather get the window and then build the canvas from that:

    // let window = sdl2_wallpaper::get_window(video_subsystem).unwrap();
    // [maybe do something to your window]
    // let mut canvas = window.into_canvas().build().unwrap()

    canvas.set_draw_color(Color::RGB(0, 64, 255));
    canvas.clear();
    canvas.present();

    let mut event_pump = sdl.event_pump().unwrap();
    let mut i = 0;
    'running: loop {
        i = (i + 1) % 255;
        canvas.set_draw_color(Color::RGB(i, 64, 255 - i));
        canvas.clear();
        for event in event_pump.poll_iter() {
            match event {
                Event::Quit { .. } => break 'running,
                _ => {}
            }
        }
        canvas.present();
        std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
    } 
}

Contributing

Pull requests are very welcome. Please feel free to make this more rusty! For major updates, like supporting another OS, please open an issue first to discuss what you want, as well as a course of action.

Since this is a new package, there is so much to add to this and I'm sure we'll find bugs. Let's work together!

License

MIT OR Apache-2.0

Commit count: 5

cargo fmt