RE: [Java-gnome-developer] GnomeCanvasPoints
Brought to you by:
afcowie
From: Jeffrey M. <Jef...@Br...> - 2001-08-29 17:10:38
|
You are correct in your thoughts that double* is represented as an array of doubles. As I worked my way through the widgets there probably was a place where gtk or gnome was passing a pointer to an array of doubles and so I made that type. Your are also correct in that the gnome function gnome_color_picker_get_d does expect pointers to a double. The method for the GnomeColorPicker as generated will not work. There are several ways to remedy this problem. You could create a new type in the JNIProps file of "Double" and use that as you suggested below. This approach would seem to move away for the common usage of the Java. Another approach would be to manually write the methods like the following: double getGreen(); double getRed(); etc... This approach is in the JavaBean fashion and would be easier for developers coming from a Java background. In the implementation for each of these methods you would call the gnome_color_picker_get_d method but would only return the requested value. This is more work than having the generator create the code for us but in the end makes the bindings more user friendly. -Jeff > > Thanks for the quick reply. > I started my attemp at implementing the GnomeCanvas* methods/functions > but I have a couple questions. > First: > I started by studying the src/gnome.defs file and saw that in cases > where the gnome C api stated things such as: > > void gnome_color_picker_get_d (GnomeColorPicker *cp, > gdouble *r, > gdouble *g, > gdouble *b, > gdouble *a); > > There were corresponding function definitions in src/gnome.defs like: > > (define-func gnome_color_picker_get_d > none > ((GnomeColorPicker cp) > (double* r) > (double* g) > (double* b) > (double* a))) > > and the src/tools/JNIProps.txt file the double*.javaType > definition is: > > double*.javaType: double[] > double*.nativeType: jdoubleArray > double*.nativeUnwrap: \ > gdouble *$TO = \ > . > . > . > > This leads me to believe that double* is converted to an array of > doubles, but I thought the in C when the statement "gdouble *r" ment a > pointer to a thing that is of type gdouble. I realize that's > the values > to this function will also hold the results, but to my understanding > there not arrays being passed in (at least not in the C api). > Now as I > understand it in Java things like int, double, etc... are not real > Objects so they are passed by value rather than by reference therefore > they will not to hold the return values. So I was wondering > if instead > of the corresponding arguments in Java for methods/functions like this > shouldn't be: > > void getD(Double r, Double g, Double b, Double a) > > where "Double r, Double g,..." are the Object types of these value > intstead of: > > void getD(double[] r, double[] g, double[] b, double[] a) > > where they are arrays of the simple variable types. (Are > they arrays to > turn them into Objects so that they can be passed by value > and hence get > the return value?) > > Let me know if I'm completely off base here, and point me to > the proper > documentation if so. The next thing is (much simpler question), > assuming I'm wrong about the above stuff, all I need to do for the > GnomeCavas* methods/functions is something like this in the > src/gnome.defs file: > > (define-func gnome_canvas_get_scroll_region > none > ((GnomeCanvas canvas) > (double* x1) > (double* y1) > (double* x2) > (double* y2))) > > where the C api looks like: > > void gnome_canvas_get_scroll_region (GnomeCanvas *canvas, > double *x1, > double *y1, > double *x2, > double *y2); > |