GnoCanvas.text slow?

Kenichi Asai <[email protected]> Mon, 22 Sep 2014 17:30:41 +0900
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Message-ID <[email protected]>
--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Dear Lablgtk experts,

Attached is a simple program that displays a matrix of numbers after
pressing a key.  When I run this program, it seems it takes some time
(a few seconds) to display the numbers after a key is pressed.  If
I instead display rectangles (as commented out in the program), they
appear instantly after a key is pressed.  (I also tried an image which
was also instant.)

Is displaying texts somewhat slower than other images?  Or am I doing
something wrong?  (I hope I am doing wrong and want to know how to
make it faster.)

- MacOSX 10.9
- XQuartz-2.7.6
- OCaml 4.01.0 (via opam)
- gtk2 2.24.24 + x11 (from macports)
- libgnomecanvas 2.30.3_5 (from macports)
- lablgtk 2.16.0 (via opam)

To compile the attached program:

ocamlfind ocamlc -package lablgtk2,lablgtk2.gnomecanvas -c board.ml
ocamlfind ocamlc -package lablgtk2,lablgtk2.gnomecanvas -linkpkg -o borad board.cmo

or if you have OCamlMakefile, use the following Makefile and make:

-----
SOURCES = board.ml
PACKS = lablgtk2 lablgtk2.gnomecanvas
RESULT = board
OCAMLMAKEFILE = OCamlMakefile
include $(OCAMLMAKEFILE)
-----

Thank you in advance.

Sincerely,

-- 
Kenichi Asai

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="board.ml"

let width = 500
let height = 500

let rec draw_board i j root =
  if i < 9 then
    if j < 9 then begin
      ignore (GnoCanvas.text ~props:[`FILL_COLOR "BLACK";
				     `SIZE_POINTS (float_of_int 24);
				     `TEXT (string_of_int ((i + j) mod 10));
				     `X (float_of_int (i * 50 + 30));
				     `Y (float_of_int (j * 50 + 30))]
			     root);
(*    ignore (GnoCanvas.rect ~props:[`FILL_COLOR "BLACK";
				     `X1 (float_of_int (i * 50 + 30));
				     `Y1 (float_of_int (j * 50 + 30));
				     `X2 (float_of_int (i * 50 + 50));
				     `Y2 (float_of_int (j * 50 + 50))]
			     root); *)
      draw_board i (j + 1) root
    end else draw_board (i + 1) 0 root
  else ()

let locale = GtkMain.Main.init ()

let window = GWindow.window ~border_width:0
			    ~show:true
			    ~resizable:false
			    ~width:width
			    ~height:height
			    ()

let canvas = GnoCanvas.canvas ~aa:true ~width:width ~height:height ()

let _ =
  ignore (GnoCanvas.rect ~props:[`FILL_COLOR "WHITE";
				 `X1 10.0;
				 `Y1 10.0;
				 `X2 50.0;
				 `Y2 50.0]
			 canvas#root);
  canvas#set_pixels_per_unit 1.0;
  canvas#set_scroll_region ~x1:0. ~y1:0.
			   ~x2:(float_of_int width)
			   ~y2:(float_of_int height);
  window#add canvas#coerce;
  window#show ();

  window#event#add [`BUTTON_PRESS; `BUTTON_RELEASE; `KEY_PRESS; `KEY_RELEASE];

  let keypressed ev =
    ignore (window#remove window#child);
    draw_board 0 0 canvas#root;
    window#add canvas#coerce;
    window#show ();
    true
  in

  ignore (window#event#connect#key_press ~callback:keypressed);

  GMain.Main.main ()

--envbJBWh7q8WU6mo
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Lablgtk-list mailing list
[email protected]
https://lists.ocamlcore.org/cgi-bin/listinfo/lablgtk-list

--envbJBWh7q8WU6mo--