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

📄 iconedit_canvas.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
      rect_construct(&r, x0, y0, x0-x1+1, y0-y1+1);   }   */   /*   pw_lock(iced_canvas_pw, &r);   */   (void)pw_vector(iced_canvas_pw, x0, y0, x0, y1, PIX_SRC^PIX_DST, 1);   (void)pw_vector(iced_canvas_pw, x0, y0, x1, y0, PIX_SRC^PIX_DST, 1);   (void)pw_vector(iced_canvas_pw, x0, y1, x1, y1, PIX_SRC^PIX_DST, 1);   (void)pw_vector(iced_canvas_pw, x1, y0, x1, y1, PIX_SRC^PIX_DST, 1);   /*   pw_unlock(iced_canvas_pw);   */}static voidbox_feedback(event) Event  *event; {	CELL_POS     new_cell;	if (LOOKING_FOR_FIRST)  {		(void)get_first_cell(event);		return;	}	if (!cell_of_event(event, &new_cell) )		return;	box_xor(paired_points);	paired_points[1] = midpoint_of_cell(&new_cell);	box_xor(paired_points);}static voidbox_accept() {   CELL_POS  corner[2];   box_xor(paired_points);   paint_cell(pinned.x, pinned.y, pr_get(iced_canvas_pr, pinned.x, pinned.y));   if (pinned.x > cur_x) {	  corner[0].x = cur_x;	  corner[1].x = pinned.x;   } else {	  corner[0].x = pinned.x;	  corner[1].x = cur_x;   }   if (pinned.y > cur_y) {	  corner[0].y = cur_y;	  corner[1].y = pinned.y;   } else {	  corner[0].y = pinned.y;	  corner[1].y = cur_y;   }   (void)backup();   if ((int)(panel_get_value(iced_fill_square_item)) == NONE ) {      box_border(corner);   } else {      box_solid(corner);   }   iced_dirty_ul_cell.x = corner[0].x;   iced_dirty_ul_cell.y = corner[0].y;   iced_dirty_dr_cell.x = corner[1].x;   iced_dirty_dr_cell.y = corner[1].y;}static voidbox_cancel(){   box_xor(paired_points);   paired_points[0].x = -1;   paint_cell(pinned.x, pinned.y, pr_get(iced_canvas_pr, pinned.x, pinned.y));}/**************************************************************************//* text stuff                                                             *//**************************************************************************/static voidtext_feedback(event)Event *event;{   u_int            op;   if (event_action(event) == LOC_STILL) {      op = ops[cur_op][(u_int)panel_get_value(iced_fill_op_item)];      (void)pr_rop(&iced_temp_pr,0,0,64,64,PIX_SRC,&iced_icon_pr,0,0);      write_str_to_pr(&iced_temp_pr, abc_cell_origin.x, abc_cell_origin.y,		      abc_string,iced_abc_font,op);      if (iced_state == ICONIC) {	 (void)pw_replrop(proof_pixwin, ICON_LEFT_OFFSET, ICON_TOP_OFFSET,		    64, 64, PIX_SRC, iced_proof_pr, 0, 0);	 (void)pw_write(proof_pixwin, ICON_LEFT_OFFSET, ICON_TOP_OFFSET, 		  64, 64, iced_new_cursor.cur_function, &iced_temp_pr, 0, 0);      } else {	 (void)pw_write(proof_pixwin, CURSOR_LEFT_OFFSET, CURSOR_TOP_OFFSET, 		  16, 16, PIX_SRC, iced_proof_pr, 0, 0);	 (void)pw_write(proof_pixwin, CURSOR_LEFT_OFFSET, CURSOR_TOP_OFFSET, 		  16, 16, iced_new_cursor.cur_function, &iced_temp_pr, 0, 0);	 (void)window_set(iced_proof, WIN_CURSOR, &iced_new_cursor, 0);      }      return;   }   if (LOOKING_FOR_FIRST)  {      int	action = event_action(event);      if (win_inputposevent(event) && 	  (action == MS_LEFT   || 	   action == MS_MIDDLE || 	   action == LOC_DRAG	  ) && 	  cell_of_event(event, &abc_cell_origin)	 )        {	 if (!strlen(abc_string))	    iced_panelmsg("No string to insert;","please enter desired text.");	 compute_abc_feedback();         box_xor(paired_points);      }   } else if (cell_of_event(event, &abc_cell_origin)) {      box_xor(paired_points);      compute_abc_feedback();      box_xor(paired_points);   }}staticcompute_abc_feedback() {   abc_get_info();   if (iced_abc_font == iced_screenr7  ||       iced_abc_font == iced_screenr11 ||       iced_abc_font == iced_gallantr19      )      abc_cell_origin.y++;   abc_h_cell_origin.x   = abc_cell_origin.x;   abc_h_cell_origin.y   = abc_cell_origin.y + abc_home;   abc_feedback_origin.x = abc_h_cell_origin.x;   abc_feedback_origin.y = abc_h_cell_origin.y < CANVAS_MARGIN ?      0 : abc_h_cell_origin.y;   paired_points[0]   = midpoint_of_cell(&abc_h_cell_origin);   paired_points[1].x = paired_points[0].x + ((abc_size.x-1)*cell_size);   paired_points[1].y = paired_points[0].y + ((abc_size.y-1)*cell_size);}staticabc_get_info() {   abc_string = (char *)panel_get(iced_abc_item,PANEL_VALUE);   abc_len    = strlen(abc_string);   abc_size   = pf_textwidth(abc_len,iced_abc_font,abc_string);}static voidtext_accept(){   struct pr_pos extent;   u_int         op;   box_xor(paired_points);   op       = ops[cur_op][(u_int)panel_get_value(iced_fill_op_item)];   (void)backup();   write_str_to_pr(iced_canvas_pr,abc_cell_origin.x,abc_cell_origin.y,		   abc_string,iced_abc_font,op);   extent.x = abc_h_cell_origin.x + abc_size.x;   extent.y = abc_h_cell_origin.y + abc_size.y;   if (extent.x > iced_cell_count-1)      extent.x = iced_cell_count-1;   if (extent.y >= iced_cell_count-1)      extent.y = iced_cell_count-1;   paint_subcanvas(abc_feedback_origin.x, abc_feedback_origin.y,		   extent.x, extent.y);   iced_dirty_ul_cell.x = abc_feedback_origin.x;   iced_dirty_ul_cell.y = abc_feedback_origin.y;   iced_dirty_dr_cell.x = extent.x;   iced_dirty_dr_cell.y = extent.y;}static write_str_to_pr(pr,left_offset,vertical_offset,string,font,op)struct pixrect *pr;int             left_offset;int             vertical_offset;char           *string;struct pixfont *font;u_int           op;{   struct pr_prpos loc;	   loc.pr    = pr;   loc.pos.x = left_offset;   loc.pos.y = vertical_offset;    (void)pf_text(loc,(int)op,font,string);}static voidtext_cancel(){   box_xor(paired_points);   paired_points[0].x = -1;}/**************************************************************************//* circle stuff                                                           *//**************************************************************************/static intcircle_radius(cell0, cell1)CELL_POS *cell0, *cell1;{   register int	dx, dy;   dx = cell1->x - cell0->x;   dy = cell1->y - cell0->y;   return (int) (sqrt ( (double) (dx*dx + dy*dy) ) + 0.5 );}static voidcircle_xor(points)SCREEN_POS points[];{   line_xor(points);}static voidcircle_feedback(event)Event  *event;{   CELL_POS	new_cell;   if (LOOKING_FOR_FIRST)  {      (void)get_first_cell(event);      return;   }   if (cell_of_event(event, &new_cell) )  {      circle_xor(paired_points);      paired_points[1] = midpoint_of_cell(&new_cell);      circle_xor(paired_points);   }}static voidcircle_cancel(){   circle_xor(paired_points);   paired_points[0].x = -1;   paint_cell(pinned.x, pinned.y, pr_get(iced_canvas_pr, pinned.x, pinned.y));}static void circle_edge(x0, x1, y)register int	x0, x1, y;{   if ( y >= 0 && y < iced_cell_count ) {      if (x0 >= 0) {	 (void)pr_put(iced_canvas_pr, x0, y, cur_op);	 paint_cell(x0, y, cur_op);      }      if (x1 < iced_cell_count ) {	 (void)pr_put(iced_canvas_pr, x1, y, cur_op);	 paint_cell(x1, y, cur_op);      }   }}static voidcircle_edge_pair(x,y)register int	x, y;{   register int	mid_x = pinned.x, mid_y = pinned.y;   circle_edge(mid_x - x, mid_x + x, mid_y - y);   circle_edge(mid_x - y, mid_x + y, mid_y - x);   circle_edge(mid_x - x, mid_x + x, mid_y + y);   circle_edge(mid_x - y, mid_x + y, mid_y + x);}#define MAX_LINES	((CANVAS_DISPLAY / ICON_SIZE) * 4)static struct fill_line  {   int	left;   int	right;   int	y;}		 scan_lines[MAX_LINES],		*free_line = scan_lines;#define CLAMP(n) ((n) < 0) ? 0 :	\			((n) >= iced_cell_count) ? iced_cell_count-1 : (n)static voidcircle_fill_pair(x, y)	register int	x, y;{	register struct fill_line *line_ptr = free_line;	free_line += 4;	line_ptr->left	= CLAMP(pinned.x - x);	line_ptr->right = CLAMP(pinned.x + x);	line_ptr->y	= CLAMP(pinned.y - y);	++line_ptr;	line_ptr->left  = CLAMP(pinned.x - y); 	line_ptr->right = CLAMP(pinned.x + y); 	line_ptr->y     = CLAMP(pinned.y - x);	++line_ptr;	line_ptr->left  = CLAMP(pinned.x - y);	line_ptr->right = CLAMP(pinned.x + y);	line_ptr->y     = CLAMP(pinned.y + x);	++line_ptr;	line_ptr->left  = CLAMP(pinned.x - x);	line_ptr->right = CLAMP(pinned.x + x);	line_ptr->y     = CLAMP(pinned.y + y);}static intcompare_lines(l1, l2)	register struct fill_line  *l1, *l2;{	if (l1->y < l2->y)		return -1;	else if (l1->y > l2->y)		return 1;	else if (l1->left < l2->left 		|| l1->right > l2->right)		return -1;	else if (l1->left > l2->left		|| l1->right  <  l2->right)		return 1;	else return 0;}static voidcircle_fill(){	register struct fill_line *line_ptr = scan_lines;	register int		   len, op, y = -1;	op = ops[cur_op][(int)panel_get_value(iced_fill_op_item)];	qsort((char *)(LINT_CAST(scan_lines)), free_line - scan_lines,		    sizeof(struct fill_line), compare_lines);	while (line_ptr < free_line)  {		register int	x0;		if (line_ptr->y != y) {			x0 = line_ptr->left;			y = line_ptr->y;			len = line_ptr->right - x0 + 1;			(void)pr_rop(iced_canvas_pr, x0, y, len, 1, op, iced_fill_ci_pr, x0, y);			paint_subcanvas(x0, y, line_ptr->right, y);		}		line_ptr++;	}}static voidcircle_accept(){	int		d, x, y, filled;	CELL_POS	cell2;	circle_xor(paired_points);	paint_cell(pinned.x, pinned.y, pr_get(iced_canvas_pr, pinned.x, pinned.y));	if (filled = (int)panel_get_value(iced_fill_circle_item) != NONE)  {		free_line = scan_lines;	}/*	Basic Bresenham circle starts at pi/2 (x == 0, y == radius), and *	moves x and y toward each other until they meet at pi/4.  Swapping *	x and y gives the symmetric point within a quadrant; symmetric *	points in other quadrants are derived by twiddling signs of x and y. */	cell2 = cell_of_point(&paired_points[1]);	x = 0;	y = circle_radius(&pinned, &cell2);	d = 3 - 2*y;        iced_dirty_ul_cell.x = pinned.x - y;        iced_dirty_ul_cell.y = pinned.y - y;        iced_dirty_dr_cell.x = pinned.x + y;        iced_dirty_dr_cell.y = pinned.y + y;	(void)backup();	while ( x < y ) {		if (filled) {			circle_fill_pair(x, y);		}  else  {			circle_edge_pair(x, y);		}		if (d < 0)			d += 4*x + 6;		else {			d += 4*(x-y) +10;			y -= 1;		}		x++;	}	if (x == y) {		if (filled) {			circle_fill_pair(x, y);		}  else  {			circle_edge_pair(x, y);		}	}	if (filled) {		circle_fill();	}}

⌨️ 快捷键说明

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