Skip to content

Commit

Permalink
Convert the GUI to premultiplied alpha.
Browse files Browse the repository at this point in the history
  • Loading branch information
froggey committed Aug 24, 2015
1 parent 3f7cd34 commit a456f63
Show file tree
Hide file tree
Showing 17 changed files with 1,118 additions and 690 deletions.
65 changes: 37 additions & 28 deletions applications/editor.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,8 @@ Tries to stay as close to the hint column as possible."
with win-width = (editor-width)
with point = (buffer-point (current-buffer *editor*))
with mark-active = (buffer-mark-active (current-buffer *editor*))
with buffer = (make-array (list line-height win-width)
:element-type '(unsigned-byte 32)
:initial-element background)
with buffer = (mezzano.gui:make-surface win-width line-height
:initial-colour background)
for ch-position from start below (line-length line)
for glyph = (mezzano.gui.font:character-to-glyph font (line-character line ch-position))
for mask = (mezzano.gui.font:glyph-mask glyph)
Expand All @@ -994,24 +993,29 @@ Tries to stay as close to the hint column as possible."
(< ch-position line-2-charpos)))))))
;; Invert the point.
(when at-point
(mezzano.gui:bitset line-height advance
foreground
buffer 0 pen))
(mezzano.gui:bitset-argb-xrgb-mask-8 (array-dimension mask 0) (array-dimension mask 1)
(if at-point
background
foreground)
mask 0 0
buffer
(- baseline (mezzano.gui.font:glyph-yoff glyph))
(+ pen (mezzano.gui.font:glyph-xoff glyph)))
(mezzano.gui:bitset :set
advance line-height
foreground
buffer
pen 0))
(mezzano.gui:bitset :blend
(mezzano.gui:surface-width mask) (mezzano.gui:surface-height mask)
(if at-point
background
foreground)
buffer
(+ pen (mezzano.gui.font:glyph-xoff glyph))
(- baseline (mezzano.gui.font:glyph-yoff glyph))
mask 0 0)
;; Underline the region.
(when in-region
(mezzano.gui:bitset-argb-xrgb 1 advance
(if at-point
background
foreground)
buffer baseline pen))
(mezzano.gui:bitset :blend
advance 1
(if at-point
background
foreground)
buffer
pen baseline))
(incf pen advance))
finally
;; Reached end of line, check for the point.
Expand All @@ -1020,10 +1024,12 @@ Tries to stay as close to the hint column as possible."
;; Point is here, render it past the last character.
(let* ((glyph (mezzano.gui.font:character-to-glyph font #\Space))
(advance (mezzano.gui.font:glyph-advance glyph)))
(when (<= (+ pen advance) win-width) ; FIXME, how to display point at end of line & display line properly. also fix blit crash bug.
(mezzano.gui:bitset line-height advance
(when (<= (+ pen advance) win-width) ; FIXME, how to display point at end of line & display line properly.
(mezzano.gui:bitset :set
advance line-height
foreground
buffer 0 pen))))
buffer
pen 0))))
;; TODO: Render underline to end of line region spans whole line.
(return (values buffer ch-position)))))

Expand Down Expand Up @@ -1069,16 +1075,18 @@ Tries to stay as close to the hint column as possible."
(win-width (editor-width)))
(if line
;; Blitting line.
(mezzano.gui:bitblt line-height win-width
(mezzano.gui:bitblt :set
win-width line-height
(display-line-representation line)
0 0
fb
real-y left)
left real-y)
;; Line is empty.
(mezzano.gui:bitset line-height win-width
(mezzano.gui:bitset :set
win-width line-height
(background-colour *editor*)
fb
real-y left))
left real-y))
(mezzano.gui.compositor:damage-window (window *editor*)
left real-y
win-width line-height))))
Expand Down Expand Up @@ -1720,11 +1728,12 @@ If no such form is found, then return the CL-USER package."
(mezzano.gui.widgets:draw-frame frame)
(multiple-value-bind (left right top bottom)
(mezzano.gui.widgets:frame-size (frame *editor*))
(mezzano.gui:bitset (- (mezzano.gui.compositor:height window) top bottom)
(mezzano.gui:bitset :set
(- (mezzano.gui.compositor:width window) left right)
(- (mezzano.gui.compositor:height window) top bottom)
(background-colour *editor*)
framebuffer
top left)
left top)
(mezzano.gui.compositor:damage-window window
left top
(- (mezzano.gui.compositor:width window) left right)
Expand Down
37 changes: 21 additions & 16 deletions applications/fs-viewer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@
for glyph = (mezzano.gui.font:character-to-glyph font ch)
for mask = (mezzano.gui.font:glyph-mask glyph)
do
(mezzano.gui:bitset-argb-xrgb-mask-8 (array-dimension mask 0) (array-dimension mask 1) colour
mask 0 0
framebuffer
(- y (mezzano.gui.font:glyph-yoff glyph))
(+ pen (mezzano.gui.font:glyph-xoff glyph)))
(mezzano.gui:bitset :blend
(mezzano.gui:surface-width mask) (mezzano.gui:surface-height mask)
colour
framebuffer
(+ pen (mezzano.gui.font:glyph-xoff glyph))
(- y (mezzano.gui.font:glyph-yoff glyph))
mask 0 0)
(incf pen (mezzano.gui.font:glyph-advance glyph))
finally (return pen)))

