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
,
96 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
101 if (!win
) cleanup("Can't open window");
107 /***********************************************************************************/
109 static void renderwin(void)
111 struct Region
*oldshape
;
112 struct Rectangle rect
;
115 static WORD oldheight
= 0;
116 static WORD oldwidth
= 0;
118 if (oldheight
== win
->GZZHeight
&& oldwidth
== win
->GZZWidth
)
121 oldheight
= win
->GZZHeight
;
122 oldwidth
= win
->GZZWidth
;
124 cx
= win
->BorderLeft
+ win
->GZZWidth
/ 2;
125 cy
= win
->BorderTop
+ win
->GZZHeight
/ 2;
127 r
= ((win
->GZZWidth
< win
->GZZHeight
) ? win
->GZZWidth
: win
->GZZHeight
) / 2 - 10;
129 #if INSTALL_NULL_SHAPE_FIRST
130 oldshape
= ChangeWindowShape(win
, shape
, NULL
);
131 if (oldshape
) DisposeRegion(oldshape
);
134 shape
= NewRectRegion(0, 0, win
->Width
- 1, win
->BorderTop
- 1);
136 rect
.MinX
= win
->Width
- win
->BorderRight
;
137 rect
.MinY
= win
->Height
- win
->BorderBottom
;
138 rect
.MaxX
= win
->Width
- 1;
139 rect
.MaxY
= win
->Height
- 1;
141 OrRectRegion(shape
, &rect
);
143 for(y
= 0; y
< r
; y
++)
145 WORD dx
= (WORD
)sqrt((double)(r
* r
- y
* y
));
148 RectFill(rp
, cx
- dx
, cy
- y
, cx
+ dx
, cy
- y
);
149 RectFill(rp
, cx
- dx
, cy
+ y
, cx
+ dx
, cy
+ y
);
152 WritePixel(rp
, cx
- dx
, cy
- y
);
153 WritePixel(rp
, cx
- dx
, cy
+ y
);
156 WritePixel(rp
, cx
+ dx
, cy
- y
);
157 WritePixel(rp
, cx
+ dx
, cy
+ y
);
164 OrRectRegion(shape
, &rect
);
171 OrRectRegion(shape
, &rect
);
174 oldshape
= ChangeWindowShape(win
, shape
, NULL
);
175 if (oldshape
) DisposeRegion(oldshape
);
177 RefreshWindowFrame(win
);
180 /***********************************************************************************/
184 /***********************************************************************************/
186 static void action(void)
188 struct IntuiMessage
*msg
;
192 WaitPort(win
->UserPort
);
194 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
198 case IDCMP_CLOSEWINDOW
:
204 WORD code
= msg
->Code
& ~IECODE_UP_PREFIX
;
206 Keys
[code
] = (code
== msg
->Code
) ? 1 : 0;
216 ReplyMsg((struct Message
*)msg
);
219 } while(!Keys
[KC_ESC
]);
222 /***********************************************************************************/
236 /***********************************************************************************/