⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _sunview.c

📁 数据类型和算法库LEDA 数据类型和算法库LEDA
💻 C
📖 第 1 页 / 共 3 页
字号:
                             FRAME_NO_CONFIRM, TRUE, 
                             WIN_X, 100, WIN_Y, 100, 0);

    panel = window_create(panel_frame, PANEL, 0);



  x_draw_set_font(x_draw_default_font);

  pix_mode_op = PIX_SRC;

  x_draw_init_colors(); 

  solid  = 0;
  dashed = (Pr_texture*) malloc(sizeof(Pr_texture));
  dashed->pattern = pr_tex_dashed;
  dotted = (Pr_texture*) malloc(sizeof(Pr_texture));
  dotted->pattern = pr_tex_dotted;

  x_draw_line_style   = 0;   /* solid */
  x_draw_node_width   = 12;
  x_draw_line_width   = 1;
  x_draw_text_mode    = 0;   /* transparent   */
  x_draw_drawing_mode = 0;   /* src           */

  x_draw_window_xpos = w_xpos;
  x_draw_window_ypos = w_ypos;
  x_draw_window_width = w_width;
  x_draw_window_height = w_height;


  mesg_count = 0;

}


x_draw_init(x0,x1,y0,g_mode)
double x0,x1,y0;
int g_mode;
{
  double x,y;

  if (x0>=x1) 
  { fprintf(stderr,"Illegal arguments in draw_init: x0 >= x1\n");
    exit(1);
   }

  x_draw_grid_mode = g_mode; 

  x_draw_reset_frame_label();

  xdots = (int)window_get(canvas, CANVAS_WIDTH);
  ydots = (int)window_get(canvas, CANVAS_HEIGHT);

  x_draw_depth = pw->pw_pixrect->pr_depth;

  x_draw_scale = ((double)xdots)/(x1-x0);

  /* at least grid distance of 2 pixels */
  if ((x_draw_grid_mode) && (x_draw_grid_mode*x_draw_scale < 2)) 
  { x_draw_grid_mode=0;  
    fprintf(stderr,"warning: grid distance to small.\n");
   }

  if (x_draw_grid_mode) 
    if (x_draw_scale < 1) x_draw_scale = 1;
    else x_draw_scale = (int)x_draw_scale;

  x_draw_xmin = x0;
  x_draw_ymin = y0;
  x_draw_xmax = x0+xdots/x_draw_scale;
  x_draw_ymax = y0+ydots/x_draw_scale;

  xorigin = -x0*x_draw_scale;
  yorigin = ydots+y0*x_draw_scale;

  mouse_xreal = 0;
  mouse_yreal = 0;

  x_draw_clear(0);

 if (x_draw_grid_mode)  x_draw_cursor();

 notify_dispatch();

 if (x_draw_grid_mode)  x_draw_cursor();

 (*x_draw_redraw)();

}


x_show_window() 
{ while (!x_draw_done) notify_dispatch(); }

x_draw_end()
{ if (pw)
  { pw_close(pw);
    pf_close(font);
    /* window_destroy(frame); */
    pw = 0;
   }
}

x_draw_line(x1, y1, x2, y2, col)
double x1,y1,x2,y2;
int col;
{ 
  int C[4];
  int i;
  int M = 32768;   /* 2^15    */ 

  Pr_brush br;
  br.width = x_draw_line_width;


  C[0] = XPIX(x1);
  C[1] = YPIX(y1);
  C[2] = XPIX(x2);
  C[3] = YPIX(y2);

  /* 
    Fehler beim Clipping fuer Koordinaten mit Absolutwert in
    [i*2^15..(i+1)*2^15-1],i ungerade.
  */

 /*
  for(i=0; i<4; i++)
    if ((C[i]/M) % 2) C[i] = -C[i];

 */

  pw_line(pw,C[0],C[1],C[2],C[3],&br,Line_style,pix_mode(col));

}


x_draw_point(x,y,col)
double x,y;
int col;

{ int X,Y;

  Pr_brush br;
  br.width = 1;

  X = XPIX(x);
  Y = YPIX(y);

  if (x_draw_depth==1 && col>1) col = 1;

  pw_line(pw,X-2,Y-2,X+2,Y+2,&br,solid,pix_mode(col));
  pw_line(pw,X+1,Y-1,X+2,Y-2,&br,solid,pix_mode(col));
  pw_line(pw,X-1,Y+1,X-2,Y+2,&br,solid,pix_mode(col));


}


x_draw_node(x0,y0,col)
double x0,y0;
int col;

