Here's where the "meat" of it is.  Damn..., wordwrap may have killed
some of the last patch.  Okay, I'm going to re-send it to Micah
personally, anyone else that wants a copy send me an email.
(This ones got the cool stuff in it anyway :)

Thanks,
Shane Nay.


Index: pgserver/gcore/render.c
===================================================================
RCS file: /cvsroot/pgui/pgserver/gcore/render.c,v
retrieving revision 1.5
diff -u -r1.5 render.c
--- pgserver/gcore/render.c     2001/05/31 07:15:14     1.5
+++ pgserver/gcore/render.c     2001/06/06 18:44:23
@@ -510,6 +510,7 @@
 
 void gropnode_draw(struct groprender *r, struct gropnode *n) {
    char *str;
+   short *arr;
    hwrbitmap bit;
    s16 bw,bh;
    hwrcolor c;
@@ -699,6 +700,15 @@
             r->lgop 
             ); 
      break; 
+   case PG_GROP_FPOLYGON:
+     if (iserror(rdhandle((void**)&arr,PG_TYPE_ARRAY,-1,
+                         n->param[0])) || !arr) break;
+     VID(fpolygon) (r->output,
+                   arr,
+                   c,
+                   r->lgop
+                   );
+           
     }
 }
 
Index: pgserver/include/pgserver/video.h
===================================================================
RCS file: /cvsroot/pgui/pgserver/include/pgserver/video.h,v
retrieving revision 1.41
diff -u -r1.41 video.h
--- pgserver/include/pgserver/video.h   2001/05/31 07:15:15     1.41
+++ pgserver/include/pgserver/video.h   2001/06/06 18:44:23
@@ -302,6 +302,7 @@
  
   void (*ellipse) (hwrbitmap dest, s16 x, s16 y, s16 w, s16 h, hwrcolor c, s16 lgop); 
   void (*fellipse) (hwrbitmap dest, s16 x, s16 y, s16 w, s16 h, hwrcolor c, s16 
lgop); 
+  void (*fpolygon) (hwrbitmap dest, s16* array, hwrcolor c, s16 lgop);
    
   /***************** Bitmaps */
 
Index: pgserver/include/picogui/constants.h
===================================================================
RCS file: /cvsroot/pgui/pgserver/include/picogui/constants.h,v
retrieving revision 1.56
diff -u -r1.56 constants.h
--- pgserver/include/picogui/constants.h        2001/05/31 07:15:15     1.56
+++ pgserver/include/picogui/constants.h        2001/06/06 18:44:24
@@ -222,6 +222,7 @@
 #define PG_TYPE_STRING     4    //!< Created by pgNewString()
 #define PG_TYPE_THEME      5    //!< Created by pgLoadTheme()
 #define PG_TYPE_FILLSTYLE  6    //!< Used internally to store a theme's fillstyles
+#define PG_TYPE_ARRAY      7    //!< Created by pgNewArray()
 
 //! \}
 
@@ -536,6 +537,7 @@
 #define PG_GROP_LINE              0x50
 #define PG_GROP_ELLIPSE    0x60 
 #define PG_GROP_FELLIPSE   0x70 
+#define PG_GROP_FPOLYGON   0x90
 #define PG_GROP_TEXT       0x04   //!< Param: string 
 #define PG_GROP_BITMAP     0x14   //!< Param: bitmap 
 #define PG_GROP_TILEBITMAP 0x24   //!< Param: bitmap 
Index: pgserver/include/picogui/network.h
===================================================================
RCS file: /cvsroot/pgui/pgserver/include/picogui/network.h,v
retrieving revision 1.25
diff -u -r1.25 network.h
--- pgserver/include/picogui/network.h  2001/05/17 04:50:29     1.25
+++ pgserver/include/picogui/network.h  2001/06/06 18:44:24
@@ -127,8 +127,9 @@
 #define PGREQ_MKMENU       30  /* Creates a simple popup menu    |  handle[] */
 #define PGREQ_WRITETO      31  /* Stream data to a widget        |  handle + data */
 #define PGREQ_UPDATEPART   32  /* Updates subtree defined by wgt |  handle */
+#define PGREQ_MKARRAY      33  /* Send an array of shorts */
 
-#define PGREQ_UNDEF        33     /* types > this will be truncated. return error */
+#define PGREQ_UNDEF        34     /* types > this will be truncated. return error */
 
 /******* Request data structures */
 
Index: pgserver/net/dispatch.c
===================================================================
RCS file: /cvsroot/pgui/pgserver/net/dispatch.c,v
retrieving revision 1.37
diff -u -r1.37 dispatch.c
--- pgserver/net/dispatch.c     2001/04/29 17:28:39     1.37
+++ pgserver/net/dispatch.c     2001/06/06 18:44:24
@@ -215,6 +215,22 @@
   return sucess;
 }
 
