• Translucent overlay of photo

    From Claude Rubinson@cjr@grundrisse.org to comp.lang.tcl on Mon Apr 8 13:56:48 2024
    From Newsgroup: comp.lang.tcl

    I have a Tk app that has a series of photos arranged in a grid. Each
    photo is embedded in its own canvas. I'd like to indicate that a photo
    has been selected by the user by highlighting it with a translucent
    overlay. Is this possible? My initial investigation indicates that Tk doesn't (yet) support alpha blending?
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Rich@rich@example.invalid to comp.lang.tcl on Mon Apr 8 19:11:03 2024
    From Newsgroup: comp.lang.tcl

    Claude Rubinson <cjr@grundrisse.org> wrote:
    I have a Tk app that has a series of photos arranged in a grid. Each
    photo is embedded in its own canvas. I'd like to indicate that a photo
    has been selected by the user by highlighting it with a translucent
    overlay. Is this possible? My initial investigation indicates that Tk doesn't (yet) support alpha blending?

    One 'workaround' if Tk does not support alpha blending is to have
    present in the app two versions of the photo, one without and a second
    with the overlay present. Then for a "selected" photo you swap the
    "without" and "with" versions (remembering to "unswap" the last
    selected one as well).

    Of course this only works if the overlay is completely static.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Emiliano@emil.gavilan@gmail.com to comp.lang.tcl on Mon Apr 8 19:01:15 2024
    From Newsgroup: comp.lang.tcl

    On Mon, 8 Apr 2024 13:56:48 -0500
    Claude Rubinson <cjr@grundrisse.org> wrote:

    I have a Tk app that has a series of photos arranged in a grid. Each
    photo is embedded in its own canvas. I'd like to indicate that a photo
    has been selected by the user by highlighting it with a translucent
    overlay. Is this possible? My initial investigation indicates that Tk doesn't (yet) support alpha blending?

    This works for me on 8.6.8 on X11 (color blue4 and alpha 0.4 are examples)

    package require Tk
    # load image from tk demo or choose any other
    set img1 [image create photo -file [file join $env(HOME) \
    src/tk/library/demos/images/ouster.png]]
    set w [image width $img1]
    set h [image height $img1]
    set tmp [image create photo -width $w -height $h]
    $tmp put blue4 -to 0 0 $w $h
    set img2 [image create photo -data [$tmp data -format png] \
    -format {png -alpha 0.4}]
    pack [canvas .c -width [expr {20+$w}] -height [expr {20+$h}]]
    .c create image 10 10 -image $img1 -anchor nw
    .c create image 10 10 -image $img2 -anchor nw -tags sel

    With 8.7/9.0 (still in beta) you can avoid the data round trip using
    directly

    set img2 [image create photo -width $w -height $h
    $img2 put blue4@0.4 -to 0 0 $w $h

    and avoid the tmp image altogether.
    After this, the selection effect can be obtained with

    .c itemconfigure sel -state {hidden|normal}

    Hope this helps
    --
    Emiliano
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Tue Apr 9 10:36:15 2024
    From Newsgroup: comp.lang.tcl

    * Claude Rubinson <cjr@grundrisse.org>
    | I have a Tk app that has a series of photos arranged in a grid. Each
    | photo is embedded in its own canvas. I'd like to indicate that a
    | photo has been selected by the user by highlighting it with a translucent
    | overlay. Is this possible? My initial investigation indicates that
    | Tk doesn't (yet) support alpha blending?

    A different approach might be to add a border around each canvas and
    highlight that to indicate the selected one:

    grid [canvas .c1 -highlightthickness 3 -highlightcolor blue -borderwidth 2 -relief ridge] -row 0 -column 0 -sticky ewnw
    grid [canvas .c2 -highlightthickness 3 -highlightcolor blue -borderwidth 2 -relief ridge] -row 0 -column 1 -sticky ewnw
    grid [canvas .c3 -highlightthickness 3 -highlightcolor blue -borderwidth 2 -relief ridge] -row 1 -column 0 -sticky ewnw
    grid [canvas .c4 -highlightthickness 3 -highlightcolor blue -borderwidth 2 -relief ridge] -row 1 -column 1 -sticky ewnw

    bind .c1 <Button-1> {focus %W}
    bind .c2 <Button-1> {focus %W}
    bind .c3 <Button-1> {focus %W}
    bind .c4 <Button-1> {focus %W}

    grid rowconfigure . 0 -weight 1
    grid rowconfigure . 1 -weight 1
    grid columnconfigure . 0 -weight 1
    grid columnconfigure . 1 -weight 1

    HTH
    R'
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From andreas.kupries@gmail.com@user152@cmacleod.me.uk.invalid to comp.lang.tcl on Thu May 2 11:58:24 2024
    From Newsgroup: comp.lang.tcl

    Claude Rubinson <cjr@grundrisse.org> posted:

    I have a Tk app that has a series of photos arranged in a grid. Each
    photo is embedded in its own canvas. I'd like to indicate that a photo
    has been selected by the user by highlighting it with a translucent
    overlay. Is this possible? My initial investigation indicates that Tk doesn't (yet) support alpha blending?

    As yet another possibility you may want to have a look at the `imgdisplaymulti.tcl` found at

    https://chiselapp.com/user/andreas_kupries/repository/jtools/dir?ci=b6ebc326f0763148904c76cca8aab5d297531303&name=lib/jedit

    It uses TkTreeCtrl (aka `treectrl`) for the grid, and let it handle the highlighting.

    The repo provides an app (`jedit`) demoing the packages.
    --- Synchronet 3.20a-Linux NewsLink 1.114