home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3512 / graphics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-20  |  5.7 KB  |  183 lines

  1.  
  2. /*  @(#)graphics.c 1.5 90/04/10
  3.  *
  4.  *  Independent graphics routines associated with the scantool program.
  5.  *
  6.  *  Copyright (c) Rich Burridge.
  7.  *                Sun Microsystems, Australia - All rights reserved.
  8.  *
  9.  *  Permission is given to distribute these sources, as long as the
  10.  *  copyright messages are not removed, and no monies are exchanged.
  11.  *
  12.  *  No responsibility is taken for any errors or inaccuracies inherent
  13.  *  either to the comments or the code of this program, but if
  14.  *  reported to me, then an attempt will be made to fix them.
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <strings.h>
  19. #include <signal.h>
  20. #include "scantool.h"
  21. #include "scantool_extern.h"
  22.  
  23.  
  24. do_repaint()         /* Draw titleline and page layout. */
  25. {
  26.   int i ;
  27.  
  28.   draw_area(0, 0, SCAN_WIDTH, SCAN_HEIGHT, GCLR) ;
  29.   draw_text(0*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Brightness") ;
  30.   draw_text(1*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Contrast") ;
  31.   draw_text(2*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Grain") ;
  32.   draw_text(3*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Help") ;
  33.   draw_text(4*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Resolution") ;
  34.   draw_text(5*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Set") ;
  35.   draw_area(0, 0, SCAN_WIDTH, MBAR_HEIGHT, GNOT) ;
  36.  
  37.   make_switch(SCAN_WIDTH-150, 0*SWITCH_HEIGHT+40,
  38.               "Mode", "Line Art", "Halftone") ;
  39.   make_switch(SCAN_WIDTH-150, 1*SWITCH_HEIGHT+40,
  40.               "Data Transfer", "Uncompressed", "Compressed") ;
  41.   make_switch(SCAN_WIDTH-150, 2*SWITCH_HEIGHT+40,
  42.               "Serial Port", "A", "B") ;
  43.   make_switch(SCAN_WIDTH-150, 3*SWITCH_HEIGHT+40,
  44.               "Baud Rate", "9600", "19200") ;
  45.  
  46.   for (i = 0; i < 4; i++)
  47.     set_switch(SCAN_WIDTH-150, i*SWITCH_HEIGHT+50+switches[i]*20, ON) ;
  48.  
  49.   if (scanning)
  50.     make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_INVERT) ;
  51.   else make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_NORMAL) ;
  52.  
  53.   make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_NORMAL) ;
  54.  
  55.   if (showing)
  56.     make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_INVERT) ;
  57.   else make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_NORMAL) ;
  58.  
  59.   draw_scanning_frame(SCAN_FRAME_X, SCAN_FRAME_Y) ;
  60.  
  61.   switch ((int) drawstate)
  62.     {
  63.       case DO_NOTHING  : break ;
  64.       case DO_PICNAME  : draw_picarea() ;
  65.                          break ;
  66.       case DO_MESSAGE  : make_message() ;
  67.                          break ;
  68.       case DO_HELP     : get_help() ;
  69.                          break ;
  70.       case DO_SETTINGS : draw_settings() ;
  71.     }
  72. }
  73.  
  74.  
  75. draw_frame(x, y, width, height)
  76. int x, y, width, height ;
  77. {
  78.   draw_area(x,   y,   width,    height,    GSET) ;
  79.   draw_area(x+1, y+1, width-2,  height-2,  GCLR) ;
  80.   draw_area(x+3, y+3, width-6,  height-6,  GSET) ;
  81.   draw_area(x+5, y+5, width-10, height-10, GCLR) ;
  82. }
  83.  
  84.  
  85. draw_picarea()
  86. {
  87.   char dummy[MAXLINE] ;
  88.   int nochars, x, y ;
  89.  
  90.   x = (SCAN_WIDTH - 500) / 2 ;
  91.   y = (SCAN_HEIGHT - 50) / 2 ;
  92.   draw_frame(x, y, 500, 50) ;
  93.   draw_text(x + 10, y + 27, STEN_OFF, BFONT, "Name:") ;
  94.   draw_rect(x + 70, y + 10, x + 265, y + 35, GSET) ;
  95.   nochars = (strlen(picname) <= 20) ? strlen(picname) : 20 ;
  96.   STRNCPY(dummy, &picname[strlen(picname) - nochars], nochars) ;
  97.   dummy[nochars] = '\0' ;
  98.   draw_text(x + 80, y + 27, STEN_OFF, BFONT, dummy) ;
  99.   draw_line(x + 80 + get_strwidth(BFONT, dummy), y + 15,
  100.             x + 80 + get_strwidth(BFONT, dummy), y + 30, GSET) ;
  101.   make_button(x + 300, y + 10, "OK", B_NORMAL) ;
  102.   make_button(x + 400, y + 10, "Cancel", B_NORMAL) ;
  103.   drawstate = DO_PICNAME ;
  104.   butx = x ;
  105.   buty = y ;
  106. }
  107.  
  108.  
  109. draw_rect(x1, y1, x2, y2, op)
  110. int x1, y1, x2, y2 ;
  111. enum op_type op ;
  112. {
  113.   draw_line(x1, y1, x2, y1, op) ;
  114.   draw_line(x1, y1, x1, y2, op) ;
  115.   draw_line(x2, y1, x2, y2, op) ;
  116.   draw_line(x1, y2, x2, y2, op) ;
  117. }
  118.  
  119.  
  120. draw_scanning_frame(x, y)     /* Draw the current scanning frame. */
  121. int x, y ;
  122. {
  123.   char number[3] ;
  124.   int i ;
  125.  
  126.   for (i = 0; i <= 35; i++)       /* Draw horizontal rule. */
  127.     if (!(i % 4))
  128.       {
  129.         SPRINTF(number, "%1d", i / 4) ;
  130.         draw_text(x+i*LINEGAP+2, y-15, STEN_ON, NFONT, number) ;
  131.         draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-26, GSET) ;
  132.       }
  133.     else if (!(i % 2))
  134.       draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-18, GSET) ;
  135.     else draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-14, GSET) ;
  136.  
  137.   draw_line(x, y-10, x+36*LINEGAP, y-10, GSET) ;
  138.  
  139.   for (i = 0; i <= 45; i++)       /* Draw vertical rule. */
  140.     if (!(i % 4))
  141.       {
  142.         SPRINTF(number, "%1d", i / 4) ;
  143.         draw_text(x-26, y+i*LINEGAP+12, STEN_ON, NFONT, number) ;
  144.         draw_line(x-10, y+i*LINEGAP, x-26, y+i*LINEGAP, GSET) ;
  145.       }
  146.     else if (!(i % 2))
  147.       draw_line(x-10, y+i*LINEGAP, x-18, y+i*LINEGAP, GSET) ;
  148.     else draw_line(x-10, y+i*LINEGAP, x-14, y+i*LINEGAP, GSET) ;
  149.  
  150.   draw_line(x-10, y, x-10, y+46*LINEGAP, GSET) ;
  151.  
  152. /* Initial page frame. */
  153.   draw_rect(x,   y,   x+34*LINEGAP,   y+44*LINEGAP,   GSET) ;
  154.   draw_rect(x+1, y+1, x+34*LINEGAP+1, y+44*LINEGAP+1, GSET) ;
  155.  
  156. /* Make gray surrondings. */
  157.   draw_line(x, y+44*LINEGAP, x, SCAN_HEIGHT, GSET) ;
  158.   draw_line(x+34*LINEGAP, y,x+36*LINEGAP, y, GSET) ;
  159.   draw_line(x+36*LINEGAP, y-26,x+36*LINEGAP, SCAN_HEIGHT, GSET) ;
  160.   grey_area(x+1, y+44*LINEGAP+2, 36*LINEGAP-1, 2*LINEGAP-2) ;
  161.   grey_area(x+LINEGAP*34+2, y+1, 2*LINEGAP-2, SCAN_HEIGHT-65) ;
  162.  
  163. /* Draw initial scanning frame. */
  164.   draw_rect(x+framevals[X1]*FRAMEGAP, y+framevals[Y1]*FRAMEGAP,
  165.             x+framevals[X2]*FRAMEGAP, y+framevals[Y2]*FRAMEGAP, GSET) ;
  166. }
  167.  
  168.  
  169. get_picname()       /* Get new picture name. */
  170. {
  171.   char c, dummy[MAXLINE] ;
  172.   int finished, nochars, state ;
  173.  
  174.   finished = 0 ;
  175.   if (type == LEFT_DOWN)
  176.     {
  177.            if (curx > butx+300 && curx < butx+300+BUTTON_WIDTH &&
  178.                cury > buty+10  && cury < buty+10+BUTTON_HEIGHT)
  179.         {
  180.           make_button(butx+300, buty+10, "OK", B_INVERT) ;
  181.           state = OK ;
  182.           finished = 1 ;
  183.