3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <proto/alib.h>
6 #include <proto/exec.h>
8 #include <proto/graphics.h>
9 #include <proto/intuition.h>
15 #define INSTALL_NULL_SHAPE_FIRST 0
20 /***********************************************************************************/
22 struct IntuitionBase
*IntuitionBase
;
23 struct GfxBase
*GfxBase
;
31 /***********************************************************************************/
33 static void cleanup(char *msg
)
37 printf("roundshape: %s\n",msg
);
40 if (win
) CloseWindow(win
);
41 if (shape
) DisposeRegion(shape
);
42 if (scr
) UnlockPubScreen(0, scr
);
44 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
45 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
50 /***********************************************************************************/
52 static void openlibs(void)
54 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
56 cleanup("Can't open intuition.library V39!");
59 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
61 cleanup("Can't open graphics.library V39!");
66 /***********************************************************************************/
68 static void getvisual(void)
70 if (!(scr
= LockPubScreen(NULL
)))
72 cleanup("Can't lock pub screen!");
76 /***********************************************************************************/
78 static void makewin(void)
80 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
81 WA_InnerWidth
, WINWIDTH
,
82 WA_InnerHeight
, WINHEIGHT
,
83 WA_Title
, (IPTR
)"Round Shape",
85 WA_DepthGadget
, TRUE
,
86 WA_CloseGadget
, TRUE
,
93 WA_SizeBBottom
, TRUE
,
95 WA_NoCareRefresh
, TRUE
,
97 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
102 if (!win
) cleanup("Can't open window");
108 /***********************************************************************************/
110 static void renderwin(void)
112 struct Region
*oldshape
;
113 struct Rectangle rect
;
116 static WORD oldheight
= 0;
117 static WORD oldwidth
= 0;
119 if (oldheight
== win
->GZZHeight
&& oldwidth
== win
->GZZWidth
)
122 oldheight
= win
->GZZHeight
;
123 oldwidth
= win
->GZZWidth
;
125 cx
= win
->BorderLeft
+ win
->GZZWidth
/ 2;
126 cy
= win
->BorderTop
+ win
->GZZHeight
/ 2;
128 r
= ((win
->GZZWidth
< win
->GZZHeight
) ? win
->GZZWidth
: win
->GZZHeight
) / 2 - 10;
130 #if INSTALL_NULL_SHAPE_FIRST
131 oldshape
= ChangeWindowShape(win
, shape
, NULL
);
132 if (oldshape
) DisposeRegion(oldshape
);
135 shape
= NewRectRegion(0, 0, win
->Width
- 1, win
->BorderTop
- 1);
137 rect
.MinX
= win
->Width
- win
->BorderRight
;
138 rect
.MinY
= win
->Height
- win
->BorderBottom
;
139 rect
.MaxX
= win
->Width
- 1;
140 rect
.MaxY
= win
->Height
- 1;
142 OrRectRegion(shape
, &rect
);
144 for(y
= 0; y
< r
; y
++)
146 WORD dx
= (WORD
)sqrt((double)(r
* r
- y
* y
));
149 RectFill(rp
, cx
- dx
, cy
- y
, cx
+ dx
, cy
- y
);
150 RectFill(rp
, cx
- dx
, cy
+ y
, cx
+ dx
, cy
+ y
);
153 WritePixel(rp
, cx
- dx
, cy
- y
);
154 WritePixel(rp
, cx
- dx
, cy
+ y
);
157 WritePixel(rp
, cx
+ dx
, cy
- y
);
158 WritePixel(rp
, cx
+ dx
, cy
+ y
);
165 OrRectRegion(shape
, &rect
);
172 OrRectRegion(shape
, &rect
);
175 oldshape
= ChangeWindowShape(win
, shape
, NULL
);
176 if (oldshape
) DisposeRegion(oldshape
);
178 RefreshWindowFrame(win
);
181 /***********************************************************************************/
185 /***********************************************************************************/
187 static void action(void)
189 struct IntuiMessage
*msg
;
193 WaitPort(win
->UserPort
);
195 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
199 case IDCMP_CLOSEWINDOW
:
205 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
207 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
217 ReplyMsg((struct Message
*)msg
);
220 } while(!Keys
[KC_ESC
]);
223 /***********************************************************************************/
237 /***********************************************************************************/