racket / racket/gui

pasteboard% generates artifacts when snips are dragged behind each other

Open
#216 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
68
Forks
82
PR merge metrics
No merged PRs in 30d

Description

I am using Racket 8.0 on Windows 10. Run the following code.

#lang racket/gui

(struct dc-state (smoothing pen brush font))

(define (capture-dc-state dc)
  (dc-state (send dc get-smoothing)
            (send dc get-pen)
            (send dc get-brush)
            (send dc get-font)))

(define (restore-dc-state dc dc-state)
  (send dc set-smoothing (dc-state-smoothing dc-state))
  (send dc set-pen (dc-state-pen dc-state))
  (send dc set-brush (dc-state-brush dc-state))
  (send dc set-font (dc-state-font dc-state)))

(define node-snip-class
  (make-object
      (class snip-class%
        (super-new)
        (send this set-classname "node-snip"))))

(send (get-the-snip-class-list) add node-snip-class)

(define (set-extent-others others)
  (for/list ([other others])
    (when other (set-box! other 0.0))))

(define node%
  (class snip%
    (init-field size color)
    (super-new)
    (send this set-snipclass node-snip-class)

    (define/override (get-extent dc x y width height . others)
      (when width (set-box! width size))
      (when height (set-box! height size))
      (set-extent-others others))

    (define/override (draw dc x y . other)
      (let ([dc-state (capture-dc-state dc)])
        (send dc set-smoothing 'smoothed)
        (send dc set-pen "Black" 3 'solid)
        (send dc set-brush color 'solid)
        (send dc draw-rounded-rectangle x y size size 7)
        (restore-dc-state dc dc-state)))
    ))

(define diagram (new pasteboard%))

(define frame (new frame%
                   [label "Diagram"]
                   [width 500]
                   [height 500]))

(define canvas (new editor-canvas%
                    [parent frame]
                    [style '(no-hscroll no-vscroll)]
                    [horizontal-inset 0]
                    [vertical-inset 0]
                    [editor diagram]))

(send diagram insert (new node% [size 50] [color "Pale Green"]) 100 100)

(send diagram insert (new node% [size 50] [color "Pale Turquoise"]) 200 200)

(send frame show #t)

Note that the dc state is captured and restored in the draw override. Drag the green node over the blue one and note that no artifacts occur.

image

Now drag the blue node, which is behind the green node, and note that artifacts appear, potentially from the smoothing property not being correctly handled by the pasteboard%. Although, I'm not sure where exactly the artifacts are coming from at the moment. Notice that the artifacts only occur while the blue node is being dragged behind the green node and that they stop after the blue node "clears" the green node.

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Racket 8.0 Windows reproduction and inspect pasteboard% drawing and drag handling, especially how overlapping snips manage the drawing context. Done means dragging the rear blue node across the green node produces no visual artifacts, including while the nodes overlap.

Written by the indexing model from the issue text.

Assessment

Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.