2017-08-10 20:27:50 +02:00
|
|
|
|
/* grTOGL3.c -
|
|
|
|
|
|
*
|
|
|
|
|
|
* Copyright 2003 Open Circuit Design, Inc., for MultiGiG Ltd.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This file contains additional functions to manipulate an X window system
|
|
|
|
|
|
* color display. Included here are device-dependent routines to draw and
|
|
|
|
|
|
* erase text and draw a grid.
|
|
|
|
|
|
*
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
#include <GL/gl.h>
|
|
|
|
|
|
#include <GL/glx.h>
|
|
|
|
|
|
#include <GL/glu.h>
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-08-30 22:34:42 +02:00
|
|
|
|
#include <cairo/cairo-xlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
#include "tcltk/tclmagic.h"
|
|
|
|
|
|
#include "utils/magic.h"
|
|
|
|
|
|
#include "utils/geometry.h"
|
|
|
|
|
|
#include "utils/malloc.h"
|
|
|
|
|
|
#include "windows/windows.h"
|
|
|
|
|
|
#include "graphics/graphics.h"
|
|
|
|
|
|
#include "graphics/graphicsInt.h"
|
|
|
|
|
|
#include "dbwind/dbwind.h"
|
|
|
|
|
|
#include "textio/textio.h"
|
|
|
|
|
|
#include "utils/signals.h"
|
|
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
|
#include "utils/hash.h"
|
2017-08-18 20:15:12 +02:00
|
|
|
|
//#include "graphics/grTOGLInt.h"
|
|
|
|
|
|
#include "graphics/grTCairoInt.h"
|
2017-08-10 20:27:50 +02:00
|
|
|
|
#include "graphics/grTkCommon.h"
|
|
|
|
|
|
#include "database/fonts.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern Display *grXdpy;
|
|
|
|
|
|
extern cairo_t *grCairoContext;
|
|
|
|
|
|
|
2017-08-30 22:34:42 +02:00
|
|
|
|
static GC grXcopyGC = (GC)NULL;
|
|
|
|
|
|
|
2017-08-10 20:27:50 +02:00
|
|
|
|
/* locals */
|
|
|
|
|
|
|
2017-08-30 22:34:42 +02:00
|
|
|
|
//GLuint grXBases[4];
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
|
|
* grtoglDrawGrid:
|
|
|
|
|
|
* grxDrawGrid adds a grid to the grid layer, using the current
|
|
|
|
|
|
* write mask and color.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Results:
|
|
|
|
|
|
* TRUE is returned normally. However, if the grid gets too small
|
|
|
|
|
|
* to be useful, then nothing is drawn and FALSE is returned.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side Effects: None.
|
|
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
grtcairoDrawGrid (prect, outline, clip)
|
|
|
|
|
|
Rect *prect; /* A rectangle that forms the template
|
|
|
|
|
|
* for the grid. Note: in order to maintain
|
|
|
|
|
|
* precision for the grid, the rectangle
|
|
|
|
|
|
* coordinates are specified in units of
|
|
|
|
|
|
* screen coordinates multiplied by SUBPIXEL.
|
|
|
|
|
|
*/
|
|
|
|
|
|
int outline; /* the outline style */
|
|
|
|
|
|
Rect *clip; /* a clipping rectangle */
|
|
|
|
|
|
{
|
|
|
|
|
|
int xsize, ysize;
|
|
|
|
|
|
int x, y;
|
|
|
|
|
|
int xstart, ystart;
|
|
|
|
|
|
int snum, low, hi, shifted;
|
|
|
|
|
|
|
|
|
|
|
|
xsize = prect->r_xtop - prect->r_xbot;
|
|
|
|
|
|
ysize = prect->r_ytop - prect->r_ybot;
|
|
|
|
|
|
if (!xsize || !ysize || GRID_TOO_SMALL(xsize, ysize))
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
xstart = prect->r_xbot % xsize;
|
|
|
|
|
|
while (xstart < clip->r_xbot << SUBPIXELBITS) xstart += xsize;
|
|
|
|
|
|
ystart = prect->r_ybot % ysize;
|
|
|
|
|
|
while (ystart < clip->r_ybot << SUBPIXELBITS) ystart += ysize;
|
|
|
|
|
|
|
|
|
|
|
|
//grtoglSetLineStyle(outline);
|
|
|
|
|
|
|
|
|
|
|
|
//glBegin(GL_LINES);
|
|
|
|
|
|
|
|
|
|
|
|
snum = 0;
|
|
|
|
|
|
low = clip->r_ybot;
|
|
|
|
|
|
hi = clip->r_ytop;
|
|
|
|
|
|
for (x = xstart; x < (clip->r_xtop + 1) << SUBPIXELBITS; x += xsize)
|
|
|
|
|
|
{
|
|
|
|
|
|
shifted = x >> SUBPIXELBITS;
|
|
|
|
|
|
//glVertex2i(shifted, low);
|
|
|
|
|
|
//glVertex2i(shifted, hi);
|
|
|
|
|
|
cairo_move_to(grCairoContext, shifted, low);
|
|
|
|
|
|
cairo_line_to(grCairoContext, shifted, hi);
|
|
|
|
|
|
snum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
snum = 0;
|
|
|
|
|
|
low = clip->r_xbot;
|
|
|
|
|
|
hi = clip->r_xtop;
|
|
|
|
|
|
for (y = ystart; y < (clip->r_ytop + 1) << SUBPIXELBITS; y += ysize)
|
|
|
|
|
|
{
|
|
|
|
|
|
shifted = y >> SUBPIXELBITS;
|
|
|
|
|
|
//glVertex2i(low, shifted);
|
|
|
|
|
|
//glVertex2i(hi, shifted);
|
|
|
|
|
|
cairo_move_to(grCairoContext, low, shifted);
|
|
|
|
|
|
cairo_line_to(grCairoContext, hi, shifted);
|
|
|
|
|
|
snum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
//glEnd();
|
|
|
|
|
|
cairo_stroke(grCairoContext);
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
|
|
* grtoglLoadFont
|
|
|
|
|
|
* This local routine transfers the X font bitmaps
|
|
|
|
|
|
* into OpenGL display lists for simple text
|
|
|
|
|
|
* rendering.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Results: Success/Failure
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side Effects: None.
|
|
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
|
grtoglLoadFont()
|
|
|
|
|
|
{
|
2017-08-17 19:47:38 +02:00
|
|
|
|
/*
|
2017-08-10 20:27:50 +02:00
|
|
|
|
Font id;
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
|
id = Tk_FontId(grTkFonts[i]);
|
|
|
|
|
|
|
|
|
|
|
|
grXBases[i] = glGenLists(256);
|
|
|
|
|
|
if (grXBases[i] == 0) {
|
|
|
|
|
|
TxError("Out of display lists!\n");
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
glXUseXFont(id, 0, 256, grXBases[i]);
|
|
|
|
|
|
}
|
2017-08-17 19:47:38 +02:00
|
|
|
|
*/
|
|
|
|
|
|
cairo_select_font_face(grCairoContext, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
|
|
* grtoglSetCharSize:
|
|
|
|
|
|
* This local routine sets the character size in the display,
|
|
|
|
|
|
* if necessary.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Results: None.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side Effects: None.
|
|
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-10 20:28:06 +02:00
|
|
|
|
grtcairoSetCharSize (size)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
int size; /* Width of characters, in pixels (6 or 8). */
|
|
|
|
|
|
{
|
2017-08-10 20:28:06 +02:00
|
|
|
|
tcairoCurrent.fontSize = size;
|
2017-08-29 18:52:57 +02:00
|
|
|
|
cairo_set_font_size(grCairoContext, size * 4 + 10);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
switch (size)
|
|
|
|
|
|
{
|
|
|
|
|
|
case GR_TEXT_DEFAULT:
|
|
|
|
|
|
case GR_TEXT_SMALL:
|
2017-08-10 20:28:06 +02:00
|
|
|
|
tcairoCurrent.font = grSmallFont;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
break;
|
|
|
|
|
|
case GR_TEXT_MEDIUM:
|
2017-08-10 20:28:06 +02:00
|
|
|
|
tcairoCurrent.font = grMediumFont;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
break;
|
|
|
|
|
|
case GR_TEXT_LARGE:
|
2017-08-10 20:28:06 +02:00
|
|
|
|
tcairoCurrent.font = grLargeFont;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
break;
|
|
|
|
|
|
case GR_TEXT_XLARGE:
|
2017-08-10 20:28:06 +02:00
|
|
|
|
tcairoCurrent.font = grXLargeFont;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2017-08-10 20:28:06 +02:00
|
|
|
|
TxError("%s%d\n", "grtcairoSetCharSize: Unknown character size ",
|
2017-08-10 20:27:50 +02:00
|
|
|
|
size );
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
|
* GrTOGLTextSize --
|
|
|
|
|
|
*
|
|
|
|
|
|
* Determine the size of a text string.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Results:
|
|
|
|
|
|
* None.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side effects:
|
|
|
|
|
|
* A rectangle is filled in that is the size of the text in pixels.
|
|
|
|
|
|
* The origin (0, 0) of this rectangle is located on the baseline
|
|
|
|
|
|
* at the far left side of the string.
|
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-10 20:28:06 +02:00
|
|
|
|
GrTCairoTextSize(text, size, r)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
char *text;
|
|
|
|
|
|
int size;
|
|
|
|
|
|
Rect *r;
|
|
|
|
|
|
{
|
|
|
|
|
|
Tk_FontMetrics overall;
|
|
|
|
|
|
Tk_Font font;
|
|
|
|
|
|
int width;
|
|
|
|
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
|
|
case GR_TEXT_DEFAULT:
|
|
|
|
|
|
case GR_TEXT_SMALL:
|
|
|
|
|
|
font = grSmallFont;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GR_TEXT_MEDIUM:
|
|
|
|
|
|
font = grMediumFont;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GR_TEXT_LARGE:
|
|
|
|
|
|
font = grLargeFont;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GR_TEXT_XLARGE:
|
|
|
|
|
|
font = grXLargeFont;
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2017-08-18 20:15:12 +02:00
|
|
|
|
TxError("%s%d\n", "GrTCairoTextSize: Unknown character size ",
|
2017-08-10 20:27:50 +02:00
|
|
|
|
size );
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (font == NULL) return;
|
|
|
|
|
|
Tk_GetFontMetrics(font, &overall);
|
|
|
|
|
|
width = Tk_TextWidth(font, text, strlen(text));
|
|
|
|
|
|
/* Hack alert! Tk_TextWidth returns values too small! */
|
|
|
|
|
|
width = width + (width >> 4);
|
|
|
|
|
|
r->r_ytop = overall.ascent;
|
|
|
|
|
|
r->r_ybot = -overall.descent;
|
|
|
|
|
|
r->r_xtop = width;
|
|
|
|
|
|
r->r_xbot = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* OpenGL backing store functions (now removed from the X11-based ones) */
|
|
|
|
|
|
/* Since we always paint into the front buffer, the back buffer is */
|
|
|
|
|
|
/* always available for backing store. We need not create or destroy */
|
|
|
|
|
|
/* it. We just use the w_backingStore location to store whether the */
|
|
|
|
|
|
/* backing store contains valid data or not. */
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-15 21:19:13 +02:00
|
|
|
|
grtcairoFreeBackingStore(MagWindow *window)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
{
|
2017-08-15 21:19:13 +02:00
|
|
|
|
//window->w_backingStore = (ClientData)0;
|
|
|
|
|
|
Pixmap pmap = (Pixmap)window->w_backingStore;
|
|
|
|
|
|
if (pmap == (Pixmap)NULL) return;
|
|
|
|
|
|
XFreePixmap(grXdpy, pmap);
|
|
|
|
|
|
window->w_backingStore = (ClientData)NULL;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-15 21:19:13 +02:00
|
|
|
|
grtcairoCreateBackingStore(MagWindow *w)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
{
|
2017-08-15 21:19:13 +02:00
|
|
|
|
Pixmap pmap;
|
|
|
|
|
|
Window wind = (Window)w->w_grdata;
|
|
|
|
|
|
unsigned int width, height;
|
|
|
|
|
|
GC gc;
|
|
|
|
|
|
XGCValues gcValues;
|
|
|
|
|
|
int grDepth;
|
|
|
|
|
|
|
|
|
|
|
|
//Tk_Window tkwind = (Tk_Window)w->w_grdata;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
/* ignore all windows other than layout */
|
2017-08-15 21:19:13 +02:00
|
|
|
|
//if (w->w_client != DBWclientID) return;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
/* Deferred */
|
2017-08-15 21:19:13 +02:00
|
|
|
|
//if (tkwind == NULL) return;
|
|
|
|
|
|
|
|
|
|
|
|
//w->w_backingStore = (ClientData)1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (w->w_client != DBWclientID) return;
|
|
|
|
|
|
|
|
|
|
|
|
/* deferred */
|
2017-08-30 22:34:42 +02:00
|
|
|
|
if (wind == (Window)NULL) return;
|
2017-08-15 21:19:13 +02:00
|
|
|
|
|
|
|
|
|
|
width = w->w_screenArea.r_xtop - w->w_screenArea.r_xbot;
|
|
|
|
|
|
height = w->w_screenArea.r_ytop - w->w_screenArea.r_ybot;
|
|
|
|
|
|
|
|
|
|
|
|
if (w->w_backingStore != (ClientData)NULL) grtcairoFreeBackingStore(w);
|
2017-08-30 22:34:42 +02:00
|
|
|
|
|
2017-08-15 21:19:13 +02:00
|
|
|
|
if (grXcopyGC == (GC)NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
gcValues.graphics_exposures = FALSE;
|
|
|
|
|
|
grXcopyGC = XCreateGC(grXdpy, wind, GCGraphicsExposures, &gcValues);
|
|
|
|
|
|
}
|
2017-08-30 22:34:42 +02:00
|
|
|
|
|
|
|
|
|
|
grDepth = Tk_Depth((Tk_Window)w->w_grdata);
|
|
|
|
|
|
|
2017-08-16 19:52:31 +02:00
|
|
|
|
//if (grClass == 3) grDepth = 8; /* Needed since grDisplay.depth is reset
|
|
|
|
|
|
// to 7 if Pseudocolor */
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
2017-08-15 21:19:13 +02:00
|
|
|
|
pmap = XCreatePixmap(grXdpy, wind, width, height, grDepth);
|
|
|
|
|
|
w->w_backingStore = (ClientData)pmap;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoGetBackingStore(MagWindow *w, Rect *area)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
{
|
|
|
|
|
|
unsigned int width, height;
|
|
|
|
|
|
int xbot, ybot;
|
|
|
|
|
|
Rect r;
|
|
|
|
|
|
|
|
|
|
|
|
// GLboolean result;
|
|
|
|
|
|
// GLint rasterpos[4];
|
|
|
|
|
|
|
|
|
|
|
|
if (w->w_backingStore == (ClientData)0) return FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
GEO_EXPAND(area, 1, &r);
|
|
|
|
|
|
GeoClip(&r, &(w->w_screenArea));
|
|
|
|
|
|
|
|
|
|
|
|
width = r.r_xtop - r.r_xbot;
|
|
|
|
|
|
height = r.r_ytop - r.r_ybot;
|
|
|
|
|
|
|
|
|
|
|
|
xbot = r.r_xbot;
|
|
|
|
|
|
ybot = r.r_ybot;
|
|
|
|
|
|
|
2017-08-15 21:19:13 +02:00
|
|
|
|
/*
|
|
|
|
|
|
glDrawBuffer(GL_FRONT);
|
|
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
|
|
glRasterPos2i((GLint)xbot, (GLint)ybot);
|
|
|
|
|
|
*/
|
2017-08-10 20:27:50 +02:00
|
|
|
|
/* Check for valid raster position */
|
|
|
|
|
|
// glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, (GLboolean *)(&result));
|
|
|
|
|
|
// glGetIntegerv(GL_CURRENT_RASTER_POSITION, (GLint *)(&rasterpos[0]));
|
|
|
|
|
|
|
|
|
|
|
|
// TxPrintf("Raster valid = %d, position = %d %d %d %d\n",
|
|
|
|
|
|
// (int)result, (int)rasterpos[0], (int)rasterpos[1],
|
|
|
|
|
|
// (int)rasterpos[2], (int)rasterpos[3]);
|
|
|
|
|
|
// if (result == 0)
|
|
|
|
|
|
// TxPrintf("Intended position = %d %d\n", xbot, ybot);
|
2017-08-15 21:19:13 +02:00
|
|
|
|
/*
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
glCopyPixels(xbot, ybot, width, height, GL_COLOR);
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
Window root_return;
|
|
|
|
|
|
int x_return, y_return;
|
|
|
|
|
|
unsigned int width_return, height_return;
|
|
|
|
|
|
unsigned int border_width_return;
|
|
|
|
|
|
unsigned int depth_return;
|
2017-08-30 22:34:42 +02:00
|
|
|
|
Pixmap pmap;
|
2017-08-15 21:19:13 +02:00
|
|
|
|
|
|
|
|
|
|
pmap = (Pixmap)w->w_backingStore;
|
|
|
|
|
|
if (pmap == (Pixmap)NULL)
|
|
|
|
|
|
return FALSE;
|
2017-08-30 22:34:42 +02:00
|
|
|
|
XGetGeometry(grXdpy, pmap, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return);
|
2017-08-15 21:19:13 +02:00
|
|
|
|
|
|
|
|
|
|
cairo_surface_t *backingStoreSurface;
|
|
|
|
|
|
backingStoreSurface = cairo_xlib_surface_create(grXdpy, pmap, DefaultVisual(grXdpy, DefaultScreen(grXdpy)), width_return, height_return);
|
|
|
|
|
|
cairo_set_source_surface(grCairoContext, backingStoreSurface, xbot, ybot);
|
|
|
|
|
|
cairo_rectangle(grCairoContext, xbot, ybot, width, height);
|
|
|
|
|
|
cairo_fill(grCairoContext);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoScrollBackingStore(MagWindow *w, Point *shift)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
{
|
2017-08-15 21:19:13 +02:00
|
|
|
|
/*
|
2017-08-10 20:27:50 +02:00
|
|
|
|
unsigned int width, height;
|
|
|
|
|
|
int xorigin, yorigin, xshift, yshift;
|
|
|
|
|
|
|
|
|
|
|
|
if (w->w_backingStore == (ClientData)0)
|
|
|
|
|
|
{
|
|
|
|
|
|
TxPrintf("grtoglScrollBackingStore %d %d failure\n",
|
|
|
|
|
|
shift->p_x, shift->p_y);
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
width = w->w_screenArea.r_xtop - w->w_screenArea.r_xbot;
|
|
|
|
|
|
height = w->w_screenArea.r_ytop - w->w_screenArea.r_ybot;
|
|
|
|
|
|
xorigin = 0;
|
|
|
|
|
|
yorigin = 0;
|
|
|
|
|
|
xshift = shift->p_x;
|
|
|
|
|
|
yshift = shift->p_y;
|
|
|
|
|
|
|
|
|
|
|
|
if (xshift > 0)
|
|
|
|
|
|
width -= xshift;
|
|
|
|
|
|
else if (xshift < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
width += xshift;
|
|
|
|
|
|
xorigin = -xshift;
|
|
|
|
|
|
xshift = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (yshift > 0)
|
|
|
|
|
|
height -= yshift;
|
|
|
|
|
|
else if (yshift < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
height += yshift;
|
|
|
|
|
|
yorigin = -yshift;
|
|
|
|
|
|
yshift = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
glDrawBuffer(GL_BACK);
|
|
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
|
|
glRasterPos2i((GLint)xshift, (GLint)yshift);
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
glCopyPixels(xorigin, yorigin, width, height, GL_COLOR);
|
|
|
|
|
|
|
|
|
|
|
|
glDrawBuffer(GL_FRONT);
|
|
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2017-08-15 21:19:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// copied from grX11su3.c
|
|
|
|
|
|
Pixmap pmap;
|
|
|
|
|
|
unsigned int width, height;
|
|
|
|
|
|
int xorigin, yorigin, xshift, yshift;
|
|
|
|
|
|
|
|
|
|
|
|
pmap = (Pixmap)w->w_backingStore;
|
|
|
|
|
|
if (pmap == (Pixmap)NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
TxPrintf("grx11ScrollBackingStore %d %d failure\n",
|
|
|
|
|
|
shift->p_x, shift->p_y);
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
width = w->w_screenArea.r_xtop - w->w_screenArea.r_xbot;
|
|
|
|
|
|
height = w->w_screenArea.r_ytop - w->w_screenArea.r_ybot;
|
|
|
|
|
|
xorigin = 0;
|
|
|
|
|
|
yorigin = 0;
|
|
|
|
|
|
xshift = shift->p_x;
|
|
|
|
|
|
yshift = -shift->p_y;
|
|
|
|
|
|
|
|
|
|
|
|
if (xshift > 0)
|
|
|
|
|
|
width -= xshift;
|
|
|
|
|
|
else if (xshift < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
width += xshift;
|
|
|
|
|
|
xorigin = -xshift;
|
|
|
|
|
|
xshift = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (yshift > 0)
|
|
|
|
|
|
height -= yshift;
|
|
|
|
|
|
else if (yshift < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
height += yshift;
|
|
|
|
|
|
yorigin = -yshift;
|
|
|
|
|
|
yshift = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
XCopyArea(grXdpy, pmap, pmap, grXcopyGC, xorigin, yorigin, width, height,
|
|
|
|
|
|
xshift, yshift);
|
|
|
|
|
|
|
|
|
|
|
|
/* TxPrintf("grx11ScrollBackingStore %d %d\n", shift->p_x, shift->p_y); */
|
|
|
|
|
|
return TRUE;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoPutBackingStore(MagWindow *w, Rect *area)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
{
|
|
|
|
|
|
unsigned int width, height;
|
|
|
|
|
|
int ybot, xbot;
|
|
|
|
|
|
|
|
|
|
|
|
// GLboolean result;
|
|
|
|
|
|
// GLint rasterpos[4];
|
|
|
|
|
|
|
|
|
|
|
|
if (w->w_backingStore == (ClientData)0) return;
|
|
|
|
|
|
|
|
|
|
|
|
width = area->r_xtop - area->r_xbot;
|
|
|
|
|
|
height = area->r_ytop - area->r_ybot;
|
|
|
|
|
|
|
|
|
|
|
|
ybot = area->r_ybot;
|
|
|
|
|
|
xbot = area->r_xbot;
|
|
|
|
|
|
|
|
|
|
|
|
if (xbot < 0) {
|
|
|
|
|
|
width -= xbot;
|
|
|
|
|
|
xbot = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ybot < 0) {
|
|
|
|
|
|
height -= ybot;
|
|
|
|
|
|
ybot = 0;
|
|
|
|
|
|
}
|
2017-08-15 21:19:13 +02:00
|
|
|
|
/*
|
|
|
|
|
|
glReadBuffer(GL_FRONT);
|
|
|
|
|
|
glDrawBuffer(GL_BACK);
|
|
|
|
|
|
glRasterPos2i((GLint)xbot, (GLint)ybot);
|
|
|
|
|
|
*/
|
|
|
|
|
|
// Check for valid raster position
|
2017-08-10 20:27:50 +02:00
|
|
|
|
// glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, (GLboolean *)(&result));
|
|
|
|
|
|
// glGetIntegerv(GL_CURRENT_RASTER_POSITION, (GLint *)(&rasterpos[0]));
|
|
|
|
|
|
|
|
|
|
|
|
// TxPrintf("Raster valid = %d, position = %d %d %d %d\n",
|
|
|
|
|
|
// (int)result, (int)rasterpos[0], (int)rasterpos[1],
|
|
|
|
|
|
// (int)rasterpos[2], (int)rasterpos[3]);
|
|
|
|
|
|
// if (result == 0)
|
|
|
|
|
|
// TxPrintf("Intended position = %d %d\n", xbot, ybot);
|
2017-08-15 21:19:13 +02:00
|
|
|
|
/*
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
glCopyPixels(xbot, ybot, width, height, GL_COLOR);
|
|
|
|
|
|
|
|
|
|
|
|
glDrawBuffer(GL_FRONT); // Return to normal front rendering
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-08-16 19:52:31 +02:00
|
|
|
|
Window root_return;
|
|
|
|
|
|
int x_return, y_return;
|
|
|
|
|
|
unsigned int width_return, height_return;
|
|
|
|
|
|
unsigned int border_width_return;
|
|
|
|
|
|
unsigned int depth_return;
|
2017-08-30 22:34:42 +02:00
|
|
|
|
Pixmap pmap;
|
2017-08-16 19:52:31 +02:00
|
|
|
|
|
|
|
|
|
|
pmap = (Pixmap)w->w_backingStore;
|
|
|
|
|
|
if (pmap == (Pixmap)NULL)
|
2017-08-30 22:34:42 +02:00
|
|
|
|
return;
|
|
|
|
|
|
XGetGeometry(grXdpy, pmap, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return);
|
2017-08-16 19:52:31 +02:00
|
|
|
|
|
2017-08-15 21:19:13 +02:00
|
|
|
|
cairo_surface_t *backingStoreSurface;
|
|
|
|
|
|
backingStoreSurface = cairo_xlib_surface_create(grXdpy, pmap, DefaultVisual(grXdpy, DefaultScreen(grXdpy)), width_return, height_return);
|
|
|
|
|
|
cairo_t *tempContext = cairo_create(backingStoreSurface);
|
2017-08-30 22:34:42 +02:00
|
|
|
|
cairo_set_source(tempContext, cairo_get_source(grCairoContext));
|
2017-08-15 21:19:13 +02:00
|
|
|
|
cairo_rectangle(tempContext, xbot, ybot, width, height);
|
|
|
|
|
|
cairo_fill(tempContext);
|
2017-08-30 22:34:42 +02:00
|
|
|
|
|
|
|
|
|
|
pmap = XCreatePixmap(grXdpy, wind, width, height, grDepth);
|
|
|
|
|
|
w->w_backingStore = (ClientData)pmap;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
|
* GrTOGLReadPixel --
|
|
|
|
|
|
*
|
|
|
|
|
|
* Read one pixel from the screen.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Results:
|
|
|
|
|
|
* An integer containing the pixel's color.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side effects:
|
|
|
|
|
|
* none.
|
|
|
|
|
|
*
|
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2017-08-18 20:15:12 +02:00
|
|
|
|
GrTCairoReadPixel (w, x, y)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
MagWindow *w;
|
|
|
|
|
|
int x, y; /* the location of a pixel in screen coords */
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0; /* OpenGL has no such function, so return 0 */
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
|
* GrTOGLBitBlt --
|
|
|
|
|
|
*
|
|
|
|
|
|
* Copy information in bit block transfers.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Results:
|
|
|
|
|
|
* None.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side effects:
|
|
|
|
|
|
* changes the screen.
|
|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
GrTCairoBitBlt(r, p)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
Rect *r;
|
|
|
|
|
|
Point *p;
|
|
|
|
|
|
{
|
2017-08-30 22:34:42 +02:00
|
|
|
|
/*
|
2017-08-10 20:27:50 +02:00
|
|
|
|
glCopyPixels(r->r_xbot, r->r_ybot, r->r_xtop - r->r_xbot + 1,
|
|
|
|
|
|
r->r_ytop - r->r_ybot + 1, GL_COLOR);
|
2017-08-30 22:34:42 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
cairo_set_source_surface(grCairoContext, cairo_get_source(grCairoContext), p->p_x, p->p_y);
|
|
|
|
|
|
// do some stuff
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef VECTOR_FONTS
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
|
|
*
|
|
|
|
|
|
* Technically, there should be no self-intersecting polygons in outline
|
|
|
|
|
|
* fonts. However, decomposition of bezier curves into line segments
|
|
|
|
|
|
* may occasionally produce one, so it needs to be handled.
|
|
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2017-08-30 22:34:42 +02:00
|
|
|
|
/*
|
|
|
|
|
|
// unused in cairo graphics
|
2017-08-10 20:27:50 +02:00
|
|
|
|
void
|
|
|
|
|
|
myCombine(GLdouble coords[3], GLdouble *vertex_data[4],
|
|
|
|
|
|
GLfloat weight[4], GLdouble **outData, void *dataptr)
|
|
|
|
|
|
{
|
2017-08-30 22:34:42 +02:00
|
|
|
|
// This needs to be free'd at the end of gluTessEndPolygon()!
|
2017-08-10 20:27:50 +02:00
|
|
|
|
GLdouble *new = (GLdouble *)mallocMagic(2 * sizeof(GLdouble));
|
|
|
|
|
|
new[0] = coords[0];
|
|
|
|
|
|
new[1] = coords[1];
|
|
|
|
|
|
*outData = new;
|
2017-08-30 22:34:42 +02:00
|
|
|
|
// Diagnostic
|
2017-08-10 20:27:50 +02:00
|
|
|
|
TxError("Intersecting polygon in char \"%c\" at %g %g!\n",
|
|
|
|
|
|
*((char *)dataptr), coords[0], coords[1]);
|
|
|
|
|
|
}
|
2017-08-30 22:34:42 +02:00
|
|
|
|
*/
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
|
|
* Draw a text character
|
|
|
|
|
|
* This routine differs from grtoglFillPolygon() in that it uses the
|
|
|
|
|
|
* glu library to handle non-convex polygons as may appear in font
|
|
|
|
|
|
* outlines.
|
|
|
|
|
|
*----------------------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoDrawCharacter(clist, tc, pixsize)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
FontChar *clist;
|
|
|
|
|
|
unsigned char tc;
|
|
|
|
|
|
int pixsize;
|
|
|
|
|
|
{
|
|
|
|
|
|
Point *tp;
|
|
|
|
|
|
int np, nptotal;
|
|
|
|
|
|
int i, j;
|
2017-08-16 19:52:31 +02:00
|
|
|
|
// static GLUtesselator *tess = NULL;
|
|
|
|
|
|
// static GLdouble *v = NULL;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
static int maxnp = 0;
|
|
|
|
|
|
FontChar *ccur;
|
|
|
|
|
|
|
|
|
|
|
|
if (pixsize < 5) return; /* Label too small to be useful */
|
|
|
|
|
|
|
2017-08-16 20:11:12 +02:00
|
|
|
|
//should we be using cairo_show_glyphs??
|
2017-08-16 19:52:31 +02:00
|
|
|
|
for (ccur = clist; ccur != NULL; ccur = ccur->fc_next) {
|
|
|
|
|
|
tp = ccur->fc_points;
|
|
|
|
|
|
np = ccur->fc_numpoints;
|
|
|
|
|
|
cairo_move_to(grCairoContext, tp[0].p_x, tp[0].p_y);
|
|
|
|
|
|
for (i = 1; i < np; i++, j += 3) {
|
|
|
|
|
|
cairo_line_to(grCairoContext, tp[0].p_x, tp[0].p_y);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-08-17 21:42:31 +02:00
|
|
|
|
cairo_fill(grCairoContext);
|
2017-08-16 19:52:31 +02:00
|
|
|
|
|
2017-08-29 18:52:57 +02:00
|
|
|
|
/*
|
|
|
|
|
|
if (tess == NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
tess = gluNewTess();
|
|
|
|
|
|
gluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)glBegin);
|
|
|
|
|
|
gluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)glVertex3dv);
|
|
|
|
|
|
gluTessCallback(tess, GLU_TESS_END, (_GLUfuncptr)glEnd);
|
|
|
|
|
|
gluTessCallback(tess, GLU_TESS_COMBINE_DATA, (_GLUfuncptr)myCombine);
|
|
|
|
|
|
}
|
|
|
|
|
|
// Boundary-only does not look particularly good. . .
|
|
|
|
|
|
gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE);
|
|
|
|
|
|
|
|
|
|
|
|
nptotal = 0;
|
|
|
|
|
|
for (ccur = clist; ccur != NULL; ccur = ccur->fc_next)
|
|
|
|
|
|
nptotal += ccur->fc_numpoints;
|
|
|
|
|
|
|
|
|
|
|
|
if (nptotal > maxnp)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (v != NULL) freeMagic((char *)v);
|
|
|
|
|
|
maxnp = nptotal;
|
|
|
|
|
|
v = (GLdouble *)mallocMagic(nptotal * 3 * sizeof(GLdouble));
|
|
|
|
|
|
}
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
2017-08-29 18:52:57 +02:00
|
|
|
|
j = 0;
|
|
|
|
|
|
for (ccur = clist; ccur != NULL; ccur = ccur->fc_next)
|
|
|
|
|
|
{
|
|
|
|
|
|
tp = ccur->fc_points;
|
|
|
|
|
|
np = ccur->fc_numpoints;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < np; i++, j += 3) {
|
|
|
|
|
|
v[j] = tp[i].p_x;
|
|
|
|
|
|
v[j + 1] = tp[i].p_y;
|
|
|
|
|
|
v[j + 2] = 0;
|
|
|
|
|
|
}
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-29 18:52:57 +02:00
|
|
|
|
gluTessBeginPolygon(tess, (GLvoid *)(&tc));
|
|
|
|
|
|
j = 0;
|
|
|
|
|
|
for (ccur = clist; ccur != NULL; ccur = ccur->fc_next)
|
|
|
|
|
|
{
|
|
|
|
|
|
np = ccur->fc_numpoints;
|
|
|
|
|
|
gluTessBeginContour(tess);
|
|
|
|
|
|
for (i = 0; i < np; i++, j += 3) {
|
|
|
|
|
|
gluTessVertex(tess, &v[j], &v[j]);
|
|
|
|
|
|
}
|
|
|
|
|
|
gluTessEndContour(tess);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
2017-08-29 18:52:57 +02:00
|
|
|
|
gluTessEndPolygon(tess);
|
|
|
|
|
|
*/
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
|
|
* grtoglFontText:
|
|
|
|
|
|
*
|
|
|
|
|
|
* This routine draws text from font vectors using the
|
|
|
|
|
|
* font vector routines in DBlabel.c. Text is clipped
|
|
|
|
|
|
* to the clipping rectangle.
|
|
|
|
|
|
*
|
|
|
|
|
|
* For speed, we should be transferring the font
|
|
|
|
|
|
* vectors into OpenGL display lists!
|
|
|
|
|
|
*
|
|
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoFontText(text, font, size, rotate, pos, clip, obscure)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
char *text; /* The text to be drawn */
|
|
|
|
|
|
int font; /* Font to use from fontList */
|
|
|
|
|
|
int size; /* Pixel size of the font */
|
|
|
|
|
|
int rotate; /* Text rotation */
|
|
|
|
|
|
Point *pos; /* Text base position */
|
|
|
|
|
|
Rect *clip; /* Clipping area */
|
|
|
|
|
|
LinkedRect *obscure; /* List of obscuring areas */
|
|
|
|
|
|
{
|
|
|
|
|
|
char *tptr;
|
|
|
|
|
|
Point *coffset; /* vector to next character */
|
|
|
|
|
|
Rect *cbbox;
|
2017-08-30 22:34:42 +02:00
|
|
|
|
//GLfloat fsize, matvals[16];
|
|
|
|
|
|
float fsize;
|
2017-08-10 20:27:50 +02:00
|
|
|
|
FontChar *clist;
|
|
|
|
|
|
int cheight, baseline;
|
|
|
|
|
|
float tmp;
|
|
|
|
|
|
|
|
|
|
|
|
/* Keep it simple for now---ignore clip and obscure */
|
2017-08-16 19:52:31 +02:00
|
|
|
|
/*
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
glTranslated(pos->p_x, pos->p_y, 0);
|
|
|
|
|
|
glRotated(rotate, 0, 0, 1);
|
|
|
|
|
|
*/
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
2017-08-17 21:42:31 +02:00
|
|
|
|
cairo_save(grCairoContext);
|
2017-08-16 19:52:31 +02:00
|
|
|
|
cairo_translate(grCairoContext, pos->p_x, pos->p_y);
|
2017-08-30 22:34:42 +02:00
|
|
|
|
cairo_rotate(grCairoContext, ((double)rotate) / 360 * 2 * M_PI);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
/* Get label size */
|
|
|
|
|
|
cbbox = &DBFontList[font]->mf_extents;
|
|
|
|
|
|
|
2017-08-16 19:52:31 +02:00
|
|
|
|
//fsize = (GLfloat)size / (GLfloat)cbbox->r_ytop;
|
|
|
|
|
|
fsize = (uint8_t)size / (uint8_t)cbbox->r_ytop;
|
|
|
|
|
|
//glScalef(fsize, fsize, 1.0);
|
|
|
|
|
|
cairo_scale(grCairoContext, fsize, fsize);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
/* Adjust to baseline */
|
|
|
|
|
|
baseline = 0;
|
|
|
|
|
|
for (tptr = text; *tptr != '\0'; tptr++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DBFontChar(font, *tptr, NULL, NULL, &cbbox);
|
|
|
|
|
|
if (cbbox->r_ybot < baseline)
|
|
|
|
|
|
baseline = cbbox->r_ybot;
|
|
|
|
|
|
}
|
2017-08-16 19:52:31 +02:00
|
|
|
|
//glTranslated(0, -baseline, 0);
|
|
|
|
|
|
cairo_translate(grCairoContext, 0, -baseline);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
for (tptr = text; *tptr != '\0'; tptr++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DBFontChar(font, *tptr, &clist, &coffset, NULL);
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoDrawCharacter(clist, *tptr, size);
|
2017-08-16 19:52:31 +02:00
|
|
|
|
//glTranslated(coffset->p_x, coffset->p_y, 0);
|
|
|
|
|
|
cairo_translate(grCairoContext, coffset->p_x, coffset->p_y);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
2017-08-16 19:52:31 +02:00
|
|
|
|
//glPopMatrix();
|
2017-08-17 21:42:31 +02:00
|
|
|
|
cairo_restore(grCairoContext);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* VECTOR_FONTS */
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
|
|
|
|
|
* grtoglPutText:
|
|
|
|
|
|
* (modified on SunPutText)
|
|
|
|
|
|
*
|
|
|
|
|
|
* This routine puts a chunk of text on the screen in the current
|
|
|
|
|
|
* color, size, etc. The caller must ensure that it fits on
|
|
|
|
|
|
* the screen -- no clipping is done except to the obscuring rectangle
|
|
|
|
|
|
* list and the clip rectangle.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Results:
|
|
|
|
|
|
* none.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side Effects:
|
|
|
|
|
|
* The text is drawn on the screen.
|
|
|
|
|
|
*
|
|
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoPutText (text, pos, clip, obscure)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
char *text; /* The text to be drawn. */
|
|
|
|
|
|
Point *pos; /* A point located at the leftmost point of
|
|
|
|
|
|
* the baseline for this string.
|
|
|
|
|
|
*/
|
|
|
|
|
|
Rect *clip; /* A rectangle to clip against */
|
|
|
|
|
|
LinkedRect *obscure; /* A list of obscuring rectangles */
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
Rect location;
|
|
|
|
|
|
Rect overlap;
|
|
|
|
|
|
Rect textrect;
|
|
|
|
|
|
LinkedRect *ob;
|
2017-08-18 20:15:12 +02:00
|
|
|
|
void grTCairoGeoSub();
|
2017-08-10 20:27:50 +02:00
|
|
|
|
int i;
|
|
|
|
|
|
float tscale;
|
|
|
|
|
|
|
2017-08-18 20:15:12 +02:00
|
|
|
|
GrTCairoTextSize(text, tcairoCurrent.fontSize, &textrect);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
|
|
|
|
|
|
location.r_xbot = pos->p_x + textrect.r_xbot;
|
|
|
|
|
|
location.r_xtop = pos->p_x + textrect.r_xtop;
|
|
|
|
|
|
location.r_ybot = pos->p_y + textrect.r_ybot;
|
|
|
|
|
|
location.r_ytop = pos->p_y + textrect.r_ytop;
|
|
|
|
|
|
|
|
|
|
|
|
/* erase parts of the bitmap that are obscured */
|
|
|
|
|
|
for (ob = obscure; ob != NULL; ob = ob->r_next)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GEO_TOUCH(&ob->r_r, &location))
|
|
|
|
|
|
{
|
|
|
|
|
|
overlap = location;
|
|
|
|
|
|
GeoClip(&overlap, &ob->r_r);
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grTCairoGeoSub(&location, &overlap);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
overlap = location;
|
|
|
|
|
|
GeoClip(&overlap, clip);
|
|
|
|
|
|
|
|
|
|
|
|
/* copy the text to the color screen */
|
|
|
|
|
|
if ((overlap.r_xbot < overlap.r_xtop) && (overlap.r_ybot <= overlap.r_ytop))
|
|
|
|
|
|
{
|
2017-08-17 19:47:38 +02:00
|
|
|
|
//glScissor(overlap.r_xbot, overlap.r_ybot, overlap.r_xtop - overlap.r_xbot,
|
|
|
|
|
|
// overlap.r_ytop - overlap.r_ybot);
|
2017-08-17 21:42:31 +02:00
|
|
|
|
cairo_rectangle(grCairoContext, overlap.r_xbot, overlap.r_ybot, overlap.r_xtop - overlap.r_xbot, overlap.r_ytop - overlap.r_ybot);
|
2017-08-17 19:47:38 +02:00
|
|
|
|
cairo_clip(grCairoContext);
|
|
|
|
|
|
/*
|
2017-08-10 20:27:50 +02:00
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
glRasterPos2i(pos->p_x, pos->p_y);
|
|
|
|
|
|
glListBase(grXBases[(toglCurrent.fontSize == GR_TEXT_DEFAULT) ?
|
|
|
|
|
|
GR_TEXT_SMALL : toglCurrent.fontSize]);
|
|
|
|
|
|
glCallLists(strlen(text), GL_UNSIGNED_BYTE, (unsigned char *)text);
|
|
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2017-08-17 19:47:38 +02:00
|
|
|
|
*/
|
|
|
|
|
|
cairo_move_to(grCairoContext, location.r_xbot, location.r_ybot);
|
|
|
|
|
|
cairo_show_text(grCairoContext, text);
|
2017-08-17 21:42:31 +02:00
|
|
|
|
cairo_fill(grCairoContext);
|
2017-08-10 20:27:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* grTOGLGeoSub:
|
|
|
|
|
|
* return the tallest sub-rectangle of r not obscured by area
|
|
|
|
|
|
* area must be within r.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grTCairoGeoSub(r, area)
|
2017-08-10 20:27:50 +02:00
|
|
|
|
Rect *r; /* Rectangle to be subtracted from. */
|
|
|
|
|
|
Rect *area; /* Area to be subtracted. */
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
if (r->r_xbot == area->r_xbot) r->r_xbot = area->r_xtop;
|
|
|
|
|
|
else if (r->r_xtop == area->r_xtop) r->r_xtop = area->r_xbot;
|
|
|
|
|
|
else if (r->r_ybot <= area->r_ybot) r->r_ybot = area->r_ytop;
|
|
|
|
|
|
else if (r->r_ytop == area->r_ytop) r->r_ytop = area->r_ybot;
|
|
|
|
|
|
else
|
|
|
|
|
|
r->r_xtop = area->r_xbot;
|
|
|
|
|
|
}
|