3 #include <exec/types.h>
4 #include <aros/asmcall.h>
5 #include <graphics/rastport.h>
6 #include <graphics/regions.h>
7 #include <graphics/layers.h>
8 #include <graphics/clip.h>
9 #include <intuition/intuition.h>
10 #include <proto/dos.h>
11 #include <proto/exec.h>
12 #include <proto/graphics.h>
13 #include <proto/intuition.h>
14 #include <proto/layers.h>
16 #define GFX_SYSTEM X11 /* ord HIDD */
18 struct IntuitionBase
*IntuitionBase
;
19 struct GfxBase
*GfxBase
;
20 struct Library
*LayersBase
;
21 struct DosLibrary
*DOSBase
;
22 struct Screen
*screen
;
23 struct Window
* window
;
26 struct Screen
* openscreen(void);
27 void closescreen(struct Screen
* screen
);
31 int main(int argc
, char **argv
)
33 if ((IntuitionBase
= (struct IntuitionBase
*) OpenLibrary("intuition.library", 0)))
35 if ((GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 0)))
37 if ((LayersBase
= OpenLibrary("layers.library", 0)))
39 if ((DOSBase
= (struct DosLibrary
*) OpenLibrary("dos.library",0)))
41 if ((screen
= openscreen()))
46 CloseLibrary((struct Library
*)DOSBase
);
48 CloseLibrary(LayersBase
);
50 CloseLibrary((struct Library
*)GfxBase
);
52 CloseLibrary((struct Library
*) IntuitionBase
);
58 struct Screen
* openscreen(void)
60 struct Screen
* screen
;
62 screen
= OpenScreenTags(NULL
,
67 Draw(&screen
->RastPort
, 100, 100);
72 void closescreen(struct Screen
* screen
)
77 struct Layer
*layers
[10];
82 for (i
=0; i
< 10; i
++)
84 if (NULL
!= layers
[i
])
86 DeleteLayer(0, layers
[i
]);
87 if (layers
[i
]->SuperBitMap
)
88 FreeBitMap(layers
[i
]->SuperBitMap
);
96 for (i
=0; i
< 10; i
++)
98 if (NULL
== layers
[i
])
104 void createupfrontlayer(void)
110 struct BitMap
* sb
= NULL
;
111 for (i
= 0; i
< 10; i
++)
113 if (layers
[i
] == NULL
)
118 printf("Backdroplayer [y/N]: ");
120 printf("SuperBitMap [y/N]: ");
131 if (c
=='y' || c
=='Y')
133 printf("Generating a backdrop layer.\n");
134 flags
|= LAYERBACKDROP
;
136 if (s
=='y' || s
=='Y')
138 printf("Generating a superbitmap layer.\n");
140 sb
= AllocBitMap(x1
-x0
+1,y1
-y0
+1,1,BMF_CLEAR
,NULL
);
145 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
146 screen
->RastPort
.BitMap
,
154 printf("Created layer with ID %d\n",i
);
156 printf("Couldn't create layer. No more memory (?).\n");
159 printf("No more layers possible!\n");
162 void createbehindlayer(void)
168 struct BitMap
* sb
= NULL
;
169 for (i
= 0; i
< 10; i
++)
171 if (layers
[i
] == NULL
)
176 printf("Backdroplayer [y/N]: ");
178 printf("SuperBitMap [y/N]: ");
189 if (c
=='y' || c
=='Y')
191 printf("Generating a backdrop layer.\n");
192 flags
|= LAYERBACKDROP
;
194 if (s
=='y' || s
=='Y')
196 printf("Generating a superbitmap layer.\n");
198 sb
= AllocBitMap(x1
-x0
+1,y1
-y0
+1,1,BMF_CLEAR
,NULL
);
203 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
204 screen
->RastPort
.BitMap
,
212 printf("Created layer with ID %d\n",i
);
214 printf("Couldn't create layer. No more memory (?).\n");
217 printf("No more layers possible!\n");
220 void deletelayer(void)
223 printf("Delete layer with id: ");
227 DeleteLayer(0, layers
[i
]);
228 if (layers
[i
]->SuperBitMap
)
229 FreeBitMap(layers
[i
]->SuperBitMap
);
230 printf("Deleted layer with id %d\n",i
);
235 printf("No layer with id %d\n",i
);
239 void upfrontlayer(void)
242 printf("Upfront layer with id: ");
245 UpfrontLayer(0, layers
[i
]);
246 printf("Moved layer with id %d upfront\n",i
);
250 printf("No layer with id %d\n",i
);
254 void behindlayer(void)
257 printf("Behind layer with id: ");
260 BehindLayer(0, layers
[i
]);
261 printf("Moved layer with id %d behind\n",i
);
265 printf("No layer with id %d\n",i
);
269 void movelayerinfrontof(void)
272 printf("Move layer with id: ");
274 printf("in front of layer with id: ");
276 if (layers
[i1
] && layers
[i2
]) {
277 MoveLayerInFrontOf(layers
[i1
], layers
[i2
]);
278 printf("Moved layer with id %d in front of layer with id %d\n",i1
,i2
);
282 printf("No layer with id %d or id %d\n",i1
,i2
);
289 printf("Move layer with id: ");
297 MoveLayer(0, layers
[i
], dx
, dy
);
298 printf("Moved layer with id %d to new position.\n",i
);
302 printf("No layer with id %d\n",i
);
306 void movesizelayer(void)
309 printf("Move and size layer with id: ");
315 printf("delta width: ");
317 printf("delta height: ");
321 MoveSizeLayer(layers
[i
], dx
, dy
, dw
, dh
);
322 printf("Moved and sized layer with id %d.\n",i
);
326 printf("No layer with id %d\n",i
);
333 printf("Resize layer with id: ");
335 printf("delta width: ");
337 printf("delta height: ");
341 SizeLayer(0, layers
[i
], dx
, dy
);
342 printf("Resized layer with id %d.\n",i
);
346 printf("No layer with id %d\n",i
);
350 void scrolllayer(void)
353 printf("Scroll layer with id: ");
355 if (NULL
== layers
[i
])
357 printf("No layer with id %d\n",i
);
365 if (0 == (layers
[i
]->Flags
& LAYERSUPER
))
366 printf("This is a non-superbitmapped layer.\n");
368 printf("This is a superbitmapped layer.\n");
370 ScrollLayer(0, layers
[i
], dx
, dy
);
371 printf("Scrolled layer with id %d.\n",i
);
378 printf("Move layer with id: ");
384 printf("iterations: ");
388 while (iter
> 0 && (TRUE
== MoveLayer(0, layers
[i
],dx
,dy
)))
390 printf("Moved layer with id %d to new position.\n",i
);
394 printf("No layer with id %d\n",i
);
398 /* Draw a simple frame around a layer */
399 void frame(struct Layer
* layer
)
401 int c
, width
= layer
->bounds
.MaxX
-layer
->bounds
.MinX
,i
=0;
402 SetAPen(layer
->rp
, 1);
403 Move(layer
->rp
, 0,0);
404 Draw(layer
->rp
, layer
->bounds
.MaxX
- layer
->bounds
.MinX
, 0);
405 Draw(layer
->rp
, layer
->bounds
.MaxX
- layer
->bounds
.MinX
,
406 layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
407 Draw(layer
->rp
, 0, layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
408 Draw(layer
->rp
, 0, 0);
409 Draw(layer
->rp
, layer
->bounds
.MaxX
- layer
->bounds
.MinX
,
410 layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
412 for (c
=0; c
<= width
; c
= c
+(width
&0x0f)+i
)
416 Draw(layer
->rp
,c
,layer
->bounds
.MaxY
- layer
->bounds
.MinY
);
423 printf("Framing layer with id: ");
432 printf("No layer with id %d\n",i
);
436 void GenerateLayers1(void)
441 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
442 screen
->RastPort
.BitMap
,
454 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
455 screen
->RastPort
.BitMap
,
467 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
468 screen
->RastPort
.BitMap
,
479 void GenerateLayers2(void)
483 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
484 screen
->RastPort
.BitMap
,
495 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
496 screen
->RastPort
.BitMap
,
507 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
508 screen
->RastPort
.BitMap
,
519 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
520 screen
->RastPort
.BitMap
,
531 void GenerateLayers3(void)
535 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
536 screen
->RastPort
.BitMap
,
547 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
548 screen
->RastPort
.BitMap
,
559 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
560 screen
->RastPort
.BitMap
,
570 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
571 screen
->RastPort
.BitMap
,
582 void GenerateLayers4(void)
591 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
592 screen
->RastPort
.BitMap
,
608 printf("Deleting all previously generated layers...\n");
609 for (i
= 0; i
< 10; i
++)
613 DeleteLayer(0, layers
[i
]);
619 printf("After each step there will be a short delay.\n");
620 printf("Activate other X-window (Amiga Screen) and always press a key\nto see what is going on\n");
621 printf("Creating layer %i.\n",i
);
623 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
624 screen
->RastPort
.BitMap
,
634 printf("Creating layer %i.\n",++i
);
636 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
637 screen
->RastPort
.BitMap
,
646 printf("Creating layer %i.\n",++i
);
648 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
649 screen
->RastPort
.BitMap
,
658 printf("Creating layer %i.\n",++i
);
660 layers
[i
] = CreateUpfrontLayer(&screen
->LayerInfo
,
661 screen
->RastPort
.BitMap
,
671 printf("Moving layer %i in front of all other layers.\n",i
);
673 UpfrontLayer(0, layers
[i
]);
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
]);
692 printf("Moving layer %i in front of all other layers.\n",i
);
694 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
]);
716 for (i
= 0; i
< 10; i
++)
717 if (NULL
!= layers
[i
])
719 printf("Destroying layer %i.\n",i
);
721 DeleteLayer(0, layers
[i
]);
725 printf("End of demo .\n");
731 #define DELAYTIME 100
733 printf("Deleting all previously generated layers...\n");
734 for (i
= 0; i
< 10; i
++)
738 DeleteLayer(0, layers
[i
]);
744 printf("After each step there will be a short delay.\n");
745 printf("Activate other X-window (Amiga Screen) and always press a key\nto see what is going on\n");
746 printf("Creating behind-layer %i.\n",i
);
748 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
749 screen
->RastPort
.BitMap
,
759 printf("Creating behind-layer %i.\n",++i
);
761 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
762 screen
->RastPort
.BitMap
,
772 printf("Creating behind-layer %i.\n",++i
);
774 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
775 screen
->RastPort
.BitMap
,
785 printf("Creating behind-layer %i.\n",++i
);
787 layers
[i
] = CreateBehindLayer(&screen
->LayerInfo
,
788 screen
->RastPort
.BitMap
,
799 printf("Moving layer %i in front of all other layers.\n",i
);
801 UpfrontLayer(0, layers
[i
]);
803 printf("Moving layer %i in front of layer %i\n",3,0);
805 MoveLayerInFrontOf(layers
[3], layers
[0]);
807 printf("Moving layer %i in front of layer %i\n",0,3);
809 MoveLayerInFrontOf(layers
[0], layers
[3]);
812 printf("Moving layer %i in front of all other layers.\n",i
);
814 UpfrontLayer(0, layers
[i
]);
817 printf("Moving layer %i in front of all other layers.\n",i
);
819 UpfrontLayer(0, layers
[i
]);
822 printf("Moving layer %i behind all other layers.\n",i
);
824 BehindLayer(0, layers
[i
]);
826 for (i
= 0; i
< 10; i
++)
827 if (NULL
!= layers
[i
])
829 printf("Destroying layer %i.\n",i
);
831 DeleteLayer(0, layers
[i
]);
835 printf("End of demo .\n");
842 printf("Generating a few layers\n");
846 printf("Moving layer 1...\n");
849 while (i
>0 && (TRUE
== MoveLayer(0, layers
[1], 1,1)))
854 printf("Moving layer 2...\n");
857 while (i
>0 && (TRUE
== MoveLayer(0, layers
[2], 2, -1)))
862 printf("Moving layer 3...\n");
865 while (i
>0 && TRUE
== MoveLayer(0, layers
[3], 1, 3))
870 printf("Moving layer 0...\n");
873 while (i
>0 && TRUE
== MoveLayer(0, layers
[0], 0 ,1))
876 printf("Deleting all visible layers!\n");
881 DeleteLayer(0, layers
[i
]);
893 printf("Deleting all previously generated layers...\n");
894 for (i
= 0; i
< 10; i
++)
898 DeleteLayer(0, layers
[i
]);
904 printf("Creating 4 superbitmap layers\n");
906 sb
= AllocBitMap(91,91,1,BMF_CLEAR
,NULL
);
908 layers
[0] = CreateUpfrontLayer(&screen
->LayerInfo
,
909 screen
->RastPort
.BitMap
,
914 LAYERSMART
|LAYERSUPER
,
919 sb
= AllocBitMap(71,71,1,BMF_CLEAR
,NULL
);
920 layers
[1] = CreateUpfrontLayer(&screen
->LayerInfo
,
921 screen
->RastPort
.BitMap
,
926 LAYERSMART
|LAYERSUPER
,
931 sb
= AllocBitMap(71,61,1,BMF_CLEAR
,NULL
);
932 layers
[2] = CreateUpfrontLayer(&screen
->LayerInfo
,
933 screen
->RastPort
.BitMap
,
938 LAYERSMART
|LAYERSUPER
,
942 sb
= AllocBitMap(131,41,1,BMF_CLEAR
,NULL
);
943 layers
[3] = CreateUpfrontLayer(&screen
->LayerInfo
,
944 screen
->RastPort
.BitMap
,
949 LAYERSMART
|LAYERSUPER
,
954 printf("Resizing layer 4\n");
956 SizeLayer(0, layers
[3], -80, -10);
957 /* this leaves width = 51, height = 31 */
958 printf("Scrolling layer 4\n");
965 ScrollLayer(0, layers
[3], 1, 0);
973 ScrollLayer(0, layers
[3], 0 ,1);
981 ScrollLayer(0, layers
[3], -8 ,-1);
984 printf("Resizing layer 4 to its full size\n");
986 SizeLayer(0, layers
[3], 80, 10);
988 printf("Resizing layer 1\n");
989 SizeLayer(0, layers
[0], -50, -50);
991 /* this leaves width = 41, height = 41 */
992 printf("Scrolling layer 1\n");
999 ScrollLayer(0, layers
[0], 1, 0);
1007 ScrollLayer(0, layers
[0], 0 ,1);
1015 ScrollLayer(0, layers
[0], -1 ,-1);
1018 printf("Resizing layer 1 to its full size\n");
1020 SizeLayer(0, layers
[0], 50, 50);
1022 printf("Shuffling layers...\n");
1023 UpfrontLayer(0, layers
[0]);
1025 UpfrontLayer(0, layers
[1]);
1027 UpfrontLayer(0, layers
[2]);
1029 UpfrontLayer(0, layers
[3]);
1031 BehindLayer(0, layers
[2]);
1033 BehindLayer(0,layers
[1]);
1035 BehindLayer(0,layers
[0]);
1036 printf("Inviting a few smart friends...\n");
1038 printf("Moving the layers...\n");
1042 MoveLayer(0, layers
[4], -1, -1);
1043 MoveLayer(0, layers
[0], 1,2);
1044 MoveLayer(0, layers
[2], 2,1);
1045 MoveLayer(0, layers
[5], -2, 0);
1052 MoveLayer(0, layers
[4], -1, -1);
1053 MoveLayer(0, layers
[5], -1, 0);
1054 MoveLayer(0, layers
[3], 3, 2);
1055 MoveSizeLayer(layers
[2], 2, -1, -1, -1);
1062 MoveSizeLayer(layers
[2], -2, 1, 1 ,1);
1063 MoveSizeLayer(layers
[1], 2, 0, -1 ,-1);
1064 MoveLayer(0, layers
[5], 2, 1);
1071 MoveSizeLayer(layers
[1], -1, -1 ,1 , 1);
1075 printf("Deleting the layers...\n");
1079 while ((layers
[i
]->bounds
.MaxX
- layers
[i
]->bounds
.MinX
) >= 1 &&
1080 (layers
[i
]->bounds
.MaxY
- layers
[i
]->bounds
.MinY
) >= 1)
1082 MoveSizeLayer(layers
[i
], 2, 0, -1, -1);
1084 DeleteLayer(0, layers
[i
]);
1090 void DumpCliprects(void)
1093 struct ClipRect
* CR
;
1096 printf("Dump ClipRects of which layer? ");
1098 if (i
< 0 || i
> 10 || NULL
== layers
[i
])
1100 printf("No such layer!\n");
1104 printf("Layer at %px is a ",layers
[i
]);
1105 if (0 != (layers
[i
]->Flags
& LAYERSIMPLE
))
1106 printf("simple layer\n");
1107 else if (0 != (layers
[i
]->Flags
& LAYERSUPER
))
1108 printf("superbitmap layer\n");
1110 printf("smart layer\n");
1113 CR
= layers
[i
]->ClipRect
;
1116 printf("CR #%i\n",c
);
1118 printf("Bounds: (%i,%i)-(%i,%i)\n",CR
->bounds
.MinX
,CR
->bounds
.MinY
,CR
->bounds
.MaxX
,CR
->bounds
.MaxY
);
1119 if (NULL
!= CR
->lobs
)
1120 printf("This cliprect is hidden by layer %px !\n",CR
->lobs
);
1122 printf("This cliprect is visible!\n");
1127 printf("-------------------------------------\n");
1134 for (i
= 0; i
< 10; i
++)
1143 if (!strcmp(buf
,"quit"))
1148 else if (!strcmp(buf
, "help"))
1150 printf("quit help createupfrontlayer [cul] createbehindlayer [cbl] deletelayer [dl]\n");
1151 printf("behindlayerupfrontlayer [ul] movelayerinfrontof [mlio]\n");
1152 printf("movelayer [ml] movesizelayer [msl] sizelayer [sl] scrollayer [scl]\n");
1153 printf("motion [mot] DumpCliprects [dc] \n");
1154 printf("Frame [F] DemoA DemoB DemoC DemoD\n");
1155 printf("Generate a few layers: [gl1,gl2,gl3,gl4]\n");
1157 else if (!strcmp(buf
, "createupfrontlayer") || !strcmp(buf
, "cul"))
1159 createupfrontlayer();
1161 else if (!strcmp(buf
, "createbehindlayer") || !strcmp(buf
, "cbl"))
1163 createbehindlayer();
1165 else if (!strcmp(buf
, "deletelayer") || !strcmp(buf
, "dl"))
1169 else if (!strcmp(buf
, "behindlayer") || !strcmp(buf
, "bl"))
1173 else if (!strcmp(buf
, "upfrontlayer") || !strcmp(buf
, "ul"))
1177 else if (!strcmp(buf
, "movelayerinfrontof") || !strcmp(buf
, "mlio"))
1179 movelayerinfrontof();
1181 else if (!strcmp(buf
, "movelayer") || !strcmp(buf
, "ml"))
1185 else if (!strcmp(buf
, "movesizelayer") || !strcmp(buf
, "msl"))
1189 else if (!strcmp(buf
, "sizelayer") || !strcmp(buf
, "sl"))
1193 else if (!strcmp(buf
, "scrolllayer") || !strcmp(buf
, "scl"))
1197 else if (!strcmp(buf
, "motion") || !strcmp(buf
, "mot"))
1201 else if (!strcmp(buf
, "Frame") || !strcmp(buf
, "F"))
1205 else if (!strcmp(buf
, "DemoA"))
1209 else if (!strcmp(buf
, "DemoB"))
1213 else if (!strcmp(buf
, "DemoC"))
1217 else if (!strcmp(buf
, "DemoD"))
1221 else if (!strcmp(buf
, "gl1"))
1225 else if (!strcmp(buf
, "gl2"))
1229 else if (!strcmp(buf
, "gl3"))
1233 else if (!strcmp(buf
, "gl4"))
1237 else if (!strcmp(buf
, "dc"))
1242 printf("Unknown command. Try 'help'.\n");