2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
8 #include <exec/types.h>
9 #include <aros/asmcall.h>
10 #include <graphics/rastport.h>
11 #include <graphics/regions.h>
12 #include <graphics/layers.h>
13 #include <graphics/clip.h>
14 #include <intuition/intuition.h>
15 #include <proto/dos.h>
16 #include <proto/exec.h>
17 #include <proto/graphics.h>
18 #include <proto/intuition.h>
19 #include <proto/layers.h>
21 #define GFX_SYSTEM X11 /* ord HIDD */
23 struct IntuitionBase
*IntuitionBase
;
24 struct GfxBase
*GfxBase
;
25 struct Library
*LayersBase
;
26 struct DosLibrary
*DOSBase
;
27 struct Screen
*screen
;
28 struct Window
* window
;
31 struct Screen
* openscreen(void);
32 void closescreen(struct Screen
* screen
);
36 int main(int argc
, char **argv
)
38 if ((IntuitionBase
= (struct IntuitionBase
*) OpenLibrary("intuition.library", 0)))
40 if ((GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 0)))
42 if ((LayersBase
= OpenLibrary("layers.library", 0)))
44 if ((DOSBase
= (struct DosLibrary
*) OpenLibrary("dos.library",0)))
46 if ((screen
= openscreen()))
51 CloseLibrary((struct Library
*)DOSBase
);
53 CloseLibrary(LayersBase
);
55 CloseLibrary((struct Library
*)GfxBase
);
57 CloseLibrary((struct Library
*) IntuitionBase
);
63 struct Screen
* openscreen(void)
65 struct Screen
* screen
;
67 screen
= OpenScreenTags(NULL
,
72 Draw(&screen
->RastPort
, 100, 100);
77 void closescreen(struct Screen
* screen
)
82 struct Layer
*layers
[10];
87 for (i
=0; i
< 10; i
++)
89 if (NULL
!= layers
[i
])
91 DeleteLayer(0, layers
[i
]);
92 if (layers
[i
]->SuperBitMap
)
93 FreeBitMap(layers
[i
]->SuperBitMap
);
101 for (i
=0; i
< 10; i
++)
103 if (NULL
== layers
[i
])
109 void createupfrontlayer(void)
115 struct BitMap
* sb
= NULL
;
116 for (i
= 0; i
< 10; i
++)
118 if (layers
[i
] == NULL
)
123 printf("Backdroplayer [y/N]: ");
125 printf("SuperBitMap [y/N]: ");
136 if (c
=='y' || c
=='Y')
138 printf("Generating a backdrop layer.\n");
139 flags
|= LAYERBACKDROP
;
141 if (s
=='y' || s
=='Y')
143 printf("Generating a superbitmap layer.\n");
145 sb
= AllocBitMap(x1
-x0
+1,y1
-y0
+1,1,BMF_CLEAR
,NULL
);
150 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
151 screen
->RastPort
.BitMap
,
159 printf("Created layer with ID %d\n",i
);
161 printf("Couldn't create layer. No more memory (?).\n");
164 printf("No more layers possible!\n");
167 void createbehindlayer(void)
173 struct BitMap
* sb
= NULL
;
174 for (i
= 0; i
< 10; i
++)
176 if (layers
[i
] == NULL
)
181 printf("Backdroplayer [y/N]: ");
183 printf("SuperBitMap [y/N]: ");
194 if (c
=='y' || c
=='Y')
196 printf("Generating a backdrop layer.\n");
197 flags
|= LAYERBACKDROP
;
199 if (s
=='y' || s
=='Y')
201 printf("Generating a superbitmap layer.\n");
203 sb
= AllocBitMap(x1
-x0
+1,y1
-y0
+1,1,BMF_CLEAR
,NULL
);
208 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
209 screen
->RastPort
.BitMap
,
217 printf("Created layer with ID %d\n",i
);
219 printf("Couldn't create layer. No more memory (?).\n");
222 printf("No more layers possible!\n");
225 void deletelayer(void)
228 printf("Delete layer with id: ");
232 DeleteLayer(0, layers
[i
]);
233 if (layers
[i
]->SuperBitMap
)
234 FreeBitMap(layers
[i
]->SuperBitMap
);
235 printf("Deleted layer with id %d\n",i
);
240 printf("No layer with id %d\n",i
);
244 void upfrontlayer(void)
247 printf("Upfront layer with id: ");
250 UpfrontLayer(0, layers
[i
]);
251 printf("Moved layer with id %d upfront\n",i
);
255 printf("No layer with id %d\n",i
);
259 void behindlayer(void)
262 printf("Behind layer with id: ");
265 BehindLayer(0, layers
[i
]);
266 printf("Moved layer with id %d behind\n",i
);
270 printf("No layer with id %d\n",i
);
274 void movelayerinfrontof(void)
277 printf("Move layer with id: ");
279 printf("in front of layer with id: ");
281 if (layers
[i1
] && layers
[i2
]) {
282 MoveLayerInFrontOf(layers
[i1
], layers
[i2
]);
283 printf("Moved layer with id %d in front of layer with id %d\n",i1
,i2
);
287 printf("No layer with id %d or id %d\n",i1
,i2
);
294 printf("Move layer with id: ");
302 MoveLayer(0, layers
[i
], dx
, dy
);
303 printf("Moved layer with id %d to new position.\n",i
);
307 printf("No layer with id %d\n",i
);
311 void movesizelayer(void)
314 printf("Move and size layer with id: ");
320 printf("delta width: ");
322 printf("delta height: ");
326 MoveSizeLayer(layers
[i
], dx
, dy
, dw
, dh
);
327 printf("Moved and sized layer with id %d.\n",i
);
331 printf("No layer with id %d\n",i
);
338 printf("Resize layer with id: ");
340 printf("delta width: ");
342 printf("delta height: ");
346 SizeLayer(0, layers
[i
], dx
, dy
);
347 printf("Resized layer with id %d.\n",i
);
351 printf("No layer with id %d\n",i
);
355 void scrolllayer(void)
358 printf("Scroll layer with id: ");
360 if (NULL
== layers
[i
])
362 printf("No layer with id %d\n",i
);
370 if (0 == (layers
[i
]->Flags
& LAYERSUPER
))
371 printf("This is a non-superbitmapped layer.\n");
373 printf("This is a superbitmapped layer.\n");
375 ScrollLayer(0, layers
[i
], dx
, dy
);
376 printf("Scrolled layer with id %d.\n",i
);
383 printf("Move layer with id: ");
389 printf("iterations: ");
393 while (iter
> 0 && (TRUE
== MoveLayer(0, layers
[i
],dx
,dy
)))
395 printf("Moved layer with id %d to new position.\n",i
);
399 printf("No layer with id %d\n",i
);
403 /* Draw a simple frame around a layer */
404 void frame(struct Layer
* layer
)
406 int c
, width
= layer
->bounds
.MaxX
-layer
->bounds
.MinX
,i
=0;
407 SetAPen(layer
->rp
, 1);
408 Move(layer
->rp
, 0,0);
409 Draw(layer
->rp
, layer
->bounds
.MaxX
- layer
->bounds
.MinX
, 0);
410 Draw(layer
->rp
, layer
->bounds
.MaxX
- layer
->bounds
.MinX
,
411 layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
412 Draw(layer
->rp
, 0, layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
413 Draw(layer
->rp
, 0, 0);
414 Draw(layer
->rp
, layer
->bounds
.MaxX
- layer
->bounds
.MinX
,
415 layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
417 for (c
=0; c
<= width
; c
= c
+(width
&0x0f)+i
)
421 Draw(layer
->rp
,c
,layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
428 printf("Framing layer with id: ");
437 printf("No layer with id %d\n",i
);
441 void GenerateLayers1(void)
446 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
447 screen
->RastPort
.BitMap
,
459 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
460 screen
->RastPort
.BitMap
,
472 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
473 screen
->RastPort
.BitMap
,
484 void GenerateLayers2(void)
488 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
489 screen
->RastPort
.BitMap
,
500 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
501 screen
->RastPort
.BitMap
,
512 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
513 screen
->RastPort
.BitMap
,
524 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
525 screen
->RastPort
.BitMap
,
536 void GenerateLayers3(void)
540 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
541 screen
->RastPort
.BitMap
,
552 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
553 screen
->RastPort
.BitMap
,
564 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
565 screen
->RastPort
.BitMap
,
575 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
576 screen
->RastPort
.BitMap
,
587 void GenerateLayers4(void)
596 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
597 screen
->RastPort
.BitMap
,
613 printf("Deleting all previously generated layers...\n");
614 for (i
= 0; i
< 10; i
++)
618 DeleteLayer(0, layers
[i
]);
624 printf("After each step there will be a short delay.\n");
625 printf("Activate other X-window (Amiga Screen) and always press a key\nto see what is going on\n");
626 printf("Creating layer %i.\n",i
);
628 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
629 screen
->RastPort
.BitMap
,
639 printf("Creating layer %i.\n",++i
);
641 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
642 screen
->RastPort
.BitMap
,
651 printf("Creating layer %i.\n",++i
);
653 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
654 screen
->RastPort
.BitMap
,
663 printf("Creating layer %i.\n",++i
);
665 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
666 screen
->RastPort
.BitMap
,
676 printf("Moving layer %i in front of all other layers.\n",i
);
678 UpfrontLayer(0, layers
[i
]);
681 printf("Moving layer %i in front of all other layers.\n",i
);
683 UpfrontLayer(0, layers
[i
]);
686 printf("Moving layer %i in front of all other layers.\n",i
);
688 UpfrontLayer(0, layers
[i
]);
691 printf("Moving layer %i in front of all other layers.\n",i
);
693 UpfrontLayer(0, layers
[i
]);
697 printf("Moving layer %i in front of all other layers.\n",i
);
699 UpfrontLayer(0, layers
[i
]);
702 printf("Moving layer %i in front of all other layers.\n",i
);
704 UpfrontLayer(0, layers
[i
]);
707 printf("Moving layer %i in front of all other layers.\n",i
);
709 UpfrontLayer(0, layers
[i
]);
712 printf("Moving layer %i in front of all other layers.\n",i
);
714 UpfrontLayer(0, layers
[i
]);
717 printf("Moving layer %i in front of all other layers.\n",i
);
719 UpfrontLayer(0, layers
[i
]);
721 for (i
= 0; i
< 10; i
++)
722 if (NULL
!= layers
[i
])
724 printf("Destroying layer %i.\n",i
);
726 DeleteLayer(0, layers
[i
]);
730 printf("End of demo .\n");
736 #define DELAYTIME 100
738 printf("Deleting all previously generated layers...\n");
739 for (i
= 0; i
< 10; i
++)
743 DeleteLayer(0, layers
[i
]);
749 printf("After each step there will be a short delay.\n");
750 printf("Activate other X-window (Amiga Screen) and always press a key\nto see what is going on\n");
751 printf("Creating behind-layer %i.\n",i
);
753 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
754 screen
->RastPort
.BitMap
,
764 printf("Creating behind-layer %i.\n",++i
);
766 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
767 screen
->RastPort
.BitMap
,
777 printf("Creating behind-layer %i.\n",++i
);
779 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
780 screen
->RastPort
.BitMap
,
790 printf("Creating behind-layer %i.\n",++i
);
792 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
793 screen
->RastPort
.BitMap
,
804 printf("Moving layer %i in front of all other layers.\n",i
);
806 UpfrontLayer(0, layers
[i
]);
808 printf("Moving layer %i in front of layer %i\n",3,0);
810 MoveLayerInFrontOf(layers
[3], layers
[0]);
812 printf("Moving layer %i in front of layer %i\n",0,3);
814 MoveLayerInFrontOf(layers
[0], layers
[3]);
817 printf("Moving layer %i in front of all other layers.\n",i
);
819 UpfrontLayer(0, layers
[i
]);
822 printf("Moving layer %i in front of all other layers.\n",i
);
824 UpfrontLayer(0, layers
[i
]);
827 printf("Moving layer %i behind all other layers.\n",i
);
829 BehindLayer(0, layers
[i
]);
831 for (i
= 0; i
< 10; i
++)
832 if (NULL
!= layers
[i
])
834 printf("Destroying layer %i.\n",i
);
836 DeleteLayer(0, layers
[i
]);
840 printf("End of demo .\n");
847 printf("Generating a few layers\n");
851 printf("Moving layer 1...\n");
854 while (i
>0 && (TRUE
== MoveLayer(0, layers
[1], 1,1)))
859 printf("Moving layer 2...\n");
862 while (i
>0 && (TRUE
== MoveLayer(0, layers
[2], 2, -1)))
867 printf("Moving layer 3...\n");
870 while (i
>0 && TRUE
== MoveLayer(0, layers
[3], 1, 3))
875 printf("Moving layer 0...\n");
878 while (i
>0 && TRUE
== MoveLayer(0, layers
[0], 0 ,1))
881 printf("Deleting all visible layers!\n");
886 DeleteLayer(0, layers
[i
]);
898 printf("Deleting all previously generated layers...\n");
899 for (i
= 0; i
< 10; i
++)
903 DeleteLayer(0, layers
[i
]);
909 printf("Creating 4 superbitmap layers\n");
911 sb
= AllocBitMap(91,91,1,BMF_CLEAR
,NULL
);
913 layers
[0] = CreateUpfrontLayer(&screen
->LayerInfo
,
914 screen
->RastPort
.BitMap
,
919 LAYERSMART
|LAYERSUPER
,
924 sb
= AllocBitMap(71,71,1,BMF_CLEAR
,NULL
);
925 layers
[1] = CreateUpfrontLayer(&screen
->LayerInfo
,
926 screen
->RastPort
.BitMap
,
931 LAYERSMART
|LAYERSUPER
,
936 sb
= AllocBitMap(71,61,1,BMF_CLEAR
,NULL
);
937 layers
[2] = CreateUpfrontLayer(&screen
->LayerInfo
,
938 screen
->RastPort
.BitMap
,
943 LAYERSMART
|LAYERSUPER
,
947 sb
= AllocBitMap(131,41,1,BMF_CLEAR
,NULL
);
948 layers
[3] = CreateUpfrontLayer(&screen
->LayerInfo
,
949 screen
->RastPort
.BitMap
,
954 LAYERSMART
|LAYERSUPER
,
959 printf("Resizing layer 4\n");
961 SizeLayer(0, layers
[3], -80, -10);
962 /* this leaves width = 51, height = 31 */
963 printf("Scrolling layer 4\n");
970 ScrollLayer(0, layers
[3], 1, 0);
978 ScrollLayer(0, layers
[3], 0 ,1);
986 ScrollLayer(0, layers
[3], -8 ,-1);
989 printf("Resizing layer 4 to its full size\n");
991 SizeLayer(0, layers
[3], 80, 10);
993 printf("Resizing layer 1\n");
994 SizeLayer(0, layers
[0], -50, -50);
996 /* this leaves width = 41, height = 41 */
997 printf("Scrolling layer 1\n");
1004 ScrollLayer(0, layers
[0], 1, 0);
1012 ScrollLayer(0, layers
[0], 0 ,1);
1020 ScrollLayer(0, layers
[0], -1 ,-1);
1023 printf("Resizing layer 1 to its full size\n");
1025 SizeLayer(0, layers
[0], 50, 50);
1027 printf("Shuffling layers...\n");
1028 UpfrontLayer(0, layers
[0]);
1030 UpfrontLayer(0, layers
[1]);
1032 UpfrontLayer(0, layers
[2]);
1034 UpfrontLayer(0, layers
[3]);
1036 BehindLayer(0, layers
[2]);
1038 BehindLayer(0,layers
[1]);
1040 BehindLayer(0,layers
[0]);
1041 printf("Inviting a few smart friends...\n");
1043 printf("Moving the layers...\n");
1047 MoveLayer(0, layers
[4], -1, -1);
1048 MoveLayer(0, layers
[0], 1,2);
1049 MoveLayer(0, layers
[2], 2,1);
1050 MoveLayer(0, layers
[5], -2, 0);
1057 MoveLayer(0, layers
[4], -1, -1);
1058 MoveLayer(0, layers
[5], -1, 0);
1059 MoveLayer(0, layers
[3], 3, 2);
1060 MoveSizeLayer(layers
[2], 2, -1, -1, -1);
1067 MoveSizeLayer(layers
[2], -2, 1, 1 ,1);
1068 MoveSizeLayer(layers
[1], 2, 0, -1 ,-1);
1069 MoveLayer(0, layers
[5], 2, 1);
1076 MoveSizeLayer(layers
[1], -1, -1 ,1 , 1);
1080 printf("Deleting the layers...\n");
1084 while ((layers
[i
]->bounds
.MaxX
- layers
[i
]->bounds
.MinX
) >= 1 &&
1085 (layers
[i
]->bounds
.MaxY
- layers
[i
]->bounds
.MinY
) >= 1)
1087 MoveSizeLayer(layers
[i
], 2, 0, -1, -1);
1089 DeleteLayer(0, layers
[i
]);
1095 void DumpCliprects(void)
1098 struct ClipRect
* CR
;
1101 printf("Dump ClipRects of which layer? ");
1103 if (i
< 0 || i
> 10 || NULL
== layers
[i
])
1105 printf("No such layer!\n");
1109 printf("Layer at %px is a ",layers
[i
]);
1110 if (0 != (layers
[i
]->Flags
& LAYERSIMPLE
))
1111 printf("simple layer\n");
1112 else if (0 != (layers
[i
]->Flags
& LAYERSUPER
))
1113 printf("superbitmap layer\n");
1115 printf("smart layer\n");
1118 CR
= layers
[i
]->ClipRect
;
1121 printf("CR #%i\n",c
);
1123 printf("Bounds: (%i,%i)-(%i,%i)\n",CR
->bounds
.MinX
,CR
->bounds
.MinY
,CR
->bounds
.MaxX
,CR
->bounds
.MaxY
);
1124 if (NULL
!= CR
->lobs
)
1125 printf("This cliprect is hidden by layer %px !\n",CR
->lobs
);
1127 printf("This cliprect is visible!\n");
1132 printf("-------------------------------------\n");
1139 for (i
= 0; i
< 10; i
++)
1148 if (!strcmp(buf
,"quit"))
1153 else if (!strcmp(buf
, "help"))
1155 printf("quit help createupfrontlayer [cul] createbehindlayer [cbl] deletelayer [dl]\n");
1156 printf("behindlayerupfrontlayer [ul] movelayerinfrontof [mlio]\n");
1157 printf("movelayer [ml] movesizelayer [msl] sizelayer [sl] scrollayer [scl]\n");
1158 printf("motion [mot] DumpCliprects [dc] \n");
1159 printf("Frame [F] DemoA DemoB DemoC DemoD\n");
1160 printf("Generate a few layers: [gl1,gl2,gl3,gl4]\n");
1162 else if (!strcmp(buf
, "createupfrontlayer") || !strcmp(buf
, "cul"))
1164 createupfrontlayer();
1166 else if (!strcmp(buf
, "createbehindlayer") || !strcmp(buf
, "cbl"))
1168 createbehindlayer();
1170 else if (!strcmp(buf
, "deletelayer") || !strcmp(buf
, "dl"))
1174 else if (!strcmp(buf
, "behindlayer") || !strcmp(buf
, "bl"))
1178 else if (!strcmp(buf
, "upfrontlayer") || !strcmp(buf
, "ul"))
1182 else if (!strcmp(buf
, "movelayerinfrontof") || !strcmp(buf
, "mlio"))
1184 movelayerinfrontof();
1186 else if (!strcmp(buf
, "movelayer") || !strcmp(buf
, "ml"))
1190 else if (!strcmp(buf
, "movesizelayer") || !strcmp(buf
, "msl"))
1194 else if (!strcmp(buf
, "sizelayer") || !strcmp(buf
, "sl"))
1198 else if (!strcmp(buf
, "scrolllayer") || !strcmp(buf
, "scl"))
1202 else if (!strcmp(buf
, "motion") || !strcmp(buf
, "mot"))
1206 else if (!strcmp(buf
, "Frame") || !strcmp(buf
, "F"))
1210 else if (!strcmp(buf
, "DemoA"))
1214 else if (!strcmp(buf
, "DemoB"))
1218 else if (!strcmp(buf
, "DemoC"))
1222 else if (!strcmp(buf
, "DemoD"))
1226 else if (!strcmp(buf
, "gl1"))
1230 else if (!strcmp(buf
, "gl2"))
1234 else if (!strcmp(buf
, "gl3"))
1238 else if (!strcmp(buf
, "gl4"))
1242 else if (!strcmp(buf
, "dc"))
1247 printf("Unknown command. Try 'help'.\n");