Revert StaticDisplayState; For hosted only allow debug to be used.
[SquirrelJME.git] / modules / midp-lcdui / src / main / java / cc / squirreljme / runtime / lcdui / gfx / SerializedGraphics.java
blobc8203a33ad9e40ce4ce0e1719c074400619be052
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.runtime.lcdui.gfx;
12 import cc.squirreljme.runtime.cldc.debug.Debugging;
13 import java.io.ByteArrayInputStream;
14 import java.io.ByteArrayOutputStream;
15 import java.io.DataInputStream;
16 import java.io.DataOutputStream;
17 import java.io.IOException;
18 import javax.microedition.lcdui.Font;
19 import javax.microedition.lcdui.Graphics;
20 import javax.microedition.lcdui.Image;
21 import javax.microedition.lcdui.Text;
23 /**
24 * This class takes any input graphics operations that were performed for it,
25 * serializing anything that was sent to it. The serialized graphics can be
26 * forwarded somewhere for example for later deserialization.
28 * Translation is performed locally to the graphics and wherever the graphics
29 * target is, it will not have translation forwarded and serialized to simplify
30 * the target.
32 * @since 2018/11/19
34 @SuppressWarnings({"ManualMinMaxCalculation", "MagicNumber"})
35 @Deprecated
36 public abstract class SerializedGraphics
37 extends Graphics
39 /** X translation. */
40 protected int transx;
42 /** Y translation. */
43 protected int transy;
45 /**
46 * This method is called for any operation which serializes to graphics.
48 * @param __func The graphics operation to perform.
49 * @param __args The input arguments to the function.
50 * @return Any result from the operation.
51 * @since 2018/11/19
53 public abstract Object serialize(GraphicsFunction __func,
54 Object... __args);
56 /**
57 * {@inheritDoc}
58 * @since 2018/11/19
60 @Override
61 public void clipRect(int __x, int __y, int __w, int __h)
63 int transx = this.transx,
64 transy = this.transy;
66 // Calculate the actual desired clip location
67 int nx = __x + transx,
68 ny = __y + transy,
69 na = nx + __w,
70 nb = ny + __h;
72 // Get the current clip location
73 int cx = this.__getClipX(),
74 cy = this.__getClipY(),
75 ca = cx + this.getClipWidth(),
76 cb = cy + this.getClipHeight();
78 // Use direct set clip but with the correct coordinates
79 int bx = (nx > cx ? nx : cx),
80 by = (ny > cy ? ny : cy);
81 this.serialize(GraphicsFunction.SET_CLIP,
82 bx,
83 by,
84 (na < ca ? na : ca) - bx,
85 (nb < cb ? nb : cb) - by);
88 /**
89 * {@inheritDoc}
90 * @since 2018/11/19
92 @Override
93 public void copyArea(int __sx, int __sy, int __w, int __h,
94 int __dx, int __dy, int __anchor)
95 throws IllegalArgumentException, IllegalStateException
97 int transx = this.transx,
98 transy = this.transy;
100 this.serialize(GraphicsFunction.COPY_AREA,
101 __sx + transx, __sy + transy, __w, __h,
102 __dx + transx, __dy + transy, __anchor);
106 * {@inheritDoc}
107 * @since 2018/11/19
109 @Override
110 public void drawArc(int __x, int __y, int __w, int __h, int __sa,
111 int __aa)
113 int transx = this.transx,
114 transy = this.transy;
116 this.serialize(GraphicsFunction.DRAW_ARC,
117 __x + transx, __y + transy, __w, __h, __sa, __aa);
121 * {@inheritDoc}
122 * @since 2018/11/19
124 @Override
125 public void drawARGB16(short[] __data, int __off, int __scanlen,
126 int __x, int __y, int __w, int __h)
127 throws NullPointerException
129 int transx = this.transx,
130 transy = this.transy;
132 this.serialize(GraphicsFunction.DRAW_ARGB16,
133 __data, __off, __scanlen, __x + transx, __y + transy, __w, __h);
137 * {@inheritDoc}
138 * @since 2018/11/19
140 @Override
141 public void drawChar(char __s, int __x, int __y, int __anchor)
143 int transx = this.transx,
144 transy = this.transy;
146 this.serialize(GraphicsFunction.DRAW_CHAR,
147 (int)__s, __x + transx, __y + transy, __anchor);
151 * {@inheritDoc}
152 * @since 2018/11/19
154 @Override
155 public void drawChars(char[] __s, int __o, int __l, int __x,
156 int __y, int __anchor)
157 throws NullPointerException
159 int transx = this.transx,
160 transy = this.transy;
162 this.serialize(GraphicsFunction.DRAW_CHARS,
163 __s, __o, __l, __x + transx, __y + transy, __anchor);
167 * {@inheritDoc}
168 * @since 2018/11/19
170 @Override
171 public void drawImage(Image __i, int __x, int __y, int __anchor)
172 throws IllegalArgumentException, NullPointerException
174 if (__i == null)
175 throw new NullPointerException("NARG");
177 this.drawRegion(__i, 0, 0, __i.getWidth(), __i.getHeight(), 0,
178 __x, __y, __anchor);
182 * {@inheritDoc}
183 * @since 2018/11/19
185 @Override
186 public void drawLine(int __x1, int __y1, int __x2, int __y2)
188 int transx = this.transx,
189 transy = this.transy;
191 this.serialize(GraphicsFunction.DRAW_LINE,
192 __x1 + transx, __y1 + transy, __x2 + transx, __y2 + transy);
196 * {@inheritDoc}
197 * @since 2018/11/19
199 @Override
200 public void drawRGB(int[] __data, int __off, int __scanlen,
201 int __x, int __y, int __w, int __h, boolean __alpha)
202 throws NullPointerException
204 int transx = this.transx,
205 transy = this.transy;
207 this.serialize(GraphicsFunction.DRAW_RGB,
208 __data, __off, __scanlen, __x + transx, __y + transy,
209 __w, __h, (__alpha ? 1 : 0));
213 * {@inheritDoc}
214 * @since 2018/11/19
216 @Override
217 public void drawRGB16(short[] __data, int __off, int __scanlen,
218 int __x, int __y, int __w, int __h)
219 throws NullPointerException
221 int transx = this.transx,
222 transy = this.transy;
224 this.serialize(GraphicsFunction.DRAW_RGB16,
225 __data, __off, __scanlen, __x + transx, __y + transy, __w, __h);
229 * {@inheritDoc}
230 * @since 2018/11/19
232 @Override
233 public void drawRect(int __x, int __y, int __w, int __h)
235 int transx = this.transx,
236 transy = this.transy;
238 this.serialize(GraphicsFunction.DRAW_RECT,
239 __x + transx, __y + transy, __w, __h);
243 * {@inheritDoc}
244 * @since 2018/11/19
246 @Override
247 public void drawRegion(Image __src, int __xsrc, int __ysrc,
248 int __wsrc, int __hsrc, int __trans, int __xdest, int __ydest,
249 int __anch)
250 throws IllegalArgumentException, NullPointerException
252 if (__src == null)
253 throw new NullPointerException("NARG");
255 this.drawRegion(__src, __xsrc, __ysrc, __wsrc, __hsrc, __trans,
256 __xdest, __ydest, __anch, __wsrc, __hsrc);
260 * {@inheritDoc}
261 * @since 2018/11/19
263 @Override
264 public void drawRegion(Image __src, int __xsrc, int __ysrc,
265 int __wsrc, int __hsrc, int __trans, int __xdest, int __ydest,
266 int __anch, int __wdest, int __hdest)
267 throws IllegalArgumentException, NullPointerException
269 if (__src == null)
270 throw new NullPointerException("NARG");
272 int transx = this.transx,
273 transy = this.transy;
275 // Extract image pixel data before sending over
276 int numpixels = __wsrc * __hsrc;
277 int[] data = new int[numpixels];
278 __src.getRGB(data, 0, __wsrc, __xsrc, __ysrc, __wsrc, __hsrc);
280 // {@squirreljme.error EB0l Illegal region draw.}
281 int rv = (Integer)this.serialize(GraphicsFunction.DRAW_REGION,
282 data, (__wsrc << 16) | __hsrc, __trans,
283 __xdest + transx, __ydest + transy,
284 __anch, (__wdest << 16) | __hdest);
285 if (rv < 0)
286 throw new IllegalArgumentException("EB0l");
290 * {@inheritDoc}
291 * @since 2018/11/19
293 @Override
294 public void drawRoundRect(int __x, int __y, int __w, int __h,
295 int __aw, int __ah)
297 int transx = this.transx,
298 transy = this.transy;
300 this.serialize(GraphicsFunction.DRAW_ROUND_RECT,
301 __x + transx, __y + transy, __w, __h, __aw, __ah);
305 * {@inheritDoc}
306 * @since 2018/11/19
308 @Override
309 public void drawString(String __s, int __x, int __y,
310 int __anchor)
311 throws NullPointerException
313 // Just pass the chars of the string since we cannot represent
314 // string at all
315 this.serialize(GraphicsFunction.DRAW_SUB_CHARS,
316 __s.toCharArray(), 0, __s.length(), __x, __y, __anchor);
320 * {@inheritDoc}
321 * @since 2018/11/19
323 @Override
324 public void drawSubstring(String __s, int __o, int __l, int __x,
325 int __y, int __anchor)
326 throws NullPointerException, StringIndexOutOfBoundsException
328 // Just pass the chars of the string since we cannot represent
329 // string at all
330 this.serialize(GraphicsFunction.DRAW_SUB_CHARS,
331 __s.toCharArray(), __o, __l, __x, __y, __anchor);
335 * {@inheritDoc}
336 * @since 2018/11/19
338 @Override
339 public void drawText(Text __t, int __x, int __y)
341 this.serialize(GraphicsFunction.DRAW_TEXT,
342 SerializedGraphics.textSerialize(__t), __x, __y);
346 * {@inheritDoc}
347 * @since 2018/11/19
349 @Override
350 public void fillArc(int __x, int __y, int __w, int __h, int __sa,
351 int __aa)
353 this.serialize(GraphicsFunction.FILL_ARC,
354 __x, __y, __w, __h, __sa, __aa);
358 * {@inheritDoc}
359 * @since 2018/11/19
361 @Override
362 public void fillRect(int __x, int __y, int __w, int __h)
364 this.serialize(GraphicsFunction.FILL_RECT,
365 __x, __y, __w, __h);
369 * {@inheritDoc}
370 * @since 2018/11/19
372 @Override
373 public void fillRoundRect(int __x, int __y, int __w, int __h,
374 int __aw, int __ah)
376 this.serialize(GraphicsFunction.FILL_ROUND_RECT,
377 __x, __y, __w, __h, __aw, __ah);
381 * {@inheritDoc}
382 * @since 2018/11/19
384 @Override
385 public void fillTriangle(int __x1, int __y1, int __x2, int __y2,
386 int __x3, int __y3)
388 this.serialize(GraphicsFunction.FILL_TRIANGLE,
389 __x1, __y1, __x2, __y2, __x3, __y3);
393 * {@inheritDoc}
394 * @since 2018/11/19
396 @Override
397 public int getAlpha()
399 return (this.getAlphaColor() >> 24) & 0xFF;
403 * {@inheritDoc}
404 * @since 2018/11/19
406 @Override
407 public int getAlphaColor()
409 return (Integer)this.serialize(GraphicsFunction.GET_ALPHA_COLOR);
413 * {@inheritDoc}
414 * @since 2018/11/19
416 @Override
417 public int getBlendingMode()
419 return (Integer)this.serialize(GraphicsFunction.GET_BLENDING_MODE);
423 * {@inheritDoc}
424 * @since 2018/11/19
426 @Override
427 public int getBlueComponent()
429 return (this.getAlphaColor()) & 0xFF;
433 * {@inheritDoc}
434 * @since 2018/11/19
436 @Override
437 public int getClipHeight()
439 return (Integer)this.serialize(GraphicsFunction.GET_CLIP_HEIGHT);
443 * {@inheritDoc}
444 * @since 2018/11/19
446 @Override
447 public int getClipWidth()
449 return (Integer)this.serialize(GraphicsFunction.GET_CLIP_WIDTH);
453 * {@inheritDoc}
454 * @since 2018/11/19
456 @Override
457 public int getClipX()
459 return this.__getClipX() - this.transx;
463 * {@inheritDoc}
464 * @since 2018/11/19
466 @Override
467 public int getClipY()
469 return this.__getClipY() - this.transy;
473 * {@inheritDoc}
474 * @since 2018/11/19
476 @Override
477 public int getColor()
479 return this.getAlphaColor() & 0xFFFFFF;
483 * {@inheritDoc}
484 * @since 2018/11/19
486 @Override
487 public int getDisplayColor(int __rgb)
489 return (Integer)this.serialize(GraphicsFunction.GET_DISPLAY_COLOR,
490 __rgb);
494 * {@inheritDoc}
495 * @since 2018/11/19
497 @Override
498 public Font getFont()
500 return SerializedGraphics.fontDeserialize(
501 (byte[])this.serialize(GraphicsFunction.GET_FONT));
505 * {@inheritDoc}
506 * @since 2018/11/19
508 @Override
509 public int getGrayScale()
511 return (this.getRedComponent() + this.getGreenComponent() +
512 this.getBlueComponent()) / 3;
516 * {@inheritDoc}
517 * @since 2018/11/19
519 @Override
520 public int getGreenComponent()
522 return (this.getAlphaColor() >> 8) & 0xFF;
526 * {@inheritDoc}
527 * @since 2018/11/19
529 @Override
530 public int getRedComponent()
532 return (this.getAlphaColor() >> 16) & 0xFF;
536 * {@inheritDoc}
537 * @since 2018/11/19
539 @Override
540 public int getStrokeStyle()
542 return (Integer)this.serialize(GraphicsFunction.GET_STROKE_STYLE);
546 * {@inheritDoc}
547 * @since 2018/11/19
549 @Override
550 public int getTranslateX()
552 return this.transx;
556 * {@inheritDoc}
557 * @since 2018/11/19
559 @Override
560 public int getTranslateY()
562 return this.transy;
566 * {@inheritDoc}
567 * @since 2018/11/19
569 @Override
570 public void setAlpha(int __a)
571 throws IllegalArgumentException
573 this.setAlphaColor(__a, this.getRedComponent(),
574 this.getGreenComponent(), this.getBlueComponent());
578 * {@inheritDoc}
579 * @since 2018/11/19
581 @Override
582 public void setAlphaColor(int __argb)
584 this.serialize(GraphicsFunction.SET_ALPHA_COLOR, __argb);
588 * {@inheritDoc}
589 * @since 2018/11/19
591 @Override
592 public void setAlphaColor(int __a, int __r, int __g, int __b)
593 throws IllegalArgumentException
595 this.serialize(GraphicsFunction.SET_ALPHA_COLOR,
596 ((__a & 0xFF) << 24) |
597 ((__r & 0xFF) << 16) |
598 ((__g & 0xFF) << 8) |
599 (__b & 0xFF));
603 * {@inheritDoc}
604 * @since 2018/11/19
606 @Override
607 public void setBlendingMode(int __m)
608 throws IllegalArgumentException
610 // {@squirreljme.error EB0m Failed to set blending mode.}
611 int okay = (Integer)this.serialize(GraphicsFunction.SET_BLENDING_MODE,
612 __m);
613 if (okay < 0)
614 throw new IllegalArgumentException("EB0m");
618 * {@inheritDoc}
619 * @since 2018/11/19
621 @Override
622 public void setClip(int __x, int __y, int __w, int __h)
624 int transx = this.transx,
625 transy = this.transy;
627 this.serialize(GraphicsFunction.SET_CLIP,
628 __x + transx, __y + transy, __w, __h);
632 * {@inheritDoc}
633 * @since 2018/11/19
635 @Override
636 public void setColor(int __rgb)
638 this.serialize(GraphicsFunction.SET_COLOR, __rgb);
642 * {@inheritDoc}
643 * @since 2018/11/19
645 @Override
646 public void setColor(int __r, int __g, int __b)
647 throws IllegalArgumentException
649 this.serialize(GraphicsFunction.SET_COLOR,
650 ((__r & 0xFF) << 16) |
651 ((__g & 0xFF) << 8) |
652 (__b & 0xFF));
656 * {@inheritDoc}
657 * @since 2018/11/19
659 @Override
660 public void setFont(Font __font)
662 // Default?
663 if (__font == null)
664 __font = Font.getDefaultFont();
666 // Serialize it
667 this.serialize(GraphicsFunction.SET_FONT,
668 SerializedGraphics.fontSerialize(__font));
672 * {@inheritDoc}
673 * @since 2018/11/19
675 @Override
676 public void setGrayScale(int __v)
678 this.setAlphaColor(this.getAlpha(), __v, __v, __v);
682 * {@inheritDoc}
683 * @since 2018/11/19
684 * @param __s
686 @Override
687 public void setStrokeStyle(int __s)
688 throws IllegalArgumentException
690 // {@squirreljme.error EB0n Failed to set stroke style.}
691 int okay = (Integer)this.serialize(GraphicsFunction.SET_STROKE_STYLE,
692 __s);
693 if (okay < 0)
694 throw new IllegalArgumentException("EB0n");
698 * {@inheritDoc}
699 * @since 2018/11/19
701 @Override
702 public void translate(int __x, int __y)
704 this.transx += __x;
705 this.transy += __y;
709 * Returns the raw clipping X of the target.
711 * @return The target clipping.
712 * @since 2020/01/10
714 private int __getClipX()
716 return (Integer)this.serialize(GraphicsFunction.GET_CLIP_X);
720 * Returns the raw clipping Y of the target.
722 * @return The target clipping.
723 * @since 2020/01/10
725 private int __getClipY()
727 return (Integer)this.serialize(GraphicsFunction.GET_CLIP_Y);
731 * Deserializes the input operation arguments and performs the call on
732 * the destination graphics.
734 * @param __g The destination graphics object.
735 * @param __func The graphics function to call.
736 * @param __args Arguments to the function.
737 * @return The result of the call.
738 * @throws NullPointerException On null arguments.
739 * @since 2018/11/19
741 public static Object deserialize(Graphics __g, GraphicsFunction __func,
742 Object... __args)
743 throws IllegalArgumentException, NullPointerException
745 if (__g == null || __func == null)
746 throw new NullPointerException("NARG");
748 // Depends on the function
749 switch (__func)
751 case SET_COLOR:
752 __g.setColor(
753 (Integer)__args[0]);
754 return null;
756 case DRAW_LINE:
757 __g.drawLine(
758 (Integer)__args[0],
759 (Integer)__args[1],
760 (Integer)__args[2],
761 (Integer)__args[3]);
762 return null;
764 case GET_CLIP_X:
765 return __g.getClipX();
767 case GET_CLIP_Y:
768 return __g.getClipY();
770 case GET_CLIP_WIDTH:
771 return __g.getClipWidth();
773 case GET_CLIP_HEIGHT:
774 return __g.getClipHeight();
776 case SET_CLIP:
777 __g.setClip(
778 (Integer)__args[0],
779 (Integer)__args[1],
780 (Integer)__args[2],
781 (Integer)__args[3]);
782 return null;
784 // Draw rectangle
785 case DRAW_RECT:
786 __g.drawRect(
787 (Integer)__args[0],
788 (Integer)__args[1],
789 (Integer)__args[2],
790 (Integer)__args[3]);
791 return null;
793 // Get alpha color
794 case GET_ALPHA_COLOR:
795 return __g.getAlphaColor();
797 // Set alpha color
798 case SET_ALPHA_COLOR:
799 __g.setAlphaColor((Integer)__args[0]);
800 return null;
802 // Fill rectangle
803 case FILL_RECT:
804 __g.fillRect(
805 (Integer)__args[0],
806 (Integer)__args[1],
807 (Integer)__args[2],
808 (Integer)__args[3]);
809 return null;
811 // Set font
812 case SET_FONT:
813 __g.setFont(SerializedGraphics.fontDeserialize(
814 (byte[])__args[0]));
815 return null;
817 // Get font
818 case GET_FONT:
819 return SerializedGraphics.fontSerialize(__g.getFont());
821 // Draw sub-characters
822 case DRAW_SUB_CHARS:
823 __g.drawChars(
824 (char[])__args[0],
825 (Integer)__args[1],
826 (Integer)__args[2],
827 (Integer)__args[3],
828 (Integer)__args[4],
829 (Integer)__args[5]);
830 return null;
832 // Draw text
833 case DRAW_TEXT:
834 __g.drawText(
835 SerializedGraphics.textDeserialize((byte[])__args[0]),
836 (Integer)__args[1],
837 (Integer)__args[2]);
838 return null;
840 // Get stroke style
841 case GET_STROKE_STYLE:
842 return __g.getStrokeStyle();
844 // Set stroke style
845 case SET_STROKE_STYLE:
848 __g.setStrokeStyle((Integer)__args[0]);
850 catch (IllegalArgumentException e)
852 return -1;
854 return 0;
856 // Copy area.
857 case COPY_AREA:
858 __g.copyArea(
859 (Integer)__args[0],
860 (Integer)__args[1],
861 (Integer)__args[2],
862 (Integer)__args[3],
863 (Integer)__args[4],
864 (Integer)__args[5],
865 (Integer)__args[6]);
866 return null;
868 // Draw arc.
869 case DRAW_ARC:
870 __g.drawArc(
871 (Integer)__args[0],
872 (Integer)__args[1],
873 (Integer)__args[2],
874 (Integer)__args[3],
875 (Integer)__args[4],
876 (Integer)__args[5]);
877 return null;
879 // Draw ARGB16.
880 case DRAW_ARGB16:
881 __g.drawARGB16(
882 (short[])__args[0],
883 (Integer)__args[1],
884 (Integer)__args[2],
885 (Integer)__args[3],
886 (Integer)__args[4],
887 (Integer)__args[5],
888 (Integer)__args[6]);
889 return null;
891 // Draw character.
892 case DRAW_CHAR:
893 __g.drawChar(
894 (char)(((Integer)__args[0]).intValue()),
895 (Integer)__args[1],
896 (Integer)__args[2],
897 (Integer)__args[3]);
898 return null;
900 // Draw characters.
901 case DRAW_CHARS:
902 __g.drawChars(
903 (char[])__args[0],
904 (Integer)__args[1],
905 (Integer)__args[2],
906 (Integer)__args[3],
907 (Integer)__args[4],
908 (Integer)__args[5]);
909 return null;
911 // Draw RGB.
912 case DRAW_RGB:
913 __g.drawRGB(
914 (int[])__args[0],
915 (Integer)__args[1],
916 (Integer)__args[2],
917 (Integer)__args[3],
918 (Integer)__args[4],
919 (Integer)__args[5],
920 (Integer)__args[6],
921 (((Integer)__args[7]) != 0 ? true : false));
922 return null;
924 // Draw RGB16.
925 case DRAW_RGB16:
926 __g.drawRGB16(
927 (short[])__args[0],
928 (Integer)__args[1],
929 (Integer)__args[2],
930 (Integer)__args[3],
931 (Integer)__args[4],
932 (Integer)__args[5],
933 (Integer)__args[6]);
934 return null;
936 // Draw round rectangle.
937 case DRAW_ROUND_RECT:
938 __g.drawRoundRect(
939 (Integer)__args[0],
940 (Integer)__args[1],
941 (Integer)__args[2],
942 (Integer)__args[3],
943 (Integer)__args[4],
944 (Integer)__args[5]);
945 return null;
947 // Fill arc.
948 case FILL_ARC:
949 __g.fillArc(
950 (Integer)__args[0],
951 (Integer)__args[1],
952 (Integer)__args[2],
953 (Integer)__args[3],
954 (Integer)__args[4],
955 (Integer)__args[5]);
956 return null;
958 // Fill round rectangle.
959 case FILL_ROUND_RECT:
960 __g.fillRoundRect(
961 (Integer)__args[0],
962 (Integer)__args[1],
963 (Integer)__args[2],
964 (Integer)__args[3],
965 (Integer)__args[4],
966 (Integer)__args[5]);
967 return null;
969 // Fill triangle.
970 case FILL_TRIANGLE:
971 __g.fillTriangle(
972 (Integer)__args[0],
973 (Integer)__args[1],
974 (Integer)__args[2],
975 (Integer)__args[3],
976 (Integer)__args[4],
977 (Integer)__args[5]);
978 return null;
980 // Get blending mode.
981 case GET_BLENDING_MODE:
982 return __g.getBlendingMode();
984 // Get display color.
985 case GET_DISPLAY_COLOR:
986 return __g.getDisplayColor((Integer)__args[0]);
988 // Set blending mode.
989 case SET_BLENDING_MODE:
992 __g.setBlendingMode((Integer)__args[0]);
994 catch (IllegalArgumentException e)
996 return -1;
998 return 0;
1000 // Draw region
1001 case DRAW_REGION:
1004 // Extract width/heights since they are combined here
1005 int sw = ((Integer)__args[1]) >>> 16,
1006 sh = ((Integer)__args[1]) & 0xFFFF,
1007 dw = ((Integer)__args[6]) >>> 16,
1008 dh = ((Integer)__args[6]) & 0xFFFF;
1010 // Note that the passed buffer only contains image data
1011 // from the source region, as such the source coordinates
1012 // will always be zero
1013 __g.drawRegion(Image.createRGBImage(
1014 (int[])__args[0], sw, sh, true),
1015 0, 0,
1016 sw, sh,
1017 (Integer)__args[2],
1018 (Integer)__args[3],
1019 (Integer)__args[4],
1020 (Integer)__args[5],
1021 dw, dh);
1023 catch (IllegalArgumentException e)
1025 return -1;
1027 return 0;
1029 default:
1030 throw Debugging.oops(__func);
1035 * Deserializes the font.
1037 * @param __b The input byte data.
1038 * @return The resulting font.
1039 * @throws NullPointerException On null arguments.
1040 * @since 2018/12/02
1042 public static Font fontDeserialize(byte[] __b)
1043 throws NullPointerException
1045 if (__b == null)
1046 throw new NullPointerException("NARG");
1048 // Deserialize all of the data
1049 try (ByteArrayInputStream bais = new ByteArrayInputStream(__b))
1051 int style, pixelsize;
1052 String name;
1054 try (DataInputStream dis = new DataInputStream(bais))
1056 style = dis.readInt();
1057 pixelsize = dis.readInt();
1058 name = dis.readUTF();
1061 return Font.getFont(name, style, pixelsize);
1064 // {@squirreljme.error EB0o Could not serialize the text object.}
1065 catch (IOException e)
1067 throw new RuntimeException("EB0o", e);
1072 * Deserializes the font.
1074 * @param __dis The stream to read from.
1075 * @return The deserialized font.
1076 * @throws IOException On read errors.
1077 * @throws NullPointerException On null arguments.
1078 * @since 2018/12/02
1080 public static Font fontDeserialize(DataInputStream __dis)
1081 throws IOException, NullPointerException
1083 if (__dis == null)
1084 throw new NullPointerException("NARG");
1086 // Read byte data
1087 int len = __dis.readUnsignedShort();
1088 byte[] ser = new byte[len];
1089 __dis.readFully(ser);
1090 return SerializedGraphics.fontDeserialize(ser);
1094 * Serializes the font.
1096 * @param __f The font to serialize.
1097 * @return The resulting byte data.
1098 * @throws NullPointerException On null arguments.
1099 * @since 2018/12/02
1101 public static byte[] fontSerialize(Font __f)
1102 throws NullPointerException
1104 if (__f == null)
1105 throw new NullPointerException("NARG");
1107 // Serialize all of the data
1108 try (ByteArrayOutputStream baos = new ByteArrayOutputStream(64))
1110 try (DataOutputStream dos = new DataOutputStream(baos))
1112 dos.writeInt(__f.getStyle());
1113 dos.writeInt(__f.getPixelSize());
1114 dos.writeUTF(__f.getFontName());
1117 // Return it
1118 return baos.toByteArray();
1121 // {@squirreljme.error EB0p Could not serialize the text object.}
1122 catch (IOException e)
1124 throw new RuntimeException("EB0p", e);
1129 * Serializes the font.
1131 * @param __dos The stream to write to.
1132 * @param __f The font to serialize.
1133 * @throws IOException On write errors.
1134 * @throws NullPointerException On null arguments.
1135 * @since 2018/12/02
1137 public static void fontSerialize(DataOutputStream __dos, Font __f)
1138 throws IOException, NullPointerException
1140 if (__dos == null || __f == null)
1141 throw new NullPointerException("NARG");
1143 // Record data
1144 byte[] ser = SerializedGraphics.fontSerialize(__f);
1145 __dos.writeShort(ser.length);
1146 __dos.write(ser);
1150 * Deserializes the byte array to a {@link Text} object.
1152 * @param __b The byte array to deserialize.
1153 * @return The deserialized text.
1154 * @throws NullPointerException On null arguments.
1155 * @since 2018/12/02
1157 public static Text textDeserialize(byte[] __b)
1158 throws NullPointerException
1160 if (__b == null)
1161 throw new NullPointerException("NARG");
1163 // Deserialize all of the data
1164 try (ByteArrayInputStream bais = new ByteArrayInputStream(__b))
1166 Text rv = new Text();
1167 try (DataInputStream dis = new DataInputStream(bais))
1169 rv.setWidth(dis.readInt());
1170 rv.setHeight(dis.readInt());
1171 rv.setAlignment(dis.readInt());
1172 rv.setBackgroundColor(dis.readInt());
1173 rv.setFont(SerializedGraphics.fontDeserialize(dis));
1174 rv.setForegroundColor(dis.readInt());
1175 rv.setIndent(dis.readInt());
1176 rv.setInitialDirection(dis.readInt());
1177 rv.setScrollOffset(dis.readInt());
1178 rv.setSpaceAbove(dis.readInt());
1179 rv.setSpaceBelow(dis.readInt());
1181 // Read length
1182 int n = dis.readInt();
1184 // Read in text string
1185 rv.insert(0, dis.readUTF());
1187 // Read all character properties
1188 for (int i = 0; i < n; i++)
1190 rv.setForegroundColor(dis.readInt(), i, 1);
1192 // Was a font used?
1193 if (dis.readBoolean())
1194 rv.setFont(
1195 SerializedGraphics.fontDeserialize(dis), i, 1);
1198 // And now that there is proper length
1199 rv.setCaret(dis.readInt());
1200 rv.setHighlight(dis.readInt(), dis.readInt());
1203 // Return it
1204 return rv;
1207 // {@squirreljme.error EB0q Could not serialize the text object.}
1208 catch (IOException e)
1210 throw new RuntimeException("EB0q", e);
1215 * Serializes the text object to a byte array.
1217 * @param __t The text to serialize.
1218 * @return The serialized byte array.
1219 * @throws NullPointerException On null arguments.
1220 * @since 2018/12/02
1222 public static byte[] textSerialize(Text __t)
1223 throws NullPointerException
1225 if (__t == null)
1226 throw new NullPointerException("NARG");
1228 // Serialize all of the data
1229 try (ByteArrayOutputStream baos = new ByteArrayOutputStream(4096))
1231 try (DataOutputStream dos = new DataOutputStream(baos))
1233 // Properties which do not need characters
1234 dos.writeInt(__t.getWidth());
1235 dos.writeInt(__t.getHeight());
1236 dos.writeInt(__t.getAlignment());
1237 dos.writeInt(__t.getBackgroundColor());
1238 SerializedGraphics.fontSerialize(dos, __t.getFont());
1239 dos.writeInt(__t.getForegroundColor());
1240 dos.writeInt(__t.getIndent());
1241 dos.writeInt(__t.getInitialDirection());
1242 dos.writeInt(__t.getScrollOffset());
1243 dos.writeInt(__t.getSpaceAbove());
1244 dos.writeInt(__t.getSpaceBelow());
1246 // Record length
1247 int n = __t.getTextLength();
1248 dos.writeInt(n);
1250 // Record the string
1251 dos.writeUTF(__t.getText(0, n));
1253 // Record all the character properties
1254 for (int i = 0; i < n; i++)
1256 dos.writeInt(__t.getForegroundColor(i));
1258 // Font needs serialization
1259 Font f = __t.getFont(i);
1260 if (f == null)
1261 dos.writeBoolean(false);
1262 else
1264 dos.writeBoolean(true);
1265 SerializedGraphics.fontSerialize(dos, f);
1269 // Depends on character stuff
1270 dos.writeInt(__t.getCaret());
1271 dos.writeInt(__t.getHighlightIndex());
1272 dos.writeInt(__t.getHighlightLength());
1275 // Return it
1276 return baos.toByteArray();
1279 // {@squirreljme.error EB0r Could not serialize the text object.}
1280 catch (IOException e)
1282 throw new RuntimeException("EB0r", e);