Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / demos / readicon.c
blob545d14cebd35185b7adbad4f6452d74de2c9f762
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Read an icon from an .info file
6 Lang: english
7 */
8 #include <stdio.h>
10 #include <aros/bigendianio.h>
11 #include <graphics/gfxbase.h>
12 #include <workbench/workbench.h>
13 #include <workbench/icon.h>
14 #include <devices/inputevent.h>
16 #include <proto/icon.h>
17 #include <proto/exec.h>
18 #include <proto/dos.h>
19 #include <proto/intuition.h>
21 static const char version[] = "$VER: readicon 41.2 (5.9.1997)\n";
23 #define IM(x) ((struct Image *)x)
25 struct IntuitionBase *IntuitionBase;
26 struct GfxBase *GfxBase;
27 struct Library * IconBase;
29 void DoWindow (struct DiskObject * dobj)
31 struct Window * win = NULL;
32 struct RastPort * rp;
33 struct IntuiMessage * im;
34 int cont;
36 GfxBase=(struct GfxBase *)OpenLibrary(GRAPHICSNAME,39);
37 IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39);
39 if (!GfxBase)
41 printf ("Couldn't open %s\n", GRAPHICSNAME);
42 goto end;
45 if (!IntuitionBase)
47 printf ("Couldn't open intuition.library\n");
48 goto end;
51 win = OpenWindowTags (NULL
52 , WA_Title, (ULONG)"Show an icon"
53 , WA_DragBar, TRUE
54 , WA_CloseGadget, TRUE
55 , WA_DepthGadget, TRUE
56 , WA_Activate, TRUE
57 , WA_Left, 100
58 , WA_Top, 100
59 , WA_InnerWidth, dobj->do_Gadget.Width * 3 + 40
60 , WA_InnerHeight, dobj->do_Gadget.Height + 20
61 , WA_IDCMP, IDCMP_RAWKEY | IDCMP_CLOSEWINDOW
62 , WA_SimpleRefresh, TRUE
63 , TAG_END
66 if (!win)
67 goto end;
69 rp = win->RPort;
71 dobj->do_Gadget.LeftEdge = win->BorderLeft + dobj->do_Gadget.Width * 2 + 30;
72 dobj->do_Gadget.TopEdge = win->BorderTop + 10;
74 AddGadget(win, &dobj->do_Gadget, -1);
75 RefreshGList(&dobj->do_Gadget, win, NULL, 1);
77 DrawImage (rp, dobj->do_Gadget.GadgetRender, win->BorderLeft + 10, win->BorderTop + 10);
78 DrawImage (rp, dobj->do_Gadget.SelectRender, win->BorderLeft + 20 + dobj->do_Gadget.Width, win->BorderTop + 10);
80 cont = 1;
82 printf ("Press a key to exit\n");
84 while (cont)
86 if ((im = (struct IntuiMessage *)GetMsg (win->UserPort)))
88 /* D("Got msg\n"); */
89 printf("Got msg %lx\n", im->Class);
91 switch (im->Class)
93 case IDCMP_CLOSEWINDOW:
94 cont = FALSE;
95 break;
97 case IDCMP_RAWKEY:
98 if (!(im->Code & IECODE_UP_PREFIX))
100 cont = FALSE;
102 break;
106 ReplyMsg ((struct Message *)im);
108 else
110 /* D("Waiting\n"); */
111 Wait (1L << win->UserPort->mp_SigBit);
115 end:
116 if (win)
117 CloseWindow (win);
119 if (GfxBase)
120 CloseLibrary ((struct Library *)GfxBase);
122 if (IntuitionBase)
123 CloseLibrary ((struct Library *)IntuitionBase);
125 return;
126 } /* DoWindow */
128 int main (int argc, char ** argv)
130 struct RDArgs * rda;
131 struct DiskObject * dobj;
133 STRPTR arg;
134 int rc;
135 int t;
137 rc = 0;
139 IconBase = OpenLibrary (ICONNAME, 39);
141 if (!IconBase)
143 printf ("Couldn't open %s\n", ICONNAME);
144 return RETURN_FAIL;
147 rda = ReadArgs ("IconFile/A", (IPTR *)&arg, NULL);
149 if (rda)
151 if (!(dobj = GetDiskObject (arg)) )
153 printf ("Cannot open icon for %s: ", arg);
154 PrintFault (IoErr(), "");
155 rc = 10;
157 else
159 /* hexdump (dobj, 0L, sizeof (struct DiskObject)); */
161 printf ("Some information about the icon:\n"
162 "Magic = %d\n"
163 "Version = %d\n"
164 "Type = %d\n"
165 "Gadget: %dx%d+%d+%d Flags=%x Act=%x Type=%d\n"
166 "Stack = %ld\n"
167 , dobj->do_Magic
168 , dobj->do_Version
169 , dobj->do_Type
170 , dobj->do_Gadget.Width
171 , dobj->do_Gadget.Height
172 , dobj->do_Gadget.LeftEdge
173 , dobj->do_Gadget.TopEdge
174 , dobj->do_Gadget.Flags
175 , dobj->do_Gadget.Activation
176 , dobj->do_Gadget.GadgetType
177 , dobj->do_StackSize
180 if (dobj->do_Gadget.GadgetRender)
182 printf ("GImage: %dx%d+%d+%d\n"
183 , IM(dobj->do_Gadget.GadgetRender)->Width
184 , IM(dobj->do_Gadget.GadgetRender)->Height
185 , IM(dobj->do_Gadget.GadgetRender)->LeftEdge
186 , IM(dobj->do_Gadget.GadgetRender)->TopEdge
189 /* hexdump (IM(dobj->do_Gadget.GadgetRender)->ImageData
190 , 0L
191 , 720
192 ); */
194 else
196 printf ("GImage: none\n");
199 if (dobj->do_Gadget.SelectRender)
201 printf ("SImage: %dx%d+%d+%d\n"
202 , IM(dobj->do_Gadget.SelectRender)->Width
203 , IM(dobj->do_Gadget.SelectRender)->Height
204 , IM(dobj->do_Gadget.SelectRender)->LeftEdge
205 , IM(dobj->do_Gadget.SelectRender)->TopEdge
208 /* hexdump (IM(dobj->do_Gadget.SelectRender)->ImageData
209 , 0L
210 , 720
211 ); */
213 else
215 printf ("SImage: none\n");
218 printf ("DefaultTool: %s\n", dobj->do_DefaultTool);
220 printf ("ToolTypes:\n");
222 if (dobj->do_ToolTypes)
223 for (t=0; dobj->do_ToolTypes[t]; t++)
224 printf ("TT %d: %s\n", t, dobj->do_ToolTypes[t]);
225 else
226 printf ("--- none ---\n");
228 if (!PutDiskObject ("readicon", dobj))
229 PrintFault (IoErr(), "Writing of icon to readicon.info failed");
231 DoWindow (dobj);
233 FreeDiskObject (dobj);
236 FreeArgs (rda);
238 else
239 rc = 10;
241 return rc;
242 } /* main */