1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
11 * Internal framebuffer functions.
16 #ifndef SQUIRRELJME_FBINTERN_H
17 #define SQUIRRELJME_FBINTERN_H
19 #include "lib/scritchui/framebuffer/fb.h"
20 #include "lib/scritchui/scritchui.h"
24 #ifndef SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_IS_EXTERNED
26 #define SJME_CXX_SQUIRRELJME_FBINTERN_H
29 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
30 #endif /* #ifdef __cplusplus */
32 /*--------------------------------------------------------------------------*/
35 * Callback for when an item has been activated.
37 * @param inState The input state.
38 * @param inComponent The input component.
39 * @return On any resultant error, if any.
42 typedef sjme_errorCode (*sjme_scritchui_fb_lightActivateListenerFunc
)(
43 sjme_attrInNotNull sjme_scritchui inState
,
44 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
);
47 * Callback for when a lightweight component is clicked.
49 * @param inState The input state.
50 * @param inComponent The input component.
51 * @param selectionId The selection Id.
52 * @param atX The X coordinate.
53 * @param atY The Y coordinate.
54 * @return On any resultant error, if any.
57 typedef sjme_errorCode (*sjme_scritchui_fb_lightClickListenerFunc
)(
58 sjme_attrInNotNull sjme_scritchui inState
,
59 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
,
60 sjme_attrInValue sjme_jint selectionId
,
61 sjme_attrInValue sjme_jint atX
,
62 sjme_attrInValue sjme_jint atY
);
65 * Callback for when there is cursor movement requested.
67 * @param inState The input state.
68 * @param inComponent The input component.
69 * @param moveX The X coordinate.
70 * @param moveY The Y coordinate.
71 * @return On any resultant error, if any.
74 typedef sjme_errorCode (*sjme_scritchui_fb_lightCursorListenerFunc
)(
75 sjme_attrInNotNull sjme_scritchui inState
,
76 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
,
77 sjme_attrInValue sjme_jint moveX
,
78 sjme_attrInValue sjme_jint moveY
);
80 /** Hover listener, same parameters as click. */
81 typedef sjme_scritchui_fb_lightClickListenerFunc
82 sjme_scritchui_fb_lightHoverListenerFunc
;
84 /** Selection listener is the same as activate. */
85 typedef sjme_scritchui_fb_lightActivateListenerFunc
86 sjme_scritchui_fb_lightSelectListenerFunc
;
89 * Widget state and interactions accordingly.
93 typedef struct sjme_scritchui_fb_widgetState
95 /** The currently focused sub-item. */
96 sjme_jint subFocusIndex
;
98 /** Selection buffer, for pointer interaction. */
101 /** The length of the selection buffer. */
104 /** The selection buffer width. */
105 sjme_jint selBufWidth
;
107 /** The selection buffer height. */
108 sjme_jint selBufHeight
;
110 /** The selection buffer pencil. */
111 sjme_scritchui_pencil selBufPencil
;
113 /** Lightweight activation. */
114 sjme_scritchui_fb_lightActivateListenerFunc lightActivateListener
;
116 /** Lightweight click. */
117 sjme_scritchui_fb_lightClickListenerFunc lightClickListener
;
119 /** Lightweight cursor. */
120 sjme_scritchui_fb_lightCursorListenerFunc lightCursorListener
;
122 /** Lightweight hover. */
123 sjme_scritchui_fb_lightHoverListenerFunc lightHoverListener
;
125 /** Lightweight select. */
126 sjme_scritchui_fb_lightSelectListenerFunc lightSelectListener
;
127 } sjme_scritchui_fb_widgetState
;
130 * A type of entry within a display list.
134 typedef enum sjme_scritchui_fb_displayListType
137 SJME_SCRITCHUI_FB_DL_TYPE_NOTHING
,
140 SJME_SCRITCHUI_FB_DL_TYPE_BOX
,
143 SJME_SCRITCHUI_FB_DL_TYPE_TEXT
,
145 /** Another display list. */
146 SJME_SCRITCHUI_FB_DL_TYPE_DL
,
148 /** The number of display list types. */
149 SJME_SCRITCHUI_FB_NUM_DL_TYPE
150 } sjme_scritchui_fb_displayListType
;
153 * Modifier for display list drawing.
157 typedef enum sjme_scritchui_fb_displayListMod
160 SJME_SCRITCHUI_FB_DL_TYPE_MOD_NONE
= 0,
163 SJME_SCRITCHUI_FB_DL_TYPE_MOD_FOCUS
= 1,
166 SJME_SCRITCHUI_FB_DL_TYPE_MOD_SELECTED
= 2,
169 SJME_SCRITCHUI_FB_DL_TYPE_MOD_DISABLED
= 4,
170 } sjme_scritchui_fb_displayListMod
;
173 * Text display list data.
177 typedef struct sjme_scritchui_fb_displayListText
179 /** The string to render. */
180 sjme_scritchui_pencilFont font
;
182 /** The font used. */
184 } sjme_scritchui_fb_displayListText
;
187 * Represents a single item within a display list.
191 typedef struct sjme_scritchui_fb_displayList
193 /** The type of entry this is. */
194 sjme_scritchui_fb_displayListType type
;
196 /** Modifiers for this entry. */
197 sjme_scritchui_fb_displayListMod mod
;
199 /** The bounds to use for this item. */
200 sjme_scritchui_rect bound
;
202 /** The selection item, used for mouse actions. */
205 /** The color to use. */
206 sjme_scritchui_lafElementColorType color
;
208 /** The display list entry data. */
212 sjme_scritchui_fb_displayListText text
;
214 } sjme_scritchui_fb_displayList
;
217 * Shaders used to modify how items are drawn.
221 typedef struct sjme_scritchui_fb_displayShaders
224 } sjme_scritchui_fb_displayShaders
;
227 * Initializes the lightweight component.
229 * @param inState The input state.
230 * @param inComponent The input component.
231 * @param outWState The output widget state.
232 * @param isInteractive Is this an interactive component?
233 * @param paintListener The listener for paint operations.
236 typedef sjme_errorCode (*sjme_scritchui_fb_intern_lightweightInitFunc
)(
237 sjme_attrInNotNull sjme_scritchui inState
,
238 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
,
239 sjme_attrOutNotNull sjme_scritchui_fb_widgetState
** outWState
,
240 sjme_attrInValue sjme_jboolean isInteractive
,
241 sjme_attrInNotNull sjme_scritchui_paintListenerFunc paintListener
);
244 * Returns the logical button that was pressed.
246 * @param inState The input state.
247 * @param inEvent The input event.
248 * @return Any resultant error, if any.
251 typedef sjme_errorCode (*sjme_scritchui_fb_intern_logicalButtonFunc
)(
252 sjme_attrInNotNull sjme_scritchui inState
,
253 sjme_attrInNotNull
const sjme_scritchinput_event
* inEvent
,
254 sjme_attrOutNotNull sjme_scritchinput_key
* outKey
);
257 * Refreshes the specified component.
259 * @param inState The input state.
260 * @param inComponent The component to refresh.
261 * @return Any resultant error, if any.
264 typedef sjme_errorCode (*sjme_scritchui_fb_intern_refreshFunc
)(
265 sjme_attrInNotNull sjme_scritchui inState
,
266 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
);
269 * Renders the given display list.
271 * @param inState The input state.
272 * @param inComponent Optional component being drawn, used for selections.
273 * @param g The pencil to draw with.
274 * @param dlFull The display list to draw.
275 * @param dlCount The size of the display list.
276 * @param focusRect The focus rectangle.
277 * @param shaders Shaders that may modify rendering.
278 * @param shaderData Any data to pass to shaders.
279 * @return Any resultant error, if any.
282 typedef sjme_errorCode (*sjme_scritchui_fb_intern_renderFunc
)(
283 sjme_attrInNotNull sjme_scritchui inState
,
284 sjme_attrInNullable sjme_scritchui_uiComponent inComponent
,
285 sjme_attrInNotNull sjme_scritchui_pencil g
,
286 sjme_attrInNotNull
const sjme_scritchui_fb_displayList
* dlFull
,
287 sjme_attrInPositive sjme_jint dlCount
,
288 sjme_attrOutNullable sjme_scritchui_rect
* focusRect
,
289 sjme_attrInNullable
const sjme_scritchui_fb_displayShaders
* shaders
,
290 sjme_attrInNullable sjme_pointer shaderData
);
293 * Renders the given display list in a scroll window for the given component.
295 * @param inState The input state.
296 * @param inComponent The component to render for within a scroll window.
297 * @param g The pencil to draw with.
298 * @param dlFull The display list to draw.
299 * @param dlCount The size of the display list.
300 * @param focusRect The focus rectangle.
301 * @param shaders Shaders that may modify rendering.
302 * @param shaderData Any data to pass to shaders.
303 * @return Any resultant error, if any.
306 typedef sjme_errorCode (*sjme_scritchui_fb_intern_renderInScrollFunc
)(
307 sjme_attrInNotNull sjme_scritchui inState
,
308 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
,
309 sjme_attrInNotNull sjme_scritchui_pencil g
,
310 sjme_attrInNotNull
const sjme_scritchui_fb_displayList
* dlFull
,
311 sjme_attrInPositive sjme_jint dlCount
,
312 sjme_attrOutNullable sjme_scritchui_rect
* focusRect
,
313 sjme_attrInNullable
const sjme_scritchui_fb_displayShaders
* shaders
,
314 sjme_attrInNullable sjme_pointer shaderData
);
316 struct sjme_scritchui_implInternFunctions
318 /** Initialize lightweight component. */
319 sjme_scritchui_fb_intern_lightweightInitFunc lightweightInit
;
321 /** Get logical button. */
322 sjme_scritchui_fb_intern_logicalButtonFunc logicalButton
;
324 /** Refresh widget. */
325 sjme_scritchui_fb_intern_refreshFunc refresh
;
327 /** Render directly. */
328 sjme_scritchui_fb_intern_renderFunc render
;
330 /** Render in scroll window. */
331 sjme_scritchui_fb_intern_renderInScrollFunc renderInScroll
;
334 sjme_errorCode
sjme_scritchui_fb_intern_lightweightInit(
335 sjme_attrInNotNull sjme_scritchui inState
,
336 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
,
337 sjme_attrOutNotNull sjme_scritchui_fb_widgetState
** outWState
,
338 sjme_attrInValue sjme_jboolean isInteractive
,
339 sjme_attrInNotNull sjme_scritchui_paintListenerFunc paintListener
);
341 sjme_errorCode
sjme_scritchui_fb_intern_logicalButton(
342 sjme_attrInNotNull sjme_scritchui inState
,
343 sjme_attrInNotNull
const sjme_scritchinput_event
* inEvent
,
344 sjme_attrOutNotNull sjme_scritchinput_key
* outKey
);
346 sjme_errorCode
sjme_scritchui_fb_intern_refresh(
347 sjme_attrInNotNull sjme_scritchui inState
,
348 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
);
350 sjme_errorCode
sjme_scritchui_fb_intern_render(
351 sjme_attrInNotNull sjme_scritchui inState
,
352 sjme_attrInNullable sjme_scritchui_uiComponent inComponent
,
353 sjme_attrInNotNull sjme_scritchui_pencil g
,
354 sjme_attrInNotNull
const sjme_scritchui_fb_displayList
* dlFull
,
355 sjme_attrInPositive sjme_jint dlCount
,
356 sjme_attrOutNullable sjme_scritchui_rect
* focusRect
,
357 sjme_attrInNullable
const sjme_scritchui_fb_displayShaders
* shaders
,
358 sjme_attrInNullable sjme_pointer shaderData
);
360 sjme_errorCode
sjme_scritchui_fb_intern_renderInScroll(
361 sjme_attrInNotNull sjme_scritchui inState
,
362 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent
,
363 sjme_attrInNotNull sjme_scritchui_pencil g
,
364 sjme_attrInNotNull
const sjme_scritchui_fb_displayList
* dlFull
,
365 sjme_attrInPositive sjme_jint dlCount
,
366 sjme_attrOutNullable sjme_scritchui_rect
* focusRect
,
367 sjme_attrInNullable
const sjme_scritchui_fb_displayShaders
* shaders
,
368 sjme_attrInNullable sjme_pointer shaderData
);
370 /*--------------------------------------------------------------------------*/
374 #ifdef SJME_CXX_SQUIRRELJME_FBINTERN_H
376 #undef SJME_CXX_SQUIRRELJME_FBINTERN_H
377 #undef SJME_CXX_IS_EXTERNED
378 #endif /* #ifdef SJME_CXX_SQUIRRELJME_FBINTERN_H */
379 #endif /* #ifdef __cplusplus */
381 #endif /* SQUIRRELJME_FBINTERN_H */