18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
*/ |
20 |
|
|
21 |
#include "includes.h" |
#include <X11/Xlib.h> |
22 |
|
#include <time.h> |
23 |
|
#include "rdesktop.h" |
24 |
|
|
25 |
|
extern int width; |
26 |
|
extern int height; |
27 |
|
extern BOOL motion; |
28 |
|
|
29 |
|
static Display *display; |
30 |
|
static Window wnd; |
31 |
|
static GC gc; |
32 |
|
static Visual *visual; |
33 |
|
static XIM IM; |
34 |
|
|
35 |
HWINDOW ui_create_window(HCONN conn, int width, int height) |
BOOL ui_create_window(char *title) |
36 |
{ |
{ |
37 |
struct window *wnd; |
Screen *screen; |
38 |
XSetWindowAttributes attribs; |
XSetWindowAttributes attribs; |
39 |
Display *display; |
unsigned long input_mask; |
40 |
Visual *visual; |
int i; |
|
Window window; |
|
|
int black; |
|
|
GC gc; |
|
41 |
|
|
42 |
display = XOpenDisplay(NULL); |
display = XOpenDisplay(NULL); |
43 |
if (display == NULL) |
if (display == NULL) |
44 |
return NULL; |
{ |
45 |
|
ERROR("Failed to open display\n"); |
46 |
|
return False; |
47 |
|
} |
48 |
|
|
49 |
|
/* Check the screen supports 8-bit depth. */ |
50 |
|
screen = DefaultScreenOfDisplay(display); |
51 |
|
for (i = 0; i < screen->ndepths; i++) |
52 |
|
if (screen->depths[i].depth == 8) |
53 |
|
break; |
54 |
|
|
55 |
|
if (i >= screen->ndepths) |
56 |
|
{ |
57 |
|
ERROR("8-bit depth required (in this version).\n"); |
58 |
|
XCloseDisplay(display); |
59 |
|
return False; |
60 |
|
} |
61 |
|
|
62 |
visual = DefaultVisual(display, DefaultScreen(display)); |
visual = DefaultVisual(display, DefaultScreen(display)); |
|
black = BlackPixel(display, DefaultScreen(display)); |
|
63 |
|
|
64 |
attribs.background_pixel = black; |
attribs.background_pixel = BlackPixel(display, DefaultScreen(display)); |
65 |
attribs.backing_store = Always; |
attribs.backing_store = Always; |
66 |
window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, |
wnd = XCreateWindow(display, DefaultRootWindow(display), |
67 |
width, height, 0, 8, InputOutput, visual, |
0, 0, width, height, 0, 8, InputOutput, visual, |
68 |
CWBackingStore | CWBackPixel, &attribs); |
CWBackingStore | CWBackPixel, &attribs); |
69 |
|
|
70 |
XStoreName(display, window, "rdesktop"); |
XStoreName(display, wnd, title); |
71 |
XMapWindow(display, window); |
XMapWindow(display, wnd); |
72 |
XSelectInput(display, window, KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask); |
|
73 |
XSync(display, True); |
input_mask = KeyPressMask | KeyReleaseMask; |
74 |
|
input_mask |= ButtonPressMask | ButtonReleaseMask; |
75 |
gc = XCreateGC(display, window, 0, NULL); |
if (motion) |
76 |
|
input_mask |= PointerMotionMask; |
77 |
wnd = xmalloc(sizeof(struct window)); |
|
78 |
wnd->conn = conn; |
XSelectInput(display, wnd, input_mask); |
79 |
wnd->width = width; |
gc = XCreateGC(display, wnd, 0, NULL); |
80 |
wnd->height = height; |
|
81 |
wnd->display = display; |
IM = XOpenIM(display, NULL, NULL, NULL); |
82 |
wnd->wnd = window; |
return True; |
83 |
wnd->gc = gc; |
} |
84 |
wnd->visual = visual; |
|
85 |
|
void ui_destroy_window() |
86 |
return wnd; |
{ |
87 |
} |
XCloseIM(IM); |
88 |
|
XFreeGC(display, gc); |
89 |
void ui_destroy_window(HWINDOW wnd) |
XDestroyWindow(display, wnd); |
90 |
{ |
XCloseDisplay(display); |
|
XFreeGC(wnd->display, wnd->gc); |
|
|
XDestroyWindow(wnd->display, wnd->wnd); |
|
|
XCloseDisplay(wnd->display); |
|
91 |
} |
} |
92 |
|
|
93 |
static uint8 xwin_translate_key(unsigned long key) |
static uint8 xwin_translate_key(unsigned long key) |
129 |
return 0; |
return 0; |
130 |
} |
} |
131 |
|
|
132 |
void ui_process_events(HWINDOW wnd, HCONN conn) |
void ui_process_events() |
133 |
{ |
{ |
134 |
XEvent event; |
XEvent event; |
135 |
uint8 scancode; |
uint8 scancode; |
136 |
uint16 button; |
uint16 button; |
137 |
|
uint32 ev_time; |
138 |
|
|
139 |
if (wnd == NULL) |
if (display == NULL) |
140 |
return; |
return; |
141 |
|
|
142 |
while (XCheckWindowEvent(wnd->display, wnd->wnd, 0xffffffff, &event)) |
while (XCheckWindowEvent(display, wnd, 0xffffffff, &event)) |
143 |
{ |
{ |
144 |
|
ev_time = time(NULL); |
145 |
|
|
146 |
switch (event.type) |
switch (event.type) |
147 |
{ |
{ |
148 |
case KeyPress: |
case KeyPress: |
150 |
if (scancode == 0) |
if (scancode == 0) |
151 |
break; |
break; |
152 |
|
|
153 |
rdp_send_input(conn, RDP_INPUT_SCANCODE, 0, |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, 0, |
154 |
scancode, 0); |
scancode, 0); |
155 |
break; |
break; |
156 |
|
|
159 |
if (scancode == 0) |
if (scancode == 0) |
160 |
break; |
break; |
161 |
|
|
162 |
rdp_send_input(conn, RDP_INPUT_SCANCODE, |
rdp_send_input(ev_time, RDP_INPUT_SCANCODE, |
163 |
KBD_FLAG_DOWN | KBD_FLAG_UP, |
KBD_FLAG_DOWN | KBD_FLAG_UP, |
164 |
scancode, 0); |
scancode, 0); |
165 |
break; |
break; |
170 |
if (button == 0) |
if (button == 0) |
171 |
break; |
break; |
172 |
|
|
173 |
rdp_send_input(conn, RDP_INPUT_MOUSE, |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
174 |
button | MOUSE_FLAG_DOWN, |
button | MOUSE_FLAG_DOWN, |
175 |
event.xbutton.x, |
event.xbutton.x, |
176 |
event.xbutton.y); |
event.xbutton.y); |
181 |
if (button == 0) |
if (button == 0) |
182 |
break; |
break; |
183 |
|
|
184 |
rdp_send_input(conn, RDP_INPUT_MOUSE, |
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
185 |
button, |
button, |
186 |
event.xbutton.x, |
event.xbutton.x, |
187 |
event.xbutton.y); |
event.xbutton.y); |
188 |
|
break; |
189 |
|
|
190 |
|
case MotionNotify: |
191 |
|
rdp_send_input(ev_time, RDP_INPUT_MOUSE, |
192 |
|
MOUSE_FLAG_MOVE, |
193 |
|
event.xmotion.x, |
194 |
|
event.xmotion.y); |
195 |
} |
} |
196 |
} |
} |
197 |
} |
} |
198 |
|
|
199 |
void ui_move_pointer(HWINDOW wnd, int x, int y) |
void ui_move_pointer(int x, int y) |
200 |
{ |
{ |
201 |
XWarpPointer(wnd->display, wnd->wnd, wnd->wnd, 0, 0, 0, 0, x, y); |
XWarpPointer(display, wnd, wnd, 0, 0, 0, 0, x, y); |
202 |
} |
} |
203 |
|
|
204 |
HBITMAP ui_create_bitmap(HWINDOW wnd, int width, int height, uint8 *data) |
HBITMAP ui_create_bitmap(int width, int height, uint8 *data) |
205 |
{ |
{ |
206 |
XImage *image; |
XImage *image; |
207 |
Pixmap bitmap; |
Pixmap bitmap; |
208 |
|
|
209 |
bitmap = XCreatePixmap(wnd->display, wnd->wnd, width, height, 8); |
bitmap = XCreatePixmap(display, wnd, width, height, 8); |
210 |
|
|
211 |
image = XCreateImage(wnd->display, wnd->visual, 8, ZPixmap, 0, |
image = XCreateImage(display, visual, 8, ZPixmap, 0, |
212 |
data, width, height, 8, width); |
data, width, height, 8, width); |
213 |
XSetFunction(wnd->display, wnd->gc, GXcopy); |
XSetFunction(display, gc, GXcopy); |
214 |
XPutImage(wnd->display, bitmap, wnd->gc, image, 0, 0, 0, 0, |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
|
width, height); |
|
215 |
XFree(image); |
XFree(image); |
216 |
|
|
217 |
return (HBITMAP)bitmap; |
return (HBITMAP)bitmap; |
218 |
} |
} |
219 |
|
|
220 |
void ui_destroy_bitmap(HWINDOW wnd, HBITMAP bmp) |
void ui_paint_bitmap(int x, int y, int cx, int cy, |
221 |
|
int width, int height, uint8 *data) |
222 |
|
{ |
223 |
|
XImage *image; |
224 |
|
|
225 |
|
image = XCreateImage(display, visual, 8, ZPixmap, 0, |
226 |
|
data, width, height, 8, width); |
227 |
|
XSetFunction(display, gc, GXcopy); |
228 |
|
XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy); |
229 |
|
XFree(image); |
230 |
|
} |
231 |
|
|
232 |
|
void ui_destroy_bitmap(HBITMAP bmp) |
233 |
{ |
{ |
234 |
XFreePixmap(wnd->display, (Pixmap)bmp); |
XFreePixmap(display, (Pixmap)bmp); |
235 |
} |
} |
236 |
|
|
237 |
HGLYPH ui_create_glyph(HWINDOW wnd, int width, int height, uint8 *data) |
HGLYPH ui_create_glyph(int width, int height, uint8 *data) |
238 |
{ |
{ |
239 |
XImage *image; |
XImage *image; |
240 |
Pixmap bitmap; |
Pixmap bitmap; |
243 |
|
|
244 |
scanline = (width + 7) / 8; |
scanline = (width + 7) / 8; |
245 |
|
|
246 |
bitmap = XCreatePixmap(wnd->display, wnd->wnd, width, height, 1); |
bitmap = XCreatePixmap(display, wnd, width, height, 1); |
247 |
gc = XCreateGC(wnd->display, bitmap, 0, NULL); |
gc = XCreateGC(display, bitmap, 0, NULL); |
248 |
|
|
249 |
image = XCreateImage(wnd->display, wnd->visual, 1, ZPixmap, 0, |
image = XCreateImage(display, visual, 1, ZPixmap, 0, |
250 |
data, width, height, 8, scanline); |
data, width, height, 8, scanline); |
251 |
XSetFunction(wnd->display, wnd->gc, GXcopy); |
XSetFunction(display, gc, GXcopy); |
252 |
XPutImage(wnd->display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); |
253 |
XFree(image); |
XFree(image); |
254 |
XFreeGC(wnd->display, gc); |
XFreeGC(display, gc); |
255 |
|
|
256 |
return (HGLYPH)bitmap; |
return (HGLYPH)bitmap; |
257 |
} |
} |
258 |
|
|
259 |
void ui_destroy_glyph(HWINDOW wnd, HGLYPH glyph) |
void ui_destroy_glyph(HGLYPH glyph) |
260 |
{ |
{ |
261 |
XFreePixmap(wnd->display, (Pixmap)glyph); |
XFreePixmap(display, (Pixmap)glyph); |
262 |
} |
} |
263 |
|
|
264 |
HCOLOURMAP ui_create_colourmap(HWINDOW wnd, COLOURMAP *colours) |
HCOLOURMAP ui_create_colourmap(COLOURMAP *colours) |
265 |
{ |
{ |
266 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
267 |
XColor *xcolours, *xentry; |
XColor *xcolours, *xentry; |
268 |
Colormap map; |
Colormap map; |
269 |
int i, ncolours = colours->ncolours; |
int i, ncolours = colours->ncolours; |
270 |
|
|
271 |
xcolours = malloc(sizeof(XColor) * ncolours); |
xcolours = xmalloc(sizeof(XColor) * ncolours); |
272 |
for (i = 0; i < ncolours; i++) |
for (i = 0; i < ncolours; i++) |
273 |
{ |
{ |
274 |
entry = &colours->colours[i]; |
entry = &colours->colours[i]; |
281 |
xentry->flags = DoRed | DoBlue | DoGreen; |
xentry->flags = DoRed | DoBlue | DoGreen; |
282 |
} |
} |
283 |
|
|
284 |
map = XCreateColormap(wnd->display, wnd->wnd, wnd->visual, AllocAll); |
map = XCreateColormap(display, wnd, visual, AllocAll); |
285 |
XStoreColors(wnd->display, map, xcolours, ncolours); |
XStoreColors(display, map, xcolours, ncolours); |
286 |
|
|
287 |
free(xcolours); |
xfree(xcolours); |
288 |
return (HCOLOURMAP)map; |
return (HCOLOURMAP)map; |
289 |
} |
} |
290 |
|
|
291 |
void ui_destroy_colourmap(HWINDOW wnd, HCOLOURMAP map) |
void ui_destroy_colourmap(HCOLOURMAP map) |
292 |
{ |
{ |
293 |
XFreeColormap(wnd->display, (Colormap)map); |
XFreeColormap(display, (Colormap)map); |
294 |
} |
} |
295 |
|
|
296 |
void ui_set_colourmap(HWINDOW wnd, HCOLOURMAP map) |
void ui_set_colourmap(HCOLOURMAP map) |
297 |
{ |
{ |
298 |
XSetWindowColormap(wnd->display, wnd->wnd, (Colormap)map); |
XSetWindowColormap(display, wnd, (Colormap)map); |
299 |
} |
} |
300 |
|
|
301 |
void ui_set_clip(HWINDOW wnd, int x, int y, int cx, int cy) |
void ui_set_clip(int x, int y, int cx, int cy) |
302 |
{ |
{ |
303 |
XRectangle rect; |
XRectangle rect; |
304 |
|
|
306 |
rect.y = y; |
rect.y = y; |
307 |
rect.width = cx; |
rect.width = cx; |
308 |
rect.height = cy; |
rect.height = cy; |
309 |
XSetClipRectangles(wnd->display, wnd->gc, 0, 0, &rect, 1, YXBanded); |
XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded); |
310 |
} |
} |
311 |
|
|
312 |
void ui_reset_clip(HWINDOW wnd) |
void ui_reset_clip() |
313 |
{ |
{ |
314 |
XRectangle rect; |
XRectangle rect; |
315 |
|
|
316 |
rect.x = 0; |
rect.x = 0; |
317 |
rect.y = 0; |
rect.y = 0; |
318 |
rect.width = wnd->width; |
rect.width = width; |
319 |
rect.height = wnd->height; |
rect.height = height; |
320 |
XSetClipRectangles(wnd->display, wnd->gc, 0, 0, &rect, 1, YXBanded); |
XSetClipRectangles(display, gc, 0, 0, &rect, 1, YXBanded); |
321 |
|
} |
322 |
|
|
323 |
|
void ui_bell() |
324 |
|
{ |
325 |
|
XBell(display, 0); |
326 |
} |
} |
327 |
|
|
328 |
static int rop2_map[] = { |
static int rop2_map[] = { |
344 |
GXset /* 1 */ |
GXset /* 1 */ |
345 |
}; |
}; |
346 |
|
|
347 |
static void xwin_set_function(HWINDOW wnd, uint8 rop2) |
static void xwin_set_function(uint8 rop2) |
348 |
{ |
{ |
349 |
XSetFunction(wnd->display, wnd->gc, rop2_map[rop2]); |
XSetFunction(display, gc, rop2_map[rop2]); |
350 |
} |
} |
351 |
|
|
352 |
void ui_destblt(HWINDOW wnd, uint8 opcode, |
void ui_destblt(uint8 opcode, |
353 |
/* dest */ int x, int y, int cx, int cy) |
/* dest */ int x, int y, int cx, int cy) |
354 |
{ |
{ |
355 |
xwin_set_function(wnd, opcode); |
xwin_set_function(opcode); |
356 |
|
|
357 |
XFillRectangle(wnd->display, wnd->wnd, wnd->gc, x, y, cx, cy); |
XFillRectangle(display, wnd, gc, x, y, cx, cy); |
358 |
} |
} |
359 |
|
|
360 |
void ui_patblt(HWINDOW wnd, uint8 opcode, |
void ui_patblt(uint8 opcode, |
361 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
362 |
/* brush */ BRUSH *brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH *brush, int bgcolour, int fgcolour) |
363 |
{ |
{ |
364 |
Display *dpy = wnd->display; |
Display *dpy = display; |
|
GC gc = wnd->gc; |
|
365 |
Pixmap fill; |
Pixmap fill; |
366 |
|
|
367 |
xwin_set_function(wnd, opcode); |
xwin_set_function(opcode); |
368 |
|
|
369 |
switch (brush->style) |
switch (brush->style) |
370 |
{ |
{ |
371 |
case 0: /* Solid */ |
case 0: /* Solid */ |
372 |
XSetForeground(dpy, gc, fgcolour); |
XSetForeground(dpy, gc, fgcolour); |
373 |
XFillRectangle(dpy, wnd->wnd, gc, x, y, cx, cy); |
XFillRectangle(dpy, wnd, gc, x, y, cx, cy); |
374 |
break; |
break; |
375 |
|
|
376 |
case 3: /* Pattern */ |
case 3: /* Pattern */ |
377 |
fill = (Pixmap)ui_create_glyph(wnd, 8, 8, brush->pattern); |
fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern); |
378 |
|
|
379 |
XSetForeground(dpy, gc, fgcolour); |
XSetForeground(dpy, gc, fgcolour); |
380 |
XSetBackground(dpy, gc, bgcolour); |
XSetBackground(dpy, gc, bgcolour); |
381 |
XSetFillStyle(dpy, gc, FillOpaqueStippled); |
XSetFillStyle(dpy, gc, FillOpaqueStippled); |
382 |
XSetStipple(dpy, gc, fill); |
XSetStipple(dpy, gc, fill); |
383 |
|
|
384 |
XFillRectangle(dpy, wnd->wnd, gc, x, y, cx, cy); |
XFillRectangle(dpy, wnd, gc, x, y, cx, cy); |
385 |
|
|
386 |
XSetFillStyle(dpy, gc, FillSolid); |
XSetFillStyle(dpy, gc, FillSolid); |
387 |
ui_destroy_glyph(wnd, (HGLYPH)fill); |
ui_destroy_glyph((HGLYPH)fill); |
388 |
break; |
break; |
389 |
|
|
390 |
default: |
default: |
391 |
NOTIMP("brush style %d\n", brush->style); |
NOTIMP("brush %d\n", brush->style); |
392 |
} |
} |
393 |
} |
} |
394 |
|
|
395 |
void ui_screenblt(HWINDOW wnd, uint8 opcode, |
void ui_screenblt(uint8 opcode, |
396 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
397 |
/* src */ int srcx, int srcy) |
/* src */ int srcx, int srcy) |
398 |
{ |
{ |
399 |
xwin_set_function(wnd, opcode); |
xwin_set_function(opcode); |
400 |
|
|
401 |
XCopyArea(wnd->display, wnd->wnd, wnd->wnd, wnd->gc, srcx, srcy, |
XCopyArea(display, wnd, wnd, gc, srcx, srcy, |
402 |
cx, cy, x, y); |
cx, cy, x, y); |
403 |
} |
} |
404 |
|
|
405 |
void ui_memblt(HWINDOW wnd, uint8 opcode, |
void ui_memblt(uint8 opcode, |
406 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
407 |
/* src */ HBITMAP src, int srcx, int srcy) |
/* src */ HBITMAP src, int srcx, int srcy) |
408 |
{ |
{ |
409 |
xwin_set_function(wnd, opcode); |
xwin_set_function(opcode); |
410 |
|
|
411 |
XCopyArea(wnd->display, (Pixmap)src, wnd->wnd, wnd->gc, srcx, srcy, |
XCopyArea(display, (Pixmap)src, wnd, gc, srcx, srcy, |
412 |
cx, cy, x, y); |
cx, cy, x, y); |
413 |
} |
} |
414 |
|
|
415 |
void ui_triblt(HWINDOW wnd, uint8 opcode, |
void ui_triblt(uint8 opcode, |
416 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
417 |
/* src */ HBITMAP src, int srcx, int srcy, |
/* src */ HBITMAP src, int srcx, int srcy, |
418 |
/* brush */ BRUSH *brush, int bgcolour, int fgcolour) |
/* brush */ BRUSH *brush, int bgcolour, int fgcolour) |
419 |
{ |
{ |
420 |
/* This is potentially difficult to do in general. Until someone |
/* This is potentially difficult to do in general. Until someone |
421 |
comes up with an efficient way of doing that I am using cases. */ |
comes up with a more efficient way of doing it I am using cases. */ |
422 |
|
|
423 |
switch (opcode) |
switch (opcode) |
424 |
{ |
{ |
425 |
|
case 0x69: /* PDSxxn */ |
426 |
|
ui_memblt(ROP2_XOR, x, y, cx, cy, src, srcx, srcy); |
427 |
|
ui_patblt(ROP2_NXOR, x, y, cx, cy, |
428 |
|
brush, bgcolour, fgcolour); |
429 |
|
break; |
430 |
|
|
431 |
case 0xb8: /* PSDPxax */ |
case 0xb8: /* PSDPxax */ |
432 |
ui_patblt(wnd, ROP2_XOR, x, y, cx, cy, |
ui_patblt(ROP2_XOR, x, y, cx, cy, |
433 |
brush, bgcolour, fgcolour); |
brush, bgcolour, fgcolour); |
434 |
ui_memblt(wnd, ROP2_AND, x, y, cx, cy, |
ui_memblt(ROP2_AND, x, y, cx, cy, src, srcx, srcy); |
435 |
src, srcx, srcy); |
ui_patblt(ROP2_XOR, x, y, cx, cy, |
|
ui_patblt(wnd, ROP2_XOR, x, y, cx, cy, |
|
436 |
brush, bgcolour, fgcolour); |
brush, bgcolour, fgcolour); |
437 |
break; |
break; |
438 |
|
|
439 |
default: |
default: |
440 |
NOTIMP("triblt opcode 0x%x\n", opcode); |
NOTIMP("triblt 0x%x\n", opcode); |
441 |
ui_memblt(wnd, ROP2_COPY, x, y, cx, cy, |
ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy); |
|
brush, bgcolour, fgcolour); |
|
442 |
} |
} |
443 |
} |
} |
444 |
|
|
445 |
void ui_line(HWINDOW wnd, uint8 opcode, |
void ui_line(uint8 opcode, |
446 |
/* dest */ int startx, int starty, int endx, int endy, |
/* dest */ int startx, int starty, int endx, int endy, |
447 |
/* pen */ PEN *pen) |
/* pen */ PEN *pen) |
448 |
{ |
{ |
449 |
xwin_set_function(wnd, opcode); |
xwin_set_function(opcode); |
450 |
|
|
451 |
XSetForeground(wnd->display, wnd->gc, pen->colour); |
XSetForeground(display, gc, pen->colour); |
452 |
XDrawLine(wnd->display, wnd->wnd, wnd->gc, startx, starty, endx, endy); |
XDrawLine(display, wnd, gc, startx, starty, endx, endy); |
453 |
} |
} |
454 |
|
|
455 |
void ui_rect(HWINDOW wnd, |
void ui_rect( |
456 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
457 |
/* brush */ int colour) |
/* brush */ int colour) |
458 |
{ |
{ |
459 |
xwin_set_function(wnd, ROP2_COPY); |
xwin_set_function(ROP2_COPY); |
460 |
|
|
461 |
XSetForeground(wnd->display, wnd->gc, colour); |
XSetForeground(display, gc, colour); |
462 |
XFillRectangle(wnd->display, wnd->wnd, wnd->gc, x, y, cx, cy); |
XFillRectangle(display, wnd, gc, x, y, cx, cy); |
463 |
} |
} |
464 |
|
|
465 |
void ui_draw_glyph(HWINDOW wnd, int mixmode, |
void ui_draw_glyph(int mixmode, |
466 |
/* dest */ int x, int y, int cx, int cy, |
/* dest */ int x, int y, int cx, int cy, |
467 |
/* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour, int fgcolour) |
/* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour, int fgcolour) |
468 |
{ |
{ |
469 |
Pixmap pixmap = (Pixmap)glyph; |
Pixmap pixmap = (Pixmap)glyph; |
470 |
|
|
471 |
xwin_set_function(wnd, ROP2_COPY); |
xwin_set_function(ROP2_COPY); |
472 |
|
|
473 |
XSetForeground(wnd->display, wnd->gc, fgcolour); |
XSetForeground(display, gc, fgcolour); |
474 |
|
|
475 |
switch (mixmode) |
switch (mixmode) |
476 |
{ |
{ |
477 |
case MIX_TRANSPARENT: |
case MIX_TRANSPARENT: |
478 |
XSetStipple(wnd->display, wnd->gc, pixmap); |
XSetStipple(display, gc, pixmap); |
479 |
XSetFillStyle(wnd->display, wnd->gc, FillStippled); |
XSetFillStyle(display, gc, FillStippled); |
480 |
XSetTSOrigin(wnd->display, wnd->gc, x, y); |
XSetTSOrigin(display, gc, x, y); |
481 |
XFillRectangle(wnd->display, wnd->wnd, wnd->gc, |
XFillRectangle(display, wnd, gc, |
482 |
x, y, cx, cy); |
x, y, cx, cy); |
483 |
XSetFillStyle(wnd->display, wnd->gc, FillSolid); |
XSetFillStyle(display, gc, FillSolid); |
484 |
break; |
break; |
485 |
|
|
486 |
case MIX_OPAQUE: |
case MIX_OPAQUE: |
487 |
XSetBackground(wnd->display, wnd->gc, bgcolour); |
XSetBackground(display, gc, bgcolour); |
488 |
XCopyPlane(wnd->display, pixmap, wnd->wnd, wnd->gc, |
XCopyPlane(display, pixmap, wnd, gc, |
489 |
srcx, srcy, cx, cy, x, y, 1); |
srcx, srcy, cx, cy, x, y, 1); |
490 |
break; |
break; |
491 |
|
|
492 |
default: |
default: |
493 |
NOTIMP("mix mode %d\n", mixmode); |
NOTIMP("mix %d\n", mixmode); |
494 |
} |
} |
495 |
} |
} |
496 |
|
|
497 |
void ui_draw_text(HWINDOW wnd, uint8 font, uint8 flags, int mixmode, int x, |
void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y, |
498 |
int y, int boxx, int boxy, int boxcx, int boxcy, |
int clipx, int clipy, int clipcx, int clipcy, |
499 |
|
int boxx, int boxy, int boxcx, int boxcy, |
500 |
int bgcolour, int fgcolour, uint8 *text, uint8 length) |
int bgcolour, int fgcolour, uint8 *text, uint8 length) |
501 |
{ |
{ |
502 |
FONT_GLYPH *glyph; |
FONTGLYPH *glyph; |
503 |
int i; |
int i; |
504 |
|
|
505 |
if (boxcx > 1) |
if (boxcx > 1) |
506 |
{ |
{ |
507 |
ui_rect(wnd, boxx, boxy, boxcx, boxcy, bgcolour); |
ui_rect(boxx, boxy, boxcx, boxcy, bgcolour); |
508 |
|
} |
509 |
|
else if (mixmode == MIX_OPAQUE) |
510 |
|
{ |
511 |
|
ui_rect(clipx, clipy, clipcx, clipcy, bgcolour); |
512 |
} |
} |
513 |
|
|
514 |
/* Paint text, character by character */ |
/* Paint text, character by character */ |
515 |
for (i = 0; i < length; i++) |
for (i = 0; i < length; i++) |
516 |
{ |
{ |
517 |
glyph = cache_get_font(wnd->conn, font, text[i]); |
glyph = cache_get_font(font, text[i]); |
518 |
|
|
519 |
|
if (!(flags & TEXT2_IMPLICIT_X)) |
520 |
|
x += text[++i]; |
521 |
|
|
522 |
if (glyph != NULL) |
if (glyph != NULL) |
523 |
{ |
{ |
524 |
ui_draw_glyph(wnd, mixmode, x, |
ui_draw_glyph(mixmode, x + (short)glyph->offset, |
525 |
y + (short)glyph->baseline, |
y + (short)glyph->baseline, |
526 |
glyph->width, glyph->height, |
glyph->width, glyph->height, |
527 |
glyph->pixmap, 0, 0, |
glyph->pixmap, 0, 0, |
529 |
|
|
530 |
if (flags & TEXT2_IMPLICIT_X) |
if (flags & TEXT2_IMPLICIT_X) |
531 |
x += glyph->width; |
x += glyph->width; |
|
else |
|
|
x += text[++i]; |
|
532 |
} |
} |
533 |
} |
} |
534 |
} |
} |
535 |
|
|
536 |
void ui_desktop_save(HWINDOW wnd, uint8 *data, int x, int y, int cx, int cy) |
void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy) |
537 |
{ |
{ |
538 |
XImage *image; |
XImage *image; |
|
int scanline; |
|
539 |
|
|
540 |
scanline = (cx + 3) & ~3; |
image = XGetImage(display, wnd, x, y, cx, cy, 0xffffffff, ZPixmap); |
541 |
image = XGetImage(wnd->display, wnd->wnd, x, y, cx, cy, |
cache_put_desktop(offset, cx, cy, image->bytes_per_line, image->data); |
542 |
0xffffffff, ZPixmap); |
XFree(image->data); |
543 |
memcpy(data, image->data, scanline*cy); |
XFree(image); |
|
XDestroyImage(image); |
|
544 |
} |
} |
545 |
|
|
546 |
void ui_desktop_restore(HWINDOW wnd, uint8 *data, int x, int y, int cx, int cy) |
void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy) |
547 |
{ |
{ |
548 |
XImage *image; |
XImage *image; |
549 |
int scanline; |
uint8 *data; |
550 |
|
|
551 |
|
data = cache_get_desktop(offset, cx, cy); |
552 |
|
if (data == NULL) |
553 |
|
return; |
554 |
|
|
555 |
scanline = (cx + 3) & ~3; |
image = XCreateImage(display, visual, 8, ZPixmap, 0, |
556 |
image = XCreateImage(wnd->display, wnd->visual, 8, ZPixmap, 0, |
data, cx, cy, 32, cx); |
557 |
data, cx, cy, 32, scanline); |
XSetFunction(display, gc, GXcopy); |
558 |
XSetFunction(wnd->display, wnd->gc, GXcopy); |
XPutImage(display, wnd, gc, image, 0, 0, x, y, cx, cy); |
|
XPutImage(wnd->display, wnd->wnd, wnd->gc, image, 0, 0, x, y, cx, cy); |
|
559 |
XFree(image); |
XFree(image); |
560 |
} |
} |