示例#1
0
        void ParseParameters(GimpParamSet parameters, int num_args, IntPtr argsPtr,
                             params object[] list)
        {
            var paramDef = GetParamDef(num_args, argsPtr);

            int i = parameters.Count;

            foreach (object obj in list)
            {
                Console.WriteLine("ParseParameters: " + paramDef[i].type);
                switch (paramDef[i].type)
                {
                case PDBArgType.Int32:
                    parameters.Add(GimpParam.GetIntParam(obj));
                    break;

                case PDBArgType.Float:
                    parameters.Add(GimpParam.GetFloatParam(obj));
                    break;

                case PDBArgType.String:
                    parameters.Add(GimpParam.GetStringParam(obj));
                    break;

                default:
                    Console.WriteLine("Procedure: Implement this: " +
                                      paramDef[i].type);
                    break;
                }
                i++;
            }
        }
示例#2
0
        public static GimpParam GetStringParam(Object obj)
        {
            var param = new GimpParam()
            {
                type = PDBArgType.String
            };

            param._param.data.d_string = Marshal.StringToHGlobalAuto(obj as string);
            return(param);
        }
示例#3
0
        void FillValue(int i, GimpParam param)
        {
            Type type = this[i].Type;

            switch (param.type)
            {
            case PDBArgType.Int32:
                if (type == typeof(int) || type == typeof(uint))
                {
                    this[i].Value = (Int32)param.data.d_int32;
                }
                else if (type == typeof(bool))
                {
                    this[i].Value = ((Int32)param.data.d_int32 == 0)
              ? false
              : true;
                }
                break;

            case PDBArgType.Float:
                this[i].Value = param.data.d_float;
                break;

            case PDBArgType.Color:
                this[i].Value = new RGB(param.data.d_color);
                break;

            case PDBArgType.Image:
                this[i].Value = new Image((Int32)param.data.d_image);
                break;

            case PDBArgType.String:
                if (type == typeof(string))
                {
                    this[i].Value = Marshal.PtrToStringAuto(param.data.d_string);
                }
                else
                {
                    this[i].Value = Marshaller.FilenamePtrToString
                                        (param.data.d_string);
                }
                break;

            case PDBArgType.Drawable:
                this[i].Value = new Drawable((Int32)param.data.d_drawable);
                break;

            default:
                Console.WriteLine("Fill: parameter " + param.type +
                                  " not supported yet!");
                break;
            }
        }
示例#4
0
        public static GimpParam GetFloatParam(Object obj)
        {
            var param = new GimpParam()
            {
                type = PDBArgType.Float
            };

            if (obj is int)
            {
                param._param.data.d_float = (double)(int)obj;
            }
            else
            {
                param._param.data.d_float = (double)obj;
            }
            return(param);
        }
示例#5
0
        public static GimpParam GetIntParam(Object obj)
        {
            var param = new GimpParam()
            {
                type = PDBArgType.Int32
            };

            if (obj is bool)
            {
                Int32 val = ((bool)obj) ? 1 : 0;
                param._param.data.d_int32 = val;
            }
            else
            {
                param._param.data.d_int32 = (Int32)obj;
            }
            return(param);
        }
