File: XQtArrows.cpp

package info (click to toggle)
xpat2 1.07-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,212 kB
  • ctags: 2,097
  • sloc: ansic: 13,755; perl: 3,068; cpp: 2,935; makefile: 176; sh: 32
file content (148 lines) | stat: -rw-r--r-- 3,837 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* -*- C++ -*-	Time-stamp: <05 Nov 00 21:22:13 Michael Bischoff> */
/*****************************************************************************/
/*									     */
/*									     */
/*	X patience version 2 -- module XQtArrows.cpp			     */
/*									     */
/*	Displays hint arrows for the Qt widget set			     */
/*	written by Michael Bischoff					     */
/*	see COPYRIGHT.xpat2 for Copyright details			     */
/*									     */
/*									     */
/*****************************************************************************/
#include <qpixmap.h>
#include <qbitmap.h>
#include <qcolor.h>
#include <qbrush.h>
#include <qpainter.h>
#include <qpointarray.h>
#include <qwidget.h>
#include "XQtCardPile.h"
#include "XQtTableau.h"
extern "C" {
#include "xpatgeo.h"
}

extern XQtTableau *tableau;

static QBrush *arrow_brush = 0;
static QPainter arrow_painter;

#if 0
static struct arrow_storage {
    int w, h;
    QPixmap *arrow_storage;
} as[4] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };

extern "C" void bitblt_arrow(int type, int save, int x, int y, int w, int h) {
    struct arrow_storage *ap = as + type;
    if (save) {
	/* for for minimum size */
	if (!ap->arrow_storage || ap->w < w || ap->h < h) {
	    /* not allocated or insufficient size */
	    if (ap->arrow_storage)
		delete ap->arrow_storage;
	    if (ap->w < w)
		ap->w = w;
	    if (ap->h < h)
		ap->h = h;
	    ap->arrow_storage = new QPixmap(ap->w, ap->h);
	}
	bitBlt(ap->arrow_storage, 0, 0, tableau, x, y, w, h, CopyROP, FALSE);
    } else {
	if (ap->arrow_storage) {
	    bitBlt(tableau, x, y, ap->arrow_storage, 0, 0, w, h, CopyROP, FALSE);
	}
    }
}

extern "C" void draw_arrow_polygon(int npoints, const struct Coord *poly) {
    int i;
    QPointArray Poly(ARROW_MAX_COORDINATES);

    printf("drawing polygon on %x\n", tableau);
    for (i = 0; i < npoints; ++i)
	Poly.setPoint(i, poly[i].x, poly[i].y);

    if (!arrow_brush)
	arrow_brush = new QBrush("yellow");

    arrow_painter.begin(tableau);
    arrow_painter.setBrush(*arrow_brush);
    arrow_painter.drawPolygon(Poly, FALSE, 0, npoints);
    arrow_painter.end();
}

#else

static QWidget *aw = 0;
static QPixmap *apix =0;
static QBitmap *aclip = 0;

extern "C" void bitblt_arrow(int type, int save, int x, int y, int w, int h) {
    if (!save && aw) {
	delete aw;
	delete apix;
	delete aclip;
	aw = 0;
	apix = 0;
	aclip = 0;
    }
}

extern "C" void draw_arrow_polygon(int npoints, const struct Coord *poly) {
    int i, maxx, maxy, minx, miny, w, h;
    QPointArray Poly(ARROW_MAX_COORDINATES);

//    printf("drawing polygon on %x\n", tableau);
    minx = maxx = poly[0].x;
    miny = maxy = poly[0].y;
    for (i = 1; i < npoints; ++i) {
	if (poly[i].x < minx)
	    minx = poly[i].x;
	if (poly[i].x > maxx)
	    maxx = poly[i].x;
	if (poly[i].y < miny)
	    miny = poly[i].y;
	if (poly[i].y > maxy)
	    maxy = poly[i].y;
    }
    if (aw) {
	delete aw;
	delete apix;
	delete aclip;
    }
    w = maxx-minx+1;
    h = maxy-miny+1;
    aclip = new QBitmap(w, h, TRUE);
    apix = new QPixmap(w, h);
    aw = new QWidget(tableau);
    aw->move(minx, miny);
    aw->resize(w, h);

    for (i = 0; i < npoints; ++i)
	Poly.setPoint(i, poly[i].x-minx, poly[i].y-miny);

    if (!arrow_brush)
	arrow_brush = new QBrush("yellow");

    arrow_painter.begin(apix);
    arrow_painter.setBrush(*arrow_brush);
    arrow_painter.drawPolygon(Poly, FALSE, 0, npoints);
    arrow_painter.end();
    arrow_painter.begin(aclip);
    arrow_painter.setPen(Qt::color1);
//    arrow_painter.setBrush(Dense3Pattern);
//    arrow_painter.setBrush(SolidPattern);
    arrow_painter.setBrush(Qt::color1);
    arrow_painter.drawPolygon(Poly, FALSE, 0, npoints);
    arrow_painter.end();

    aw->setMask(*aclip);
    aw->setBackgroundPixmap(*apix);
    aw->show();
    aw->move(minx, miny);
    aw->raise();
}

#endif