| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- extern crate piston_window;
- use clap;
- use clap::{App, Arg, SubCommand};
- use piston_window::*;
- // use opengl_graphics::{ GlGraphics, OpenGL };
- // use graphics::{ Context, Graphics };
- fn main() {
- let matches = App::new("Oculante")
- .arg(
- Arg::with_name("INPUT")
- .help("Display this image")
- .required(true)
- .index(1),
- )
- .get_matches();
- let img = matches.value_of("INPUT").unwrap();
- let opengl = OpenGL::V3_2;
- let mut window: PistonWindow = WindowSettings::new("Oculante", [300, 300])
- .exit_on_esc(true)
- .graphics_api(opengl)
- .build()
- .unwrap();
- // let ref mut gl = GlGraphics::new(opengl);
- match Texture::from_path(
- &mut window.create_texture_context(),
- &img,
- Flip::None,
- &TextureSettings::new(),
- ) {
- Ok(texture) => {
- window.set_lazy(true);
- let mut events = Events::new(EventSettings::new().lazy(true));
- let mut offset = (100.0,0.0);
- while let Some(e) = events.next(&mut window) {
- if let Some(Button::Mouse(button)) = e.press_args() {
- println!("Pressed mouse button '{:?}'", button);
- }
-
- e.mouse_scroll(|d| {
- });
- e.mouse_cursor(|d| {
- println!("Relative mouse moved '{} {}'", d[0], d[1]);
- // offset.0 = d[0];
- // offset.1 = d[1];
- // println!("Scrolled mouse '{}, {}'", d[0], d[1]);
- println!("offset {:?}", offset);
-
- });
- e.resize(|args| {
- println!("Resized '{}, {}'", args.window_size[0], args.window_size[1])
- });
-
- if let Some(args) = e.render_args() {
- window.draw_2d(&e, |c, gfx, _| {
- clear([0.3; 4], gfx);
- // c.trans(111.0,1.0);
- let transform = c.transform.trans(offset.0, offset.1);
- image(&texture, transform, gfx);
- });
- }
- }
- // while let Some(e) = window.next() {
- // let mut offset = (0.0, 0.0);
- // e.mouse_cursor(|d| {
- // offset.0 = d[0];
- // offset.1 = d[1];
- // // image(&texture, transform, gfx);
- // // println!("Relative mouse moved '{} {}'", d[0], d[1])
- // window.draw_2d(&e, |c, gfx, _| {
- // clear([0.3; 4], gfx);
- // // c.trans(111.0,1.0);
- // let transform = c.transform.trans(offset.0, offset.1);
- // image(&texture, transform, gfx);
- // });
- // }
- // );
- // // offset = (100.0, 0.0);
- // println!("Offset '{} {}'", offset.0, offset.1);
- // if let Some(Button::Mouse(button)) = e.press_args() {
- // println!("Pressed mouse button '{:?}'", button);
- // }
- // }
- }
- Err(e) => println!("Could not create texture. {}", e),
- }
- }
|