From d11117683fe9136d73b7ce6b3d7b368bc8ea5072 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 27 Mar 2009 15:37:24 +0000 Subject: [PATCH] Keep 'current' mouseover package. --- rpmdepsize.ml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/rpmdepsize.ml b/rpmdepsize.ml index 9570da6..28e9f33 100644 --- a/rpmdepsize.ml +++ b/rpmdepsize.ml @@ -385,6 +385,12 @@ let open_window pkgstr = window#set_geometry_hints ~min_size:(80,80) (da :> GObj.widget); + (* Force a repaint of the drawing area. *) + let drawing_area_repaint () = + debug "drawing_area_repaint\n%!"; + GtkBase.Widget.queue_draw da#as_widget + in + (* Pango contexts used to draw large and small text. *) let pango_large_context = da#misc#create_pango_context in pango_large_context#set_font_description (Pango.Font.from_string "Sans 12"); @@ -436,8 +442,7 @@ let open_window pkgstr = (* Update the window title. *) window#set_title (pkgstr ^ " - " ^ base_title); - (* Force a repaint of the drawing area. *) - GtkBase.Widget.queue_draw da#as_widget; + drawing_area_repaint () ) in @@ -482,6 +487,24 @@ let open_window pkgstr = let tooltips = ref None in + (* If we are moused-over a particular package, then this is != None. *) + let current = ref None in + let set_current new_current = + let old_current = !current in + current := new_current; + (* Because this structure contains loops, we can't use + * structural comparisons like: = <> compare. + *) + let do_repaint = + match old_current, new_current with + | None, Some _ -> true + | Some _, None -> true + | Some { pkg = { nevra = n1 } }, Some { pkg = { nevra = n2 } } -> + n1 <> n2 + | _ -> false in + if do_repaint then drawing_area_repaint () + in + (* To track tooltips, the 'repaint' function records the location of * each box (ie. package) in the drawing area in this private data * structure, and the 'motion' function looks them up in order to @@ -751,8 +774,12 @@ Tot: %.1f%% %s" pkg.name (match get_locn x y with | None -> + set_current None; kill_tooltip () | Some (colour, pkg, total, increm) -> + (* Update 'current' which points to the currently moused package. *) + set_current (Some (StringMap.find pkg.nevra depsmap)); + (* The only way to make the tooltip follow the mouse is to * kill the whole tooltips object and recreate it each time ... *) -- 1.8.3.1