3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <proto/exec.h>
7 #include <proto/graphics.h>
8 #include <proto/intuition.h>
14 #define INSTALL_NULL_SHAPE_FIRST 0
19 /***********************************************************************************/
21 struct IntuitionBase
*IntuitionBase
;
22 struct GfxBase
*GfxBase
;
30 /***********************************************************************************/
32 static void cleanup(char *msg
)
36 printf("roundshape: %s\n",msg
);
39 if (win
) CloseWindow(win
);
40 if (shape
) DisposeRegion(shape
);
41 if (scr
) UnlockPubScreen(0, scr
);
43 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
44 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
49 /***********************************************************************************/
51 static void openlibs(void)
53 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
55 cleanup("Can't open intuition.library V39!");
58 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
60 cleanup("Can't open graphics.library V39!");
65 /***********************************************************************************/
67 static void getvisual(void)
69 if (!(scr
= LockPubScreen(NULL
)))
71 cleanup("Can't lock pub screen!");
75 /***********************************************************************************/
77 static void makewin(void)
79 win
= OpenWindowTags(NULL
, WA_CustomScreen
, (IPTR
)scr
,
80 WA_InnerWidth
, WINWIDTH
,
81 WA_InnerHeight
, WINHEIGHT
,
82 WA_Title
, (IPTR
)"Round Shape",
84 WA_DepthGadget
, TRUE
,
85 WA_CloseGadget
, TRUE
,
92 WA_SizeBBottom
, TRUE
,
94 WA_NoCareRefresh
, TRUE
,
95 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
100 if (!win
) cleanup("Can't open window");
106 /***********************************************************************************/
108 static void renderwin(void)
110 struct Region
*oldshape
;
111 struct Rectangle rect
;
114 static WORD oldheight
= 0;
115 static WORD oldwidth
= 0;
117 if (oldheight
== win
->GZZHeight
&& oldwidth
== win
->GZZWidth
)
120 oldheight
= win
->GZZHeight
;
121 oldwidth
= win
->GZZWidth
;
123 cx
= win
->BorderLeft
+ win
->GZZWidth
/ 2;
124 cy
= win
->BorderTop
+ win
->GZZHeight
/ 2;
126 r
= ((win
->GZZWidth
< win
->GZZHeight
) ? win
->GZZWidth
: win
->GZZHeight
) / 2 - 10;
128 #if INSTALL_NULL_SHAPE_FIRST
129 oldshape
= ChangeWindowShape(win
, shape
, NULL
);
130 if (oldshape
) DisposeRegion(oldshape
);
133 shape
= NewRectRegion(0, 0, win
->Width
- 1, win
->BorderTop
- 1);
135 rect
.MinX
= win
->Width
- win
->BorderRight
;
136 rect
.MinY
= win
->Height
- win
->BorderBottom
;
137 rect
.MaxX
= win
->Width
- 1;
138 rect
.MaxY
= win
->Height
- 1;
140 OrRectRegion(shape
, &rect
);
142 for(y
= 0; y
< r
; y
++)
144 WORD dx
= (WORD
)sqrt((double)(r
* r
- y
* y
));
147 RectFill(rp
, cx
- dx
, cy
- y
, cx
+ dx
, cy
- y
);
148 RectFill(rp
, cx
- dx
, cy
+ y
, cx
+ dx
, cy
+ y
);
151 WritePixel(rp
, cx
- dx
, cy
- y
);
152 WritePixel(rp
, cx
- dx
, cy
+ y
);
155 WritePixel(rp
, cx
+ dx
, cy
- y
);
156 WritePixel(rp
, cx
+ dx
, cy
+ y
);
163 OrRectRegion(shape
, &rect
);
170 OrRectRegion(shape
, &rect
);
173 oldshape
= ChangeWindowShape(win
, shape
, NULL
);
174 if (oldshape
) DisposeRegion(oldshape
);
176 RefreshWindowFrame(win
);
179 /***********************************************************************************/
183 /***********************************************************************************/
185 static void action(void)
187 struct IntuiMessage
*msg
;
191 WaitPort(win
->UserPort
);
193 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
197 case IDCMP_CLOSEWINDOW
:
203 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
205 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
215 ReplyMsg((struct Message
*)msg
);
218 } while(!Keys
[KC_ESC
]);
221 /***********************************************************************************/
235 /***********************************************************************************/