2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
10 #include "registertab.h"
14 /****************************************************************************************/
16 #define IMWIDTH(x) (((struct Image *)(x))->Width)
17 #define IMHEIGHT(x) (((struct Image *)(x))->Height)
19 /****************************************************************************************/
21 void InitRegisterTab(struct RegisterTab
*reg
, struct RegisterTabItem
*items
)
33 /****************************************************************************************/
35 void LayoutRegisterTab(struct RegisterTab
*reg
, struct Screen
*scr
,
36 struct DrawInfo
*dri
, BOOL samewidth
)
38 struct RastPort temprp
;
39 WORD i
, x
, h
, biggest_w
= 0;
41 InitRastPort(&temprp
);
42 SetFont(&temprp
, dri
->dri_Font
);
45 reg
->fonth
= dri
->dri_Font
->tf_YSize
;
46 reg
->fontb
= dri
->dri_Font
->tf_Baseline
;
49 for(i
= 0; i
< reg
->numitems
; i
++)
51 if (reg
->items
[i
].image
)
53 if (IMHEIGHT(reg
->items
[i
].image
) > h
) h
= IMHEIGHT(reg
->items
[i
].image
);
57 if (h
) h
+= REGISTERTAB_IMEXTRA_HEIGHT
;
59 i
= reg
->fonth
+ REGISTERTAB_EXTRA_HEIGHT
;
62 reg
->height
= (h
+ 3) & ~3; /* Multiple of 4 */
66 reg
->slopew
= (reg
->height
- 4) / 2;
68 for(i
= 0; i
< reg
->numitems
; i
++)
70 reg
->items
[i
].textlen
= strlen(reg
->items
[i
].text
);
71 reg
->items
[i
].w
= TextLength(&temprp
, reg
->items
[i
].text
, reg
->items
[i
].textlen
);
72 reg
->items
[i
].w
+= REGISTERTABITEM_EXTRA_WIDTH
+ reg
->slopew
* 2;
74 if (reg
->items
[i
].image
)
76 reg
->items
[i
].w
+= REGISTERTAB_IMAGE_TEXT_SPACE
+
77 ((struct Image
*)reg
->items
[i
].image
)->Width
;
80 if (reg
->items
[i
].w
> biggest_w
) biggest_w
= reg
->items
[i
].w
;
85 for(i
= 0; i
< reg
->numitems
; i
++)
87 reg
->items
[i
].w
= biggest_w
;
91 x
= REGISTERTAB_SPACE_LEFT
;
92 for(i
= 0; i
< reg
->numitems
; i
++)
96 itemwidth
= TextLength(&temprp
, reg
->items
[i
].text
, reg
->items
[i
].textlen
);
98 if (reg
->items
[i
].image
)
100 to
= IMWIDTH(reg
->items
[i
].image
) + REGISTERTAB_IMAGE_TEXT_SPACE
;
104 reg
->items
[i
].x1
= x
;
105 reg
->items
[i
].y1
= 0;
106 reg
->items
[i
].x2
= x
+ reg
->items
[i
].w
- 1;
107 reg
->items
[i
].y2
= reg
->height
- 1;
108 reg
->items
[i
].h
= reg
->items
[i
].y2
- reg
->items
[i
].y1
+ 1;
109 reg
->items
[i
].ix
= (reg
->items
[i
].w
- itemwidth
) / 2;
110 if (reg
->items
[i
].image
)
112 reg
->items
[i
].iy
= (reg
->items
[i
].h
- IMHEIGHT(reg
->items
[i
].image
)) / 2;
115 reg
->items
[i
].tx
= reg
->items
[i
].ix
+ to
;
116 reg
->items
[i
].ty
= reg
->fontb
+ (reg
->items
[i
].h
- reg
->fonth
) / 2;
119 x
+= reg
->items
[i
].w
- reg
->slopew
;
122 reg
->width
= x
+ reg
->slopew
+ REGISTERTAB_SPACE_RIGHT
;
124 DeinitRastPort(&temprp
);
127 /****************************************************************************************/
129 void SetRegisterTabPos(struct RegisterTab
*reg
, WORD left
, WORD top
)
135 /****************************************************************************************/
137 void SetRegisterTabFrameSize(struct RegisterTab
*reg
, WORD width
, WORD height
)
139 reg
->framewidth
= width
;
140 reg
->frameheight
= height
;
143 /****************************************************************************************/
145 void RenderRegisterTabItem(struct RastPort
*rp
, struct RegisterTab
*reg
, WORD item
)
147 struct RegisterTabItem
*ri
= ®
->items
[item
];
151 SetFont(rp
, reg
->dri
->dri_Font
);
153 x
= reg
->left
+ ri
->x1
;
154 y
= reg
->top
+ ri
->y1
;
157 SetAPen(rp
, reg
->dri
->dri_Pens
[(reg
->active
== item
) ? TEXTPEN
: BACKGROUNDPEN
]);
158 Move(rp
, x
+ ri
->tx
+ 1, y
+ ri
->ty
);
159 Text(rp
, ri
->text
, ri
->textlen
);
160 SetAPen(rp
, reg
->dri
->dri_Pens
[TEXTPEN
]);
161 Move(rp
, x
+ ri
->tx
, y
+ ri
->ty
);
162 Text(rp
, ri
->text
, ri
->textlen
);
166 DrawImageState(rp
, (struct Image
*) ri
->image
, x
+ ri
->ix
, y
+ ri
->iy
, IDS_NORMAL
, dri
);
169 /* upper / at left side */
171 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
172 WritePixel(rp
, x
+ reg
->slopew
, y
+ 2);
173 Move(rp
, x
+ reg
->slopew
/ 2, y
+ 3 + reg
->slopew
- 1);
174 Draw(rp
, x
+ reg
->slopew
- 1, y
+ 3);
176 /* --- at top side */
178 RectFill(rp
, x
+ reg
->slopew
+ 1, y
+ 1, x
+ reg
->slopew
+ 2, y
+ 1);
179 RectFill(rp
, x
+ reg
->slopew
+ 3, y
, x
+ ri
->w
- 1 - reg
->slopew
- 3, y
);
181 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
182 RectFill(rp
, x
+ ri
->w
- 1 - reg
->slopew
- 2, y
+ 1, x
+ ri
->w
- 1 - reg
->slopew
- 1, y
+ 1);
184 /* upper \ at right side */
186 WritePixel(rp
, x
+ ri
->w
- 1 - reg
->slopew
, y
+ 2);
187 Move(rp
, x
+ ri
->w
- 1 - reg
->slopew
+ 1, y
+ 3);
188 Draw(rp
, x
+ ri
->w
- 1 - reg
->slopew
/ 2, y
+ 3 + reg
->slopew
- 1);
190 /* lower / at left side. */
192 if ((item
== 0) || (reg
->active
== item
))
194 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
198 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
200 Move(rp
, x
, y
+ ri
->h
- 2);
201 Draw(rp
, x
+ reg
->slopew
/ 2 - 1, y
+ ri
->h
- 2 - reg
->slopew
+ 1);
203 /* lower \ at the lefst side from the previous item */
207 if (reg
->active
== item
)
209 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
213 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
215 Move(rp
, x
+ reg
->slopew
/ 2, y
+ ri
->h
- 2 - reg
->slopew
+ 1);
216 Draw(rp
, x
+ reg
->slopew
- 1, y
+ ri
->h
- 2);
219 /* lower \ at right side. */
221 if (reg
->active
== item
+ 1)
223 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
227 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
229 Move(rp
, x
+ ri
->w
- 1 - reg
->slopew
/ 2 + 1, y
+ ri
->h
- 2 - reg
->slopew
+ 1);
230 Draw(rp
, x
+ ri
->w
- 1, y
+ ri
->h
- 2);
232 if (reg
->active
== item
)
234 SetAPen(rp
, reg
->dri
->dri_Pens
[BACKGROUNDPEN
]);
235 RectFill(rp
, x
, y
+ ri
->h
- 1, x
+ ri
->w
- 1, y
+ ri
->h
- 1);
244 if (reg
->active
== item
- 1)
246 else if (reg
->active
== item
+ 1)
249 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
250 RectFill(rp
, x1
, y
+ ri
->h
- 1, x2
, y
+ ri
->h
- 1);
255 /****************************************************************************************/
257 void RenderRegisterTab(struct RastPort
*rp
, struct RegisterTab
*reg
, BOOL alsoframe
)
263 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
265 RectFill(rp
, reg
->left
,
266 reg
->top
+ reg
->height
- 1,
267 reg
->left
+ REGISTERTAB_SPACE_LEFT
- 1,
268 reg
->top
+ reg
->height
- 1);
270 RectFill(rp
, reg
->left
+ reg
->width
- REGISTERTAB_SPACE_RIGHT
,
271 reg
->top
+ reg
->height
- 1,
272 reg
->left
+ reg
->width
- 1,
273 reg
->top
+ reg
->height
- 1);
275 for(i
= 0; i
< reg
->numitems
; i
++)
277 RenderRegisterTabItem(rp
, reg
, i
);
282 SetAPen(rp
, reg
->dri
->dri_Pens
[SHINEPEN
]);
284 RectFill(rp
, reg
->left
,
285 reg
->top
+ reg
->height
- 1,
287 reg
->top
+ reg
->height
+ reg
->frameheight
- 1);
289 RectFill(rp
, reg
->left
+ reg
->width
,
290 reg
->top
+ reg
->height
- 1,
291 reg
->left
+ reg
->framewidth
- 2,
292 reg
->top
+ reg
->height
- 1);
294 SetAPen(rp
, reg
->dri
->dri_Pens
[SHADOWPEN
]);
296 RectFill(rp
, reg
->left
+ reg
->framewidth
- 1,
297 reg
->top
+ reg
->height
- 1,
298 reg
->left
+ reg
->framewidth
- 1,
299 reg
->top
+ reg
->height
+ reg
->frameheight
- 1);
301 RectFill(rp
, reg
->left
+ 1,
302 reg
->top
+ reg
->height
+ reg
->frameheight
- 1,
303 reg
->left
+ reg
->framewidth
- 2,
304 reg
->top
+ reg
->height
+ reg
->frameheight
- 1);
308 /****************************************************************************************/
310 BOOL
HandleRegisterTabInput(struct RegisterTab
*reg
, struct IntuiMessage
*msg
)
312 struct Window
*win
= msg
->IDCMPWindow
;
315 if ((msg
->Class
== IDCMP_MOUSEBUTTONS
) &&
316 (msg
->Code
== SELECTDOWN
))
319 WORD x
= win
->MouseX
- reg
->left
;
320 WORD y
= win
->MouseY
- reg
->top
;
322 for(i
= 0; i
< reg
->numitems
; i
++)
324 if ((x
>= reg
->items
[i
].x1
) &&
325 (y
>= reg
->items
[i
].y1
) &&
326 (x
<= reg
->items
[i
].x2
) &&
327 (y
<= reg
->items
[i
].y2
))
331 if (reg
->active
!= i
)
333 WORD oldactive
= reg
->active
;
336 RenderRegisterTabItem(win
->RPort
, reg
, oldactive
);
337 RenderRegisterTabItem(win
->RPort
, reg
, i
);
349 /****************************************************************************************/
350 /****************************************************************************************/