only update affected area of bitmap
[AROS.git] / workbench / demos / childwindow.c
blob74ade6564d62cb7ba6088c48eebdc296c812f88c
2 #include <intuition/intuition.h>
3 #include <graphics/gfx.h>
4 #include <graphics/gfxmacros.h>
5 #include <proto/exec.h>
6 #include <proto/intuition.h>
7 #include <proto/graphics.h>
8 #include <proto/dos.h>
9 #include <dos/rdargs.h>
11 #include <stdio.h>
12 #include <stdlib.h>
14 #define WINWIDTH 260
15 #define WINHEIGHT 260
16 #define WINCX (WINWIDTH / 2)
17 #define WINCY (WINHEIGHT / 2)
19 struct IntuitionBase *IntuitionBase;
20 struct GfxBase *GfxBase;
21 struct Screen *scr;
22 struct DrawInfo *dri;
23 struct Window *win;
24 struct RastPort *rp;
25 struct Region *shape;
27 static void cleanup(char *msg, struct Window *w)
29 if(msg) printf("winshape: %s\n", msg);
31 if (w) CloseWindow(w);
33 if (shape) DisposeRegion(shape);
35 if (dri) FreeScreenDrawInfo(scr, dri);
36 if (scr) UnlockPubScreen(0, scr);
38 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
39 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
41 exit(0);
44 static void openlibs(void)
46 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
48 cleanup("Can't open intuition.library!", NULL);
51 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
53 cleanup("Can't open graphics.library!", NULL);
58 static void getvisual(void)
60 if (!(scr = LockPubScreen(0))) cleanup("Can't lock pub screen!", NULL);
61 if (!(dri = GetScreenDrawInfo(scr))) cleanup("Can't get drawinfo!", NULL);
64 static void makeshape(void)
66 struct Rectangle rect;
68 if (!(shape = NewRegion())) cleanup("Can't create region!\n", NULL);
70 rect.MinX = 0;
71 rect.MinY = 0;
72 rect.MaxX = WINWIDTH - 1;
73 rect.MaxY = scr->WBorTop + scr->Font->ta_YSize + 1 - 1;
75 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n", NULL);
77 rect.MinX = WINCX - 20;
78 rect.MinY = 20;
79 rect.MaxX = WINCX + 20;
80 rect.MaxY = WINHEIGHT - 1 - 20;
82 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n", NULL);
84 rect.MinX = 20;
85 rect.MinY = WINCY - 20;
86 rect.MaxX = WINWIDTH - 1 - 20;
87 rect.MaxY = WINCY + 20;
89 if (!(OrRectRegion(shape, &rect))) cleanup("Can't create region!\n", NULL);
93 static struct Window * makeparentwin(ULONG visible)
95 struct TagItem win_tags[] =
97 { WA_Left , 30 },
98 { WA_Top , 30 },
99 { WA_Width , 400 },
100 { WA_Height , 300 },
101 { WA_MinWidth , 200 },
102 { WA_MaxWidth , 500 },
103 { WA_MinHeight , 200 },
104 { WA_MaxHeight , 400 },
105 { WA_Title , (IPTR)"Parent window" },
106 { WA_CloseGadget, TRUE },
107 { WA_DepthGadget, TRUE },
108 { WA_DragBar , TRUE },
109 { WA_IDCMP , IDCMP_CLOSEWINDOW },
110 { WA_Activate , TRUE },
111 { WA_Hidden , !visible },
112 { WA_SizeGadget , TRUE },
113 { TAG_DONE }
116 return OpenWindowTagList(0, win_tags);
119 static void makewin(struct Window * parent)
121 UWORD pattern[] = {0x5555, 0xAAAA};
122 struct TagItem win_tags[] =
124 { WA_Left , 30 },
125 { WA_Top , 30 },
126 { WA_Width , WINWIDTH },
127 { WA_Height , WINHEIGHT },
128 { WA_Title , (IPTR)"Irregular shaped window" },
129 { WA_DepthGadget, TRUE },
130 { WA_DragBar , TRUE },
131 { WA_Activate , TRUE },
132 { WA_ShapeRegion, (IPTR)shape },
133 { WA_Parent , (IPTR)parent },
134 { TAG_DONE }
137 win = OpenWindowTagList(0, win_tags);
138 if (win) shape = 0;
139 if (!win) cleanup("Can't create window!", NULL);
141 rp = win->RPort;
142 SetAPen(rp, dri->dri_Pens[FILLPEN]);
143 SetBPen(rp, dri->dri_Pens[SHINEPEN]);
144 SetDrMd(rp, JAM2);
146 SetAfPt(rp, pattern, 1);
147 RectFill(rp, 0, 20, WINWIDTH - 1, WINHEIGHT - 1);
148 SetAfPt(rp, 0, 0);
150 SetAPen(rp, dri->dri_Pens[SHINEPEN]);
151 RectFill(rp, WINCX - 20, 20, WINCX + 20, 20);
152 RectFill(rp, WINCX - 20, 21, WINCX - 20, WINCY - 20);
153 RectFill(rp, 20, WINCY - 20, WINCX - 20, WINCY - 20);
154 RectFill(rp, 20, WINCY - 20, 20, WINCY + 20);
155 RectFill(rp, WINCX - 20, WINCY + 20, WINCX - 20, WINHEIGHT - 1 - 20);
156 RectFill(rp, WINCX + 20, WINCY - 20, WINWIDTH - 1 - 20, WINCY - 20);
158 SetAPen(rp, dri->dri_Pens[SHADOWPEN]);
159 RectFill(rp, WINCX + 20, 20, WINCX + 20, WINCY - 20);
160 RectFill(rp, WINCX + 20, WINCY + 20, WINWIDTH - 1 - 20, WINCY + 20);
161 RectFill(rp, WINWIDTH - 1 - 20, WINCY - 20, WINWIDTH - 1 - 20, WINCY + 20);
162 RectFill(rp, 20, WINCY + 20, WINCX - 20, WINCY + 20);
163 RectFill(rp, WINCX - 20, WINHEIGHT - 1 - 20, WINCX + 20, WINHEIGHT - 1 - 20);
164 RectFill(rp, WINCX + 20, WINCY + 20, WINCX + 20, WINHEIGHT - 1 - 20);
167 static void handleall(struct Window * w)
169 WaitPort(w->UserPort);
172 int main(int argc, char **argv)
174 STRPTR args[1] = {(STRPTR)FALSE};
175 struct RDArgs * rda;
176 struct Window * w;
177 ULONG visible = TRUE;
179 rda = ReadArgs("INVISIBLE/S", (IPTR *)args, NULL);
181 if (TRUE == (IPTR)args[0])
183 visible = FALSE;
186 if (rda)
188 openlibs();
189 getvisual();
190 makeshape();
191 w = makeparentwin(visible);
193 if (w)
195 makewin(w);
196 handleall(w);
199 cleanup(0, w);
200 FreeArgs(rda);
203 return 0;