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

Implement selection flipping #85

Merged
merged 7 commits into from Jul 13, 2020
Merged

Conversation

@luciusmagn
Copy link
Contributor

@luciusmagn luciusmagn commented Jun 7, 2020

Hi,
this is my humble attempt at implementing the functionality to flip a selection. It was once again a pleasant experience as I really like the structure of the code, but I'm not sure if I'm doing it "idiomatically".

Here is a demonstration of how it looks:
flip.gif
(yea, the colors are screwed because it's a gif, here's a webm for more pleasant viewing -> flip.webm)

This is what I did for these changes:

  1. create a command selection/flip which takes one argument of direction, valid values are h or horizontal and v or vertical.
  2. then I created a ViewOp for flip and went to gl/mod.rs to create an implementation. It's pretty much a yank, which also takes direction as an argument and then flips the pixels accordingly
  3. In session.rs, I added appropriate functions taking yank as example. To allow possibly doing a bunch of flips with a hotkey, I figured the easiest would be doing it in the place of selection, so I did this:
            Command::SelectionFlip(dir) => {
                self.flip_selection(dir);
                // I think its handy to flip in place for now, hence these commands
                // 1., 2. prevent overlap and paste
                // 3.     preserve location so you can flip repeatedly w/ hotkey
                self.command(Command::SelectionErase);
                self.command(Command::SelectionPaste);
                self.command(Command::Mode(Mode::Visual(VisualState::Selecting { dragging: false })));
            }

I'm really unsure if this is the correct way to do it, so I am sorry if I did something wrong, haha 😅

luciusmagn added 3 commits Jun 5, 2020
@cloudhead
Copy link
Owner

@cloudhead cloudhead commented Jun 7, 2020

Awesome, thanks! I think the approach is right overall, with a clever use of the paste buffer 👌

I'm going to comb 👀 through it as soon as I have some time.

@luciusmagn
Copy link
Contributor Author

@luciusmagn luciusmagn commented Jun 8, 2020

thanks! I was considering doing rotations as well, but I'm unsure about changing the dimensions of a selection and have yet to figure out a eloquent solution, but I haven't had the need to rotate anything in my five days of using rx so it's not a priority.

Here are some other ideas that I'm considering trying, though:

  • own file format for rx, which would just be the entire state of the editor dumped into a file, so I can get back to work with the palette loaded in, undo/redo history, layers, views, frames etc. preserved and ready.
  • color replace function for when I'm a dingus (probably allow to replace foreground w/ background or the other way around?)

if you think any of these is a particulary good idea, I can prioritize it, or if you have any tips what to watch out for, it would be awesome :D

@cloudhead
Copy link
Owner

@cloudhead cloudhead commented Jun 8, 2020

  • own file format for rx, which would just be the entire state of the editor dumped into a file, so I can get back to work with the palette loaded in, undo/redo history, layers, views, frames etc. preserved and ready.

Yes, I'd love to have something like this. Actually, part of this is already implemented via the "archive" format (.rxa) which I had to implement for layers functionality.

The other part exists via the .rxrc support, which is loaded when you start rx from a directory with an .rxrc file. Combining those would involve having .rxrc files inside .rxa archives, that would be auto-loaded when you open an archive, plus a way to create a .rxrc from an rx session. Palette writing already exists via p/write, but in the archive case, you could just write the colors to the .rxrc..

@cloudhead
Copy link
Owner

@cloudhead cloudhead commented Jun 8, 2020

  • color replace function for when I'm a dingus (probably allow to replace foreground w/ background or the other way around?)

I also want this. The way I was thinking is to just replace the current bg with the current fg. So you would do:

  1. Pick two colors with the sampler (or via a new pick command?)
  2. Call :colors/replace with no arguments to replace the first color selected (bg) with the second (fg).

The command could also take arguments, in case the color isn't in your session, then you would do :colors/replace <old> <new>

@luciusmagn
Copy link
Contributor Author

@luciusmagn luciusmagn commented Jun 8, 2020

Yes, I'd love to have something like this. Actually, part of this is already implemented via the "archive" format (.rxa) which I had to implement for layers functionality.

The other part exists via the .rxrc support, which is loaded when you start rx from a directory with an .rxrc file. Combining those would involve having .rxrc files inside .rxa archives, that would be auto-loaded when you open an archive, plus a way to create a .rxrc from an rx session. Palette writing already exists via p/write, but in the archive case, you could just write the colors to the .rxrc..

Oh, that's great, I hadn't known about ˙.rxa, I'll look into it! Using them in conjunction with .rxrc` sounds like a good idea, yea!

@luciusmagn
Copy link
Contributor Author

@luciusmagn luciusmagn commented Jun 8, 2020

I also want this. The way I was thinking is to just replace the current bg with the current fg. So you would do:

1. Pick two colors with the sampler (or via a new `pick` command?)

2. Call `:colors/replace` with no arguments to replace the first color selected (bg) with the second (fg).

The command could also take arguments, in case the color isn't in your session, then you would do :colors/replace <old> <new>

Yea, that's pretty much what I thought I'd try. The colorpicking command might a great addition to, especially in reference to #22 .

the :colors/replace <old> <new> could possibly work with not just arbitrary colors but indexes in palette too, although the utility might not be as high unless one can tell a color's number easily (perhaps with a optional index number?)

@cloudhead
Copy link
Owner

@cloudhead cloudhead commented Jun 8, 2020

the :colors/replace <old> <new> could possibly work with not just arbitrary colors but indexes in palette too, although the utility might not be as high unless one can tell a color's number easily (perhaps with a optional index number?)

Note that a semi-hidden feature is that you can use the color sampler while in command mode, and the hex code is added to the command line. This is a lot easier if you're picking from the palette.

@luciusmagn
Copy link
Contributor Author

@luciusmagn luciusmagn commented Jun 8, 2020

Note that a semi-hidden feature is that you can use the color sampler while in command mode, and the hex code is added to the command line. This is a lot easier if you're picking from the palette.

Oh, I didn't know that! Yea, that invalidates my concern completely, haha

src/cmd.rs Show resolved Hide resolved
src/cmd.rs Outdated Show resolved Hide resolved
src/gl/mod.rs Show resolved Hide resolved
src/session.rs Show resolved Hide resolved
src/view.rs Outdated Show resolved Hide resolved
src/session.rs Outdated Show resolved Hide resolved
@cloudhead
Copy link
Owner

@cloudhead cloudhead commented Jun 27, 2020

@luciusmagn do you want to finish this?

@luciusmagn
Copy link
Contributor Author

@luciusmagn luciusmagn commented Jun 30, 2020

Yea, I do. Sorry, I was graduating which kinda temporarily brought my programming endeavors to a screeching halt. I resolved most of the issues already, I will commit them asap!

…tch arm and check if we are selecting
src/session.rs Outdated Show resolved Hide resolved
@cloudhead
Copy link
Owner

@cloudhead cloudhead commented Jul 13, 2020

Thanks for this contribution!

@cloudhead cloudhead merged commit 70017fa into cloudhead:master Jul 13, 2020
1 check passed
1 check passed
Travis CI - Pull Request Build Passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.