Commit 21c35246 authored by Scott Lembcke's avatar Scott Lembcke Committed by Scott Lembcke

Added ext/rbgimpdialog.c.

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

        * ext/Makefile.am: Added ext/rbgimpdialog.c.

        * Added ext/rbgimpdialog.c.

        * ext/conversion.c: Removed some stray blank lines.

        * ext/rbgimp.c: Added a call to initialize the dialog code.

        * ext/rbgimp.h: Added the dialog init function prototype.

        * plug-ins/test.rb: Added a procedure to run the dialog.
parent 0163e625
2006-07-18 Scott Lembcke <lemb0029@gnome.org>
* ext/Makefile.am: Added ext/rbgimpdialog.c.
* Added ext/rbgimpdialog.c.
* ext/conversion.c: Removed some stray blank lines.
* ext/rbgimp.c: Added a call to initialize the dialog code.
* ext/rbgimp.h: Added the dialog init function prototype.
* plug-ins/test.rb: Added a procedure to run the dialog.
2006-07-10 Scott Lembcke <lemb0029@gnome.org>
* ext/*.c: Style fixes. Swapped stdlib functions for glib ones.
......
......@@ -22,6 +22,7 @@ gimpext_la_SOURCES = \
rbgimpcolorrgb.c \
rbgimpcolorspace.c \
rbgimpconstants.c \
rbgimpdialog.c \
rbgimp.h \
rbgimpmain.c \
rbgimpproceduraldb.c \
......
......@@ -442,8 +442,6 @@ rb2GimpParamDefs (VALUE rbparamdefs,
int i;
for(i=0; i<num; i++)
gimpparamdefs[i] = rb2GimpParamDef(arr[i]);
*count = (gint)num;
return gimpparamdefs;
......
......@@ -141,4 +141,5 @@ Init_gimpext (void)
Init_gimpcolorhsv();
Init_gimpcolorcmyk();
Init_gimpcolorspace();
Init_rubyfudialog();
}
......@@ -72,3 +72,5 @@ void Init_gimpcolorrgb(void);
void Init_gimpcolorhsv(void);
void Init_gimpcolorcmyk(void);
void Init_gimpcolorspace(void);
void Init_rubyfudialog(void);
\ No newline at end of file
#include <ruby.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include "rbgimp.h"
typedef struct
{
GtkWidget *widget;
VALUE (*result)(GtkWidget *widget);
} ValuePair;
VALUE
get_text (GtkWidget *widget)
{
GtkEntry *entry = GTK_ENTRY(widget);
return rb_str_new2(gtk_entry_get_text(entry));
}
VALUE
get_int (GtkWidget *widget)
{
GtkSpinButton *spinner = GTK_SPIN_BUTTON(widget);
return INT2NUM(gtk_spin_button_get_value_as_int(spinner));
}
VALUE
get_float (GtkWidget *widget)
{
GtkSpinButton *spinner = GTK_SPIN_BUTTON(widget);
return rb_float_new(gtk_spin_button_get_value(spinner));
}
VALUE
get_bool (GtkWidget *widget)
{
GtkToggleButton *toggle = GTK_TOGGLE_BUTTON(widget);
return INT2NUM(gtk_toggle_button_get_active(toggle) ? 1 : 0);
}
ValuePair
make_widget (VALUE param)
{
ValuePair pair;
GimpPDBArgType type = NUM2INT(rb_struct_aref(param, ID2SYM(id_type)));
switch(type)
{
case GIMP_PDB_STRING:
pair.widget = gtk_entry_new();
pair.result = &get_text;
break;
default:
case GIMP_PDB_INT32:
pair.widget = gtk_spin_button_new_with_range(-10, 10, 1);
pair.result = &get_text;
break;
}
return pair;
}
GtkWidget *
make_table (VALUE params,
int *num_pairs,
ValuePair **pairs)
{
params = rb_check_array_type(params);
int num = RARRAY(params)->len;
VALUE *ary = RARRAY(params)->ptr;
ValuePair *pair_arr = g_new(ValuePair, num);
GtkWidget *table = gtk_table_new(num, 2, FALSE);
int i;
for (i=0; i<num; i++)
{
VALUE param = ary[i];
if (!rb_obj_is_kind_of(param, sGimpParamDef))
rb_raise(rb_eArgError, "Parameters must be of type Gimp::ParamDef");
VALUE name = rb_struct_aref(param, ID2SYM(id_name));
GtkWidget *label = gtk_label_new(StringValuePtr(name));
gtk_table_attach(GTK_TABLE(table), label,
0, 1, i, i+1,
GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
ValuePair pair = make_widget(param);
pair_arr[i] = pair;
gtk_table_attach(GTK_TABLE(table), pair.widget,
1, 2, i, i+1,
GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
}
gtk_widget_show_all(table);
*num_pairs = num;
*pairs = pair_arr;
return table;
}
VALUE
collect_results (int num_pairs,
ValuePair *pairs)
{
volatile VALUE ary = rb_ary_new();
int i;
for (i=0; i<num_pairs; i++)
{
ValuePair pair = pairs[i];
rb_ary_push(ary, pair.result(pair.widget));
}
return ary;
}
VALUE
show_dialog (VALUE self,
VALUE rbname,
VALUE params)
{
GtkWidget *dialog, *table;
gchar *name = StringValuePtr(rbname);
int num_pairs;
ValuePair *pairs;
gtk_init(NULL, NULL);
dialog = gtk_dialog_new_with_buttons(name, NULL, 0,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
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)
return collect_results(num_pairs, pairs);
return Qnil;
}
void Init_rubyfudialog(void)
{
mRubyFu = rb_define_module("RubyFu");
rb_define_module_function(mRubyFu, "dialog", show_dialog, 2);
}
\ No newline at end of file
......@@ -240,7 +240,7 @@ end
RubyFu.register(
'ruby-fu-test-OO', #procedure name
'Test that the ', #blurb
'Test that the object functionality works', #blurb
nil, #help
nil, #author
nil, #copyright
......@@ -268,4 +268,28 @@ RubyFu.register(
img
end
RubyFu.register(
'ruby-fu-test-dialog', #procedure name
'runs dialog', #blurb
nil, #help
nil, #author
nil, #copyright
nil, #date
'<Toolbox>/Xtns/Languages/Ruby-Fu/Test/dialog', #menupath
nil, #image types
[], #params
[] #results
) do|run_mode|
params = [
Gimp::ParamDef.STRING('a', 'a'),
Gimp::ParamDef.INT32('b', 'b'),
]
result = RubyFu.dialog('billy', params)
Gimp.message result.inspect
nil
end
RubyFu.main
\ No newline at end of file
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