Initial commit
[amiga/OpenBoopsi.git] / common / GetGadgetBox.c
1 /*
2 **      $Id:$
3 **
4 **      Copyright (C) 1999 Bernardo Innocenti
5 **      All rights reserved.
6 **
7 **      Use 4 chars wide TABs to read this file
8 **
9 **      GetGadgetBox() computes the actual IBox where a gadget exists in a window.
10 **      The special cases it handles are all the REL#? (relative positioning flags).
11 **
12 **      This function returns the gadget size in the provided
13 **      IBox structure, computing the values from the coordinates
14 **      in the gadget structure and the container (window or requester)
15 **      where it lives.
16 */
17
18 #include <intuition/intuition.h>
19
20 #include <CompilerSpecific.h>
21 #include <DebugMacros.h>
22 #include <BoopsiLib.h>
23
24
25 void GetGadgetBox(struct GadgetInfo *ginfo, struct ExtGadget *g, struct IBox *box)
26 {
27         ASSERT_VALID_PTR(g)
28         ASSERT_VALID_PTR(ginfo)
29         ASSERT_VALID_PTR(box)
30
31         DB2(if (g->Flags & GFLG_EXTENDED)
32                 DBPRINTF("GetGadgetBox(): GFLG_EXTENDED is set\n");)
33         DB2(if ((g->Flags & GFLG_EXTENDED) && (g->MoreFlags & GMORE_BOUNDS))
34                 DBPRINTF("GetGadgetBox(): Gadget has valid bounds\n");)
35
36
37         box->Left = g->LeftEdge;
38         if (g->Flags & GFLG_RELRIGHT)
39                 box->Left += ginfo->gi_Domain.Width - 1;
40
41         box->Top = g->TopEdge;
42         if (g->Flags & GFLG_RELBOTTOM)
43                 box->Top += ginfo->gi_Domain.Height - 1;
44
45         box->Width = g->Width;
46         if (g->Flags & GFLG_RELWIDTH)
47                 box->Width += ginfo->gi_Domain.Width;
48
49         box->Height = g->Height;
50         if (g->Flags & GFLG_RELHEIGHT)
51                 box->Height += ginfo->gi_Domain.Height;
52
53         DB2(DBPRINTF("GetGadgetBox(): Left = %ld, Top = %ld, Width = %ld, Height = %ld\n",
54                 box->Left, box->Top, box->Width, box->Height);)
55 }
56
57
58
59 /* Useful macro missing in <intuition/imageclass.h> */
60 #define GADGET_BOUNDS(g) ((struct IBox *)&((struct ExtGadget *)(g))->BoundsLeftEdge)
61
62
63 void GetGadgetBounds(struct GadgetInfo *ginfo, struct ExtGadget *g, struct IBox *bounds)
64 {
65         struct IBox *box;
66
67         ASSERT_VALID_PTR(g)
68         ASSERT_VALID_PTR(ginfo)
69         ASSERT_VALID_PTR(bounds)
70
71
72         box = ((g->Flags & GFLG_EXTENDED) && (g->MoreFlags & GMORE_BOUNDS)) ?
73                 GADGET_BOUNDS(g) : GADGET_BOX(g);
74
75         memcpy(bounds, box, sizeof(struct IBox));
76
77         if (g->Flags & GFLG_RELRIGHT)
78                 bounds->Left += ginfo->gi_Domain.Width - 1;
79
80         if (g->Flags & GFLG_RELBOTTOM)
81                 bounds->Top += ginfo->gi_Domain.Height - 1;
82
83         if (g->Flags & GFLG_RELWIDTH)
84                 bounds->Width += ginfo->gi_Domain.Width;
85
86         if (g->Flags & GFLG_RELHEIGHT)
87                 bounds->Height += ginfo->gi_Domain.Height;
88 }