-
Notifications
You must be signed in to change notification settings - Fork 1
feat(chaosymmetry): implemented adjustable multiplier for zooming and panning commands #9
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
Open
ElkeVSant
wants to merge
1
commit into
master
Choose a base branch
from
feat/adjustable-commands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,8 @@ mod symmetry; | |
| use std::fs::File; | ||
| use std::io::BufWriter; | ||
| use std::sync::Arc; | ||
| use std::time::Instant; | ||
| use std::{fs, thread}; | ||
| use std::time::{Duration, Instant, SystemTime}; | ||
| use std::{default, fs, thread}; | ||
|
|
||
| use chrono::Local; | ||
| use clap::Parser; | ||
|
|
@@ -86,14 +86,30 @@ fn main() { | |
| window: None, | ||
| pixels: None, | ||
| render: renderer, | ||
| mult: Mult::default(), | ||
| }; | ||
| event_loop.run_app(&mut app).unwrap(); | ||
| } | ||
|
|
||
| struct Mult { | ||
| value: String, | ||
| valid_since: SystemTime, | ||
| } | ||
|
|
||
| impl Default for Mult { | ||
| fn default() -> Self { | ||
| Mult { | ||
| value: "1".to_string(), | ||
| valid_since: SystemTime::UNIX_EPOCH, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct App { | ||
| window: Option<Arc<Window>>, | ||
| pixels: Option<Pixels<'static>>, | ||
| render: Renderer, | ||
| mult: Mult, | ||
| } | ||
|
|
||
| impl ApplicationHandler for App { | ||
|
|
@@ -179,36 +195,56 @@ impl ApplicationHandler for App { | |
| is_synthetic: false, | ||
| .. | ||
| } => { | ||
| if event.logical_key == Key::Character("+".into()) && event.state.is_pressed() { | ||
| self.render.scale *= ZOOM_FACTOR; | ||
| } else if event.logical_key == Key::Character("-".into()) | ||
| && event.state.is_pressed() | ||
| if event.state.is_pressed() | ||
| // Since "+" requires pressing "Shift", this would otherwise reset the multiplier to "1" before zooming in | ||
| && event.logical_key != Key::Named(winit::keyboard::NamedKey::Shift) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dit kunnen we denk ik nog wel wat refactoren:
En aangezien de |
||
| { | ||
| self.render.scale /= ZOOM_FACTOR; | ||
| } else if event.logical_key == Key::Character("s".into()) | ||
| && event.state.is_pressed() | ||
| { | ||
| let data = self.pixels.as_ref().unwrap().frame(); | ||
| if self.mult.valid_since.elapsed().unwrap() > Duration::from_secs(5) { | ||
| self.mult = Default::default() | ||
| } | ||
| if Key::Character("0".into()) <= event.logical_key | ||
| && event.logical_key <= Key::Character("9".into()) | ||
| { | ||
| if self.mult.valid_since.elapsed().unwrap() <= Duration::from_secs(5) { | ||
| self.mult.value.push_str(&event.text.unwrap().to_string()); | ||
| } else { | ||
| self.mult.value = event.text.unwrap().to_string(); | ||
| } | ||
| self.mult.valid_since = SystemTime::now(); | ||
| } else { | ||
| if event.logical_key == Key::Character("s".into()) { | ||
| let data = self.pixels.as_ref().unwrap().frame(); | ||
|
|
||
| let filename = format!("{}.png", Local::now().to_rfc3339()); | ||
| let path = Path::new(&filename); | ||
| save_png(data, self.render.win_width, path); | ||
| } else if event.logical_key == Key::Named(winit::keyboard::NamedKey::ArrowUp) | ||
| && event.state.is_pressed() | ||
| { | ||
| self.render.position.vertical -= PAN_STEP; | ||
| } else if event.logical_key == Key::Named(winit::keyboard::NamedKey::ArrowDown) | ||
| && event.state.is_pressed() | ||
| { | ||
| self.render.position.vertical += PAN_STEP; | ||
| } else if event.logical_key == Key::Named(winit::keyboard::NamedKey::ArrowRight) | ||
| && event.state.is_pressed() | ||
| { | ||
| self.render.position.horizontal += PAN_STEP; | ||
| } else if event.logical_key == Key::Named(winit::keyboard::NamedKey::ArrowLeft) | ||
| && event.state.is_pressed() | ||
| { | ||
| self.render.position.horizontal -= PAN_STEP; | ||
| let filename = format!("{}.png", Local::now().to_rfc3339()); | ||
| let path = Path::new(&filename); | ||
| save_png(data, self.render.win_width, path); | ||
| } else if event.logical_key == Key::Character("+".into()) { | ||
| self.render.scale *= ZOOM_FACTOR.powf(self.mult.value.parse().unwrap()); | ||
| } else if event.logical_key == Key::Character("-".into()) { | ||
| self.render.scale /= ZOOM_FACTOR.powf(self.mult.value.parse().unwrap()); | ||
| } else if event.logical_key | ||
| == Key::Named(winit::keyboard::NamedKey::ArrowUp) | ||
| { | ||
| self.render.position.vertical -= | ||
| self.mult.value.parse::<isize>().unwrap() * PAN_STEP; | ||
| } else if event.logical_key | ||
| == Key::Named(winit::keyboard::NamedKey::ArrowDown) | ||
| { | ||
| self.render.position.vertical += | ||
| self.mult.value.parse::<isize>().unwrap() * PAN_STEP; | ||
| } else if event.logical_key | ||
| == Key::Named(winit::keyboard::NamedKey::ArrowRight) | ||
| { | ||
| self.render.position.horizontal += | ||
| self.mult.value.parse::<isize>().unwrap() * PAN_STEP; | ||
| } else if event.logical_key | ||
| == Key::Named(winit::keyboard::NamedKey::ArrowLeft) | ||
| { | ||
| self.render.position.horizontal -= | ||
| self.mult.value.parse::<isize>().unwrap() * PAN_STEP; | ||
| } | ||
| self.mult = Default::default(); | ||
| } | ||
| } | ||
| } | ||
| _ => (), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aangezien dit in de
Appzit zou ik de struct iets generieker noemen, bv:Dan kunnen we dat nog voor andere zaken ook gebruiken, terwijl
Multimpliceert dat er maar 1 functie is voor inputs.