31 #ifdef G4VIS_BUILD_RAYTRACERX_DRIVER
39 #include <X11/Xutil.h>
40 #include <X11/Xatom.h>
43 Bool G4RayTracerXScannerWaitForNotify (Display*, XEvent* e,
char* arg) {
44 return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
48 G4RTXScanner::G4RTXScanner():
50 ,theIRow(0), theIColumn(0)
51 ,display(0), win(0), scmap(0)
53 theGSName =
"RayTracerX";
54 theGSNickname =
"RayTracerX";
57 G4RTXScanner::~G4RTXScanner() {}
59 const G4String& G4RTXScanner::GetGSName()
const
62 const G4String& G4RTXScanner::GetGSNickname()
const
63 {
return theGSNickname;}
73 if (theStep > nMax)
break;
76 theIRow = theStep / 2;
77 theIColumn = theStep / 2 - theStep;
83 theIColumn += theStep;
86 if ((theIColumn + (3 * theStep) / 2 + 1)%(3 * theStep) == 0 &&
87 (theIRow + (3 * theStep) / 2 + 1)%(3 * theStep) == 0)
88 theIColumn += theStep;
91 if (theIColumn >= theNColumn) {
92 theIColumn = theStep / 2;
97 if (theIRow >= theNRow && theStep <= 1)
return false;
100 if (theIRow >= theNRow) {
102 theIRow = theStep / 2;
103 theIColumn = theStep / 2;
108 iColumn = theIColumn;
114 display = XOpenDisplay(0);
116 G4cerr <<
"G4RTXScanner::Initialize(): cannot get display."
121 int screen_num = DefaultScreen(display);
124 int xOffset = 0, yOffset = 0;
125 XSizeHints* size_hints = XAllocSizeHints();
126 unsigned int width, height;
128 if (!XGeometryString.empty()) {
129 G4int geometryResultMask = XParseGeometry
130 ((
char*)XGeometryString.c_str(),
131 &xOffset, &yOffset, &
width, &height);
132 if (geometryResultMask & (WidthValue | HeightValue)) {
133 if (geometryResultMask & XValue) {
134 if (geometryResultMask & XNegative) {
135 xOffset = DisplayWidth(display, screen_num) + xOffset -
width;
137 size_hints->flags |= PPosition;
138 size_hints->x = xOffset;
140 if (geometryResultMask & YValue) {
141 if (geometryResultMask & YNegative) {
142 yOffset = DisplayHeight(display, screen_num) + yOffset - height;
144 size_hints->flags |= PPosition;
145 size_hints->y = yOffset;
148 G4cout <<
"ERROR: Geometry string \""
150 <<
"\" invalid. Using \"600x600\"."
156 G4cout <<
"ERROR: Geometry string \""
158 <<
"\" is empty. Using \"600x600\"."
163 size_hints->width =
width;
164 size_hints->height = height;
165 size_hints->flags |= PSize;
167 win = XCreateSimpleWindow
168 (display, RootWindow(display, screen_num),
169 xOffset, yOffset, width, height,
171 WhitePixel(display, screen_num),
172 BlackPixel(display, screen_num));
175 gc = XCreateGC(display, win, 0, &values);
178 Status status = XGetRGBColormaps
179 (display, RootWindow(display, screen_num),
180 &scmap, &nMaps, XA_RGB_DEFAULT_MAP);
182 system(
"xstdcmap -best");
183 status = XGetRGBColormaps
184 (display, RootWindow(display, screen_num),
185 &scmap, &nMaps, XA_RGB_DEFAULT_MAP);
188 "G4RTXScanner::Initialize(): cannot get color map."
189 "\n Perhaps your system does not support XA_RGB_DEFAULT_MAP."
194 if (!scmap->colormap) {
195 G4cerr <<
"G4RTXScanner::Initialize(): color map empty."
200 XWMHints* wm_hints = XAllocWMHints();
201 XClassHint* class_hint = XAllocClassHint();
202 const char* window_name = name.c_str();
203 XTextProperty windowName;
204 XStringListToTextProperty((
char**)&window_name, 1, &windowName);
206 XSetWMProperties(display, win, &windowName, &windowName,
207 0, 0, size_hints, wm_hints, class_hint);
209 XMapWindow(display, win);
212 XSelectInput(display, win, StructureNotifyMask);
214 XIfEvent (display, &event, G4RayTracerXScannerWaitForNotify, (
char*) win);
219 void G4RTXScanner::Draw
220 (
unsigned char red,
unsigned char green,
unsigned char blue)
223 unsigned long pixel_value = scmap->base_pixel +
224 ((
unsigned long) ((red * scmap->red_max) / 256.) * scmap->red_mult) +
225 ((
unsigned long) ((green * scmap->green_max) / 256.) * scmap->green_mult) +
226 ((
unsigned long) ((blue * scmap->blue_max) / 256.) * scmap->blue_mult);
227 XSetForeground(display, gc, pixel_value);
230 XFillRectangle(display, win, gc,
231 theIColumn - theStep / 2,
232 theIRow - theStep / 2,
235 XDrawPoint(display, win, gc, theIColumn, theIRow);
const G4String & GetXGeometryString() const
G4GLOB_DLL std::ostream G4cout
T max(const T t1, const T t2)
brief Return the largest of the two arguments
static G4String Status(G4StepStatus stps)
G4GLOB_DLL std::ostream G4cerr