Closed cedlemo closed 5 years ago
@garrigue ,
In gtk3, in order to draw on a GtkDrawingArea
, one have to use the draw signal that is GtkWidget
signal (https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-draw).
I tried to look at the code to see how I could try to add it but I have some question.
Does the gtkBase*
files are related to GtkWidget
?
Could you explain me what are the gtk*.props
and gtk*Props.ml
and how they are used ?
GtkBase is about GtkWidget and a few auxiliary widgets. The .props files are used to generate the gtkProps.ml and ogtkProps.ml files. The syntax is not documented :( Syntax for signals and properties should be clear enough.
@garrigue ,
I have 2 questions:
diff --git a/src/gtkBase.props b/src/gtkBase.props
index 2dc9878..f2d80b5 100644
--- a/src/gtkBase.props
+++ b/src/gtkBase.props
@@ -87,6 +87,7 @@ class Widget abstract : Object {
signal hide
signal map
signal unmap
+ signal draw
signal query_tooltip : x:int y:int kbd:bool GtkTooltip -> bool
signal realize
signal unrealize
It generates in the gtkBaseProps.ml via propcc:
let draw = {name="draw"; classe=`widget; marshaller=marshal_unit}
But when I try to use the signal with:
open GMain
let window = GWindow.window ()
let area = GMisc.drawing_area ~packing:window#add ()
let w = area#misc#realize (); area#misc#window
let redraw () =
Printf.printf "draw\n"
let _ =
window#connect#destroy ~callback:Main.quit;
area#connect#draw ~callback:redraw;
window#show ();
Main.main ()
It seems that the draw signal is not know.
../src/lablgtk2 -localdir drawing.ml
File "./drawing.ml", line 24, characters 2-14:
Error: This expression has type GObj.widget_signals
It has no method draw
Is there another files I should modify to add a signal ?
there are the Cairo types convertion functions. If we can create the same Cairo types, then the OCaml-cairo package should be usable with the draw
event (I guess ...). Have you got any ideas on how / where I can add a CairoContext new type in the propscc
generator and a C Cairo pointer to Cairo type function ?
You can add this method to all widgets, by adding it manually to GObj.misc_signals
.
Note that you also need to edit gObj.mli
.
For cairo, there seems to be 2 bindings, I didn't get any reaction yet. Maybe ask one of the maintainers directly. The problem is that since lablgtk2on3 becomes dependent on ocaml-cairo, the bindings should be done on the lablgtk2on3 side rather than on the ocaml-cairo side.
Once you have converter functions, you can build a Gobject.data_conv
from them, and either add them to the conversions
section of the props
file, or directly to propcc.ml4
.
Hi, I am also interested into bringing back cairo to lablgtk3. Cedlemo, do you have working code to share? Otherwise, I have right now a working implementation, but it is based on Obj.magic to turn a lablgtk3 cairo context into a cairo cairo context.
Chris00, Jacques, what are your preferences? Either
2 is ugly and requires an unneeded gimnics from the coders; 1 introduces an hard dependency (which already exists at the C level btw)
@sacerdot, No I have not been able to make something work. That is really great that you can provide a working implementation.
I have no problem introducing a hard dependency ocaml-cairo. The loss of drawing primitives is a huge gap in lablgtk3 at this point. However it requires cooperation from @Chris00. If you can obtain it, then let’s go for that.
Great. For @Chris00 I operationally suggest to:
Christophe, please let me know if you prefer a different plan or if I can proceed. If I receive the green light I will first do a pull request on lablgtk3 to introduce the depenency over ocam_cairo and move there you cairo2-gtk and cairo2-pango code and only then a pull request to remove those parts from ocaml-cairo.
cairo2
.I have just made a pull request to lablgtk3 according to Christophe wishes. It introduces an hard dependency on cairo2. So far I moved verbatim the code of cairo-pango to the one of lablgtk3. I have not ported cairo-gtk at all since it binds mostly deprecated functions and it is no longer necessary to have working examples. Finally, I have copied and modified examples-{gtk,pango}/* to examples/{cairo,pango1,pango2}.ml
Please, read the changelog of the pull request for further details.
Btw, I have also ported drawing.ml to cairo in order to allow to close this issue if Jacques wants to.
@sacerdot made some comments on the example.
The drawing.ml example fail with:
Furthermore it uses an
GdkDraw
api which is outdated (https://developer.gnome.org/gdk2/stable/gdk2-Drawing-Primitives.html#gdk-draw-point) in favor of Cairo. Does cairo work with lablgtk ?