gcc: Move -larossupport after -larosc during linking
[AROS.git] / workbench / demos / winbackfill.c
blobd58e310a47adfb24cbcebfcb3f5209db5d898a43
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <utility/hooks.h>
7 #include <proto/exec.h>
8 #include <proto/intuition.h>
9 #include <proto/graphics.h>
10 #include <proto/layers.h>
12 #include <clib/alib_protos.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
18 #define PATTERNWIDTH 32
19 #define PATTERNHEIGHT 32
20 #define PATTERNCOL1 SHADOWPEN
21 #define PATTERNCOL2 SHINEPEN
23 struct LayerHookMsg
25 struct Layer *lay;
26 struct Rectangle bounds;
27 LONG offsetx;
28 LONG offsety;
31 struct IntuitionBase *IntuitionBase;
32 struct GfxBase *GfxBase;
33 struct Library *LayersBase;
35 static struct Screen *scr;
36 static struct Window *win;
37 static struct DrawInfo *dri;
38 static struct BitMap *patternbm;
40 static struct Hook backfillhook;
43 static void Cleanup(char *msg)
45 WORD rc;
47 if (msg)
49 printf("winbackfill: %s\n",msg);
50 rc = RETURN_WARN;
52 else
54 rc = RETURN_OK;
57 if (win) CloseWindow(win);
59 if (patternbm)
61 WaitBlit();
62 FreeBitMap(patternbm);
65 if (dri) FreeScreenDrawInfo(scr,dri);
66 UnlockPubScreen(0,scr);
68 if (LayersBase) CloseLibrary(LayersBase);
69 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
70 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
72 exit(rc);
76 static void OpenLibs(void)
78 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
80 Cleanup("Can't open intuition.library V39!");
83 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
85 Cleanup("Can't open graphics.library V39!");
88 if (!(LayersBase = OpenLibrary("layers.library",39)))
90 Cleanup("Can't open layers.library V39!");
95 static void MyBackfillFunc(struct Hook *hook,struct RastPort *rp,
96 struct LayerHookMsg *msg)
98 struct RastPort myrp;
99 struct Layer *lay;
100 WORD x1,y1,x2,y2,px,py,pw,ph;
102 myrp = *rp;
103 lay = msg->lay;
105 myrp.Layer = 0;
107 x1 = msg->bounds.MinX;
108 y1 = msg->bounds.MinY;
109 x2 = msg->bounds.MaxX;
110 y2 = msg->bounds.MaxY;
112 px = (x1 - lay->bounds.MinX) % PATTERNWIDTH;
114 pw = PATTERNWIDTH - px;
118 y1 = msg->bounds.MinY;
119 py = (y1 - lay->bounds.MinY) % PATTERNHEIGHT;
121 ph = PATTERNHEIGHT - py;
123 if (pw > (x2 - x1 + 1)) pw = x2 - x1 + 1;
127 if (ph > (y2 - y1 + 1)) ph = y2 - y1 + 1;
129 BltBitMap(patternbm,
132 rp->BitMap,
137 192,
138 255,
141 y1 += ph;
143 py = 0;
144 ph = PATTERNHEIGHT;
146 } while (y1 <= y2); /* while(y1 < y2) */
148 x1 += pw;
150 px = 0;
151 pw = PATTERNWIDTH;
153 } while (x1 <= x2); /* while (x1 < x2) */
157 static void InitBackfillHook(void)
159 backfillhook.h_Entry = HookEntry;
160 backfillhook.h_SubEntry = (HOOKFUNC)MyBackfillFunc;
164 static void GetVisual(void)
166 if (!(scr = LockPubScreen(0)))
168 Cleanup("Can't lock pub screen!");
171 if (!(dri = GetScreenDrawInfo(scr)))
173 Cleanup("Can't get drawinfo!");
178 static void MakePattern(void)
180 struct RastPort *temprp;
182 if (!(patternbm = AllocBitMap(PATTERNWIDTH * 2,
183 PATTERNHEIGHT * 2,
184 GetBitMapAttr(scr->RastPort.BitMap,BMA_DEPTH),
185 BMF_CLEAR,
186 scr->RastPort.BitMap)))
188 Cleanup("Can't create pattern bitmap!");
191 if (!(temprp = CreateRastPort()))
193 Cleanup("Can't create rastport!");
196 temprp->BitMap = patternbm;
198 SetAPen(temprp,dri->dri_Pens[PATTERNCOL1]);
200 RectFill(temprp,0,0,10,10);
202 RectFill(temprp,0,0,PATTERNWIDTH - 1,PATTERNHEIGHT - 1);
204 SetAPen(temprp,dri->dri_Pens[PATTERNCOL2]);
205 RectFill(temprp,0,
207 PATTERNWIDTH / 2 - 1,
208 PATTERNHEIGHT / 2 - 1);
210 RectFill(temprp,PATTERNWIDTH / 2,
211 PATTERNHEIGHT / 2,
212 PATTERNWIDTH - 1,
213 PATTERNHEIGHT - 1);
215 FreeRastPort(temprp);
219 static void MakeWin(void)
221 if (!(win = OpenWindowTags(0,WA_PubScreen,(IPTR)scr,
222 WA_Left,10,
223 WA_Top,10,
224 WA_Width,300,
225 WA_Height,150,
226 WA_Title,(IPTR)"Window Backfill Test",
227 WA_SimpleRefresh,TRUE,
228 WA_CloseGadget,TRUE,
229 WA_DepthGadget,TRUE,
230 WA_DragBar,TRUE,
231 WA_SizeGadget,TRUE,
232 WA_MinWidth,50,
233 WA_MinHeight,50,
234 WA_MaxWidth,scr->Width,
235 WA_MaxHeight,scr->Height,
236 WA_IDCMP,IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
237 WA_BackFill,(IPTR)&backfillhook,
238 TAG_DONE)))
240 Cleanup("Can't open window!");
243 ScreenToFront(win->WScreen);
248 static void HandleAll(void)
250 struct IntuiMessage *msg;
252 BOOL quitme = FALSE;
254 while (!quitme)
256 WaitPort(win->UserPort);
258 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
260 switch (msg->Class)
262 case IDCMP_CLOSEWINDOW:
263 quitme = TRUE;
264 break;
266 case IDCMP_REFRESHWINDOW:
267 BeginRefresh(win);
268 EndRefresh(win,TRUE);
269 break;
272 ReplyMsg((struct Message *)msg);
278 int main(void)
280 OpenLibs();
281 InitBackfillHook();
282 GetVisual();
283 MakePattern();
284 MakeWin();
285 HandleAll();
286 Cleanup(0);
288 return 0;