home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / func / text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  3.1 KB  |  149 lines

  1. /*
  2.  * text.c -- routine for dealing with annotation text
  3.  *
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "ui.h"
  8. #include "common.h"
  9. #include "llist.h"
  10. #include "sm.h"
  11. #include "log.h"
  12. #include "reg.h"
  13. #include "display.h"
  14.  
  15. static char cbuf[256];
  16. static int nchar = 0;
  17.  
  18. struct plist *getcpl();
  19.  
  20. /*********************************************/
  21. draw_text(reg)
  22.     struct region *reg;
  23. {
  24.     unsigned  blank;
  25.  
  26.     printf(" in draw_text \n");
  27.  
  28.     reg->r_sbs = (struct strbs *) malloc(sizeof(struct strbs));
  29.     reg->r_sbs->string = NULL;
  30.  
  31.     if (nchar > 0) {
  32.     reg->r_sbs->string = (char *) malloc(nchar + 1);
  33.     strcpy(reg->r_sbs->string, cbuf);
  34.     }
  35.     reg->r_sbs->x = reg->r_plist->pt.x;
  36.     reg->r_sbs->y = reg->r_plist->pt.y;
  37.  
  38.     if (nchar > 0) {
  39.     XTextExtents(xfs, reg->r_sbs->string, strlen(reg->r_sbs->string),
  40.              &blank, &blank, &blank, ®->r_sbs->metr);
  41.  
  42.     draw_text_string(reg);
  43.     }
  44. }
  45.  
  46. /*********************************************/
  47. draw_text_string(reg)
  48.     struct region *reg;
  49. {
  50.     if (reg->r_sbs == NULL || reg->r_plist == NULL)
  51.     return;
  52.  
  53.     printf("drawing string: %s  at (%d,%d) \n",
  54.        reg->r_sbs->string, reg->r_sbs->x, reg->r_sbs->y);
  55. #ifdef DEBUG
  56. #endif
  57.  
  58.     XSetForeground(display, gc, standout);
  59.     XDrawString(display, img_win->d_xid, gc, reg->r_sbs->x, reg->r_sbs->y,
  60.         reg->r_sbs->string, strlen(reg->r_sbs->string));
  61. }
  62.  
  63. /*****************************************************/
  64.  
  65. text_reset(reg)
  66.     struct region *reg;
  67. {
  68.     bzero(cbuf, nchar);
  69.     nchar = 0;
  70.     flush_cpl(reg);
  71. }
  72.  
  73. /*********************************************/
  74. add_char(c)
  75.     char      c;
  76. {
  77.     struct plist *pl;
  78.  
  79.     if (getrtype() != AN_TEXT)
  80.     return;
  81.     if (getnpoints() < 1 && pl == NULL)
  82.     return;
  83.  
  84.     if ((pl = getcpl()) == NULL)
  85.     return;
  86.  
  87.     if (nchar > 255) {
  88.     fprintf(stderr, "character buffer overflow!\n");
  89.     nchar = 0;
  90.     return;
  91.     }
  92.     if (c == '\n' || c == '\r') {
  93.     /* implict eval */
  94.     state_dispatch(EVAL, NULL);
  95.     return;
  96.     }
  97.     if (c == '\b' || c == 0x7f) {
  98.     if (nchar > 0) {
  99.         XPutImage(display, img_win->d_xid, gc, orig_ximg, pl->cb.top.x,
  100.               pl->cb.top.y, pl->cb.top.x, pl->cb.top.y,
  101.               (strlen(cbuf) + 1) * 9, 30);
  102.         cbuf[--nchar] = 0;
  103.     }
  104.     } else
  105.     cbuf[nchar++] = c;
  106.  
  107.     XSetForeground(display, gc, standout);
  108.     XDrawString(display, img_win->d_xid, gc, pl->pt.x, pl->pt.y,
  109.         cbuf, strlen(cbuf));
  110. }
  111.  
  112. /*********************************************/
  113. /* used for loading in text from the log. Works just like a bunch of
  114.    succesive add_char() operations, except that: there is no del or
  115.    backspace processing, newline does not cause a state transition,
  116.    and this is more efficient */
  117. add_string(s)
  118.     char     *s;
  119. {
  120.  
  121. #ifdef DEBUG
  122.     printf("String:%s\n", s);
  123. #endif
  124.     if (getrtype() != AN_TEXT)
  125.     return;
  126.     if (getnpoints() < 1)
  127.     return;
  128.  
  129.     strcpy(cbuf, s);
  130.     nchar = strlen(cbuf) + 1;
  131. }
  132.  
  133. /*********************************************/
  134. set_string(s)
  135.     char     *s;
  136. {
  137.     strcpy(cbuf, s);
  138.     nchar = strlen(s) + 1;
  139.  
  140.     fprintf(stderr, "setting nchar to %d \n", nchar);
  141. }
  142.  
  143. /*****************************************************/
  144. char     *
  145. get_string()
  146. {
  147.     return (cbuf);
  148. }
  149.