home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / intuition / gadgets.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  2KB  |  109 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: gadgets.c,v 1.3 1997/01/27 00:36:38 ldp Exp $
  4.  
  5.     Desc: Common routines for Gadgets
  6.     Lang: english
  7. */
  8. #include "intuition_intern.h"
  9. #include "gadgets.h"
  10. #include <intuition/intuition.h>
  11. #include <intuition/cghooks.h>
  12. #include <proto/graphics.h>
  13.  
  14. #define EG(o) ((struct ExtGadget *)o)
  15.  
  16. /* Calculate the size of the Bounding Box of the gadget */
  17. void CalcBBox (struct Window * window, struct Gadget * gadget,
  18.     struct BBox * bbox)
  19. {
  20. #define ADDREL(flag,field)  ((gadget->Flags & (flag)) ? window->field : 0)
  21.  
  22.     bbox->Left     = ADDREL(GFLG_RELRIGHT,Width-1)   + gadget->LeftEdge;
  23.     bbox->Top     = ADDREL(GFLG_RELBOTTOM,Height-1) + gadget->TopEdge;
  24.     bbox->Width  = ADDREL(GFLG_RELWIDTH,Width)     + gadget->Width;
  25.     bbox->Height = ADDREL(GFLG_RELHEIGHT,Height)   + gadget->Height;
  26. } /* CalcBBox */
  27.  
  28. /* Figure out the size of the gadget rectangle, taking relative
  29.  * positioning into account.
  30.  */
  31. VOID GetGadgetIBox(Object *o, struct GadgetInfo *gi, struct IBox *ibox)
  32. {
  33.     ibox->Left     = EG(o)->LeftEdge;
  34.     ibox->Top     = EG(o)->TopEdge;
  35.     ibox->Width  = EG(o)->Width;
  36.     ibox->Height = EG(o)->Height;
  37.  
  38.     if (gi)
  39.     {
  40.     if (EG(o)->Flags & GFLG_RELRIGHT)
  41.         ibox->Left     += gi->gi_Domain.Width - 1;
  42.  
  43.     if (EG(o)->Flags & GFLG_RELBOTTOM)
  44.         ibox->Top     += gi->gi_Domain.Height - 1;
  45.  
  46.     if (EG(o)->Flags & GFLG_RELWIDTH)
  47.         ibox->Width  += gi->gi_Domain.Width;
  48.  
  49.     if (EG(o)->Flags & GFLG_RELHEIGHT)
  50.         ibox->Height += gi->gi_Domain.Height;
  51.     }
  52. }
  53.  
  54. ULONG LabelWidth (struct RastPort * rp, STRPTR label, ULONG len,
  55.         struct IntuitionBase * IntuitionBase)
  56. {
  57.     ULONG totalwidth, uscorewidth;
  58.  
  59.     totalwidth    = TextLength (rp, label, len);
  60.     uscorewidth = TextLength (rp, "_", 1);
  61.  
  62.     while (len && *label)
  63.     {
  64.     if (*label == '_')
  65.         totalwidth -= uscorewidth;
  66.  
  67.     label ++;
  68.     len --;
  69.     }
  70.  
  71.     return totalwidth;
  72. }
  73.  
  74. void RenderLabel (struct RastPort * rp, STRPTR label, ULONG len,
  75.         struct IntuitionBase * IntuitionBase)
  76. {
  77.     ULONG renderlen;
  78.     ULONG uscorewidth;
  79.  
  80.     while (*label)
  81.     {
  82.     renderlen = 0;
  83.  
  84.     while (label[renderlen] && label[renderlen] != '_')
  85.         renderlen ++;
  86.  
  87.     Text (rp, label, renderlen);
  88.  
  89.     label += renderlen;
  90.  
  91.     if (*label) /* '_' ? */
  92.     {
  93.         WORD cx, cy;
  94.  
  95.         label ++; /* Skip */
  96.  
  97.         uscorewidth = TextLength (rp, label, 1);
  98.  
  99.         cx = rp->cp_x;
  100.         cy = rp->cp_y;
  101.  
  102.         Move (rp, cx, cy+2);
  103.         Draw (rp, cx+uscorewidth-1, cy+2);
  104.         Move (rp, cx, cy);
  105.     }
  106.     }
  107. }
  108.  
  109.