1 #include <intuition/intuition.h>
2 #include <graphics/gfx.h>
3 #include <graphics/text.h>
4 #include <proto/exec.h>
5 #include <proto/intuition.h>
6 #include <proto/graphics.h>
12 /****************************************************************************************/
14 #define REGISTER_EXTRA_HEIGHT 4
15 #define REGISTERITEM_EXTRA_WIDTH 8
16 #define REGISTER_SPACE_LEFT 8
17 #define REGISTER_SPACE_RIGHT 8
21 struct RegisterItem
*items
;
39 WORD x1
, y1
, x2
, y2
, w
, h
;
43 /****************************************************************************************/
45 struct IntuitionBase
*IntuitionBase
;
46 struct GfxBase
*GfxBase
;
52 /****************************************************************************************/
54 struct RegisterItem myregisteritems
[] =
63 struct Register myregister
;
65 /****************************************************************************************/
67 static void cleanup(char *msg
)
69 if (msg
) printf("register: %s\n", msg
);
71 if (win
) CloseWindow(win
);
73 if (dri
) FreeScreenDrawInfo(scr
, dri
);
74 if (scr
) UnlockPubScreen(NULL
, scr
);
76 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
77 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
82 /****************************************************************************************/
84 static void openlibs(void)
86 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
88 cleanup("Can't open intuition.library V39!");
91 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
93 cleanup("Can't open graphics.library V39!");
97 /****************************************************************************************/
99 static void getvisual(void)
101 scr
= LockPubScreen(NULL
);
102 if (!scr
) cleanup("Can't lock pub screen!");
104 dri
= GetScreenDrawInfo(scr
);
105 if (!dri
) cleanup("Can't get drawinfo!");
109 /****************************************************************************************/
111 static void initregister(struct Register
*reg
, struct RegisterItem
*items
)
123 /****************************************************************************************/
125 static void layoutregister(struct Register
*reg
, struct Screen
*scr
,
126 struct DrawInfo
*dri
, BOOL samewidth
)
128 struct RastPort temprp
;
129 WORD i
, x
, biggest_w
= 0;
131 InitRastPort(&temprp
);
132 SetFont(&temprp
, dri
->dri_Font
);
134 reg
->fonth
= dri
->dri_Font
->tf_YSize
;
135 reg
->fontb
= dri
->dri_Font
->tf_Baseline
;
137 reg
->height
= ((reg
->fonth
+ REGISTER_EXTRA_HEIGHT
) + 3) & ~3; /* Multiple of 4 */
140 reg
->slopew
= (reg
->height
- 4) / 2;
142 for(i
= 0; i
< reg
->numitems
; i
++)
144 reg
->items
[i
].textlen
= strlen(reg
->items
[i
].text
);
145 reg
->items
[i
].w
= TextLength(&temprp
, reg
->items
[i
].text
, reg
->items
[i
].textlen
);
146 reg
->items
[i
].w
+= REGISTERITEM_EXTRA_WIDTH
+ reg
->slopew
* 2;
148 if (reg
->items
[i
].w
> biggest_w
) biggest_w
= reg
->items
[i
].w
;
153 for(i
= 0; i
< reg
->numitems
; i
++)
155 reg
->items
[i
].w
= biggest_w
;
159 x
= REGISTER_SPACE_LEFT
;
160 for(i
= 0; i
< reg
->numitems
; i
++)
162 reg
->items
[i
].x1
= x
;
163 reg
->items
[i
].y1
= 0;
164 reg
->items
[i
].x2
= x
+ reg
->items
[i
].w
- 1;
165 reg
->items
[i
].y2
= reg
->height
- 1;
166 reg
->items
[i
].h
= reg
->items
[i
].y2
- reg
->items
[i
].y1
+ 1;
167 reg
->items
[i
].tx
= reg
->items
[i
].w
/ 2 - TextLength(&temprp
, reg
->items
[i
].text
, reg
->items
[i
].textlen
) / 2;
168 reg
->items
[i
].ty
= reg
->fontb
+ reg
->items
[i
].h
/ 2 - reg
->fonth
/ 2;
170 x
+= reg
->items
[i
].w
- reg
->slopew
;
173 reg
->width
= x
+ reg
->slopew
+ REGISTER_SPACE_RIGHT
;
176 /****************************************************************************************/
178 static void setregisterpos(struct Register
*reg
, WORD left
, WORD top
)
184 /****************************************************************************************/
186 static void renderregisteritem(struct RastPort
*rp
, struct Register
*reg
, WORD item
)
188 struct RegisterItem
*ri
= ®
->items
[item
];
192 SetFont(rp
, reg
->dri
->dri_Font
);
194 x
= reg
->left
+ ri
->x1
;
195 y
= reg
->top
+ ri
->y1
;
198 SetAPen(rp
, reg
->dri
->dri_Pens
[(reg
->active
== item
) ? TEXTPEN
: BACKGROUNDPEN
]);
199 Move(rp
, x
+ ri
->tx
+ 1, y
+ ri
->ty
);
200 Text(rp
, ri
->text
, ri
->textlen
);
201 SetAPen(rp
, reg
->dri
->dri_Pens
[TEXTPEN
]);
202 Move(rp
, x
+ ri
->tx
, y
+ ri
->ty
);
203 Text(rp
, ri
->text
, ri
->textlen
);
205 /* upper / at left side */
207 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
208 WritePixel(rp
, x
+ reg
->slopew
, y
+ 2);
209 Move(rp
, x
+ reg
->slopew
/ 2, y
+ 3 + reg
->slopew
- 1);
210 Draw(rp
, x
+ reg
->slopew
- 1, y
+ 3);
212 /* --- at top side */
214 RectFill(rp
, x
+ reg
->slopew
+ 1, y
+ 1, x
+ reg
->slopew
+ 2, y
+ 1);
215 RectFill(rp
, x
+ reg
->slopew
+ 3, y
, x
+ ri
->w
- 1 - reg
->slopew
- 3, y
);
217 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
218 RectFill(rp
, x
+ ri
->w
- 1 - reg
->slopew
- 2, y
+ 1, x
+ ri
->w
- 1 - reg
->slopew
- 1, y
+ 1);
220 /* upper \ at right side */
222 WritePixel(rp
, x
+ ri
->w
- 1 - reg
->slopew
, y
+ 2);
223 Move(rp
, x
+ ri
->w
- 1 - reg
->slopew
+ 1, y
+ 3);
224 Draw(rp
, x
+ ri
->w
- 1 - reg
->slopew
/ 2, y
+ 3 + reg
->slopew
- 1);
226 /* lower / at left side. */
228 if ((item
== 0) || (reg
->active
== item
))
230 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
234 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
236 Move(rp
, x
, y
+ ri
->h
- 2);
237 Draw(rp
, x
+ reg
->slopew
/ 2 - 1, y
+ ri
->h
- 2 - reg
->slopew
+ 1);
239 /* lower \ at the lefst side from the previous item */
243 if (reg
->active
== item
)
245 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
249 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
251 Move(rp
, x
+ reg
->slopew
/ 2, y
+ ri
->h
- 2 - reg
->slopew
+ 1);
252 Draw(rp
, x
+ reg
->slopew
- 1, y
+ ri
->h
- 2);
255 /* lower \ at right side. */
257 if (reg
->active
== item
+ 1)
259 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
263 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
265 Move(rp
, x
+ ri
->w
- 1 - reg
->slopew
/ 2 + 1, y
+ ri
->h
- 2 - reg
->slopew
+ 1);
266 Draw(rp
, x
+ ri
->w
- 1, y
+ ri
->h
- 2);
268 if (reg
->active
== item
)
270 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
271 RectFill(rp
, x
, y
+ ri
->h
- 1, x
+ ri
->w
- 1, y
+ ri
->h
- 1);
280 if (reg
->active
== item
- 1)
282 else if (reg
->active
== item
+ 1)
285 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
286 RectFill(rp
, x1
, y
+ ri
->h
- 1, x2
, y
+ ri
->h
- 1);
292 /* \ at left side from previous item */
296 if (reg
->active
== item
)
298 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
302 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
305 Move(rp
, x
+ reg
->slopew
/ 2, y
+ ri
->h
- 2 - reg
->slopew
+ 1);
306 Draw(rp
, x
+ reg
->slopew
- 1, y
+ ri
->h
- 2);
312 /****************************************************************************************/
314 static void renderregister(struct RastPort
*rp
, struct Register
*reg
)
320 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
322 RectFill(rp
, reg
->left
,
323 reg
->top
+ reg
->height
- 1,
324 reg
->left
+ REGISTER_SPACE_LEFT
- 1,
325 reg
->top
+ reg
->height
- 1);
327 RectFill(rp
, reg
->left
+ reg
->width
- REGISTER_SPACE_RIGHT
,
328 reg
->top
+ reg
->height
- 1,
329 reg
->left
+ reg
->width
- 1,
330 reg
->top
+ reg
->height
- 1);
332 for(i
= 0; i
< reg
->numitems
; i
++)
334 renderregisteritem(rp
, reg
, i
);
340 /****************************************************************************************/
342 static BOOL
handleregisterinput(struct Register
*reg
, struct IntuiMessage
*msg
)
344 struct Window
*win
= msg
->IDCMPWindow
;
347 if ((msg
->Class
== IDCMP_MOUSEBUTTONS
) &&
348 (msg
->Code
== SELECTDOWN
))
351 WORD x
= win
->MouseX
- reg
->left
;
352 WORD y
= win
->MouseY
- reg
->top
;
354 for(i
= 0; i
< reg
->numitems
; i
++)
356 if ((x
>= reg
->items
[i
].x1
) &&
357 (y
>= reg
->items
[i
].y1
) &&
358 (x
<= reg
->items
[i
].x2
) &&
359 (y
<= reg
->items
[i
].y2
))
361 if (reg
->active
!= i
)
363 WORD oldactive
= reg
->active
;
366 renderregisteritem(win
->RPort
, reg
, oldactive
);
367 renderregisteritem(win
->RPort
, reg
, i
);
379 /****************************************************************************************/
381 static void makewin(void)
383 win
= OpenWindowTags(0, WA_PubScreen
, (IPTR
)scr
,
384 WA_Title
, (IPTR
) "Register Tabs",
385 WA_InnerWidth
, myregister
.width
+ 8,
386 WA_InnerHeight
, myregister
.height
+ 8,
387 WA_CloseGadget
, TRUE
,
388 WA_DepthGadget
, TRUE
,
390 WA_IDCMP
, IDCMP_CLOSEWINDOW
| IDCMP_MOUSEBUTTONS
,
393 if (!win
) cleanup("Can't open window!");
396 /****************************************************************************************/
398 static void handleall(void)
400 struct IntuiMessage
*msg
;
406 WaitPort(win
->UserPort
);
408 while((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
410 if (!handleregisterinput(&myregister
, msg
))
414 case IDCMP_CLOSEWINDOW
:
419 ReplyMsg((struct Message
*)msg
);
421 } /* while((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
423 } /* while(!quitme) */
426 /****************************************************************************************/
432 initregister(&myregister
, myregisteritems
);
433 layoutregister(&myregister
, scr
, dri
, TRUE
);
435 setregisterpos(&myregister
, win
->BorderLeft
+ 4, win
->BorderTop
+ 4);
436 renderregister(win
->RPort
, &myregister
);
442 /****************************************************************************************/
443 /****************************************************************************************/
444 /****************************************************************************************/
445 /****************************************************************************************/
446 /****************************************************************************************/
447 /****************************************************************************************/