30#ifdef G4VIS_BUILD_RAYTRACERX_DRIVER
42 Bool G4RayTracerXScannerWaitForNotify (Display*, XEvent* e,
char* arg) {
43 return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
47G4RTXScanner::G4RTXScanner():
49 ,theIRow(0), theIColumn(0)
50 ,display(0), win(0), scmap(0)
52 theGSName =
"RayTracerX";
53 theGSNickname =
"RayTracerX";
56G4RTXScanner::~G4RTXScanner() {}
58const G4String& G4RTXScanner::GetGSName()
const
61const G4String& G4RTXScanner::GetGSNickname()
const
62{
return theGSNickname;}
64void G4RTXScanner::Initialize(
G4int nRow,
G4int nColumn) {
67 G4int nMax = std::max (nRow, nColumn);
72 if (theStep > nMax)
break;
75 theIRow = theStep / 2;
76 theIColumn = theStep / 2 - theStep;
82 theIColumn += theStep;
85 if ((theIColumn + (3 * theStep) / 2 + 1)%(3 * theStep) == 0 &&
86 (theIRow + (3 * theStep) / 2 + 1)%(3 * theStep) == 0)
87 theIColumn += theStep;
90 if (theIColumn >= theNColumn) {
91 theIColumn = theStep / 2;
96 if (theIRow >= theNRow && theStep <= 1)
return false;
99 if (theIRow >= theNRow) {
101 theIRow = theStep / 2;
102 theIColumn = theStep / 2;
107 iColumn = theIColumn;
113 display = XOpenDisplay(0);
115 G4cerr <<
"G4RTXScanner::Initialize(): cannot get display."
120 int screen_num = DefaultScreen(display);
123 int xOffset = 0, yOffset = 0;
124 XSizeHints* size_hints = XAllocSizeHints();
125 unsigned int width, height;
127 if (!XGeometryString.empty()) {
128 G4int geometryResultMask = XParseGeometry
129 ((
char*)XGeometryString.c_str(),
130 &xOffset, &yOffset, &width, &height);
131 if (geometryResultMask & (WidthValue | HeightValue)) {
132 if (geometryResultMask & XValue) {
133 if (geometryResultMask & XNegative) {
134 xOffset = DisplayWidth(display, screen_num) + xOffset - width;
136 size_hints->flags |= PPosition;
137 size_hints->x = xOffset;
139 if (geometryResultMask & YValue) {
140 if (geometryResultMask & YNegative) {
141 yOffset = DisplayHeight(display, screen_num) + yOffset - height;
143 size_hints->flags |= PPosition;
144 size_hints->y = yOffset;
147 G4cout <<
"ERROR: Geometry string \""
149 <<
"\" invalid. Using \"600x600\"."
155 G4cout <<
"ERROR: Geometry string \""
157 <<
"\" is empty. Using \"600x600\"."
162 size_hints->width = width;
163 size_hints->height = height;
164 size_hints->flags |= PSize;
166 win = XCreateSimpleWindow
167 (display, RootWindow(display, screen_num),
168 xOffset, yOffset, width, height,
170 WhitePixel(display, screen_num),
171 BlackPixel(display, screen_num));
174 gc = XCreateGC(display, win, 0, &values);
177 Status status = XGetRGBColormaps
178 (display, RootWindow(display, screen_num),
179 &scmap, &nMaps, XA_RGB_BEST_MAP);
181 system(
"xstdcmap -best");
182 status = XGetRGBColormaps
183 (display, RootWindow(display, screen_num),
184 &scmap, &nMaps, XA_RGB_BEST_MAP);
187 "G4RTXScanner::Initialize(): cannot get color map."
188 "\n Perhaps your system does not support XA_RGB_BEST_MAP."
193 if (!scmap->colormap) {
194 G4cerr <<
"G4RTXScanner::Initialize(): color map empty."
199 XWMHints* wm_hints = XAllocWMHints();
200 XClassHint* class_hint = XAllocClassHint();
201 const char* window_name =
name.c_str();
202 XTextProperty windowName;
203 XStringListToTextProperty((
char**)&window_name, 1, &windowName);
205 XSetWMProperties(display, win, &windowName, &windowName,
206 0, 0, size_hints, wm_hints, class_hint);
208 XMapWindow(display, win);
211 XSelectInput(display, win, StructureNotifyMask);
213 XIfEvent (display, &event, G4RayTracerXScannerWaitForNotify, (
char*) win);
218void G4RTXScanner::Draw
219(
unsigned char red,
unsigned char green,
unsigned char blue)
222 unsigned long pixel_value = scmap->base_pixel +
223 ((
unsigned long) ((red * scmap->red_max) / 256.) * scmap->red_mult) +
224 ((
unsigned long) ((green * scmap->green_max) / 256.) * scmap->green_mult) +
225 ((
unsigned long) ((blue * scmap->blue_max) / 256.) * scmap->blue_mult);
226 XSetForeground(display, gc, pixel_value);
229 XFillRectangle(display, win, gc,
230 theIColumn - theStep / 2,
231 theIRow - theStep / 2,
234 XDrawPoint(display, win, gc, theIColumn, theIRow);
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const G4String & GetXGeometryString() const
const char * name(G4int ptype)