Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
pfff_visual: support for layer display at macrolevel!
Browse files Browse the repository at this point in the history
  • Loading branch information
pad committed Nov 1, 2010
1 parent 3c37503 commit fd6f37e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 25 deletions.
2 changes: 1 addition & 1 deletion main_sgrep.ml
Expand Up @@ -105,7 +105,7 @@ let gen_layer ~root file =
let lines = Common.uniq lines in
(file, { Layer_code.
micro_level = (lines +> List.map (fun l -> l, "m"));
macro_level = [];
macro_level = if null lines then [] else ["m", 1.];
})
);
}
Expand Down
29 changes: 29 additions & 0 deletions visual/draw_macrolevel.ml
Expand Up @@ -55,6 +55,7 @@ let draw_treemap_rectangle2 ~cr ?(color=None) ?(alpha=1.) rect =
Cairo.line_to cr r.q.x r.p.y;
Cairo.line_to cr r.q.x r.q.y;
Cairo.line_to cr r.p.x r.q.y;

Cairo.fill cr;
()

Expand All @@ -64,6 +65,34 @@ let draw_treemap_rectangle ~cr ?color ?alpha a =
(*e: draw_treemap_rectangle() *)


(*****************************************************************************)
(* Layers macrolevel *)
(*****************************************************************************)

let draw_trect_using_layers ~cr layers_with_index rect =
let _r = rect.T.tr_rect in

let is_file = not rect.T.tr_is_node in
let color = if is_file then "white" else "black" in

draw_treemap_rectangle ~cr ~color:(Some color) rect;

if is_file then begin
let file = rect.T.tr_label in

let color_info =
try Hashtbl.find layers_with_index.Layer_code.macro_index file
with Not_found -> []
in
(* TODO what to draw ? a splitted rectangle ?
* For now the last win ...
*)
color_info +> List.iter (fun (float, color) ->
draw_treemap_rectangle ~cr ~color:(Some color) rect;
);
end


(*****************************************************************************)
(* File Summary *)
(*****************************************************************************)
Expand Down
6 changes: 6 additions & 0 deletions visual/draw_macrolevel.mli
Expand Up @@ -9,4 +9,10 @@ val draw_treemap_rectangle :
unit
(*e: draw_treemap_rectangle sig *)

val draw_trect_using_layers:
cr:Cairo.t ->
Layer_code.layers_with_index ->
Treemap.treemap_rectangle ->
unit

(*e: draw_macrolevel.mli *)
14 changes: 9 additions & 5 deletions visual/draw_microlevel.ml
Expand Up @@ -238,11 +238,15 @@ let draw_content2 ~cr ~layout ~context ~file rect =
| n when n <= 10 -> 0.6
| _ -> 0.3
in
Draw_macrolevel.draw_treemap_rectangle ~cr ~color:(Some "DarkSlateGray")
~alpha rect;
(* draw a thin rectangle with aspect color *)
CairoH.draw_rectangle_bis ~cr ~color:(rect.T.tr_color)
~line_width:(font_size / 2.) rect.T.tr_rect;
(* unset when used when debugging the layering display *)
if Hashtbl.length context.layers_microlevel = 0 || true
then begin
Draw_macrolevel.draw_treemap_rectangle ~cr ~color:(Some "DarkSlateGray")
~alpha rect;
(* draw a thin rectangle with aspect color *)
CairoH.draw_rectangle_bis ~cr ~color:(rect.T.tr_color)
~line_width:(font_size / 2.) rect.T.tr_rect;
end;
end;

(* highlighting layers (and grep-like queries) *)
Expand Down
40 changes: 21 additions & 19 deletions visual/view_mainmap.ml
Expand Up @@ -30,7 +30,7 @@ module CairoH = Cairo_helpers

module Flag = Flag_visual
open Model2
module Controller = Controller2
module Ctl = Controller2

(*****************************************************************************)
(* Prelude *)
Expand Down Expand Up @@ -119,25 +119,23 @@ let lazy_paint ~user_rect dw () =
pr2 "Lazy Paint";
let start = Unix.gettimeofday () in
while Unix.gettimeofday () - start < 0.3 do
match !Controller.current_rects_to_draw with
match !Ctl.current_rects_to_draw with
| [] -> ()
| x::xs ->
Controller.current_rects_to_draw := xs;
Ctl.current_rects_to_draw := xs;
pr2 (spf "Drawing: %s" (x.T.tr_label));
paint_content_maybe_rect ~user_rect dw x;
done;
!Controller._refresh_da ();
if !Controller.current_rects_to_draw = []
!Ctl._refresh_da ();
if !Ctl.current_rects_to_draw = []
then false
else true


let paint2 dw =

!Controller.paint_content_maybe_refresher +> Common.do_option (fun x ->
GMain.Idle.remove x;
);
Controller.current_rects_to_draw := [];
!Ctl.paint_content_maybe_refresher +> Common.do_option GMain.Idle.remove;
Ctl.current_rects_to_draw := [];

let cr = Cairo_lablgtk.create dw.pm#pixmap in
dw.pm#rectangle
Expand All @@ -155,21 +153,25 @@ let paint2 dw =
let rects = dw.treemap in
let nb_rects = dw.nb_rects in

(* phase 1, draw the rectangles *)
rects +> List.iter (Draw_macrolevel.draw_treemap_rectangle ~cr);
(if null dw.layers.Layer_code.layers
then
(* phase 1, draw the rectangles *)
rects +> List.iter (Draw_macrolevel.draw_treemap_rectangle ~cr)
else
rects +> List.iter (Draw_macrolevel.draw_trect_using_layers ~cr dw.layers)
);

(* phase 2, draw the labels, if have enough space *)
rects +> List.iter
(Draw_labels.draw_treemap_rectangle_label_maybe
~cr ~zoom:dw.zoom ~color:None);
rects +> List.iter (Draw_labels.draw_treemap_rectangle_label_maybe
~cr ~zoom:dw.zoom ~color:None);

(* phase 3, draw the content, if have enough space *)
if not dw.in_dragging && nb_rects < !Flag.threshold_nb_rects_draw_content
(* draw_content_maybe calls nblines which is quite expensive so
* want to limit it *)
then begin
Controller.current_rects_to_draw := rects;
Controller.paint_content_maybe_refresher :=
Ctl.current_rects_to_draw := rects;
Ctl.paint_content_maybe_refresher :=
Some (Gui.gmain_idle_add ~prio:3000 (lazy_paint ~user_rect dw));
end;

Expand Down Expand Up @@ -242,7 +244,7 @@ let key_pressed (da, da2) dw_ref ev =
true

| k when k = K._b ->
!Controller._go_back dw_ref;
!Ctl._go_back dw_ref;
true

| k when k = K._e ->
Expand Down Expand Up @@ -355,7 +357,7 @@ let button_action da dw_ref ev =
r_opt +> Common.do_option (fun (r, _, _r_englobing) ->
let path = r.T.tr_label in

!Controller._go_dirs_or_file dw_ref [path];
!Ctl._go_dirs_or_file dw_ref [path];
);
true
| _ -> false
Expand All @@ -379,7 +381,7 @@ let button_action da dw_ref ev =

r_opt +> Common.do_option (fun (_r, _, r_englobing) ->
let path = r_englobing.T.tr_label in
!Controller._go_dirs_or_file dw_ref [path];
!Ctl._go_dirs_or_file dw_ref [path];
);

true
Expand Down

0 comments on commit fd6f37e

Please sign in to comment.