📄 iconedit_canvas.c
字号:
if (win_inputnegevent(event)) return; switch (event_action(event)) { case MS_LEFT: cur_op = 1; if (iced_state == ICONIC) iced_icon_canvas_is_clear = FALSE; break; case MS_MIDDLE: cur_op = 0; break; case MS_RIGHT: undo(); return; default: return; /* ignore all other input */ } cur_x = cur_y = -1; set_mode(); (*current).feedback(event);}static voidtracker(event)Event *event;{ if (win_inputnegevent(event)) { /* mouse button up */ switch (event_action(event)) { case MS_LEFT: case MS_MIDDLE: (*current).accept(); reset_handlers(); iced_paint_proof_rect(); paired_points[0].x = -1; } return; } switch (event_action(event)) { case LOC_WINEXIT: if (current == &point) /* paint the proof rect to get any points not yet painted */ iced_paint_proof_rect(); (*current).cancel(); reset_handlers(); return; case MS_LEFT: case MS_MIDDLE: /* two buttons are down, so cancel */ (*current).cancel(); reset_handlers(); return; case LOC_STILL: case LOC_DRAG: (*current).feedback(event); return; }}static voidset_mode(){ switch (panel_get_value(iced_mode_item)) { case MODE_POINT: current = &point; break; case MODE_LINE: current = &line; break; case MODE_RECTANGLE: current = &box; break; case MODE_CIRCLE: current = &circle; break; case MODE_TEXT: current = &text; break; }}static voidreset_handlers(){ current = &base; cur_op = -1;}static SCREEN_POSmidpoint_of_cell(src) CELL_POS *src;{ SCREEN_POS result; result.x = src->x*cell_size + CANVAS_MARGIN + cell_size/2; result.y = src->y*cell_size + CANVAS_MARGIN + cell_size/2; return result;}static SCREEN_POSorigin_of_cell(src) CELL_POS *src;{ SCREEN_POS result; result.x = src->x*cell_size + CANVAS_MARGIN; result.y = src->y*cell_size + CANVAS_MARGIN; return result;}/* ARGSUSED */static CELL_POScell_of_point(point_local) SCREEN_POS *point_local;{ CELL_POS result; result.x = (point_local->x - CANVAS_MARGIN) / cell_size; result.y = (point_local->y - CANVAS_MARGIN) / cell_size; return result;}staticcell_of_event(ie, dest_cell) Event *ie; CELL_POS *dest_cell;{ if (ie->ie_locx < CANVAS_MARGIN || ie->ie_locy < CANVAS_MARGIN) { return FALSE; } dest_cell->x = (ie->ie_locx - CANVAS_MARGIN) / cell_size; dest_cell->y = (ie->ie_locy - CANVAS_MARGIN) / cell_size; if (dest_cell->x >= iced_cell_count || dest_cell->y >= iced_cell_count) { dest_cell->x = dest_cell->y = -1; return FALSE; } if (dest_cell->x == cur_x && dest_cell->y == cur_y) return FALSE; cur_x = dest_cell->x; cur_y = dest_cell->y; return TRUE;}static voidpin_cell(cell)CELL_POS *cell;{ SCREEN_POS origin; origin = origin_of_cell(cell); (void)pw_write(iced_canvas_pw, origin.x+1, origin.y+1, cell_size - 2, cell_size - 2, PIX_SRC^PIX_DST, &iced_pin_pr, (CURSOR_SIZE - cell_size)/2 + 1, (CURSOR_SIZE - cell_size)/2 + 1 );}#define LOOKING_FOR_FIRST (paired_points[0].x == -1)static get_first_cell(ie)Event *ie;{ CELL_POS new_cell; int action = event_action(ie); if (win_inputposevent(ie) && (action == MS_LEFT || action == MS_MIDDLE || action == LOC_DRAG ) && cell_of_event(ie, &new_cell) ) { paired_points[0] = midpoint_of_cell(&new_cell); paired_points[1] = paired_points[0]; pinned = new_cell; pin_cell(&new_cell); return TRUE; /* set it if you can */ } /* if not, it will come round again */ return FALSE;}static voidpoint_feedback(ie)struct inputevent *ie;{ CELL_POS new; if (event_action(ie) == LOC_STILL) { iced_paint_proof_rect(); return; } if (cell_of_event(ie, &new)) { if (event_action(ie) != LOC_DRAG) { (void)backup(); iced_dirty_ul_cell.x = new.x; iced_dirty_ul_cell.y = new.y; iced_dirty_dr_cell.x = new.x; iced_dirty_dr_cell.y = new.y; } else { iced_dirty_ul_cell.x = min(iced_dirty_ul_cell.x,new.x); iced_dirty_ul_cell.y = min(iced_dirty_ul_cell.y,new.y); iced_dirty_dr_cell.x = max(iced_dirty_dr_cell.x,new.x); iced_dirty_dr_cell.y = max(iced_dirty_dr_cell.y,new.y); } paint_cell(new.x, new.y, cur_op); (void)pr_put(iced_canvas_pr, new.x, new.y, cur_op); }}static voidline_xor(ends)register SCREEN_POS ends[] ;{ (void)pw_vector(iced_canvas_pw, ends[0].x, ends[0].y, ends[1].x, ends[1].y, PIX_SRC^PIX_DST, 1);}static voidline_feedback(ie)Event *ie;{ CELL_POS new_cell; if (LOOKING_FOR_FIRST) { (void)get_first_cell(ie); return; } if (cell_of_event(ie, &new_cell) ) { line_xor(paired_points); paired_points[1] = midpoint_of_cell(&new_cell); line_xor(paired_points); }}static voidline_accept(){ line_xor(paired_points); paint_cell(pinned.x, pinned.y, pr_get(iced_canvas_pr, pinned.x, pinned.y)); draw_line_of_cells(pinned.x, pinned.y, cur_x, cur_y); iced_dirty_ul_cell.x = min(pinned.x,cur_x); iced_dirty_ul_cell.y = min(pinned.y,cur_y); iced_dirty_dr_cell.x = max(pinned.x,cur_x); iced_dirty_dr_cell.y = max(pinned.y,cur_y);}static voidline_cancel(){ line_xor(paired_points); paired_points[0].x = -1; paint_cell(pinned.x, pinned.y, pr_get(iced_canvas_pr, pinned.x, pinned.y));}/* * This function is the preprocessor to the Bresenham line drawing routine. * If the slope of the line is < 1, then x is passed as the independent * variable; otherwise y is the independent variable. */staticdraw_line_of_cells(x1, y1, x2, y2) register int x1, y1, /* coordinates of the first cell */ x2, y2; /* coordinates of the second cell */{ register int dx, dy; (void)backup(); dx = x2 - x1; if (dx < 0) dx = -dx; dy = y2 - y1; if (dy < 0) dy = -dy; if (dy < dx) { /* slope is < 1 */ bresenham(x1, y1, x2, y2, dx, dy, 1); } else { /* slope is >= 1 */ bresenham(y1, x1, y2, x2, dy, dx, 0); }}/* * This function draws a line in the bitmap by using a generalized * Bresenham's method. This method determines for each point between the * independent endpoints a dependent value. Thus for slopes >=1 y is * the independent variable and x values are calculated; for slopes < 1 * x is the independent variable. (NOTE: the determination of the independent * and dependent variable is done by draw_line. ) */staticbresenham (ind1, dep1, ind2, dep2, d_ind, d_dep, is_x)int ind1, dep1, /* the 1st pt */ ind2, dep2, /* the 2nd pt */ d_ind, /* difference between the indpendent variable */ d_dep, /* difference between the dependent variable */ is_x; /* = 1 if x is the indpendent variable */{ register int incr1, /* increment if d < 0 */ incr2, /* increment if d >= 0 */ incr_dep, /* increment the dependent variable; either 1 (positive slope) or -1 (neg.) */ d, /* determines if the dependent variable should be increment */ ind, /* the current value of the independent variable */ dep, /* the current value of the dependent variable */ ind_end, /* the stopping point of the independent variable */ y, /* the y value of the pixel */ x; /* the x value of the pixel */ d = 2 * d_dep - d_ind; /* calulate the initial d value */ incr1 = 2 * d_dep; incr2 = 2 * (d_dep - d_ind); /* * Find which point has the lowest independent variable and use it * as the starting point. */ if (ind1 > ind2) { ind = ind2; dep = dep2; ind_end = ind1; incr_dep = (dep2 > dep1) ? -1 : 1; } else { ind = ind1; dep = dep1; ind_end = ind2; incr_dep = (dep1 > dep2) ? -1 : 1; } do { /* * x and y are assigned depending on whether x is the dependent or * independent variable. */ if (is_x) { x = ind; y = dep; } else { x = dep; y = ind; } paint_cell(x, y, cur_op); (void)pr_put(iced_canvas_pr, x, y, cur_op); if (d < 0) d += incr1; else { dep += incr_dep; d += incr2; } } while (ind++ < ind_end);}static voidbox_solid(cells) CELL_POS cells[]; { u_int op, result; result = (u_int)panel_get_value(iced_fill_op_item); op = ops[cur_op][result]; (void)pr_replrop(iced_canvas_pr, cells[0].x, cells[0].y, cells[1].x - cells[0].x + 1, cells[1].y - cells[0].y + 1, (int)op, iced_fill_sq_pr, cells[0].x, cells[0].y); paint_subcanvas(cells[0].x, cells[0].y, cells[1].x, cells[1].y);}static voidbox_border(cells)CELL_POS cells[];{ register u_int i, j; for (i = cells[0].x; i <= cells[1].x; i++) { paint_cell((int)i, (int)cells[0].y, cur_op); (void)pr_put(iced_canvas_pr, (int)i, cells[0].y, cur_op); if (i == cells[0].x || i == cells[1].x) { for (j = cells[0].y+1; j < cells[1].y; j++) { paint_cell((int)i, (int)j, cur_op); (void)pr_put(iced_canvas_pr, (int)i, (int)j, cur_op); } } paint_cell((int)i, cells[1].y, cur_op); (void)pr_put(iced_canvas_pr, (int)i, cells[1].y, cur_op); }}static void box_xor(cor) CELL_POS cor[]; { register int x0 = cor[0].x; register int y0 = cor[0].y; register int x1 = cor[1].x; register int y1 = cor[1].y; /* if (x1>x0 && y1>y0) { rect_construct(&r, x0, y0, x1-x0+1, y1-y0+1); } else if (x1>x0 && y1<=y0) { rect_construct(&r, x0, y0, x1-x0+1, y0-y1+1); } else if (x1<=x0 && y1>y0) { rect_construct(&r, x0, y0, x0-x1+1, y1-y0+1); } else if (x1<=x0 && y1<=y0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -