Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Reclutch and fix resizing #1

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,169 changes: 2,169 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Fredrick Brennan <copypaste@kittens.ph>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
skia-safe = { version = "0.32.1", features = ["gl"] }
reclutch = { git = "https://github.com/jazzfool/reclutch", features = ["skia"] }
imgui-glium-renderer = "0.4.0"
imgui-winit-support = "0.4.0"
imgui = "0.4.0"
Expand Down
54 changes: 38 additions & 16 deletions src/events.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,72 @@
use skia_safe::{Canvas, Matrix};
use crate::state;
use std::cell::RefCell;
use glutin::dpi::PhysicalPosition;
use reclutch::skia::{Canvas, Matrix};
use std::cell::RefCell;

pub fn update_viewport(offset: Option<(f32, f32)>, scale: Option<f32>, v: &RefCell<state::State>, canvas: &mut Canvas ) {
pub fn update_viewport(
offset: Option<(f32, f32)>,
scale: Option<f32>,
v: &RefCell<state::State>,
canvas: &mut Canvas,
) {
let offset = match offset {
None => { v.borrow().offset },
Some(offset) => { offset }
None => v.borrow().offset,
Some(offset) => offset,
};
let scale = match scale {
None => { v.borrow().factor },
Some(scale) => { scale }
None => v.borrow().factor,
Some(scale) => scale,
};
let mut matrix = Matrix::new_identity();
matrix.set_scale_translate((scale, scale), offset);
canvas.set_matrix(&matrix);
v.borrow_mut().factor=scale;
v.borrow_mut().offset=offset;
v.borrow_mut().factor = scale;
v.borrow_mut().offset = offset;
}

pub fn update_mousepos(position: PhysicalPosition<f64>, v: &RefCell<state::State>) -> PhysicalPosition<f64> {
let factor = 1./v.borrow().factor as f64;
pub fn update_mousepos(
position: PhysicalPosition<f64>,
v: &RefCell<state::State>,
) -> PhysicalPosition<f64> {
let factor = 1. / v.borrow().factor as f64;
let uoffset = v.borrow().offset;
let offset = (uoffset.0 as f64, uoffset.1 as f64);
//let mposition = PhysicalPosition::from(((position.x - offset.0) * factor, (position.y - offset.1) * factor));
let mposition = PhysicalPosition::from(((position.x).floor() * factor, (position.y).floor() * factor));
let mposition =
PhysicalPosition::from(((position.x).floor() * factor, (position.y).floor() * factor));
v.borrow_mut().mousepos = mposition;
mposition
}

pub fn mouse_moved_select(position: PhysicalPosition<f64>, v: &RefCell<state::State>, canvas: &mut Canvas) -> bool {
pub fn mouse_moved_select(
position: PhysicalPosition<f64>,
v: &RefCell<state::State>,
canvas: &mut Canvas,
) -> bool {
let mposition = update_mousepos(position, &v);
v.borrow_mut().corner_two = Some(mposition);
v.borrow().show_sel_box
}

pub fn mouse_moved_move(position: PhysicalPosition<f64>, v: &RefCell<state::State>, canvas: &mut Canvas) -> bool {
pub fn mouse_moved_move(
position: PhysicalPosition<f64>,
v: &RefCell<state::State>,
canvas: &mut Canvas,
) -> bool {
let old_mposition = v.borrow().mousepos.clone();
let mut offset = v.borrow().offset;
let mposition = update_mousepos(position, &v);
if !v.borrow().mousedown { return false }
if !v.borrow().mousedown {
return false;
}
offset.0 += (mposition.x - old_mposition.x).floor() as f32;
offset.1 += (mposition.y - old_mposition.y).floor() as f32;
//offset = (mposition.x as f32, mposition.y as f32);
v.borrow_mut().offset = offset;
println!("C: {:?}", (mposition.x - old_mposition.x, mposition.y - old_mposition.y));
println!(
"C: {:?}",
(mposition.x - old_mposition.x, mposition.y - old_mposition.y)
);
println!("O: {:?}", offset);
update_viewport(None, None, &v, canvas);
true
Expand Down
Loading