{ int X0,Y0,x,y,e;

  int r = x_draw_node_width;

  struct pr_pos *points;
  int n = 8*r;
  int i = 0;

  points = (struct pr_pos*) malloc(n*sizeof(struct pr_pos));


  X0 = XPIX(x0);
  Y0 = YPIX(y0);

  if (x_draw_depth==1 && col>1) col = 1;

    x = 0;
    y = r;
    e = 3-2*y;

   points[i].x = X0;   points[i].y = Y0+r;
   i++;
   points[i].x = X0;   points[i].y = Y0-r;
   i++;
   points[i].x = X0+r; points[i].y = Y0;
   i++;
   points[i].x = X0-r; points[i].y = Y0;
   i++;
  
    for (x=1;x<y;)
    { points[i].x = X0+x; points[i].y = Y0+y;
      i++;
      points[i].x = X0+x; points[i].y = Y0-y;
      i++;
      points[i].x = X0-x; points[i].y = Y0+y;
      i++;
      points[i].x = X0-x; points[i].y = Y0-y;
      i++;
      points[i].x = X0+y; points[i].y = Y0+x;
      i++;
      points[i].x = X0+y; points[i].y = Y0-x;
      i++;
      points[i].x = X0-y; points[i].y = Y0+x;
      i++;
      points[i].x = X0-y; points[i].y = Y0-x;
      i++;

      x++;
      if (e>=0) { y--; e = e - 4*y; }
      e = e + 4*x + 2;
     }


   points[i].x = X0+x; points[i].y = Y0+y;
   i++;
   points[i].x = X0+x; points[i].y = Y0-y;
   i++;
   points[i].x = X0-x; points[i].y = Y0+y;
   i++;
   points[i].x = X0-x; points[i].y = Y0-y;
   i++;

   pw_polypoint(pw,0,0,i,points,pix_mode(col));

   free((char*)points);

}

x_draw_message(s)
char* s;
{ int y;
  mesg_list[mesg_count] = (char*)malloc(strlen(s)+1);
  strcpy(mesg_list[mesg_count],s);
  mesg_count++;
  y = 30*mesg_count+15;
  x_draw_set_font("cour.b.24");
  pw_ttext(pw,30,y,XCOL(1),font,s);
  x_draw_set_font(x_draw_default_font);
}


x_draw_del_messages()
{ int y;
  char* s;
  x_draw_set_font("cour.b.24");
  while(mesg_count > 0)
  { s = mesg_list[mesg_count-1];
    y = 30*mesg_count+15;
    pw_ttext(pw,30,y,XCOL(1),font,s);
    mesg_count--;
    free(s);
   }
  x_draw_set_font(x_draw_default_font);
}


x_draw_text_node(x0,y0,s,col)
double x0,y0;
int col;
char* s;
{ 
  if (x_draw_depth==1 || col == 1)
   { x_draw_node(x0,y0,1);
     x_draw_ctext(x0,y0,s,1);
    }
  else
   { x_draw_filled_node(x0,y0,col);
     x_draw_ctext(x0,y0,s,0);
    }

 }

x_draw_int_node(x0,y0,i,col)
double x0,y0;
int i,col;
{ 
  char buf[16];
  sprintf(buf,"%d",i);
  x_draw_text_node(x0,y0,buf,col);
 }


x_draw_filled_node(x0,y0,col)
double x0,y0;
int col;
{ 
  int X0,Y0,x,y,e;
  int r = x_draw_node_width;

  Pr_brush br;
  br.width = 1;

  X0 = XPIX(x0);
  Y0 = YPIX(y0);

  x = 1;
  y = r;
  e = 3-2*r;

  pw_line(pw,X0,Y0+y,X0,Y0-y,&br,0,pix_mode(col));

  while (x<=y)
  { pw_line(pw,X0+x,Y0+y,X0+x,Y0,  &br,0,pix_mode(col));
    pw_line(pw,X0+x,Y0-y,X0+x,Y0-1,&br,0,pix_mode(col));
    pw_line(pw,X0-x,Y0+y,X0-x,Y0,  &br,0,pix_mode(col));
    pw_line(pw,X0-x,Y0-y,X0-x,Y0-1,&br,0,pix_mode(col));


    if (x<y && e>=0) 
    { pw_line(pw,X0+y,Y0+x,X0+y,Y0,  &br,0,pix_mode(col));
      pw_line(pw,X0+y,Y0-x,X0+y,Y0-1,&br,0,pix_mode(col));
      pw_line(pw,X0-y,Y0+x,X0-y,Y0,  &br,0,pix_mode(col));
      pw_line(pw,X0-y,Y0-x,X0-y,Y0-1,&br,0,pix_mode(col));
      y--; 
      e = e - 4*y; 
     }

    x++;

    e = e + 4*x + 2;
   }

}


typedef struct{ int x,y,d; } queue_el;

static  queue_el P_QUEUE[2048];

#define FILLPUT(x1,y1,d1)\
{if (pw_get(pw,x1,y1) != col)\
  { pw_put(pw,x1,y1,col);\
    top->x = x1;\
    top->y = y1;\
    top->d = d1;\
    top++;\
    if (top==stop) top=P_QUEUE; }\
}

