Sweden-Number/graphics/x11drv/graphics.c

682 lines
22 KiB
C
Raw Normal View History

Release 970112 Sat Jan 11 18:17:59 1997 Alexandre Julliard <julliard@lrc.epfl.ch> * [controls/menu.c] Updated to new Win32 types. * [controls/listbox.c] Fixed Winfile extended selection bug. * [files/directory.c] Changed DIR_SearchPath to return both long and short file names. * [files/dos_fs.c] Implemented VFAT ioctl to retrieve the original short filenames from a VFAT filesystem (Linux only for now). Replaced DOSFS_GetUnixFileName()/DOSFS_GetDosTrueName() by DOS_GetFullName(). Properly implemented GetShortPathName() and GetFullPathName(). Made all functions re-entrant. * [files/file.c] [misc/main.c] Replaced -allowreadonly option by -failreadonly. The default is now to report success when opening a read-only file for writing. * [objects/metafile.c] Fixed bug in DIB bitmaps pointer calculation. * [scheduler/process.c] Implemented environment strings and Get/SetStdHandle with process environment block. * [tools/build.c] Rewrote BuildContext32() to avoid instructions that may not be supported by all assemblers. Fri Jan 10 17:11:09 1997 David Faure <david.faure@ifhamy.insa-lyon.fr> * [windows/event.c] Created table keyc2vkey, which associate a vkey(+extended bit) to any keycode. Changed EVENT_event_to_vkey to use this table to return the correct vkey. Changed EVENT_ToAscii to get the keycode from this table too. Assigned OEM specific vkeys arbitrarily. Fri Jan 10 09:26:17 1997 John Harvey <john@division.co.uk> * [misc/winsock.c] [misc/winsoc_async.c] Fixed svr4 header files. Changed bzero() to memset(). * [tools/fnt2bdf.c] Removed bcopy() and used memcpy() instead. * [debugger/msc.c] Include string.h instead of strings.h * [debugger/stabs.c] Include string.h instead of strings.h. Define __ELF__ for svr4 systems. * [loader/signal.c] Use wait() instead of wait4() which doesnt exist on Unixware. * [memory/global.c] Use sysconf() instead of getpagesize() for svr4 systems. Thu Jan 9 21:07:20 1997 Robert Pouliot <krynos@clic.net> * [Make.rules.in] [Makefile.in] [make_os2.sh] [rc/Makefile.in] [tools/Makefile.in] [documentation/wine_os2.txt] Patches for OS/2 support. Note that it doesn't compile yet. Tue Jan 7 20:03:53 1997 Eric Youngdale <eric@sub2304.jic.com> * [debugger/*] Many more debugger improvements (see debugger/README for details). Tue Jan 7 15:12:21 1997 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de> * [windows/graphics.c] [objects/text.c] [graphics/x11drv/*] [graphics/metafiledrv/*] Moved some device dependent code into the resp. subdirs. * [include/gdi.h] [include/metafiledrv.h] [include/x11drv.h] Prototypes added, DC_FUNCTIONS: GetPixel added, some unnecessary functions removed. * [objects/region.c] CreatePolyPolygonRgn32 added. * [files/dos_fs.c] QueryDosDevice added. * [misc/lstr.c] FormatMessage: broken heap management fixed. * [scheduler/process.c] [scheduler/thread.c] Get/SetThreadPriority/PriorityClass added. Mon Jan 6 21:55:30 1997 Philippe De Muyter <phdm@info.ucl.ac.be> * [misc/keyboard.c] ToAscii : Use EVENT_ToAscii instead. * [windows/event.c] keypad_key : Do not convert XK_Mode_switch to VK_MENU; recognize keypad cursor keys. EVENT_event_to_vkey : New function, to transform a X keycode into a MSwin vkey + extended bit. EVENT_ToAscii : New function, to transform a vkey + extended bit (+ key state table) into ascii char(s), using XLookupString, and recognizing dead chars. EVENT_key : Transform AltGr into Ctrl+Alt sequence; call EVENT_event_to_vkey for keycode to vkey conversion; fixed previous, context and extended bits. * [windows/keyboard.c] Include stddebug.h, to get -debugmsg messages. GetKeyState : Handle VK_MBUTTON case. GetKeyboardState, SetKeyboardState : Debugging messages added. * [windows/message.c] TranslateMessage : Handle dead chars. Mon Jan 6 20:10:11 1997 Dominik Strasser <bm424953@muenchen.org> * [if1632/crtdll.spec] [misc/crtdll.c] C++ functions new/delete/set_new_handler implemented. Mon Jan 6 15:48:15 1997 Frans van Dorsselaer <dorssel@rulhmpc49.LeidenUniv.nl> * [controls/edit.c] [include/windows.h] Moved the edit control to 32 bits. Included new (win95) message definitions in windows.h Implemented EM_SCROLLCARET, EM_SETMARGINS, EM_GETMARGINS, EM_GETLIMITTEXT, EM_POSFROMCHAR, EM_CHARFROMPOS. Broke EM_SETWORDBREAKPROC (internal wordwrap still works). Fixed some bugs, introduced a couple of others. Text buffer is now initially in 32-bit heap. * [controls/EDIT.TODO] [controls/combo.c] [controls/widgets.c] [if1632/wprocs.spec] [library/miscstubs.c] [windows/defdlg.c] [misc/commdlg.c] Updated to work with 32-bit edit control. Sat Jan 4 22:07:27 1997 O.Flebbe <O.Flebbe@science-computing.uni-tuebingen.de> * [loader/pe_image.c] Use mmap rather then malloc. Better workaround for clean segments.
1997-01-12 19:32:19 +01:00
/*
* X11 graphics driver graphics functions
*
* Copyright 1993,1994 Alexandre Julliard
*/
#include <math.h>
Release 970120 Sun Jan 19 11:46:48 1997 Alexandre Julliard <julliard@lrc.epfl.ch> * [loader/module.c] Fixed LoadModule() to always call the DLL initialization code. * [windows/event.c] Moved all the keyboard stuff to windows/keyboard.c * [tools/build.c] Fixed Win32 register functions. Sat Jan 18 22:24:41 1997 David Makepeace <D.Makepeace@mailbox.uq.oz.au> * [tools/makedep.c] Fixed bug which causes SEGV on Solaris x86. Fri Jan 17 18:32:27 1997 Frans van Dorsselaer <dorssel@rulhmpc49.LeidenUniv.nl> * [controls/edit.c] Implemented WM_UNDO, WM_CONTEXTMENU (temporary using WM_RBUTTONUP), WM_COMMAND, WM_INITPOPUPMENU, WM_SYSKEYDOWN. Fixed EM_SETSEL and some minor bugs (features). Hence: fully functional undo and a win95 menu with the right mouse button. * [include/resources.h] [resources/TODO] [resources/sysres_??.rc] Added a context menu for the edit control. Translations, please ... Fri Jan 17 08:29:52 1997 David Faure <david.faure@ifhamy.insa-lyon.fr> * [windows/event.c] Move EVENT_ToAscii to windows/keyboard.c (where name ToAscii) Fixed Keypad keys 0-9 and . in EVENT_event_to_vkey. Added 3-state handling of toggle keys (CapsLock, NumLock) in order to make them work with any X server. Toggle keys now generate WM_KEYDOWN and WM_KEYUP on each pressing. * [include/keyboard.h] Totally replaced the file (formerly containing the vkcase definitions) by the declaration of 'extern' variables contained by event.c and used by keyboard.c * [windows/keyboard.c] Started to rewrite VkKeyScan and MapVirtualKey, to make them use the table keyc2vkey or X functions only. ToAscii : added keypad 0-9 and . special case. Changed toggle keys active mask from 0x80 to 0x1. * [misc/keyboard.c] File deleted. Contents moved to windows/keyboard.c. * [misc/main.c] Added putenv XKB_DISABLE to disable XKB extension (which, when present, causes AltGr to change keyboard group instead of being a modifier). Tue Jan 14 22:56:43 1997 Philippe De Muyter <phdm@info.ucl.ac.be> * [windows/event.c] Do not assume NumLockMask is Mod2Mask, but compute it by scanning output of XGetModifierMapping for XK_Num_Lock. Tue Jan 14 15:49:49 1997 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de> * [loader/pe_*.c] [include/peexe.h] [include/resource32.h] [debugger/*.c] General clean up. Changed defines/structures to match Windows NT SDK. * [loader/main.c] Don't crash on empty command-line. * [windows/winpos.c] winpos.c made win32 clean. * [misc/ntdll.c] Some string conversion additions. * [files/file.c] GetFileAttributes/GetTempFileName fixed. * [misc/ver.c] VerInstallFile implemented. Mon Jan 13 15:03:11 1997 Philippe De Muyter <phdm@info.ucl.ac.be> * [tools/build.c]: Use PREFIX also in stabs messages. Mon Jan 13 10:40:33 1997 John Harvey <john@division.co.uk> * [graphics/win16drv/*] [include/win16drv.h] Many fixes and some new features. * [graphics/x11drv/font.c] [graphics/x11drv/init.c] [include/x11drv.h] [objects/font.c] GetTextMetrics() moved to graphics driver. * [if1632/gdi.spec] [misc/fontengine.c] [misc/Makefile.in] New dummy EngineEnumerateFont, EngineRealizeFont functions. * [include/windows.h] TEXTFORM16 and FONTINFO16 structure definitions moved here from include/win16drv.h
1997-01-20 20:43:45 +01:00
#if defined(__EMX__)
#include <float.h>
#endif
Release 970112 Sat Jan 11 18:17:59 1997 Alexandre Julliard <julliard@lrc.epfl.ch> * [controls/menu.c] Updated to new Win32 types. * [controls/listbox.c] Fixed Winfile extended selection bug. * [files/directory.c] Changed DIR_SearchPath to return both long and short file names. * [files/dos_fs.c] Implemented VFAT ioctl to retrieve the original short filenames from a VFAT filesystem (Linux only for now). Replaced DOSFS_GetUnixFileName()/DOSFS_GetDosTrueName() by DOS_GetFullName(). Properly implemented GetShortPathName() and GetFullPathName(). Made all functions re-entrant. * [files/file.c] [misc/main.c] Replaced -allowreadonly option by -failreadonly. The default is now to report success when opening a read-only file for writing. * [objects/metafile.c] Fixed bug in DIB bitmaps pointer calculation. * [scheduler/process.c] Implemented environment strings and Get/SetStdHandle with process environment block. * [tools/build.c] Rewrote BuildContext32() to avoid instructions that may not be supported by all assemblers. Fri Jan 10 17:11:09 1997 David Faure <david.faure@ifhamy.insa-lyon.fr> * [windows/event.c] Created table keyc2vkey, which associate a vkey(+extended bit) to any keycode. Changed EVENT_event_to_vkey to use this table to return the correct vkey. Changed EVENT_ToAscii to get the keycode from this table too. Assigned OEM specific vkeys arbitrarily. Fri Jan 10 09:26:17 1997 John Harvey <john@division.co.uk> * [misc/winsock.c] [misc/winsoc_async.c] Fixed svr4 header files. Changed bzero() to memset(). * [tools/fnt2bdf.c] Removed bcopy() and used memcpy() instead. * [debugger/msc.c] Include string.h instead of strings.h * [debugger/stabs.c] Include string.h instead of strings.h. Define __ELF__ for svr4 systems. * [loader/signal.c] Use wait() instead of wait4() which doesnt exist on Unixware. * [memory/global.c] Use sysconf() instead of getpagesize() for svr4 systems. Thu Jan 9 21:07:20 1997 Robert Pouliot <krynos@clic.net> * [Make.rules.in] [Makefile.in] [make_os2.sh] [rc/Makefile.in] [tools/Makefile.in] [documentation/wine_os2.txt] Patches for OS/2 support. Note that it doesn't compile yet. Tue Jan 7 20:03:53 1997 Eric Youngdale <eric@sub2304.jic.com> * [debugger/*] Many more debugger improvements (see debugger/README for details). Tue Jan 7 15:12:21 1997 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de> * [windows/graphics.c] [objects/text.c] [graphics/x11drv/*] [graphics/metafiledrv/*] Moved some device dependent code into the resp. subdirs. * [include/gdi.h] [include/metafiledrv.h] [include/x11drv.h] Prototypes added, DC_FUNCTIONS: GetPixel added, some unnecessary functions removed. * [objects/region.c] CreatePolyPolygonRgn32 added. * [files/dos_fs.c] QueryDosDevice added. * [misc/lstr.c] FormatMessage: broken heap management fixed. * [scheduler/process.c] [scheduler/thread.c] Get/SetThreadPriority/PriorityClass added. Mon Jan 6 21:55:30 1997 Philippe De Muyter <phdm@info.ucl.ac.be> * [misc/keyboard.c] ToAscii : Use EVENT_ToAscii instead. * [windows/event.c] keypad_key : Do not convert XK_Mode_switch to VK_MENU; recognize keypad cursor keys. EVENT_event_to_vkey : New function, to transform a X keycode into a MSwin vkey + extended bit. EVENT_ToAscii : New function, to transform a vkey + extended bit (+ key state table) into ascii char(s), using XLookupString, and recognizing dead chars. EVENT_key : Transform AltGr into Ctrl+Alt sequence; call EVENT_event_to_vkey for keycode to vkey conversion; fixed previous, context and extended bits. * [windows/keyboard.c] Include stddebug.h, to get -debugmsg messages. GetKeyState : Handle VK_MBUTTON case. GetKeyboardState, SetKeyboardState : Debugging messages added. * [windows/message.c] TranslateMessage : Handle dead chars. Mon Jan 6 20:10:11 1997 Dominik Strasser <bm424953@muenchen.org> * [if1632/crtdll.spec] [misc/crtdll.c] C++ functions new/delete/set_new_handler implemented. Mon Jan 6 15:48:15 1997 Frans van Dorsselaer <dorssel@rulhmpc49.LeidenUniv.nl> * [controls/edit.c] [include/windows.h] Moved the edit control to 32 bits. Included new (win95) message definitions in windows.h Implemented EM_SCROLLCARET, EM_SETMARGINS, EM_GETMARGINS, EM_GETLIMITTEXT, EM_POSFROMCHAR, EM_CHARFROMPOS. Broke EM_SETWORDBREAKPROC (internal wordwrap still works). Fixed some bugs, introduced a couple of others. Text buffer is now initially in 32-bit heap. * [controls/EDIT.TODO] [controls/combo.c] [controls/widgets.c] [if1632/wprocs.spec] [library/miscstubs.c] [windows/defdlg.c] [misc/commdlg.c] Updated to work with 32-bit edit control. Sat Jan 4 22:07:27 1997 O.Flebbe <O.Flebbe@science-computing.uni-tuebingen.de> * [loader/pe_image.c] Use mmap rather then malloc. Better workaround for clean segments.
1997-01-12 19:32:19 +01:00
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Intrinsic.h>
#ifndef PI
#define PI M_PI
#endif
#include <string.h>
#include "x11drv.h"
#include "bitmap.h"
#include "gdi.h"
#include "graphics.h"
#include "dc.h"
#include "bitmap.h"
#include "callback.h"
#include "metafile.h"
#include "syscolor.h"
#include "stddebug.h"
#include "palette.h"
#include "color.h"
#include "region.h"
#include "struct32.h"
#include "debug.h"
#include "xmalloc.h"
/**********************************************************************
* X11DRV_MoveToEx
*/
BOOL32
X11DRV_MoveToEx(DC *dc,INT32 x,INT32 y,LPPOINT32 pt) {
if (pt)
{
pt->x = dc->w.CursPosX;
pt->y = dc->w.CursPosY;
}
dc->w.CursPosX = x;
dc->w.CursPosY = y;
return TRUE;
}
/***********************************************************************
* X11DRV_LineTo
*/
BOOL32
X11DRV_LineTo( DC *dc, INT32 x, INT32 y )
{
if (DC_SetupGCForPen( dc ))
XDrawLine(display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + XLPTODP( dc, dc->w.CursPosX ),
dc->w.DCOrgY + YLPTODP( dc, dc->w.CursPosY ),
dc->w.DCOrgX + XLPTODP( dc, x ),
dc->w.DCOrgY + YLPTODP( dc, y ) );
dc->w.CursPosX = x;
dc->w.CursPosY = y;
return TRUE;
}
/***********************************************************************
* GRAPH_DrawArc
*
* Helper functions for Arc(), Chord() and Pie().
* 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
*/
static BOOL32
X11DRV_DrawArc( DC *dc, INT32 left, INT32 top, INT32 right,
INT32 bottom, INT32 xstart, INT32 ystart,
INT32 xend, INT32 yend, INT32 lines )
{
INT32 xcenter, ycenter, istart_angle, idiff_angle, tmp;
double start_angle, end_angle;
XPoint points[3];
left = XLPTODP( dc, left );
top = YLPTODP( dc, top );
right = XLPTODP( dc, right );
bottom = YLPTODP( dc, bottom );
xstart = XLPTODP( dc, xstart );
ystart = YLPTODP( dc, ystart );
xend = XLPTODP( dc, xend );
yend = YLPTODP( dc, yend );
if ((left == right) || (top == bottom)) return FALSE;
xcenter = (right + left) / 2;
ycenter = (bottom + top) / 2;
start_angle = atan2( (double)(ycenter-ystart)*(right-left),
(double)(xstart-xcenter)*(bottom-top) );
end_angle = atan2( (double)(ycenter-yend)*(right-left),
(double)(xend-xcenter)*(bottom-top) );
istart_angle = (INT32)(start_angle * 180 * 64 / PI);
idiff_angle = (INT32)((end_angle - start_angle) * 180 * 64 / PI );
if (idiff_angle <= 0) idiff_angle += 360 * 64;
if (left > right) { tmp=left; left=right; right=tmp; }
if (top > bottom) { tmp=top; top=bottom; bottom=tmp; }
/* Fill arc with brush if Chord() or Pie() */
if ((lines > 0) && DC_SetupGCForBrush( dc ))
{
XSetArcMode( display, dc->u.x.gc, (lines==1) ? ArcChord : ArcPieSlice);
XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + top,
right-left-1, bottom-top-1, istart_angle, idiff_angle );
}
/* Draw arc and lines */
if (!DC_SetupGCForPen( dc )) return TRUE;
XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + top,
right-left-1, bottom-top-1, istart_angle, idiff_angle );
if (!lines) return TRUE;
points[0].x = dc->w.DCOrgX + xcenter + (int)(cos(start_angle) * (right-left) / 2);
points[0].y = dc->w.DCOrgY + ycenter - (int)(sin(start_angle) * (bottom-top) / 2);
points[1].x = dc->w.DCOrgX + xcenter + (int)(cos(end_angle) * (right-left) / 2);
points[1].y = dc->w.DCOrgY + ycenter - (int)(sin(end_angle) * (bottom-top) / 2);
if (lines == 2)
{
points[2] = points[1];
points[1].x = dc->w.DCOrgX + xcenter;
points[1].y = dc->w.DCOrgY + ycenter;
}
XDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
points, lines+1, CoordModeOrigin );
return TRUE;
}
/***********************************************************************
* X11DRV_Arc
*/
BOOL32
X11DRV_Arc( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
{
return X11DRV_DrawArc( dc, left, top, right, bottom,
xstart, ystart, xend, yend, 0 );
}
/***********************************************************************
* X11DRV_Pie
*/
BOOL32
X11DRV_Pie( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
{
return X11DRV_DrawArc( dc, left, top, right, bottom,
xstart, ystart, xend, yend, 2 );
}
/***********************************************************************
* X11DRV_Chord
*/
BOOL32
X11DRV_Chord( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
{
return X11DRV_DrawArc( dc, left, top, right, bottom,
xstart, ystart, xend, yend, 1 );
}
/***********************************************************************
* X11DRV_Ellipse
*/
BOOL32
X11DRV_Ellipse( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom )
{
left = XLPTODP( dc, left );
top = YLPTODP( dc, top );
right = XLPTODP( dc, right );
bottom = YLPTODP( dc, bottom );
if ((left == right) || (top == bottom)) return FALSE;
if (right < left) { INT32 tmp = right; right = left; left = tmp; }
if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
if ((dc->u.x.pen.style == PS_INSIDEFRAME) &&
(dc->u.x.pen.width < right-left-1) &&
(dc->u.x.pen.width < bottom-top-1))
{
left += dc->u.x.pen.width / 2;
right -= (dc->u.x.pen.width + 1) / 2;
top += dc->u.x.pen.width / 2;
bottom -= (dc->u.x.pen.width + 1) / 2;
}
if (DC_SetupGCForBrush( dc ))
XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + top,
right-left-1, bottom-top-1, 0, 360*64 );
if (DC_SetupGCForPen( dc ))
XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + top,
right-left-1, bottom-top-1, 0, 360*64 );
return TRUE;
}
/***********************************************************************
* X11DRV_Rectangle
*/
BOOL32
X11DRV_Rectangle(DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom)
{
INT32 width;
left = XLPTODP( dc, left );
top = YLPTODP( dc, top );
right = XLPTODP( dc, right );
bottom = YLPTODP( dc, bottom );
if (right < left) { INT32 tmp = right; right = left; left = tmp; }
if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
if ((left == right) || (top == bottom))
{
if (DC_SetupGCForPen( dc ))
XDrawLine(display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left,
dc->w.DCOrgY + top,
dc->w.DCOrgX + right,
dc->w.DCOrgY + bottom);
return TRUE;
}
width = dc->u.x.pen.width;
if (!width) width = 1;
if(dc->u.x.pen.style == PS_NULL) width = 0;
if ((dc->u.x.pen.style == PS_INSIDEFRAME) &&
(width < right-left) && (width < bottom-top))
{
left += width / 2;
right -= (width + 1) / 2;
top += width / 2;
bottom -= (width + 1) / 2;
}
if (DC_SetupGCForBrush( dc ))
XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left + (width + 1) / 2,
dc->w.DCOrgY + top + (width + 1) / 2,
right-left-width-1, bottom-top-width-1);
if (DC_SetupGCForPen( dc ))
XDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + top,
right-left-1, bottom-top-1 );
return TRUE;
}
/***********************************************************************
* X11DRV_RoundRect
*/
BOOL32
X11DRV_RoundRect( DC *dc, INT32 left, INT32 top, INT32 right,
INT32 bottom, INT32 ell_width, INT32 ell_height )
{
dprintf_graphics(stddeb, "X11DRV_RoundRect(%d %d %d %d %d %d\n",
left, top, right, bottom, ell_width, ell_height);
left = XLPTODP( dc, left );
top = YLPTODP( dc, top );
right = XLPTODP( dc, right );
bottom = YLPTODP( dc, bottom );
ell_width = abs( ell_width * dc->vportExtX / dc->wndExtX );
ell_height = abs( ell_height * dc->vportExtY / dc->wndExtY );
/* Fix the coordinates */
if (right < left) { INT32 tmp = right; right = left; left = tmp; }
if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
if (ell_width > right - left) ell_width = right - left;
if (ell_height > bottom - top) ell_height = bottom - top;
if (DC_SetupGCForBrush( dc ))
{
if (ell_width && ell_height)
{
XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + top,
ell_width, ell_height, 90 * 64, 90 * 64 );
XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + bottom - ell_height,
ell_width, ell_height, 180 * 64, 90 * 64 );
XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + right - ell_width,
dc->w.DCOrgY + bottom - ell_height,
ell_width, ell_height, 270 * 64, 90 * 64 );
XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + right - ell_width, dc->w.DCOrgY + top,
ell_width, ell_height, 0, 90 * 64 );
}
if (ell_width < right - left)
{
XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left + ell_width / 2,
dc->w.DCOrgY + top,
right - left - ell_width, ell_height / 2 );
XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left + ell_width / 2,
dc->w.DCOrgY + bottom - (ell_height+1) / 2,
right - left - ell_width, (ell_height+1) / 2 );
}
if (ell_height < bottom - top)
{
XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left,
dc->w.DCOrgY + top + ell_height / 2,
right - left, bottom - top - ell_height );
}
}
if (DC_SetupGCForPen(dc))
{
if (ell_width && ell_height)
{
XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + top,
ell_width, ell_height, 90 * 64, 90 * 64 );
XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left, dc->w.DCOrgY + bottom - ell_height,
ell_width, ell_height, 180 * 64, 90 * 64 );
XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + right - ell_width,
dc->w.DCOrgY + bottom - ell_height,
ell_width, ell_height, 270 * 64, 90 * 64 );
XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + right - ell_width, dc->w.DCOrgY + top,
ell_width, ell_height, 0, 90 * 64 );
}
if (ell_width < right - left)
{
XDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left + ell_width / 2,
dc->w.DCOrgY + top,
dc->w.DCOrgX + right - ell_width / 2,
dc->w.DCOrgY + top );
XDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left + ell_width / 2,
dc->w.DCOrgY + bottom,
dc->w.DCOrgX + right - ell_width / 2,
dc->w.DCOrgY + bottom );
}
if (ell_height < bottom - top)
{
XDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + right,
dc->w.DCOrgY + top + ell_height / 2,
dc->w.DCOrgX + right,
dc->w.DCOrgY + bottom - ell_height / 2 );
XDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + left,
dc->w.DCOrgY + top + ell_height / 2,
dc->w.DCOrgX + left,
dc->w.DCOrgY + bottom - ell_height / 2 );
}
}
return TRUE;
}
/***********************************************************************
* X11DRV_SetPixel
*/
COLORREF
X11DRV_SetPixel( DC *dc, INT32 x, INT32 y, COLORREF color )
{
Pixel pixel;
x = dc->w.DCOrgX + XLPTODP( dc, x );
y = dc->w.DCOrgY + YLPTODP( dc, y );
pixel = COLOR_ToPhysical( dc, color );
XSetForeground( display, dc->u.x.gc, pixel );
XSetFunction( display, dc->u.x.gc, GXcopy );
XDrawPoint( display, dc->u.x.drawable, dc->u.x.gc, x, y );
/* inefficient but simple... */
return COLOR_ToLogical(pixel);
}
/***********************************************************************
* X11DRV_GetPixel
*/
COLORREF
X11DRV_GetPixel( DC *dc, INT32 x, INT32 y )
{
static Pixmap pixmap = 0;
XImage * image;
int pixel;
x = dc->w.DCOrgX + XLPTODP( dc, x );
y = dc->w.DCOrgY + YLPTODP( dc, y );
if (dc->w.flags & DC_MEMORY)
{
image = XGetImage( display, dc->u.x.drawable, x, y, 1, 1,
AllPlanes, ZPixmap );
}
else
{
/* If we are reading from the screen, use a temporary copy */
/* to avoid a BadMatch error */
if (!pixmap) pixmap = XCreatePixmap( display, rootWindow,
1, 1, dc->w.bitsPerPixel );
XCopyArea( display, dc->u.x.drawable, pixmap, BITMAP_colorGC,
x, y, 1, 1, 0, 0 );
image = XGetImage( display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
}
pixel = XGetPixel( image, 0, 0 );
XDestroyImage( image );
return COLOR_ToLogical(pixel);
}
/***********************************************************************
* X11DRV_PaintRgn
*/
BOOL32
X11DRV_PaintRgn( DC *dc, HRGN32 hrgn )
{
RECT32 box;
HRGN32 tmpVisRgn, prevVisRgn;
HDC32 hdc = dc->hSelf; /* FIXME: should not mix dc/hdc this way */
/* Modify visible region */
if (!(prevVisRgn = SaveVisRgn( hdc ))) return FALSE;
if (!(tmpVisRgn = CreateRectRgn32( 0, 0, 0, 0 )))
{
RestoreVisRgn( hdc );
return FALSE;
}
CombineRgn32( tmpVisRgn, prevVisRgn, hrgn, RGN_AND );
SelectVisRgn( hdc, tmpVisRgn );
DeleteObject32( tmpVisRgn );
/* Fill the region */
GetRgnBox32( dc->w.hGCClipRgn, &box );
if (DC_SetupGCForBrush( dc ))
XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + box.left, dc->w.DCOrgY + box.top,
box.right-box.left, box.bottom-box.top );
/* Restore the visible region */
RestoreVisRgn( hdc );
return TRUE;
}
/**********************************************************************
* X11DRV_Polyline
*/
BOOL32
X11DRV_Polyline( DC *dc, const LPPOINT32 pt, INT32 count )
{
register int i;
if (DC_SetupGCForPen( dc ))
for (i = 0; i < count-1; i ++)
XDrawLine (display, dc->u.x.drawable, dc->u.x.gc,
dc->w.DCOrgX + XLPTODP(dc, pt [i].x),
dc->w.DCOrgY + YLPTODP(dc, pt [i].y),
dc->w.DCOrgX + XLPTODP(dc, pt [i+1].x),
dc->w.DCOrgY + YLPTODP(dc, pt [i+1].y));
return TRUE;
}
/**********************************************************************
* X11DRV_Polygon
*/
BOOL32
X11DRV_Polygon( DC *dc, LPPOINT32 pt, INT32 count )
{
register int i;
XPoint *points;
points = (XPoint *) xmalloc (sizeof (XPoint) * (count+1));
for (i = 0; i < count; i++)
{
points[i].x = dc->w.DCOrgX + XLPTODP( dc, pt[i].x );
points[i].y = dc->w.DCOrgY + YLPTODP( dc, pt[i].y );
}
points[count] = points[0];
if (DC_SetupGCForBrush( dc ))
XFillPolygon( display, dc->u.x.drawable, dc->u.x.gc,
points, count+1, Complex, CoordModeOrigin);
if (DC_SetupGCForPen ( dc ))
XDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
points, count+1, CoordModeOrigin );
free( points );
return TRUE;
}
/**********************************************************************
* X11DRV_PolyPolygon
*/
BOOL32
X11DRV_PolyPolygon( DC *dc, LPPOINT32 pt, LPINT32 counts, UINT32 polygons)
{
HRGN32 hrgn;
/* FIXME: The points should be converted to device coords before */
/* creating the region. But as CreatePolyPolygonRgn is not */
/* really correct either, it doesn't matter much... */
/* At least the outline will be correct :-) */
hrgn = CreatePolyPolygonRgn32( pt, counts, polygons, dc->w.polyFillMode );
X11DRV_PaintRgn( dc, hrgn );
DeleteObject32( hrgn );
/* Draw the outline of the polygons */
if (DC_SetupGCForPen ( dc ))
{
int i, j, max = 0;
XPoint *points;
for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
points = (XPoint *) xmalloc( sizeof(XPoint) * (max+1) );
for (i = 0; i < polygons; i++)
{
for (j = 0; j < counts[i]; j++)
{
points[j].x = dc->w.DCOrgX + XLPTODP( dc, pt->x );
points[j].y = dc->w.DCOrgY + YLPTODP( dc, pt->y );
pt++;
}
points[j] = points[0];
XDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
points, j + 1, CoordModeOrigin );
}
free( points );
}
return TRUE;
}
/**********************************************************************
* X11DRV_InternalFloodFill
*
* Internal helper function for flood fill.
* (xorg,yorg) is the origin of the X image relative to the drawable.
* (x,y) is relative to the origin of the X image.
*/
static void X11DRV_InternalFloodFill(XImage *image, DC *dc,
int x, int y,
int xOrg, int yOrg,
Pixel pixel, WORD fillType )
{
int left, right;
#define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
(XGetPixel(image,x,y) != pixel) : \
(XGetPixel(image,x,y) == pixel))
if (!TO_FLOOD(x,y)) return;
/* Find left and right boundaries */
left = right = x;
while ((left > 0) && TO_FLOOD( left-1, y )) left--;
while ((right < image->width) && TO_FLOOD( right, y )) right++;
XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
xOrg + left, yOrg + y, right-left, 1 );
/* Set the pixels of this line so we don't fill it again */
for (x = left; x < right; x++)
{
if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
else XPutPixel( image, x, y, ~pixel );
}
/* Fill the line above */
if (--y >= 0)
{
x = left;
while (x < right)
{
while ((x < right) && !TO_FLOOD(x,y)) x++;
if (x >= right) break;
while ((x < right) && TO_FLOOD(x,y)) x++;
X11DRV_InternalFloodFill(image, dc, x-1, y,
xOrg, yOrg, pixel, fillType );
}
}
/* Fill the line below */
if ((y += 2) < image->height)
{
x = left;
while (x < right)
{
while ((x < right) && !TO_FLOOD(x,y)) x++;
if (x >= right) break;
while ((x < right) && TO_FLOOD(x,y)) x++;
X11DRV_InternalFloodFill(image, dc, x-1, y,
xOrg, yOrg, pixel, fillType );
}
}
#undef TO_FLOOD
}
/**********************************************************************
* X11DRV_DoFloodFill
*
* Main flood-fill routine.
*/
static BOOL32 X11DRV_DoFloodFill( DC *dc, RECT32 *rect, INT32 x, INT32 y,
COLORREF color, UINT32 fillType )
{
XImage *image;
if (!(image = XGetImage( display, dc->u.x.drawable,
dc->w.DCOrgX + rect->left,
dc->w.DCOrgY + rect->top,
rect->right - rect->left,
rect->bottom - rect->top,
AllPlanes, ZPixmap ))) return FALSE;
if (DC_SetupGCForBrush( dc ))
{
/* ROP mode is always GXcopy for flood-fill */
XSetFunction( display, dc->u.x.gc, GXcopy );
X11DRV_InternalFloodFill(image, dc,
XLPTODP(dc,x) - rect->left,
YLPTODP(dc,y) - rect->top,
dc->w.DCOrgX + rect->left,
dc->w.DCOrgY + rect->top,
COLOR_ToPhysical( dc, color ), fillType );
}
XDestroyImage( image );
return TRUE;
}
/**********************************************************************
* X11DRV_ExtFloodFill
*/
BOOL32
X11DRV_ExtFloodFill( DC *dc, INT32 x, INT32 y, COLORREF color,
UINT32 fillType )
{
RECT32 rect;
HDC32 hdc = dc->hSelf; /* FIXME */
dprintf_graphics( stddeb, "X11DRV_ExtFloodFill %d,%d %06lx %d\n",
x, y, color, fillType );
if (!PtVisible32( hdc, x, y )) return FALSE;
if (GetRgnBox32( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
return CallTo32_LargeStack( (int(*)())X11DRV_DoFloodFill, 6,
dc, &rect, x, y, color, fillType );
}