From 4d86dae1c0c9255e0ad19bcc5c3648b76c994550 Mon Sep 17 00:00:00 2001 From: sanette Date: Fri, 19 Jul 2019 09:00:08 +0200 Subject: [PATCH] nonlinear slider display and html header --- bogue.opam | 4 +- docs/Embedded.html | 1 + docs/INSTALL-14.04.html | 1 + docs/INSTALL.html | 1 + docs/Principles.html | 1 + dune-project | 2 +- lib/b_long_list.ml | 3 +- lib/b_slider.ml | 94 ++++++++++++++++++++++++---------------- lib/b_theme.ml | 2 +- share/themes.tgz | Bin 2614531 -> 2614531 bytes 10 files changed, 66 insertions(+), 43 deletions(-) diff --git a/bogue.opam b/bogue.opam index 525d2f0..b66c3c7 100644 --- a/bogue.opam +++ b/bogue.opam @@ -11,7 +11,7 @@ bug-reports: "https://github.com/sanette/bogue/issues" homepage: "https://github.com/sanette/bogue" doc: "http://sanette.github.io/bogue/Bogue.html" license: "GPL2" -version: "20190717" +version: "20190719" dev-repo: "git+https://github.com/sanette/bogue.git" synopsis: "GUI library for ocaml, with animations, based on SDL2" description: """ @@ -35,6 +35,6 @@ depends: [ "tsdl-image" {>= "0.2"} "tsdl-ttf" {>= "0.2"} "ocaml" {>= "4.03.0"} - "dune" {build & > "1.10"} + "dune" {"1.10"} "tsdl" {>= "0.9.0"} ] diff --git a/docs/Embedded.html b/docs/Embedded.html index af0f7b8..219c5c7 100644 --- a/docs/Embedded.html +++ b/docs/Embedded.html @@ -3,6 +3,7 @@ + Embedded diff --git a/docs/INSTALL-14.04.html b/docs/INSTALL-14.04.html index 74324a3..4b02fdf 100644 --- a/docs/INSTALL-14.04.html +++ b/docs/INSTALL-14.04.html @@ -3,6 +3,7 @@ + INSTALL-14.04 diff --git a/docs/INSTALL.html b/docs/INSTALL.html index 7399c45..f259aa0 100644 --- a/docs/INSTALL.html +++ b/docs/INSTALL.html @@ -3,6 +3,7 @@ + INSTALL diff --git a/docs/Principles.html b/docs/Principles.html index 2308f29..a5750a1 100644 --- a/docs/Principles.html +++ b/docs/Principles.html @@ -3,6 +3,7 @@ + Principles diff --git a/dune-project b/dune-project index 1fd63a7..16f0dad 100644 --- a/dune-project +++ b/dune-project @@ -1,6 +1,6 @@ (lang dune 1.10) (name bogue) -(version "20190717") +(version "20190719") (generate_opam_files true) (license GPL2) (maintainers "Vu Ngoc San ") diff --git a/lib/b_long_list.ml b/lib/b_long_list.ml index d965231..6fc3df2 100644 --- a/lib/b_long_list.ml +++ b/lib/b_long_list.ml @@ -523,7 +523,8 @@ let create ~w ~h ~length ?(first=0) ~generate ?height_fn then container (* no need for scrollbar *) else begin let clicked_value = ref None (* TODO protect this *) in - let steps = max ll.length h in (* TODO can do better, taking tick size into account *) + let steps = max ll.length h in (* TODO can do better, taking tick size into + account *) let var = Tvar.create ll.offset (* the var for the scrollbar (slider) *) ~t_from: (* from offset we set slider new position *) (fun v -> let o = Avar.get v in diff --git a/lib/b_slider.ml b/lib/b_slider.ml index f7b48fb..abe3ff3 100644 --- a/lib/b_slider.ml +++ b/lib/b_slider.ml @@ -25,7 +25,10 @@ type t = { (* TODO: (int Avar.t) is here to make smoother transitions. not done yet *) cache : int Var.t; (* used to avoid computing too many times the same value *) clicked_value : (int option) Var.t; - offset : int Var.t; (* if offset=0 the tick will place itself with the mouse pointer exactly in its middle point. Offset is used to not move the tick if one clicks at any other position of the tick. *) + offset : int Var.t; (* if offset=0 the tick will place itself with the mouse + pointer exactly in its middle point. Offset is used + to not move the tick if one clicks at any other + position of the tick. *) max: int; step: int; length : int; (* length in pixels *) @@ -114,7 +117,10 @@ let set s value = Tvar.set s.var value; Var.set s.cache value;; -(* this has to be done for each external call to this module *) +(* This has to be done for each external call to this module *) +(* It will update the position of the slider by looking at the s.var. Hence, if + the s.var has a nontrivial transformation, it might be that the value differs + from the value initially computed from the mouse position. See example 34. *) let update_value s = Var.set s.cache (Tvar.get s.var);; @@ -151,10 +157,11 @@ let compute_value s ev = let x0 = Var.get s.room_x + s.length/6 in let y0 = Var.get s.room_y + s.length/6 in if x = x0 then if y>y0 then 3 * s.max / 4 else s.max / 4 - else let a = (float s.max) *. atan (float (y0-y) /. (float (x-x0))) /. pi /. 2. in - let a' = if x > x0 then if y <= y0 then a else a +. (float s.max) - else a +. (float s.max) /. 2. in - round (a') in + else + let a = (float s.max) *. atan (float (y0-y) /. (float (x-x0))) /. pi /. 2. in + let a' = if x > x0 then if y <= y0 then a else a +. (float s.max) + else a +. (float s.max) /. 2. in + round a' in (* printd debug_custom "Mouse (%d,%d), value=%d" x y v; *) v;; @@ -266,6 +273,10 @@ let make_box_blit ~dst ?(shadow=true) ~focus voffset canvas layer box = else [box_blit] let display canvas layer s g = + (* We use y_pos before updating to display a gradient box at the real mouse + position, in case of non-linear (vertical) slider (see example 34)... TODO + do the same for Horizontal sliders. *) + let oldy = y_pos s in update_value s; let scale = Theme.scale_int in let tick_size = scale s.tick_size @@ -287,12 +298,12 @@ let display canvas layer s g = (* set_color renderer (opaque color); *) match s.kind with | Horizontal -> - (* let rect = Sdl.Rect.create ~x:x0 ~y:g.y ~w:thickness ~h:width in *) + (* let rect = Sdl.Rect.create ~x:x0 ~y:g.y ~w:thickness ~h:width in *) (* go (Sdl.render_fill_rect renderer (Some rect)); *) - let box = texture canvas.renderer ~color ~w:tick_size ~h:thickness in - let dst = Sdl.Rect.create ~x:x0 ~y:g.y ~w:tick_size ~h:thickness in - forget_texture box; (* or save ? but be careful color may change *) - make_box_blit ~dst ~shadow ~focus g.voffset canvas layer box + let box = texture canvas.renderer ~color ~w:tick_size ~h:thickness in + let dst = Sdl.Rect.create ~x:x0 ~y:g.y ~w:tick_size ~h:thickness in + forget_texture box; (* or save ? but be careful color may change *) + make_box_blit ~dst ~shadow ~focus g.voffset canvas layer box | HBar -> (* horizontal gradient for the slider (TODO: with button color) *) let box = gradient_texture canvas.renderer ~w:(x0 - g.x + tick_size) @@ -301,37 +312,44 @@ let display canvas layer s g = ~h:thickness in forget_texture box; (* or save ? *) make_box_blit ~dst ~shadow ~focus g.voffset canvas layer box - (* [make_blit ~voffset:g.voffset ~dst canvas layer box] *) + (* [make_blit ~voffset:g.voffset ~dst canvas layer box] *) | Vertical -> - let y0 = scale (y_pos s) in - let box = texture canvas.renderer ~color ~h:tick_size ~w:thickness in - let dst = Sdl.Rect.create ~x:g.x ~y:y0 ~h:tick_size ~w:thickness in - forget_texture box; (* or save ? *) - make_box_blit ~dst ~shadow ~focus g.voffset canvas layer box + let y0 = scale (y_pos s) in + let dy = scale oldy - y0 in + let y = imin y0 (y0 + dy) in + let h = imax tick_size (abs dy) in (* see example 34 .*) + let box = if dy = 0 + then texture canvas.renderer ~color ~h ~w:thickness + else let colors = [lighter color; color] in + let colors = if dy < 0 then colors else List.rev colors in + gradient_texture canvas.renderer ~h ~w:thickness colors in + let dst = Sdl.Rect.create ~x:g.x ~y ~h ~w:thickness in + forget_texture box; (* or save ? *) + make_box_blit ~dst ~shadow ~focus g.voffset canvas layer box | Circular -> - let radius = g.w/2-2 in - let tex = match Var.get s.render with - | Some t -> t - | None -> - let t' = ring_tex renderer ~color:(lighter (transp grey)) - ~radius ~width:thickness (g.w/2) (g.h/2) in - (* j'ai essayé de mettre une taille double puis de réduire avec + let radius = g.w/2-2 in + let tex = match Var.get s.render with + | Some t -> t + | None -> + let t' = ring_tex renderer ~color:(lighter (transp grey)) + ~radius ~width:thickness (g.w/2) (g.h/2) in + (* j'ai essayé de mettre une taille double puis de réduire avec render_copy, mais apparemment ça ne fait pas d'antialiasing *) - (* let t' = convolution ~emboss:false renderer *) - (* (gaussian_blur ~radius:3) 3 t in *) - Var.set s.render (Some t'); t' in - let w',h' = tex_size tex in - let dst = Sdl.Rect.create ~x:(g.x) ~y:(g.y) ~w:w' ~h:h' in - (* go (Sdl.render_copy ~dst renderer tex); *) - let sbox = make_blit ~voffset:g.voffset ~dst canvas layer tex in - (* ring renderer ~bg:(lighter (opaque grey)) ~radius:(w/2-2) + (* let t' = convolution ~emboss:false renderer *) + (* (gaussian_blur ~radius:3) 3 t in *) + Var.set s.render (Some t'); t' in + let w',h' = tex_size tex in + let dst = Sdl.Rect.create ~x:(g.x) ~y:(g.y) ~w:w' ~h:h' in + (* go (Sdl.render_copy ~dst renderer tex); *) + let sbox = make_blit ~voffset:g.voffset ~dst canvas layer tex in + (* ring renderer ~bg:(lighter (opaque grey)) ~radius:(w/2-2) ~width (x+w/2) (y+h/2); *) - let tick = ray_to_layer canvas layer ~voffset:g.voffset ~bg:color - ~thickness:tick_size - ~angle:(360. *. (float (s.max - value s)) /. (float s.max)) ~radius - ~width:thickness (g.x + g.w/2) (g.y + g.h/2) in - forget_texture tick.texture; - [sbox; tick];; + let tick = ray_to_layer canvas layer ~voffset:g.voffset ~bg:color + ~thickness:tick_size + ~angle:(360. *. (float (s.max - value s)) /. (float s.max)) ~radius + ~width:thickness (g.x + g.w/2) (g.y + g.h/2) in + forget_texture tick.texture; + [sbox; tick];; (* this function can be used for the ~t_to function to slow down the slider when diff --git a/lib/b_theme.ml b/lib/b_theme.ml index be466ef..cbd0996 100644 --- a/lib/b_theme.ml +++ b/lib/b_theme.ml @@ -22,7 +22,7 @@ DIR = /home/john/.config/bogue/themes *) -let this_version = "20190717" (* see VERSION file *) +let this_version = "20190719" (* see VERSION file *) let default_vars = [ (* Debug: *) diff --git a/share/themes.tgz b/share/themes.tgz index 61a5d3259582db5e4b219f008bc8cf17eae622ce..c2c1beb8faaef314deab70426480a02c06098124 100644 GIT binary patch delta 137 zcmWN_xe74$Cl*V3Vyrub`@tKEuZCetjT; zG^HhN=}1@V45cT18OTsZGM0%%GL@OclE_>ZvXqsqWg}bJ$zBeUN+w6irI1oia(;99 FegDH+Acg<{ delta 137 zcmWN_w-JH>06p>SM<1FIfOfS=Mv807#32z=GC8PP&ddQVJmsv?noeQ z=}1?4(w8PfiDV!{8Oc~CGL={onMo>{%w-`