home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Programming / MR_Classes / Dev / Source / tcpalette / Layout.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-07-11  |  2.1 KB  |  101 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4. #include "private.h"
  5. #include "protos.h"
  6.  
  7. // GM_LAYOUT
  8. ULONG __saveds gad_Layout(Class *C, struct Gadget *Gad, struct gpLayout *layout)
  9. {
  10.   struct GadData *gdata;
  11.   LONG rows,cols,l,topedge,leftedge,width,height;
  12.   BOOL swap=0;
  13.   
  14.   
  15.   float cfloat,aspect;
  16.  
  17.   gdata=INST_DATA(C, Gad);
  18.  
  19. //  DKP("GM_LAYOUT\n");
  20. // GadgetInfo
  21.   SetAttrs(gdata->Bevel, IA_Left,       Gad->LeftEdge,
  22.                          IA_Top,        Gad->TopEdge,
  23.                          IA_Width,      Gad->Width,
  24.                          IA_Height,     Gad->Height,
  25.                          BEVEL_ColorMap,layout->gpl_GInfo->gi_Screen->ViewPort.ColorMap,
  26.                          TAG_DONE);
  27.  
  28.   GetAttr(BEVEL_InnerTop,     gdata->Bevel, &topedge);
  29.   GetAttr(BEVEL_InnerLeft,    gdata->Bevel, &leftedge);
  30.   GetAttr(BEVEL_InnerWidth,   gdata->Bevel, &width);
  31.   GetAttr(BEVEL_InnerHeight,  gdata->Bevel, &height);
  32.  
  33.   if(width>0 && height>0)
  34.   {
  35.     aspect=((float)height / (float)width);
  36.     
  37.     if(aspect<1)
  38.     { 
  39.       aspect=((float)width / (float)height);
  40.       swap=1;
  41.     }
  42.     
  43. //    DKP("  aspect %ld\n",(ULONG)(aspect*1000));
  44.     
  45.     rows=sqrt(gdata->Pens * aspect) + .5;
  46.  
  47.     if(rows<1) rows=1;
  48.     if(rows>gdata->Pens) rows=gdata->Pens;
  49.     
  50. //    DKP("  rows=%ld\n",rows);
  51.     
  52.     cfloat=gdata->Pens / rows;
  53.     cols=cfloat;
  54.     
  55.     while(rows>1 && (cfloat * rows)!=gdata->Pens)
  56.     {
  57.       rows--;
  58.       cfloat=gdata->Pens / rows;
  59.       cols=cfloat;
  60. //      DKP("   testing - rows %ld cfloat %lf cols=%ld\n",rows, cfloat, cols);
  61.     }
  62.  
  63. //    DKP("  cols=%ld\n",cols);
  64.   
  65.     if(swap)
  66.     {
  67.       gdata->Rows = cols;
  68.       gdata->Cols = rows;
  69.       
  70.       rows=gdata->Rows;
  71.       cols=gdata->Cols;      
  72.     }    
  73.     else
  74.     {
  75.       gdata->Rows = rows;
  76.       gdata->Cols = cols;
  77.     }
  78.  
  79.     for(l=0;l<=rows;l++)
  80.     {
  81.       gdata->Row[l]=(LONG)height * l / (rows) + topedge;
  82.     }
  83.  
  84.     for(l=0;l<=cols;l++)
  85.     {
  86.       gdata->Col[l]=(LONG)width * l / (cols)  + leftedge;
  87.     }
  88.   }
  89.   else
  90.   {
  91.     gdata->Rows=gdata->Cols=0;
  92.   }
  93.   
  94.   if(layout->gpl_Initial)
  95.   {
  96.     i_Notify(C,Gad,layout,0);
  97.   }
  98.   
  99.   return(1);
  100. }
  101.