2 (asdf:oos
'asdf
:load-op
'#:cowl-glfw
)
7 (defclass cowl-matrix
()
8 ((container :type cowl
:container
:accessor widget-of
)
10 :initform
(make-array '(4 4) :element-type
'single-float
11 :initial-contents
'((1.0
0.0 0.0 0.0)
16 (:documentation
"This is a graphical representation of a matrix."))
18 (defmethod initialize-instance :after
((cowl-matrix cowl-matrix
) &key
)
19 (setf (widget-of cowl-matrix
)
21 ((cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 0 0))
22 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 0 1))
23 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 0 2))
24 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 0 3)))
25 ((cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 1 0))
26 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 1 1))
27 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 1 2))
28 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 1 3)))
29 ((cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 2 0))
30 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 2 1))
31 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 2 2))
32 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 2 3)))
33 ((cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 3 0))
34 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 3 1))
35 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 3 2))
36 (cowl:make-scroll-button
() "~4f" (aref (matrix-of cowl-matrix
) 3 3))))))
39 (defun multiply-matrix (a b r
)
40 "Multiply matrix a by b and put result in r."
42 do
(loop for col below
4
43 do
(setf (aref r row col
)
44 (loop for i below
4 summing
50 (glfw:do-window
(:title
"Cowl Matrix Example" :width
800 :height
600)
51 ((setf cowl
:*root-widget
*
52 ;; here we have our bindings to the matrices so we can close over them
54 (cowl:make-vbox
(:width
800 :height
600
55 :row-heights
'((:weight .
1.0)
61 ;; the body of this macro is a list of widgets for the wrapper
63 nil
;; nil in weighted spaces will expand as necessary
65 (cowl:make-label
"Matrix multiplication example")
67 (cowl:make-hbox
(:width
800
68 :column-widths
'((:weight .
1.0)
80 (widget-of (setf ma
(make-instance 'cowl-matrix
)))
84 (widget-of (setf mb
(make-instance 'cowl-matrix
)))
88 (widget-of (setf mr
(make-instance 'cowl-matrix
)))
91 (cowl:make-button
() "Calculate"
92 (multiply-matrix (matrix-of ma
)
95 (cowl:update-text
(widget-of mr
)))
98 (cowl:make-button
() "Quit"
103 (cowl-glfw:setup-input-callbacks
))
105 ;; Main loop the same as before
106 (gl:clear gl
:+color-buffer-bit
+)