+g_error rqh_mkarray(int owner, struct pgrequest *req,
+                    void *data, unsigned long *ret, int *fatal) {
+  short *buf;
+  handle h;
+  g_error e;
+  e = g_malloc((void **) &buf, req->size);
+  errorcheck;
+  memcpy(buf,data,req->size);
+
+  e = mkhandle(&h,PG_TYPE_ARRAY,owner,buf);
+  errorcheck;
+
+  *ret = h;
+  return sucess;
+}
+
 g_error rqh_free(int owner, struct pgrequest *req,
                   void *data, unsigned long *ret, int *fatal) {
   reqarg(handlestruct);  
Index: pgserver/net/requests.inc
===================================================================
RCS file: /cvsroot/pgui/pgserver/net/requests.inc,v
retrieving revision 1.4
diff -u -r1.4 requests.inc
--- pgserver/net/requests.inc   2001/03/30 09:57:58     1.4
+++ pgserver/net/requests.inc   2001/06/06 18:44:24
@@ -1,5 +1,7 @@
 /* This is the actual table of request handlers, included in some
- * macro junk by dispatch.c */
+ * macro junk by dispatch.c.  Must be in order as stipulated by
+ * by PGREQ in network.h.
+ */
 
 RQH(ping)
 RQH(update)
@@ -34,6 +36,7 @@
 RQH(mkmenu)
 RQH(writeto)
 RQH(updatepart)
+RQH(mkarray)
 RQH(undef)
 
 /* The End */
Index: pgserver/vidbase/defaultvbl.c
===================================================================
RCS file: /cvsroot/pgui/pgserver/vidbase/defaultvbl.c,v
retrieving revision 1.41
diff -u -r1.41 defaultvbl.c
--- pgserver/vidbase/defaultvbl.c       2001/05/31 07:17:06     1.41
+++ pgserver/vidbase/defaultvbl.c       2001/06/06 18:44:25
@@ -495,7 +495,231 @@
     SYMLINE(x,y); 
   } 
 } 
