
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.11.0"
winit_input_helper_temp = "0.14.2"
Code
You can use scenes using run_scenes
:
fn main() -> Result<()> {
let window_prefs = WindowPreferences::new("com", "example", "app")?;
let options = Options::default();
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(())
}
#[derive(Clone, Debug, PartialEq)]
enum SceneName {
Example,
}
#[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(&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(())
}
impl System for Example {
fn update(&mut self, timing: &Timing) {}
fn render(&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
A few retro games
Editor for IndexedImage
Test GUI for USFX