-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspriteflip.scm
69 lines (65 loc) · 2.75 KB
/
spriteflip.scm
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;
; Spriteflip
;
; Flip or rotate regions of an image. Useful for working with sprites.
; The image should be flattened in a single layer.
;
; Copyright 2021 David Farrell
; https://github.com/dnmfarrell/GIMP-Spriteflip
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
(define (script-fu-spriteflip img frameW frameH transID)
(if (and (> frameW 0) (> frameH 0))
(let* ((imgWidth (car (gimp-image-width img)))
(imgHeight (car (gimp-image-height img)))
(baseLayer (car (gimp-image-get-active-layer img))))
(gimp-image-undo-group-start img)
(do ((frameY 0 (+ frameY frameH))) ((>= frameY imgHeight))
(do ((frameX 0 (+ frameX frameW))) ((>= frameX imgWidth))
(script-fu-spriteflip-flip frameX
frameY
frameW
frameH
baseLayer
img transID)))
(gimp-image-merge-visible-layers img CLIP-TO-IMAGE)
(gimp-displays-flush)
(gimp-image-undo-group-end img))
(gimp-message "Frame Width and Height must be higher than 0")))
(define (script-fu-spriteflip-flip x y w h layer img flipID)
(gimp-image-select-rectangle img CHANNEL-OP-REPLACE x y w h)
(gimp-floating-sel-to-layer (car (gimp-selection-float layer 0 0)))
(if (<= flipID 1)
(gimp-item-transform-flip-simple
(car (gimp-image-get-active-layer img)) flipID TRUE 0)
(gimp-item-transform-rotate-simple
(car (gimp-image-get-active-layer img)) (- flipID 2) TRUE 0 0)))
(script-fu-register "script-fu-spriteflip"
"Spriteflip"
"Flips frames on a spritesheet."
"David Farrell"
"copyright 2021 David Farrell"
"March 8, 2021"
"*" ;all img types
SF-IMAGE "Image" -1 ;current image obj
SF-VALUE "Frame Width" ""
SF-VALUE "Frame Height" ""
SF-OPTION "Transformation" '("Flip Horizontal"
"Flip Vertical"
"Rotate 90"
"Rotate 180"
"Rotate 270")
)
(script-fu-menu-register "script-fu-spriteflip"
"<Image>/Tools/Transform Tools")