File: shift.pl

package info (click to toggle)
golly 2.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 9,560 kB
  • ctags: 5,064
  • sloc: cpp: 38,119; python: 3,203; perl: 1,121; makefile: 58; java: 49; sh: 22
file content (44 lines) | stat: -rw-r--r-- 1,369 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Shift current selection by given x y amounts using optional mode.
# Author: Andrew Trevorrow (andrew@trevorrow.com), June 2007.

use strict;

my @selrect = g_getselrect();
g_exit("There is no selection.") if @selrect == 0;

my $s = g_getstring("Enter x y shift amounts and an optional mode\n".
                    "(valid modes are copy/or/xor, default is or):",
                    "0 0 or",
                    "Shift selection");
my ($x, $y, $mode) = split(' ', $s, 3);

# check x and y
g_exit() if $x eq "";
g_exit("Enter x and y amounts separated by a space.") if $y eq "";
g_exit("Bad x value: $x") unless $x =~ /^[+-]?\d+$/;
g_exit("Bad y value: $y") unless $y =~ /^[+-]?\d+$/;

# check optional mode
if ($mode eq "") {
   $mode = "or";
} else {
   $mode = lc($mode);
   $mode = "copy" if $mode eq "c";
   $mode = "or"   if $mode eq "o";
   $mode = "xor"  if $mode eq "x";
   if (not ($mode eq "copy" or $mode eq "or" or $mode eq "xor")) {
      g_exit("Unknown mode: $mode (must be copy/or/xor)");
   }
}

# this method cuts the current selection and pastes it into the
# new position (without changing the current clipboard pattern)
my $selcells = g_getcells(@selrect);
g_clear(0);
$selrect[0] += $x;
$selrect[1] += $y;
g_select(@selrect);
g_clear(0) if $mode eq "copy";
g_putcells($selcells, $x, $y, 1, 0, 0, 1, $mode);

g_fitsel() if !g_visrect(@selrect);