home *** CD-ROM | disk | FTP | other *** search
-
- /* @(#)graphics.c 1.5 90/04/10
- *
- * Independent graphics routines associated with the scantool program.
- *
- * Copyright (c) Rich Burridge.
- * Sun Microsystems, Australia - All rights reserved.
- *
- * Permission is given to distribute these sources, as long as the
- * copyright messages are not removed, and no monies are exchanged.
- *
- * No responsibility is taken for any errors or inaccuracies inherent
- * either to the comments or the code of this program, but if
- * reported to me, then an attempt will be made to fix them.
- */
-
- #include <stdio.h>
- #include <strings.h>
- #include <signal.h>
- #include "scantool.h"
- #include "scantool_extern.h"
-
-
- do_repaint() /* Draw titleline and page layout. */
- {
- int i ;
-
- draw_area(0, 0, SCAN_WIDTH, SCAN_HEIGHT, GCLR) ;
- draw_text(0*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Brightness") ;
- draw_text(1*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Contrast") ;
- draw_text(2*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Grain") ;
- draw_text(3*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Help") ;
- draw_text(4*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Resolution") ;
- draw_text(5*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Set") ;
- draw_area(0, 0, SCAN_WIDTH, MBAR_HEIGHT, GNOT) ;
-
- make_switch(SCAN_WIDTH-150, 0*SWITCH_HEIGHT+40,
- "Mode", "Line Art", "Halftone") ;
- make_switch(SCAN_WIDTH-150, 1*SWITCH_HEIGHT+40,
- "Data Transfer", "Uncompressed", "Compressed") ;
- make_switch(SCAN_WIDTH-150, 2*SWITCH_HEIGHT+40,
- "Serial Port", "A", "B") ;
- make_switch(SCAN_WIDTH-150, 3*SWITCH_HEIGHT+40,
- "Baud Rate", "9600", "19200") ;
-
- for (i = 0; i < 4; i++)
- set_switch(SCAN_WIDTH-150, i*SWITCH_HEIGHT+50+switches[i]*20, ON) ;
-
- if (scanning)
- make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_INVERT) ;
- else make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_NORMAL) ;
-
- make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_NORMAL) ;
-
- if (showing)
- make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_INVERT) ;
- else make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_NORMAL) ;
-
- draw_scanning_frame(SCAN_FRAME_X, SCAN_FRAME_Y) ;
-
- switch ((int) drawstate)
- {
- case DO_NOTHING : break ;
- case DO_PICNAME : draw_picarea() ;
- break ;
- case DO_MESSAGE : make_message() ;
- break ;
- case DO_HELP : get_help() ;
- break ;
- case DO_SETTINGS : draw_settings() ;
- }
- }
-
-
- draw_frame(x, y, width, height)
- int x, y, width, height ;
- {
- draw_area(x, y, width, height, GSET) ;
- draw_area(x+1, y+1, width-2, height-2, GCLR) ;
- draw_area(x+3, y+3, width-6, height-6, GSET) ;
- draw_area(x+5, y+5, width-10, height-10, GCLR) ;
- }
-
-
- draw_picarea()
- {
- char dummy[MAXLINE] ;
- int nochars, x, y ;
-
- x = (SCAN_WIDTH - 500) / 2 ;
- y = (SCAN_HEIGHT - 50) / 2 ;
- draw_frame(x, y, 500, 50) ;
- draw_text(x + 10, y + 27, STEN_OFF, BFONT, "Name:") ;
- draw_rect(x + 70, y + 10, x + 265, y + 35, GSET) ;
- nochars = (strlen(picname) <= 20) ? strlen(picname) : 20 ;
- STRNCPY(dummy, &picname[strlen(picname) - nochars], nochars) ;
- dummy[nochars] = '\0' ;
- draw_text(x + 80, y + 27, STEN_OFF, BFONT, dummy) ;
- draw_line(x + 80 + get_strwidth(BFONT, dummy), y + 15,
- x + 80 + get_strwidth(BFONT, dummy), y + 30, GSET) ;
- make_button(x + 300, y + 10, "OK", B_NORMAL) ;
- make_button(x + 400, y + 10, "Cancel", B_NORMAL) ;
- drawstate = DO_PICNAME ;
- butx = x ;
- buty = y ;
- }
-
-
- draw_rect(x1, y1, x2, y2, op)
- int x1, y1, x2, y2 ;
- enum op_type op ;
- {
- draw_line(x1, y1, x2, y1, op) ;
- draw_line(x1, y1, x1, y2, op) ;
- draw_line(x2, y1, x2, y2, op) ;
- draw_line(x1, y2, x2, y2, op) ;
- }
-
-
- draw_scanning_frame(x, y) /* Draw the current scanning frame. */
- int x, y ;
- {
- char number[3] ;
- int i ;
-
- for (i = 0; i <= 35; i++) /* Draw horizontal rule. */
- if (!(i % 4))
- {
- SPRINTF(number, "%1d", i / 4) ;
- draw_text(x+i*LINEGAP+2, y-15, STEN_ON, NFONT, number) ;
- draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-26, GSET) ;
- }
- else if (!(i % 2))
- draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-18, GSET) ;
- else draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-14, GSET) ;
-
- draw_line(x, y-10, x+36*LINEGAP, y-10, GSET) ;
-
- for (i = 0; i <= 45; i++) /* Draw vertical rule. */
- if (!(i % 4))
- {
- SPRINTF(number, "%1d", i / 4) ;
- draw_text(x-26, y+i*LINEGAP+12, STEN_ON, NFONT, number) ;
- draw_line(x-10, y+i*LINEGAP, x-26, y+i*LINEGAP, GSET) ;
- }
- else if (!(i % 2))
- draw_line(x-10, y+i*LINEGAP, x-18, y+i*LINEGAP, GSET) ;
- else draw_line(x-10, y+i*LINEGAP, x-14, y+i*LINEGAP, GSET) ;
-
- draw_line(x-10, y, x-10, y+46*LINEGAP, GSET) ;
-
- /* Initial page frame. */
- draw_rect(x, y, x+34*LINEGAP, y+44*LINEGAP, GSET) ;
- draw_rect(x+1, y+1, x+34*LINEGAP+1, y+44*LINEGAP+1, GSET) ;
-
- /* Make gray surrondings. */
- draw_line(x, y+44*LINEGAP, x, SCAN_HEIGHT, GSET) ;
- draw_line(x+34*LINEGAP, y,x+36*LINEGAP, y, GSET) ;
- draw_line(x+36*LINEGAP, y-26,x+36*LINEGAP, SCAN_HEIGHT, GSET) ;
- grey_area(x+1, y+44*LINEGAP+2, 36*LINEGAP-1, 2*LINEGAP-2) ;
- grey_area(x+LINEGAP*34+2, y+1, 2*LINEGAP-2, SCAN_HEIGHT-65) ;
-
- /* Draw initial scanning frame. */
- draw_rect(x+framevals[X1]*FRAMEGAP, y+framevals[Y1]*FRAMEGAP,
- x+framevals[X2]*FRAMEGAP, y+framevals[Y2]*FRAMEGAP, GSET) ;
- }
-
-
- get_picname() /* Get new picture name. */
- {
- char c, dummy[MAXLINE] ;
- int finished, nochars, state ;
-
- finished = 0 ;
- if (type == LEFT_DOWN)
- {
- if (curx > butx+300 && curx < butx+300+BUTTON_WIDTH &&
- cury > buty+10 && cury < buty+10+BUTTON_HEIGHT)
- {
- make_button(butx+300, buty+10, "OK", B_INVERT) ;
- state = OK ;
- finished = 1 ;
-