mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-09-02 11:08:30 +02:00
Corrected problems having to do with color (blue and green were swapped)
and incorrect call to cairo_set_source_rgba which is in an unused function and has no effect except with versions of Tcl less than 8.6 where "load -lazy" is not available and unknown functions cause immediate exit. Cleaned up remaining references to OpenGL in the Cairo code, and updated the copyright and acknowledged Chuan Chen, who coded the Cairo interface. No attempt yet to deal with memory leaks caused by calling Cairo "create" functions without the accompanying "destroy" functions.
This commit is contained in:
+17
-157
@@ -1,9 +1,11 @@
|
||||
/* grTCairo1.c
|
||||
*
|
||||
* Copyright (C) 2003 Open Circuit Design, Inc., for MultiGiG Ltd.
|
||||
* Copyright (C) 2017 Open Circuit Design
|
||||
*
|
||||
* This file contains primitive functions for OpenGL running under
|
||||
* This file contains primitive functions for Cairo running under
|
||||
* an X window system in a Tcl/Tk interpreter environment
|
||||
*
|
||||
* Written by Chuan Chen
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -19,10 +21,6 @@
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
/*
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
*/
|
||||
#include <cairo/cairo-xlib.h>
|
||||
|
||||
#include "tcltk/tclmagic.h"
|
||||
@@ -43,21 +41,16 @@
|
||||
#include "database/database.h"
|
||||
#include "drc/drc.h"
|
||||
#include "utils/macros.h"
|
||||
//#include "graphics/grTCairoInt.h"
|
||||
#include "graphics/grTCairoInt.h"
|
||||
#include "utils/paths.h"
|
||||
#include "graphics/grTkCommon.h"
|
||||
|
||||
uint8_t **grTCairoStipples;
|
||||
HashTable grTCairoWindowTable;
|
||||
//GLXContext grXcontext;
|
||||
cairo_surface_t *grCairoSurface;
|
||||
cairo_t *grCairoContext;
|
||||
XVisualInfo *grVisualInfo;
|
||||
|
||||
//TCairo_CURRENT tcairoCurrent= {(Tk_Font)0, 0, 0, 0, 0,
|
||||
// (Tk_Window)0, (Window)0, (MagWindow *)NULL};
|
||||
|
||||
TCAIRO_CURRENT tcairoCurrent = {(Tk_Font)0, 0, 0, 0, 0,
|
||||
(Tk_Window)0, (Window)0, (MagWindow *)NULL
|
||||
};
|
||||
@@ -103,49 +96,20 @@ int c; /* New value for current color */
|
||||
static int oldMask = -1;
|
||||
|
||||
int lr, lb, lg;
|
||||
//GLfloat fr, fb, fg;
|
||||
//GLfloat aval; /* Alpha default value was 0.75 */
|
||||
float fr, fb, fg, aval;
|
||||
|
||||
if (mask == -65) mask = 127; /* All planes */
|
||||
if (mask == oldMask && c == oldColor) return;
|
||||
|
||||
//GR_TCairo_FLUSH_BATCH();
|
||||
GR_TCAIRO_FLUSH_BATCH();
|
||||
|
||||
GrGetColor(c, &lr, &lb, &lg);
|
||||
GrGetColor(c, &lr, &lg, &lb);
|
||||
|
||||
fr = ((float)lr / 255);
|
||||
fg = ((float)lg / 255);
|
||||
fb = ((float)lb / 255);
|
||||
aval = ((float)mask / 127.0);
|
||||
|
||||
/*
|
||||
if (mask == 127)
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
aval = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Calculate a "supercolor", outside of the normal color range,
|
||||
//but which results in the desired color after a blend with
|
||||
//the background color.
|
||||
|
||||
fr = fr * 2 - 0.8;
|
||||
fg = fg * 2 - 0.8;
|
||||
fb = fb * 2 - 0.8;
|
||||
|
||||
aval = (GLfloat)mask / 127.0; // mask translates to alpha in
|
||||
//the OpenGL version.
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
*/
|
||||
|
||||
//glColor4f(fr, fb, fg, aval);
|
||||
|
||||
cairo_set_source_rgba(grCairoContext, fr, fg, fb, aval);
|
||||
|
||||
oldColor = c;
|
||||
@@ -170,28 +134,6 @@ grtcairoSetLineStyle (style)
|
||||
int style; /* New stipple pattern for lines. */
|
||||
{
|
||||
// unimplemented for cairo
|
||||
/*
|
||||
static int oldStyle = -1;
|
||||
GLushort glstyle;
|
||||
|
||||
style &= 0xFF;
|
||||
if (style == oldStyle) return;
|
||||
oldStyle = style;
|
||||
GR_TCairo_FLUSH_BATCH();
|
||||
|
||||
switch (style) {
|
||||
case 0xFF:
|
||||
case 0x00:
|
||||
glDisable(GL_LINE_STIPPLE);
|
||||
break;
|
||||
default:
|
||||
glstyle = style | (style << 8);
|
||||
glEnable(GL_LINE_STIPPLE);
|
||||
glLineStipple(1, glstyle);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -225,7 +167,7 @@ int numstipples; /* Number of stipples */
|
||||
pdata = (uint8_t *)mallocMagic(128 * sizeof(uint8_t));
|
||||
n = 0;
|
||||
|
||||
/* expand magic's default 8x8 stipple to OpenGL's 32x32 */
|
||||
/* expand magic's default 8x8 stipple to 32x32 */
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
@@ -263,18 +205,12 @@ int stipple; /* The stipple number to be used. */
|
||||
oldStip = stipple;
|
||||
GR_TCAIRO_FLUSH_BATCH();
|
||||
if (stipple == 0 || stipple > grNumStipples) {
|
||||
//glDisable(GL_POLYGON_STIPPLE);
|
||||
//cairo_set_source_rgb(grCairoContext, 0, 0, 0);
|
||||
currentStipple = cairo_pattern_create_rgba(0, 0, 0, 1);
|
||||
} else {
|
||||
if (stipplePatterns[stipple] == (cairo_pattern_t *)NULL) MainExit(1);
|
||||
//glEnable(GL_POLYGON_STIPPLE);
|
||||
//glPolygonStipple(grTCairoStipples[stipple]);
|
||||
cairo_pattern_set_extend(stipplePatterns[stipple], CAIRO_EXTEND_REPEAT);
|
||||
cairo_pattern_set_filter(stipplePatterns[stipple], CAIRO_FILTER_NEAREST);
|
||||
currentStipple = stipplePatterns[stipple];
|
||||
//cairo_set_source(grCairoContext, stipplePatterns[stipple]);
|
||||
//cairo_mask_surface(grCairoContext, grCairoSurface, 0.0, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,13 +235,6 @@ bool
|
||||
GrTCairoInit ()
|
||||
{
|
||||
bool rstatus;
|
||||
/*
|
||||
#ifdef THREE_D
|
||||
static int attributeList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
|
||||
#else
|
||||
static int attributeList[] = { GLX_RGBA, None, None };
|
||||
#endif
|
||||
*/
|
||||
|
||||
tcairoCurrent.window = Tk_MainWindow(magicinterp); // XDefaultRootWindow(grXdpy) ??
|
||||
if (tcairoCurrent.window == NULL)
|
||||
@@ -320,7 +249,6 @@ GrTCairoInit ()
|
||||
|
||||
grXscrn = DefaultScreen(grXdpy);
|
||||
|
||||
//grVisualInfo = glXChooseVisual(grXdpy, grXscrn, attributeList);
|
||||
XVisualInfo grtemplate;
|
||||
int gritems;
|
||||
grtemplate.screen = grXscrn;
|
||||
@@ -331,43 +259,19 @@ GrTCairoInit ()
|
||||
{
|
||||
TxError("No suitable visual!\n");
|
||||
return FALSE;
|
||||
/*
|
||||
// Try for a double-buffered configuration
|
||||
#ifdef THREE_D
|
||||
attributeList[1] = None;
|
||||
#else
|
||||
attributeList[1] = GLX_DOUBLEBUFFER;
|
||||
#endif
|
||||
grVisualInfo = glXChooseVisual(grXdpy, grXscrn, attributeList);
|
||||
if (!grVisualInfo)
|
||||
{
|
||||
TxError("No suitable visual!\n");
|
||||
return FALSE;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
grXscrn = grVisualInfo->screen;
|
||||
tcairoCurrent.depth = grVisualInfo->depth;
|
||||
|
||||
/* TRUE = Direct rendering, FALSE = Indirect rendering */
|
||||
/* (note that direct rendering may not be able to deal with pixmaps) */
|
||||
//grXcontext = glXCreateContext(grXdpy, grVisualInfo, NULL, GL_FALSE);
|
||||
|
||||
grCairoSurface = cairo_xlib_surface_create(grXdpy, tcairoCurrent.windowid, grVisualInfo->visual, Tk_Width(tcairoCurrent.window), Tk_Height(tcairoCurrent.window));
|
||||
grCairoContext = cairo_create(grCairoSurface);
|
||||
|
||||
/* Basic GL parameters */
|
||||
/*
|
||||
glLineWidth(1.0);
|
||||
glShadeModel (GL_FLAT);
|
||||
glPixelStorei(GL_PACK_LSB_FIRST, TRUE);
|
||||
*/
|
||||
cairo_set_line_width(grCairoContext, 1.0);
|
||||
cairo_set_source_rgb(grCairoContext, 0, 0, 0);
|
||||
currentStipple = cairo_pattern_create_rgba(0, 0, 0, 1);
|
||||
|
||||
/* OpenGL sets its own names for colormap and dstyle file types */
|
||||
/* Use OpenGL names for colormap and dstyle file types */
|
||||
grCMapType = "OpenGL";
|
||||
grDStyleType = "OpenGL";
|
||||
|
||||
@@ -418,19 +322,17 @@ void
|
||||
GrTCairoFlush ()
|
||||
{
|
||||
GR_TCAIRO_FLUSH_BATCH();
|
||||
//glFlush();
|
||||
//glFinish();
|
||||
}
|
||||
|
||||
/*
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define glTransYs(n) (DisplayHeight(grXdpy, grXscrn)-(n))
|
||||
#define grTransYs(n) (DisplayHeight(grXdpy, grXscrn)-(n))
|
||||
|
||||
/*
|
||||
*---------------------------------------------------------
|
||||
* Set the OpenGL viewport (projection matrix) for a window
|
||||
* Set the Cairo projection matrix for a window
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -441,50 +343,9 @@ int llx, lly, width, height;
|
||||
grCairoSurface = cairo_xlib_surface_create(grXdpy, tcairoCurrent.windowid, grVisualInfo->visual, width, height);
|
||||
grCairoContext = cairo_create(grCairoSurface);
|
||||
|
||||
/* Because this tends to result in thick lines, it has been moved */
|
||||
/* the line drawing routine so it can be enabled for individual */
|
||||
/* lines. */
|
||||
/* glEnable(GL_LINE_SMOOTH); */
|
||||
|
||||
/* Force draw to front buffer (in case of double-buffered config) */
|
||||
//glDrawBuffer(GL_FRONT);
|
||||
|
||||
//glMatrixMode(GL_PROJECTION);
|
||||
//glLoadIdentity();
|
||||
cairo_identity_matrix(grCairoContext);
|
||||
|
||||
//glViewport((GLsizei)llx, (GLsizei)lly, (GLsizei) width, (GLsizei) height);
|
||||
// cairo equivalent??
|
||||
|
||||
/* scale to fit window */
|
||||
/*
|
||||
#ifdef CAIRO_INVERT_Y
|
||||
//glScalef(1.0 / (float)(width >> 1), -1.0 / (float)(height >> 1), 1.0);
|
||||
#else
|
||||
//glScalef(1.0 / (float)(width >> 1), 1.0 / (float)(height >> 1), 1.0);
|
||||
#endif
|
||||
*/
|
||||
//cairo_translate(grCairoContext, (width >> 1), (height >> 1));
|
||||
//cairo_translate(grCairoContext, width/2.0, height/2.0);
|
||||
cairo_translate(grCairoContext, 0, height);
|
||||
|
||||
|
||||
//cairo_scale(grCairoContext, width >> 1, -(height >> 1));
|
||||
cairo_scale(grCairoContext, 1.0, -1.0);
|
||||
//cairo_scale(grCairoContext, 1.0 / width, -1.0 / height);
|
||||
|
||||
|
||||
/* magic origin maps to window center; move to window origin */
|
||||
|
||||
//glTranslated(-(GLsizei)(width >> 1), -(GLsizei)(height >> 1), 0);
|
||||
|
||||
|
||||
/* Remaining transformations are done on the modelview matrix */
|
||||
|
||||
//glMatrixMode(GL_MODELVIEW);
|
||||
//glLoadIdentity();
|
||||
//cairo_identity_matrix(grCairoContext);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -850,8 +711,8 @@ keys_and_buttons:
|
||||
|
||||
screenRect.r_xbot = ConfigureEvent->x;
|
||||
screenRect.r_xtop = ConfigureEvent->x + width;
|
||||
screenRect.r_ytop = glTransYs(ConfigureEvent->y);
|
||||
screenRect.r_ybot = glTransYs(ConfigureEvent->y + height);
|
||||
screenRect.r_ytop = grTransYs(ConfigureEvent->y);
|
||||
screenRect.r_ybot = grTransYs(ConfigureEvent->y + height);
|
||||
|
||||
need_resize = (screenRect.r_xbot != mw->w_screenArea.r_xbot ||
|
||||
screenRect.r_xtop != mw->w_screenArea.r_xtop ||
|
||||
@@ -1084,7 +945,7 @@ char *name;
|
||||
char *windowplace;
|
||||
char windowname[10];
|
||||
int x = w->w_frameArea.r_xbot;
|
||||
int y = glTransYs(w->w_frameArea.r_ytop);
|
||||
int y = grTransYs(w->w_frameArea.r_ytop);
|
||||
int width = w->w_frameArea.r_xtop - w->w_frameArea.r_xbot;
|
||||
int height = w->w_frameArea.r_ytop - w->w_frameArea.r_ybot;
|
||||
unsigned long attribmask = CWBackPixel | CWBorderPixel | CWColormap;
|
||||
@@ -1099,8 +960,8 @@ char *name;
|
||||
(unsigned int *)&width, (unsigned int *)&height);
|
||||
w->w_frameArea.r_xbot = x;
|
||||
w->w_frameArea.r_xtop = x + width;
|
||||
w->w_frameArea.r_ytop = glTransYs(y);
|
||||
w->w_frameArea.r_ybot = glTransYs(y + height);
|
||||
w->w_frameArea.r_ytop = grTransYs(y);
|
||||
w->w_frameArea.r_ybot = grTransYs(y + height);
|
||||
WindReframe(w, &(w->w_frameArea), FALSE, FALSE);
|
||||
}
|
||||
|
||||
@@ -1175,7 +1036,6 @@ char *name;
|
||||
|
||||
wind = Tk_WindowId(tkwind);
|
||||
tcairoCurrent.windowid = wind;
|
||||
//glXMakeCurrent(grXdpy, (GLXDrawable)wind, grXcontext);
|
||||
grCairoSurface = cairo_xlib_surface_create(grXdpy, tcairoCurrent.windowid, grVisualInfo->visual, Tk_Width(tcairoCurrent.window), Tk_Height(tcairoCurrent.window));
|
||||
grCairoContext = cairo_create(grCairoSurface);
|
||||
|
||||
@@ -1212,7 +1072,7 @@ char *name;
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* GrTCairoDelete --
|
||||
* Destroy a Tk/OpenGL window.
|
||||
* Destroy a Tk/Cairo window.
|
||||
*
|
||||
* Results:
|
||||
* None.
|
||||
@@ -1260,7 +1120,7 @@ MagWindow *w;
|
||||
if (w->w_flags & WIND_OFFSCREEN) return;
|
||||
|
||||
Tk_MoveResizeWindow((Tk_Window)w->w_grdata,
|
||||
w->w_frameArea.r_xbot, glTransYs(w->w_frameArea.r_ytop),
|
||||
w->w_frameArea.r_xbot, grTransYs(w->w_frameArea.r_ytop),
|
||||
w->w_frameArea.r_xtop - w->w_frameArea.r_xbot,
|
||||
w->w_frameArea.r_ytop - w->w_frameArea.r_ybot);
|
||||
}
|
||||
@@ -1388,7 +1248,7 @@ GrTCairoUnlock(w)
|
||||
MagWindow *w;
|
||||
{
|
||||
/* GR_TCairo_FLUSH_BATCH(); */
|
||||
GrTCairoFlush(); /* (?) Adds glFlush and glFinish to the above. */
|
||||
GrTCairoFlush();
|
||||
grSimpleUnlock(w);
|
||||
}
|
||||
|
||||
|
||||
+14
-66
@@ -1,19 +1,17 @@
|
||||
/* grTOGL2.c -
|
||||
/* grTCairo2.c -
|
||||
*
|
||||
* Copyright 2003 Open Circuit Design, Inc., for MultiGiG Ltd.
|
||||
* Copyright 2017 Open Circuit Design
|
||||
*
|
||||
* This file contains additional functions to manipulate an X
|
||||
* color display. Included here are rectangle drawing and color map
|
||||
* loading.
|
||||
*
|
||||
* Written by Chuan Chen
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
char *getenv();
|
||||
|
||||
/*
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
*/
|
||||
#include <cairo/cairo-xlib.h>
|
||||
|
||||
#include "tcltk/tclmagic.h"
|
||||
@@ -24,13 +22,11 @@ char *getenv();
|
||||
#include "windows/windows.h"
|
||||
#include "graphics/graphics.h"
|
||||
#include "graphics/graphicsInt.h"
|
||||
//#include "grTOGLInt.h"
|
||||
#include "grTCairoInt.h"
|
||||
|
||||
#include "textio/txcommands.h"
|
||||
|
||||
extern char *DBWStyleType;
|
||||
//extern GLXContext grXcontext;
|
||||
extern Display *grXdpy;
|
||||
|
||||
extern cairo_t *grCairoContext;
|
||||
@@ -38,9 +34,9 @@ extern cairo_surface_t *grCairoSurface;
|
||||
extern cairo_pattern_t *currentStipple;
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* GrOGLSetCMap --
|
||||
* GrTCairoSetCMap --
|
||||
*
|
||||
* OpenGL uses RGB values as read from the colormap file,
|
||||
* Cairo uses RGB values as read from the colormap file,
|
||||
* directly, so there is no need to install colors into a
|
||||
* colormap. Therefore, this is a null routine.
|
||||
*
|
||||
@@ -64,7 +60,7 @@ Rect grtcairoDiagonal[TCAIRO_BATCH_SIZE];
|
||||
int grtcairoNbDiagonal = 0;
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglDrawLines:
|
||||
* grtcairoDrawLines:
|
||||
* This routine draws a batch of lines.
|
||||
*
|
||||
* Results: None.
|
||||
@@ -79,23 +75,6 @@ grtcairoDrawLines(lines, nb)
|
||||
Rect lines[];
|
||||
int nb;
|
||||
{
|
||||
/*
|
||||
#ifdef OGL_SERVER_SIDE_ONLY
|
||||
int i;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
for (i = 0; i < nb; i++)
|
||||
{
|
||||
glVertex2i(lines[i].r_ll.p_x, lines[i].r_ll.p_y);
|
||||
glVertex2i(lines[i].r_ur.p_x, lines[i].r_ur.p_y);
|
||||
}
|
||||
glEnd();
|
||||
#else
|
||||
glVertexPointer(2, GL_INT, 0, (GLvoid *)lines);
|
||||
glDrawArrays(GL_LINES, 0, nb << 1);
|
||||
#endif
|
||||
*/
|
||||
|
||||
int i;
|
||||
for (i = 0; i < nb; i++)
|
||||
{
|
||||
@@ -108,7 +87,7 @@ int nb;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglDrawLine:
|
||||
* grtcairoDrawLine:
|
||||
* This routine draws a line.
|
||||
*
|
||||
* Results: None.
|
||||
@@ -123,9 +102,8 @@ grtcairoDrawLine (x1, y1, x2, y2)
|
||||
int x1, y1; /* Screen coordinates of first point. */
|
||||
int x2, y2; /* Screen coordinates of second point. */
|
||||
{
|
||||
/* Treat straight and diagonal lines separately. Some */
|
||||
/* implementations of OpenGL make straight lines twice as thick */
|
||||
/* when smoothing is enabled. */
|
||||
/* Treat straight and diagonal lines separately. */
|
||||
/* (Done for OpenGL; possibly not necessary for Cairo) */
|
||||
|
||||
if ((x1 == x2) || (y1 == y2))
|
||||
{
|
||||
@@ -148,7 +126,7 @@ int x2, y2; /* Screen coordinates of second point. */
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglFillRects:
|
||||
* grtcairoFillRects:
|
||||
* This routine draws a bunch of solid rectangles.
|
||||
*
|
||||
* Results: None.
|
||||
@@ -163,24 +141,6 @@ grtcairoFillRects(rects, nb)
|
||||
TCairoRect rects[];
|
||||
int nb;
|
||||
{
|
||||
/*
|
||||
#ifdef OGL_SERVER_SIDE_ONLY
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nb; i++)
|
||||
{
|
||||
glRecti(rects[i].r_ll.p_x, rects[i].r_ll.p_y,
|
||||
rects[i].r_ur.p_x, rects[i].r_ur.p_y);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
glVertexPointer(2, GL_INT, 0, (GLvoid *)rects);
|
||||
glDrawArrays(GL_QUADS, 0, nb << 2);
|
||||
|
||||
#endif
|
||||
*/
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nb; i++)
|
||||
@@ -188,16 +148,14 @@ int nb;
|
||||
cairo_rectangle(grCairoContext,
|
||||
rects[i].r_ll.p_x, rects[i].r_ll.p_y,
|
||||
rects[i].r_ur.p_x-rects[i].r_ll.p_x, rects[i].r_ur.p_y-rects[i].r_ll.p_y);
|
||||
TxPrintf("%d %d %d %d \n", rects[i].r_ll.p_x, rects[i].r_ll.p_y, rects[i].r_ur.p_x-rects[i].r_ll.p_x, rects[i].r_ur.p_y-rects[i].r_ll.p_y);
|
||||
// TxPrintf("%d %d %d %d \n", rects[i].r_ll.p_x, rects[i].r_ll.p_y, rects[i].r_ur.p_x-rects[i].r_ll.p_x, rects[i].r_ur.p_y-rects[i].r_ll.p_y);
|
||||
}
|
||||
cairo_clip(grCairoContext);
|
||||
cairo_mask(grCairoContext, currentStipple);
|
||||
|
||||
//cairo_fill(grCairoContext);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglFillRect:
|
||||
* grtcairoFillRect:
|
||||
* This routine draws a solid rectangle.
|
||||
*
|
||||
* Results: None.
|
||||
@@ -220,19 +178,17 @@ Rect *r; /* Address of a rectangle in screen
|
||||
grtcairoRects[grtcairoNbRects].r_ur.p_x = r->r_ur.p_x;
|
||||
grtcairoRects[grtcairoNbRects].r_ur.p_y = r->r_ur.p_y;
|
||||
|
||||
#ifndef OGL_SERVER_SIDE_ONLY
|
||||
grtcairoRects[grtcairoNbRects].r_ul.p_x = r->r_ll.p_x;
|
||||
grtcairoRects[grtcairoNbRects].r_ul.p_y = r->r_ur.p_y;
|
||||
|
||||
grtcairoRects[grtcairoNbRects].r_lr.p_x = r->r_ur.p_x;
|
||||
grtcairoRects[grtcairoNbRects].r_lr.p_y = r->r_ll.p_y;
|
||||
#endif
|
||||
|
||||
grtcairoNbRects++;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglFillPolygon:
|
||||
* grtcairoFillPolygon:
|
||||
* This routine draws a solid (convex) polygon
|
||||
*
|
||||
* Results: None.
|
||||
@@ -248,14 +204,6 @@ Point *tp;
|
||||
int np;
|
||||
{
|
||||
int i;
|
||||
/*
|
||||
glEnable(GL_POLYGON_SMOOTH);
|
||||
glBegin(GL_POLYGON);
|
||||
for (i = 0; i < np; i++)
|
||||
glVertex2i(tp[i].p_x, tp[i].p_y);
|
||||
glEnd();
|
||||
glDisable(GL_POLYGON_SMOOTH);
|
||||
*/
|
||||
cairo_move_to(grCairoContext, tp[0].p_x, tp[0].p_y);
|
||||
for (i = 1; i < np; i++)
|
||||
cairo_line_to(grCairoContext, tp[i].p_x, tp[i].p_y);
|
||||
|
||||
+22
-282
@@ -1,22 +1,17 @@
|
||||
/* grTOGL3.c -
|
||||
/* grTCairo3.c -
|
||||
*
|
||||
* Copyright 2003 Open Circuit Design, Inc., for MultiGiG Ltd.
|
||||
* Copyright 2017 Open Circuit Design
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Written by Chuan Chen
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glu.h>
|
||||
*/
|
||||
|
||||
#include <cairo/cairo-xlib.h>
|
||||
|
||||
#include <math.h>
|
||||
@@ -33,7 +28,6 @@
|
||||
#include "utils/signals.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/hash.h"
|
||||
//#include "graphics/grTOGLInt.h"
|
||||
#include "graphics/grTCairoInt.h"
|
||||
#include "graphics/grTkCommon.h"
|
||||
#include "database/fonts.h"
|
||||
@@ -46,11 +40,9 @@ static GC grXcopyGC = (GC)NULL;
|
||||
|
||||
/* locals */
|
||||
|
||||
//GLuint grXBases[4];
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglDrawGrid:
|
||||
* grtcairoDrawGrid:
|
||||
* grxDrawGrid adds a grid to the grid layer, using the current
|
||||
* write mask and color.
|
||||
*
|
||||
@@ -88,18 +80,12 @@ Rect *clip; /* a clipping rectangle */
|
||||
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++;
|
||||
@@ -111,23 +97,19 @@ Rect *clip; /* a clipping rectangle */
|
||||
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.
|
||||
* grtcairoLoadFont
|
||||
* This local routine loads the default ("toy API")
|
||||
* font for Cairo.
|
||||
*
|
||||
* Results: Success/Failure
|
||||
*
|
||||
@@ -138,28 +120,13 @@ Rect *clip; /* a clipping rectangle */
|
||||
bool
|
||||
grtcairoLoadFont()
|
||||
{
|
||||
/*
|
||||
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]);
|
||||
}
|
||||
*/
|
||||
cairo_select_font_face(grCairoContext, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglSetCharSize:
|
||||
* grtcairoSetCharSize:
|
||||
* This local routine sets the character size in the display,
|
||||
* if necessary.
|
||||
*
|
||||
@@ -200,7 +167,7 @@ int size; /* Width of characters, in pixels (6 or 8). */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* GrTOGLTextSize --
|
||||
* GrTCairoTextSize --
|
||||
*
|
||||
* Determine the size of a text string.
|
||||
*
|
||||
@@ -254,16 +221,11 @@ Rect *r;
|
||||
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. */
|
||||
/* Cairo backing store functions (now removed from the X11-based ones) */
|
||||
|
||||
void
|
||||
grtcairoFreeBackingStore(MagWindow *window)
|
||||
{
|
||||
//window->w_backingStore = (ClientData)0;
|
||||
Pixmap pmap = (Pixmap)window->w_backingStore;
|
||||
if (pmap == (Pixmap)NULL) return;
|
||||
XFreePixmap(grXdpy, pmap);
|
||||
@@ -274,7 +236,6 @@ void
|
||||
grtcairoCreateBackingStore(MagWindow *w)
|
||||
{
|
||||
Pixmap pmap;
|
||||
//Window wind = (Window)w->w_grdata;
|
||||
Tk_Window tkwind = (Tk_Window)w->w_grdata;
|
||||
Window wind;
|
||||
unsigned int width, height;
|
||||
@@ -282,18 +243,12 @@ grtcairoCreateBackingStore(MagWindow *w)
|
||||
XGCValues gcValues;
|
||||
int grDepth;
|
||||
|
||||
|
||||
|
||||
/* ignore all windows other than layout */
|
||||
//if (w->w_client != DBWclientID) return;
|
||||
|
||||
/* Deferred */
|
||||
if (tkwind == NULL) return;
|
||||
|
||||
//w->w_backingStore = (ClientData)1;
|
||||
|
||||
wind = (Window)Tk_WindowId(tkwind);
|
||||
|
||||
/* ignore all windows other than layout */
|
||||
if (w->w_client != DBWclientID) return;
|
||||
|
||||
/* deferred */
|
||||
@@ -312,9 +267,6 @@ grtcairoCreateBackingStore(MagWindow *w)
|
||||
|
||||
grDepth = Tk_Depth((Tk_Window)w->w_grdata);
|
||||
|
||||
//if (grClass == 3) grDepth = 8; /* Needed since grDisplay.depth is reset
|
||||
// to 7 if Pseudocolor */
|
||||
|
||||
pmap = XCreatePixmap(grXdpy, wind, width, height, grDepth);
|
||||
w->w_backingStore = (ClientData)pmap;
|
||||
}
|
||||
@@ -326,9 +278,6 @@ grtcairoGetBackingStore(MagWindow *w, Rect *area)
|
||||
int xbot, ybot;
|
||||
Rect r;
|
||||
|
||||
// GLboolean result;
|
||||
// GLint rasterpos[4];
|
||||
|
||||
if (w->w_backingStore == (ClientData)0) return FALSE;
|
||||
|
||||
GEO_EXPAND(area, 1, &r);
|
||||
@@ -340,25 +289,6 @@ grtcairoGetBackingStore(MagWindow *w, Rect *area)
|
||||
xbot = r.r_xbot;
|
||||
ybot = r.r_ybot;
|
||||
|
||||
/*
|
||||
glDrawBuffer(GL_FRONT);
|
||||
glReadBuffer(GL_BACK);
|
||||
glRasterPos2i((GLint)xbot, (GLint)ybot);
|
||||
*/
|
||||
/* 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);
|
||||
/*
|
||||
glDisable(GL_BLEND);
|
||||
glCopyPixels(xbot, ybot, width, height, GL_COLOR);
|
||||
*/
|
||||
|
||||
Window root_return;
|
||||
int x_return, y_return;
|
||||
unsigned int width_return, height_return;
|
||||
@@ -374,7 +304,6 @@ grtcairoGetBackingStore(MagWindow *w, Rect *area)
|
||||
|
||||
cairo_surface_t *backingStoreSurface;
|
||||
backingStoreSurface = cairo_xlib_surface_create(grXdpy, pmap, DefaultVisual(grXdpy, DefaultScreen(grXdpy)), width_return, height_return);
|
||||
// backingStoreSurface = cairo_xlib_surface_create(grXdpy, pmap, DefaultVisual(grXdpy, DefaultScreen(grXdpy)), width, height);
|
||||
cairo_set_source_surface(grCairoContext, backingStoreSurface, 0, 0);
|
||||
cairo_rectangle(grCairoContext, xbot, ybot, width, height);
|
||||
cairo_set_operator(grCairoContext, CAIRO_OPERATOR_SOURCE);
|
||||
@@ -387,53 +316,7 @@ grtcairoGetBackingStore(MagWindow *w, Rect *area)
|
||||
bool
|
||||
grtcairoScrollBackingStore(MagWindow *w, Point *shift)
|
||||
{
|
||||
/*
|
||||
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;
|
||||
*/
|
||||
|
||||
// copied from grX11su3.c
|
||||
// (copied from grX11su3.c)
|
||||
Pixmap pmap;
|
||||
unsigned int width, height;
|
||||
int xorigin, yorigin, xshift, yshift;
|
||||
@@ -470,17 +353,11 @@ grtcairoScrollBackingStore(MagWindow *w, Point *shift)
|
||||
yshift = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
XCopyArea(grXdpy, pmap, pmap, grXcopyGC, xorigin, yorigin, width, height,
|
||||
xshift, yshift);
|
||||
*/
|
||||
|
||||
/* TxPrintf("grx11ScrollBackingStore %d %d\n", shift->p_x, shift->p_y); */
|
||||
|
||||
cairo_surface_t *backingStoreSurface;
|
||||
backingStoreSurface = cairo_xlib_surface_create(grXdpy, pmap, DefaultVisual(grXdpy, DefaultScreen(grXdpy)), width, height);
|
||||
cairo_set_source_surface(grCairoContext, backingStoreSurface, xshift, yshift);
|
||||
//cairo_rectangle(grCairoContext, xorigin, yorigin, width, height);
|
||||
cairo_rectangle(grCairoContext, xshift, yshift, width, height);
|
||||
cairo_set_operator(grCairoContext, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_fill(grCairoContext);
|
||||
@@ -494,9 +371,6 @@ grtcairoPutBackingStore(MagWindow *w, Rect *area)
|
||||
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;
|
||||
@@ -514,26 +388,6 @@ grtcairoPutBackingStore(MagWindow *w, Rect *area)
|
||||
height -= ybot;
|
||||
ybot = 0;
|
||||
}
|
||||
/*
|
||||
glReadBuffer(GL_FRONT);
|
||||
glDrawBuffer(GL_BACK);
|
||||
glRasterPos2i((GLint)xbot, (GLint)ybot);
|
||||
*/
|
||||
// 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);
|
||||
/*
|
||||
glDisable(GL_BLEND);
|
||||
glCopyPixels(xbot, ybot, width, height, GL_COLOR);
|
||||
|
||||
glDrawBuffer(GL_FRONT); // Return to normal front rendering
|
||||
*/
|
||||
|
||||
Window root_return;
|
||||
int x_return, y_return;
|
||||
@@ -548,7 +402,6 @@ grtcairoPutBackingStore(MagWindow *w, Rect *area)
|
||||
XGetGeometry(grXdpy, pmap, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return);
|
||||
|
||||
cairo_surface_t *backingStoreSurface;
|
||||
//backingStoreSurface = cairo_xlib_surface_create(grXdpy, pmap, DefaultVisual(grXdpy, DefaultScreen(grXdpy)), width_return, height_return);
|
||||
backingStoreSurface = cairo_xlib_surface_create(grXdpy, pmap, DefaultVisual(grXdpy, DefaultScreen(grXdpy)), width, height);
|
||||
cairo_t *tempContext = cairo_create(backingStoreSurface);
|
||||
cairo_set_source_surface(tempContext, grCairoSurface, 0.0, 0.0);
|
||||
@@ -564,7 +417,7 @@ grtcairoPutBackingStore(MagWindow *w, Rect *area)
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* GrTOGLReadPixel --
|
||||
* GrTCairoReadPixel --
|
||||
*
|
||||
* Read one pixel from the screen.
|
||||
*
|
||||
@@ -582,13 +435,13 @@ GrTCairoReadPixel (w, x, y)
|
||||
MagWindow *w;
|
||||
int x, y; /* the location of a pixel in screen coords */
|
||||
{
|
||||
return 0; /* OpenGL has no such function, so return 0 */
|
||||
return 0; /* (unimplemented) */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* GrTOGLBitBlt --
|
||||
* GrTCairoBitBlt --
|
||||
*
|
||||
* Copy information in bit block transfers.
|
||||
*
|
||||
@@ -605,51 +458,15 @@ GrTCairoBitBlt(r, p)
|
||||
Rect *r;
|
||||
Point *p;
|
||||
{
|
||||
/*
|
||||
glCopyPixels(r->r_xbot, r->r_ybot, r->r_xtop - r->r_xbot + 1,
|
||||
r->r_ytop - r->r_ybot + 1, GL_COLOR);
|
||||
*/
|
||||
|
||||
//cairo_set_source_surface(grCairoContext, grCairoSurface, p->p_x, p->p_y);
|
||||
// do some stuff
|
||||
|
||||
; // unimplemented
|
||||
// (unimplemented)
|
||||
}
|
||||
|
||||
#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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
// unused in cairo graphics
|
||||
void
|
||||
myCombine(GLdouble coords[3], GLdouble *vertex_data[4],
|
||||
GLfloat weight[4], GLdouble **outData, void *dataptr)
|
||||
{
|
||||
// This needs to be free'd at the end of gluTessEndPolygon()!
|
||||
GLdouble *new = (GLdouble *)mallocMagic(2 * sizeof(GLdouble));
|
||||
new[0] = coords[0];
|
||||
new[1] = coords[1];
|
||||
*outData = new;
|
||||
// Diagnostic
|
||||
TxError("Intersecting polygon in char \"%c\" at %g %g!\n",
|
||||
*((char *)dataptr), coords[0], coords[1]);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* 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.
|
||||
* This routine is similar to grtcairoFillPolygon()
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -662,8 +479,6 @@ int pixsize;
|
||||
Point *tp;
|
||||
int np, nptotal;
|
||||
int i, j;
|
||||
// static GLUtesselator *tess = NULL;
|
||||
// static GLdouble *v = NULL;
|
||||
static int maxnp = 0;
|
||||
FontChar *ccur;
|
||||
|
||||
@@ -679,67 +494,17 @@ int pixsize;
|
||||
}
|
||||
}
|
||||
cairo_fill(grCairoContext);
|
||||
|
||||
/*
|
||||
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));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
gluTessEndPolygon(tess);
|
||||
*/
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglFontText:
|
||||
* grtcairoFontText:
|
||||
*
|
||||
* 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!
|
||||
* For speed, should we be transferring the font
|
||||
* vectors into cairo glyphs?
|
||||
*
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
@@ -757,20 +522,11 @@ LinkedRect *obscure; /* List of obscuring areas */
|
||||
char *tptr;
|
||||
Point *coffset; /* vector to next character */
|
||||
Rect *cbbox;
|
||||
//GLfloat fsize, matvals[16];
|
||||
float fsize;
|
||||
FontChar *clist;
|
||||
int cheight, baseline;
|
||||
float tmp;
|
||||
|
||||
/* Keep it simple for now---ignore clip and obscure */
|
||||
/*
|
||||
glDisable(GL_BLEND);
|
||||
glPushMatrix();
|
||||
glTranslated(pos->p_x, pos->p_y, 0);
|
||||
glRotated(rotate, 0, 0, 1);
|
||||
*/
|
||||
|
||||
cairo_save(grCairoContext);
|
||||
cairo_translate(grCairoContext, pos->p_x, pos->p_y);
|
||||
cairo_rotate(grCairoContext, ((double)rotate) / 360 * 2 * M_PI);
|
||||
@@ -778,9 +534,7 @@ LinkedRect *obscure; /* List of obscuring areas */
|
||||
/* Get label size */
|
||||
cbbox = &DBFontList[font]->mf_extents;
|
||||
|
||||
//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);
|
||||
|
||||
/* Adjust to baseline */
|
||||
@@ -791,24 +545,21 @@ LinkedRect *obscure; /* List of obscuring areas */
|
||||
if (cbbox->r_ybot < baseline)
|
||||
baseline = cbbox->r_ybot;
|
||||
}
|
||||
//glTranslated(0, -baseline, 0);
|
||||
cairo_translate(grCairoContext, 0, -baseline);
|
||||
|
||||
for (tptr = text; *tptr != '\0'; tptr++)
|
||||
{
|
||||
DBFontChar(font, *tptr, &clist, &coffset, NULL);
|
||||
grtcairoDrawCharacter(clist, *tptr, size);
|
||||
//glTranslated(coffset->p_x, coffset->p_y, 0);
|
||||
cairo_translate(grCairoContext, coffset->p_x, coffset->p_y);
|
||||
}
|
||||
//glPopMatrix();
|
||||
cairo_restore(grCairoContext);
|
||||
}
|
||||
|
||||
#endif /* VECTOR_FONTS */
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* grtoglPutText:
|
||||
* grtcairoPutText:
|
||||
* (modified on SunPutText)
|
||||
*
|
||||
* This routine puts a chunk of text on the screen in the current
|
||||
@@ -867,19 +618,8 @@ LinkedRect *obscure; /* A list of obscuring rectangles */
|
||||
/* copy the text to the color screen */
|
||||
if ((overlap.r_xbot < overlap.r_xtop) && (overlap.r_ybot <= overlap.r_ytop))
|
||||
{
|
||||
//glScissor(overlap.r_xbot, overlap.r_ybot, overlap.r_xtop - overlap.r_xbot,
|
||||
// overlap.r_ytop - overlap.r_ybot);
|
||||
cairo_rectangle(grCairoContext, overlap.r_xbot, overlap.r_ybot, overlap.r_xtop - overlap.r_xbot, overlap.r_ytop - overlap.r_ybot);
|
||||
cairo_clip(grCairoContext);
|
||||
/*
|
||||
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);
|
||||
*/
|
||||
cairo_move_to(grCairoContext, location.r_xbot, location.r_ybot);
|
||||
cairo_show_text(grCairoContext, text);
|
||||
cairo_fill(grCairoContext);
|
||||
@@ -887,7 +627,7 @@ LinkedRect *obscure; /* A list of obscuring rectangles */
|
||||
}
|
||||
|
||||
|
||||
/* grTOGLGeoSub:
|
||||
/* grTCairoGeoSub:
|
||||
* return the tallest sub-rectangle of r not obscured by area
|
||||
* area must be within r.
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/* grTCairo4.c -
|
||||
*
|
||||
* Copyright 2003 Open Circuit Design, Inc., for MultiGiG Ltd.
|
||||
* Copyright 2017 Open Circuit Design
|
||||
*
|
||||
* This file contains functions to manage the graphics tablet associated
|
||||
* with the X display.
|
||||
*
|
||||
* Written by Chuan Chen
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
@@ -39,6 +40,7 @@ extern Display *grXdpy;
|
||||
void
|
||||
GrTCairoDisableTablet ()
|
||||
{
|
||||
/* (Unimplemented) */
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +59,7 @@ GrTCairoDisableTablet ()
|
||||
void
|
||||
GrTCairoEnableTablet ()
|
||||
{
|
||||
/* (Unimplemented) */
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-18
@@ -1,16 +1,15 @@
|
||||
/* grTOGL5.c -
|
||||
/* grTCairo5.c -
|
||||
*
|
||||
* Copyright 2003 Open Circuit Design, Inc., for MultiGiG Ltd.
|
||||
* Copyright 2017 Open Circuit Design
|
||||
*
|
||||
* Manipulate the programable cursor on the graphics display.
|
||||
*
|
||||
* Written by Chuan Chen
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
//#include <GL/gl.h>
|
||||
//#include <GL/glx.h>
|
||||
#include <cairo/cairo-xlib.h>
|
||||
|
||||
#include "tcltk/tclmagic.h"
|
||||
@@ -24,7 +23,6 @@
|
||||
#include "graphics/graphics.h"
|
||||
#include "graphics/graphicsInt.h"
|
||||
#include "grTkCommon.h"
|
||||
//#include "grTOGLInt.h"
|
||||
#include "grTCairoInt.h"
|
||||
|
||||
extern Display *grXdpy;
|
||||
@@ -35,7 +33,7 @@ extern cairo_t *grCairoContext;
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* GrTOGLDrawGlyph --
|
||||
* GrTCairoDrawGlyph --
|
||||
*
|
||||
* Draw one glyph on the display.
|
||||
*
|
||||
@@ -99,20 +97,15 @@ Point *p; /* screen pos of lower left corner */
|
||||
mask = GrStyleTable[thisp].mask << 1;
|
||||
color = GrStyleTable[thisp].color;
|
||||
GrGetColor(color, &red, &green, &blue);
|
||||
//glColor4ub((GLubyte)red, (GLubyte)green, (GLubyte)blue,
|
||||
// (GLubyte)mask);
|
||||
cairo_set_source_rgba(grCairoContext, ((float)red / 255), ((float)green / 255), ((float)blue / 255), ((float)mask / 127.0));
|
||||
//glBegin(GL_POINTS);
|
||||
}
|
||||
x1 = bBox.r_xbot + x;
|
||||
//glVertex2i((GLint)x1, (GLint)y1);
|
||||
cairo_rectangle(grCairoContext, x1, y1, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lastp != -1) {
|
||||
cairo_fill(grCairoContext);
|
||||
//glEnd();
|
||||
}
|
||||
} else {
|
||||
/* do pixel by pixel clipping */
|
||||
@@ -158,13 +151,8 @@ Point *p; /* screen pos of lower left corner */
|
||||
mask = GrStyleTable[*pixelp].mask << 1;
|
||||
color = GrStyleTable[*pixelp].color;
|
||||
GrGetColor(color, &red, &green, &blue);
|
||||
cairo_set_source_rbga(grCairoContext, ((float)red / 255), ((float)green / 255), ((float)blue / 255), ((float)mask / 127.0));
|
||||
cairo_set_source_rgba(grCairoContext, ((float)red / 255), ((float)green / 255), ((float)blue / 255), ((float)mask / 127.0));
|
||||
|
||||
//glColor4ub((GLubyte)red, (GLubyte)green,
|
||||
// (GLubyte)blue, (GLubyte)mask);
|
||||
//glBegin(GL_POINTS);
|
||||
//glVertex2i((GLint)startx, (GLint)yloc);
|
||||
//glEnd();
|
||||
cairo_rectangle(grCairoContext, startx, yloc, 1, 1);
|
||||
cairo_fill(grCairoContext);
|
||||
}
|
||||
@@ -181,7 +169,7 @@ Point *p; /* screen pos of lower left corner */
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* GrTOGLSetCursor:
|
||||
* GrTCairoSetCursor:
|
||||
*
|
||||
* Make the cursor be a new pattern, as defined in the display styles file.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user