queue and paint repairs

This commit is contained in:
Matthew Flatt 2010-07-23 08:19:34 -05:00
parent efb88aef4f
commit 5af3d96a5d
4 changed files with 35 additions and 10 deletions

View File

@ -10,6 +10,7 @@
"types.rkt" "types.rkt"
"window.rkt" "window.rkt"
"dc.rkt" "dc.rkt"
"queue.rkt"
"../common/event.rkt" "../common/event.rkt"
"../common/queue.rkt" "../common/queue.rkt"
"../../syntax.rkt" "../../syntax.rkt"
@ -40,7 +41,9 @@
(CGContextFillRect cg (make-NSRect (make-NSPoint 0 0) (CGContextFillRect cg (make-NSRect (make-NSPoint 0 0)
(make-NSSize 32000 32000)))) (make-NSSize 32000 32000))))
(tellv ctx restoreGraphicsState)))) (tellv ctx restoreGraphicsState))))
(send wx queue-paint)) (send wx queue-paint)
;; ensure that `nextEventMatchingMask:' returns
(post-dummy-event))
(-a _void (viewWillMoveToWindow: [_id w]) (-a _void (viewWillMoveToWindow: [_id w])
(when wx (when wx
(queue-window-event wx (lambda () (send wx fix-dc))))) (queue-window-event wx (lambda () (send wx fix-dc)))))
@ -76,15 +79,26 @@
(define canvas-style style) (define canvas-style style)
;; Avoid multiple queued paints:
(define paint-queued? #f) (define paint-queued? #f)
;; To handle paint requests that happen while on-paint
;; is being called already:
(define now-drawing? #f)
(define refresh-after-drawing? #f)
(define/public (queue-paint) (define/public (queue-paint)
;; can be called from any thread, including the event-pump thread ;; can be called from any thread, including the event-pump thread
(unless paint-queued? (unless paint-queued?
(set! paint-queued? #t) (set! paint-queued? #t)
(queue-window-event this (lambda () (queue-window-event this (lambda ()
(set! paint-queued? #f) (set! paint-queued? #f)
(on-paint))))) (set! now-drawing? #t)
(fix-dc)
(on-paint)
(set! now-drawing? #f)
(when refresh-after-drawing?
(set! refresh-after-drawing? #f)
(refresh))))))
(define/override (refresh) (define/override (refresh)
(tellv content-cocoa setNeedsDisplay: #:type _BOOL #t)) (tellv content-cocoa setNeedsDisplay: #:type _BOOL #t))
@ -312,9 +326,13 @@
(define/public (get-canvas-background) bg-col) (define/public (get-canvas-background) bg-col)
(define/public (set-canvas-background col) (set! bg-col col)) (define/public (set-canvas-background col) (set! bg-col col))
(define/public (get-canvas-background-for-clearing) (define/public (get-canvas-background-for-clearing)
(and (not (memq 'transparent canvas-style)) (if now-drawing?
(not (memq 'no-autoclear canvas-style)) (begin
bg-col)) (set! refresh-after-drawing? #t)
#f)
(and (not (memq 'transparent canvas-style))
(not (memq 'no-autoclear canvas-style))
bg-col)))
(define/public (do-scroll direction scroller) (define/public (do-scroll direction scroller)
;; Called from the Cocoa handler thread ;; Called from the Cocoa handler thread

View File

@ -19,6 +19,7 @@
set-eventspace-hook! set-eventspace-hook!
set-front-hook! set-front-hook!
set-menu-bar-hooks! set-menu-bar-hooks!
post-dummy-event
;; from common/queue: ;; from common/queue:
current-eventspace current-eventspace

View File

@ -37,7 +37,7 @@
(define-glib g_main_context_query (_fun _GMainContext (define-glib g_main_context_query (_fun _GMainContext
_int _int
_pointer _pointer
_GPollFD-pointer _pointer ;; GPollFD array
_int _int
-> _int)) -> _int))

View File

@ -759,7 +759,11 @@
(do-text cr #f s 0 0 font combine? offset 0.0))) (do-text cr #f s 0 0 font combine? offset 0.0)))
(define/private (do-text cr draw? s x y font combine? offset angle) (define/private (do-text cr draw? s x y font combine? offset angle)
(let ([s (if (zero? offset) s (substring s offset))]) (let* ([s (if (zero? offset)
s
(substring s offset))]
[blank? (equal? s "")]
[s (if (and (not draw?) blank?) " " s)])
(unless context (unless context
(set! context (pango_cairo_create_context cr))) (set! context (pango_cairo_create_context cr)))
(set-font-antialias context (send font get-smoothing)) (set-font-antialias context (send font get-smoothing))
@ -788,7 +792,9 @@
(void) (void)
(let ([logical (make-PangoRectangle 0 0 0 0)]) (let ([logical (make-PangoRectangle 0 0 0 0)])
(pango_layout_get_extents layout #f logical) (pango_layout_get_extents layout #f logical)
(values (integral (/ (PangoRectangle-width logical) (exact->inexact PANGO_SCALE))) (values (if blank?
0.0
(integral (/ (PangoRectangle-width logical) (exact->inexact PANGO_SCALE))))
(integral (/ (PangoRectangle-height logical) (exact->inexact PANGO_SCALE))) (integral (/ (PangoRectangle-height logical) (exact->inexact PANGO_SCALE)))
(integral (/ (- (PangoRectangle-height logical) (integral (/ (- (PangoRectangle-height logical)
(pango_layout_get_baseline layout)) (pango_layout_get_baseline layout))
@ -820,7 +826,7 @@
(pango_layout_get_baseline layout)) (pango_layout_get_baseline layout))
(exact->inexact PANGO_SCALE)))] (exact->inexact PANGO_SCALE)))]
[la 0.0]) [la 0.0])
(values (+ w lw) (max h lh) (max d ld) (max a la)))))))))) (values (if blank? 0.0 (+ w lw)) (max h lh) (max d ld) (max a la))))))))))
(def/public (get-char-width) (def/public (get-char-width)
10.0) 10.0)