home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_GRCHAR.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  12.0 KB  |  393 lines

  1. STATIC entry_scr := '', graph_col := 0, graph_row := 0,    ;
  2.        graph_set := 0, graph_on, graphics[11], pointer := 1
  3.  
  4. ****************************************************************
  5. FUNCTION GRAPHCHAR
  6. ****************************************************************
  7. *
  8. * Allows entry of graphics characters during a read or memoedit
  9. *
  10. * Copyright(c) 1991 - James Occhiogrosso
  11.  
  12. #include "dl_keys.ch"
  13. #include "set.ch"
  14. #include "inkey.ch"
  15. #include "setcurs.ch"
  16.  
  17. * Last graphic set defined
  18. # define LASTGRSET  7
  19.  
  20. LOCAL  init_row, init_col, init_scr, keypress, old_color,  ;
  21.        old_score, old_cursor
  22.  
  23. * Save entry conditions
  24. old_color  = SETCOLOR(colwindow)
  25. old_score  = SET(_SET_SCOREBOARD, .F.)
  26. old_cursor = SET(_SET_CURSOR, SC_NONE)
  27. init_row = ROW() ; init_col = COL()
  28.  
  29. * Test for array initialization
  30. IF graph_on = NIL
  31.     * Load graphics array
  32.     graph_on = .T.
  33.     LOADARRAY()
  34. ELSE
  35.     * Otherwise, toggle it
  36.     graph_on = !graph_on
  37. ENDIF
  38.  
  39.  
  40. IF graph_on
  41.  
  42.     * This is first time, set default graphic box position
  43.  
  44.     IF init_row < INT(MAXROW()/2) .AND. init_col < INT(MAXCOL()/2)
  45.         graph_row = INT(MAXROW()-8)
  46.         graph_col = INT(MAXCOL()-12)
  47.     ELSEIF init_row < INT(MAXROW()/2) .AND. init_col >= INT(MAXCOL()/2)
  48.         graph_row = INT(MAXROW()-8)
  49.         graph_col = 0
  50.     ELSEIF init_row >= INT(MAXROW()/2) .AND. init_col < INT(MAXCOL()/2)
  51.         graph_row = 0
  52.         graph_col = INT(MAXCOL()-12)
  53.     ELSEIF init_row >= INT(MAXROW()/2) .AND. init_col >= INT(MAXCOL()/2)
  54.         graph_row = 0
  55.         graph_col = 0
  56.     ENDIF
  57.  
  58.     * Save the screen area we are going to use
  59.     entry_scr = SCRNSAVE(graph_row, graph_col, ;
  60.                          graph_row + 8, graph_col + 12)
  61.  
  62.     * Let operator move box
  63.     MOVEBLOCK()
  64.  
  65.     * When box is positioned, turn on the key definitions
  66.  
  67.     SET KEY K_PLUS   TO PROCESSKEY
  68.     SET KEY K_MINUS  TO PROCESSKEY
  69.     SET KEY K_ZERO   TO PROCESSKEY
  70.     SET KEY K_ONE    TO PROCESSKEY
  71.     SET KEY K_TWO    TO PROCESSKEY
  72.     SET KEY K_THREE  TO PROCESSKEY
  73.     SET KEY K_FOUR   TO PROCESSKEY
  74.     SET KEY K_FIVE   TO PROCESSKEY
  75.     SET KEY K_SIX    TO PROCESSKEY
  76.     SET KEY K_SEVEN  TO PROCESSKEY
  77.     SET KEY K_EIGHT  TO PROCESSKEY
  78.     SET KEY K_NINE   TO PROCESSKEY
  79.     SET KEY K_PERIOD TO PROCESSKEY
  80.  
  81.     * Display graphics key set
  82.     SHOWBLOCK()
  83.  
  84. ELSE
  85.     * Restore entry screen
  86.     SCRNREST(entry_scr)
  87.  
  88.     * Turn off all key definitions
  89.  
  90.     SET KEY K_PLUS   TO
  91.     SET KEY K_MINUS  TO
  92.     SET KEY K_ZERO   TO
  93.     SET KEY K_ONE    TO
  94.     SET KEY K_TWO    TO
  95.     SET KEY K_THREE  TO
  96.     SET KEY K_FOUR   TO
  97.     SET KEY K_FIVE   TO
  98.     SET KEY K_SIX    TO
  99.     SET KEY K_SEVEN  TO
  100.     SET KEY K_EIGHT  TO
  101.     SET KEY K_NINE   TO
  102.     SET KEY K_PERIOD TO
  103.  
  104. ENDIF
  105.  
  106. * Restore to entry conditions and return
  107. SETCOLOR(old_color)
  108. SET SCOREBOARD (old_score)
  109. SETCURSOR(old_cursor)
  110. @ init_row, init_col SAY ''
  111.  
  112. RETURN NIL
  113.  
  114.  
  115. *****************************************************************
  116. STATIC FUNCTION PROCESSKEY
  117. *****************************************************************
  118.  
  119. * Process keystrokes
  120.  
  121.  
  122. LOCAL init_row, init_col, keypress, old_color
  123.  
  124. init_row = ROW()
  125. init_col = COL()
  126. old_color = SETCOLOR(colwindow)
  127. keypress = LASTKEY()
  128.  
  129. IF keypress = K_PLUS .OR. keypress = K_MINUS
  130.  
  131.     * Change graphics character set
  132.  
  133.     IF graph_set < LASTGRSET .AND. keypress = K_PLUS
  134.         graph_set++
  135.     ELSEIF graph_set > 0 .AND. keypress = K_MINUS
  136.         graph_set--
  137.     ELSEIF graph_set = 0 .AND. keypress = K_MINUS
  138.         graph_set = LASTGRSET
  139.     ELSE
  140.         graph_set = 0
  141.     ENDIF
  142.  
  143.     * Load new graphics set
  144.     LOADARRAY()
  145.  
  146.     * Display new graphics set
  147.     SHOWBLOCK()
  148. ELSE
  149.     * Generate pointer to graphics array element
  150.  
  151.     IF keypress >= K_ONE .AND. keypress <= K_NINE
  152.         * Subtract 48 from ACSII value of Keys 1 through 9
  153.         pointer = keypress - 48
  154.     ELSEIF keypress = K_ZERO
  155.         * Zero key is 10th element
  156.         pointer = 10
  157.     ELSEIF keypress = K_PERIOD
  158.         * Period key is 11th element
  159.         pointer = 11
  160.     ENDIF
  161.  
  162.     * Stuff selected character in keyboard buffer
  163.     KEYBOARD graphics[pointer]
  164. ENDIF
  165.  
  166. * Restore color and cursor position and return
  167. SETCOLOR(old_color)
  168.  
  169. @ init_row, init_col SAY ''
  170.  
  171. RETURN NIL
  172.  
  173.  
  174. ****************************************************************
  175. STATIC FUNCTION LOADARRAY
  176. ****************************************************************
  177.  
  178. * Load graphics array
  179.  
  180. IF graph_set = 0
  181.    graphics[1]  = CHR(200)   &&
  182.    graphics[2]  = CHR(202)   &&    Double line
  183.    graphics[3]  = CHR(188)   &&   ┌───┬───┬───┐
  184.    graphics[4]  = CHR(204)   &&   │ ╔ │ ╦ │ ╗ │
  185.    graphics[5]  = CHR(206)   &&   ├───┼───┼───┤
  186.    graphics[6]  = CHR(185)   &&   │ ╠ │ ╬ │ ╣ │
  187.    graphics[7]  = CHR(201)   &&   ├───┼───┼───┤
  188.    graphics[8]  = CHR(203)   &&   │ ╚ │ ╩ │ ╝ │
  189.    graphics[9]  = CHR(187)   &&   ├───┴───┼───┤
  190.    graphics[10] = CHR(205)   &&   │   ═   │ ║ │
  191.    graphics[11] = CHR(186)   &&   └───────┴───┘
  192.  
  193. ELSEIF graph_set = 1
  194.  
  195.    graphics[1]  = CHR(192)   &&
  196.    graphics[2]  = CHR(193)   &&    Single line
  197.    graphics[3]  = CHR(217)   &&   ┌───┬───┬───┐
  198.    graphics[4]  = CHR(195)   &&   │ ┌ │ ┬ │ ┐ │
  199.    graphics[5]  = CHR(197)   &&   ├───┼───┼───┤
  200.    graphics[6]  = CHR(180)   &&   │ ├ │ ┼ │ ┤ │
  201.    graphics[7]  = CHR(218)   &&   ├───┼───┼───┤
  202.    graphics[8]  = CHR(194)   &&   │ └ │ ┴ │ ┘ │
  203.    graphics[9]  = CHR(191)   &&   ├───┴───┼───┤
  204.    graphics[10] = CHR(196)   &&   │   ─   │ │ │
  205.    graphics[11] = CHR(179)   &&   └───────┴───┘
  206.  
  207.  
  208. ELSEIF graph_set = 2
  209.  
  210.    graphics[1]  = CHR(211)   &&      Double
  211.    graphics[2]  = CHR(208)   &&     vertical
  212.    graphics[3]  = CHR(189)   &&   ┌───┬───┬───┐
  213.    graphics[4]  = CHR(199)   &&   │ ╓ │ ╥ │ ╖ │
  214.    graphics[5]  = CHR(215)   &&   ├───┼───┼───┤
  215.    graphics[6]  = CHR(182)   &&   │ ╟ │ ╫ │ ╢ │
  216.    graphics[7]  = CHR(214)   &&   ├───┼───┼───┤
  217.    graphics[8]  = CHR(210)   &&   │ ╙ │ ╨ │ ╜ │
  218.    graphics[9]  = CHR(183)   &&   ├───┴───┼───┤
  219.    graphics[10] = CHR(196)   &&   │   ─   │ ║ │
  220.    graphics[11] = CHR(186)   &&   └───────┴───┘
  221.  
  222. ELSEIF graph_set = 3
  223.  
  224.    graphics[1]  = CHR(212)   &&      Single
  225.    graphics[2]  = CHR(207)   &&     vertical
  226.    graphics[3]  = CHR(190)   &&   ┌───┬───┬───┐
  227.    graphics[4]  = CHR(198)   &&   │ ╒ │ ╤ │ ╕ │
  228.    graphics[5]  = CHR(216)   &&   ├───┼───┼───┤
  229.    graphics[6]  = CHR(181)   &&   │ ╞ │ ╪ │ ╡ │
  230.    graphics[7]  = CHR(213)   &&   ├───┼───┼───┤
  231.    graphics[8]  = CHR(209)   &&   │ ╘ │ ╧ │ ╛ │
  232.    graphics[9]  = CHR(184)   &&   ├───┴───┼───┤
  233.    graphics[10] = CHR(205)   &&   │   ═   │ │ │
  234.    graphics[11] = CHR(179)   &&   └───────┴───┘
  235.  
  236. ELSEIF graph_set = 4
  237.  
  238.    graphics[1]  = CHR(221)   &&   Miscellaneous
  239.    graphics[2]  = CHR(222)   &&      Symbols
  240.    graphics[3]  = CHR(254)   &&   ┌───┬───┬───┐
  241.    graphics[4]  = CHR(219)   &&   │ ░ │ ▒ │ ▓ │
  242.    graphics[5]  = CHR(220)   &&   ├───┼───┼───┤
  243.    graphics[6]  = CHR(223)   &&   │ █ │ ▄ │ ▀ │
  244.    graphics[7]  = CHR(176)   &&   ├───┼───┼───┤
  245.    graphics[8]  = CHR(177)   &&   │ ▌ │ ▐ │ ■ │
  246.    graphics[9]  = CHR(178)   &&   ├───┴───┼───┤
  247.    graphics[10] = CHR(174)   &&   │   »   │ « │
  248.    graphics[11] = CHR(175)   &&   └───────┴───┘
  249.  
  250. ELSEIF graph_set = 5
  251.  
  252.    graphics[1]  = CHR(252)   &&   Miscellaneous
  253.    graphics[2]  = CHR(253)   &&      Symbols
  254.    graphics[3]  = CHR(172)   &&   ┌───┬───┬───┐
  255.    graphics[4]  = CHR(246)   &&   │ ± │ ≥ │ ≤ │
  256.    graphics[5]  = CHR(251)   &&   ├───┼───┼───┤
  257.    graphics[6]  = CHR(171)   &&   │ ÷ │ √ │ ½ │
  258.    graphics[7]  = CHR(241)   &&   ├───┼───┼───┤
  259.    graphics[8]  = CHR(242)   &&   │ ⁿ │ ² │ ¼ │
  260.    graphics[9]  = CHR(243)   &&   ├───┴───┼───┤
  261.    graphics[10] = CHR(155)   &&   │   ¢   │ £ │
  262.    graphics[11] = CHR(156)   &&   └───────┴───┘
  263.  
  264. ELSEIF graph_set = 6
  265.  
  266.    graphics[1]  = CHR(224)   &&    Miscellaneous 
  267.    graphics[2]  = CHR(225)   &&       Symbols
  268.    graphics[3]  = CHR(226)   &&    ┌───┬───┬───┐
  269.    graphics[4]  = CHR(227)   &&    │ α │ ß │ Γ │
  270.    graphics[5]  = CHR(228)   &&    ├───┼───┼───┤
  271.    graphics[6]  = CHR(229)   &&    │ π │ Σ │ σ │
  272.    graphics[7]  = CHR(230)   &&    ├───┼───┼───┤
  273.    graphics[8]  = CHR(231)   &&    │ µ │ τ │ Φ │
  274.    graphics[9]  = CHR(232)   &&    ├───┴───┼───┤
  275.    graphics[10] = CHR(233)   &&    │   Θ   │ Ω │
  276.    graphics[11] = CHR(234)   &&    └───────┴───┘
  277.  
  278. ELSEIF graph_set = 7
  279.  
  280.    graphics[1]  = CHR(235)   &&    Miscellaneous 
  281.    graphics[2]  = CHR(236)   &&       Symbols
  282.    graphics[3]  = CHR(237)   &&    ┌───┬───┬───┐
  283.    graphics[4]  = CHR(238)   &&    │ δ │ ∞ │ φ │
  284.    graphics[5]  = CHR(239)   &&    ├───┼───┼───┤
  285.    graphics[6]  = CHR(247)   &&    │ ε │ ∩ │ ≈ │
  286.    graphics[7]  = CHR(244)   &&    ├───┼───┼───┤
  287.    graphics[8]  = CHR(245)   &&    │ ⌠ │ ⌡ │ ° │
  288.    graphics[9]  = CHR(248)   &&    ├───┴───┼───┤
  289.    graphics[10] = CHR(249)   &&    │   ∙   │  │
  290.    graphics[11] = CHR(127)   &&    └───────┴───┘
  291.  
  292. ENDIF
  293.  
  294. RETURN NIL
  295.  
  296.  
  297. ****************************************************************
  298. STATIC FUNCTION SHOWBLOCK
  299. ****************************************************************
  300.  
  301. * Display selected graphics set
  302.  
  303. @ graph_row + 1, graph_col + 2  SAY graphics[7]
  304. @ graph_row + 1, graph_col + 6  SAY graphics[8]
  305. @ graph_row + 1, graph_col + 10 SAY graphics[9]
  306. @ graph_row + 3, graph_col + 2  SAY graphics[4]
  307. @ graph_row + 3, graph_col + 6  SAY graphics[5]
  308. @ graph_row + 3, graph_col + 10 SAY graphics[6]
  309. @ graph_row + 5, graph_col + 2  SAY graphics[1]
  310. @ graph_row + 5, graph_col + 6  SAY graphics[2]
  311. @ graph_row + 5, graph_col + 10 SAY graphics[3]
  312. @ graph_row + 7, graph_col + 4  SAY graphics[10]
  313. @ graph_row + 7, graph_col + 10 SAY graphics[11]
  314.  
  315. RETURN NIL
  316.  
  317.  
  318. ****************************************************************
  319. STATIC FUNCTION MOVEBLOCK
  320. ****************************************************************
  321.  
  322. * Let operator position the graph box on initial entry
  323.  
  324. LOCAL init_scr, keypress
  325.  
  326. * Display initial box at default area
  327.  
  328. @ graph_row,     graph_col SAY '┌───────────┐'
  329. @ graph_row + 1, graph_col SAY '│Cursor keys│'
  330. @ graph_row + 2, graph_col SAY '│move box.  │'
  331. @ graph_row + 3, graph_col SAY '│Any key for│'
  332. @ graph_row + 4, graph_col SAY '│graphics.  │'
  333. @ graph_row + 5, graph_col SAY '│Use +/- to │'
  334. @ graph_row + 6, graph_col SAY '│change key │'
  335. @ graph_row + 7, graph_col SAY '│set.       │'
  336. @ graph_row + 8, graph_col SAY '└───────────┘'
  337.  
  338. init_scr  = SAVESCREEN(graph_row, graph_col, ;
  339.                        graph_row + 8, graph_col + 12)
  340.  
  341. DO WHILE .T.
  342.    * Wait for a key
  343.    keypress = INKEY(0)
  344.  
  345.    * Restore entry screen before moving box
  346.    SCRNREST(entry_scr)      
  347.  
  348.    IF keypress = K_RIGHT
  349.        graph_col = IF(graph_col < INT(MAXCOL()-12), graph_col + 1, INT(MAXCOL()-12))
  350.    ELSEIF keypress = K_LEFT
  351.        graph_col = IF(graph_col > 1, graph_col - 1, 0)
  352.    ELSEIF keypress = K_UP
  353.        graph_row = IF(graph_row > 0, graph_row - 1, 0)
  354.    ELSEIF keypress = K_DOWN
  355.        graph_row = IF(graph_row < INT(MAXROW()-8), graph_row + 1, INT(MAXROW()-8))
  356.    ELSEIF keypress = K_CTRL_RIGHT
  357.        graph_col = INT(MAXCOL()-12)
  358.    ELSEIF keypress = K_CTRL_LEFT
  359.        graph_col = 0
  360.    ELSEIF keypress = K_CTRL_UP
  361.        graph_row = 0
  362.    ELSEIF keypress = K_CTRL_DOWN
  363.        graph_row = INT(MAXROW()-8)
  364.    ELSE
  365.        * Any other key, exit and display graphics box.
  366.        EXIT
  367.    ENDIF
  368.  
  369.    * Save new entry screen area
  370.    entry_scr = SCRNSAVE(graph_row, graph_col, ;
  371.                         graph_row + 8, graph_col + 12)
  372.  
  373.    * And redisplay initial box in new position
  374.    RESTSCREEN(graph_row, graph_col, graph_row + 8,;
  375.               graph_col + 12, init_scr)
  376. ENDDO
  377.  
  378. * When box is positioned, display graphics outline
  379.  
  380. @ graph_row,     graph_col SAY '┌───┬───┬───┐'
  381. @ graph_row + 1, graph_col SAY '│   │   │   │'
  382. @ graph_row + 2, graph_col SAY '├───┼───┼───┤'
  383. @ graph_row + 3, graph_col SAY '│   │   │   │'
  384. @ graph_row + 4, graph_col SAY '├───┼───┼───┤'
  385. @ graph_row + 5, graph_col SAY '│   │   │   │'
  386. @ graph_row + 6, graph_col SAY '├───┴───┼───┤'
  387. @ graph_row + 7, graph_col SAY '│       │   │'
  388. @ graph_row + 8, graph_col SAY '└───────┴───┘'
  389.  
  390. RETURN NIL
  391.  
  392.  
  393.