Commit 6221bcf9 authored by Scott Lembcke's avatar Scott Lembcke Committed by Scott Lembcke

Added an id for 'flags'.

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

        * ext/ids.c: Added an id for 'flags'.

        * ext/structures.c: Added Gimp::Parasite.

        * ext/rbgimp.h: Added the new id and structure.

        * Added plug-ins/test.rb.

        * gimp-lib/gimp.rb: Moved the PDB module to gimp-lib/pdb.rb. Added some
          utility methods to the Gimp::Rgb class. Added Gimp.Color as a shortcut
          for Gimp::Rgb.new. Added the Gimp::Shelf module for persistent
          storage.

        * ext/*: Removed // style comments.

	* Deleted enumconvert.rb: Didn't realize that this was still lurking
	  around. Should never have been submited to CVS in the first place.

	* ext/conversion.c: Removed an accidental debugging change for
	  converting strings. Began adding functions for parasite conversion.
parent 24286346
2006-07-01 Scott Lembcke <lemb0029@gnome.org>
* ext/ids.c: Added an id for 'flags'.
* ext/structures.c: Added Gimp::Parasite.
* ext/rbgimp.h: Added the new id and structure.
* Added plug-ins/test.rb.
* gimp-lib/gimp.rb: Moved the PDB module to gimp-lib/pdb.rb. Added some
utility methods to the Gimp::Rgb class. Added Gimp.Color as a shortcut
for Gimp::Rgb.new. Added the Gimp::Shelf module for persistent
storage.
* ext/*: Removed // style comments.
* Deleted enumconvert.rb: Didn't realize that this was still lurking
around. Should never have been submited to CVS in the first place.
* ext/conversion.c: Removed an accidental debugging change for
converting strings. Began adding functions for parasite conversion.
2006-07-01 Kevin Cozens <kcozens@cvs.gnome.org>
* ChangeLog: Minor reformatting to stop long lines from wrapping.
......
......@@ -49,7 +49,6 @@ EXTRA_DIST = \
intltool-extract.in \
intltool-merge.in \
intltool-update.in \
enumconvert.rb \
notes.txt \
todo.txt
......
template = "\trb_define_const(mGimptest, \"%s\", INT2NUM(%s));"
strs = readlines
strs.collect! do|str|
str = str.chomp[0..-1].delete(',').split.first
sprintf(template, str[5..-1], str)
end
puts strs.join("\n")
puts
\ No newline at end of file
......@@ -103,7 +103,7 @@ GimpParam2rb (const GimpParam *params,
break;
case GIMP_PDB_STRING:
data = rb_str_new2("the");//param->data.d_string);
data = rb_str_new2(param->data.d_string);
break;
case GIMP_PDB_INT32ARRAY:
......@@ -121,9 +121,9 @@ GimpParam2rb (const GimpParam *params,
data = GimpRGB2rb(&param->data.d_color);
break;
// case GIMP_PDB_REGION:
// data = GimpParamRegion2rb(&param->data.d_region);
// break;
/* case GIMP_PDB_REGION:
data = GimpParamRegion2rb(&param->data.d_region);
break;*/
case GIMP_PDB_DISPLAY:
data = INT2NUM(param->data.d_display);
......@@ -137,9 +137,9 @@ GimpParam2rb (const GimpParam *params,
data = INT2NUM(param->data.d_layer);
break;
// case GIMP_PDB_LAYER_MASK:
// data = INT2NUM(param.data.d_layer_mask);
// break;
/* case GIMP_PDB_LAYER_MASK:
data = INT2NUM(param.data.d_layer_mask);
break;*/
case GIMP_PDB_CHANNEL:
data = INT2NUM(param->data.d_channel);
......@@ -161,18 +161,18 @@ GimpParam2rb (const GimpParam *params,
data = INT2NUM(param->data.d_vectors);
break;
// case GIMP_PDB_UNIT:
// data = INT2NUM(param.data.d_unit);
// break;
/* case GIMP_PDB_UNIT:
data = INT2NUM(param.data.d_unit);
break;*/
case GIMP_PDB_PARASITE:
rb_warn("Parasite type is not implemented, sending nil");
data = Qnil;
break;
// case GIMP_PDB_TATTOO:
// data = INT2NUM(param.data.d_tattoo);
// break;
/* case GIMP_PDB_TATTOO:
data = INT2NUM(param.data.d_tattoo);
break;*/
case GIMP_PDB_STATUS:
data = INT2NUM(param->data.d_status);
......@@ -239,7 +239,7 @@ rb2gimp_array(GimpPDBArgType type,
}
}
static gint8 *
static guint8 *
str2gint8(VALUE rb_str)
{
Check_Type(rb_str, T_STRING);
......@@ -322,9 +322,9 @@ rb2GimpParam (VALUE rbparam)
result.data.d_layer = (gint32)NUM2INT(rbdata);
break;
// case GIMP_PDB_LAYER_MASK:
// result.data.d_layer_mask = (gint32)NUM2INT(rbdata);
// break;
/* case GIMP_PDB_LAYER_MASK:
result.data.d_layer_mask = (gint32)NUM2INT(rbdata);
break;*/
case GIMP_PDB_CHANNEL:
result.data.d_channel = (gint32)NUM2INT(rbdata);
......@@ -346,18 +346,18 @@ rb2GimpParam (VALUE rbparam)
result.data.d_vectors = (gint32)NUM2INT(rbdata);
break;
// case GIMP_PDB_UNIT:
// result.data.d_unit = (gint32)NUM2INT(rbdata);
// break;
/* case GIMP_PDB_UNIT:
result.data.d_unit = (gint32)NUM2INT(rbdata);
break;*/
case GIMP_PDB_PARASITE:
rb_warn("Parasite type is not implemented.");
rb_notimplement();
break;
// case GIMP_PDB_TATTOO:
// result.data.d_tattoo = (gint32)NUM2INT(rbdata);
// break;
/* case GIMP_PDB_TATTOO:
result.data.d_tattoo = (gint32)NUM2INT(rbdata);
break;*/
case GIMP_PDB_STATUS:
result.data.d_status = (GimpPDBStatusType)NUM2INT(rbdata);
......@@ -423,7 +423,7 @@ rb2GimpParamDef (VALUE param)
result.name = StringValuePtr(name);
result.description = StringValuePtr(dscr);
// printf("%d %s %s\n", result.type, result.name, result.description); //PRINTF
/* printf("%d %s %s\n", result.type, result.name, result.description); //PRINTF*/
return result;
}
......@@ -530,3 +530,31 @@ rb2GimpCMYK (VALUE color)
{
return *rb2GimpCMYKPtr(color);
}
VALUE
GimpParasite2rb(GimpParasite leech)
{
volatile VALUE name = rb_str_new2(leech.name);
volatile VALUE flags = UINT2NUM(leech.flags);
volatile VALUE data = rb_str_new(leech.data, leech.size);
return rb_struct_new(sGimpParasite, name, flags, data, NULL);
}
GimpParasite
rb2GimpParasite(VALUE leech)
{
GimpParasite result;
VALUE rbname = rb_struct_aref(leech, id_name);
result.name = g_strdup(StringValuePtr(rbname));
result.flags = NUM2UINT(rb_struct_aref(leech, id_flags));
/*result.size = */
/*TODO finish me*/
return result;
}
\ No newline at end of file
......@@ -12,10 +12,7 @@ ID id_quit_proc;
ID id_query_proc;
ID id_run_proc;
ID id_call;
ID id_x;
ID id_y;
ID id_width;
ID id_height;
ID id_flags;
void
Init_ids (void)
......@@ -29,4 +26,5 @@ Init_ids (void)
id_query_proc = rb_intern("query_proc");
id_run_proc = rb_intern("run_proc");
id_call = rb_intern("call");
id_flags = rb_intern("flags");
}
//modules
/* modules */
extern VALUE mGimp;
//classes
/* classes */
extern VALUE cGimpRGB;
extern VALUE cGimpHSV;
extern VALUE cGimpCMYK;
//structures (structures.c)
/* structures (structures.c) */
extern VALUE sGimpParamDef;
extern VALUE sGimpParam;
extern VALUE sGimpPlugInInfo;
extern VALUE sGimpParasite;
//Type conversion functions (conversion.c)
/* Type conversion functions (conversion.c) */
VALUE GimpParam2rb (const GimpParam *param,
int index);
VALUE GimpParams2rb (const GimpParam *params,
......@@ -43,7 +44,7 @@ GimpCMYK *rb2GimpCMYKPtr (VALUE color);
GimpCMYK rb2GimpCMYK (VALUE color);
//ids (ids.c)
/* ids (ids.c) */
extern ID id_type;
extern ID id_name;
extern ID id_dscr;
......@@ -53,9 +54,10 @@ extern ID id_quit_proc;
extern ID id_query_proc;
extern ID id_run_proc;
extern ID id_call;
extern ID id_flags;
//Init functions
/* Init functions */
void Init_structures(void);
void Init_ids(void);
......
......@@ -561,10 +561,10 @@ rb_GIMP_RGB_INTENSITY (VALUE self,
return rb_float_new(result);
}
//GIMP_TYPE_RGB
//GIMP_TYPE_PARAM_RGB
//gimp_param_spec_rgb
//GIMP_VALUE_HOLDS_RGB
/*GIMP_TYPE_RGB
GIMP_TYPE_PARAM_RGB
gimp_param_spec_rgb
GIMP_VALUE_HOLDS_RGB*/
void Init_gimpcolorrgb(void)
{
......
......@@ -17,7 +17,7 @@ static VALUE
rb_gimp_rgb_to_hsl (VALUE self,
VALUE rgb)
{
//TODO
/*TODO*/
rb_notimplement();
return Qnil;
}
......@@ -49,7 +49,7 @@ static VALUE
rb_gimp_hsl_to_rgb (VALUE self,
VALUE hsl)
{
//TODO
/*TODO*/
rb_notimplement();
return Qnil;
}
......@@ -59,7 +59,7 @@ rb_gimp_cmyk_to_rgb (VALUE self,
VALUE cmyk)
{
GimpRGB rgb;
gimp_cmyk_to_rgb(rb2GimpCMYKPtr(cmyk), &rgb);//rb2CMYKPtr(cmyk), &rgb);
gimp_cmyk_to_rgb(rb2GimpCMYKPtr(cmyk), &rgb);
return GimpRGB2rb(&rgb);
}
......
......@@ -16,7 +16,6 @@ typedef struct {
static void
params_wrapper_free (ParamsWrapper *ptr)
{
// printf("freeing params.\n");
gimp_destroy_params(ptr->array, ptr->count);
}
......@@ -153,7 +152,7 @@ run_callback (const gchar *name,
if(err)
handle_exception("An exception has occured while running the run callback");
//FIXME rb2GimpParams can raise exceptions
/*FIXME rb2GimpParams can raise exceptions*/
*return_vals = rb2GimpParams(rbreturn_vals, n_return_vals);
gc_register_params(*return_vals, *n_return_vals);
}
......@@ -174,7 +173,7 @@ rb_gimp_main (VALUE self,
plug_in_callbacks[2] = rb_struct_aref(plug_in_info, ID2SYM(id_query_proc));
plug_in_callbacks[3] = rb_struct_aref(plug_in_info, ID2SYM(id_run_proc));
//build argv
/*build argv*/
VALUE *arr = RARRAY(rb_argv)->ptr;
gint argc = RARRAY(rb_argv)->len;
gchar *argv[argc + 1];
......@@ -186,7 +185,7 @@ rb_gimp_main (VALUE self,
for(i=0; i<argc; i++)
argv[i + 1] = StringValuePtr(arr[i]);
//call gimp_main
/*call gimp_main*/
gint rstatus = gimp_main(&PLUG_IN_INFO, argc + 1, argv);
return INT2NUM(rstatus);
}
......@@ -234,14 +233,14 @@ rb_gimp_install_procedure (VALUE self,
paramdefs,
returndefs);
free(paramdefs);
free(returndefs);
free(paramdefs); /*FIXME: should be using gimp_destroy_paramdefs here.*/
free(returndefs); /*make sure that I'm not giving away Ruby ptrs in my paramdefs*/
return Qnil;
}
//TODO temp proc functions
// Are they needed?
/*TODO temp proc functions
Are they needed?*/
static VALUE
rb_gimp_run_procedure (VALUE self,
......@@ -262,7 +261,6 @@ rb_gimp_run_procedure (VALUE self,
rbreturn_vals = GimpParams2rb(return_vals, n_return_vals);
gimp_destroy_params(params, n_params);
// gc_register_params(return_vals, n_return_vals);
gimp_destroy_params(return_vals, n_return_vals);
return rbreturn_vals;
......
......@@ -3,8 +3,9 @@
#include "rbgimp.h"
//TODO a lot of these function might as well be used from the pdb.
// figure out which ones.
/*TODO a lot of these function might as well be used from the pdb.
figure out which ones.*/
static VALUE
rb_gimp_procedural_db_temp_name (VALUE self)
{
......@@ -73,7 +74,7 @@ static VALUE
rb_gimp_procedural_db_get_data (VALUE self,
VALUE identifier)
{
//TODO
/*TODO*/
rb_notimplement();
return Qnil;
}
......@@ -83,7 +84,7 @@ VALUE rb_gimp_procedural_db_set_data(VALUE self,
VALUE identifier,
VALUE data)
{
//TODO
/*TODO*/
rb_notimplement();
return Qnil;
}
......
......@@ -7,6 +7,7 @@ VALUE sGimpParamDef;
VALUE sGimpParam;
VALUE sGimpPlugInInfo;
VALUE sGimpParamRegion;
VALUE sGimpParasite;
void Init_structures(void)
{
......@@ -22,4 +23,10 @@ void Init_structures(void)
"query_proc",
"run_proc", NULL);
rb_define_const(mGimp, "PlugInInfo", sGimpPlugInInfo);
sGimpParasite = rb_struct_define("GimpParasite",
"name",
"flags",
"data", NULL);
rb_define_const(mGimp, "Parasite", sGimpParasite);
}
......@@ -5,6 +5,7 @@ gimplibdir = $(GIMP_LIBDIR)/ruby
gimplib = \
gimp_oo.rb \
gimp.rb \
pdb.rb \
rubyfu.rb
gimplib_SCRIPTS = $(gimplib)
......
require 'gimpext'
require 'pdb'
#require 'gimp_oo.rb'
require 'rubyfu.rb'
......@@ -97,130 +98,55 @@ module Gimp
"GimpParam #{EnumNames::PDBArgType[type]}: #{data}"
end
end
end
module PDB
class PDBException < Exception
end
class NoProcedure < PDBException
def initialize(name)
@name = name
end
def message
"'#@name' is not in the PDB"
end
end
class CallError < PDBException
def initialize(name, status)
@name = name
@status = Gimp::EnumNames::PDBStatusType[status]
class Rgb
def _dump(level)
Marshal.dump([r, g, b, a])
end
def message
"#@name exited with status #@status"
end
end
class Procedure
attr_reader :name, :blurb, :help, :author, :copyright, :date
attr_reader :proc_type, :args, :return_vals
@@cache = {}
def self.new(name)
@@cache[name] = super unless @@cache.include? name
return @@cache[name]
def _load(str)
new(*Marshal.load(str))
end
def initialize(name)
@name = name
def eql?(other)
return false unless other.is_a? Rgb
values = Gimp.procedural_db_proc_info(name)
raise(NoProcedure, name) unless values
@blurb = values.shift
@help = values.shift
@author = values.shift
@copyright = values.shift
@date = values.shift
@proc_type = values.shift
@args = values.shift
@return_vals = values.shift
end
def convert_args(args, paramdefs)
arglen = args.length
prmlen = paramdefs.length
unless arglen == prmlen
message = "Wrong number of parameters. #{arglen} for #{prmlen}"
raise(ArgumentError, message)
unless r == other.r
g == other.g
b == other.b
a == other.a
return false
end
begin
result = args.zip(paramdefs).collect do|arg, paramdef|
paramdef.check(arg)
Gimp::Param.new(paramdef.type, arg)
end
rescue TypeError
message = "Bad Argument: #{$!.message}"
raise(TypeError, message)
end
return true
end
def call(*args)
params = convert_args(args, @args)
values = Gimp.run_procedure(@name, params)
status = values.shift.data
raise CallError.new(@name, status) unless status == Gimp::PDB_SUCCESS
return *values.collect{|param| param.data}
end
alias_method :==, :eql?
def to_s
[
" name: #@name",
" blurb: #@blurb",
" help: #@help",
" author: #@author",
" copyright: #@copyright",
" date: #@date",
" proc_type: #@proc_type",
" args: #@args",
"return_vals: #@return_vals",
].join("\n")
end
def to_proc
lambda do|*args|
self.call(*args)
end
"RGB<r=#{r}, g=#{g}, b=#{b}, a=#{a}>"
end
end
def self.[](name)
Procedure.new(name)
def Color(*args)
Rgb.new(*args)
end
module Access
def self.method_missing(sym, *args)
# begin
Procedure.new(sym.to_s.gsub('_', '-')).call(*args)
# rescue NoProcedure
# warn $!.message
# super
# end
module Shelf
def self.[](key)
begin
bytes, data = PDB.gimp_procedural_db_get_data(key)
return Marshal.load(data)
rescue PDB::CallError
return nil
end
end
def method_missing(sym, *args)
Access.method_missing(sym, *args)
def self.[]=(key, obj)
puts 'setting'
data = Marshal.dump(obj)
bytes = data.length
PDB.gimp_procedural_db_set_data(key, bytes, data)
end
end
def self.method_missing(sym, *args)
Access.method_missing(sym, *args)
end
end
module PDB
class PDBException < Exception
end
class NoProcedure < PDBException
def initialize(name)
@name = name
end
def message
"'#@name' is not in the PDB"
end
end
class CallError < PDBException
def initialize(name, status)
@name = name
@status = Gimp::EnumNames::PDBStatusType[status]
end
def message
"#@name exited with status #@status"
end
end
class Procedure
attr_reader :name, :blurb, :help, :author, :copyright, :date
attr_reader :proc_type, :args, :return_vals
@@cache = {}
def self.new(name)
@@cache[name] = super unless @@cache.include? name
return @@cache[name]
end
def initialize(name)
@name = name
values = Gimp.procedural_db_proc_info(name)
raise(NoProcedure, name) unless values
@blurb = values.shift
@help = values.shift
@author = values.shift
@copyright = values.shift
@date = values.shift
@proc_type = values.shift
@args = values.shift
@return_vals = values.shift
end
def convert_args(args, paramdefs)
arglen = args.length
prmlen = paramdefs.length
unless arglen == prmlen
message = "Wrong number of parameters. #{arglen} for #{prmlen}"
raise(ArgumentError, message)
end
begin
result = args.zip(paramdefs).collect do|arg, paramdef|
paramdef.check(arg)
Gimp::Param.new(paramdef.type, arg)
end
rescue TypeError
message = "Bad Argument: #{$!.message}"
raise(TypeError, message)
end
end
def call(*args)
params = convert_args(args, @args)
values = Gimp.run_procedure(@name, params)
status = values.shift.data
raise CallError.new(@name, status) unless status == Gimp::PDB_SUCCESS
return *values.collect{|param| param.data}
end
def to_s
[
" name: #@name",
" blurb: #@blurb",
" help: #@help",
" author: #@author",
" copyright: #@copyright",
" date: #@date",
" proc_type: #@proc_type",
" args: #@args",
"return_vals: #@return_vals",
].join("\n")
end
def to_proc
lambda do|*args|
self.call(*args)
end
end
end
def self.[](name)
Procedure.new(name)
end
module Access
def method_missing(sym, *args)
begin
Procedure.new(sym.to_s.gsub('_', '-')).call(*args)
rescue NoProcedure
warn $!.message
super
end
end
module_function :method_missing
end
extend Access
end
......@@ -4,10 +4,11 @@ pluginexecdir = $(GIMP_PLUGINDIR)
scripts = \
coolmetal-logo.rb \
sphere.rb
sphere.rb \
hello.rb \
test.rb
test_scripts = \
hello.rb
test_scripts =
if RUBYGIMP_UNSTABLE
......
GimpParam arrays aren't freed right away, but only registered with the GC. This could be a problem for very long sessions.
Track down the corrupted string issue that occurs in coolmetal-logo.rb.
Parasite argument types.
Make sure GINT8 params are handled correctly as uints.
Finish OO Gimp types.
Make sure all the useful parts of the C API were wrapped.
The color code has turned out to be sub-par, lots of room for improvment.
Region parameters seem to have issues in GIMP. Should they just be removed?
Signal handlers might need to be backed up. (see how the old one did this. Is it still necessary?)
Remove // style comments.
Read up on Gtk before working on any UI stuff.
Signal handlers might need to be backed up. (see how the old one did this. Is it still necessary?)
Console mode.
Read up on Gtk before working on any UI stuff.
\ No newline at end of file
Localization issues?
\ 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