-#undef SYMLINE 
+#undef SYMLINE
+
+struct poly_line_info {
+  s16 x0,y0,x1,y1;  /* From to */
+  s16 fraction; /* Derivative position */
+  s16 dx,dy; /* Derivitive respect to.. */
+  s16 stepx; /* Stepping, sy always==1 */
+};
+
+#define NEXT(X) ((X+1>=array[0])?0:X+1)
+#define PREV(X) ((X-1<0)?array[0]-1:X-1)
+
+#define XAT(INDEX) (array[(INDEX<<1)+1])
+#define YAT(INDEX) (array[(INDEX<<1)+2])
+
+#define HLINE(A,B) ((YAT(A)==YAT(B))?1:0)
+
+#define X0() (mptr->x0)
+#define Y0() (mptr->y0) 
+#define X1() (mptr->x1)
+#define Y1() (mptr->y1)
+#define FR() (mptr->fraction)
+#define DX() (mptr->dx)
+#define DY() (mptr->dy)  
+#define SX() (mptr->stepx)
+
+
+int polygon_simple_compare ( struct poly_line_info* a, struct poly_line_info* b )
+{
+    return b->y1 - a->y1;
+}
+
+void def_fpolygon (hwrbitmap dest, s16* array, hwrcolor c, s16 lgop) {
+  /* Idea:
+   * We run a series of scanlines traversing in the y direction,
+   * calculating Bresenhams along the way for each polyline.
+   * We only calculate the bresenhams for "presently active" polylines
+   * and they act as "on/off" markers for horizontal lines
+   * that will form the polygon.
+   *
+   * The first step is to create the polylines.  There is
+   * a potential for N polylines where N is the number of vertices
+   * in the polygon.  However, horizontal lines are ignored and subtracted
+   * from the total number of polylines.
+   *
+   * Future optimizations:
+   * 1) Move the horizontal/vertical logic into some goto label
+   *    sort of thing to optimize code size.  (This *should* be
+   *    done by the compiler, but I haven't checked the assembly
+   *    output) Revision, I looked at the assembly output, and it
+   *    isn't centralizing it.
+   *    Down to 2.45k from 6k on Intel
+   *
+   */
+  s16 nplines=array[0]; // First set nplines to max number
+  s16 i,j,k,n,t,hi,lo,m;
+  hi=YAT(0);
+  lo=YAT(0);
+  for(i=1;i<array[0];i++) {
+    j=YAT(i);
+    if(j>hi)
+      hi=j;
+    else if(j<lo)
+      lo=j;
+    if(HLINE(i,NEXT(i))==1)
+      nplines--;
+  }
+
+  /* Now we know how many polylines we will need */
+  {
+    struct poly_line_info mpoly[nplines]; /* Each of these has 16bytes worth of data 
+*/
+    struct poly_line_info* mptr=mpoly;
+    s16 vert[nplines];
+    /* First stick info in the poly_lines in order */
+    j=0;
+    for(i=0;i<array[0];i++) {
+      k=NEXT(i);
+      if((HLINE(i,k))!=1) {
+       /* Do all the setup for the Bresenham for this line */
+       m=i;
+       if(YAT(k)<YAT(m)) {
+         m=k;
+         k=i;
+         n=NEXT(m);
+         t=PREV(k);
+       } else {
+         n=PREV(m);
+         t=NEXT(k);
+       }
+
+       X0()=XAT(m);
+       Y0()=YAT(m);
+       X1()=XAT(k);
+       Y1()=YAT(k);
+
+
+       k=DX()=X1()-X0();
+       DY()=Y1()-Y0(); /* Always positive */
+
+       if(DX()<0) {
+         DX()=-(DX()<<1);
+         SX()=-1;
+       } else {
+         DX()=DX()<<1;
+         SX()=1;
+       }
+       DY()=DY()<<1;
+
+       FR()=(DX()>DY())? DY()-(DX()>>1) : -(DY()>>1) ;
+       /* Remove horizontal odd parity x deltas for YO...
+          in this case, we remove our highest physically
+          point.  (Lowest numerical Y), We also need
+          to push the algorithm forward (FIXME)
+        */
+       if(YAT(t)>=Y1()) {
+         Y1()--;
+       }
+       if(HLINE(m,n)==1) {
+         n=XAT(n)-X0();
+         if((n | k)<0 && (n & k)>0) { /* DX Parity Calculation */
+           /* Increase Y max, effectively killing the top point. */
+           Y0()++;
+           if(DX()>DY()) { /* Horiz major axis */
+             while(1) {
+               if(FR()>=0) {
+                 FR()+=DY() - DX();
+                 X0()+=SX();
+                 break;
+               }
+               X0()+=SX();
+               FR()+=DY();
+             }
+           } else { /* Vert major axis */
+             if(FR() >= 0) { 
+               X0()+=SX();
+               FR() -= DY();
+             }
+             FR()+=DX();
+           }
+         }
+       }
+       mptr++; 
+      }
+    }
+    mptr=mpoly;
+    qsort(mpoly,nplines,sizeof(struct poly_line_info),&polygon_simple_compare);
+
+    m=0;
+    while(lo <= hi) {
+      t=0;
+      mptr=mpoly;
+      for(i=0; i<nplines ;i++,mptr++) {
+       /* Traverse the polylines */
+       /* First conditional here skips the present line if it isn't
+        * relevant yet, or has passed its relevancy
+        */
+       if(Y0()>lo) {
+         continue;
+       }
+       if(Y1()<lo) {
+         nplines--;
+         break;
+       }
+       /* Now we calculate some Bresenhams, and add some points. */
+       
+       if(DX()>DY()) { /* Horiz major axis */
+         n=X0();
+         while(1) {
+           if(FR()>=0) {
+             if(SX()>0)
+               n=X0();
+             Y0()++;
+             FR()+=DY() - DX();
+             X0()+=SX();
+             break;
+           }
+           X0()+=SX();
+           FR()+=DY();
+         }
+       } else { /* Vert major axis */
+         if(FR() >= 0) { 
+           X0()+=SX();
+           FR() -= DY();
+         }
+         Y0()++;
+         FR()+=DX();
+         n=X0();
+       }
+
+       for(j=0;j<t;j++){
+         if(vert[j]>=n) {
+           for(k=t;k>=j;k--)
+             vert[k+1]=vert[k];
+           break;
+         }
+       }
+       t++;
+       vert[j]=n;
+      }
+      t=t>>1;
+      for(j=0;j<t;j++) {
+       k=j<<1;
+       (*vid->slab) (dest,vert[k],lo,vert[k+1]-vert[k]+1,c,lgop);
+      }
+      
+      lo++;
+    }
+  }
+}
+
+#undef NEXT
+#undef PREV
+#undef XAT
+#undef YAT
+#undef HLINE
+#undef X0
+#undef Y0
+#undef X1
+#undef Y1
+#undef FR
+#undef DX
+#undef DY
+#undef SX
+
+
  
 void def_gradient(hwrbitmap dest,s16 x,s16 y,s16 w,s16 h,s16 angle,
                  pgcolor c1, pgcolor c2, s16 lgop) {
@@ -1384,6 +1608,7 @@
   vid->tileblit = &def_tileblit;
   vid->ellipse = &def_ellipse; 
   vid->fellipse = &def_fellipse; 
+  vid->fpolygon = &def_fpolygon;
 #ifdef CONFIG_FORMAT_XBM
   vid->bitmap_loadxbm = &def_bitmap_loadxbm;
 #endif

_______________________________________________
Pgui-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/pgui-devel

Reply via email to