revert between 56095 -> 55830 in arch
[AROS.git] / workbench / demos / compleximage.c
blob45eda775c3d94300801bf4e9b15ba980c09c968d
1 ;/* compleximage.c - program to show the use of a complex Intuition Image.
2 lc -b1 -cfist -v -y -j73 compleximage.c
3 blink FROM LIB:c.o compleximage.o TO compleximage LIB LIB:lc.lib LIB:amiga.lib
4 quit
5 */
7 /*
8 Copyright (c) 1992 Commodore-Amiga, Inc.
10 This example is provided in electronic form by Commodore-Amiga, Inc. for
11 use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
12 published by Addison-Wesley (ISBN 0-201-56774-1).
14 The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
15 information on the correct usage of the techniques and operating system
16 functions presented in these examples. The source and executable code
17 of these examples may only be distributed in free electronic form, via
18 bulletin board or as part of a fully non-commercial and freely
19 redistributable diskette. Both the source and executable code (including
20 comments) must be included, without modification, in any copy. This
21 example may not be published in printed form or distributed with any
22 commercial product. However, the programming techniques and support
23 routines set forth in these examples may be used in the development
24 of original executable software products for Commodore Amiga computers.
26 All other rights reserved.
28 This example is provided "as-is" and is subject to change; no
29 warranties are made. All use is at your own risk. No liability or
30 responsibility is assumed.
34 #define INTUI_V36_NAMES_ONLY
36 #include <exec/types.h>
37 #include <intuition/intuition.h>
38 #include <intuition/intuitionbase.h>
40 #include <proto/exec.h>
41 #include <proto/dos.h>
42 #include <proto/intuition.h>
44 #include <stdio.h>
46 static const char version[] __attribute__((used)) = "$VER: compleximage 41.1 (14.3.1997)\n";
48 #ifdef __AROS__
49 #ifdef __chip
50 #undef __chip
51 #endif
52 #define __chip
53 #include <proto/alib.h>
54 #endif
56 #ifdef LATTICE
57 int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
58 int chkabort(void) { return(0); } /* really */
59 #endif
61 struct IntuitionBase *IntuitionBase = NULL;
63 #define MYIMAGE_LEFT (0)
64 #define MYIMAGE_TOP (0)
65 #define MYIMAGE_WIDTH (24)
66 #define MYIMAGE_HEIGHT (10)
67 #define MYIMAGE_DEPTH (2)
69 /* This is the image data. It is a two bitplane open rectangle which
70 ** is 24 pixels wide and 10 high. Make sure that it is in CHIP memory,
71 ** or allocate a block of chip memory with a call like:
73 ** AllocMem(data_size,MEMF_CHIP)
75 ** and copy the data to that block. See the Exec chapter on
76 ** Memory Allocation for more information on AllocMem().
78 UBYTE __chip myImageData[] =
80 /* first bitplane of data,
81 ** open rectangle.
83 0xFF,0xFF, 0xFF,0x00,
84 0xC0,0x00, 0x03,0x00,
85 0xC0,0x00, 0x03,0x00,
86 0xC0,0x00, 0x03,0x00,
87 0xC0,0x00, 0x03,0x00,
88 0xC0,0x00, 0x03,0x00,
89 0xC0,0x00, 0x03,0x00,
90 0xC0,0x00, 0x03,0x00,
91 0xC0,0x00, 0x03,0x00,
92 0xFF,0xFF, 0xFF,0x00,
94 /* second bitplane of data,
95 ** filled rectangle to appear within open rectangle.
97 0x00,0x00, 0x00,0x00,
98 0x00,0x00, 0x00,0x00,
99 0x00,0x00, 0x00,0x00,
100 0x00,0xFF, 0x00,0x00,
101 0x00,0xFF, 0x00,0x00,
102 0x00,0xFF, 0x00,0x00,
103 0x00,0xFF, 0x00,0x00,
104 0x00,0x00, 0x00,0x00,
105 0x00,0x00, 0x00,0x00,
106 0x00,0x00, 0x00,0x00,
109 /* used to get the "new look" on a custom screen */
110 UWORD pens[] = { ~0 };
114 ** main routine. Open required library and window and draw the images.
115 ** This routine opens a very simple window with no IDCMP. See the
116 ** chapters on "Windows" and "Input and Output Methods" for more info.
117 ** Free all resources when done.
119 int main(int argc, char *argv[])
121 struct Screen *scr;
122 struct Window *win;
123 struct Image myImage;
124 BOOL quitme = FALSE;
125 struct IntuiMessage *imsg;
127 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37);
128 if (IntuitionBase != NULL)
130 if (NULL != (scr = OpenScreenTags(NULL,
131 SA_Depth, 4,
132 SA_Pens, (IPTR) &pens,
133 TAG_END)))
135 #ifdef __AROS__
136 if (NULL != (win = OpenWindowTags(NULL,
137 WA_RMBTrap, TRUE,
138 WA_CustomScreen, (IPTR) scr,
139 WA_IDCMP, IDCMP_RAWKEY|IDCMP_CLOSEWINDOW,
140 WA_Activate, TRUE,
141 WA_CloseGadget, TRUE,
142 WA_Width, 200,
143 WA_Height, 200,
144 TAG_END)))
145 #else
146 if (NULL != (win = OpenWindowTags(NULL,
147 WA_RMBTrap, TRUE,
148 WA_CustomScreen, scr,
149 TAG_END)))
150 #endif
152 myImage.LeftEdge = MYIMAGE_LEFT;
153 myImage.TopEdge = MYIMAGE_TOP;
154 myImage.Width = MYIMAGE_WIDTH;
155 myImage.Height = MYIMAGE_HEIGHT;
156 myImage.Depth = MYIMAGE_DEPTH;
157 myImage.ImageData = (UWORD *)myImageData;
158 myImage.PlanePick = 0x3; /* use first two bitplanes */
159 myImage.PlaneOnOff = 0x0; /* clear all unused planes */
160 myImage.NextImage = NULL;
162 /* Draw the image into the first two bitplanes */
163 DrawImage(win->RPort,&myImage,20,50);
165 /* Draw the same image at a new location */
166 DrawImage(win->RPort,&myImage,100,50);
168 /* Change the image to use the second and fourth bitplanes,
169 ** PlanePick is 1010 binary or 0xA,
170 ** and draw it again at a different location
172 myImage.PlanePick = 0xA;
173 DrawImage(win->RPort,&myImage,20,100);
175 /* Now set all the bits in the first bitplane with PlaneOnOff.
176 ** This will make all the bits set in the second bitplane
177 ** appear as color 3 (0011 binary), all the bits set in the
178 ** fourth bitplane appear as color 9 (1001 binary) and all
179 ** other pixels will be color 1 (0001 binary. If there were
180 ** any points in the image where both bits were set, they
181 ** would appear as color 11 (1011 binary).
182 ** Draw the image at a different location.
184 myImage.PlaneOnOff = 0x1;
185 DrawImage(win->RPort,&myImage,100,50);
187 #ifdef __AROS__
188 while (!quitme)
190 WaitPort(win->UserPort);
192 while ((imsg = (struct IntuiMessage *)GetMsg(win->UserPort)))
194 switch (imsg->Class)
196 case IDCMP_CLOSEWINDOW:
197 quitme = TRUE;
198 break;
199 #if 0
200 case IDCMP_RAWKEY: // bug or feature? The program immediately exits
201 // when querying for RAWKEY
202 printf("code %d\n", imsg->Code);
203 quitme = TRUE;
204 break;
205 #endif
208 ReplyMsg((struct Message *)imsg);
212 #else
213 /* Wait a bit, then quit.
214 ** In a real application, this would be an event loop, like the
215 ** one described in the Intuition Input and Output Methods chapter.
217 Delay(200);
218 #endif
220 CloseWindow(win);
222 CloseScreen(scr);
224 CloseLibrary((struct Library *)IntuitionBase);
226 return 0;