Commit 9e8cf164 authored by Scott Lembcke's avatar Scott Lembcke Committed by Scott Lembcke

More parameter types added.

2006-07-19  Scott Lembcke <lemb0029@gnome.org>

        * ext/rbgimpdialog.c: More parameter types added.

        * gimp-lib/rubyfu.rb: Added RubyFu::ParamDef subtypes. Connected the
          dialog code to run for interactive mode.

        * plug-ins/test.rb: Added more parameter types to the dialog test
          procedure.
parent 2caf1884
2006-07-19 Scott Lembcke <lemb0029@gnome.org>
* ext/rbgimpdialog.c: More parameter types added.
* gimp-lib/rubyfu.rb: Added RubyFu::ParamDef subtypes. Connected the
dialog code to run for interactive mode.
* plug-ins/test.rb: Added more parameter types to the dialog test
procedure.
2006-07-19 Kevin Cozens <kcozens@cvs.gnome.org>
* ext/rbgimpdialog.c: Added missing declaration for mRubyFu.
......
#include <ruby.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "rbgimp.h"
......@@ -12,58 +14,228 @@ typedef struct
VALUE (*result)(GtkWidget *widget);
} ValuePair;
VALUE
get_text (GtkWidget *widget)
static VALUE
get_entry_text (GtkWidget *widget)
{
GtkEntry *entry = GTK_ENTRY(widget);
return rb_str_new2(gtk_entry_get_text(entry));
}
VALUE
get_int (GtkWidget *widget)
static VALUE
get_spinner_int (GtkWidget *widget)
{
GtkSpinButton *spinner = GTK_SPIN_BUTTON(widget);
return INT2NUM(gtk_spin_button_get_value_as_int(spinner));
}
VALUE
get_float (GtkWidget *widget)
static VALUE
get_spinner_float (GtkWidget *widget)
{
GtkSpinButton *spinner = GTK_SPIN_BUTTON(widget);
return rb_float_new(gtk_spin_button_get_value(spinner));
}
VALUE
static VALUE
get_color (GtkWidget *widget)
{
GimpColorButton *cbutton = GIMP_COLOR_BUTTON(widget);
GimpRGB color;
gimp_color_button_get_color(cbutton, &color);
volatile VALUE rbcolor = GimpRGB2rb(&color);
return rbcolor;
}
static VALUE
get_bool (GtkWidget *widget)
{
GtkToggleButton *toggle = GTK_TOGGLE_BUTTON(widget);
return INT2NUM(gtk_toggle_button_get_active(toggle) ? 1 : 0);
}
ValuePair
static VALUE
get_combo_box_int (GtkWidget *widget)
{
gint value;
gimp_int_combo_box_get_active(GIMP_INT_COMBO_BOX(widget), &value);
return INT2NUM(value);
}
/*static VALUE
get_font_name (GtkWidget *widget)
{
GimpFontSelectButton *button = GIMP_FONT_SELECT_BUTTON(widget);
gchar *str = gimp_font_select_button_get_font_name(button);
return rb_str_new2(str);
}*/
/*TODO remove this function*/
static VALUE
nothing(GtkWidget *widget)
{
return Qnil;
}
static GtkWidget *
make_spinner (gdouble min,
gdouble max,
gdouble step,
VALUE deflt)
{
GtkWidget *spinner;
spinner = gtk_spin_button_new_with_range(min, max, step);
if (deflt != Qnil)
gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinner), NUM2DBL(deflt));
return spinner;
}
static GtkWidget *
make_color_button (VALUE deflt)
{
GtkWidget *cbutton;
GimpRGB *color = g_new(GimpRGB, 1);
if (deflt == Qnil)
gimp_rgba_set(color, 1.0, 1.0, 1.0, 1.0);
else
*color = rb2GimpRGB(deflt);
cbutton = gimp_color_button_new("Ruby-Fu color selection", 60, 15, color,
GIMP_COLOR_AREA_FLAT);
gimp_color_button_set_update(GIMP_COLOR_BUTTON(cbutton), TRUE);
return cbutton;
}
static GtkWidget *
make_int_combo_box (GimpPDBArgType type)
{
switch (type)
{
case GIMP_PDB_IMAGE:
return gimp_image_combo_box_new(NULL, NULL);
case GIMP_PDB_DRAWABLE:
return gimp_drawable_combo_box_new(NULL, NULL);
case GIMP_PDB_CHANNEL:
return gimp_channel_combo_box_new(NULL, NULL);
case GIMP_PDB_LAYER:
return gimp_layer_combo_box_new(NULL, NULL);
default:
return NULL;
}
}
static ValuePair
handle_string_types (GimpPDBArgType type,
VALUE deflt,
VALUE param)
{
ValuePair pair;
char *defstr;
if (deflt == Qnil)
defstr = "";
else
defstr = StringValuePtr(deflt);
VALUE subtype = rb_iv_get(param, "@subtype");
if (subtype == Qnil)
{
pair.widget = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(pair.widget), defstr);
pair.result = &get_entry_text;
}
ID subtypeid = SYM2ID(subtype);
if (subtypeid == rb_intern("font"))
{
/* pair.widget = gimp_font_select_button_new('Ruby-Fu font selection', defstr);
pair.result = &get_font_name;*/
}
else if (subtypeid == rb_intern("file"))
{
}
else if (subtypeid == rb_intern("palette"))
{
}
else if (subtypeid == rb_intern("gradient"))
{
}
else if (subtypeid == rb_intern("pattern"))
{
}
else if (subtypeid == rb_intern("brush"))
{
}
return pair;
}
static ValuePair
make_widget (VALUE param)
{
ValuePair pair;
GimpPDBArgType type = NUM2INT(rb_struct_aref(param, ID2SYM(id_type)));
switch(type)
VALUE deflt = rb_iv_get(param, "@default");
switch (type)
{
case GIMP_PDB_INT32:
pair.widget = make_spinner(-2147483640, 2147483640, 1, deflt);
pair.result = &get_spinner_int;
break;
case GIMP_PDB_INT16:
pair.widget = make_spinner(-32768, 32767, 1, deflt);
pair.result = &get_spinner_int;
break;
case GIMP_PDB_INT8:
pair.widget = make_spinner(0, 255, 1, deflt);
pair.result = &get_spinner_int;
break;
case GIMP_PDB_FLOAT:
pair.widget = make_spinner(-G_MAXDOUBLE, G_MAXDOUBLE, 0.1, deflt);
pair.result = &get_spinner_float;
break;
case GIMP_PDB_STRING:
pair.widget = gtk_entry_new();
pair.result = &get_text;
pair = handle_string_types(type, deflt, param);
break;
case GIMP_PDB_COLOR:
pair.widget = make_color_button(deflt);
pair.result = &get_color;
break;
case GIMP_PDB_IMAGE:
case GIMP_PDB_DRAWABLE:
case GIMP_PDB_CHANNEL:
case GIMP_PDB_LAYER:
pair.widget = make_int_combo_box(type);
if (deflt != Qnil)
gimp_int_combo_box_set_active(GIMP_INT_COMBO_BOX(pair.widget),
NUM2INT(deflt));
pair.result = &get_combo_box_int;
break;
default:
case GIMP_PDB_INT32:
pair.widget = gtk_spin_button_new_with_range(-10, 10, 1);
pair.result = &get_text;
pair.widget = gtk_label_new("Unimplemented");
pair.result = &nothing;
break;
}
return pair;
}
GtkWidget *
static GtkWidget *
make_table (VALUE params,
int *num_pairs,
ValuePair **pairs)
......@@ -103,7 +275,7 @@ make_table (VALUE params,
return table;
}
VALUE
static VALUE
collect_results (int num_pairs,
ValuePair *pairs)
{
......@@ -119,7 +291,7 @@ collect_results (int num_pairs,
return ary;
}
VALUE
static VALUE
show_dialog (VALUE self,
VALUE rbname,
VALUE params)
......@@ -131,17 +303,24 @@ show_dialog (VALUE self,
ValuePair *pairs;
gtk_init(NULL, NULL);
gimp_ui_init ("ruby-fu", TRUE);
dialog = gtk_dialog_new_with_buttons(name, NULL, 0,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
dialog = gimp_dialog_new(name, "ruby-fu",
NULL, 0,
gimp_standard_help_func, "FIXME",
/*GIMP_STOCK_RESET, RESPONSE_RESET,*/
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
table = make_table(params, &num_pairs, &pairs);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table, TRUE, TRUE, 0);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
if (gimp_dialog_run(GIMP_DIALOG(dialog)) == GTK_RESPONSE_OK)
return collect_results(num_pairs, pairs);
return Qnil;
......@@ -149,6 +328,6 @@ show_dialog (VALUE self,
void Init_rubyfudialog(void)
{
mRubyFu = rb_define_module("RubyFu");
VALUE mRubyFu = rb_define_module("RubyFu");
rb_define_module_function(mRubyFu, "dialog", show_dialog, 2);
}
......@@ -6,7 +6,7 @@ module RubyFu
end
class ParamDef < Gimp::ParamDef
attr_reader :default
attr_reader :default, :subtype
def self.method_missing(sym, *args)
nargs = args.length
......@@ -21,6 +21,42 @@ module RubyFu
return super
end
end
def self.FONT(*args)
value = STRING(*args)
value.instance_variable_set(:@subtype, :font)
return value
end
def self.FILE(*args)
value = STRING(*args)
value.instance_variable_set(:@subtype, :file)
return value
end
def self.PALETTE(*args)
value = STRING(*args)
value.instance_variable_set(:@subtype, :palette)
return value
end
def self.GRADIENT(*args)
value = STRING(*args)
value.instance_variable_set(:@subtype, :gradient)
return value
end
def self.PATTERN(*args)
value = STRING(*args)
value.instance_variable_set(:@subtype, :pattern)
return value
end
def self.BRUSH(*args)
value = STRING(*args)
value.instance_variable_set(:@subtype, :brush)
return value
end
end
class Procedure
......@@ -94,10 +130,7 @@ module RubyFu
end
def run_interactive(args)
#use default values for now
#TODO (much later) create an input dialog.
warn "Interactive mode not implemented, sending default params."
args += default_args
args += RubyFu.dialog(@name, @params)
values = @function.call(*args)
end
......
......@@ -277,17 +277,22 @@ RubyFu.register(
nil, #date
'<Toolbox>/Xtns/Languages/Ruby-Fu/Test/dialog', #menupath
nil, #image types
[], #params
[
RubyFu::ParamDef.INT32('INT32', '', 32),
RubyFu::ParamDef.INT16('INT16', '', 16),
RubyFu::ParamDef.INT8('INT8', '', 8),
RubyFu::ParamDef.FLOAT('FLOAT', '', 123.4),
RubyFu::ParamDef.STRING('STRING', '', 'string'),
RubyFu::ParamDef.COLOR('COLOR', '', Gimp::Rgb.new(1.0, 0.0, 0.0, 0.0)),
RubyFu::ParamDef.IMAGE('IMAGE', ''),
RubyFu::ParamDef.DRAWABLE('DRAWABLE', ''),
RubyFu::ParamDef.CHANNEL('CHANNEL', ''),
RubyFu::ParamDef.LAYER('LAYER', ''),
], #params
[] #results
) do|run_mode|
params = [
Gimp::ParamDef.STRING('a', 'a'),
Gimp::ParamDef.INT32('b', 'b'),
]
result = RubyFu.dialog('billy', params)
) do|run_mode, *params|
Gimp.message result.inspect
Gimp.message params.inspect
nil
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment