/**
* call-square.c
* An attempt to demonstrate calling mechanisms.
*
* Copyright (c) 2013 Samuel A. Rebelsky. All rights reserved.
*
* This file is part of The Glimmer Guide to GIMP Plugins (aka GGGP).
*
* GGGP 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.
*
* GGGP 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 GGGP. If not, see .
*/
// +---------+---------------------------------------------------------
// | Headers |
// +---------+
#include
#include
#include
// +--------------------------+----------------------------------------
// | Function Predeclarations |
// +--------------------------+
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals);
// +---------+---------------------------------------------------------
// | Helpers |
// +---------+
void
print_gimp_param (FILE *port, GimpParam *param)
{
switch (param->type)
{
case GIMP_PDB_DRAWABLE:
fprintf (port, "", param->data.d_image);
break;
case GIMP_PDB_IMAGE:
fprintf (port, "", param->data.d_image);
break;
case GIMP_PDB_INT32:
fprintf (port, "%d", param->data.d_int32);
break;
case GIMP_PDB_STRING:
fprintf (port, "%s", param->data.d_string);
break;
default:
fprintf (port, "");
} // switch
} // print_gimp_param
void
report_results (FILE *port, char *message, int nresults, GimpParam *results)
{
fprintf (port, "%s: Got %d results.\n", message, nresults);
int i;
for (i = 1; i < nresults; i++)
{
fprintf (port, "%s: [%2d] ", message, i);
print_gimp_param (port, results+i);
fprintf (port, "\n");
} // for
} // report_results
// +-------------+-----------------------------------------------------
// | Boilerplate |
// +-------------+
/**
* The four key functions. This structure *must* be called PLUG_IN_INFO.
*/
GimpPlugInInfo PLUG_IN_INFO =
{
NULL,
NULL,
query,
run
};
/**
* Indicate that we're ready to begin the main part of the code.
*/
MAIN ()
// +-------------------------+-----------------------------------------
// | Standard GIMP Functions |
// +-------------------------+
static void
query (void)
{
// Tell the GIMP about our plugin.
gimp_install_procedure (
"gggp/callsquare", // Name
"Demo function for proc calls", // Blurb
"Show two mechanisms for calling functions", // Help
"Samuel A. Rebelsky", // Author
"Copyright (c) Samuel A. Rebelsky. All rights reserved.",
// Copyright
"2013", // Year
"", // Path
NULL, // Image types
GIMP_PLUGIN, // Type
0, // Number of params
0, // Number of return vals
NULL, // Param descriptions
NULL // Return descriptions
);
} // query
static void
run (const gchar *name,
gint nparams,
const GimpParam *params,
gint *nreturn_vals,
GimpParam **return_vals)
{
// Set up return values
static GimpParam results[1];
results[0].type = GIMP_PDB_STATUS;
results[0].data.d_status = GIMP_PDB_SUCCESS;
*nreturn_vals = 1;
*return_vals = results;
GimpParam *returned;
int nreturned;
// Calling mechanism one
returned = gimp_run_procedure ("gggp-square", &nreturned,
GIMP_PDB_INT32, 5,
GIMP_PDB_END);
report_results (stdout, "First Call", nreturned, returned);
// Calling mechanism two
GimpParam newparams[] = { { GIMP_PDB_INT32, 5 } };
returned = gimp_run_procedure2 ("gggp-square", &nreturned, 1, newparams);
report_results (stdout, "Second Call", nreturned, returned);
// And we're done
} // run