home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / may94 / util / edit / jade.lha / Jade / src / x11_render.c < prev    next >
C/C++ Source or Header  |  1994-04-19  |  7KB  |  242 lines

  1. /* x11_render.c -- Rendering for X11
  2.    Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. This file is part of Jade.
  5.  
  6. Jade is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Jade is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Jade; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "jade.h"
  21. #include "jade_protos.h"
  22.  
  23. _PR void drawmsgsepline(VW *);
  24. _PR void drawmsg(VW *, u_char *, int);
  25. _PR void redrawcmdline(VW *, u_char *, u_char *, long, long);
  26. _PR void redrawcmdlinefrom(VW *, u_char *, u_char *, long, long, long);
  27. _PR void restorecmdline(VW *);
  28. _PR void cmdlncursor(VW *, bool);
  29. _PR void handlegexposures(VW *);
  30. _PR void handleexpose(VW *, XExposeEvent *);
  31. _PR void scrollvw(VW *, long);
  32.  
  33. void
  34. drawmsgsepline(VW *vw)
  35. {
  36.     XDrawLine(XDisplay, vw->vw_Window, vw->vw_WindowSys.ws_TextFontGC,
  37.           vw->vw_XStartPix, vw->vw_WindowSys.ws_MessageLineY,
  38.           vw->vw_XEndPix, vw->vw_WindowSys.ws_MessageLineY);
  39. }
  40. void
  41. drawmsg(VW *vw, u_char *str, int len)
  42. {
  43.     if(len >= vw->vw_MaxX)
  44.     len = vw->vw_MaxX - 1;
  45.     XDrawImageString(XDisplay, vw->vw_Window, vw->vw_WindowSys.ws_TextFontGC,
  46.              vw->vw_XStartPix, vw->vw_WindowSys.ws_MessageFontY, str,
  47.              len);
  48.     if(len != vw->vw_MaxX - 1)
  49.     {
  50.     XClearArea(XDisplay, vw->vw_Window,
  51.            vw->vw_XStartPix + (len * vw->vw_FontX),
  52.            vw->vw_WindowSys.ws_MessageFontY - vw->vw_Font->ascent, 0,
  53.            vw->vw_FontY, False);
  54.     }
  55. }
  56.  
  57. /*
  58.  */
  59. void
  60. redrawcmdline(VW *vw, u_char *prompt, u_char *cmdLine, long promptLen, long cmdLen)
  61. {
  62.     vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY - vw->vw_Font->ascent;
  63.     CLR_AREA(vw, vw->vw_XStartPix, vw->vw_WindowSys.ws_PenY,
  64.          vw->vw_XEndPix - 1, vw->vw_WindowSys.ws_PenY + vw->vw_FontY - 1);
  65.     vw->vw_WindowSys.ws_PenX = vw->vw_XStartPix;
  66.     vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY;
  67.     drawbit(vw, P_TEXT, prompt, 100000, 0, promptLen + 1);
  68.     drawbit(vw, P_TEXT, cmdLine - promptLen, 100000, promptLen,
  69.         cmdLen + promptLen + 1);
  70. }
  71.  
  72. void
  73. redrawcmdlinefrom(VW *vw, u_char *prompt, u_char *cmdLine, long promptLen, long cmdLen, long startPos)
  74. {
  75.     vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY - vw->vw_Font->ascent;
  76.     if(startPos < vw->vw_StartCol)
  77.     startPos = vw->vw_StartCol;
  78.     if(startPos < (vw->vw_StartCol + vw->vw_MaxX))
  79.     {
  80.     int xord = vw->vw_XStartPix + (startPos * vw->vw_FontX);
  81.     CLR_AREA(vw, xord, vw->vw_WindowSys.ws_PenY, vw->vw_XEndPix - xord,
  82.           vw->vw_FontY);
  83.     vw->vw_WindowSys.ws_PenX = xord;
  84.     vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY;
  85.     if(startPos < promptLen)
  86.     {
  87.         drawbit(vw, P_TEXT, prompt, 100000, startPos, promptLen + 1);
  88.         drawbit(vw, P_TEXT, cmdLine - promptLen, 100000, promptLen,
  89.             cmdLen + promptLen + 1);
  90.     }
  91.     else
  92.         drawbit(vw, P_TEXT, cmdLine - promptLen, 100000, startPos,
  93.             cmdLen + promptLen + 1);
  94.     }
  95. }
  96.  
  97. /*
  98.  * draws the cursor for the command line
  99.  */
  100. void
  101. cmdlncursor(VW *vw, bool status)
  102. {
  103.     GC cursgc;
  104.     if(status == CURS_ON)
  105.     cursgc = vw->vw_WindowSys.ws_TextFontGC;
  106.     else
  107.     cursgc = vw->vw_WindowSys.ws_BlkFontGC;
  108.     vw->vw_WindowSys.ws_PenX = vw->vw_XStartPix
  109.     + ((vw->vw_CursorPos.pos_Col - vw->vw_StartCol) * vw->vw_FontX);
  110.     vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY
  111.     - vw->vw_Font->ascent;
  112.     XFillRectangle(XDisplay, vw->vw_Window, cursgc, vw->vw_WindowSys.ws_PenX,
  113.            vw->vw_WindowSys.ws_PenY, vw->vw_FontX, vw->vw_FontY);
  114. }
  115.  
  116. static Bool
  117. gexpred(Display *dpy, XEvent *ev, XPointer arg)
  118. {
  119.     return((ev->type == NoExpose) || (ev->type == GraphicsExpose));
  120. }
  121. void
  122. handlegexposures(VW *vw)
  123. {
  124.     XEvent ev;
  125.     do {
  126.     POS start, end;
  127.     unsigned int x1, y1, x2, y2;
  128.     XIfEvent(XDisplay, &ev, gexpred, (XPointer)NULL);
  129.     if(ev.type == NoExpose)
  130.         return;
  131.     x1 = ev.xgraphicsexpose.x;
  132.     y1 = ev.xgraphicsexpose.y;
  133.     x2 = x1 + ev.xgraphicsexpose.width;
  134.     y2 = y1 + ev.xgraphicsexpose.height;
  135.     if(y2 >= vw->vw_WindowSys.ws_MessageLineY)
  136.     {
  137.         y2 = vw->vw_WindowSys.ws_MessageLineY - 1;
  138.         drawmsgsepline(vw);
  139.         if(vw->vw_LastTitle)
  140.         drawmsg(vw, vw->vw_LastTitle, strlen(vw->vw_LastTitle));
  141.         else
  142.         drawmsg(vw, "", 0);
  143.         if(y1 >= vw->vw_WindowSys.ws_MessageLineY)
  144.         continue;
  145.     }
  146.     start.pos_Col = ((x1 - vw->vw_XStartPix) / vw->vw_FontX)
  147.         + vw->vw_StartCol;
  148.     start.pos_Line = ((y1 - vw->vw_YStartPix) / vw->vw_FontY)
  149.         + vw->vw_StartLine;
  150.     end.pos_Col = (((x2 - 1)- vw->vw_XStartPix) / vw->vw_FontX)
  151.         + vw->vw_StartCol;
  152.     end.pos_Line = (((y2 - 1) - vw->vw_YStartPix) / vw->vw_FontY)
  153.         + vw->vw_StartLine;
  154.     redrawrect(vw, &start, &end, FALSE);
  155.     } while(ev.xgraphicsexpose.count > 0);
  156. }
  157.  
  158. void
  159. handleexpose(VW *vw, XExposeEvent *ev)
  160. {
  161.     POS start, end;
  162.     unsigned int x1, y1, x2, y2;
  163.     x1 = ev->x;
  164.     y1 = ev->y;
  165.     x2 = x1 + ev->width;
  166.     y2 = y1 + ev->height;
  167.     if(y2 >= vw->vw_WindowSys.ws_MessageLineY)
  168.     {
  169.     y2 = vw->vw_WindowSys.ws_MessageLineY - 1;
  170.     drawmsgsepline(vw);
  171.     if(vw->vw_LastTitle)
  172.         drawmsg(vw, vw->vw_LastTitle, strlen(vw->vw_LastTitle));
  173.     else
  174.         drawmsg(vw, "", 0);
  175.     if(y1 >= vw->vw_WindowSys.ws_MessageLineY)
  176.         return;
  177.     }
  178.     /*
  179.      * Special case of whole window being redrawn
  180.      */
  181.     if((x1 == 0) && (y1 == 0) && (x2 >= vw->vw_XEndPix)
  182.        && (y2 >= (vw->vw_WindowSys.ws_MessageLineY - 1)))
  183.     redrawall(vw);
  184.     else
  185.     {
  186.     start.pos_Col = ((x1 - vw->vw_XStartPix) / vw->vw_FontX)
  187.         + vw->vw_StartCol;
  188.     start.pos_Line = ((y1 - vw->vw_YStartPix) / vw->vw_FontY)
  189.         + vw->vw_StartLine;
  190.     end.pos_Col = (((x2 - 1)- vw->vw_XStartPix) / vw->vw_FontX)
  191.         + vw->vw_StartCol;
  192.     end.pos_Line = (((y2 - 1) - vw->vw_YStartPix) / vw->vw_FontY)
  193.         + vw->vw_StartLine;
  194.     redrawrect(vw, &start, &end, TRUE);
  195.     }
  196. }
  197.  
  198. /*
  199.  * Scrolls the view `lines' towards line 0,
  200.  */
  201. void
  202. scrollvw(VW *vw, long lines)
  203. {
  204.     int xsrc, ysrc, xwth, yht, xdst, ydst;
  205.     xsrc = vw->vw_XStartPix;
  206.     xwth = vw->vw_XWidthPix;
  207.     xdst = vw->vw_XStartPix;
  208.     if(lines > 0)
  209.     {
  210.     ysrc = vw->vw_YStartPix + (lines * vw->vw_FontY);
  211.     yht  = vw->vw_YHeightPix - (lines * vw->vw_FontY);
  212.     ydst = vw->vw_YStartPix;
  213.     XCopyArea(XDisplay, vw->vw_Window, vw->vw_Window,
  214.           vw->vw_WindowSys.ws_TextFontGC,
  215.           xsrc, ysrc,
  216.           xwth, yht,
  217.           xdst, ydst);
  218.     handlegexposures(vw);
  219.     XClearArea(XDisplay, vw->vw_Window,
  220.            xsrc, vw->vw_YStartPix + yht,
  221.            xwth, ysrc - ydst,
  222.            False);
  223.     }
  224.     else if(lines < 0)
  225.     {
  226.     lines = 0 - lines;
  227.     ysrc = vw->vw_YStartPix;
  228.     yht  = vw->vw_YHeightPix - (lines * vw->vw_FontY);
  229.     ydst = vw->vw_YStartPix + (lines * vw->vw_FontY);
  230.     XCopyArea(XDisplay, vw->vw_Window, vw->vw_Window,
  231.           vw->vw_WindowSys.ws_TextFontGC,
  232.           xsrc, ysrc,
  233.           xwth, yht,
  234.           xdst, ydst);
  235.     handlegexposures(vw);
  236.     XClearArea(XDisplay, vw->vw_Window,
  237.            xsrc, ysrc,
  238.            xwth, ydst - ysrc,
  239.            False);
  240.     }
  241. }
  242.