示例#6
0
        // Can this be done by a casting overload?
        internal GimpParam GetGimpParam()
        {
            var param = new GimpParam();

              param.type = GetGimpType();

              switch (param.type)
            {
            case PDBArgType.Int32:
              param.data.d_int32 = (Int32) Value;
              break;
            case PDBArgType.Float:
              param.data.d_float = (double) Value;
              break;
            case PDBArgType.String:
              param.data.d_string = Marshal.StringToHGlobalAuto((string) Value);
              break;
            case PDBArgType.Image:
              param.data.d_image = (Value as Image).ID;
              break;
            case PDBArgType.Status:
              param.data.d_status = (PDBStatusType) Value;
              break;
            default:
              Console.WriteLine("GetGimpParam: couldn't create");
              break;
            }

              return param;
        }
 GimpParam GetStringParam(Object obj)
 {
     var param = new GimpParam() {type = PDBArgType.String};
       param.data.d_string = Marshal.StringToHGlobalAuto(obj as string);
       return param;
 }
        int ParseParameters(int i, GimpParam[] _params, int num_args, IntPtr argsPtr, 
			params object[] list)
        {
            var paramDef = GetParamDef(num_args, argsPtr);

              foreach (object obj in list)
            {
              switch (paramDef[i].type)
            {
            case PDBArgType.Int32:
              _params[i] = GetIntParam(obj);
              break;
            case PDBArgType.Float:
              _params[i] = GetFloatParam(obj);
              break;
            case PDBArgType.String:
              _params[i] = GetStringParam(obj);
              break;
            default:
              Console.WriteLine("Procedure: Implement this: " +
                paramDef[i].type);
              break;
            }
              i++;
            }
              return i;
        }
 GimpParam GetIntParam(Object obj)
 {
     var param = new GimpParam() {type = PDBArgType.Int32};
       if (obj is bool)
     {
       Int32 val = ((bool) obj) ? 1 : 0;
       param.data.d_int32 = val;
     }
       else
     {
       param.data.d_int32 = (Int32) obj;
     }
       return param;
 }
示例#10
0
 GimpParam GetFloatParam(Object obj)
 {
     var param = new GimpParam() {type = PDBArgType.Float};
       if (obj is int)
     {
       param.data.d_float = (double) (int) obj;
     }
       else
     {
       param.data.d_float = (double) obj;
     }
       return param;
 }
示例#11
0
        public void Run(Image image, Drawable drawable, params object[] list)
        {
            PDBProcType proc_type;
              int num_args;
              int num_values;
              IntPtr argsPtr;
              IntPtr return_vals;

              if (gimp_procedural_db_proc_info(Name,
                       out _blurb,
                       out _help,
                       out _author,
                       out _copyright,
                       out _date,
                       out proc_type,
                       out num_args,
                       out num_values,
                       out argsPtr,
                       out return_vals))
            {
              // Get parameter types
              var parameters = new GimpParam[num_args];

              // First 3 parameters are default

              parameters[0].type = PDBArgType.Int32;
              parameters[0].data.d_int32 = (Int32) RunMode.Noninteractive;
              parameters[1].type = PDBArgType.Image;
              parameters[1].data.d_image = image.ID;
              parameters[2].type = PDBArgType.Drawable;
              parameters[2].data.d_drawable = drawable.ID;

              int i = ParseParameters(3, parameters, num_args, argsPtr, list);
              // Todo: destroy argsPtr!

              int n_return_vals;
              gimp_run_procedure2(Name, out n_return_vals, i, parameters);
            }
              else
            {
              Console.WriteLine(Name + " not found!");
            }
        }
示例#12
0
        public List<object> Run(params object[] list)
        {
            PDBProcType proc_type;
              int num_args;
              int num_values;
              IntPtr argsPtr;
              IntPtr return_vals;

              if (gimp_procedural_db_proc_info(Name,
                       out _blurb,
                       out _help,
                       out _author,
                       out _copyright,
                       out _date,
                       out proc_type,
                       out num_args,
                       out num_values,
                       out argsPtr,
                       out return_vals))
            {
              var parameters = new GimpParam[num_args];

              parameters[0].type = PDBArgType.Int32;
              parameters[0].data.d_int32 = (Int32) RunMode.Noninteractive;

              int i = ParseParameters(1, parameters, num_args, argsPtr, list);
              // Todo: destroy argsPtr!

              int n_return_vals;
              IntPtr returnArgsPtr = gimp_run_procedure2(Name, out n_return_vals,
                             i, parameters);

              return ParseReturnArgs(returnArgsPtr, n_return_vals);
            }
              else
            {
              Console.WriteLine(Name + " not found!");
            }
              return null;
        }
示例#13
0
        public static extern IntPtr gimp_run_procedure2(string name,
						    out int n_return_vals,
						    int n_params,
						    GimpParam[] _params);