Icons for Radium and Shellplayer.
[AROS-Contrib.git] / bgui / gfx.c
blobfa0500ed7709fecde0a5f055257d7272ac5f1fc3
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * gfx.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.6 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.5 2003/01/18 19:09:56 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.4 2000/08/09 11:45:57 chodorowski
21 * Removed a lot of #ifdefs that disabled the AROS_LIB* macros when not building on AROS. This is now handled in contrib/bgui/include/bgui_compilerspecific.h.
23 * Revision 42.3 2000/05/29 00:40:23 bergers
24 * Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
26 * Revision 42.2 2000/05/15 19:27:01 stegerg
27 * another hundreds of REG() macro replacements in func headers/protos.
29 * Revision 42.1 2000/05/14 23:32:47 stegerg
30 * changed over 200 function headers which all use register
31 * parameters (oh boy ...), because the simple REG() macro
32 * doesn't work with AROS. And there are still hundreds
33 * of headers left to be fixed :(
35 * Many of these functions would also work with stack
36 * params, but since i have fixed every single one
37 * I encountered up to now, I guess will have to do
38 * the same for the rest.
40 * Revision 42.0 2000/05/09 22:09:05 mlemos
41 * Bumped to revision 42.0 before handing BGUI to AROS team
43 * Revision 41.11 2000/05/09 19:54:20 mlemos
44 * Merged with the branch Manuel_Lemos_fixes.
46 * Revision 41.10.2.2 1999/07/04 05:16:05 mlemos
47 * Added a debuging version of the function BRectFill.
49 * Revision 41.10.2.1 1998/07/05 19:26:58 mlemos
50 * Added debugging code to trap invalid RectFill calls.
52 * Revision 41.10 1998/02/25 21:12:07 mlemos
53 * Bumping to 41.10
55 * Revision 1.1 1998/02/25 17:08:24 mlemos
56 * Ian sources
61 #include "include/classdefs.h"
64 * Default drawinfo pens.
66 makeproto UWORD DefDriPens[12] = { 0, 1, 1, 2, 1, 3, 1, 0, 2, 1, 2, 1 };
69 * Disabled pattern.
71 STATIC UWORD DisPat[2] = { 0x2222, 0x8888 };
74 * Calculate the text width.
76 makeproto ASM ULONG TextWidth(REG(a1) struct RastPort *rp, REG(a0) UBYTE *text)
78 return TextWidthNum(rp, text, strlen(text));
81 makeproto ASM ULONG TextWidthNum(REG(a1) struct RastPort *rp, REG(a0) UBYTE *text, REG(d0) ULONG len)
83 struct TextExtent te;
84 ULONG extent;
87 * Call TextExtent to find out the text width.
89 TextExtent(rp, text, len, &te);
92 * Figure out extent width.
94 extent = te.te_Extent.MaxX - te.te_Extent.MinX + 1;
97 * Return which ever is bigger.. extent or te.te_Width.
99 return( extent /*( extent > te.te_Width ) ? extent : te.te_Width */);
103 * Disable the given area.
105 makeproto ASM VOID BDisableBox(REG(a0) struct BaseInfo *bi, REG(a1) struct IBox *area)
107 BSetAfPt(bi, DisPat, 1);
108 BSetDrMd(bi, JAM1);
109 BSetDPenA(bi, SHADOWPEN);
110 BBoxFillA(bi, area);
111 BClearAfPt(bi);
114 #ifdef DEBUG_BGUI
115 makeproto ASM VOID SRectFillDebug(REG(a0) struct RastPort *rp, REG(d0) LONG l, REG(d1) LONG t, REG(d2) LONG r, REG(d3) LONG b,REG(a1) STRPTR file,REG(d4) ULONG line)
116 #else
117 ASM VOID SRectFill(REG(a0) struct RastPort *rp, REG(d0) LONG l, REG(d1) LONG t, REG(d2) LONG r, REG(d3) LONG b)
118 #endif
120 if ((r >= l) && (b >= t))
121 RectFill(rp, l, t, r, b);
122 #ifdef DEBUG_BGUI
123 else
124 D(bug("***Invalid RectFill (%lx,%ld,%ld,%ld,%ld) (%s,%lu)\n",rp,l,t,r,b,file ? file : (STRPTR)"Unknown file",line));
125 #endif
129 * Do a safe rect-fill.
131 #ifdef DEBUG_BGUI
132 makeproto ASM VOID BRectFillDebug(REG(a0) struct BaseInfo *bi, REG(d0) LONG l, REG(d1) LONG t, REG(d2) LONG r, REG(d3) LONG b,REG(a1) STRPTR file,REG(d4) ULONG line)
134 SRectFillDebug(bi->bi_RPort, l, t, r, b,file,line);
136 #else
137 ASM VOID BRectFill(REG(a0) struct BaseInfo *bi, REG(d0) LONG l, REG(d1) LONG t, REG(d2) LONG r, REG(d3) LONG b)
139 SRectFill(bi->bi_RPort, l, t, r, b);
141 #endif
145 * Render a frame/separator title.
147 makeproto VOID RenderTitle(Object *title, struct BaseInfo *bi, WORD l, WORD t, WORD w, BOOL highlight, BOOL center, UWORD place)
149 struct IBox box;
151 w -= 24;
152 l += 12;
154 if (w > 8)
156 DoMethod(title, TEXTM_DIMENSIONS, bi->bi_RPort, &box.Width, &box.Height);
159 * Figure out where to render.
161 if (box.Width > w) box.Width = w;
163 switch (place)
165 case 1:
166 box.Left = l;
167 break;
168 case 2:
169 box.Left = l + w - box.Width;
170 break;
171 default:
172 box.Left = l + ((w - box.Width) >> 1);
173 break;
175 if (box.Left < l) box.Left = l;
178 * Figure out y position.
180 if (center) box.Top = t - (box.Height >> 1);
181 else box.Top = t - bi->bi_RPort->TxBaseline;
184 * Setup rastport.
186 BSetDPenA(bi, BACKGROUNDPEN);
187 BSetDrMd(bi, JAM1);
188 BClearAfPt(bi);
191 * Clear text area.
193 BRectFill(bi, box.Left - 4, box.Top, box.Left + box.Width + 4, box.Top + box.Height);
195 BSetDPenA(bi, highlight ? HIGHLIGHTTEXTPEN : TEXTPEN);
196 DoMethod(title, TEXTM_RENDER, bi, &box);
200 makeproto VOID ASM SetDashedLine(REG(a0) struct BaseInfo *bi, REG(d0) UWORD offset)
203 * Render a SHINE/SHADOW pen, dotted box or,
204 * when the two pens are equal a SHADOW/BACKGROUND
205 * pen dotted box.
207 BSetDPenA(bi, SHINEPEN);
208 BSetDPenB(bi, SHADOWPEN);
209 BSetDrMd(bi, JAM2);
210 BSetDrPt(bi, 0xF0F0F0F0 >> offset);
212 if (bi->bi_RPort->FgPen == bi->bi_RPort->BgPen)
213 BSetDPenA(bi, BACKGROUNDPEN);
217 * Quickly render a bevelled box.
219 makeproto VOID RenderBevelBox(struct BaseInfo *bi, WORD l, WORD t, WORD r, WORD b, UWORD state, BOOL recessed, BOOL thin)
221 struct RastPort *rp = bi->bi_RPort;
224 * Selected or normal?
226 if ((state == IDS_SELECTED) || (state == IDS_INACTIVESELECTED))
228 recessed = !recessed;
232 * Shiny side.
234 BSetDPenA(bi, recessed ? SHADOWPEN : SHINEPEN);
236 HLine(rp, l, t, r);
237 VLine(rp, l, t, b - 1);
238 if (!thin) VLine(rp, l + 1, t + 1, b - 1);
241 * Shadow side.
243 BSetDPenA(bi, recessed ? SHINEPEN : SHADOWPEN);
245 HLine(rp, l, b, r);
246 VLine(rp, r, t + 1, b);
247 if (!thin) VLine(rp, r - 1, t + 1, b - 1);
250 makeproto ASM VOID BRectFillA(REG(a0) struct BaseInfo *bi, REG(a1) struct Rectangle *rect)
252 BRectFill(bi, rect->MinX, rect->MinY, rect->MaxX, rect->MaxY);
255 makeproto ASM VOID BBoxFill(REG(a0) struct BaseInfo *bi, REG(d0) LONG l, REG(d1) LONG t, REG(d2) LONG w, REG(d3) LONG h)
257 SRectFill(bi->bi_RPort, l, t, l + w - 1, t + h - 1);
260 makeproto ASM VOID BBoxFillA(REG(a0) struct BaseInfo *bi, REG(a1) struct IBox *box)
262 BBoxFill(bi, box->Left, box->Top, box->Width, box->Height);
266 * Background filling.
268 #ifdef DEBUG_BGUI
269 makeproto ASM VOID RenderBackFillRasterDebug(REG(a0) struct RastPort *rp, REG(a1) struct IBox *ib, REG(d0) UWORD apen, REG(d1) UWORD bpen,REG(a2) STRPTR file, REG(d2) ULONG line)
270 #else
271 ASM VOID RenderBackFillRaster(REG(a0) struct RastPort *rp, REG(a1) struct IBox *ib, REG(d0) UWORD apen, REG(d1) UWORD bpen)
272 #endif
274 static UWORD pat[] = { 0x5555, 0xAAAA };
276 * Setup RastPort.
279 FSetABPenDrMd(rp, apen, bpen, JAM2);
281 if (apen == bpen)
283 FSetDrMd(rp, JAM1);
284 FClearAfPt(rp);
286 else
288 SetAfPt(rp, pat, 1);
292 * Render...
294 #ifdef DEBUG_BGUI
295 SRectFillDebug(rp, ib->Left, ib->Top, ib->Left + ib->Width - 1, ib->Top + ib->Height - 1,file,line);
296 #else
297 SRectFill(rp, ib->Left, ib->Top, ib->Left + ib->Width - 1, ib->Top + ib->Height - 1);
298 #endif
301 * Clear area pattern.
303 FClearAfPt(rp);
307 makeproto ASM VOID RenderBackFill(REG(a0) struct RastPort *rp, REG(a1) struct IBox *ib, REG(a2) UWORD *pens, REG(d0) ULONG type)
309 int apen, bpen;
311 if (!pens) pens = DefDriPens;
314 * Which type?
316 switch (type)
318 case SHINE_RASTER:
319 apen = SHINEPEN;
320 bpen = BACKGROUNDPEN;
321 break;
323 case SHADOW_RASTER:
324 apen = SHADOWPEN;
325 bpen = BACKGROUNDPEN;
326 break;
328 case SHINE_SHADOW_RASTER:
329 apen = SHINEPEN;
330 bpen = SHADOWPEN;
331 break;
333 case FILL_RASTER:
334 apen = FILLPEN;
335 bpen = BACKGROUNDPEN;
336 break;
338 case SHINE_FILL_RASTER:
339 apen = SHINEPEN;
340 bpen = FILLPEN;
341 break;
343 case SHADOW_FILL_RASTER:
344 apen = SHADOWPEN;
345 bpen = FILLPEN;
346 break;
348 case SHINE_BLOCK:
349 apen = SHINEPEN;
350 bpen = apen;
351 break;
353 case SHADOW_BLOCK:
354 apen = SHADOWPEN;
355 bpen = apen;
356 break;
358 default:
359 apen = BACKGROUNDPEN;
360 bpen = apen;
361 break;
363 RenderBackFillRaster(rp, ib, pens[apen], pens[bpen]);
367 * Draw a dotted box.
369 makeproto ASM VOID DottedBox(REG(a0) struct BaseInfo *bi, REG(a1) struct IBox *ibx)
371 int x1 = ibx->Left;
372 int x2 = ibx->Left + ibx->Width - 1;
373 int y1 = ibx->Top;
374 int y2 = ibx->Top + ibx->Height - 1;
376 ULONG secs, micros, hundredths;
378 struct RastPort *rp = bi->bi_RPort;
381 * We clear any thick framing which may be
382 * there or not.
384 BSetDPenA(bi, BACKGROUNDPEN);
385 Move(rp, x1 + 1, y1 + 1);
386 Draw(rp, x1 + 1, y2 - 1);
387 Draw(rp, x2 - 1, y2 - 1);
388 Draw(rp, x2 - 1, y1 + 1);
389 Draw(rp, x1 + 2, y1 + 1);
391 CurrentTime(&secs, &micros);
392 hundredths = ((secs & 0xFFFFFF) * 100) + (micros / 10000);
393 SetDashedLine(bi, (hundredths / 5) % 8);
396 * Draw the box.
398 Move(rp, x1, y1);
399 Draw(rp, x2, y1);
400 Draw(rp, x2, y2);
401 Draw(rp, x1, y2);
402 Draw(rp, x1, y1 + 1);
406 * Find out rendering state.
408 makeproto ASM ULONG GadgetState(REG(a0) struct BaseInfo *bi, REG(a1) Object *obj, REG(d0) BOOL norec)
410 BOOL active = !(GADGET(obj)->Activation & BORDERMASK) || (bi->bi_IWindow->Flags & WFLG_WINDOWACTIVE);
411 BOOL normal = !(GADGET(obj)->Flags & GFLG_SELECTED) || norec;
413 return active ? (ULONG)(normal ? IDS_NORMAL : IDS_SELECTED)
414 : (ULONG)(normal ? IDS_INACTIVENORMAL : IDS_INACTIVESELECTED);
417 #ifdef __AROS__
418 makearosproto
419 AROS_LH6(VOID, BGUI_FillRectPattern,
420 AROS_LHA(struct RastPort *, r, A1),
421 AROS_LHA(struct bguiPattern *, bp, A0),
422 AROS_LHA(ULONG, x1, D0),
423 AROS_LHA(ULONG, y1, D1),
424 AROS_LHA(ULONG, x2, D2),
425 AROS_LHA(ULONG, y2, D3),
426 struct Library *, BGUIBase, 22, BGUI)
427 #else
428 makeproto SAVEDS ASM VOID BGUI_FillRectPattern(REG(a1) struct RastPort *r, REG(a0) struct bguiPattern *bp,
429 REG(d0) ULONG x1, REG(d1) ULONG y1, REG(d2) ULONG x2, REG(d3) ULONG y2)
430 #endif
432 AROS_LIBFUNC_INIT
434 int i, j;
436 int x0 = bp->bp_Left;
437 int y0 = bp->bp_Top;
438 int w = bp->bp_Width;
439 int h = bp->bp_Height;
441 int col_min, col_max;
442 int row_min, row_max;
444 int from_x, to_x1, to_x2, to_w;
445 int from_y, to_y1, to_y2, to_h;
447 struct BitMap *bm = bp->bp_BitMap;
449 if (bm && w && h)
451 col_min = x1 / w;
452 row_min = y1 / h;
453 col_max = x2++ / w + 1;
454 row_max = y2++ / h + 1;
456 for (i = col_min; i <= col_max; i++)
458 to_x1 = i * w;
459 to_x2 = to_x1 + w;
461 if (to_x1 < x1)
463 from_x = x0 + x1 - to_x1;
464 to_x1 = x1;
466 else
468 from_x = x0;
470 if (to_x2 > x2)
472 to_x2 = x2;
474 if ((to_w = to_x2 - to_x1) > 0)
476 for (j = row_min; j <= row_max; j++)
478 to_y1 = j * h;
479 to_y2 = to_y1 + h;
481 if (to_y1 < y1)
483 from_y = y0 + y1 - to_y1;
484 to_y1 = y1;
486 else
488 from_y = y0;
490 if (to_y2 > y2)
492 to_y2 = y2;
494 if ((to_h = to_y2 - to_y1) > 0)
496 BltBitMapRastPort(bm, from_x, from_y, r, to_x1, to_y1, to_w, to_h, 0xC0);
503 AROS_LIBFUNC_EXIT
506 makeproto VOID ASM HLine(REG(a1) struct RastPort *rp, REG(d0) UWORD l, REG(d1) UWORD t, REG(d2) UWORD r)
508 Move(rp, l, t);
509 Draw(rp, r, t);
512 makeproto VOID ASM VLine(REG(a1) struct RastPort *rp, REG(d0) UWORD l, REG(d1) UWORD t, REG(d2) UWORD b)
514 Move(rp, l, t);
515 Draw(rp, l, b);
518 makeproto ASM ULONG FGetAPen(REG(a1) struct RastPort *rp)
520 #ifdef ENHANCED
521 return GetAPen(rp);
522 #else
523 if (OS30) return GetAPen(rp);
524 return rp->FgPen;
525 #endif
528 makeproto ASM ULONG FGetBPen(REG(a1) struct RastPort *rp)
530 #ifdef ENHANCED
531 return GetBPen(rp);
532 #else
533 if (OS30) return GetBPen(rp);
534 return rp->BgPen;
535 #endif
538 makeproto ASM ULONG FGetDrMd(REG(a1) struct RastPort *rp)
540 #ifdef ENHANCED
541 return GetDrMd(rp);
542 #else
543 if (OS30) return GetDrMd(rp);
544 return rp->DrawMode;
545 #endif
548 makeproto ASM ULONG FGetDepth(REG(a1) struct RastPort *rp)
550 #ifdef ENHANCED
551 return (ULONG)GetBitMapAttr(rp->BitMap, BMA_DEPTH);
552 #else
553 if (OS30) return GetBitMapAttr(rp->BitMap, BMA_DEPTH);
554 return rp->BitMap->Depth;
555 #endif
558 makeproto ASM VOID FSetAPen(REG(a1) struct RastPort *rp, REG(d0) ULONG pen)
560 #ifdef ENHANCED
561 SetRPAttrs(rp, RPTAG_APen, pen, TAG_END);
562 #else
563 if (OS30) SetRPAttrs(rp, RPTAG_APen, pen, TAG_END);
564 else if (rp->FgPen != pen) SetAPen(rp, pen);
565 #endif
568 makeproto ASM VOID FSetBPen(REG(a1) struct RastPort *rp, REG(d0) ULONG pen)
570 #ifdef ENHANCED
571 SetRPAttrs(rp, RPTAG_BPen, pen, TAG_END);
572 #else
573 if (OS30) SetRPAttrs(rp, RPTAG_BPen, pen, TAG_END);
574 else if (rp->BgPen != pen) SetBPen(rp, pen);
575 #endif
578 makeproto ASM VOID FSetDrMd(REG(a1) struct RastPort *rp, REG(d0) ULONG drmd)
580 #ifdef ENHANCED
581 SetRPAttrs(rp, RPTAG_DrMd, drmd, TAG_END);
582 #else
583 if (OS30) SetRPAttrs(rp, RPTAG_DrMd, drmd, TAG_END);
584 else if (rp->DrawMode != drmd) SetDrMd(rp, drmd);
585 #endif
588 makeproto ASM VOID FSetABPenDrMd(REG(a1) struct RastPort *rp, REG(d0) ULONG apen, REG(d1) ULONG bpen, REG(d2) ULONG mode)
590 #ifdef ENHANCED
591 SetABPenDrMd(rp, apen, bpen, mode);
592 #else
593 if (OS30) SetABPenDrMd(rp, apen, bpen, mode);
594 else
596 SetAPen(rp, apen);
597 SetBPen(rp, bpen);
598 SetDrMd(rp, mode);
600 #endif
603 makeproto ASM VOID FSetFont(REG(a1) struct RastPort *rp, REG(a0) struct TextFont *tf)
605 #ifdef ENHANCED
606 SetRPAttrs(rp, RPTAG_Font, tf, TAG_END);
607 #else
608 if (OS30) SetRPAttrs(rp, RPTAG_Font, tf, TAG_END);
609 else
611 if (rp->Font != tf) SetFont(rp, tf);
613 #endif
616 makeproto ASM VOID FSetFontStyle(REG(a1) struct RastPort *rp, REG(d0) ULONG style)
618 SetSoftStyle(rp, style, AskSoftStyle(rp));
621 makeproto ASM VOID FClearAfPt(REG(a1) struct RastPort *rp)
623 SetAfPt(rp, NULL, 0);
626 makeproto ASM VOID BSetDPenA(REG(a0) struct BaseInfo *bi, REG(d0) LONG pen)
628 FSetAPen(bi->bi_RPort, bi->bi_Pens[pen]);
631 makeproto ASM VOID BSetPenA(REG(a0) struct BaseInfo *bi, REG(d0) ULONG pen)
633 FSetAPen(bi->bi_RPort, pen);
636 makeproto ASM VOID BSetDPenB(REG(a0) struct BaseInfo *bi, REG(d0) LONG pen)
638 FSetBPen(bi->bi_RPort, bi->bi_Pens[pen]);
641 makeproto ASM VOID BSetPenB(REG(a0) struct BaseInfo *bi, REG(d0) ULONG pen)
643 FSetBPen(bi->bi_RPort, pen);
646 makeproto ASM VOID BSetDrMd(REG(a0) struct BaseInfo *bi, REG(d0) ULONG drmd)
648 FSetDrMd(bi->bi_RPort, drmd);
651 makeproto ASM VOID BSetFont(REG(a0) struct BaseInfo *bi, REG(a1) struct TextFont *tf)
653 FSetFont(bi->bi_RPort, tf);
656 makeproto ASM VOID BSetFontStyle(REG(a0) struct BaseInfo *bi, REG(d0) ULONG style)
658 SetSoftStyle(bi->bi_RPort, style, AskSoftStyle(bi->bi_RPort));
661 makeproto ASM VOID BSetAfPt(REG(a0) struct BaseInfo *bi, REG(a1) UWORD *pat, REG(d0) ULONG size)
663 SetAfPt(bi->bi_RPort, pat, size);
666 makeproto ASM VOID BClearAfPt(REG(a0) struct BaseInfo *bi)
668 SetAfPt(bi->bi_RPort, NULL, 0);
671 makeproto ASM VOID BSetDrPt(REG(a0) struct BaseInfo *bi, REG(d0) ULONG pat)
673 SetDrPt(bi->bi_RPort, pat & 0xFFFF);
676 makeproto ASM VOID BDrawImageState(REG(a0) struct BaseInfo *bi, REG(a1) Object *image,
677 REG(d0) ULONG x, REG(d1) ULONG y, REG(d2) ULONG state)
679 //tprintf("%08lx %08lx %ld %ld %04lx %08lx\n", /4*
680 DrawImageState(bi->bi_RPort, IMAGE(image), x, y, state, bi->bi_DrInfo);