#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# GIMP plugin to interleave layers from two different images
# (c) Ofnuts 2012-2024
#
#   History:
#
#   v0.0: 2012-06-22: First published version
#   v0.1: 2012-06-22: Don't dup layers at both ends
#   v1.0: 2024-11-24: Port to Gimp3, add some methods
#
#   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 2 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, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# This plugin is dedicated to PowerPoint presentations and their authors.
# Nothing looks more like someone taking notes than someone coding a plugin.

import gi

gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('Gegl', '0.4')
from gi.repository import Gegl
gi.require_version('Babl', '0.1')
from gi.repository import Babl

from gimphelpers import *
import sys

def N_(message): return message
def _(message): return GLib.dgettext(None, message)

methods=Choice('methods',_('Method'),_('How to add the reverse ordered layers'),'swing',
               [
                   Option('swing', _('Swing'),
                          blurb=_('ABCD -> ABCDCB'),value=lambda x: x[1:-1]),
                   Option('symmetry', _('Symmetry'),
                          blurb=_('ABCD -> ABCDDCBA'), value=lambda x: x[:]),
                   Option('mirror', _('Mirror'),
                          blurb=_('ABCD -> ABCDCBA'), value=lambda x: x[:-1]),
               ])

def mirrorLayers(procedure: Gimp.Procedure, run_mode: Gimp.RunMode,
                 image: Gimp.Image, drawables: list[Gimp.Drawable],
                 config: Gimp.ProcedureConfig, data: Any):
    methodName,=getConfigArgs(config,['methods'])
    sourceLayers=methods[methodName](image.get_selected_layers())
    for layer in reversed(sourceLayers):
        mirrorLayer=layer.copy()
        mirrorLayer.set_name('Mirrored '+layer.get_name())
        image.insert_layer(mirrorLayer,None,0)

### Registrations
class Ofn3Mirror(HelpedPlugin):
    procedures=[
        ProcedureDescription(
            'ofn3-mirror-layers',
            '*',
            Gimp.ProcedureSensitivityMask.DRAWABLES,
            mirrorLayers,
            args=[methods],
            menuLabel=_('Mirror layers'),
            menuPath='<Image>/'+_('Image'),
            descShort=_('Makes copies of layers in reverse order'),
            descLong=_('Makes copies of layers in reverse order'),
        ),
    ]
    #domain=getDomain(__file__)
    # icon=getIcon(__file__)
    author='Ofnuts'
    copyright='Ofnuts'
    year='2012-2024'

Gimp.main(Ofn3Mirror.__gtype__, sys.argv)