home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 4 / CD_Magazyn_EXEC_nr_4.iso / Recent / dev / c / apputil.lha / apputil / gadgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-04  |  1.6 KB  |  75 lines

  1. /*
  2.  * gadgets.c
  3.  * =========
  4.  * Gadget utility functions.
  5.  *
  6.  * Copyright (C) 1999-2000 HÃ¥kan L. Younes (lorens@hem.passagen.se)
  7.  */
  8.  
  9. #include <intuition/gadgetclass.h>
  10.  
  11. #include <clib/alib_protos.h>
  12. #include <proto/graphics.h>
  13.  
  14. #include "apputil.h"
  15.  
  16.  
  17. static VOID EraseGadget(struct RastPort *rp, struct Gadget *gad) {
  18.   if (gad->Width > 0 && gad->Height > 0) {
  19.     EraseRect(rp, (LONG)gad->LeftEdge, (LONG)gad->TopEdge,
  20.           (LONG)gad->LeftEdge + gad->Width - 1,
  21.           (LONG)gad->TopEdge + gad->Height - 1);
  22.   }
  23. }
  24.  
  25.  
  26. VOID EraseGadgets(struct Gadget *gads, struct Window *win,
  27.           struct Requester *req) {
  28.   struct RastPort *rp;
  29.   struct Gadget *gad;
  30.  
  31.   if (win != NULL) {
  32.     rp = win->RPort;
  33.   } else {
  34.     rp = req->RWindow->RPort;
  35.   }
  36.   for (gad = gads; gad != NULL; gad = gad->NextGadget) {
  37.     EraseGadget(rp, gad);
  38.   }
  39. }
  40.  
  41.  
  42. VOID EraseGList(struct Gadget *gads, struct Window *win,
  43.         struct Requester *req, LONG numGads) {
  44.   if (numGads == -1) {
  45.     EraseGadgets(gads, win, req);
  46.   } else {
  47.     struct RastPort *rp;
  48.     struct Gadget *gad;
  49.     LONG i;
  50.  
  51.     if (win != NULL) {
  52.       rp = win->RPort;
  53.     } else {
  54.       rp = req->RWindow->RPort;
  55.     }
  56.     for (gad = gads, i = 0; gad != NULL && i < numGads;
  57.      gad = gad->NextGadget, i++) {
  58.       EraseGadget(rp, gad);
  59.     }
  60.   }
  61. }
  62.  
  63.  
  64. BOOL PointInGadget(ULONG point, struct Gadget *gad) {
  65.   WORD x = (point >> 16L) - gad->LeftEdge;
  66.   WORD y = (point & 0xFFFF) - gad->TopEdge;
  67.  
  68.   if (gad->GadgetType & GTYP_CUSTOMGADGET) {
  69.     return (BOOL)(GMR_GADGETHIT ==
  70.           DoMethod((Object *)gad, GM_HITTEST, NULL, (x << 16L) + y));
  71.   } else {
  72.     return (BOOL)(x >= 0 && y >= 0 && x < gad->Width && y < gad->Height);
  73.   }
  74. }
  75.