Skip to content

Commit

Permalink
Add z-index handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Sep 8, 2019
1 parent a73573c commit 8903084
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
12 changes: 7 additions & 5 deletions renderers/opengl/protocol.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
(in-package #:org.shirakumo.alloy.renderers.opengl)

;; Required GL state before ALLOY:RENDER call:
;; (gl:enable :blend :stencil-test :line-smooth)
;; (gl:disable :depth-test)
;; (gl:enable :blend :depth-test :stencil-test :line-smooth)
;; (gl:stencil-func :always 1 #xFF)
;; (gl:clear-stencil #x00)
;; (gl:clear-depth 1.0)
;; (gl:depth-func :lequal)
;; (gl:depth-mask T)
;; (gl:blend-func :src-alpha :one-minus-src-alpha)
;; If cull-face is enabled:
;; (gl:front-face :ccw)
;; (gl:cull-face :back)
;; The target being rendered to must have a color
;; and stencil attachment. A depth attachment is not
;; required, as all UI is drawn at Z 0.
;; The target being rendered to must have a color and a
;; combined depth-stencil attachment.

;; alloy:allocate
;; alloy:deallocate
;; simple:text
;; simple:request-font
;; simple:request-image

(defgeneric bind (resource))
(defgeneric gl-name (resource))

Expand Down
3 changes: 3 additions & 0 deletions renderers/opengl/renderer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

(defvar *circ-polycount* 100)

;; FIXME: With a UBO we could avoid having to re-set uniforms at ever draw
;; and instead change them when the style is set.

(defclass renderer (simple:transformed-renderer
simple:styled-renderer)
((resources :initform (make-hash-table :test 'equal) :reader resources)))
Expand Down
1 change: 1 addition & 0 deletions renderers/simple/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#:translate
#:scale
#:rotate
#:z-index
#:call-with-pushed-styles
#:fill-color
#:line-width
Expand Down
8 changes: 6 additions & 2 deletions renderers/simple/presentations/default.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

(in-package #:org.shirakumo.alloy.renderers.simple.presentations)

;; TODO: Pallettes

(defclass default-look-and-feel (renderer)
())

Expand All @@ -18,7 +20,8 @@
(:border
:fill-color (case (alloy:focus)
((:weak :strong) (simple:color 0.9 0.9 0.9))
(T (simple:color 0 0 0 0))))
(T (simple:color 0 0 0 0)))
:z-index -1)
(:label
:fill-color (case (alloy:focus)
((:weak :strong) (simple:color 0 0 0))
Expand Down Expand Up @@ -71,5 +74,6 @@
(define-style (default-look-and-feel alloy:input-line)
(:background
:fill-color (case (alloy:focus)
(:strong (simple:color 1 1 1))
(:strong (simple:color 0.9 0.9 0.9))
(:weak (simple:color 0.7 0.7 0.7))
(T (simple:color 0.15 0.15 0.15)))))
5 changes: 4 additions & 1 deletion renderers/simple/presentations/protocol.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
(simple:line-width :initform NIL)
(simple:fill-mode :initform NIL)
(simple:composite-mode :initform NIL)
(z-index :initarg :z-index :initform NIL :accessor z-index)
(offset :initarg :offset :initform NIL :accessor offset)
(scale :initarg :scale :initform NIL :accessor scale)
(rotation :initarg :rotation :initform NIL :accessor rotation)
Expand Down Expand Up @@ -78,7 +79,7 @@
(defmethod merge-style-into ((target style) (source style))
(loop for slot in '(simple:fill-color simple:font simple:font-size
simple:line-width simple:composite-mode
offset scale rotation pivot)
z-index offset scale rotation pivot)
for src = (slot-value source slot)
do (when src (setf (slot-value target slot) src)))
target)
Expand All @@ -90,6 +91,7 @@
(setf (simple:font-size renderer) (simple:font-size style))
(setf (simple:composite-mode renderer) (simple:composite-mode style))
;; TODO: Not sure this is quite right.
(setf (simple:z-index renderer) (z-index style))
(simple:translate renderer (offset style))
(simple:translate renderer (pivot style))
(simple:rotate renderer (rotation style))
Expand All @@ -103,6 +105,7 @@
:font (simple:request-font renderer :default)
:font-size 12.0
:composite-mode :source-over
:z-index 0
:offset (alloy:point 0 0)
:scale (alloy:size 1 1)
:rotation 0.0
Expand Down
2 changes: 2 additions & 0 deletions renderers/simple/protocol.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
(defgeneric translate (renderer point))
(defgeneric scale (renderer size))
(defgeneric rotate (renderer phi))
(defgeneric z-index (renderer))
(defgeneric (setf z-index) (z-index renderer))

(defgeneric call-with-pushed-styles (function renderer))
(defgeneric fill-color (renderer))
Expand Down
12 changes: 12 additions & 0 deletions renderers/simple/transforms.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
(sin phi) (cos phi) 0
0 0 1)))

(defmethod z-index ((transform transform))
(aref (transform-matrix transform) 8))

(defmethod (setf z-index) (z-index (transform transform))
(setf (aref (transform-matrix transform) 8) (float z-index)))

(defclass transformed-renderer (renderer)
((transform :accessor transform)))

Expand Down Expand Up @@ -124,3 +130,9 @@

(defmethod rotate ((renderer transformed-renderer) phi)
(rotate (transform renderer) phi))

(defmethod z-index ((renderer transformed-renderer))
(z-index (transform renderer)))

(defmethod (setf z-index) (z-index (renderer transformed-renderer))
(setf (z-index (transform renderer)) z-index))

0 comments on commit 8903084

Please sign in to comment.