home *** CD-ROM | disk | FTP | other *** search
- /* x11_render.c -- Rendering for X11
- Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
-
- This file is part of Jade.
-
- Jade is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- Jade is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Jade; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #include "jade.h"
- #include "jade_protos.h"
-
- _PR void drawmsgsepline(VW *);
- _PR void drawmsg(VW *, u_char *, int);
- _PR void redrawcmdline(VW *, u_char *, u_char *, long, long);
- _PR void redrawcmdlinefrom(VW *, u_char *, u_char *, long, long, long);
- _PR void restorecmdline(VW *);
- _PR void cmdlncursor(VW *, bool);
- _PR void handlegexposures(VW *);
- _PR void handleexpose(VW *, XExposeEvent *);
- _PR void scrollvw(VW *, long);
-
- void
- drawmsgsepline(VW *vw)
- {
- XDrawLine(XDisplay, vw->vw_Window, vw->vw_WindowSys.ws_TextFontGC,
- vw->vw_XStartPix, vw->vw_WindowSys.ws_MessageLineY,
- vw->vw_XEndPix, vw->vw_WindowSys.ws_MessageLineY);
- }
- void
- drawmsg(VW *vw, u_char *str, int len)
- {
- if(len >= vw->vw_MaxX)
- len = vw->vw_MaxX - 1;
- XDrawImageString(XDisplay, vw->vw_Window, vw->vw_WindowSys.ws_TextFontGC,
- vw->vw_XStartPix, vw->vw_WindowSys.ws_MessageFontY, str,
- len);
- if(len != vw->vw_MaxX - 1)
- {
- XClearArea(XDisplay, vw->vw_Window,
- vw->vw_XStartPix + (len * vw->vw_FontX),
- vw->vw_WindowSys.ws_MessageFontY - vw->vw_Font->ascent, 0,
- vw->vw_FontY, False);
- }
- }
-
- /*
- */
- void
- redrawcmdline(VW *vw, u_char *prompt, u_char *cmdLine, long promptLen, long cmdLen)
- {
- vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY - vw->vw_Font->ascent;
- CLR_AREA(vw, vw->vw_XStartPix, vw->vw_WindowSys.ws_PenY,
- vw->vw_XEndPix - 1, vw->vw_WindowSys.ws_PenY + vw->vw_FontY - 1);
- vw->vw_WindowSys.ws_PenX = vw->vw_XStartPix;
- vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY;
- drawbit(vw, P_TEXT, prompt, 100000, 0, promptLen + 1);
- drawbit(vw, P_TEXT, cmdLine - promptLen, 100000, promptLen,
- cmdLen + promptLen + 1);
- }
-
- void
- redrawcmdlinefrom(VW *vw, u_char *prompt, u_char *cmdLine, long promptLen, long cmdLen, long startPos)
- {
- vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY - vw->vw_Font->ascent;
- if(startPos < vw->vw_StartCol)
- startPos = vw->vw_StartCol;
- if(startPos < (vw->vw_StartCol + vw->vw_MaxX))
- {
- int xord = vw->vw_XStartPix + (startPos * vw->vw_FontX);
- CLR_AREA(vw, xord, vw->vw_WindowSys.ws_PenY, vw->vw_XEndPix - xord,
- vw->vw_FontY);
- vw->vw_WindowSys.ws_PenX = xord;
- vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY;
- if(startPos < promptLen)
- {
- drawbit(vw, P_TEXT, prompt, 100000, startPos, promptLen + 1);
- drawbit(vw, P_TEXT, cmdLine - promptLen, 100000, promptLen,
- cmdLen + promptLen + 1);
- }
- else
- drawbit(vw, P_TEXT, cmdLine - promptLen, 100000, startPos,
- cmdLen + promptLen + 1);
- }
- }
-
- /*
- * draws the cursor for the command line
- */
- void
- cmdlncursor(VW *vw, bool status)
- {
- GC cursgc;
- if(status == CURS_ON)
- cursgc = vw->vw_WindowSys.ws_TextFontGC;
- else
- cursgc = vw->vw_WindowSys.ws_BlkFontGC;
- vw->vw_WindowSys.ws_PenX = vw->vw_XStartPix
- + ((vw->vw_CursorPos.pos_Col - vw->vw_StartCol) * vw->vw_FontX);
- vw->vw_WindowSys.ws_PenY = vw->vw_WindowSys.ws_MessageFontY
- - vw->vw_Font->ascent;
- XFillRectangle(XDisplay, vw->vw_Window, cursgc, vw->vw_WindowSys.ws_PenX,
- vw->vw_WindowSys.ws_PenY, vw->vw_FontX, vw->vw_FontY);
- }
-
- static Bool
- gexpred(Display *dpy, XEvent *ev, XPointer arg)
- {
- return((ev->type == NoExpose) || (ev->type == GraphicsExpose));
- }
- void
- handlegexposures(VW *vw)
- {
- XEvent ev;
- do {
- POS start, end;
- unsigned int x1, y1, x2, y2;
- XIfEvent(XDisplay, &ev, gexpred, (XPointer)NULL);
- if(ev.type == NoExpose)
- return;
- x1 = ev.xgraphicsexpose.x;
- y1 = ev.xgraphicsexpose.y;
- x2 = x1 + ev.xgraphicsexpose.width;
- y2 = y1 + ev.xgraphicsexpose.height;
- if(y2 >= vw->vw_WindowSys.ws_MessageLineY)
- {
- y2 = vw->vw_WindowSys.ws_MessageLineY - 1;
- drawmsgsepline(vw);
- if(vw->vw_LastTitle)
- drawmsg(vw, vw->vw_LastTitle, strlen(vw->vw_LastTitle));
- else
- drawmsg(vw, "", 0);
- if(y1 >= vw->vw_WindowSys.ws_MessageLineY)
- continue;
- }
- start.pos_Col = ((x1 - vw->vw_XStartPix) / vw->vw_FontX)
- + vw->vw_StartCol;
- start.pos_Line = ((y1 - vw->vw_YStartPix) / vw->vw_FontY)
- + vw->vw_StartLine;
- end.pos_Col = (((x2 - 1)- vw->vw_XStartPix) / vw->vw_FontX)
- + vw->vw_StartCol;
- end.pos_Line = (((y2 - 1) - vw->vw_YStartPix) / vw->vw_FontY)
- + vw->vw_StartLine;
- redrawrect(vw, &start, &end, FALSE);
- } while(ev.xgraphicsexpose.count > 0);
- }
-
- void
- handleexpose(VW *vw, XExposeEvent *ev)
- {
- POS start, end;
- unsigned int x1, y1, x2, y2;
- x1 = ev->x;
- y1 = ev->y;
- x2 = x1 + ev->width;
- y2 = y1 + ev->height;
- if(y2 >= vw->vw_WindowSys.ws_MessageLineY)
- {
- y2 = vw->vw_WindowSys.ws_MessageLineY - 1;
- drawmsgsepline(vw);
- if(vw->vw_LastTitle)
- drawmsg(vw, vw->vw_LastTitle, strlen(vw->vw_LastTitle));
- else
- drawmsg(vw, "", 0);
- if(y1 >= vw->vw_WindowSys.ws_MessageLineY)
- return;
- }
- /*
- * Special case of whole window being redrawn
- */
- if((x1 == 0) && (y1 == 0) && (x2 >= vw->vw_XEndPix)
- && (y2 >= (vw->vw_WindowSys.ws_MessageLineY - 1)))
- redrawall(vw);
- else
- {
- start.pos_Col = ((x1 - vw->vw_XStartPix) / vw->vw_FontX)
- + vw->vw_StartCol;
- start.pos_Line = ((y1 - vw->vw_YStartPix) / vw->vw_FontY)
- + vw->vw_StartLine;
- end.pos_Col = (((x2 - 1)- vw->vw_XStartPix) / vw->vw_FontX)
- + vw->vw_StartCol;
- end.pos_Line = (((y2 - 1) - vw->vw_YStartPix) / vw->vw_FontY)
- + vw->vw_StartLine;
- redrawrect(vw, &start, &end, TRUE);
- }
- }
-
- /*
- * Scrolls the view `lines' towards line 0,
- */
- void
- scrollvw(VW *vw, long lines)
- {
- int xsrc, ysrc, xwth, yht, xdst, ydst;
- xsrc = vw->vw_XStartPix;
- xwth = vw->vw_XWidthPix;
- xdst = vw->vw_XStartPix;
- if(lines > 0)
- {
- ysrc = vw->vw_YStartPix + (lines * vw->vw_FontY);
- yht = vw->vw_YHeightPix - (lines * vw->vw_FontY);
- ydst = vw->vw_YStartPix;
- XCopyArea(XDisplay, vw->vw_Window, vw->vw_Window,
- vw->vw_WindowSys.ws_TextFontGC,
- xsrc, ysrc,
- xwth, yht,
- xdst, ydst);
- handlegexposures(vw);
- XClearArea(XDisplay, vw->vw_Window,
- xsrc, vw->vw_YStartPix + yht,
- xwth, ysrc - ydst,
- False);
- }
- else if(lines < 0)
- {
- lines = 0 - lines;
- ysrc = vw->vw_YStartPix;
- yht = vw->vw_YHeightPix - (lines * vw->vw_FontY);
- ydst = vw->vw_YStartPix + (lines * vw->vw_FontY);
- XCopyArea(XDisplay, vw->vw_Window, vw->vw_Window,
- vw->vw_WindowSys.ws_TextFontGC,
- xsrc, ysrc,
- xwth, yht,
- xdst, ydst);
- handlegexposures(vw);
- XClearArea(XDisplay, vw->vw_Window,
- xsrc, ysrc,
- xwth, ydst - ysrc,
- False);
- }
- }
-