1 // -*- Mode: Java; 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 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.jvm
.mle
;
12 import cc
.squirreljme
.jvm
.mle
.brackets
.PencilBracket
;
13 import cc
.squirreljme
.jvm
.mle
.brackets
.PencilFontBracket
;
14 import cc
.squirreljme
.jvm
.mle
.callbacks
.NativeImageLoadCallback
;
15 import cc
.squirreljme
.jvm
.mle
.constants
.NativeImageLoadType
;
16 import cc
.squirreljme
.jvm
.mle
.exceptions
.MLECallError
;
17 import cc
.squirreljme
.runtime
.cldc
.annotation
.Api
;
18 import cc
.squirreljme
.runtime
.cldc
.annotation
.SquirrelJMEVendorApi
;
19 import org
.intellij
.lang
.annotations
.MagicConstant
;
20 import org
.jetbrains
.annotations
.CheckReturnValue
;
21 import org
.jetbrains
.annotations
.NotNull
;
22 import org
.jetbrains
.annotations
.Nullable
;
23 import org
.jetbrains
.annotations
.Range
;
26 * This shelf is responsible for accelerated graphics drawing.
31 @SuppressWarnings("UnstableApiUsage")
33 public final class PencilShelf
46 * This copies one region of the image to another region.
48 * Copying to a display device is not permitted because it may impact how
49 * double buffering is implemented, as such it is not supported.
51 * Pixels are copied directly and no alpha compositing is performed.
53 * If the source and destination overlap then it must be as if they did not
54 * overlap at all, this means that the destination will be an exact copy of
57 * @param __g The hardware graphics to draw with.
58 * @param __sx The source X position, will be translated.
59 * @param __sy The source Y position, will be translated.
60 * @param __w The width to copy.
61 * @param __h The height to copy.
62 * @param __dx The destination X position, will be translated.
63 * @param __dy The destination Y position, will be translated.
64 * @param __anchor The anchor point of the destination.
65 * @throws MLECallError If the call is not valid or the native graphics
66 * does not support this operation.
70 public static native void hardwareCopyArea(@NotNull PencilBracket __g
,
72 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
73 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
,
74 int __dx
, int __dy
, int __anchor
)
78 * This draws the outer edge of the ellipse from the given angles using
79 * the color, alpha, and stroke style.
81 * The coordinates are treated as if they were in a rectangular region. As
82 * such the center of the ellipse to draw the outline of is in the center
83 * of the specified rectangle.
85 * Note that no lines are drawn to the center point, so the shape does not
86 * result in a pie slice.
88 * The angles are in degrees and visually the angles match those of the
89 * unit circle correctly transformed to the output surface. As such, zero
90 * degrees has the point of {@code (__w, __h / 2)}, that is it points to
91 * the right. An angle at 45 degrees will always point to the top right
94 * If the width or height are zero, then nothing is drawn. The arc will
95 * cover an area of {@code __w + 1} and {@code __h + 1}.
97 * @param __g The hardware graphics to draw with.
98 * @param __x The X position of the upper left corner, will be translated.
99 * @param __y The Y position of the upper left corner, will be translated.
100 * @param __w The width of the arc.
101 * @param __h The height of the arc.
102 * @param __startAngle The starting angle in degrees,
103 * @param __arcAngle The offset from the starting angle, negative values
104 * indicate clockwise direction while positive values are counterclockwise.
105 * @throws MLECallError If the pencil is not valid; or the arc requested
106 * to draw is not valid.
109 @SquirrelJMEVendorApi
110 public static native void hardwareDrawArc(@NotNull PencilBracket __g
,
112 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
113 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
,
119 * Draws the given characters.
121 * @param __g The hardware graphics to draw with.
122 * @param __s The characters to draw.
123 * @param __o The offset into the buffer.
124 * @param __l The number of characters to draw.
125 * @param __x The X position.
126 * @param __y The Y position.
127 * @param __anchor The anchor point.
128 * @throws MLECallError If the graphics is not valid, does not support
129 * the given operation, if the anchor point is not valid, or if the
130 * offset and/or length are out of bounds.
133 @SquirrelJMEVendorApi
134 public static native void hardwareDrawChars(@NotNull PencilBracket __g
,
136 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __o
,
137 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __l
,
138 int __x
, int __y
, int __anchor
)
142 * Draws a horizontal line in hardware.
144 * @param __g The graphics to draw with.
145 * @param __x The X coordinate.
146 * @param __y The Y coordinate.
147 * @param __w The width of the line.
148 * @throws MLECallError On null arguments; if the pencil is not valid; or
149 * the width is negative.
152 @SquirrelJMEVendorApi
153 public static native void hardwareDrawHoriz(@NotNull PencilBracket __g
,
154 int __x
, int __y
, @Range(from
= 1, to
= Integer
.MAX_VALUE
) int __w
)
158 * Draws a line in hardware.
160 * @param __g The hardware graphics to draw with.
161 * @param __x1 The starting X coordinate.
162 * @param __y1 The starting Y coordinate.
163 * @param __x2 The ending X coordinate.
164 * @param __y2 The ending Y coordinate.
165 * @throws MLECallError On null arguments.
168 @SquirrelJMEVendorApi
169 public static native void hardwareDrawLine(@NotNull PencilBracket __g
,
170 int __x1
, int __y1
, int __x2
, int __y2
)
174 * Draws a single pixel.
176 * @param __g The graphics to draw on.
177 * @param __x The X coordinate.
178 * @param __y The y coordinate.
179 * @throws MLECallError On null arguments or if the pencil is not valid.
182 @SquirrelJMEVendorApi
183 public static native void hardwareDrawPixel(@NotNull PencilBracket __g
,
188 * Draws the outline of a polygon.
190 * @param __g The graphics to draw with.
191 * @param __x The X coordinate.
192 * @param __xOff The offset into the X array.
193 * @param __y The Y coordinate.
194 * @param __yOff The offset into the Y array.
195 * @param __n The number of sides to draw.
196 * @throws MLECallError If the graphics is not valid; or if the sides
200 @SquirrelJMEVendorApi
201 public static native void hardwareDrawPolyline(@NotNull PencilBracket __g
,
203 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __xOff
,
205 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __yOff
,
206 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __n
)
210 * Draws the outline of the given rectangle using the current color and
211 * stroke style. The rectangle will cover an area that is
212 * {@code [width + 1, height + 1]}.
214 * Nothing is drawn if the width and/or height are zero.
216 * @param __g The hardware graphics to draw with.
217 * @param __x The X coordinate.
218 * @param __y The Y coordinate.
219 * @param __w The width.
220 * @param __h The height.
221 * @throws MLECallError If the graphics is not valid or does not support
222 * the given operation.
225 @SquirrelJMEVendorApi
226 public static native void hardwareDrawRect(@NotNull PencilBracket __g
,
228 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
229 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
)
233 * Draws a round rectangle.
235 * If the width and/or height are zero or negative, nothing is drawn.
237 * @param __x The X coordinate.
238 * @param __y The Y coordinate.
239 * @param __w The width of the rectangle.
240 * @param __h The height of the rectangle.
241 * @param __arcWidth The horizontal diameter of the arc on the corners.
242 * @param __arcHeight The vertical diameter of the arc on the corners.
243 * @throws MLECallError If the pencil is invalid; or if the requested
244 * round rectangle is not valid.
247 @SquirrelJMEVendorApi
248 public static native void hardwareDrawRoundRect(@NotNull PencilBracket __g
,
250 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
251 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
,
252 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __arcWidth
,
253 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __arcHeight
)
257 * Draws the given substring.
259 * @param __g The hardware graphics to draw with.
260 * @param __s The string to draw.
261 * @param __o The offset into the string.
262 * @param __l The offset into the length.
263 * @param __x The X coordinate.
264 * @param __y The Y coordinate.
265 * @param __anchor The anchor point.
266 * @throws MLECallError If the graphics is not valid, this operation is
267 * not supported, or on null arguments, or if the offset and/or length are
268 * negative or exceed the string bounds.
271 @SquirrelJMEVendorApi
272 public static native void hardwareDrawSubstring(@NotNull PencilBracket __g
,
274 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __o
,
275 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __l
,
276 int __x
, int __y
, int __anchor
)
280 * Draws a region of 32-bit RGB data into the target.
282 * @param __hardware The hardware graphics to draw with.
283 * @param __data The source buffer.
284 * @param __off The offset into the buffer.
285 * @param __scanLen The scanline length.
286 * @param __alpha Drawing with the alpha channel?
287 * @param __xSrc The source X position.
288 * @param __ySrc The source Y position.
289 * @param __wSrc The width of the source region.
290 * @param __hSrc The height of the source region.
291 * @param __trans Sprite translation and/or rotation, see
292 * {@code javax.microedition.lcdui.game.Sprite}.
293 * @param __xDest The destination X position, is translated.
294 * @param __yDest The destination Y position, is translated.
295 * @param __anchor The anchor point.
296 * @param __wDest The destination width.
297 * @param __hDest The destination height.
298 * @param __origImgWidth Original image width.
299 * @param __origImgHeight Original image height.
300 * @throws MLECallError On null arguments.
303 @SquirrelJMEVendorApi
304 public static native void hardwareDrawXRGB32Region(
305 @NotNull PencilBracket __hardware
, @NotNull int[] __data
,
306 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __off
,
307 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __scanLen
,
308 boolean __alpha
, int __xSrc
, int __ySrc
,
309 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __wSrc
,
310 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __hSrc
,
311 int __trans
, int __xDest
, int __yDest
, int __anchor
,
312 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __wDest
,
313 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __hDest
,
314 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __origImgWidth
,
315 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __origImgHeight
)
319 * This draws the filled slice of an ellipse (like a pie slice) from the
320 * given angles using the color, alpha, and stroke style.
322 * Unlike {@link #hardwareDrawArc(PencilBracket, int, int, int, int, int,
323 * int)}, the width and height are not increased by a single pixel.
325 * Otherwise, this follows the same set of rules as
326 * {@link #hardwareDrawArc(PencilBracket, int, int, int, int, int, int)}.
328 * @param __g The hardware graphics to draw with.
329 * @param __x The X position of the upper left corner, will be translated.
330 * @param __y The Y position of the upper left corner, will be translated.
331 * @param __w The width of the arc.
332 * @param __h The height of the arc.
333 * @param __startAngle The starting angle in degrees,
334 * @param __arcAngle The offset from the starting angle, negative values
335 * indicate clockwise direction while positive values are counterclockwise.
336 * @see #hardwareDrawArc(PencilBracket, int, int, int, int, int, int)
337 * @throws MLECallError If the pencil is not valid; or if the requested
342 public static native void hardwareFillArc(@NotNull PencilBracket __g
,
344 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
345 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
,
346 int __startAngle
, int __arcAngle
)
350 * Draws a filled polygon in the same manner
351 * as {@link #hardwareDrawPolyline(PencilBracket, int[], int, int[],
354 * @param __g The graphics to draw with.
355 * @param __x The X coordinate.
356 * @param __xOff The offset into the X array.
357 * @param __y The Y coordinate.
358 * @param __yOff The offset into the Y array.
359 * @param __n The number of sides to draw.
360 * @throws MLECallError If the graphics is not valid; if the sides
361 * are not valid; or if the values are out of bounds of the array.
364 @SquirrelJMEVendorApi
365 public static native void hardwareFillPolygon(@NotNull PencilBracket __g
,
367 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __xOff
,
369 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __yOff
,
370 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __n
)
374 * Performs rectangular fill in hardware.
376 * @param __g The hardware graphics to draw with.
377 * @param __x The X coordinate.
378 * @param __y The Y coordinate.
379 * @param __w The width.
380 * @param __h The height.
381 * @throws MLECallError On {@code null} arguments.
384 @SquirrelJMEVendorApi
385 public static native void hardwareFillRect(@NotNull PencilBracket __g
,
387 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
388 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
)
392 * Draws a filled round rectangle in the same manner
393 * as {@link #hardwareDrawRoundRect(PencilBracket, int, int, int, int,
396 * @param __g The graphics to use.
397 * @param __x The X coordinate.
398 * @param __y The Y coordinate.
399 * @param __w The width.
400 * @param __h The height.
401 * @param __arcWidth The width of the arc at each corner.
402 * @param __arcHeight The height of the arc at each corner.
403 * @throws MLECallError If the graphics is not valid; or the requested
404 * round rectangle is not valid.
408 public static native void hardwareFillRoundRect(@NotNull PencilBracket __g
,
410 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
411 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
,
417 * Draws a filled triangle using the current color, the lines which make
418 * up the triangle are included in the filled area.
420 * @param __g The graphics to use for drawing.
421 * @param __x1 First X coordinate.
422 * @param __y1 First Y coordinate.
423 * @param __x2 Second X coordinate.
424 * @param __y2 Second Y coordinate.
425 * @param __x3 Third X coordinate.
426 * @param __y3 Third Y coordinate.
427 * @throws MLECallError If no graphics were specified or the graphics does
428 * not actually support the given operation.
431 @SquirrelJMEVendorApi
432 public static native void hardwareFillTriangle(@NotNull PencilBracket __g
,
433 int __x1
, int __y1
, int __x2
, int __y2
, int __x3
, int __y3
)
437 * Is there an alpha channel for this pencil?
439 * @param __g The graphics to check.
440 * @return If there is an alpha channel or not.
441 * @throws MLECallError On null arguments or if the pencil is not valid.
444 @SquirrelJMEVendorApi
445 public static native boolean hardwareHasAlpha(@NotNull PencilBracket __g
)
449 * Sets the alpha color for graphics.
451 * @param __g The hardware graphics to draw with.
452 * @param __argb The color to set.
453 * @throws MLECallError On {@code null} arguments.
456 @SquirrelJMEVendorApi
457 public static native void hardwareSetAlphaColor(@NotNull PencilBracket __g
,
462 * Sets the blending mode to use.
464 * @param __g The hardware graphics to draw with.
465 * @param __mode The blending mode to use.
466 * @throws MLECallError On {@code null} arguments.
469 @SquirrelJMEVendorApi
470 public static native void hardwareSetBlendingMode(
471 @NotNull PencilBracket __g
, int __mode
)
475 * Sets the clipping rectangle position.
477 * @param __g The hardware graphics to draw with.
478 * @param __x The X coordinate.
479 * @param __y The Y coordinate.
480 * @param __w The width.
481 * @param __h The height.
482 * @throws MLECallError On {@code null} arguments.
485 @SquirrelJMEVendorApi
486 public static native void hardwareSetClip(@NotNull PencilBracket __g
,
488 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __w
,
489 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __h
)
493 * Sets that the graphics should now use the default font.
495 * @param __g The graphics used.
496 * @throws MLECallError If the graphics is not valid or does not support
500 @SquirrelJMEVendorApi
501 public static native void hardwareSetDefaultFont(
502 @NotNull PencilBracket __g
)
506 * Sets to use the specified font.
508 * @param __g The graphics used.
509 * @param __font The font to set.
510 * @throws MLECallError If the graphics is not valid or does not support
514 @SquirrelJMEVendorApi
515 public static native void hardwareSetFont(@NotNull PencilBracket __g
,
516 @NotNull PencilFontBracket __font
)
520 * Sets the stroke style for the hardware graphics.
522 * @param __g The hardware graphics to draw with.
523 * @param __style The stroke type to set.
524 * @throws MLECallError On {@code null} arguments.
527 @SquirrelJMEVendorApi
528 public static native void hardwareSetStrokeStyle(
529 @NotNull PencilBracket __g
,
534 * Translates drawing operations.
536 * @param __g The hardware graphics to draw with.
537 * @param __x The X translation.
538 * @param __y The Y translation.
539 * @throws MLECallError On {@code null} arguments.
542 @SquirrelJMEVendorApi
543 public static native void hardwareTranslate(@NotNull PencilBracket __g
,
548 * Returns the current hardware translation.
550 * @param __g The pencil to read from.
551 * @param __y Read the Y coordinate?
552 * @return The current translation.
553 * @throws MLECallError If the pencil is not valid.
556 @SquirrelJMEVendorApi
557 public static native int hardwareTranslateXY(@NotNull PencilBracket __g
,
562 * Performs native image loading
564 * @param __type The {@link NativeImageLoadType} to load.
565 * @param __b The buffer.
566 * @param __o The offset.
567 * @param __l The length.
568 * @param __callback The callback that performs the image loading.
569 * @return The object returned will be passed through the callback from
570 * the native callback, should return {@code null} if the load has been
572 * @throws MLECallError If the image could not be loaded.
573 * @see NativeImageLoadCallback
576 @SquirrelJMEVendorApi
578 public static native Object
nativeImageLoadRGBA(
579 @MagicConstant(valuesFromClass
= NativeImageLoadType
.class) int __type
,
581 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __o
,
582 @Range(from
= 0, to
= Integer
.MAX_VALUE
) int __l
,
583 @NotNull NativeImageLoadCallback __callback
)
587 * Returns a bit field of {@link NativeImageLoadType} which indicates which
588 * types of images are capable of being natively loaded on a platform
589 * which requiring byte code to be executed for it.
591 * @return The bit field of {@link NativeImageLoadType} that can be
595 @SquirrelJMEVendorApi
597 @MagicConstant(valuesFromClass
= NativeImageLoadType
.class)
598 public static native int nativeImageLoadTypes();