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