📄 iconedit_canvas.c
字号:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)iconedit_canvas.c 1.1 92/07/30";#endif#endif/**************************************************************************//* iconedit_canvas.c *//* Copyright (c) 1986 by Sun Microsystems Inc. *//**************************************************************************/#include <sunwindow/sun.h>#include "iconedit.h"extern double sqrt();void pw_batch();static undo(), proof_event_proc(), canvas_event_proc();/**************************************************************************//* text mode stuff *//**************************************************************************/ static CELL_POS abc_cell_origin,abc_h_cell_origin,abc_feedback_origin;static char *abc_string;static struct pr_size abc_size;static int abc_len;struct pixfont *iced_abc_font; #define abc_home iced_abc_font->pf_char[*abc_string].pc_home.y;/************************************************************************//* proof subwindow declarations *//************************************************************************/Canvas iced_proof;struct pixrect *iced_fill_sq_pr;struct pixrect *iced_fill_ci_pr;struct pixrect *iced_proof_pr = &iced_root_gray_patch;static struct pixwin *proof_pixwin;#define ICON_LEFT_OFFSET 86 #define ICON_TOP_OFFSET 14#define CURSOR_LEFT_OFFSET 110 #define CURSOR_TOP_OFFSET 38/************************************************************************//* canvas subwindow declarations *//************************************************************************/Canvas iced_canvas;struct pixwin *iced_canvas_pw;struct pixrect *iced_canvas_pr; /* points to iced_icon_pr or * iced_new_cursor_pr */CELL_POS iced_dirty_ul_cell, iced_dirty_dr_cell;int iced_cell_count;static short cell_size;static short new_cursor_array[16]; mpr_static(iced_new_cursor_pr, 16, 16, 1, new_cursor_array);struct cursor iced_new_cursor = { 0, 0, PIX_SRC, &iced_new_cursor_pr };static short icon_array[256];mpr_static(iced_icon_pr, 64, 64, 1, icon_array);static short temp_array[256];mpr_static(iced_temp_pr, 64, 64, 1, temp_array);static short undo_array[256];mpr_static(iced_undo_pr, 64, 64, 1, undo_array);static void nullproc();static void paint_subcanvas();static void paint_cell();static void basereader();static void reset_handlers();static void set_mode();static void tracker();static void point_feedback();static void line_feedback(), line_accept(), line_cancel();static void box_feedback(), box_accept(), box_cancel();static void circle_feedback(), circle_accept(), circle_cancel();static void text_feedback(), text_accept(), text_cancel();static struct canvas_handlers { void (*reader)(); void (*feedback)(); void (*accept)(); void (*cancel)();} base = { basereader, nullproc, nullproc, nullproc }, point = { tracker, point_feedback, nullproc, nullproc }, line = { tracker, line_feedback, line_accept, line_cancel }, box = { tracker, box_feedback, box_accept, box_cancel }, circle = { tracker, circle_feedback, circle_accept, circle_cancel }, text = { tracker, text_feedback, text_accept, text_cancel };static struct canvas_handlers *current = &point;static int cur_x, cur_y, cur_op;static CELL_POS pinned;static SCREEN_POS midpoint_of_cell(), paired_points[2] = { {-1, -1}, {-1, -1} };static u_short pin_bits[56] = { 0xC000, 0x0070, 0xE000, 0x00E0, 0x7000, 0x01C0, 0x3800, 0x0380, 0x1C00, 0x0700, 0x0E00, 0x0E00, 0x0700, 0x1C00, 0x0380, 0x3800, 0x01C0, 0x7000, 0x00E0, 0xE000, 0x0071, 0xC000, 0x003B, 0x8000, 0x001F, 0x0000, 0x000E, 0x0000, 0x000E, 0x0000, 0x001F, 0x0000, 0x003B, 0x8000, 0x0071, 0xC000, 0x00E0, 0xE000, 0x01C0, 0x7000, 0x0380, 0x3800, 0x0700, 0x1C00, 0x0E00, 0x0E00, 0x1C00, 0x0700, 0x3800, 0x0380, 0x7000, 0x01C0, 0xE000, 0x00E0, 0xC000, 0x0070};mpr_static(iced_pin_pr, CURSOR_SIZE, CURSOR_SIZE, 1, pin_bits);/* The rows of this array of pixrect_ops are "backwards" * because in the simplest case, the definition of paint is 1, * and of erase, 0. */static u_int ops[2][3] = { { PIX_NOT(PIX_SRC), PIX_NOT(PIX_SRC) & PIX_DST, PIX_NOT(PIX_SRC) ^ PIX_DST }, { PIX_SRC, PIX_SRC | PIX_DST, PIX_SRC ^ PIX_DST } };static voidnullproc() { return; }/**************************************************************************//* proof section *//**************************************************************************/iced_init_proof() { iced_proof = window_create(iced_base_frame, CANVAS, WIN_RIGHT_OF, iced_canvas, WIN_BELOW, iced_panel, WIN_WIDTH, iced_proof_width, WIN_HEIGHT, iced_proof_height, WIN_EVENT_PROC, proof_event_proc, WIN_ERROR_MSG, "Unable to create proof canvas\n", CANVAS_FAST_MONO, TRUE, 0); if (iced_proof == NULL) { (void)fprintf(stderr,"Unable to create proof canvas\n"); exit(1); } proof_pixwin = canvas_pixwin(iced_proof);}/* ARGSUSED */staticproof_event_proc(win, event)Window win;Event *event;{ if (iced_state != CURSOR) return; switch (event_action(event)) { case LOC_WINENTER: (void)pw_replrop(proof_pixwin, 0, 0, iced_proof_width, iced_proof_height, PIX_SRC, iced_proof_pr, 0, 0); break; case LOC_WINEXIT: iced_paint_proof_rect(); break; }}iced_paint_proof() { (void)pw_replrop(proof_pixwin, 0, 0, iced_proof_width, iced_proof_height, PIX_SRC, iced_proof_pr, 0, 0); iced_paint_proof_rect();}iced_paint_proof_rect() { 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_icon_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_new_cursor_pr, 0, 0); (void)window_set(iced_proof, WIN_CURSOR, &iced_new_cursor, 0); }}/************************************************************************//* canvas section *//************************************************************************/iced_init_canvas() { iced_canvas = window_create(iced_base_frame, CANVAS, WIN_X, 0, WIN_BELOW, iced_mouse_panel, WIN_HEIGHT, CANVAS_SIDE, WIN_WIDTH, CANVAS_SIDE, WIN_CURSOR, &iconedit_main_cursor, WIN_CONSUME_PICK_EVENTS, LOC_DRAG, LOC_STILL, 0, WIN_EVENT_PROC, canvas_event_proc, WIN_ERROR_MSG, "Unable to create iced canvas\n", CANVAS_FAST_MONO, TRUE, 0); if (iced_canvas == NULL) { (void)fprintf(stderr,"Unable to create iced canvas\n"); exit(1); } iced_canvas_pw = canvas_pixwin(iced_canvas); current = &base; cur_x = cur_y = -1;}/************************************************************************//* iced_set_state -- either CURSOR or ICON *//************************************************************************/iced_set_state(new_state) int new_state; { if (iced_state == new_state) return; (void)panel_set_value(iced_size_item,new_state); if ((iced_state = new_state) == CURSOR) { iced_canvas_pr = &iced_new_cursor_pr; cell_size = CURSOR_SIZE; (void)window_set(iced_proof, WIN_CURSOR, &iced_new_cursor, 0); } else { iced_canvas_pr = &iced_icon_pr; cell_size = ICON_SIZE; (void)window_set(iced_proof, WIN_CURSOR, &iconedit_main_cursor, 0); } iced_cell_count = CANVAS_DISPLAY / cell_size; (void)backup(); iced_paint_proof(); iced_paint_canvas();}/************************************************************************//* canvas painting routines *//************************************************************************/voidiced_paint_canvas(){ if (iced_state == ICONIC && iced_icon_canvas_is_clear) { iced_clear_proc(); return; } if (iced_state == ICONIC) { window_set(iced_base_frame, FRAME_LABEL, "painting image...", 0); iced_set_cursors_hourglass(); } (void)pw_writebackground(iced_canvas_pw, 0, 0, CANVAS_SIDE, CANVAS_SIDE, PIX_CLR); if (panel_get_value(iced_grid_item)) iced_paint_grid(PIX_SET); else iced_paint_border(); paint_subcanvas(0,0,iced_cell_count-1,iced_cell_count-1); if (iced_state == ICONIC) { window_set(iced_base_frame, FRAME_LABEL, "iconedit", 0); iced_set_cursors_normal(); }}static voidpaint_subcanvas(x0, y0, x1, y1) int x0, y0, x1, y1; { register int x, y; pw_batch(iced_canvas_pw, PW_ALL); for (y = y0; y <= y1; y++) { for (x = x0; x <= x1; x++) paint_cell(x, y, pr_get(iced_canvas_pr, x,y)); pw_show(iced_canvas_pw); } pw_batch(iced_canvas_pw, PW_NONE);}static voidpaint_cell(x, y, color)int x, y, color;{ register int dx, dy, dim; if (color) color = 3; dx = CANVAS_MARGIN + cell_size*x + 1; dy = CANVAS_MARGIN + cell_size*y + 1; dim = cell_size - 1; (void)pw_rop(iced_canvas_pw, dx, dy, dim, dim, PIX_SRC, iced_patch_prs[color], 1, 1);}voidiced_paint_border(){ struct rect r; rect_construct(&r, CANVAS_MARGIN, CANVAS_MARGIN, iced_cell_count * cell_size + 1, iced_cell_count * cell_size + 1); pw_batch(iced_canvas_pw, PW_ALL); (void)pw_vector(iced_canvas_pw, CANVAS_MARGIN, CANVAS_MARGIN, rect_right(&r), CANVAS_MARGIN, PIX_SET, 1); (void)pw_vector(iced_canvas_pw, CANVAS_MARGIN, CANVAS_MARGIN, CANVAS_MARGIN, rect_bottom(&r), PIX_SET, 1); (void)pw_vector(iced_canvas_pw, rect_right(&r), CANVAS_MARGIN, rect_right(&r), rect_bottom(&r), PIX_SET, 1); (void)pw_vector(iced_canvas_pw, CANVAS_MARGIN, rect_bottom(&r), rect_right(&r), rect_bottom(&r), PIX_SET, 1); pw_show(iced_canvas_pw); pw_batch(iced_canvas_pw, PW_NONE);}voidiced_paint_grid(op)register u_int op;{ register int i, beg, end, center, count, stub; int c_count = CANVAS_DISPLAY / CURSOR_SIZE; beg = CANVAS_MARGIN; end = CANVAS_MARGIN + c_count * CURSOR_SIZE; center = ((end-beg)/2) + 12; count = 0; pw_batch(iced_canvas_pw, PW_ALL); for (i = beg; i <= end; i += CURSOR_SIZE) { if (!(count % 4)) stub = 7; else if (!(count % 2)) stub = 3; else stub = 0; if (count == 16 || count == 0) stub = 0; if (count == 8) { (void)pw_vector(iced_canvas_pw, i, beg-stub, i, center-2, (int)op, NULL); (void)pw_vector(iced_canvas_pw, i, center+2, i, end+stub, (int)op, NULL); (void)pw_vector(iced_canvas_pw, beg-stub, i, center-2, i, (int)op, NULL); (void)pw_vector(iced_canvas_pw, center+2, i, end+stub, i, (int)op, NULL); } else { (void)pw_vector(iced_canvas_pw, i, beg-stub, i, end+stub, (int)op, NULL); (void)pw_vector(iced_canvas_pw, beg-stub, i, end+stub, i, (int)op, NULL); } count++; } pw_show(iced_canvas_pw); pw_batch(iced_canvas_pw, PW_NONE);}staticundo(){ (void)pr_rop(&iced_temp_pr,0,0,iced_cell_count,iced_cell_count,PIX_SRC,iced_canvas_pr,0,0); (void)pr_rop(iced_canvas_pr,0,0,iced_cell_count,iced_cell_count,PIX_SRC,&iced_undo_pr,0,0); (void)pr_rop(&iced_undo_pr,0,0,iced_cell_count,iced_cell_count,PIX_SRC,&iced_temp_pr,0,0); iced_paint_proof_rect(); if (iced_dirty_ul_cell.x < 0) iced_dirty_ul_cell.x = 0; if (iced_dirty_ul_cell.y < 0) iced_dirty_ul_cell.y = 0; if (iced_dirty_dr_cell.x > iced_cell_count-1) iced_dirty_dr_cell.x = iced_cell_count-1; if (iced_dirty_dr_cell.y >= iced_cell_count-1) iced_dirty_dr_cell.y = iced_cell_count-1; paint_subcanvas(iced_dirty_ul_cell.x, iced_dirty_ul_cell.y, iced_dirty_dr_cell.x, iced_dirty_dr_cell.y);}/************************************************************************//* canvas_event_proc *//************************************************************************//* ARGSUSED */staticcanvas_event_proc(win, event)Window win;Event *event;{ if (event_action(event) == LOC_RGNENTER) { abc_get_info(); return; } (*current).reader(event);}static voidbasereader(event)Event *event;{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -