49 #include <X11/Xutil.h>
50 #include <X11/Xatom.h>
51 #include <X11/cursorfont.h>
52 #include <X11/keysym.h>
61 # include <sys/socket.h>
64 extern float XRotVersion(
char*,
int);
65 extern void XRotSetMagnification(
float);
66 extern void XRotSetBoundingBoxPad(
int);
67 extern int XRotDrawString(Display*, XFontStruct*,
float,
68 Drawable, GC,
int,
int,
char*);
69 extern int XRotDrawImageString(Display*, XFontStruct*,
float,
70 Drawable, GC,
int,
int,
char*);
71 extern int XRotDrawAlignedString(Display*, XFontStruct*,
float,
72 Drawable, GC,
int,
int,
char*,
int);
73 extern int XRotDrawAlignedImageString(Display*, XFontStruct*,
float,
74 Drawable, GC,
int,
int,
char*,
int);
75 extern XPoint *XRotTextExtents(Display*, XFontStruct*,
float,
76 int,
int,
char*,
int);
80 static XWindow_t *gCws;
81 static XWindow_t *gTws;
83 const Int_t kBIGGEST_RGB_VALUE = 65535;
89 static GC gGClist[kMAXGC];
90 static GC *gGCline = &gGClist[0];
91 static GC *gGCmark = &gGClist[1];
92 static GC *gGCfill = &gGClist[2];
93 static GC *gGCtext = &gGClist[3];
94 static GC *gGCinvt = &gGClist[4];
95 static GC *gGCdash = &gGClist[5];
96 static GC *gGCpxmp = &gGClist[6];
100 static Int_t gFillHollow;
101 static Pixmap gFillPattern = 0;
106 const Int_t kMAXFONT = 4;
112 static XFontStruct *gTextFont;
113 static Int_t gCurrentFontNumber = 0;
118 const Int_t kMAXMK = 100;
128 static int gLineWidth = 0;
129 static int gLineStyle = LineSolid;
130 static int gCapStyle = CapButt;
131 static int gJoinStyle = JoinMiter;
132 static char gDashList[10];
133 static int gDashLength = 0;
134 static int gDashOffset = 0;
135 static int gDashSize = 0;
140 static ULong_t gMouseMask = ButtonPressMask | ButtonReleaseMask |
141 EnterWindowMask | LeaveWindowMask |
142 PointerMotionMask | KeyPressMask |
144 static ULong_t gKeybdMask = ButtonPressMask | KeyPressMask |
145 EnterWindowMask | LeaveWindowMask;
150 const char null_cursor_bits[] = {
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
154 static Cursor gNullCursor = 0;
156 struct RXGCValues:XGCValues{};
157 struct RXColor:XColor{};
158 struct RXImage:XImage{};
159 struct RXPoint:XPoint{};
160 struct RXVisualInfo:XVisualInfo{};
161 struct RVisual:Visual{};
181 fXEvent =
new XEvent;
191 fHasTTFonts = kFALSE;
193 fMaxNumberOfWindows = 10;
198 for (i = 0; i < kNumCursors; i++) fCursors[i] = 0;
204 TGX11::TGX11(
const char *name,
const char *title) : TVirtualX(name, title)
216 fXEvent =
new XEvent;
226 fHasTTFonts = kFALSE;
228 fMaxNumberOfWindows = 10;
233 for (i = 0; i < kNumCursors; i++) fCursors[i] = 0;
236 fWindows = (XWindow_t*) TStorage::Alloc(fMaxNumberOfWindows*
sizeof(XWindow_t));
237 for (i = 0; i < fMaxNumberOfWindows; i++)
238 fWindows[i].fOpen = 0;
240 fColors =
new TExMap;
246 TGX11::TGX11(
const TGX11 &org) : TVirtualX(org)
250 fDisplay = org.fDisplay;
251 fScreenNumber = org.fScreenNumber;
252 fVisual = org.fVisual;
253 fRootWin = org.fRootWin;
254 fVisRootWin = org.fVisRootWin;
255 fColormap = org.fColormap;
256 fBlackPixel = org.fBlackPixel;
257 fWhitePixel = org.fWhitePixel;
258 fHasTTFonts = org.fHasTTFonts;
259 fHasXft = org.fHasXft;
260 fTextAlignH = org.fTextAlignH;
261 fTextAlignV = org.fTextAlignV;
262 fTextAlign = org.fTextAlign;
263 fTextMagnitude = org.fTextMagnitude;
264 fCharacterUpX = org.fCharacterUpX;
265 fCharacterUpY = org.fCharacterUpY;
267 fRedDiv = org.fRedDiv;
268 fGreenDiv = org.fGreenDiv;
269 fBlueDiv = org.fBlueDiv;
270 fRedShift = org.fRedShift;
271 fGreenShift = org.fGreenShift;
272 fBlueShift = org.fBlueShift;
273 fDrawMode = org.fDrawMode;
274 fXEvent =
new XEvent;
276 fMaxNumberOfWindows = org.fMaxNumberOfWindows;
278 fWindows = (XWindow_t*) TStorage::Alloc(fMaxNumberOfWindows*
sizeof(XWindow_t));
279 for (i = 0; i < fMaxNumberOfWindows; i++) {
280 fWindows[i].fOpen = org.fWindows[i].fOpen;
281 fWindows[i].fDoubleBuffer = org.fWindows[i].fDoubleBuffer;
282 fWindows[i].fIsPixmap = org.fWindows[i].fIsPixmap;
283 fWindows[i].fDrawing = org.fWindows[i].fDrawing;
284 fWindows[i].fWindow = org.fWindows[i].fWindow;
285 fWindows[i].fBuffer = org.fWindows[i].fBuffer;
286 fWindows[i].fWidth = org.fWindows[i].fWidth;
287 fWindows[i].fHeight = org.fWindows[i].fHeight;
288 fWindows[i].fClip = org.fWindows[i].fClip;
289 fWindows[i].fXclip = org.fWindows[i].fXclip;
290 fWindows[i].fYclip = org.fWindows[i].fYclip;
291 fWindows[i].fWclip = org.fWindows[i].fWclip;
292 fWindows[i].fHclip = org.fWindows[i].fHclip;
293 fWindows[i].fNewColors = org.fWindows[i].fNewColors;
294 fWindows[i].fNcolors = org.fWindows[i].fNcolors;
295 fWindows[i].fShared = org.fWindows[i].fShared;
298 for (i = 0; i < kNumCursors; i++)
299 fCursors[i] = org.fCursors[i];
301 fColors =
new TExMap;
303 TExMapIter it(org.fColors);
304 while (it.Next(key, value)) {
305 XColor_t *colo = (XColor_t *) (Long_t)value;
306 XColor_t *col =
new XColor_t;
307 col->fPixel = colo->fPixel;
308 col->fRed = colo->fRed;
309 col->fGreen = colo->fGreen;
310 col->fBlue = colo->fBlue;
311 col->fDefined = colo->fDefined;
312 fColors->Add(key, (Long_t) col);
321 delete (XEvent*)fXEvent;
322 if (fWindows) TStorage::Dealloc(fWindows);
324 if (!fColors)
return;
326 TExMapIter it(fColors);
327 while (it.Next(key, value)) {
328 XColor_t *col = (XColor_t *) (Long_t)value;
337 Bool_t TGX11::Init(
void *display)
339 if (OpenDisplay((Display *) display) == -1)
return kFALSE;
361 Bool_t TGX11::AllocColor(Colormap cmap, RXColor *color)
364 if (XAllocColor((Display*)fDisplay, cmap, color))
367 color->pixel = (color->red >> fRedDiv) << fRedShift |
368 (color->green >> fGreenDiv) << fGreenShift |
369 (color->blue >> fBlueDiv) << fBlueShift;
378 void TGX11::QueryColors(Colormap cmap, RXColor *color, Int_t ncolors)
381 XQueryColors((Display*)fDisplay, cmap, color, ncolors);
384 for (Int_t i = 0; i < ncolors; i++) {
385 r = (color[i].pixel & fVisual->red_mask) >> fRedShift;
386 color[i].red = UShort_t(r*kBIGGEST_RGB_VALUE/(fVisual->red_mask >> fRedShift));
388 g = (color[i].pixel & fVisual->green_mask) >> fGreenShift;
389 color[i].green = UShort_t(g*kBIGGEST_RGB_VALUE/(fVisual->green_mask >> fGreenShift));
391 b = (color[i].pixel & fVisual->blue_mask) >> fBlueShift;
392 color[i].blue = UShort_t(b*kBIGGEST_RGB_VALUE/(fVisual->blue_mask >> fBlueShift));
394 color[i].flags = DoRed | DoGreen | DoBlue;
402 void TGX11::ClearPixmap(Drawable *pix)
406 unsigned int ww, hh, border, depth;
407 XGetGeometry((Display*)fDisplay, *pix, &root, &xx, &yy, &ww, &hh, &border, &depth);
408 SetColor(gGCpxmp, 0);
409 XFillRectangle((Display*)fDisplay, *pix, *gGCpxmp, 0 ,0 ,ww ,hh);
410 SetColor(gGCpxmp, 1);
411 XFlush((Display*)fDisplay);
417 void TGX11::ClearWindow()
419 if (!gCws->fIsPixmap && !gCws->fDoubleBuffer) {
420 XSetWindowBackground((Display*)fDisplay, gCws->fDrawing, GetColor(0).fPixel);
421 XClearWindow((Display*)fDisplay, gCws->fDrawing);
422 XFlush((Display*)fDisplay);
424 SetColor(gGCpxmp, 0);
425 XFillRectangle((Display*)fDisplay, gCws->fDrawing, *gGCpxmp,
426 0, 0, gCws->fWidth, gCws->fHeight);
427 SetColor(gGCpxmp, 1);
434 void TGX11::ClosePixmap()
442 void TGX11::CloseWindow()
456 void TGX11::CloseWindow1()
461 XFreePixmap((Display*)fDisplay, gCws->fWindow);
463 XDestroyWindow((Display*)fDisplay, gCws->fWindow);
465 if (gCws->fBuffer) XFreePixmap((Display*)fDisplay, gCws->fBuffer);
467 if (gCws->fNewColors) {
469 XFreeColors((Display*)fDisplay, fColormap, gCws->fNewColors, gCws->fNcolors, 0);
470 delete [] gCws->fNewColors;
471 gCws->fNewColors = 0;
474 XFlush((Display*)fDisplay);
479 for (wid = 0; wid < fMaxNumberOfWindows; wid++)
480 if (fWindows[wid].fOpen) {
481 gCws = &fWindows[wid];
491 void TGX11::CopyPixmap(
int wid,
int xpos,
int ypos)
493 gTws = &fWindows[wid];
495 XCopyArea((Display*)fDisplay, gTws->fDrawing, gCws->fDrawing, *gGCpxmp, 0, 0, gTws->fWidth,
496 gTws->fHeight, xpos, ypos);
497 XFlush((Display*)fDisplay);
503 void TGX11::CopyWindowtoPixmap(Drawable *pix,
int xpos,
int ypos )
507 unsigned int ww, hh, border, depth;
509 XGetGeometry((Display*)fDisplay, *pix, &root, &xx, &yy, &ww, &hh, &border, &depth);
510 XCopyArea((Display*)fDisplay, gCws->fDrawing, *pix, *gGCpxmp, xpos, ypos, ww, hh, 0, 0);
511 XFlush((Display*)fDisplay);
520 void TGX11::DrawBox(
int x1,
int y1,
int x2,
int y2, EBoxMode mode)
522 Int_t x = TMath::Min(x1, x2);
523 Int_t y = TMath::Min(y1, y2);
524 Int_t w = TMath::Abs(x2 - x1);
525 Int_t h = TMath::Abs(y2 - y1);
530 XDrawRectangle((Display*)fDisplay, gCws->fDrawing, *gGCline, x, y, w, h);
534 XFillRectangle((Display*)fDisplay, gCws->fDrawing, *gGCfill, x, y, w, h);
554 void TGX11::DrawCellArray(
int x1,
int y1,
int x2,
int y2,
int nx,
int ny,
int *ic)
556 int i, j, icol, ix, iy, w, h, current_icol;
559 w = TMath::Max((x2-x1)/(nx),1);
560 h = TMath::Max((y1-y2)/(ny),1);
563 for (i = 0; i < nx; i++) {
565 for (j = 0; j < ny; j++) {
567 if (icol != current_icol) {
568 XSetForeground((Display*)fDisplay, *gGCfill, GetColor(icol).fPixel);
571 XFillRectangle((Display*)fDisplay, gCws->fDrawing, *gGCfill, ix, iy, w, h);
584 void TGX11::DrawFillArea(
int n, TPoint *xyt)
586 XPoint *xy = (XPoint*)xyt;
589 XDrawLines((Display*)fDisplay, gCws->fDrawing, *gGCfill, xy, n, CoordModeOrigin);
592 XFillPolygon((Display*)fDisplay, gCws->fDrawing, *gGCfill,
593 xy, n, Nonconvex, CoordModeOrigin);
603 void TGX11::DrawLine(
int x1,
int y1,
int x2,
int y2)
605 if (gLineStyle == LineSolid)
606 XDrawLine((Display*)fDisplay, gCws->fDrawing, *gGCline, x1, y1, x2, y2);
608 XSetDashes((Display*)fDisplay, *gGCdash, gDashOffset, gDashList, gDashSize);
609 XDrawLine((Display*)fDisplay, gCws->fDrawing, *gGCdash, x1, y1, x2, y2);
619 void TGX11::DrawPolyLine(
int n, TPoint *xyt)
621 XPoint *xy = (XPoint*)xyt;
623 const Int_t kMaxPoints = 1000001;
625 if (n > kMaxPoints) {
627 int iend = kMaxPoints - 1;
629 DrawPolyLine( kMaxPoints, &xyt[ibeg] );
631 iend += kMaxPoints - 1;
635 DrawPolyLine( npt, &xyt[ibeg] );
638 if (gLineStyle == LineSolid)
639 XDrawLines((Display*)fDisplay, gCws->fDrawing, *gGCline, xy, n, CoordModeOrigin);
642 XSetDashes((Display*)fDisplay, *gGCdash,
643 gDashOffset, gDashList, gDashSize);
644 XDrawLines((Display*)fDisplay, gCws->fDrawing, *gGCdash, xy, n, CoordModeOrigin);
647 for (i = 1; i < n; i++) {
648 int dx = xy[i].x - xy[i-1].x;
649 int dy = xy[i].y - xy[i-1].y;
650 if (dx < 0) dx = - dx;
651 if (dy < 0) dy = - dy;
652 gDashOffset += dx > dy ? dx : dy;
654 gDashOffset %= gDashLength;
660 XDrawPoint((Display*)fDisplay, gCws->fDrawing,
661 gLineStyle == LineSolid ? *gGCline : *gGCdash, px, py);
671 void TGX11::DrawPolyMarker(
int n, TPoint *xyt)
673 XPoint *xy = (XPoint*)xyt;
675 if (gMarker.n <= 0) {
676 const int kNMAX = 1000000;
678 for (
int it=0;it<=nt;it++) {
680 XDrawPoints((Display*)fDisplay, gCws->fDrawing, *gGCmark, &xy[it*kNMAX], kNMAX, CoordModeOrigin);
682 XDrawPoints((Display*)fDisplay, gCws->fDrawing, *gGCmark, &xy[it*kNMAX], n-it*kNMAX, CoordModeOrigin);
686 int r = gMarker.n / 2;
689 for (m = 0; m < n; m++) {
692 switch (gMarker.type) {
696 XDrawArc((Display*)fDisplay, gCws->fDrawing, *gGCmark,
697 xy[m].x - r, xy[m].y - r, gMarker.n, gMarker.n, 0, 360*64);
701 XFillArc((Display*)fDisplay, gCws->fDrawing, *gGCmark,
702 xy[m].x - r, xy[m].y - r, gMarker.n, gMarker.n, 0, 360*64);
708 for (i = 0; i < gMarker.n; i++) {
709 gMarker.xy[i].x += xy[m].x;
710 gMarker.xy[i].y += xy[m].y;
713 XDrawLines((Display*)fDisplay, gCws->fDrawing, *gGCmark,
714 gMarker.xy, gMarker.n, CoordModeOrigin);
716 XFillPolygon((Display*)fDisplay, gCws->fDrawing, *gGCmark,
717 gMarker.xy, gMarker.n, Nonconvex, CoordModeOrigin);
718 for (i = 0; i < gMarker.n; i++) {
719 gMarker.xy[i].x -= xy[m].x;
720 gMarker.xy[i].y -= xy[m].y;
725 for (i = 0; i < gMarker.n; i += 2)
726 XDrawLine((Display*)fDisplay, gCws->fDrawing, *gGCmark,
727 xy[m].x + gMarker.xy[i].x, xy[m].y + gMarker.xy[i].y,
728 xy[m].x + gMarker.xy[i+1].x, xy[m].y + gMarker.xy[i+1].y);
746 void TGX11::DrawText(
int x,
int y,
float angle,
float mgn,
747 const char *text, ETextMode mode)
749 XRotSetMagnification(mgn);
756 XRotDrawAlignedString((Display*)fDisplay, gTextFont, angle,
757 gCws->fDrawing, *gGCtext, x, y, (
char*)text, fTextAlign);
761 XRotDrawAlignedImageString((Display*)fDisplay, gTextFont, angle,
762 gCws->fDrawing, *gGCtext, x, y, (
char*)text, fTextAlign);
775 void TGX11::FindBestVisual()
777 Int_t findvis = gEnv->GetValue(
"X11.FindBestVisual", 1);
779 Visual *vis = DefaultVisual((Display*)fDisplay, fScreenNumber);
780 if (((vis->c_class != TrueColor && vis->c_class != DirectColor) ||
781 DefaultDepth((Display*)fDisplay, fScreenNumber) < 15) && findvis) {
784 static XVisualInfo templates[] = {
786 { 0 , 0 , 0 , 24 , TrueColor , 0 , 0 , 0 , 0 , 0 },
787 { 0 , 0 , 0 , 32 , TrueColor , 0 , 0 , 0 , 0 , 0 },
788 { 0 , 0 , 0 , 16 , TrueColor , 0 , 0 , 0 , 0 , 0 },
789 { 0 , 0 , 0 , 15 , TrueColor , 0 , 0 , 0 , 0 , 0 },
791 { 0 , 0 , 0 , 24 , DirectColor, 0 , 0 , 0 , 0 , 0 },
792 { 0 , 0 , 0 , 32 , DirectColor, 0 , 0 , 0 , 0 , 0 },
793 { 0 , 0 , 0 , 16 , DirectColor, 0 , 0 , 0 , 0 , 0 },
794 { 0 , 0 , 0 , 15 , DirectColor, 0 , 0 , 0 , 0 , 0 },
795 { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
799 XVisualInfo *vlist = 0;
800 for (Int_t i = 0; templates[i].depth != 0; i++) {
801 Int_t mask = VisualScreenMask|VisualDepthMask|VisualClassMask;
802 templates[i].screen = fScreenNumber;
803 if ((vlist = XGetVisualInfo((Display*)fDisplay, mask, &(templates[i]), &nitems))) {
804 FindUsableVisual((RXVisualInfo*)vlist, nitems);
813 fRootWin = RootWindow((Display*)fDisplay, fScreenNumber);
816 fDepth = DefaultDepth((Display*)fDisplay, fScreenNumber);
817 fVisual = (RVisual*)DefaultVisual((Display*)fDisplay, fScreenNumber);
818 fVisRootWin = fRootWin;
820 fColormap = DefaultColormap((Display*)fDisplay, fScreenNumber);
821 fBlackPixel = BlackPixel((Display*)fDisplay, fScreenNumber);
822 fWhitePixel = WhitePixel((Display*)fDisplay, fScreenNumber);
825 Printf(
"Selected visual 0x%lx: depth %d, class %d, colormap: %s",
826 fVisual->visualid, fDepth, fVisual->c_class,
827 fColormap == DefaultColormap((Display*)fDisplay, fScreenNumber) ?
"default" :
834 static Int_t DummyX11ErrorHandler(Display *, XErrorEvent *)
843 void TGX11::FindUsableVisual(RXVisualInfo *vlist, Int_t nitems)
845 Int_t (*oldErrorHandler)(Display *, XErrorEvent *) =
846 XSetErrorHandler(DummyX11ErrorHandler);
848 XSetWindowAttributes attr;
849 memset(&attr, 0,
sizeof(attr));
851 Window root = RootWindow((Display*)fDisplay, fScreenNumber);
853 for (Int_t i = 0; i < nitems; i++) {
854 Window w = None, wjunk;
855 UInt_t width, height, ujunk;
859 if (vlist[i].visual == DefaultVisual((Display*)fDisplay, fScreenNumber)) {
860 attr.colormap = DefaultColormap((Display*)fDisplay, fScreenNumber);
862 attr.colormap = XCreateColormap((Display*)fDisplay, root, vlist[i].visual, AllocNone);
865 static XColor black_xcol = { 0, 0x0000, 0x0000, 0x0000, DoRed|DoGreen|DoBlue, 0 };
866 static XColor white_xcol = { 0, 0xFFFF, 0xFFFF, 0xFFFF, DoRed|DoGreen|DoBlue, 0 };
867 XAllocColor((Display*)fDisplay, attr.colormap, &black_xcol);
868 XAllocColor((Display*)fDisplay, attr.colormap, &white_xcol);
869 attr.border_pixel = black_xcol.pixel;
870 attr.override_redirect = True;
872 w = XCreateWindow((Display*)fDisplay, root, -20, -20, 10, 10, 0, vlist[i].depth,
873 CopyFromParent, vlist[i].visual,
874 CWColormap|CWBorderPixel|CWOverrideRedirect, &attr);
875 if (w != None && XGetGeometry((Display*)fDisplay, w, &wjunk, &junk, &junk,
876 &width, &height, &ujunk, &ujunk)) {
877 fVisual = (RVisual*)vlist[i].visual;
878 fDepth = vlist[i].depth;
879 fColormap = attr.colormap;
880 fBlackPixel = black_xcol.pixel;
881 fWhitePixel = white_xcol.pixel;
885 if (attr.colormap != DefaultColormap((Display*)fDisplay, fScreenNumber))
886 XFreeColormap((Display*)fDisplay, attr.colormap);
888 XSetErrorHandler(oldErrorHandler);
894 void TGX11::GetCharacterUp(Float_t &chupx, Float_t &chupy)
896 chupx = fCharacterUpX;
897 chupy = fCharacterUpY;
904 XColor_t &TGX11::GetColor(Int_t cid)
906 XColor_t *col = (XColor_t*) (Long_t)fColors->GetValue(cid);
909 fColors->Add(cid, (Long_t) col);
917 Window_t TGX11::GetCurrentWindow()
const
919 return (Window_t)(gCws ? gCws->fDrawing : 0);
926 void *TGX11::GetGC(Int_t which)
const
928 if (which >= kMAXGC || which < 0) {
929 Error(
"GetGC",
"trying to get illegal GC (which = %d)", which);
932 return &gGClist[which];
938 Int_t TGX11::GetDoubleBuffer(
int wid)
940 gTws = &fWindows[wid];
944 return gTws->fDoubleBuffer;
956 void TGX11::GetGeometry(
int wid,
int &x,
int &y,
unsigned int &w,
unsigned int &h)
963 w = DisplayWidth((Display*)fDisplay,fScreenNumber);
964 h = DisplayHeight((Display*)fDisplay,fScreenNumber);
967 unsigned int border, depth;
968 unsigned int width, height;
970 gTws = &fWindows[wid];
971 XGetGeometry((Display*)fDisplay, gTws->fWindow, &root, &x, &y,
972 &width, &height, &border, &depth);
973 XTranslateCoordinates((Display*)fDisplay, gTws->fWindow, fRootWin,
974 0, 0, &x, &y, &junkwin);
979 if (width > 0 && height > 0) {
980 gTws->fWidth = width;
981 gTws->fHeight = height;
991 const char *TGX11::DisplayName(
const char *dpyName)
993 return XDisplayName(dpyName);
999 ULong_t TGX11::GetPixel(Color_t ci)
1001 TColor *color = gROOT->GetColor(ci);
1003 SetRGB(ci, color->GetRed(), color->GetGreen(), color->GetBlue());
1007 XColor_t &col = GetColor(ci);
1014 void TGX11::GetPlanes(
int &nplanes)
1022 void TGX11::GetRGB(
int index,
float &r,
float &g,
float &b)
1026 }
else if (index == 1) {
1029 XColor_t &col = GetColor(index);
1030 r = ((float) col.fRed) / ((float) kBIGGEST_RGB_VALUE);
1031 g = ((float) col.fGreen) / ((float) kBIGGEST_RGB_VALUE);
1032 b = ((float) col.fBlue) / ((float) kBIGGEST_RGB_VALUE);
1043 void TGX11::GetTextExtent(
unsigned int &w,
unsigned int &h,
char *mess)
1046 if (strlen(mess)==0)
return;
1049 XRotSetMagnification(fTextMagnitude);
1050 cBox = XRotTextExtents((Display*)fDisplay, gTextFont, 0., 0, 0, mess, 0);
1063 Window_t TGX11::GetWindowID(
int wid)
1065 return (Window_t) fWindows[wid].fWindow;
1075 void TGX11::MoveWindow(
int wid,
int x,
int y)
1077 gTws = &fWindows[wid];
1078 if (!gTws->fOpen)
return;
1080 XMoveWindow((Display*)fDisplay, gTws->fWindow, x, y);
1086 Int_t TGX11::OpenDisplay(
void *disp)
1088 Pixmap pixmp1, pixmp2;
1094 if (fDisplay)
return 0;
1097 fScreenNumber = DefaultScreen((Display*)fDisplay);
1101 GetColor(1).fDefined = kTRUE;
1102 GetColor(1).fPixel = fBlackPixel;
1103 GetColor(0).fDefined = kTRUE;
1104 GetColor(0).fPixel = fWhitePixel;
1108 strlcpy(vendor, XServerVendor((Display*)fDisplay),132);
1111 for (i = 0; i < kMAXGC; i++)
1112 gGClist[i] = XCreateGC((Display*)fDisplay, fVisRootWin, 0, 0);
1115 if (XGetGCValues((Display*)fDisplay, *gGCtext, GCForeground|GCBackground, &values)) {
1116 XSetForeground((Display*)fDisplay, *gGCinvt, values.background);
1117 XSetBackground((Display*)fDisplay, *gGCinvt, values.foreground);
1119 Error(
"OpenDisplay",
"cannot get GC values");
1125 XSetGraphicsExposures((Display*)fDisplay, *gGCpxmp, False);
1129 echov.foreground = fBlackPixel;
1130 echov.background = fWhitePixel;
1131 if (strstr(vendor,
"Hewlett"))
1132 echov.function = GXxor;
1134 echov.function = GXinvert;
1136 gGCecho = XCreateGC((Display*)fDisplay, fVisRootWin,
1137 GCForeground | GCBackground | GCFunction,
1141 static int isdisp = 0;
1143 for (i = 0; i < kMAXFONT; i++) {
1145 strcpy(gFont[i].name,
" ");
1147 fontlist = XListFonts((Display*)fDisplay,
"*courier*", 1, &fontcount);
1148 if (fontlist && fontcount != 0) {
1149 gFont[gCurrentFontNumber].id = XLoadQueryFont((Display*)fDisplay, fontlist[0]);
1150 gTextFont = gFont[gCurrentFontNumber].id;
1151 strcpy(gFont[gCurrentFontNumber].name,
"*courier*");
1152 gCurrentFontNumber++;
1153 XFreeFontNames(fontlist);
1156 fontlist = XListFonts((Display*)fDisplay,
"fixed", 1, &fontcount);
1157 if (fontlist && fontcount != 0) {
1158 gFont[gCurrentFontNumber].id = XLoadQueryFont((Display*)fDisplay, fontlist[0]);
1159 gTextFont = gFont[gCurrentFontNumber].id;
1160 strcpy(gFont[gCurrentFontNumber].name,
"fixed");
1161 gCurrentFontNumber++;
1162 XFreeFontNames(fontlist);
1164 Warning(
"OpenDisplay",
"no default font loaded");
1171 pixmp1 = XCreateBitmapFromData((Display*)fDisplay, fRootWin,
1172 null_cursor_bits, 16, 16);
1173 pixmp2 = XCreateBitmapFromData((Display*)fDisplay, fRootWin,
1174 null_cursor_bits, 16, 16);
1175 gNullCursor = XCreatePixmapCursor((Display*)fDisplay,pixmp1,pixmp2,&fore,&back,0,0);
1178 fCursors[kBottomLeft] = XCreateFontCursor((Display*)fDisplay, XC_bottom_left_corner);
1179 fCursors[kBottomRight] = XCreateFontCursor((Display*)fDisplay, XC_bottom_right_corner);
1180 fCursors[kTopLeft] = XCreateFontCursor((Display*)fDisplay, XC_top_left_corner);
1181 fCursors[kTopRight] = XCreateFontCursor((Display*)fDisplay, XC_top_right_corner);
1182 fCursors[kBottomSide] = XCreateFontCursor((Display*)fDisplay, XC_bottom_side);
1183 fCursors[kLeftSide] = XCreateFontCursor((Display*)fDisplay, XC_left_side);
1184 fCursors[kTopSide] = XCreateFontCursor((Display*)fDisplay, XC_top_side);
1185 fCursors[kRightSide] = XCreateFontCursor((Display*)fDisplay, XC_right_side);
1186 fCursors[kMove] = XCreateFontCursor((Display*)fDisplay, XC_fleur);
1187 fCursors[kCross] = XCreateFontCursor((Display*)fDisplay, XC_tcross);
1188 fCursors[kArrowHor] = XCreateFontCursor((Display*)fDisplay, XC_sb_h_double_arrow);
1189 fCursors[kArrowVer] = XCreateFontCursor((Display*)fDisplay, XC_sb_v_double_arrow);
1190 fCursors[kHand] = XCreateFontCursor((Display*)fDisplay, XC_hand2);
1191 fCursors[kRotate] = XCreateFontCursor((Display*)fDisplay, XC_exchange);
1192 fCursors[kPointer] = XCreateFontCursor((Display*)fDisplay, XC_left_ptr);
1193 fCursors[kArrowRight] = XCreateFontCursor((Display*)fDisplay, XC_arrow);
1194 fCursors[kCaret] = XCreateFontCursor((Display*)fDisplay, XC_xterm);
1195 fCursors[kWatch] = XCreateFontCursor((Display*)fDisplay, XC_watch);
1196 fCursors[kNoDrop] = XCreateFontCursor((Display*)fDisplay, XC_pirate);
1199 fRedDiv = fGreenDiv = fBlueDiv = fRedShift = fGreenShift = fBlueShift = -1;
1201 if (fVisual->c_class == TrueColor) {
1202 for (i = 0; i < int(
sizeof(fVisual->blue_mask)*kBitsPerByte); i++) {
1203 if (fBlueShift == -1 && ((fVisual->blue_mask >> i) & 1))
1205 if ((fVisual->blue_mask >> i) == 1) {
1206 fBlueDiv =
sizeof(UShort_t)*kBitsPerByte - i - 1 + fBlueShift;
1210 for (i = 0; i < int(
sizeof(fVisual->green_mask)*kBitsPerByte); i++) {
1211 if (fGreenShift == -1 && ((fVisual->green_mask >> i) & 1))
1213 if ((fVisual->green_mask >> i) == 1) {
1214 fGreenDiv =
sizeof(UShort_t)*kBitsPerByte - i - 1 + fGreenShift;
1218 for (i = 0; i < int(
sizeof(fVisual->red_mask)*kBitsPerByte); i++) {
1219 if (fRedShift == -1 && ((fVisual->red_mask >> i) & 1))
1221 if ((fVisual->red_mask >> i) == 1) {
1222 fRedDiv =
sizeof(UShort_t)*kBitsPerByte - i - 1 + fRedShift;
1238 Int_t TGX11::OpenPixmap(
unsigned int w,
unsigned int h)
1241 unsigned int wval, hval;
1243 unsigned int ww, hh, border, depth;
1250 for (wid = 0; wid < fMaxNumberOfWindows; wid++)
1251 if (!fWindows[wid].fOpen) {
1252 fWindows[wid].fOpen = 1;
1253 gCws = &fWindows[wid];
1257 if (wid == fMaxNumberOfWindows) {
1258 int newsize = fMaxNumberOfWindows + 10;
1259 fWindows = (XWindow_t*) TStorage::ReAlloc(fWindows, newsize*
sizeof(XWindow_t),
1260 fMaxNumberOfWindows*
sizeof(XWindow_t));
1261 for (i = fMaxNumberOfWindows; i < newsize; i++)
1262 fWindows[i].fOpen = 0;
1263 fMaxNumberOfWindows = newsize;
1267 gCws->fWindow = XCreatePixmap((Display*)fDisplay, fRootWin, wval, hval, fDepth);
1268 XGetGeometry((Display*)fDisplay, gCws->fWindow, &root, &xx, &yy, &ww, &hh, &border, &depth);
1270 for (i = 0; i < kMAXGC; i++)
1271 XSetClipMask((Display*)fDisplay, gGClist[i], None);
1273 SetColor(gGCpxmp, 0);
1274 XFillRectangle((Display*)fDisplay, gCws->fWindow, *gGCpxmp, 0, 0, ww, hh);
1275 SetColor(gGCpxmp, 1);
1278 gCws->fDrawing = gCws->fWindow;
1280 gCws->fDoubleBuffer = 0;
1281 gCws->fIsPixmap = 1;
1283 gCws->fWidth = wval;
1284 gCws->fHeight = hval;
1285 gCws->fNewColors = 0;
1286 gCws->fShared = kFALSE;
1296 Int_t TGX11::InitWindow(ULong_t win)
1298 XSetWindowAttributes attributes;
1299 ULong_t attr_mask = 0;
1302 unsigned int wval, hval, border, depth;
1305 Window wind = (Window) win;
1307 XGetGeometry((Display*)fDisplay, wind, &root, &xval, &yval, &wval, &hval, &border, &depth);
1312 for (wid = 0; wid < fMaxNumberOfWindows; wid++)
1313 if (!fWindows[wid].fOpen) {
1314 fWindows[wid].fOpen = 1;
1315 fWindows[wid].fDoubleBuffer = 0;
1316 gCws = &fWindows[wid];
1320 if (wid == fMaxNumberOfWindows) {
1321 int newsize = fMaxNumberOfWindows + 10;
1322 fWindows = (XWindow_t*) TStorage::ReAlloc(fWindows, newsize*
sizeof(XWindow_t),
1323 fMaxNumberOfWindows*
sizeof(XWindow_t));
1324 for (
int i = fMaxNumberOfWindows; i < newsize; i++)
1325 fWindows[i].fOpen = 0;
1326 fMaxNumberOfWindows = newsize;
1332 attributes.background_pixel = GetColor(0).fPixel;
1333 attr_mask |= CWBackPixel;
1334 attributes.border_pixel = GetColor(1).fPixel;
1335 attr_mask |= CWBorderPixel;
1336 attributes.event_mask = NoEventMask;
1337 attr_mask |= CWEventMask;
1338 attributes.backing_store = Always;
1339 attr_mask |= CWBackingStore;
1340 attributes.bit_gravity = NorthWestGravity;
1341 attr_mask |= CWBitGravity;
1343 attributes.colormap = fColormap;
1344 attr_mask |= CWColormap;
1347 gCws->fWindow = XCreateWindow((Display*)fDisplay, wind,
1348 xval, yval, wval, hval, 0, fDepth,
1349 InputOutput, fVisual,
1350 attr_mask, &attributes);
1352 XMapWindow((Display*)fDisplay, gCws->fWindow);
1353 XFlush((Display*)fDisplay);
1357 gCws->fDrawing = gCws->fWindow;
1359 gCws->fDoubleBuffer = 0;
1360 gCws->fIsPixmap = 0;
1362 gCws->fWidth = wval;
1363 gCws->fHeight = hval;
1364 gCws->fNewColors = 0;
1365 gCws->fShared = kFALSE;
1373 Int_t TGX11::AddWindow(ULong_t qwid, UInt_t w, UInt_t h)
1380 for (wid = 0; wid < fMaxNumberOfWindows; wid++)
1381 if (!fWindows[wid].fOpen) {
1382 fWindows[wid].fOpen = 1;
1383 fWindows[wid].fDoubleBuffer = 0;
1384 gCws = &fWindows[wid];
1388 if (wid == fMaxNumberOfWindows) {
1389 int newsize = fMaxNumberOfWindows + 10;
1390 fWindows = (XWindow_t*) TStorage::ReAlloc(fWindows, newsize*
sizeof(XWindow_t),
1391 fMaxNumberOfWindows*
sizeof(XWindow_t));
1392 for (
int i = fMaxNumberOfWindows; i < newsize; i++)
1393 fWindows[i].fOpen = 0;
1394 fMaxNumberOfWindows = newsize;
1398 gCws->fWindow = qwid;
1401 gCws->fDrawing = gCws->fWindow;
1403 gCws->fDoubleBuffer = 0;
1404 gCws->fIsPixmap = 0;
1408 gCws->fNewColors = 0;
1409 gCws->fShared = kTRUE;
1417 void TGX11::RemoveWindow(ULong_t qwid)
1419 SelectWindow((
int)qwid);
1421 if (gCws->fBuffer) XFreePixmap((Display*)fDisplay, gCws->fBuffer);
1423 if (gCws->fNewColors) {
1425 XFreeColors((Display*)fDisplay, fColormap, gCws->fNewColors, gCws->fNcolors, 0);
1426 delete [] gCws->fNewColors;
1427 gCws->fNewColors = 0;
1433 for (Int_t wid = 0; wid < fMaxNumberOfWindows; wid++)
1434 if (fWindows[wid].fOpen) {
1435 gCws = &fWindows[wid];
1449 void TGX11::QueryPointer(
int &ix,
int &iy)
1451 Window root_return, child_return;
1452 int win_x_return, win_y_return;
1453 int root_x_return, root_y_return;
1454 unsigned int mask_return;
1456 XQueryPointer((Display*)fDisplay,gCws->fWindow, &root_return,
1457 &child_return, &root_x_return, &root_y_return, &win_x_return,
1458 &win_y_return, &mask_return);
1467 void TGX11::RemovePixmap(Drawable *pix)
1469 XFreePixmap((Display*)fDisplay,*pix);
1500 Int_t TGX11::RequestLocator(
int mode,
int ctyp,
int &x,
int &y)
1502 static int xloc = 0;
1503 static int yloc = 0;
1504 static int xlocp = 0;
1505 static int ylocp = 0;
1506 static Cursor cursor = 0;
1515 XDefineCursor((Display*)fDisplay, gCws->fWindow, gNullCursor);
1516 XSetForeground((Display*)fDisplay, gGCecho, GetColor(0).fPixel);
1518 cursor = XCreateFontCursor((Display*)fDisplay, XC_crosshair);
1519 XDefineCursor((Display*)fDisplay, gCws->fWindow, cursor);
1527 while (button_press == 0) {
1535 XDrawLine((Display*)fDisplay, gCws->fWindow, gGCecho,
1536 xloc, 0, xloc, gCws->fHeight);
1537 XDrawLine((Display*)fDisplay, gCws->fWindow, gGCecho,
1538 0, yloc, gCws->fWidth, yloc);
1542 radius = (int) TMath::Sqrt((
double)((xloc-xlocp)*(xloc-xlocp) +
1543 (yloc-ylocp)*(yloc-ylocp)));
1544 XDrawArc((Display*)fDisplay, gCws->fWindow, gGCecho,
1545 xlocp-radius, ylocp-radius,
1546 2*radius, 2*radius, 0, 23040);
1550 XDrawLine((Display*)fDisplay, gCws->fWindow, gGCecho,
1551 xlocp, ylocp, xloc, yloc);
1555 XDrawRectangle((Display*)fDisplay, gCws->fWindow, gGCecho,
1556 TMath::Min(xlocp,xloc), TMath::Min(ylocp,yloc),
1557 TMath::Abs(xloc-xlocp), TMath::Abs(yloc-ylocp));
1564 while (XEventsQueued( (Display*)fDisplay, QueuedAlready) > 1) {
1565 XNextEvent((Display*)fDisplay, &event);
1567 XWindowEvent((Display*)fDisplay, gCws->fWindow, gMouseMask, &event);
1575 XDrawLine((Display*)fDisplay, gCws->fWindow, gGCecho,
1576 xloc, 0, xloc, gCws->fHeight);
1577 XDrawLine((Display*)fDisplay, gCws->fWindow, gGCecho,
1578 0, yloc, gCws->fWidth, yloc);
1582 radius = (int) TMath::Sqrt((
double)((xloc-xlocp)*(xloc-xlocp) +
1583 (yloc-ylocp)*(yloc-ylocp)));
1584 XDrawArc((Display*)fDisplay, gCws->fWindow, gGCecho,
1585 xlocp-radius, ylocp-radius,
1586 2*radius, 2*radius, 0, 23040);
1590 XDrawLine((Display*)fDisplay, gCws->fWindow, gGCecho,
1591 xlocp, ylocp, xloc, yloc);
1595 XDrawRectangle((Display*)fDisplay, gCws->fWindow, gGCecho,
1596 TMath::Min(xlocp,xloc), TMath::Min(ylocp,yloc),
1597 TMath::Abs(xloc-xlocp), TMath::Abs(yloc-ylocp));
1604 xloc =
event.xbutton.x;
1605 yloc =
event.xbutton.y;
1607 switch (event.type) {
1612 XNextEvent((Display*)fDisplay, &event);
1613 if (event.type == EnterNotify)
break;
1621 button_press =
event.xbutton.button ;
1622 xlocp =
event.xbutton.x;
1623 ylocp =
event.xbutton.y;
1624 XUndefineCursor( (Display*)fDisplay, gCws->fWindow );
1628 case ButtonRelease :
1630 button_press = 10+
event.xbutton.button ;
1631 xlocp =
event.xbutton.x;
1632 ylocp =
event.xbutton.y;
1638 button_press =
event.xkey.keycode;
1639 xlocp =
event.xbutton.x;
1640 ylocp =
event.xbutton.y;
1646 button_press = -
event.xkey.keycode;
1647 xlocp =
event.xbutton.x;
1648 ylocp =
event.xbutton.y;
1657 if (button_press == 0)
1662 x =
event.xbutton.x;
1663 y =
event.xbutton.y;
1665 return button_press;
1678 Int_t TGX11::RequestString(
int x,
int y,
char *text)
1680 static Cursor cursor = 0;
1681 static int percent = 0;
1687 int len_text = strlen(text);
1693 XKeyboardState kbstate;
1694 cursor = XCreateFontCursor((Display*)fDisplay, XC_question_arrow);
1695 XGetKeyboardControl((Display*)fDisplay, &kbstate);
1696 percent = kbstate.bell_percent;
1699 XDefineCursor((Display*)fDisplay, gCws->fWindow, cursor);
1700 for (nt = len_text; nt > 0 && text[nt-1] ==
' '; nt--) { }
1702 XGetInputFocus((Display*)fDisplay, &focuswindow, &focusrevert);
1703 XSetInputFocus((Display*)fDisplay, gCws->fWindow, focusrevert, CurrentTime);
1709 XDrawImageString((Display*)fDisplay, gCws->fWindow, *gGCtext, x, y, text, nt);
1710 dx = XTextWidth(gTextFont, text, nt);
1711 XDrawImageString((Display*)fDisplay, gCws->fWindow, *gGCtext, x + dx, y,
" ", 1);
1712 dx = pt == 0 ? 0 : XTextWidth(gTextFont, text, pt);
1713 XDrawImageString((Display*)fDisplay, gCws->fWindow, *gGCinvt,
1714 x + dx, y, pt < len_text ? &text[pt] :
" ", 1);
1715 XWindowEvent((Display*)fDisplay, gCws->fWindow, gKeybdMask, &event);
1716 switch (event.type) {
1719 XSetInputFocus((Display*)fDisplay, gCws->fWindow, focusrevert, CurrentTime);
1722 XSetInputFocus((Display*)fDisplay, focuswindow, focusrevert, CurrentTime);
1725 nbytes = XLookupString(&event.xkey, keybuf,
sizeof(keybuf),
1738 if (isascii(keybuf[0]) && isprint(keybuf[0])) {
1742 for (i = nt - 1; i > pt; i--)
1743 text[i] = text[i-1];
1744 if (pt < len_text) {
1745 text[pt] = keybuf[0];
1749 switch (keybuf[0]) {
1756 for (i = pt; i < nt; i++)
1757 text[i-1] = text[i];
1775 for (i = pt; i < nt; i++)
1776 text[i-1] = text[i];
1793 for (i = pt; i < nt; i++)
1801 text[pt] = text[pt-1];
1814 XBell((Display*)fDisplay, percent);
1819 XSetInputFocus((Display*)fDisplay, focuswindow, focusrevert, CurrentTime);
1822 XUndefineCursor((Display*)fDisplay, gCws->fWindow);
1836 void TGX11::RescaleWindow(
int wid,
unsigned int w,
unsigned int h)
1840 gTws = &fWindows[wid];
1841 if (!gTws->fOpen)
return;
1844 if (gTws->fWidth == w && gTws->fHeight == h)
return;
1846 XResizeWindow((Display*)fDisplay, gTws->fWindow, w, h);
1848 if (gTws->fBuffer) {
1850 if (gTws->fWidth < w || gTws->fHeight < h) {
1851 XFreePixmap((Display*)fDisplay,gTws->fBuffer);
1852 gTws->fBuffer = XCreatePixmap((Display*)fDisplay, fRootWin, w, h, fDepth);
1854 for (i = 0; i < kMAXGC; i++) XSetClipMask((Display*)fDisplay, gGClist[i], None);
1855 SetColor(gGCpxmp, 0);
1856 XFillRectangle( (Display*)fDisplay, gTws->fBuffer, *gGCpxmp, 0, 0, w, h);
1857 SetColor(gGCpxmp, 1);
1858 if (gTws->fDoubleBuffer) gTws->fDrawing = gTws->fBuffer;
1870 int TGX11::ResizePixmap(
int wid,
unsigned int w,
unsigned int h)
1873 unsigned int wval, hval;
1875 unsigned int ww, hh, border, depth;
1879 gTws = &fWindows[wid];
1886 if (gTws->fWidth >= wval-1 && gTws->fWidth <= wval+1 &&
1887 gTws->fHeight >= hval-1 && gTws->fHeight <= hval+1)
return 0;
1890 if (gTws->fWidth < wval || gTws->fHeight < hval) {
1891 XFreePixmap((Display*)fDisplay, gTws->fWindow);
1892 gTws->fWindow = XCreatePixmap((Display*)fDisplay, fRootWin, wval, hval, fDepth);
1894 XGetGeometry((Display*)fDisplay, gTws->fWindow, &root, &xx, &yy, &ww, &hh, &border, &depth);
1896 for (i = 0; i < kMAXGC; i++)
1897 XSetClipMask((Display*)fDisplay, gGClist[i], None);
1899 SetColor(gGCpxmp, 0);
1900 XFillRectangle((Display*)fDisplay, gTws->fWindow, *gGCpxmp, 0, 0, ww, hh);
1901 SetColor(gGCpxmp, 1);
1904 gTws->fDrawing = gTws->fWindow;
1905 gTws->fWidth = wval;
1906 gTws->fHeight = hval;
1914 void TGX11::ResizeWindow(
int wid)
1919 unsigned int wval=0, hval=0, border=0, depth=0;
1921 gTws = &fWindows[wid];
1923 win = gTws->fWindow;
1925 XGetGeometry((Display*)fDisplay, win, &root,
1926 &xval, &yval, &wval, &hval, &border, &depth);
1927 if (wval >= 65500) wval = 1;
1928 if (hval >= 65500) hval = 1;
1931 if (gTws->fWidth == wval && gTws->fHeight == hval)
return;
1933 XResizeWindow((Display*)fDisplay, gTws->fWindow, wval, hval);
1935 if (gTws->fBuffer) {
1936 if (gTws->fWidth < wval || gTws->fHeight < hval) {
1937 XFreePixmap((Display*)fDisplay,gTws->fBuffer);
1938 gTws->fBuffer = XCreatePixmap((Display*)fDisplay, fRootWin, wval, hval, fDepth);
1940 for (i = 0; i < kMAXGC; i++) XSetClipMask((Display*)fDisplay, gGClist[i], None);
1941 SetColor(gGCpxmp, 0);
1942 XFillRectangle((Display*)fDisplay, gTws->fBuffer, *gGCpxmp, 0, 0, wval, hval);
1943 SetColor(gGCpxmp, 1);
1944 if (gTws->fDoubleBuffer) gTws->fDrawing = gTws->fBuffer;
1946 gTws->fWidth = wval;
1947 gTws->fHeight = hval;
1953 void TGX11::SelectWindow(
int wid)
1958 if (wid < 0 || wid >= fMaxNumberOfWindows || !fWindows[wid].fOpen)
return;
1960 gCws = &fWindows[wid];
1962 if (gCws->fClip && !gCws->fIsPixmap && !gCws->fDoubleBuffer) {
1963 region.x = gCws->fXclip;
1964 region.y = gCws->fYclip;
1965 region.width = gCws->fWclip;
1966 region.height = gCws->fHclip;
1967 for (i = 0; i < kMAXGC; i++)
1968 XSetClipRectangles((Display*)fDisplay, gGClist[i], 0, 0, ®ion, 1, YXBanded);
1970 for (i = 0; i < kMAXGC; i++)
1971 XSetClipMask((Display*)fDisplay, gGClist[i], None);
1978 void TGX11::SetCharacterUp(Float_t chupx, Float_t chupy)
1980 if (chupx == fCharacterUpX && chupy == fCharacterUpY)
return;
1982 if (chupx == 0 && chupy == 0) fTextAngle = 0;
1983 else if (chupx == 0 && chupy == 1) fTextAngle = 0;
1984 else if (chupx == -1 && chupy == 0) fTextAngle = 90;
1985 else if (chupx == 0 && chupy == -1) fTextAngle = 180;
1986 else if (chupx == 1 && chupy == 0) fTextAngle = 270;
1988 fTextAngle = ((TMath::ACos(chupx/TMath::Sqrt(chupx*chupx +chupy*chupy))*180.)/TMath::Pi())-90;
1989 if (chupy < 0) fTextAngle = 180 - fTextAngle;
1990 if (TMath::Abs(fTextAngle) <= 0.01) fTextAngle = 0;
1992 fCharacterUpX = chupx;
1993 fCharacterUpY = chupy;
1999 void TGX11::SetClipOFF(
int wid)
2001 gTws = &fWindows[wid];
2004 for (
int i = 0; i < kMAXGC; i++)
2005 XSetClipMask( (Display*)fDisplay, gGClist[i], None );
2015 void TGX11::SetClipRegion(
int wid,
int x,
int y,
unsigned int w,
unsigned int h)
2018 gTws = &fWindows[wid];
2024 if (gTws->fClip && !gTws->fIsPixmap && !gTws->fDoubleBuffer) {
2026 region.x = gTws->fXclip;
2027 region.y = gTws->fYclip;
2028 region.width = gTws->fWclip;
2029 region.height = gTws->fHclip;
2030 for (
int i = 0; i < kMAXGC; i++)
2031 XSetClipRectangles((Display*)fDisplay, gGClist[i], 0, 0, ®ion, 1, YXBanded);
2038 void TGX11::SetColor(
void *gci,
int ci)
2042 TColor *color = gROOT->GetColor(ci);
2044 SetRGB(ci, color->GetRed(), color->GetGreen(), color->GetBlue());
2046 XColor_t &col = GetColor(ci);
2047 if (fColormap && !col.fDefined) {
2049 }
else if (!fColormap && (ci < 0 || ci > 1)) {
2053 if (fDrawMode == kXor) {
2055 XGetGCValues((Display*)fDisplay, gc, GCBackground, &values);
2056 XSetForeground((Display*)fDisplay, gc, col.fPixel ^ values.background);
2058 XSetForeground((Display*)fDisplay, gc, col.fPixel);
2062 XGetGCValues((Display*)fDisplay, gc, GCForeground | GCBackground, &values);
2063 if (values.foreground == values.background)
2064 XSetBackground((Display*)fDisplay, gc, GetColor(!ci).fPixel);
2071 void TGX11::SetCursor(
int wid, ECursor cursor)
2073 gTws = &fWindows[wid];
2074 XDefineCursor((Display*)fDisplay, gTws->fWindow, fCursors[cursor]);
2086 void TGX11::SetDoubleBuffer(
int wid,
int mode)
2089 for (
int i = 0; i < fMaxNumberOfWindows; i++) {
2090 gTws = &fWindows[i];
2094 SetDoubleBufferON();
2097 SetDoubleBufferOFF();
2103 gTws = &fWindows[wid];
2104 if (!gTws->fOpen)
return;
2107 SetDoubleBufferON();
2110 SetDoubleBufferOFF();
2119 void TGX11::SetDoubleBufferOFF()
2121 if (!gTws->fDoubleBuffer)
return;
2122 gTws->fDoubleBuffer = 0;
2123 gTws->fDrawing = gTws->fWindow;
2129 void TGX11::SetDoubleBufferON()
2131 if (gTws->fDoubleBuffer || gTws->fIsPixmap)
return;
2132 if (!gTws->fBuffer) {
2133 gTws->fBuffer = XCreatePixmap((Display*)fDisplay, fRootWin,
2134 gTws->fWidth, gTws->fHeight, fDepth);
2135 SetColor(gGCpxmp, 0);
2136 XFillRectangle((Display*)fDisplay, gTws->fBuffer, *gGCpxmp, 0, 0, gTws->fWidth, gTws->fHeight);
2137 SetColor(gGCpxmp, 1);
2139 for (
int i = 0; i < kMAXGC; i++) XSetClipMask((Display*)fDisplay, gGClist[i], None);
2140 gTws->fDoubleBuffer = 1;
2141 gTws->fDrawing = gTws->fBuffer;
2154 void TGX11::SetDrawMode(EDrawMode mode)
2160 for (i = 0; i < kMAXGC; i++) XSetFunction((Display*)fDisplay, gGClist[i], GXcopy);
2164 for (i = 0; i < kMAXGC; i++) XSetFunction((Display*)fDisplay, gGClist[i], GXxor);
2168 for (i = 0; i < kMAXGC; i++) XSetFunction((Display*)fDisplay, gGClist[i], GXinvert);
2178 void TGX11::SetFillColor(Color_t cindex)
2180 if (!gStyle->GetFillColor() && cindex > 1) cindex = 0;
2181 if (cindex >= 0) SetColor(gGCfill, Int_t(cindex));
2182 fFillColor = cindex;
2185 if (gFillPattern != 0) {
2186 XFreePixmap((Display*)fDisplay, gFillPattern);
2197 void TGX11::SetFillStyle(Style_t fstyle)
2199 if (fFillStyle == fstyle)
return;
2200 fFillStyle = fstyle;
2201 Int_t style = fstyle/1000;
2202 Int_t fasi = fstyle%1000;
2203 SetFillStyleIndex(style,fasi);
2209 void TGX11::SetFillStyleIndex(Int_t style, Int_t fasi)
2211 static int current_fasi = 0;
2213 fFillStyle = 1000*style + fasi;
2219 XSetFillStyle((Display*)fDisplay, *gGCfill, FillSolid);
2228 XSetFillStyle((Display*)fDisplay, *gGCfill, FillStippled);
2229 if (fasi != current_fasi) {
2230 if (gFillPattern != 0) {
2231 XFreePixmap((Display*)fDisplay, gFillPattern);
2234 int stn = (fasi >= 1 && fasi <=25) ? fasi : 2;
2236 gFillPattern = XCreateBitmapFromData((Display*)fDisplay, fRootWin,
2237 (
const char*)gStipples[stn], 16, 16);
2239 XSetStipple( (Display*)fDisplay, *gGCfill, gFillPattern );
2240 current_fasi = fasi;
2252 void TGX11::SetInput(
int inp)
2254 XSetWindowAttributes attributes;
2258 attributes.event_mask = gMouseMask | gKeybdMask;
2259 attr_mask = CWEventMask;
2260 XChangeWindowAttributes((Display*)fDisplay, gCws->fWindow, attr_mask, &attributes);
2262 attributes.event_mask = NoEventMask;
2263 attr_mask = CWEventMask;
2264 XChangeWindowAttributes((Display*)fDisplay, gCws->fWindow, attr_mask, &attributes);
2271 void TGX11::SetLineColor(Color_t cindex)
2273 if (cindex < 0)
return;
2275 TAttLine::SetLineColor(cindex);
2277 SetColor(gGCline, Int_t(cindex));
2278 SetColor(gGCdash, Int_t(cindex));
2292 void TGX11::SetLineType(
int n,
int *dash)
2295 gLineStyle = LineSolid;
2296 XSetLineAttributes((Display*)fDisplay, *gGCline, gLineWidth,
2297 gLineStyle, gCapStyle, gJoinStyle);
2299 gDashSize = TMath::Min((
int)
sizeof(gDashList),n);
2301 for (
int i = 0; i < gDashSize; i++ ) {
2302 gDashList[i] = dash[i];
2303 gDashLength += gDashList[i];
2306 gLineStyle = LineOnOffDash;
2307 if (gLineWidth == 0) gLineWidth =1;
2308 XSetLineAttributes((Display*)fDisplay, *gGCline, gLineWidth,
2309 gLineStyle, gCapStyle, gJoinStyle);
2310 XSetLineAttributes((Display*)fDisplay, *gGCdash, gLineWidth,
2311 gLineStyle, gCapStyle, gJoinStyle);
2318 void TGX11::SetLineStyle(Style_t lstyle)
2320 static Int_t dashed[2] = {3,3};
2321 static Int_t dotted[2] = {1,2};
2322 static Int_t dasheddotted[4] = {3,4,1,4};
2324 if (fLineStyle != lstyle) {
2325 fLineStyle = lstyle;
2328 }
else if (lstyle == 2 ) {
2329 SetLineType(2,dashed);
2330 }
else if (lstyle == 3 ) {
2331 SetLineType(2,dotted);
2332 }
else if (lstyle == 4 ) {
2333 SetLineType(4,dasheddotted);
2335 TString st = (TString)gStyle->GetLineStyleString(lstyle);
2336 TObjArray *tokens = st.Tokenize(
" ");
2338 nt = tokens->GetEntries();
2339 Int_t *linestyle =
new Int_t[nt];
2340 for (Int_t j = 0; j<nt; j++) {
2342 sscanf(((TObjString*)tokens->At(j))->GetName(),
"%d", &it);
2343 linestyle[j] = (Int_t)(it/4);
2345 SetLineType(nt,linestyle);
2346 delete [] linestyle;
2357 void TGX11::SetLineWidth(Width_t width )
2359 if (fLineWidth == width)
return;
2362 if (width == 1 && gLineStyle == LineSolid) gLineWidth = 0;
2363 else gLineWidth = width;
2365 if (gLineWidth < 0)
return;
2367 XSetLineAttributes((Display*)fDisplay, *gGCline, gLineWidth,
2368 gLineStyle, gCapStyle, gJoinStyle);
2369 XSetLineAttributes((Display*)fDisplay, *gGCdash, gLineWidth,
2370 gLineStyle, gCapStyle, gJoinStyle);
2376 void TGX11::SetMarkerColor(Color_t cindex)
2378 if (cindex < 0)
return;
2380 TAttMarker::SetMarkerColor(cindex);
2382 SetColor(gGCmark, Int_t(cindex));
2390 void TGX11::SetMarkerSize(Float_t msize)
2392 if (msize == fMarkerSize)
return;
2394 fMarkerSize = msize;
2395 if (msize < 0)
return;
2397 SetMarkerStyle(-fMarkerStyle);
2415 void TGX11::SetMarkerType(
int type,
int n, RXPoint *xy)
2417 gMarker.type = type;
2418 gMarker.n = n < kMAXMK ? n : kMAXMK;
2419 if (gMarker.type >= 2) {
2420 for (
int i = 0; i < gMarker.n; i++) {
2421 gMarker.xy[i].x = xy[i].x;
2422 gMarker.xy[i].y = xy[i].y;
2430 void TGX11::SetMarkerStyle(Style_t markerstyle)
2432 if (fMarkerStyle == markerstyle)
return;
2433 static RXPoint shape[30];
2434 if (markerstyle >= 50)
return;
2435 markerstyle = TMath::Abs(markerstyle);
2436 fMarkerStyle = markerstyle;
2437 Int_t im = Int_t(4*fMarkerSize + 0.5);
2438 if (markerstyle == 2) {
2440 shape[0].x = -im; shape[0].y = 0;
2441 shape[1].x = im; shape[1].y = 0;
2442 shape[2].x = 0 ; shape[2].y = -im;
2443 shape[3].x = 0 ; shape[3].y = im;
2444 SetMarkerType(4,4,shape);
2445 }
else if (markerstyle == 3 || markerstyle == 31) {
2447 shape[0].x = -im; shape[0].y = 0;
2448 shape[1].x = im; shape[1].y = 0;
2449 shape[2].x = 0 ; shape[2].y = -im;
2450 shape[3].x = 0 ; shape[3].y = im;
2451 im = Int_t(0.707*Float_t(im) + 0.5);
2452 shape[4].x = -im; shape[4].y = -im;
2453 shape[5].x = im; shape[5].y = im;
2454 shape[6].x = -im; shape[6].y = im;
2455 shape[7].x = im; shape[7].y = -im;
2456 SetMarkerType(4,8,shape);
2457 }
else if (markerstyle == 4 || markerstyle == 24) {
2459 SetMarkerType(0,im*2,shape);
2460 }
else if (markerstyle == 5) {
2462 im = Int_t(0.707*Float_t(im) + 0.5);
2463 shape[0].x = -im; shape[0].y = -im;
2464 shape[1].x = im; shape[1].y = im;
2465 shape[2].x = -im; shape[2].y = im;
2466 shape[3].x = im; shape[3].y = -im;
2467 SetMarkerType(4,4,shape);
2468 }
else if (markerstyle == 6) {
2470 shape[0].x = -1 ; shape[0].y = 0;
2471 shape[1].x = 1 ; shape[1].y = 0;
2472 shape[2].x = 0 ; shape[2].y = -1;
2473 shape[3].x = 0 ; shape[3].y = 1;
2474 SetMarkerType(4,4,shape);
2475 }
else if (markerstyle == 7) {
2477 shape[0].x = -1 ; shape[0].y = 1;
2478 shape[1].x = 1 ; shape[1].y = 1;
2479 shape[2].x = -1 ; shape[2].y = 0;
2480 shape[3].x = 1 ; shape[3].y = 0;
2481 shape[4].x = -1 ; shape[4].y = -1;
2482 shape[5].x = 1 ; shape[5].y = -1;
2483 SetMarkerType(4,6,shape);
2484 }
else if (markerstyle == 8 || markerstyle == 20) {
2486 SetMarkerType(1,im*2,shape);
2487 }
else if (markerstyle == 21) {
2489 shape[0].x = -im; shape[0].y = -im;
2490 shape[1].x = im; shape[1].y = -im;
2491 shape[2].x = im; shape[2].y = im;
2492 shape[3].x = -im; shape[3].y = im;
2493 shape[4].x = -im; shape[4].y = -im;
2494 SetMarkerType(3,5,shape);
2495 }
else if (markerstyle == 22) {
2497 shape[0].x = -im; shape[0].y = im;
2498 shape[1].x = im; shape[1].y = im;
2499 shape[2].x = 0; shape[2].y = -im;
2500 shape[3].x = -im; shape[3].y = im;
2501 SetMarkerType(3,4,shape);
2502 }
else if (markerstyle == 23) {
2504 shape[0].x = 0; shape[0].y = im;
2505 shape[1].x = im; shape[1].y = -im;
2506 shape[2].x = -im; shape[2].y = -im;
2507 shape[3].x = 0; shape[3].y = im;
2508 SetMarkerType(3,4,shape);
2509 }
else if (markerstyle == 25) {
2511 shape[0].x = -im; shape[0].y = -im;
2512 shape[1].x = im; shape[1].y = -im;
2513 shape[2].x = im; shape[2].y = im;
2514 shape[3].x = -im; shape[3].y = im;
2515 shape[4].x = -im; shape[4].y = -im;
2516 SetMarkerType(2,5,shape);
2517 }
else if (markerstyle == 26) {
2519 shape[0].x = -im; shape[0].y = im;
2520 shape[1].x = im; shape[1].y = im;
2521 shape[2].x = 0; shape[2].y = -im;
2522 shape[3].x = -im; shape[3].y = im;
2523 SetMarkerType(2,4,shape);
2524 }
else if (markerstyle == 27) {
2526 Int_t imx = Int_t(2.66*fMarkerSize + 0.5);
2527 shape[0].x =-imx; shape[0].y = 0;
2528 shape[1].x = 0; shape[1].y = -im;
2529 shape[2].x = imx; shape[2].y = 0;
2530 shape[3].x = 0; shape[3].y = im;
2531 shape[4].x =-imx; shape[4].y = 0;
2532 SetMarkerType(2,5,shape);
2533 }
else if (markerstyle == 28) {
2535 Int_t imx = Int_t(1.33*fMarkerSize + 0.5);
2536 shape[0].x = -im; shape[0].y =-imx;
2537 shape[1].x =-imx; shape[1].y =-imx;
2538 shape[2].x =-imx; shape[2].y = -im;
2539 shape[3].x = imx; shape[3].y = -im;
2540 shape[4].x = imx; shape[4].y =-imx;
2541 shape[5].x = im; shape[5].y =-imx;
2542 shape[6].x = im; shape[6].y = imx;
2543 shape[7].x = imx; shape[7].y = imx;
2544 shape[8].x = imx; shape[8].y = im;
2545 shape[9].x =-imx; shape[9].y = im;
2546 shape[10].x=-imx; shape[10].y= imx;
2547 shape[11].x= -im; shape[11].y= imx;
2548 shape[12].x= -im; shape[12].y=-imx;
2549 SetMarkerType(2,13,shape);
2550 }
else if (markerstyle == 29) {
2552 Int_t im1 = Int_t(0.66*fMarkerSize + 0.5);
2553 Int_t im2 = Int_t(2.00*fMarkerSize + 0.5);
2554 Int_t im3 = Int_t(2.66*fMarkerSize + 0.5);
2555 Int_t im4 = Int_t(1.33*fMarkerSize + 0.5);
2556 shape[0].x = -im; shape[0].y = im4;
2557 shape[1].x =-im2; shape[1].y =-im1;
2558 shape[2].x =-im3; shape[2].y = -im;
2559 shape[3].x = 0; shape[3].y =-im2;
2560 shape[4].x = im3; shape[4].y = -im;
2561 shape[5].x = im2; shape[5].y =-im1;
2562 shape[6].x = im; shape[6].y = im4;
2563 shape[7].x = im4; shape[7].y = im4;
2564 shape[8].x = 0; shape[8].y = im;
2565 shape[9].x =-im4; shape[9].y = im4;
2566 shape[10].x= -im; shape[10].y= im4;
2567 SetMarkerType(3,11,shape);
2568 }
else if (markerstyle == 30) {
2570 Int_t im1 = Int_t(0.66*fMarkerSize + 0.5);
2571 Int_t im2 = Int_t(2.00*fMarkerSize + 0.5);
2572 Int_t im3 = Int_t(2.66*fMarkerSize + 0.5);
2573 Int_t im4 = Int_t(1.33*fMarkerSize + 0.5);
2574 shape[0].x = -im; shape[0].y = im4;
2575 shape[1].x =-im2; shape[1].y =-im1;
2576 shape[2].x =-im3; shape[2].y = -im;
2577 shape[3].x = 0; shape[3].y =-im2;
2578 shape[4].x = im3; shape[4].y = -im;
2579 shape[5].x = im2; shape[5].y =-im1;
2580 shape[6].x = im; shape[6].y = im4;
2581 shape[7].x = im4; shape[7].y = im4;
2582 shape[8].x = 0; shape[8].y = im;
2583 shape[9].x =-im4; shape[9].y = im4;
2584 shape[10].x= -im; shape[10].y= im4;
2585 SetMarkerType(2,11,shape);
2586 }
else if (markerstyle == 32) {
2588 shape[0].x = 0; shape[0].y = im;
2589 shape[1].x = im; shape[1].y = -im;
2590 shape[2].x = -im; shape[2].y = -im;
2591 shape[3].x = 0; shape[3].y = im;
2592 SetMarkerType(2,4,shape);
2593 }
else if (markerstyle == 33) {
2595 Int_t imx = Int_t(2.66*fMarkerSize + 0.5);
2596 shape[0].x =-imx; shape[0].y = 0;
2597 shape[1].x = 0; shape[1].y = -im;
2598 shape[2].x = imx; shape[2].y = 0;
2599 shape[3].x = 0; shape[3].y = im;
2600 shape[4].x =-imx; shape[4].y = 0;
2601 SetMarkerType(3,5,shape);
2602 }
else if (markerstyle == 34) {
2604 Int_t imx = Int_t(1.33*fMarkerSize + 0.5);
2605 shape[0].x = -im; shape[0].y =-imx;
2606 shape[1].x =-imx; shape[1].y =-imx;
2607 shape[2].x =-imx; shape[2].y = -im;
2608 shape[3].x = imx; shape[3].y = -im;
2609 shape[4].x = imx; shape[4].y =-imx;
2610 shape[5].x = im; shape[5].y =-imx;
2611 shape[6].x = im; shape[6].y = imx;
2612 shape[7].x = imx; shape[7].y = imx;
2613 shape[8].x = imx; shape[8].y = im;
2614 shape[9].x =-imx; shape[9].y = im;
2615 shape[10].x=-imx; shape[10].y= imx;
2616 shape[11].x= -im; shape[11].y= imx;
2617 shape[12].x= -im; shape[12].y=-imx;
2618 SetMarkerType(3,13,shape);
2619 }
else if (markerstyle == 35) {
2621 shape[0].x =-im; shape[0].y = 0;
2622 shape[1].x = 0; shape[1].y = -im;
2623 shape[2].x = im; shape[2].y = 0;
2624 shape[3].x = 0; shape[3].y = im;
2625 shape[4].x =-im; shape[4].y = 0;
2626 shape[5].x = im; shape[5].y = 0;
2627 shape[6].x = 0; shape[6].y = im;
2628 shape[7].x = 0; shape[7].y =-im;
2629 SetMarkerType(2,8,shape);
2630 }
else if (markerstyle == 36) {
2632 shape[0].x = -im; shape[0].y = -im;
2633 shape[1].x = im; shape[1].y = -im;
2634 shape[2].x = im; shape[2].y = im;
2635 shape[3].x = -im; shape[3].y = im;
2636 shape[4].x = -im; shape[4].y = -im;
2637 shape[5].x = im; shape[5].y = im;
2638 shape[6].x = -im; shape[6].y = im;
2639 shape[7].x = im; shape[7].y = -im;
2640 SetMarkerType(2,8,shape);
2641 }
else if (markerstyle == 37) {
2643 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2644 shape[0].x = 0; shape[0].y = 0;
2645 shape[1].x =-im2; shape[1].y = im;
2646 shape[2].x = im2; shape[2].y = im;
2647 shape[3].x = 0; shape[3].y = 0;
2648 shape[4].x =-im2; shape[4].y = -im;
2649 shape[5].x = -im; shape[5].y = 0;
2650 shape[6].x = 0; shape[6].y = 0;
2651 shape[7].x = im; shape[7].y = 0;
2652 shape[8].x = im2; shape[8].y = -im;
2653 shape[9].x = 0; shape[9].y = 0;
2654 SetMarkerType(2, 10,shape);
2655 }
else if (markerstyle == 38) {
2657 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2658 shape[0].x = -im; shape[0].y = 0;
2659 shape[1].x = -im; shape[1].y =-im2;
2660 shape[2].x =-im2; shape[2].y = -im;
2661 shape[3].x = im2; shape[3].y = -im;
2662 shape[4].x = im; shape[4].y =-im2;
2663 shape[5].x = im; shape[5].y = im2;
2664 shape[6].x = im2; shape[6].y = im;
2665 shape[7].x =-im2; shape[7].y = im;
2666 shape[8].x = -im; shape[8].y = im2;
2667 shape[9].x = -im; shape[9].y = 0;
2668 shape[10].x = im; shape[10].y = 0;
2669 shape[11].x = 0; shape[11].y = 0;
2670 shape[12].x = 0; shape[12].y = -im;
2671 shape[13].x = 0; shape[13].y = im;
2672 shape[14].x = 0; shape[14].y = 0;
2673 SetMarkerType(2,15,shape);
2674 }
else if (markerstyle == 39) {
2676 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2677 shape[0].x = 0; shape[0].y = 0;
2678 shape[1].x =-im2; shape[1].y = im;
2679 shape[2].x = im2; shape[2].y = im;
2680 shape[3].x = 0; shape[3].y = 0;
2681 shape[4].x =-im2; shape[4].y = -im;
2682 shape[5].x = -im; shape[5].y = 0;
2683 shape[6].x = 0; shape[6].y = 0;
2684 shape[7].x = im; shape[7].y = 0;
2685 shape[8].x = im2; shape[8].y = -im;
2686 SetMarkerType(3,9,shape);
2687 }
else if (markerstyle == 40) {
2689 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2690 shape[0].x = 0; shape[0].y = 0;
2691 shape[1].x = im2; shape[1].y = im;
2692 shape[2].x = im; shape[2].y = im2;
2693 shape[3].x = 0; shape[3].y = 0;
2694 shape[4].x = im; shape[4].y = -im2;
2695 shape[5].x = im2; shape[5].y = -im;
2696 shape[6].x = 0; shape[6].y = 0;
2697 shape[7].x = -im2; shape[7].y = -im;
2698 shape[8].x = -im; shape[8].y = -im2;
2699 shape[9].x = 0; shape[9].y = 0;
2700 shape[10].x = -im; shape[10].y = im2;
2701 shape[11].x = -im2; shape[11].y = im;
2702 shape[12].x = 0; shape[12].y = 0;
2703 SetMarkerType(2,13,shape);
2704 }
else if (markerstyle == 41) {
2706 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2707 shape[0].x = 0; shape[0].y = 0;
2708 shape[1].x = im2; shape[1].y = im;
2709 shape[2].x = im; shape[2].y = im2;
2710 shape[3].x = 0; shape[3].y = 0;
2711 shape[4].x = im; shape[4].y = -im2;
2712 shape[5].x = im2; shape[5].y = -im;
2713 shape[6].x = 0; shape[6].y = 0;
2714 shape[7].x = -im2; shape[7].y = -im;
2715 shape[8].x = -im; shape[8].y = -im2;
2716 shape[9].x = 0; shape[9].y = 0;
2717 shape[10].x = -im; shape[10].y = im2;
2718 shape[11].x = -im2; shape[11].y = im;
2719 shape[12].x = 0; shape[12].y = 0;
2720 SetMarkerType(3,13,shape);
2721 }
else if (markerstyle == 42) {
2723 Int_t imx = Int_t(fMarkerSize + 0.5);
2724 shape[0].x= 0; shape[0].y= im;
2725 shape[1].x= -imx; shape[1].y= imx;
2726 shape[2].x = -im; shape[2].y = 0;
2727 shape[3].x = -imx; shape[3].y = -imx;
2728 shape[4].x = 0; shape[4].y = -im;
2729 shape[5].x = imx; shape[5].y = -imx;
2730 shape[6].x = im; shape[6].y = 0;
2731 shape[7].x= imx; shape[7].y= imx;
2732 shape[8].x= 0; shape[8].y= im;
2733 SetMarkerType(2,9,shape);
2734 }
else if (markerstyle == 43) {
2736 Int_t imx = Int_t(fMarkerSize + 0.5);
2737 shape[0].x = 0; shape[0].y = im;
2738 shape[1].x = -imx; shape[1].y = imx;
2739 shape[2].x = -im; shape[2].y = 0;
2740 shape[3].x = -imx; shape[3].y = -imx;
2741 shape[4].x = 0; shape[4].y = -im;
2742 shape[5].x = imx; shape[5].y = -imx;
2743 shape[6].x = im; shape[6].y = 0;
2744 shape[7].x = imx; shape[7].y = imx;
2745 shape[8].x = 0; shape[8].y = im;
2746 SetMarkerType(3,9,shape);
2747 }
else if (markerstyle == 44) {
2749 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2750 shape[0].x = 0; shape[0].y = 0;
2751 shape[1].x = im2; shape[1].y = im;
2752 shape[2].x = -im2; shape[2].y = im;
2753 shape[3].x = im2; shape[3].y = -im;
2754 shape[4].x = -im2; shape[4].y = -im;
2755 shape[5].x = 0; shape[5].y = 0;
2756 shape[6].x = im; shape[6].y = im2;
2757 shape[7].x = im; shape[7].y = -im2;
2758 shape[8].x = -im; shape[8].y = im2;
2759 shape[9].x = -im; shape[9].y = -im2;
2760 shape[10].x = 0; shape[10].y = 0;
2761 SetMarkerType(2,11,shape);
2762 }
else if (markerstyle == 45) {
2764 Int_t im0 = Int_t(0.4*fMarkerSize + 0.5);
2765 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2766 shape[0].x = im0; shape[0].y = im0;
2767 shape[1].x = im2; shape[1].y = im;
2768 shape[2].x = -im2; shape[2].y = im;
2769 shape[3].x = -im0; shape[3].y = im0;
2770 shape[4].x = -im; shape[4].y = im2;
2771 shape[5].x = -im; shape[5].y = -im2;
2772 shape[6].x = -im0; shape[6].y = -im0;
2773 shape[7].x = -im2; shape[7].y = -im;
2774 shape[8].x = im2; shape[8].y = -im;
2775 shape[9].x = im0; shape[9].y = -im0;
2776 shape[10].x = im; shape[10].y = -im2;
2777 shape[11].x = im; shape[11].y = im2;
2778 shape[12].x = im0; shape[12].y = im0;
2779 SetMarkerType(3,13,shape);
2780 }
else if (markerstyle == 46) {
2782 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2783 shape[0].x = 0; shape[0].y = im2;
2784 shape[1].x = -im2; shape[1].y = im;
2785 shape[2].x = -im; shape[2].y = im2;
2786 shape[3].x = -im2; shape[3].y = 0;
2787 shape[4].x = -im; shape[4].y = -im2;
2788 shape[5].x = -im2; shape[5].y = -im;
2789 shape[6].x = 0; shape[6].y = -im2;
2790 shape[7].x = im2; shape[7].y = -im;
2791 shape[8].x = im; shape[8].y = -im2;
2792 shape[9].x = im2; shape[9].y = 0;
2793 shape[10].x = im; shape[10].y = im2;
2794 shape[11].x = im2; shape[11].y = im;
2795 shape[12].x = 0; shape[12].y = im2;
2796 SetMarkerType(2,13,shape);
2797 }
else if (markerstyle == 47) {
2799 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2800 shape[0].x = 0; shape[0].y = im2;
2801 shape[1].x = -im2; shape[1].y = im;
2802 shape[2].x = -im; shape[2].y = im2;
2803 shape[3].x = -im2; shape[3].y = 0;
2804 shape[4].x = -im; shape[4].y = -im2;
2805 shape[5].x = -im2; shape[5].y = -im;
2806 shape[6].x = 0; shape[6].y = -im2;
2807 shape[7].x = im2; shape[7].y = -im;
2808 shape[8].x = im; shape[8].y = -im2;
2809 shape[9].x = im2; shape[9].y = 0;
2810 shape[10].x = im; shape[10].y = im2;
2811 shape[11].x = im2; shape[11].y = im;
2812 shape[12].x = 0; shape[12].y = im2;
2813 SetMarkerType(3,13,shape);
2814 }
else if (markerstyle == 48) {
2816 Int_t im2 = Int_t(2.0*fMarkerSize + 0.5);
2817 shape[0].x = 0; shape[0].y = im2*1.005;
2818 shape[1].x = -im2; shape[1].y = im;
2819 shape[2].x = -im; shape[2].y = im2;
2820 shape[3].x = -im2; shape[3].y = 0;
2821 shape[4].x = -im; shape[4].y = -im2;
2822 shape[5].x = -im2; shape[5].y = -im;
2823 shape[6].x = 0; shape[6].y = -im2;
2824 shape[7].x = im2; shape[7].y = -im;
2825 shape[8].x = im; shape[8].y = -im2;
2826 shape[9].x = im2; shape[9].y = 0;
2827 shape[10].x = im; shape[10].y = im2;
2828 shape[11].x = im2; shape[11].y = im;
2829 shape[12].x = 0; shape[12].y = im2*0.995;
2830 shape[13].x = im2*0.995; shape[13].y = 0;
2831 shape[14].x = 0; shape[14].y = -im2*0.995;
2832 shape[15].x = -im2*0.995; shape[15].y = 0;
2833 shape[16].x = 0; shape[16].y = im2*0.995;
2834 SetMarkerType(3,16,shape);
2835 }
else if (markerstyle == 49) {
2837 Int_t imx = Int_t(1.33*fMarkerSize + 0.5);
2838 shape[0].x =-imx; shape[0].y =-imx*1.005;
2839 shape[1].x =-imx; shape[1].y = -im;
2840 shape[2].x = imx; shape[2].y = -im;
2841 shape[3].x = imx; shape[3].y =-imx;
2842 shape[4].x = im; shape[4].y =-imx;
2843 shape[5].x = im; shape[5].y = imx;
2844 shape[6].x = imx; shape[6].y = imx;
2845 shape[7].x = imx; shape[7].y = im;
2846 shape[8].x =-imx; shape[8].y = im;
2847 shape[9].x =-imx; shape[9].y = imx;
2848 shape[10].x = -im; shape[10].y = imx;
2849 shape[11].x = -im; shape[11].y =-imx;
2850 shape[12].x =-imx; shape[12].y =-imx*0.995;
2851 shape[13].x =-imx; shape[13].y = imx;
2852 shape[14].x = imx; shape[14].y = imx;
2853 shape[15].x = imx; shape[15].y =-imx;
2854 shape[16].x =-imx; shape[16].y =-imx*1.005;
2855 SetMarkerType(3,17,shape);
2858 SetMarkerType(0,0,shape);
2869 void TGX11::SetOpacity(Int_t percent)
2871 if (fDepth <= 8)
return;
2872 if (percent == 0)
return;
2875 ULong_t *orgcolors = 0, *tmpc = 0;
2876 Int_t maxcolors = 0, ncolors = 0, ntmpc = 0;
2879 if (gCws->fNewColors) {
2880 tmpc = gCws->fNewColors;
2881 ntmpc = gCws->fNcolors;
2885 XImage *image = XGetImage((Display*)fDisplay, gCws->fDrawing, 0, 0, gCws->fWidth,
2886 gCws->fHeight, AllPlanes, ZPixmap);
2890 for (y = 0; y < (int) gCws->fHeight; y++) {
2891 for (x = 0; x < (int) gCws->fWidth; x++) {
2892 ULong_t pixel = XGetPixel(image, x, y);
2893 CollectImageColors(pixel, orgcolors, ncolors, maxcolors);
2897 XDestroyImage(image);
2898 ::operator
delete(orgcolors);
2903 MakeOpaqueColors(percent, orgcolors, ncolors);
2905 if (gCws->fNewColors) {
2907 for (y = 0; y < (int) gCws->fHeight; y++) {
2908 for (x = 0; x < (int) gCws->fWidth; x++) {
2909 ULong_t pixel = XGetPixel(image, x, y);
2910 Int_t idx = FindColor(pixel, orgcolors, ncolors);
2911 XPutPixel(image, x, y, gCws->fNewColors[idx]);
2917 XPutImage((Display*)fDisplay, gCws->fDrawing, *gGCpxmp, image, 0, 0, 0, 0,
2918 gCws->fWidth, gCws->fHeight);
2919 XFlush((Display*)fDisplay);
2924 XFreeColors((Display*)fDisplay, fColormap, tmpc, ntmpc, 0);
2927 XDestroyImage(image);
2928 ::operator
delete(orgcolors);
2934 void TGX11::CollectImageColors(ULong_t pixel, ULong_t *&orgcolors, Int_t &ncolors,
2937 if (maxcolors == 0) {
2940 orgcolors = (ULong_t*) ::
operator new(maxcolors*
sizeof(ULong_t));
2943 for (
int i = 0; i < ncolors; i++)
2944 if (pixel == orgcolors[i])
return;
2946 if (ncolors >= maxcolors) {
2947 orgcolors = (ULong_t*) TStorage::ReAlloc(orgcolors,
2948 maxcolors*2*
sizeof(ULong_t), maxcolors*
sizeof(ULong_t));
2952 orgcolors[ncolors++] = pixel;
2959 void TGX11::MakeOpaqueColors(Int_t percent, ULong_t *orgcolors, Int_t ncolors)
2961 if (ncolors == 0)
return;
2963 RXColor *xcol =
new RXColor[ncolors];
2966 for (i = 0; i < ncolors; i++) {
2967 xcol[i].pixel = orgcolors[i];
2968 xcol[i].red = xcol[i].green = xcol[i].blue = 0;
2969 xcol[i].flags = DoRed | DoGreen | DoBlue;
2971 QueryColors(fColormap, xcol, ncolors);
2973 UShort_t add = percent * kBIGGEST_RGB_VALUE / 100;
2976 for (i = 0; i < ncolors; i++) {
2977 val = xcol[i].red + add;
2978 if (val > kBIGGEST_RGB_VALUE) val = kBIGGEST_RGB_VALUE;
2979 xcol[i].red = (UShort_t) val;
2980 val = xcol[i].green + add;
2981 if (val > kBIGGEST_RGB_VALUE) val = kBIGGEST_RGB_VALUE;
2982 xcol[i].green = (UShort_t) val;
2983 val = xcol[i].blue + add;
2984 if (val > kBIGGEST_RGB_VALUE) val = kBIGGEST_RGB_VALUE;
2985 xcol[i].blue = (UShort_t) val;
2986 if (!AllocColor(fColormap, &xcol[i]))
2987 Warning(
"MakeOpaqueColors",
"failed to allocate color %hd, %hd, %hd",
2988 xcol[i].red, xcol[i].green, xcol[i].blue);
2992 gCws->fNewColors =
new ULong_t[ncolors];
2993 gCws->fNcolors = ncolors;
2995 for (i = 0; i < ncolors; i++)
2996 gCws->fNewColors[i] = xcol[i].pixel;
3004 Int_t TGX11::FindColor(ULong_t pixel, ULong_t *orgcolors, Int_t ncolors)
3006 for (
int i = 0; i < ncolors; i++)
3007 if (pixel == orgcolors[i])
return i;
3009 Error(
"FindColor",
"did not find color, should never happen!");
3020 void TGX11::SetRGB(
int cindex,
float r,
float g,
float b)
3024 xcol.red = (UShort_t)(r * kBIGGEST_RGB_VALUE);
3025 xcol.green = (UShort_t)(g * kBIGGEST_RGB_VALUE);
3026 xcol.blue = (UShort_t)(b * kBIGGEST_RGB_VALUE);
3027 xcol.flags = DoRed | DoGreen | DoBlue;
3028 XColor_t &col = GetColor(cindex);
3031 if (col.fRed == xcol.red && col.fGreen == xcol.green &&
3032 col.fBlue == xcol.blue)
3034 col.fDefined = kFALSE;
3036 XFreeColors((Display*)fDisplay, fColormap, &col.fPixel, 1, 0);
3038 if (AllocColor(fColormap, &xcol)) {
3039 col.fDefined = kTRUE;
3040 col.fPixel = xcol.pixel;
3041 col.fRed = xcol.red;
3042 col.fGreen = xcol.green;
3043 col.fBlue = xcol.blue;
3053 void TGX11::SetTextAlign(Short_t talign)
3055 Int_t txalh = talign/10;
3056 Int_t txalv = talign%10;
3057 fTextAlignH = txalh;
3058 fTextAlignV = txalv;
3104 TAttText::SetTextAlign(fTextAlign);
3110 void TGX11::SetTextColor(Color_t cindex)
3112 if (cindex < 0)
return;
3114 TAttText::SetTextColor(cindex);
3116 SetColor(gGCtext, Int_t(cindex));
3119 if (XGetGCValues((Display*)fDisplay, *gGCtext, GCForeground | GCBackground, &values)) {
3120 XSetForeground( (Display*)fDisplay, *gGCinvt, values.background );
3121 XSetBackground( (Display*)fDisplay, *gGCinvt, values.foreground );
3123 Error(
"SetTextColor",
"cannot get GC values");
3125 XSetBackground((Display*)fDisplay, *gGCtext, GetColor(0).fPixel);
3139 Int_t TGX11::SetTextFont(
char *fontname, ETextSetMode mode)
3145 if (mode == kLoad) {
3146 for (i = 0; i < kMAXFONT; i++) {
3147 if (strcmp(fontname, gFont[i].name) == 0) {
3148 gTextFont = gFont[i].id;
3149 XSetFont((Display*)fDisplay, *gGCtext, gTextFont->fid);
3150 XSetFont((Display*)fDisplay, *gGCinvt, gTextFont->fid);
3156 fontlist = XListFonts((Display*)fDisplay, fontname, 1, &fontcount);
3158 if (fontlist && fontcount != 0) {
3159 if (mode == kLoad) {
3160 if (gFont[gCurrentFontNumber].
id)
3161 XFreeFont((Display*)fDisplay, gFont[gCurrentFontNumber].
id);
3162 gTextFont = XLoadQueryFont((Display*)fDisplay, fontlist[0]);
3163 XSetFont((Display*)fDisplay, *gGCtext, gTextFont->fid);
3164 XSetFont((Display*)fDisplay, *gGCinvt, gTextFont->fid);
3165 gFont[gCurrentFontNumber].id = gTextFont;
3166 strlcpy(gFont[gCurrentFontNumber].name,fontname,80);
3167 gCurrentFontNumber++;
3168 if (gCurrentFontNumber == kMAXFONT) gCurrentFontNumber = 0;
3170 XFreeFontNames(fontlist);
3180 void TGX11::SetTextFont(Font_t fontnumber)
3182 fTextFont = fontnumber;
3188 void TGX11::SetTextSize(Float_t textsize)
3190 fTextSize = textsize;
3200 void TGX11::Sync(
int mode)
3205 XSynchronize((Display*)fDisplay,1);
3209 XSynchronize((Display*)fDisplay,0);
3223 void TGX11::UpdateWindow(
int mode)
3225 if (gCws->fDoubleBuffer) {
3226 XCopyArea((Display*)fDisplay, gCws->fDrawing, gCws->fWindow,
3227 *gGCpxmp, 0, 0, gCws->fWidth, gCws->fHeight, 0, 0);
3230 XFlush((Display*)fDisplay);
3232 XSync((Display*)fDisplay, False);
3246 void TGX11::Warp(Int_t ix, Int_t iy, Window_t
id)
3252 XWarpPointer((Display*)fDisplay, None, (Window)
id, 0, 0, 0, 0, ix, iy);
3263 void TGX11::WritePixmap(
int wid,
unsigned int w,
unsigned int h,
char *pxname)
3265 unsigned int wval, hval;
3269 gTws = &fWindows[wid];
3270 XWriteBitmapFile((Display*)fDisplay, pxname, gTws->fDrawing, wval, hval, -1, -1);
3279 static XImage *gXimage = 0;
3282 int GIFquantize(UInt_t width, UInt_t height, Int_t *ncol, Byte_t *red, Byte_t *green,
3283 Byte_t *blue, Byte_t *outputBuf, Byte_t *outputCmap);
3284 long GIFencode(
int Width,
int Height, Int_t Ncol, Byte_t R[], Byte_t G[], Byte_t B[], Byte_t ScLine[],
3285 void (*get_scline) (
int,
int, Byte_t *),
void (*pb)(Byte_t));
3286 int GIFdecode(Byte_t *gifArr, Byte_t *pixArr,
int *Width,
int *Height,
int *Ncols, Byte_t *R, Byte_t *G, Byte_t *B);
3287 int GIFinfo(Byte_t *gifArr,
int *Width,
int *Height,
int *Ncols);
3293 static void GetPixel(
int y,
int width, Byte_t *scline)
3295 for (
int i = 0; i < width; i++)
3296 scline[i] = Byte_t(XGetPixel(gXimage, i, y));
3302 static void PutByte(Byte_t b)
3304 if (ferror(gOut) == 0) fputc(b, gOut);
3316 void TGX11::ImgPickPalette(RXImage *image, Int_t &ncol, Int_t *&R, Int_t *&G, Int_t *&B)
3318 ULong_t *orgcolors = 0;
3319 Int_t maxcolors = 0, ncolors = 0;
3323 for (x = 0; x < (int) gCws->fWidth; x++) {
3324 for (y = 0; y < (int) gCws->fHeight; y++) {
3325 ULong_t pixel = XGetPixel(image, x, y);
3326 CollectImageColors(pixel, orgcolors, ncolors, maxcolors);
3331 RXColor *xcol =
new RXColor[ncolors];
3334 for (i = 0; i < ncolors; i++) {
3335 xcol[i].pixel = orgcolors[i];
3336 xcol[i].red = xcol[i].green = xcol[i].blue = 0;
3337 xcol[i].flags = DoRed | DoGreen | DoBlue;
3339 QueryColors(fColormap, xcol, ncolors);
3343 R =
new Int_t[ncolors];
3344 G =
new Int_t[ncolors];
3345 B =
new Int_t[ncolors];
3347 for (i = 0; i < ncolors; i++) {
3349 G[i] = xcol[i].green;
3350 B[i] = xcol[i].blue;
3355 for (x = 0; x < (int) gCws->fWidth; x++) {
3356 for (y = 0; y < (int) gCws->fHeight; y++) {
3357 ULong_t pixel = XGetPixel(image, x, y);
3358 Int_t idx = FindColor(pixel, orgcolors, ncolors);
3359 XPutPixel(image, x, y, idx);
3365 ::operator
delete(orgcolors);
3372 Int_t TGX11::WriteGIF(
char *name)
3374 Byte_t scline[2000], r[256], b[256], g[256];
3375 Int_t *red, *green, *blue;
3376 Int_t ncol, maxcol, i;
3379 XDestroyImage(gXimage);
3383 gXimage = XGetImage((Display*)fDisplay, gCws->fDrawing, 0, 0,
3384 gCws->fWidth, gCws->fHeight,
3385 AllPlanes, ZPixmap);
3387 ImgPickPalette((RXImage*)gXimage, ncol, red, green, blue);
3391 Error(
"WriteGIF",
"Cannot create GIF of image containing more than 256 colors. Try in batch mode.");
3399 for (i = 0; i < ncol; i++) {
3400 if (maxcol < red[i] ) maxcol = red[i];
3401 if (maxcol < green[i] ) maxcol = green[i];
3402 if (maxcol < blue[i] ) maxcol = blue[i];
3408 for (i = 0; i < ncol; i++) {
3409 r[i] = red[i] * 255/maxcol;
3410 g[i] = green[i] * 255/maxcol;
3411 b[i] = blue[i] * 255/maxcol;
3415 gOut = fopen(name,
"w+");
3418 GIFencode(gCws->fWidth, gCws->fHeight,
3419 ncol, r, g, b, scline, ::GetPixel, PutByte);
3423 Error(
"WriteGIF",
"cannot write file: %s",name);
3435 void TGX11::PutImage(
int offset,
int itran,
int x0,
int y0,
int nx,
int ny,
int xmin,
3436 int ymin,
int xmax,
int ymax,
unsigned char *image,Drawable_t wid)
3438 const int maxSegment = 20;
3439 int i, n, x, y, xcur, x1, x2, y1, y2;
3440 unsigned char *jimg, *jbase, icol;
3442 XSegment lines[256][maxSegment];
3448 id = gCws->fDrawing;
3451 for (i = 0; i < 256; i++) nlines[i] = 0;
3453 x1 = x0 + xmin; y1 = y0 + ny - ymax - 1;
3454 x2 = x0 + xmax; y2 = y0 + ny - ymin - 1;
3455 jbase = image + (ymin-1)*nx + xmin;
3457 for (y = y2; y >= y1; y--) {
3458 xcur = x1; jbase += nx;
3459 for (jimg = jbase, icol = *jimg++, x = x1+1; x <= x2; jimg++, x++) {
3460 if (icol != *jimg) {
3461 if (icol != itran) {
3463 lines[icol][n].x1 = xcur; lines[icol][n].y1 = y;
3464 lines[icol][n].x2 = x-1; lines[icol][n].y2 = y;
3465 if (nlines[icol] == maxSegment) {
3466 SetColor(gGCline,(
int)icol+offset);
3467 XDrawSegments((Display*)fDisplay,
id,*gGCline,&lines[icol][0],
3472 icol = *jimg; xcur = x;
3475 if (icol != itran) {
3477 lines[icol][n].x1 = xcur; lines[icol][n].y1 = y;
3478 lines[icol][n].x2 = x-1; lines[icol][n].y2 = y;
3479 if (nlines[icol] == maxSegment) {
3480 SetColor(gGCline,(
int)icol+offset);
3481 XDrawSegments((Display*)fDisplay,
id,*gGCline,&lines[icol][0],
3488 for (i = 0; i < 256; i++) {
3489 if (nlines[i] != 0) {
3490 SetColor(gGCline,i+offset);
3491 XDrawSegments((Display*)fDisplay,
id,*gGCline,&lines[i][0],nlines[i]);
3500 Pixmap_t TGX11::ReadGIF(
int x0,
int y0,
const char *file, Window_t
id)
3503 Seek_t filesize = 0;
3504 unsigned char *gifArr, *pixArr, red[256], green[256], blue[256], *j1, *j2, icol;
3505 int i, j, k, width, height, ncolor, irep, offset;
3509 fd = fopen(file,
"r");
3511 Error(
"ReadGIF",
"unable to open GIF file");
3516 long ft = ftell(fd);
3518 Error(
"ReadGIF",
"unable to open GIF file");
3522 filesize = Seek_t(ft);
3526 if (!(gifArr = (
unsigned char *) calloc(filesize+256,1))) {
3527 Error(
"ReadGIF",
"unable to allocate array for gif");
3532 if (fread(gifArr, filesize, 1, fd) != 1) {
3533 Error(
"ReadGIF",
"GIF file read failed");
3540 irep = GIFinfo(gifArr, &width, &height, &ncolor);
3546 if (!(pixArr = (
unsigned char *) calloc((width*height),1))) {
3547 Error(
"ReadGIF",
"unable to allocate array for image");
3552 irep = GIFdecode(gifArr, pixArr, &width, &height, &ncolor, red, green, blue);
3563 for (i = 0; i < ncolor; i++) {
3573 for (i = 1; i <= height/2; i++) {
3574 j1 = pixArr + (i-1)*width;
3575 j2 = pixArr + (height-i)*width;
3576 for (k = 0; k < width; k++) {
3577 icol = *j1; *j1++ = *j2; *j2++ = icol;
3580 if (
id) pic = CreatePixmap(
id, width, height);
3581 PutImage(offset,-1,x0,y0,width,height,0,0,width-1,height-1,pixArr,pic);
3588 else if (gCws->fDrawing)
3589 return (Pixmap_t)gCws->fDrawing;
3603 unsigned char *TGX11::GetColorBits(Drawable_t , Int_t , Int_t ,
3616 Pixmap_t TGX11::CreatePixmapFromData(
unsigned char * , UInt_t ,
3630 Int_t TGX11::AddPixmap(ULong_t pixid, UInt_t w, UInt_t h)
3635 for (; wid < fMaxNumberOfWindows; ++wid)
3636 if (!fWindows[wid].fOpen)
3639 if (wid == fMaxNumberOfWindows) {
3640 Int_t newsize = fMaxNumberOfWindows + 10;
3641 fWindows = (XWindow_t*) TStorage::ReAlloc(
3642 fWindows, newsize *
sizeof(XWindow_t),
3643 fMaxNumberOfWindows*
sizeof(XWindow_t)
3646 for (Int_t i = fMaxNumberOfWindows; i < newsize; ++i)
3647 fWindows[i].fOpen = 0;
3649 fMaxNumberOfWindows = newsize;
3652 fWindows[wid].fOpen = 1;
3653 gCws = fWindows + wid;
3654 gCws->fWindow = pixid;
3655 gCws->fDrawing = gCws->fWindow;
3657 gCws->fDoubleBuffer = 0;
3658 gCws->fIsPixmap = 1;
3662 gCws->fNewColors = 0;
3663 gCws->fShared = kFALSE;
3677 Int_t TGX11::SupportsExtension(
const char *ext)
const
3679 Int_t major_opcode, first_event, first_error;
3680 if (!(Display*)fDisplay)
3682 return XQueryExtension((Display*)fDisplay, ext, &major_opcode, &first_event, &first_error);