Expand All @@ -131,11 +133,12 @@
:key (lambda (x) (first (last (pathname-directory x)))))))
(multiple-value-bind (left right top bottom)
(mezzano.gui.widgets:frame-size (frame viewer))
(mezzano.gui:bitset (- height top bottom)
(mezzano.gui:bitset :set
(- width left right)
(- height top bottom)
mezzano.gui:*default-background-colour*
framebuffer
top left)
left top)
(let ((y top))
(flet ((wr (string &optional (offset 0) (min-line-height 0))
(draw-string string
Expand All @@ -145,17 +148,18 @@
mezzano.gui:*default-foreground-colour*)
(incf y (max min-line-height (mezzano.gui.font:line-height font))))
(seperator ()
(mezzano.gui:bitset 1
(- width left right)
(mezzano.gui:bitset :set
(- width left right) 1
mezzano.gui:*default-foreground-colour*
framebuffer
y left)
left y)
(incf y))
(clickable (icon name thing)
(mezzano.gui:bitblt-argb-xrgb 16 16
icon 0 0
framebuffer
y (1+ left))
(mezzano.gui:bitblt :blend
16 16
icon 0 0
framebuffer
(1+ left) y)
(let ((end (draw-string name
font
framebuffer
Expand All @@ -176,11 +180,12 @@
framebuffer
0 0
#x00000000)))
(mezzano.gui:bitset (mezzano.gui.font:line-height font)
(mezzano.gui:bitset :set
(+ 10 text-width 10)
(mezzano.gui.font:line-height font)
mezzano.gui:*default-foreground-colour*
framebuffer
y (- pen 10))
(- pen 10) y)
(setf pen (draw-string (mezzano.file-system:host-name host)
font
framebuffer
Expand Down
27 changes: 22 additions & 5 deletions applications/irc.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,22 @@
(string= "ACTION " message :start2 1 :end2 8))
(format (display-pane irc) "~&[~A]* ~A ~A" channel from
(subseq message 8 (1- (length message)))))
(t (format (display-pane irc) "~&[~A]<~A> ~A" channel from message))))
(t (format (display-pane irc) "~&[~A]<~A> ~A" channel from message)
#+(or)
(when (and (>= (length message) 6)
(string-equal "!eval " message :end2 6))
(let ((msg (handler-case
(with-output-to-string (*standard-output*)
(eval (read-from-string message t nil :start 6)))
(error (condition)
(format nil "~A" condition)))))
(setf msg (substitute #\Space #\Newline msg))
(when (> (length msg) 400)
(setf msg (subseq msg 0 400))
(setf msg (concatenate 'string msg "...")))
(buffered-format (irc-connection irc) "PRIVMSG ~A :~A~%"
(or channel from) msg))))))


(define-server-command ping (irc from message)
(buffered-format (irc-connection irc) "PONG :~A~%" message))
Expand Down Expand Up @@ -562,18 +577,20 @@ If ORIGIN is a server name, then only the host is valid. Nick and ident will be
:input-pane input-pane)))
(setf (slot-value input-pane '%irc) irc)
;; Line seperating display and input panes.
(mezzano.gui:bitset 1 (- (mezzano.gui.compositor:width window)
(mezzano.gui:bitset :set
(- (mezzano.gui.compositor:width window)
(nth-value 0 (mezzano.gui.widgets:frame-size frame))
(nth-value 1 (mezzano.gui.widgets:frame-size frame)))
#xFF808080
1
(mezzano.gui:make-colour 0.5 0.5 0.5)
framebuffer
(nth-value 0 (mezzano.gui.widgets:frame-size frame))
(+ (nth-value 2 (mezzano.gui.widgets:frame-size frame))
(- (mezzano.gui.compositor:height window)
(nth-value 2 (mezzano.gui.widgets:frame-size frame))
(nth-value 3 (mezzano.gui.widgets:frame-size frame))
(mezzano.gui.font:line-height font)
1))
(nth-value 0 (mezzano.gui.widgets:frame-size frame)))
1)))
(mezzano.gui.widgets:draw-frame frame)
(mezzano.gui.compositor:damage-window window
0 0
Expand Down
7 changes: 2 additions & 5 deletions applications/mandelbrot.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
(frag (+ x^ 0.5) y^)
(frag x^ (+ y^ 0.5))
(frag (+ x^ 0.5) (+ y^ 0.5))
(logior #xFF000000
(ash (round (* (/ r 4) 255)) 16)
(ash (round (* (/ g 4) 255)) 8)
(round (* (/ b 4) 255))))))
(mezzano.gui:make-colour (/ r 4) (/ g 4) (/ b 4)))))

(defgeneric dispatch-event (frame event)
(:method (f e)))
Expand Down Expand Up @@ -94,7 +91,7 @@
;; More than one thread, even.
(dotimes (y height)
(dotimes (x width)
(setf (aref framebuffer (+ top y) (+ left x)) (render-mandelbrot x y width height hue-offset)))
(setf (mezzano.gui:surface-pixel framebuffer (+ left x) (+ top y)) (render-mandelbrot x y width height hue-offset)))
(mezzano.gui.compositor:damage-window window left (+ top y) width 1)
(loop
(let ((evt (mezzano.supervisor:fifo-pop fifo nil)))
Expand Down
Loading

0 comments on commit a456f63

Please sign in to comment.