home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/canvas.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* canvas.h: header for canvas.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define canvas_h 1
-
- #include "all.h"
- #include "newext.h"
-
- /* EOF */
- /* cat > src+obj/canvas/box_drawing.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* box_drawing: draw a box */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- box_drawing (x, y, xdim, ydim)
- int x, y, xdim, ydim;
- {
- register x1, x2, y1, y2;
-
- x1 = x - xdim / 2;
- y1 = y - ydim / 2;
- x2 = x1 + xdim;
- y2 = y1 + ydim;
- pw_vector (pw, x1, y1, x2, y1, PIX_NOT (PIX_DST), 255);
- pw_vector (pw, x1, y1, x1, y2, PIX_NOT (PIX_DST), 255);
- pw_vector (pw, x2, y1, x2, y2, PIX_NOT (PIX_DST), 255);
- pw_vector (pw, x1, y2, x2, y2, PIX_NOT (PIX_DST), 255);
- }
- /* EOF */
- /* cat > src+obj/canvas/can_controller.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* can_controller: Canvas controller to react to */
- /* different input events */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- can_controller (can, event)
- Canvas can;
- Event *event;
- {
- int eid = event_id (event);
-
- middle_button_down = event_is_down (event);
-
- /* right button to reset position picked */
- if (eid == MS_RIGHT && event_is_down (event))
- {
- /* reset position */
- reset_pos ();
- }
-
- /* special button assignment in color editing mode */
- switch (color_edit_mode)
- {
- case CEDIT_NONE:
- break;
- case CEDIT_CONT:
- whiteout (eid, event);
- return;
- case CEDIT_FIDDLE:
- fiddle_proc (eid, event);
- return;
- }
-
- /* special button assignment in graphing mode */
- if (graph_mode == PLOT_XY)
- { /* plotting mode */
- plot_proc (eid, event);
- return;
- }
-
- /* if one down already, second middle button down may cause
- to move a cutout or draw a new square */
- if (first_middle_down)
- { /* moving cutout image */
- switch (eid)
- {
- case MS_MIDDLE:
- if (middle_button_down)
- {
- if (event_ctrl_is_down (event))
- copy_request = 1;
- if (inarea (event, &square) || paste_request)
- { /* inside, then move */
- if (square_drawn)
- draw_square (&square);
- is_moving = 1;
- move_image (eid, event);
- }
- else
- { /* outside, get another square */
- if (square_drawn)
- draw_square (&square);
- square_drawn = first_point = first_middle_down = 0;
- get_square (eid, event);
- }
- }
- else /* button released, moving done */
- move_image (eid, event);
- break;
- case LOC_DRAG:
- if (is_moving)
- move_image (eid, event);
- break;
- default:
- break;
- }
- return;
- }
-
- /* normal mode */
- switch (eid)
- {
- case MS_LEFT: /* to pick a starting position */
- if (event_is_down (event))
- pick_position (event);
- break;
- case MS_MIDDLE: /* drawing a square */
- if (!square_drawn)
- get_square (eid, event);
- else
- { /* square exists */
- square_drawn = 0;
- first_point = 0;
- draw_square (&square); /* erase square */
- get_square (eid, event);
- }
- break;
- case LOC_DRAG: /* drawing a square */
- if (first_point)
- {
- get_square (eid, event);
- }
- break;
- default:
- break;
- }
- }
- /* EOF */
- /* cat > src+obj/canvas/coor_adjust.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* coor_adjust: adjust coordinates */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- coor_adjust (p)
- struct square_rec *p;
- {
- register tmp;
-
- if (p->startx > p->endx)
- {
- tmp = p->startx;
- p->startx = p->endx;
- p->endx = tmp;
- }
- if (p->starty > p->endy)
- {
- tmp = p->starty;
- p->starty = p->endy;
- p->endy = tmp;
- }
- }
- /* EOF */
- /* cat > src+obj/canvas/create_edit_menu.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* creat_edit_menu: create edit menu */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- create_edit_menu ()
- {
- void edit_proc ();
-
- edit_menu = menu_create (
- MENU_FONT, font_menu,
- MENU_STRINGS, "Cut", "Copy", "Paste", "Clear", 0,
- MENU_NOTIFY_PROC, edit_proc,
- 0);
- }
- /* EOF */
- /* cat > src+obj/canvas/display_panel_menu.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* display_panel_menu: routine to display menu m on */
- /* event from panel named panel */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- bool
- display_panel_menu (item, event, panel, m)
- Panel_item item;
- Event *event;
- Panel panel;
- Menu m;
- {
- Rect *enclose;
-
- static bool hilite = FALSE;
- static Panel_item hi_item = NULL;
-
- switch (event_action (event))
- {
- /* display menu on right button down */
- case MS_RIGHT:
- if (event_is_down (event))
- menu_show (m, panel, event, 0);
- break;
-
- case LOC_WINEXIT:
- if (hilite)
- {
- panel_cancel_preview (item, event);
- window_set (panel, WIN_IGNORE_PICK_EVENTS, LOC_DRAG, LOC_WINEXIT, 0, 0);
- hilite = FALSE;
- }
- break;
-
- case LOC_DRAG:
- enclose = (Rect *) panel_get (item, PANEL_ITEM_RECT);
- if (in_rect (event_x (event), event_y (event), enclose))
- {
- if (!hilite)
- {
- panel_begin_preview (item, event);
- hi_item = item;
- hilite = TRUE;
- }
- }
- else if (hilite)
- {
- panel_cancel_preview (hi_item, event);
- hilite = FALSE;
- }
- break;
-
- case MS_LEFT:
- enclose = (Rect *) panel_get (item, PANEL_ITEM_RECT);
- if (event_is_down (event))
- {
- window_set (panel, WIN_CONSUME_PICK_EVENTS, LOC_WINEXIT, LOC_DRAG, 0, 0);
-
- /* click in the button rectangle? */
- if (in_rect (event_x (event), event_y (event), enclose))
- {
- if (!hilite)
- {
- panel_begin_preview (item, event);
- hi_item = item;
- hilite = TRUE;
- }
- }
- else if (hilite)
- {
- panel_cancel_preview (hi_item, event);
- hilite = FALSE;
- }
- }
- else if (event_is_up (event))
- {
- window_set (panel, WIN_IGNORE_PICK_EVENTS, LOC_DRAG, LOC_WINEXIT, 0, 0);
- if (in_rect (event_x (event), event_y (event), enclose))
- {
- panel_accept_preview (hi_item, event);
- hilite = FALSE;
- return (TRUE);
- }
- }
- break;
-
- default:
- break;
- }
- return (FALSE);
- }
- /* EOF */
- /* cat > src+obj/canvas/draw_line.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* draw_line: plot a straight line */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- draw_line (eid, event)
- int eid;
- Event *event;
- {
- int newx, newy;
-
- switch (eid)
- {
- case MS_LEFT:
- if (!first_point)
- { /* get first point */
- if (event_is_down (event))
- {
- newx = event_x (event);
- newy = event_y (event);
- line_rec.x1 = line_rec.x2 = newx;
- line_rec.y1 = line_rec.y2 = newy;
- first_point = 1;
- line_drawn = 0;
- pw_vector (pw, line_rec.x1, line_rec.y1, line_rec.x2, line_rec.y2,
- PIX_NOT (PIX_DST), 255);
- }
- }
- else if (event_is_up (event))
- { /* line done */
- line_drawn = 1;
- first_point = 0;
- }
- break;
- case LOC_DRAG: /* drawing when dragging */
- newx = event_x (event);
- newy = event_y (event);
-
- pw_vector (pw, line_rec.x1, line_rec.y1, line_rec.x2, line_rec.y2,
- PIX_NOT (PIX_DST), 255);
-
-
- if (abs (newx - line_rec.x1) > ERANGE)
- line_rec.x2 = newx;
- else
- line_rec.x2 = line_rec.x1;;
-
- if (abs (newy - line_rec.y1) > ERANGE)
- line_rec.y2 = newy;
- else
- line_rec.y2 = line_rec.y1;;
-
- pw_vector (pw, line_rec.x1, line_rec.y1, line_rec.x2, line_rec.y2,
- PIX_NOT (PIX_DST), 255);
- break;
- default:
- break;
- }
- }
- /* EOF */
- /* cat > src+obj/canvas/draw_square.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* draw_square: plot a square */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- draw_square (p)
- struct square_rec *p;
- {
- register sx, sy, ex, ey;
-
- sx = p->startx;
- sy = p->starty;
- ex = p->endx;
- ey = p->endy;
-
- pw_vector (pw, sx, sy, sx, ey, PIX_NOT (PIX_DST), 255);
- pw_vector (pw, sx, sy, ex, sy, PIX_NOT (PIX_DST), 255);
- pw_vector (pw, sx, ey, ex, ey, PIX_NOT (PIX_DST), 255);
- pw_vector (pw, ex, sy, ex, ey, PIX_NOT (PIX_DST), 255);
- }
- /* EOF */
- /* cat > src+obj/canvas/edit_handler.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* edit_handler: handler for Edit Menu */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- edit_handler (item, event)
- Panel_item item;
- Event *event;
- {
- if (display_panel_menu (item, event, menu_panel, edit_menu))
- edit_proc (edit_menu, menu_get (edit_menu, MENU_NTH_ITEM, 1));
- }
- /* EOF */
- /* cat > src+obj/canvas/edit_proc.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* edit_proc: handler to process imae editing request: */
- /* copy, cut, paste, and clear */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- void
- edit_proc (m, mi)
- Menu m;
- Menu_item mi;
- {
- char str[MAXNAMELEN];
-
- strcpy (str, (char *) menu_get (mi, MENU_STRING));
- if (!strcmp ("Cut", str))
- { /* cut, store to clipboard */
- if (load_clipboard () == 0)
- erase_last ();
- square_drawn = 0;
- }
- else if (!strcmp ("Copy", str))
- { /* copy to clipboard */
- if (load_clipboard () == 0)
- copy_request = 1;
- }
- else if (!strcmp ("Paste", str))
- { /* paste from clipboard */
- paste_request = 1;
- first_middle_down = 1;
- }
- else if (!strcmp ("Clear", str))
- erase_last ();
- return;
- }
- /* EOF */
- /* cat > src+obj/canvas/get_square.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* get_square: get the square */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- get_square (eid, event)
- Event *event;
- int eid;
- {
- int newx, newy, xdim, ydim;
-
- if (!first_point)
- { /* get first point */
- if (middle_button_down && eid == MS_MIDDLE)
- {
- square.startx = event_x (event);
- square.starty = event_y (event);
- square.endx = square.startx;
- square.endy = square.starty;
- first_point = 1;
- square_drawn = 0;
- }
- }
- else
- { /* updating squares when dragging */
- if (middle_button_down && eid == LOC_DRAG)
- {
- newx = event_x (event);
- newy = event_y (event);
- if (newx != square.endx && newy != square.endy)
- {
- draw_square (&square);
- square.endx = newx;
- square.endy = newy;
- draw_square (&square);
- }
- }
- else if (!middle_button_down)
- { /* finish a square */
- first_point = 0;
- if ((square.endx - square.startx) == 0 ||
- (square.endy - square.starty) == 0)
- square_drawn = 0;
- else
- {
- coor_adjust (&square);
- xdim = square.endx - square.startx - 2;
- ydim = square.endy - square.starty - 2;
- switch (xdim % 4)
- {
- case 0:
- case 2:
- break;
- case 1:
- draw_square (&square);
- (square.endx)--;
- xdim--;
- draw_square (&square);
- break;
- case 3:
- draw_square (&square);
- (square.endx)++;
- xdim++;
- draw_square (&square);
- }
- curr_image.startx = square.startx + 1;
- curr_image.starty = square.starty + 1;
- curr_image.org_xdim = curr_image.xdim = xdim;
- curr_image.org_ydim = curr_image.ydim = ydim;
- curr_image.zoomx = curr_image.zoomy = 1;
- curr_image.expanded = 0;
- curr_image.cutout = 1;
- curr_image.in_use = 0;
-
- clear_request = 0;
- square_drawn = 1;
- if (graph_mode == PLOT_CON || graph_mode == PLOT_3D)
- first_middle_down = 0;
- else
- first_middle_down = 1;
- }
- }
- }
- }
- /* EOF */
- /* cat > src+obj/canvas/inarea.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* inarea: event in the area */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- inarea (event, sp)
- Event *event;
- struct square_rec *sp;
- {
- register x, y;
-
- x = event_x (event);
- y = event_y (event);
-
- if (x >= sp->startx && x <= sp->endx &&
- y >= sp->starty && y <= sp->endy)
- return (1); /* inside */
- return (0); /* outside */
- }
- /* EOF */
- /* cat > src+obj/canvas/load_clipboard.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* load_clipboard: store a cutout image onto clipboard */
- /* memory */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- load_clipboard ()
- {
- int lastw = curr_image.xdim;
- int lasth = curr_image.ydim;
- int lastx = curr_image.startx;
- int lasty = curr_image.starty;
-
- if (clipboard.pr != NULL)
- pr_close (clipboard.pr);
- if ((clipboard.pr = mem_create (lastw, lasth, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create clipboard pixrect for image.");
- return (-1);
- }
- pw_read (clipboard.pr, 0, 0, lastw, lasth, PIX_SRC, pw, lastx, lasty);
- clipboard.xdim = lastw;
- clipboard.ydim = lasth;
- return (0);
- }
- /* EOF */
- /* cat > src+obj/canvas/move_image.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* move_image: moving image around on canvas */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- move_image (eid, event)
- int eid;
- Event *event;
- {
- static struct pixrect *pr;
- static xdim, ydim, oldx, oldy;
- register x, y;
-
- if (paste_request && clipboard.pr != NULL)
- {
- xdim = clipboard.xdim;
- ydim = clipboard.ydim;
- }
- else
- {
- xdim = curr_image.xdim;
- ydim = curr_image.ydim;
- }
-
- switch (eid)
- {
- case MS_MIDDLE:
- if (event_is_down (event))
- {
- if (paste_request && clipboard.pr != NULL)
- pr = clipboard.pr;
- else
- {
- if ((pr = mem_create (xdim, ydim, 8)) == NULL)
- {
- msg_write ("Error: Not enough memory to create clipboard pixrect for image.");
- return (-1);
- }
- pw_read (pr, 0, 0, xdim, ydim, PIX_SRC, pw,
- curr_image.startx, curr_image.starty);
- }
- if (!copy_request && !paste_request)
- erase_last ();
- }
- else
- { /* button released, moving done */
- x = event_x (event);
- y = event_y (event);
- box_drawing (x, y, xdim, ydim);
- startx = x - xdim / 2;
- starty = y - ydim / 2;
- pw_write (pw, startx, starty, xdim, ydim, PIX_SRC, pr, 0, 0);
- if (pr != clipboard.pr)
- pr_close (pr);
- square_drawn = first_middle_down = 0;
- copy_request = paste_request = 0;
- oldx = oldy = 0;
- is_moving = 0;
- curr_image.startx = startx;
- curr_image.starty = starty;
- curr_image.org_xdim = curr_image.xdim = xdim;
- curr_image.org_ydim = curr_image.ydim = ydim;
- curr_image.zoomx = curr_image.zoomy = 1;
- curr_image.expanded = 0;
- curr_image.cutout = 1;
- curr_image.in_use = 0;
- }
- break;
- case LOC_DRAG:
- if (oldx != 0 && oldy != 0)
- box_drawing (oldx, oldy, xdim, ydim);
- x = event_x (event);
- y = event_y (event);
- box_drawing (x, y, xdim, ydim);
- oldx = x;
- oldy = y;
- break;
- default:
- break;
- } /* end switch */
-
- return;
- }
- /* EOF */
- /* cat > src+obj/canvas/pick_position.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* pick_position: select a position as origin for image */
- /* display */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "canvas.h" */
-
- pick_position (event)
- Event *event;
- {
- /* first click on canvas picks a position -- upper left corner */
- if (!pos_picked)
- {
- startx = event_x (event);
- starty = event_y (event);
- pos_picked = 1;
- sprintf (msgstr, "Note: Picked position - (x, y) = (%d, %d).", startx, starty);
- msg_write (msgstr);
- }
- else
- { /* second click loads image */
- msg_write ("Note: Loading image . . . .");
- if (load_proc2 ((int) panel_get_value (load_toggle)))
- return;
- clear_request = 0;
- reset_pos ();
- }
- return;
- }
- /* EOF */
-