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 ScritchUI types.
16 #ifndef SQUIRRELJME_SCRITCHUITYPES_H
17 #define SQUIRRELJME_SCRITCHUITYPES_H
19 #include "sjme/atomic.h"
20 #include "lib/scritchui/scritchui.h"
21 #include "lib/scritchui/scritchuiImpl.h"
22 #include "lib/scritchui/scritchuiPencil.h"
23 #include "lib/scritchui/scritchuiPencilFont.h"
24 #include "lib/scritchui/scritchuiText.h"
25 #include "lib/scritchui/scritchuiTypesListener.h"
29 #ifndef SJME_CXX_IS_EXTERNED
30 #define SJME_CXX_IS_EXTERNED
31 #define SJME_CXX_SQUIRRELJME_SCRITCHUITYPES_H
33 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
34 #endif /* #ifdef __cplusplus */
36 /*--------------------------------------------------------------------------*/
39 * The state of the pencil lock.
43 typedef struct sjme_scritchui_pencilLockState
45 /** Spin lock for access to the buffer. */
46 sjme_thread_spinLock spinLock
;
48 /** The times this was opened. */
49 sjme_atomic_sjme_jint count
;
51 /** The front end source for drawing. */
54 /** The base address where drawing should occur. */
57 /** The buffer limit of the base, in bytes. */
58 sjme_jint baseLimitBytes
;
60 /** Is this a copy? */
62 } sjme_scritchui_pencilLockState
;
65 * Base pencil drawing structure.
69 typedef struct sjme_scritchui_pencilBase
72 sjme_scritchui_uiCommonBase common
;
74 /** The current state of the pencil. */
75 sjme_scritchui_pencilState state
;
78 const sjme_scritchui_pencilFunctions
* api
;
80 /** Implementation API. */
81 const sjme_scritchui_pencilImplFunctions
* impl
;
83 /** Utility functions. */
84 const sjme_scritchui_pencilUtilFunctions
* util
;
86 /** Optional locking functions, for buffer access as required. */
87 const sjme_scritchui_pencilLockFunctions
* lock
;
89 /** The lock state. */
90 sjme_scritchui_pencilLockState lockState
;
92 /** Lowest level primitive pencil functions. */
93 sjme_scritchui_pencilPrimFunctions prim
;
95 /** Front end information for paint. */
96 sjme_frontEnd frontEnd
;
98 /** The pixel format used. */
99 sjme_gfx_pixelFormat pixelFormat
;
101 /** Is there an alpha channel? */
102 sjme_jboolean hasAlpha
;
104 /** The default font to use. */
105 sjme_scritchui_pencilFont defaultFont
;
107 /** The width of the surface. */
110 /** The height of the surface. */
113 /** The scanline length, in pixels. */
114 sjme_jint scanLenPixels
;
116 /** The scan line length, in bytes. */
117 sjme_jint scanLenBytes
;
119 /** Bits per pixel. */
120 sjme_jint bitsPerPixel
;
122 /** The bytes per pixel. */
123 sjme_jint bytesPerPixel
;
125 /** Forced X/Y translate. */
126 sjme_scritchui_point forceTranslate
;
128 /** Color palette. */
131 /** The colors available. */
132 const sjme_jint
* colors
;
134 /** The number of colors used. */
137 } sjme_scritchui_pencilBase
;
139 /** The string length of a component ID. */
140 #define SJME_SCRITCHUI_UI_COMPONENT_ID_STRLEN 32
143 * Stores the mouse state.
147 typedef struct sjme_scritchui_uiMouseState
149 /** The mouse buttons being held down. */
150 sjme_jint mouseButtons
;
152 /** The modifiers being held down. */
153 sjme_jint mouseModifiers
;
155 /** Last mouse X position. */
158 /** Last mouse Y position. */
160 } sjme_scritchui_uiMouseState
;
162 typedef struct sjme_scritchui_uiComponentBase
165 sjme_scritchui_uiCommonBase common
;
167 /** The parent of this component. */
168 sjme_scritchui_uiComponent parent
;
170 /** User and core listeners for the component. */
171 sjme_scritchui_uiComponentListeners listeners
[SJME_NUM_SCRITCHUI_LISTENER
];
173 /** The bounds which were set for this component. */
174 sjme_scritchui_rect bounds
;
176 /** String ID for this component. */
177 sjme_cchar strId
[SJME_SCRITCHUI_UI_COMPONENT_ID_STRLEN
];
179 /** General component state. */
182 /** Is this component currently visible? */
183 sjme_jboolean isVisible
;
185 /** Is this visible to the user? */
186 sjme_jboolean isUserVisible
;
188 /** Current and next logical mouse state. */
189 sjme_scritchui_uiMouseState mouse
[2];
191 } sjme_scritchui_uiComponentBase
;
193 /** List of component. */
194 SJME_LIST_DECLARE(sjme_scritchui_uiComponent
, 0);
196 /** Type that component pointers are. */
197 #define SJME_TYPEOF_BASIC_sjme_scritchui_uiComponent \
198 SJME_TYPEOF_BASIC_sjme_pointer
201 * Contains the information of a single item within a choice.
205 typedef struct sjme_scritchui_uiChoiceItemBase
207 /** Is this selected? */
208 sjme_jboolean isSelected
;
210 /** Is this enabled? */
211 sjme_jboolean isEnabled
;
213 /** The string text for the item. */
216 /** The font to display the text in, @c NULL is default. */
217 sjme_scritchui_pencilFont font
;
219 /** The image data, if there is one for this. */
222 /** The dimensions of the image RGB data. */
223 sjme_scritchui_dim imageRgbDim
;
225 /** The number of pixels in the image. */
226 sjme_jint imageRgbNumPixels
;
227 } sjme_scritchui_uiChoiceItemBase
;
229 /** A list of choice items. */
230 SJME_LIST_DECLARE(sjme_scritchui_uiChoiceItem
, 0);
233 * Contains all of the information on choice items.
237 typedef struct sjme_scritchui_uiChoiceBase
239 /** The type of choice this is. */
240 sjme_scritchui_choiceType type
;
242 /** The number of valid entries on the list. */
245 /** The items on this list. */
246 sjme_list_sjme_scritchui_uiChoiceItem
* items
;
247 } sjme_scritchui_uiChoiceBase
;
250 * Base data for containers which may contain components.
254 typedef struct sjme_scritchui_uiContainerBase
256 /** Components within the container. */
257 sjme_list_sjme_scritchui_uiComponent
* components
;
258 } sjme_scritchui_uiContainerBase
;
261 * Base data for anything which may have a label.
265 typedef struct sjme_scritchui_uiLabeledBase
267 /** The current label, which is always a copy. */
269 } sjme_scritchui_uiLabeledBase
;
272 * Base data for lists.
276 typedef struct sjme_scritchui_uiListBase
279 sjme_scritchui_uiComponentBase component
;
281 /** Choice information. */
282 sjme_scritchui_uiChoiceBase choice
;
283 } sjme_scritchui_uiListBase
;
285 /** Menu item list. */
286 SJME_LIST_DECLARE(sjme_scritchui_uiMenuKind
, 0);
288 struct sjme_scritchui_uiMenuKindBase
291 sjme_scritchui_uiCommonBase common
;
293 /** The index of this item in the parent. */
297 struct sjme_scritchui_uiMenuHasChildrenBase
299 /** The number of valid children. */
300 sjme_jint numChildren
;
302 /** The children to this. */
303 sjme_list_sjme_scritchui_uiMenuKind
* children
;
306 struct sjme_scritchui_uiMenuHasParentBase
308 /** The parent menu. */
309 sjme_scritchui_uiMenuKind parent
;
313 * Base data for menus.
317 typedef struct sjme_scritchui_uiMenuBase
319 /** The menu kind information. */
320 sjme_scritchui_uiMenuKindBase menuKind
;
323 sjme_scritchui_uiLabeledBase labeled
;
325 /** Menu children. */
326 sjme_scritchui_uiMenuHasChildrenBase children
;
329 sjme_scritchui_uiMenuHasParentBase parent
;
330 } sjme_scritchui_uiMenuBase
;
333 * Base data for menu bars.
337 typedef struct sjme_scritchui_uiMenuBarBase
339 /** The menu kind information. */
340 sjme_scritchui_uiMenuKindBase menuKind
;
342 /** Menu children. */
343 sjme_scritchui_uiMenuHasChildrenBase children
;
345 /** The window this is within. */
346 sjme_scritchui_uiWindow window
;
347 } sjme_scritchui_uiMenuBarBase
;
350 * Base data for menu items.
354 typedef struct sjme_scritchui_uiMenuItemBase
356 /** The menu kind information. */
357 sjme_scritchui_uiMenuKindBase menuKind
;
360 sjme_scritchui_uiLabeledBase labeled
;
362 /** Menu children. */
363 sjme_scritchui_uiMenuHasChildrenBase children
;
366 sjme_scritchui_uiMenuHasParentBase parent
;
368 /** The accelerator key @c sjme_scritchinput_key , if any. */
371 /** The accelerator modifiers @c sjme_scritchinput_modifier , if any. */
374 /** Some windowing systems need some ID to be specified. */
376 } sjme_scritchui_uiMenuItemBase
;
379 * Base data for paintable components.
383 typedef struct sjme_scritchui_uiPaintableBase
386 sjme_scritchui_uiPaintableListeners listeners
[SJME_NUM_SCRITCHUI_LISTENER
];
388 /** Extra data if needed. */
389 sjme_intPointer extra
;
391 /** Is this currently in paint? */
392 sjme_atomic_sjme_jint inPaint
;
394 /** Belayed painting. */
395 sjme_scritchui_rect belayRect
;
397 /** Last error while in paint. */
398 sjme_errorCode lastError
;
400 /** Pencil drawing information. */
401 sjme_scritchui_pencilBase pencil
;
402 } sjme_scritchui_uiPaintableBase
;
404 typedef struct sjme_scritchui_uiPanelBase
407 sjme_scritchui_uiComponentBase component
;
409 /** Container related. */
410 sjme_scritchui_uiContainerBase container
;
412 /** Paint related. */
413 sjme_scritchui_uiPaintableBase paint
;
415 /** Is focus enabled? */
416 sjme_jboolean enableFocus
;
418 /** Is default focus enabled? */
419 sjme_jboolean defaultFocus
;
420 } sjme_scritchui_uiPanelBase
;
422 typedef struct sjme_scritchui_uiScreenBase
425 sjme_scritchui_uiCommonBase common
;
427 /** The screen Id. */
430 /** Generic display handle such as for X11. */
431 sjme_scritchui_handle displayHandle
;
432 } sjme_scritchui_uiScreenBase
;
434 struct sjme_scritchui_uiViewBase
436 /** User and core listeners for the view. */
437 sjme_scritchui_uiViewListeners listeners
[SJME_NUM_SCRITCHUI_LISTENER
];
439 /** The current view area. */
440 sjme_scritchui_dim area
;
442 /** The current view rectangle. */
443 sjme_scritchui_rect view
;
445 /** The current page size. */
446 sjme_scritchui_dim pageSize
;
449 struct sjme_scritchui_uiScrollPanelBase
452 sjme_scritchui_uiComponentBase component
;
454 /** Container related. */
455 sjme_scritchui_uiContainerBase container
;
457 /** Viewport data. */
458 sjme_scritchui_uiViewBase view
;
461 typedef struct sjme_scritchui_uiWindowBase
464 sjme_scritchui_uiComponentBase component
;
466 /** Container related. */
467 sjme_scritchui_uiContainerBase container
;
470 sjme_scritchui_uiLabeledBase labeled
;
472 /** The current menu bar. */
473 sjme_scritchui_uiMenuBar menuBar
;
476 sjme_scritchui_uiWindowListeners listeners
[SJME_NUM_SCRITCHUI_LISTENER
];
478 /** The minimum window size. */
479 sjme_scritchui_dim min
;
481 /** The window overhead size, to account for menus, titlebar, etc. */
482 sjme_scritchui_dim minOverhead
;
484 /** The component that has the focus. */
485 sjme_scritchui_uiComponent focusedComponent
;
486 } sjme_scritchui_uiWindowBase
;
488 struct sjme_scritchui_pencilFontBase
491 sjme_scritchui_uiCommonBase common
;
493 /** Internal context pointer for implementation needs. */
494 sjme_pointer context
;
497 const sjme_scritchui_pencilFontFunctions
* api
;
499 /** Internal implementation. */
500 const sjme_scritchui_pencilFontImplFunctions
* impl
;
502 /** Font cache details. */
505 /** The name of the font. */
508 /** The face of the font. */
509 sjme_scritchui_pencilFontFace face
;
511 /** The style of the font. */
512 sjme_scritchui_pencilFontStyle style
;
514 /** The pixel size of the font. */
517 /** The height of the font. */
520 /** The baseline of the font. */
523 /** The leading of the font. */
526 /** The ascent of the font. */
529 /** The descent of the font. */
530 sjme_jint descent
[2];
532 /** Font fraction, for pseudo fonts. */
535 /** Inverted font fraction, for pseudo fonts. */
536 sjme_fixed ifraction
;
540 struct sjme_scritchui_textBase
543 sjme_scritchui_uiCommonBase common
;
546 /*--------------------------------------------------------------------------*/
550 #ifdef SJME_CXX_SQUIRRELJME_SCRITCHUITYPES_H
552 #undef SJME_CXX_SQUIRRELJME_SCRITCHUITYPES_H
553 #undef SJME_CXX_IS_EXTERNED
554 #endif /* #ifdef SJME_CXX_SQUIRRELJME_SCRITCHUITYPES_H */
555 #endif /* #ifdef __cplusplus */
557 #endif /* SQUIRRELJME_SCRITCHUITYPES_H */