#graphics #gamedev #pixels #simple

pixels-graphics-lib

Simple wrapper library around Pixels/Buffer Graphics

45 releases (11 breaking)

0.12.0 Aug 17, 2023
0.11.7 Jun 23, 2023
0.11.3 May 29, 2023
0.9.1 Mar 9, 2023
0.2.0 Dec 31, 2021

#101 in Game dev

Download history 52/week @ 2023-06-03 43/week @ 2023-06-10 107/week @ 2023-06-17 75/week @ 2023-06-24 76/week @ 2023-07-01 23/week @ 2023-07-08 28/week @ 2023-07-15 40/week @ 2023-07-22 9/week @ 2023-07-29 58/week @ 2023-08-05 82/week @ 2023-08-12 15/week @ 2023-08-19 53/week @ 2023-08-26 21/week @ 2023-09-02 113/week @ 2023-09-09 18/week @ 2023-09-16

208 downloads per month
Used in image-wrapper

Custom license

145KB
4K SLoC

Crates.io Documentation

Graphics Lib

This is a simple wrapper around Pixels, designed to be used with Buffer Graphics Lib

Usage

Cargo

In your Cargo.toml file add

pixels-graphics-lib = "0.12.0"
winit_input_helper_temp = "0.14.2" #only needed if you're not using `run()`

Code

You can use scenes using run_scenes:

fn main() -> Result<()> {
    // Window prefs allow the size and position of the window to be saved and restored
    let window_prefs = WindowPreferences::new("com", "example", "app")?;
    // Options contains scaling, UPS, etc
    let options = Options::default();
    // The switcher is how new scenes are created
    let switcher: SceneSwitcher<SceneResult, SceneName> =
        |style, scene_stack, new_scene| match new_scene {
            SceneName::Example => scene_stack.push(ExampleScene::new()),
        };
    let first_scene = ExampleScene::new();
    run_scenes(
        300,
        300,
        "Scenes Example",
        Some(window_prefs),
        switcher,
        first_scene,
        options,
    )?;
    Ok(())
}

// The scene name is the id used so the switcher knows which one to create
#[derive(Clone, Debug, PartialEq)]
enum SceneName {
    Example,
}

// After a scene is finished it can return values to it's parent using scene result
#[derive(Clone, Debug, PartialEq)]
enum SceneResult {}

struct ExampleScene {}

impl ExampleScene {
    pub fn new() -> Box<Self> {
        Box::new(Self {})
    }
}

impl Scene<SceneResult, SceneName> for ExampleScene {
    fn render(&mut self, graphics: &mut Graphics, mouse_xy: Coord) {
        todo!()
    }

    fn update(
        &mut self,
        timing: &Timing,
        mouse_xy: Coord,
        held_keys: &Vec<&VirtualKeyCode>,
    ) -> SceneUpdateResult<SceneResult, SceneName> {
        todo!()
    }

    fn resuming(&mut self, result: Option<SceneResult>) {
        todo!()
    }
}

or a more low level with run

struct Example {}

fn main() -> Result<()> {
    let system = Box::new(Example {});
    run(240, 160, "Example", Box::new(system), Options::default())?;
    Ok(())
}

//Check `src/scenes.rs` for examples of implementing held keys, etc
impl System for Example {
    fn update(&mut self, timing: &Timing) {}
    fn render(&mut self, graphics: &mut Graphics) {}
}

Features

window_prefs

Save and restore window position and size

To use this the impl System must override System::window_prefs()

Projects

Retro Games

A few retro games

ICI Image editor

Editor for IndexedImage

USFX Tester

Test GUI for USFX

Dependencies

~11–53MB
~816K SLoC