2017-09-12 21:42:08 +02:00
|
|
|
|
/* grTCairo2.c -
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* Copyright 2017 Open Circuit Design
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
|
|
|
|
|
* This file contains additional functions to manipulate an X
|
|
|
|
|
|
* color display. Included here are rectangle drawing and color map
|
|
|
|
|
|
* loading.
|
2017-09-12 21:42:08 +02:00
|
|
|
|
*
|
|
|
|
|
|
* Written by Chuan Chen
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
char *getenv();
|
|
|
|
|
|
|
2017-08-30 22:34:42 +02:00
|
|
|
|
#include <cairo/cairo-xlib.h>
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
|
|
|
|
|
#include "tcltk/tclmagic.h"
|
|
|
|
|
|
#include "utils/magic.h"
|
|
|
|
|
|
#include "textio/textio.h"
|
|
|
|
|
|
#include "utils/geometry.h"
|
|
|
|
|
|
#include "graphics/glyphs.h"
|
|
|
|
|
|
#include "windows/windows.h"
|
|
|
|
|
|
#include "graphics/graphics.h"
|
|
|
|
|
|
#include "graphics/graphicsInt.h"
|
2017-08-08 21:00:19 +02:00
|
|
|
|
#include "grTCairoInt.h"
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
2017-09-05 05:20:22 +02:00
|
|
|
|
#include "textio/txcommands.h"
|
|
|
|
|
|
|
2017-08-08 21:00:19 +02:00
|
|
|
|
extern char *DBWStyleType;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
extern Display *grXdpy;
|
|
|
|
|
|
|
2017-09-05 05:20:22 +02:00
|
|
|
|
extern cairo_pattern_t *currentStipple;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* GrTCairoSetCMap --
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* Cairo uses RGB values as read from the colormap file,
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* directly, so there is no need to install colors into a
|
|
|
|
|
|
* colormap. Therefore, this is a null routine.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Results: None.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
|
|
|
|
|
* Side Effects: None.
|
|
|
|
|
|
*
|
|
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
GrTCairoSetCMap ()
|
2017-08-07 22:22:11 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-08-08 21:00:19 +02:00
|
|
|
|
Rect grtcairoLines[TCAIRO_BATCH_SIZE];
|
|
|
|
|
|
int grtcairoNbLines = 0;
|
|
|
|
|
|
TCairoRect grtcairoRects[TCAIRO_BATCH_SIZE];
|
|
|
|
|
|
int grtcairoNbRects = 0;
|
|
|
|
|
|
Rect grtcairoDiagonal[TCAIRO_BATCH_SIZE];
|
|
|
|
|
|
int grtcairoNbDiagonal = 0;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* grtcairoDrawLines:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* This routine draws a batch of lines.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Results: None.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
|
|
|
|
|
* Side Effects:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Draw a bunch of lines.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoDrawLines(lines, nb)
|
|
|
|
|
|
Rect lines[];
|
|
|
|
|
|
int nb;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
{
|
2017-09-14 23:03:53 +02:00
|
|
|
|
TCairoData *tcairodata = (TCairoData *)tcairoCurrent.mw->w_grdata2;
|
2017-08-08 21:00:19 +02:00
|
|
|
|
int i;
|
2017-09-14 23:03:53 +02:00
|
|
|
|
|
|
|
|
|
|
cairo_save(tcairodata->context);
|
2017-08-08 21:00:19 +02:00
|
|
|
|
for (i = 0; i < nb; i++)
|
|
|
|
|
|
{
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_move_to(tcairodata->context, lines[i].r_ll.p_x, lines[i].r_ll.p_y);
|
|
|
|
|
|
cairo_line_to(tcairodata->context, lines[i].r_ur.p_x, lines[i].r_ur.p_y);
|
2017-08-08 21:00:19 +02:00
|
|
|
|
}
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_stroke(tcairodata->context);
|
|
|
|
|
|
cairo_restore(tcairodata->context);
|
2017-08-07 22:22:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* grtcairoDrawLine:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* This routine draws a line.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Results: None.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
|
|
|
|
|
* Side Effects:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Draw a line for (x1, y1) to (x2, y2) inclusive.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoDrawLine (x1, y1, x2, y2)
|
|
|
|
|
|
int x1, y1; /* Screen coordinates of first point. */
|
|
|
|
|
|
int x2, y2; /* Screen coordinates of second point. */
|
2017-08-07 22:22:11 +02:00
|
|
|
|
{
|
2017-09-12 21:42:08 +02:00
|
|
|
|
/* Treat straight and diagonal lines separately. */
|
|
|
|
|
|
/* (Done for OpenGL; possibly not necessary for Cairo) */
|
2017-08-08 21:00:19 +02:00
|
|
|
|
|
|
|
|
|
|
if ((x1 == x2) || (y1 == y2))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (grtcairoNbLines == TCAIRO_BATCH_SIZE) GR_TCAIRO_FLUSH_LINES();
|
|
|
|
|
|
grtcairoLines[grtcairoNbLines].r_ll.p_x = x1;
|
|
|
|
|
|
grtcairoLines[grtcairoNbLines].r_ll.p_y = y1;
|
|
|
|
|
|
grtcairoLines[grtcairoNbLines].r_ur.p_x = x2;
|
|
|
|
|
|
grtcairoLines[grtcairoNbLines].r_ur.p_y = y2;
|
|
|
|
|
|
grtcairoNbLines++;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (grtcairoNbDiagonal == TCAIRO_BATCH_SIZE) GR_TCAIRO_FLUSH_DIAGONAL();
|
|
|
|
|
|
grtcairoDiagonal[grtcairoNbDiagonal].r_ll.p_x = x1;
|
|
|
|
|
|
grtcairoDiagonal[grtcairoNbDiagonal].r_ll.p_y = y1;
|
|
|
|
|
|
grtcairoDiagonal[grtcairoNbDiagonal].r_ur.p_x = x2;
|
|
|
|
|
|
grtcairoDiagonal[grtcairoNbDiagonal].r_ur.p_y = y2;
|
|
|
|
|
|
grtcairoNbDiagonal++;
|
|
|
|
|
|
}
|
2017-08-07 22:22:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* grtcairoFillRects:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* This routine draws a bunch of solid rectangles.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Results: None.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
|
|
|
|
|
* Side Effects:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Drawing.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoFillRects(rects, nb)
|
|
|
|
|
|
TCairoRect rects[];
|
|
|
|
|
|
int nb;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
{
|
2017-09-14 23:03:53 +02:00
|
|
|
|
TCairoData *tcairodata = (TCairoData *)tcairoCurrent.mw->w_grdata2;
|
2017-08-08 21:00:19 +02:00
|
|
|
|
int i;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_save(tcairodata->context);
|
2017-08-08 21:00:19 +02:00
|
|
|
|
for (i = 0; i < nb; i++)
|
|
|
|
|
|
{
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_rectangle(tcairodata->context,
|
2017-08-30 22:34:42 +02:00
|
|
|
|
rects[i].r_ll.p_x, rects[i].r_ll.p_y,
|
2017-09-01 06:39:19 +02:00
|
|
|
|
rects[i].r_ur.p_x-rects[i].r_ll.p_x, rects[i].r_ur.p_y-rects[i].r_ll.p_y);
|
2017-09-12 21:42:08 +02:00
|
|
|
|
// 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);
|
2017-08-08 21:00:19 +02:00
|
|
|
|
}
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_clip(tcairodata->context);
|
|
|
|
|
|
cairo_mask(tcairodata->context, currentStipple);
|
|
|
|
|
|
cairo_restore(tcairodata->context);
|
2017-08-07 22:22:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* grtcairoFillRect:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* This routine draws a solid rectangle.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Results: None.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
|
|
|
|
|
* Side Effects:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Drawing.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoFillRect(r)
|
|
|
|
|
|
Rect *r; /* Address of a rectangle in screen
|
|
|
|
|
|
* coordinates.
|
|
|
|
|
|
*/
|
2017-08-07 22:22:11 +02:00
|
|
|
|
{
|
2017-08-08 21:00:19 +02:00
|
|
|
|
if (grtcairoNbRects == TCAIRO_BATCH_SIZE) GR_TCAIRO_FLUSH_RECTS();
|
|
|
|
|
|
grtcairoRects[grtcairoNbRects].r_ll.p_x = r->r_ll.p_x;
|
|
|
|
|
|
grtcairoRects[grtcairoNbRects].r_ll.p_y = r->r_ll.p_y;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoRects[grtcairoNbRects].r_ur.p_x = r->r_ur.p_x;
|
|
|
|
|
|
grtcairoRects[grtcairoNbRects].r_ur.p_y = r->r_ur.p_y;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoRects[grtcairoNbRects].r_ul.p_x = r->r_ll.p_x;
|
|
|
|
|
|
grtcairoRects[grtcairoNbRects].r_ul.p_y = r->r_ur.p_y;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoRects[grtcairoNbRects].r_lr.p_x = r->r_ur.p_x;
|
|
|
|
|
|
grtcairoRects[grtcairoNbRects].r_lr.p_y = r->r_ll.p_y;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
|
2017-08-08 21:00:19 +02:00
|
|
|
|
grtcairoNbRects++;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------
|
2017-09-12 21:42:08 +02:00
|
|
|
|
* grtcairoFillPolygon:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* This routine draws a solid (convex) polygon
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*
|
|
|
|
|
|
* Results: None.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Side Effects:
|
2017-08-08 21:00:19 +02:00
|
|
|
|
* Drawing.
|
2017-08-07 22:22:11 +02:00
|
|
|
|
*---------------------------------------------------------
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-08-18 20:15:12 +02:00
|
|
|
|
grtcairoFillPolygon(tp, np)
|
2017-08-08 21:00:19 +02:00
|
|
|
|
Point *tp;
|
|
|
|
|
|
int np;
|
2017-08-07 22:22:11 +02:00
|
|
|
|
{
|
2017-09-14 23:03:53 +02:00
|
|
|
|
TCairoData *tcairodata = (TCairoData *)tcairoCurrent.mw->w_grdata2;
|
2017-08-08 21:00:19 +02:00
|
|
|
|
int i;
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_save(tcairodata->context);
|
|
|
|
|
|
cairo_move_to(tcairodata->context, tp[0].p_x, tp[0].p_y);
|
2017-08-08 21:00:19 +02:00
|
|
|
|
for (i = 1; i < np; i++)
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_line_to(tcairodata->context, tp[i].p_x, tp[i].p_y);
|
|
|
|
|
|
cairo_close_path(tcairodata->context);
|
2017-09-27 23:43:52 +02:00
|
|
|
|
cairo_clip(tcairodata->context);
|
|
|
|
|
|
cairo_mask(tcairodata->context, currentStipple);
|
2017-09-14 23:03:53 +02:00
|
|
|
|
cairo_restore(tcairodata->context);
|
2017-08-07 22:22:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|