Skip to content

Commit

Permalink
Correctly hide windows
Browse files Browse the repository at this point in the history
  • Loading branch information
borodust committed Jan 29, 2017
1 parent 2a6f0b5 commit 32a7863
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 42 deletions.
14 changes: 7 additions & 7 deletions canvas/canvas.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@
(path (canvas)
(move-to origin canvas)
(%nvg:line-to (handle-value-of canvas) (x end) (y end))
(stroke-width thickness)
(stroke-color color)
(stroke-path)))
(stroke-width thickness canvas)
(stroke-color color canvas)
(stroke-path canvas)))


(defun draw-curve (origin end ctrl0 ctrl1 color &key (thickness 1.0) (canvas *canvas*))
(path(canvas)
(path (canvas)
(move-to origin canvas)
(%nvg:bezier-to (handle-value-of canvas) (x ctrl0) (y ctrl0) (x ctrl1) (y ctrl1)
(x end) (y end))
(stroke-color color)
(stroke-width thickness)
(stroke-path)))
(stroke-color color canvas)
(stroke-width thickness canvas)
(stroke-path canvas)))


(defun draw-rect (origin w h &key (fill-color nil) (stroke-color nil)
Expand Down
9 changes: 4 additions & 5 deletions graphics/buffers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@
(:default-initargs :target :array-buffer))


(define-system-function make-array-buffer graphics-system
(vertex-attribute-data &key (system *system*))
(define-system-function make-array-buffer graphics-system (vertex-attribute-data)
(make-instance 'array-buffer
:system system
:system *system*
:vertex-attribute-data vertex-attribute-data))


Expand Down Expand Up @@ -103,5 +102,5 @@
(gl:buffer-data :element-array-buffer :static-draw gl-array)))))


(define-system-function make-index-buffer graphics-system (index-array &key (system *system*))
(make-instance 'index-buffer :system system :index-array index-array))
(define-system-function make-index-buffer graphics-system (index-array)
(make-instance 'index-buffer :system *system* :index-array index-array))
77 changes: 47 additions & 30 deletions poiu/elements.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,38 @@
;;;
;;;
(defclass window (layout disposable)
((x :initarg :x :initform 0.0)
((id :initform (symbol-name (gensym "poiu-window")))
(x :initarg :x :initform 0.0)
(y :initarg :y :initform 0.0)
(panel-p :initarg :panel-p)
(width :initform nil)
(height :initform nil)
(background :initarg :background-color)
(title :initarg :title :initform "")
(option-mask :initarg :option-mask :initform '())
(hidden-p :initform nil :initarg :hidden-p)

(compose-actions :initform nil)
(nk-rect :initform (calloc '(:struct (%nk:rect))))
(nk-vec2 :initform (calloc '(:struct (%nk:vec2))))
(nk-color :initform (calloc '(:struct (%nk:color))))
(nk-style-item :initform (calloc '(:struct (%nk:style-item))))))


(defmethod initialize-instance :after ((this window) &key width height)
(with-slots ((w width) (h height)) this
(defun hide-window (window)
(with-slots (compose-actions id) window
(push (lambda () (%nk:window-show *handle* id %nk:+hidden+)) compose-actions)))


(defun show-window (window)
(with-slots (compose-actions id) window
(push (lambda () (%nk:window-show *handle* id %nk:+shown+)) compose-actions)))


(defmethod initialize-instance :after ((this window) &key width height hidden-p)
(with-slots ((w width) (h height) title) this
(setf w (float width 0f0)
h (float height 0f0))))
h (float height 0f0))
(when hidden-p
(hide-window this))))


(define-destructor window (nk-rect nk-color nk-style-item nk-vec2)
Expand All @@ -90,7 +102,7 @@

(defun make-window (x y w h &key (title "") (background-color nil)
(headerless-p t) (scrollable-p nil) (backgrounded-p nil)
(borderless-p t) (panel-p nil) (resizable-p nil)
(borderless-p nil) (panel-p nil) (resizable-p nil)
(minimizable-p nil) (movable-p nil) (closable-p nil)
(hidden-p nil))
(macrolet ((opt (key option)
Expand All @@ -105,35 +117,28 @@
:option-mask (apply #'nk:panel-mask
(nconc (opt (not headerless-p) :title)
(opt (not scrollable-p) :no-scrollbar)
(opt (not borderless-p) :border)
(opt (not (or panel-p borderless-p)) :border)
(opt closable-p :closable)
(opt backgrounded-p :background)
(opt resizable-p :scalable)
(opt minimizable-p :minimizable)
(opt movable-p :movable))))))


(defun hide-window (window)
(with-slots (hidden-p) window
(setf hidden-p t)))


(defun show-window (window)
(with-slots (hidden-p) window
(setf hidden-p nil)))


(defun style-item-color (style-item-buf color-buf color)
(%nk:style-item-color style-item-buf
(%nk:rgba-f color-buf
(x color) (y color)
(z color) (w color))))

(defun compose-window (win next-method)
(with-slots (x y width height title option-mask nk-rect) win
(let ((val (%nk:begin *handle* title (%nk:rect nk-rect x y width height) option-mask)))
(with-slots (x y width height title option-mask nk-rect compose-actions id) win
(mapc #'funcall compose-actions)
(setf compose-actions nil)
(let ((val (%nk:begin-titled *handle* id title (%nk:rect nk-rect x y width height)
option-mask)))
(if (= 0 val)
(hide-window win)
(%nk:window-show *handle* id %nk:+hidden+)
(funcall next-method win))
(%nk:end *handle*))))

Expand All @@ -150,13 +155,12 @@

(defmethod compose ((this window))
(with-slots (background nk-color nk-style-item panel-p hidden-p) this
(unless hidden-p
(with-styles ((%nk:style-item (when background
(style-item-color nk-style-item nk-color background))
:window :fixed-background))
(if panel-p
(compose-panel this #'call-next-method)
(compose-window this #'call-next-method))))))
(with-styles ((%nk:style-item (when background
(style-item-color nk-style-item nk-color background))
:window :fixed-background))
(if panel-p
(compose-panel this #'call-next-method)
(compose-window this #'call-next-method)))))

;;;
;;;
Expand Down Expand Up @@ -300,8 +304,7 @@

(defmethod initialize-instance :after ((this health-monitor) &key x y width height hidden-p)
(with-slots (window) this
(setf window (make-window x y width height
:title "Health monitor"
(setf window (make-window x y width height :title "Health monitor"
:headerless-p nil :scrollable-p t :resizable-p t
:movable-p t :closable-p t :hidden-p hidden-p))))

Expand Down Expand Up @@ -331,3 +334,17 @@
(defmethod compose ((this health-monitor))
(with-slots (window) this
(compose window)))


;;;
;;;
;;;
(defclass spacing (layout) ())


(defun make-spacing ()
(make-instance 'spacing))


(defmethod compose ((this spacing))
(%nk:spacing *handle* 1))
1 change: 1 addition & 0 deletions poiu/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
make-label-button
make-text-label
make-text-edit
make-spacing
make-health-monitor
show-health-monitor
hide-health-monitor
Expand Down

0 comments on commit 32a7863

Please sign in to comment.