source: Sophya/trunk/Poubelle/PI/pipixmapx.cc

Last change on this file was 222, checked in by ansari, 26 years ago

Creation module DPC/PI Reza 09/04/99

File size: 3.3 KB
Line 
1#include <stdio.h>
2
3#include <X11/Xlib.h>
4#include <X11/Xutil.h>
5#include <X11/Xatom.h>
6
7#include "pipixmapx.h"
8
9static GC mygc;
10
11/* --Methode-- */
12PIPixmapX::PIPixmapX(PIContainerGen *par, char *nom,
13 int sx, int sy, int px, int py)
14: PIPixmapGen(par,nom,sx,sy,px,py)
15{
16Init();
17AllocXImg();
18}
19
20
21/* --Methode-- */
22PIPixmapX::~PIPixmapX()
23{
24delete[] myximg->data;
25XFree(myximg);
26}
27
28/* --Methode-- */
29void PIPixmapX::Refresh()
30{
31int i,j;
32unsigned char *pp;
33
34if (pixmap)
35 {
36 for(j=0; j<ny; j++)
37 {
38 pp = pixmap+j*nx;
39 for(i=0; i<nx; i++)
40 { XPutPixel(myximg, i, j, cmap->Color(*pp) ); pp++; }
41 }
42 }
43
44for(j=ny; j<YSize(); j++)
45 for(i=nx; i<XSize(); i++)
46 XPutPixel(myximg, i, j, 0 );
47
48PIBaseWdgX::Refresh();
49}
50
51
52/* --Methode-- */
53void PIPixmapX::Resize()
54{
55delete[] myximg->data;
56XFree(myximg);
57AllocXImg();
58if (Msg()) Send(Msg(), PIMsg_Resize, mPpos);
59}
60
61/*DEL07 --Methode--
62void PIPixmapX::Draw(PIGraphicGen* g)
63{
64if (!pixmap) return;
65if (!g) return;
66if (g->kind() == PI_PSFileGraphics ) {
67 g->DrawPixmap(ofx, ofy, pixmap, nx, ny, cmap);
68 // Il faut faire quelque chose Sinon ??!
69 }
70else Draw(g, 0, 0, XSize(), YSize());
71}
72*/
73
74/* --Methode-- */
75void PIPixmapX::Draw(PIGraphic* g, int x0, int y0, int dx, int dy)
76{
77
78if (!g) return;
79if ((myximg == NULL) || (cmap == NULL)) return;
80
81if (g->kind() == PI_PSFileGraphics ) {
82 if (pixmap) g->DrawPixmap(ofx, ofy, pixmap, nx, ny, cmap);
83 return;
84 }
85
86Window xw = XtWindow(XtWdg());
87Display * mdsp = PIXDisplay();
88
89int mx, my, ox, oy;
90
91if (x0 < 0) x0 = 0;
92if (y0 < 0) y0 = 0;
93mx = nx+ofx; my = ny+ofy;
94if (dx > (XSize()-x0)) dx = XSize()-x0;
95if (dy > (YSize()-y0)) dy = YSize()-y0;
96if ((dx <= 0) || (dy <= 0)) return;
97
98if ( (mx < x0 ) || (my < y0) )
99 { XClearArea(mdsp, xw, x0, y0, dx, dy, False); return; }
100
101ox = oy = 0;
102
103if (ofx > x0)
104 { XClearArea(mdsp, xw, x0, y0, ofx-x0, dy, False);
105 dx -= (ofx-x0); x0 = ofx; ox = 0; }
106else ox = x0-ofx;
107if (ofy > y0)
108 { XClearArea(mdsp, xw, x0, y0, dx, ofy-y0, False);
109 dy -= (ofy-y0); y0 = ofy; oy = 0; }
110else oy = y0-ofy;
111
112if (mx < (x0+dx))
113 { XClearArea(mdsp, xw, mx, y0, x0+dx-mx, dy, False); dx = mx-x0; }
114if (my < (y0+dy))
115 { XClearArea(mdsp, xw, x0, my, dx, y0+dy-my, False); dy = my-y0; }
116
117XPutImage(mdsp, xw, mygc, myximg, ox, oy, x0, y0, dx, dy);
118XFlush(mdsp);
119return;
120
121}
122
123static bool fgxpxm = false;
124
125
126/* --Methode-- */
127void PIPixmapX::Init()
128{
129XGCValues values;
130XtGCMask mask;
131
132if (fgxpxm) return;
133fgxpxm = true;
134
135
136mask = GCFunction | GCPlaneMask;
137// mask = GCForeground | GCBackground;
138values.function = GXcopy;
139values.plane_mask = ~0;
140// values.foreground = WhitePixel(mdsp, scr);
141// values.background = BlackPixel(mdsp, scr);
142mygc = XtGetGC(XtWdg(), mask, &values);
143
144return;
145}
146
147
148/* --Methode-- */
149void PIPixmapX::AllocXImg()
150{
151Display * mdsp;
152int scr;
153int depth;
154int pad;
155int i,j;
156
157mdsp = PIXDisplay();
158scr = PIXScreen();
159
160depth = DefaultDepth(mdsp,scr);
161pad = (depth > 8) ? 32 : 8;
162myximg = XCreateImage (mdsp,DefaultVisual(mdsp,scr),
163 depth,ZPixmap,0,NULL, XSize(), YSize(), pad,0);
164if (myximg == NULL) return;
165myximg->data = new char [YSize()*myximg->bytes_per_line];
166if (myximg->data == NULL)
167 { XFree(myximg); myximg = NULL; return; }
168
169for(j=0; j<YSize(); j++)
170 for(i=0; i<XSize(); i++)
171 XPutPixel(myximg, i, j, 0 );
172
173return;
174}
Note: See TracBrowser for help on using the repository browser.