static void bfs_fill(x,y,col)
int x,y,col;
{ register queue_el* bot  = P_QUEUE;
  register queue_el* top  = P_QUEUE;
  register queue_el* stop = P_QUEUE+2048;

  FILLPUT(x,y,0)

  while (top != bot)
  { if (bot->d != 1) FILLPUT(bot->x-1,bot->y,3)
    if (bot->d != 3) FILLPUT(bot->x+1,bot->y,1)
    if (bot->d != 2) FILLPUT(bot->x,bot->y-1,4)
    if (bot->d != 4) FILLPUT(bot->x,bot->y+1,2)
    bot++;
    if (bot==stop) bot=P_QUEUE;
  }
}




x_draw_fill(x,y,col)
double x,y;
int col;
{ Rect *r = (Rect *) window_get(canvas, WIN_SCREEN_RECT);
  pw_lock(pw,r);
  bfs_fill(XPIX(x),YPIX(y),col); 
  pw_unlock(pw);
}
  

x_draw_arc()
{ fprintf(stderr,"sorry, draw arc not implemented\n"); }

x_draw_filled_arc()
{ fprintf(stderr,"sorry, draw arc not implemented\n"); }

x_draw_ellipse()
{ fprintf(stderr,"sorry, draw ellipse not implemented\n"); }

x_draw_filled_ellipse()
{ fprintf(stderr,"sorry, draw ellipse not implemented\n"); }

x_draw_circle(x0,y0,r,col)
double x0,y0,r; 
int col;

{ int save = x_draw_node_width;
  x_draw_node_width = (int)(r*x_draw_scale);
  x_draw_node(x0,y0,col);
  x_draw_node_width = save;
 }


x_draw_filled_circle(x0,y0,r,col)
double x0,y0,r; 
int col;
{ int save = x_draw_node_width;
  x_draw_node_width = (int)(r*x_draw_scale);
  x_draw_filled_node(x0,y0,col);
  x_draw_node_width = save;
 }


x_draw_xpix(x)
double x;
{ return XPIX(x); }

x_draw_ypix(x)
double x;
{ return YPIX(x); }

x_draw_pix(x,y,col)
double x,y;
int col;
{ pw_put(pw,XPIX(x),YPIX(y),col); }


x_draw_plot_xy(x0,x1,f,col)
double x0,x1;
double (*f)();
int col;
{ 

  int x = XPIX(x0);
  int y_old = YPIX((*f)(x0));
  int i,y_new;
  int size = 0;
  int n = 0;

  struct pr_pos *points;

  for(x = XPIX(x0)+1; x <= XPIX(x1); x++)
  { y_new = YPIX((*f)(XREAL(x)));
    if (y_new > y_old)
       size += (y_new-y_old+1);
    else
       size += (y_old-y_new+1);
    y_old = y_new;
   }

  points = (struct pr_pos*) malloc(size*sizeof(struct pr_pos));

  y_old = YPIX((*f)(x0));

  for(x = XPIX(x0)+1; x <= XPIX(x1); x++)
  { y_new = YPIX((*f)(XREAL(x)));
    if (y_new > y_old)
      for(i=y_old; i<=y_new; i++)  
      { points[n].x = x; 
        points[n].y = i;
        n++;
       }
    else
      for(i=y_old; i>=y_new; i--)  
      { points[n].x = x; 
        points[n].y = i;
        n++;
       }
    y_old = y_new;
  }

 pw_polypoint(pw,0,0,size,points,pix_mode(col));

 free((char*)points);
  
}

x_draw_plot_yx(y0,y1,f,col)
double y0,y1;
double (*f)();
int col;
{ 

  int y;
  int i,x_new;
  int x_old = XPIX((*f)(y0));
  int size = 0;
  int n = 0;

  struct pr_pos *points;

  for(y = YPIX(y0)-1; y >= YPIX(y1); y--)
  { x_new = XPIX((*f)(YREAL(y)));
    if (x_new > x_old)
       size += (x_new-x_old+1);
    else
       size += (x_old-x_new+1);
    x_old = x_new;
   }

  points = (struct pr_pos*) malloc(size*sizeof(struct pr_pos));

  x_old = XPIX((*f)(y0));

  for(y = YPIX(y0)-1; y >= YPIX(y1); y--)
  { 
    x_new = XPIX((*f)(YREAL(y)));
    if (x_new > x_old)
      for(i=x_old; i<=x_new; i++)  
      { points[n].x = i; 
        points[n].y = y;
        n++;
       }
    else
      for(i=x_old; i>=x_new; i--)  
      { points[n].x = i; 
        points[n].y = y;
        n++;
       }
    x_old = x_new;
  }

 pw_polypoint(pw,0,0,size,points,pix_mode(col));

 free((char*)points);
  
}


x_draw_filled_polygon(n,xcoord,ycoord,col)
int col, n;
double *xcoord, *ycoord;
{struct pr_pos *edges;
 int i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -