Move from github, collapse gltk and strictmath, add candle
[clnl] / src / main / clnl-gltk / base.lisp
1 (in-package #:clnl-gltk)
2
3 (defgeneric render (item)
4  (:documentation
5   "RENDER ITEM => RESULT
6
7 ARGUMENTS AND VALUES:
8
9   ITEM: item to be rendered
10   RESULT: undefined
11
12 DESCRIPTION:
13
14   RENDER is the entry point for rendering different items in the
15   CLNL-GLTK package.
16
17   RENDER will return the opengl world to the way it found it after
18   finishing, usually via just popping the matrix."))
19
20 (defgeneric resize (item width height)
21  (:documentation
22   "RESIZE ITEM WIDTH HEIGHT => RESULT
23
24 ARGUMENTS AND VALUES:
25
26   ITEM: item to be rendered
27   WIDTH: an integer
28   HEIGHT: an integer
29   RESULT: undefined
30
31 DESCRIPTION:
32
33   RESIZE is the general purpose resizing entry point for all widgets.
34
35   WIDTH and HEIGHT are contextual to the actual item being resized, and
36   may be even be ignored."))
37
38 (defgeneric reposition (item x y)
39  (:documentation
40   "REPOSITION ITEM X Y => RESULT
41
42 ARGUMENTS AND VALUES:
43
44   ITEM: item to be rendered
45   X: an integer
46   Y: an integer
47   RESULT: undefined
48
49 DESCRIPTION:
50
51   REPOSITION is the general purpose resizing entry point for all widgets.
52
53   X and Y are contextual to the actual item being repositioned, and
54   may be even be ignored."))
55
56 (defgeneric mousemove (item x y)
57  (:documentation
58   "MOUSEMOVE ITEM X Y => RESULT
59
60 ARGUMENTS AND VALUES:
61
62   ITEM: item handling event
63   X: an integer
64   Y: an integer
65   RESULT: undefined
66
67 DESCRIPTION:
68
69   MOUSEMOVE is the general purpose mousemove entry point for all widgets.  It
70   is used to alert widgets to movements of the mouse, regardless of button state.
71
72   X and Y are absolute coordinates, and assumed to be opengl coordinates,
73   not window coordinates (meaning they match the render and setup functions
74   of widgets).
75
76   A catchall method that does nothing is also defined so that mouse functions
77   can loop over all available widgets and let them decide what they want to do."))
78
79 (defmethod mousemove (item x y))
80
81 (defgeneric mousedown (item x y)
82  (:documentation
83   "MOUSEDOWN ITEM X Y => RESULT
84
85 ARGUMENTS AND VALUES:
86
87   ITEM: item handling event
88   X: an integer
89   Y: an integer
90   RESULT: undefined
91
92 DESCRIPTION:
93
94   MOUSEDOWN is the general purpose mousedown entry point for all widgets.  It
95   is used to alert widgets that a mouse button has been pressed, and where.
96   There's no information on which button has been pressed.
97
98   X and Y are absolute coordinates, and assumed to be opengl coordinates,
99   not window coordinates (meaning they match the render and setup functions
100   of widgets).
101
102   A catchall method that does nothing is also defined so that mouse functions
103   can loop over all available widgets and let them decide what they want to do."))
104
105 (defmethod mousedown (item x y))
106
107 (defgeneric mouseup (item x y)
108  (:documentation
109   "MOUSEUP ITEM X Y => RESULT
110
111 ARGUMENTS AND VALUES:
112
113   ITEM: item handling event
114   X: an integer
115   Y: an integer
116   RESULT: undefined
117
118 DESCRIPTION:
119
120   MOUSEUP is the general purpose mouseup entry point for all widgets.  It
121   is used to alert widgets to that a mouse button has been released, and where.
122   There's no information on which button has been released, and it is
123   up to the widget to decide if a click was triggered.
124
125   X and Y are absolute coordinates, and assumed to be opengl coordinates,
126   not window coordinates (meaning they match the render and setup functions
127   of widgets).
128
129   A catchall method that does nothing is also defined so that mouse functions
130   can loop over all available widgets and let them decide what they want to do."))
131
132 (defmethod mouseup (item x y))
133
134 (defgeneric toggle (item &optional state)
135  (:documentation
136   "TOGGLE ITEM &optional STATE => NEW-STATE
137
138 ARGUMENTS AND VALUES:
139
140   ITEM: an item
141   STATE: a boolean, the state to set to
142   NEW-STATE: a boolean, the state after being set
143
144 DESCRIPTION:
145
146   TOGGLE toggles an ITEM.
147
148   Inverts the current toggle status of the ITEM if no STATE
149   passed in, otherwise sets to STATE."))
150
151 ; Stick utilities here for now
152 (defun draw-border (x1 y1 x2 y2 &optional (line-width 1f0))
153  (let
154   ((offset (/ (1- line-width) 2)))
155   (gl:line-width line-width)
156   (gl:begin :lines)
157   (gl:vertex x1 y1)
158   (gl:vertex (+ x2 offset) y1)
159   (gl:vertex x2 y1)
160   (gl:vertex x2 (+ y2 offset))
161   (gl:vertex x2 y2)
162   (gl:vertex (- x1 offset) y2)
163   (gl:vertex x1 y2)
164   (gl:vertex x1 (- y1 offset))
165   (gl:end)))