main.rs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. extern crate piston_window;
  2. use clap;
  3. use clap::{App, Arg, SubCommand};
  4. use piston_window::*;
  5. // use opengl_graphics::{ GlGraphics, OpenGL };
  6. // use graphics::{ Context, Graphics };
  7. fn main() {
  8. let matches = App::new("Oculante")
  9. .arg(
  10. Arg::with_name("INPUT")
  11. .help("Display this image")
  12. .required(true)
  13. .index(1),
  14. )
  15. .get_matches();
  16. let img = matches.value_of("INPUT").unwrap();
  17. let opengl = OpenGL::V3_2;
  18. let mut window: PistonWindow = WindowSettings::new("Oculante", [300, 300])
  19. .exit_on_esc(true)
  20. .graphics_api(opengl)
  21. .build()
  22. .unwrap();
  23. // let ref mut gl = GlGraphics::new(opengl);
  24. match Texture::from_path(
  25. &mut window.create_texture_context(),
  26. &img,
  27. Flip::None,
  28. &TextureSettings::new(),
  29. ) {
  30. Ok(texture) => {
  31. window.set_lazy(true);
  32. let mut events = Events::new(EventSettings::new().lazy(true));
  33. let mut offset = (100.0,0.0);
  34. while let Some(e) = events.next(&mut window) {
  35. if let Some(Button::Mouse(button)) = e.press_args() {
  36. println!("Pressed mouse button '{:?}'", button);
  37. }
  38. e.mouse_scroll(|d| {
  39. });
  40. e.mouse_cursor(|d| {
  41. println!("Relative mouse moved '{} {}'", d[0], d[1]);
  42. // offset.0 = d[0];
  43. // offset.1 = d[1];
  44. // println!("Scrolled mouse '{}, {}'", d[0], d[1]);
  45. println!("offset {:?}", offset);
  46. });
  47. e.resize(|args| {
  48. println!("Resized '{}, {}'", args.window_size[0], args.window_size[1])
  49. });
  50. if let Some(args) = e.render_args() {
  51. window.draw_2d(&e, |c, gfx, _| {
  52. clear([0.3; 4], gfx);
  53. // c.trans(111.0,1.0);
  54. let transform = c.transform.trans(offset.0, offset.1);
  55. image(&texture, transform, gfx);
  56. });
  57. }
  58. }
  59. // while let Some(e) = window.next() {
  60. // let mut offset = (0.0, 0.0);
  61. // e.mouse_cursor(|d| {
  62. // offset.0 = d[0];
  63. // offset.1 = d[1];
  64. // // image(&texture, transform, gfx);
  65. // // println!("Relative mouse moved '{} {}'", d[0], d[1])
  66. // window.draw_2d(&e, |c, gfx, _| {
  67. // clear([0.3; 4], gfx);
  68. // // c.trans(111.0,1.0);
  69. // let transform = c.transform.trans(offset.0, offset.1);
  70. // image(&texture, transform, gfx);
  71. // });
  72. // }
  73. // );
  74. // // offset = (100.0, 0.0);
  75. // println!("Offset '{} {}'", offset.0, offset.1);
  76. // if let Some(Button::Mouse(button)) = e.press_args() {
  77. // println!("Pressed mouse button '{:?}'", button);
  78. // }
  79. // }
  80. }
  81. Err(e) => println!("Could not create texture. {}", e),
  82. }
  83. }