| version 1.3, 2003/09/12 08:55:22 |
version 1.4, 2003/10/21 10:35:05 |
|
|
| |
|
| #include <stdlib.h> |
#include <stdlib.h> |
| #include <string.h> |
#include <string.h> |
| #if defined(DEBUG) && DEBUG |
#if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| # include <stdio.h> |
# include <stdio.h> |
| #endif |
#endif |
| |
|
| |
#define X11_BGI_USE_XKeycodeToKeysym 1 |
| |
#define X11_BGI_USE_SELECT 1 |
| |
#define X11_BGI_USE_PTHREADS 0 |
| |
#define X11_BGI_INPUT_MASK \ |
| |
ExposureMask | KeyPressMask | SubstructureNotifyMask | PointerMotionMask | \ |
| |
ButtonPressMask | ButtonReleaseMask |
| |
|
| |
/* unused */ |
| |
#define X11_BGI_INPUT_MASK_2 NoEventMask \ |
| |
+ KeyPressMask \ |
| |
+ KeyReleaseMask \ |
| |
+ ButtonPressMask \ |
| |
+ ButtonReleaseMask \ |
| |
+ EnterWindowMask \ |
| |
+ LeaveWindowMask \ |
| |
+ PointerMotionMask \ |
| |
+ PointerMotionHintMask \ |
| |
+ Button1MotionMask \ |
| |
+ Button2MotionMask \ |
| |
+ Button3MotionMask \ |
| |
+ Button4MotionMask \ |
| |
+ Button5MotionMask \ |
| |
+ ButtonMotionMask \ |
| |
+ KeymapStateMask \ |
| |
+ ExposureMask \ |
| |
+ VisibilityChangeMask \ |
| |
+ StructureNotifyMask \ |
| |
+ ResizeRedirectMask \ |
| |
+ SubstructureNotifyMask \ |
| |
+ SubstructureRedirectMask \ |
| |
+ FocusChangeMask \ |
| |
+ PropertyChangeMask \ |
| |
+ ColormapChangeMask \ |
| |
+ OwnerGrabButtonMask |
| |
|
| |
#if defined(X11_BGI_USE_SELECT) && X11_BGI_USE_SELECT |
| |
# include <sys/select.h> |
| |
#else |
| |
# include <unistd.h> |
| |
#endif |
| |
|
| |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| |
# include <pthread.h> |
| |
# include <sys/types.h> |
| |
# include <signal.h> |
| |
static pthread_t ExposerThread; |
| |
static int ThreadsInitialized = 0; |
| |
#endif |
| |
|
| |
static void *ExposerFunction(void *); |
| |
static void ExposerFunctionLoop(void); |
| |
|
| |
void |
| |
X11_BGI_update_IO(void) /* {{{ */ |
| |
{ |
| |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| |
/* do nothing */ |
| |
#else |
| |
ExposerFunction(NULL); |
| |
#endif |
| |
} /* }}} */ |
| |
|
| /* TurboC-source/TurboX.c */ |
/* TurboC-source/TurboX.c */ |
| |
|
| int |
int |
| TurboX (int Forced) /* {{{ */ |
TurboX (int Forced) /* {{{ */ |
| { |
{ |
| return (0); |
return 0; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* TurboC-source/freeTurbo.c */ |
/* TurboC-source/freeTurbo.c */ |
| Line 490 extern volatile int TcShutdownGraphics; |
|
| Line 552 extern volatile int TcShutdownGraphics; |
|
| void |
void |
| closegraph (void) /* {{{ */ |
closegraph (void) /* {{{ */ |
| { |
{ |
| int i; |
if (TcGraphicsInitialized) { |
| if (TcGraphicsInitialized) |
register int i; |
| { |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| TcShutdownGraphics = 1; |
TcShutdownGraphics = 1; |
| while (TcShutdownGraphics || TcGraphicsInitialized); |
while (TcShutdownGraphics || TcGraphicsInitialized); |
| |
#endif |
| |
|
| #if 0 |
#if 0 |
| for (i = 0; i < MAX_TCIMAGEBUFS; i++) |
for (i = 0; i < MAX_TCIMAGEBUFS; i++) |
| if (TcPixmapPool[i].Allocated) |
if (TcPixmapPool[i].Allocated) |
| Line 966 graphresult (void) /* {{{ */ |
|
| Line 1030 graphresult (void) /* {{{ */ |
|
| |
|
| /* TurboC-source/initgraph.c */ |
/* TurboC-source/initgraph.c */ |
| |
|
| #include <pthread.h> |
|
| #include <sys/types.h> |
|
| #include <signal.h> |
|
| |
|
| static pthread_t ExposerThread; |
|
| static int ThreadsInitialized = 0; |
|
| static void *ExposerFunction (void *); |
|
| |
|
| /*#include "graphics.h" */ |
/*#include "graphics.h" */ |
| /*#include "conio.h" */ |
/*#include "conio.h" */ |
| |
|
| Line 999 initgraph (int *graphdriver, int *graphm |
|
| Line 1055 initgraph (int *graphdriver, int *graphm |
|
| int i, Xres, Yres, Pcnt, Pal; |
int i, Xres, Yres, Pcnt, Pal; |
| gulong White, Black; |
gulong White, Black; |
| Atom wm_delete_window; |
Atom wm_delete_window; |
| |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| if (!ThreadsInitialized) |
if (!ThreadsInitialized) |
| { |
{ |
| XInitThreads (); |
XInitThreads (); |
| ThreadsInitialized = 1; |
ThreadsInitialized = 1; |
| } |
} |
| |
#endif |
| if (TcGraphicsInitialized) |
if (TcGraphicsInitialized) |
| closegraph (); |
closegraph (); |
| /* An alternate display name might allow the program to be run remotely. */ |
/* An alternate display name might allow the program to be run remotely. */ |
| Line 1091 initgraph (int *graphdriver, int *graphm |
|
| Line 1149 initgraph (int *graphdriver, int *graphm |
|
| TcGraphResult = *graphdriver = grInvalidMode; |
TcGraphResult = *graphdriver = grInvalidMode; |
| return; |
return; |
| } |
} |
| #if defined(DEBUG) && DEBUG |
#if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| fprintf(stderr, "x11-bgi.c: initgraph(): Xres = %d, Yres = %d, Pcnt = %d\n", |
fprintf(stderr, "x11-bgi.c: initgraph(): Xres = %d, Yres = %d, Pcnt = %d\n", |
| Xres, Yres, Pcnt); |
Xres, Yres, Pcnt); |
| #endif |
#endif |
| Line 1155 initgraph (int *graphdriver, int *graphm |
|
| Line 1213 initgraph (int *graphdriver, int *graphm |
|
| 8, 8, DefaultDepth (TcDisplay, TcScreen)); |
8, 8, DefaultDepth (TcDisplay, TcScreen)); |
| TcGraphDefaults (); |
TcGraphDefaults (); |
| TcGraphicsInitialized = 1; |
TcGraphicsInitialized = 1; |
| |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| if (ThreadsInitialized == 1) |
if (ThreadsInitialized == 1) |
| { |
{ |
| ThreadsInitialized = 2; |
ThreadsInitialized = 2; |
| Line 1164 initgraph (int *graphdriver, int *graphm |
|
| Line 1223 initgraph (int *graphdriver, int *graphm |
|
| return; |
return; |
| } |
} |
| } |
} |
| |
#endif |
| } /* }}} */ |
} /* }}} */ |
| |
|
| int volatile TcShutdownGraphics = 0; |
int volatile TcShutdownGraphics = 0; |
| Line 1171 int volatile TcShutdownGraphics = 0; |
|
| Line 1231 int volatile TcShutdownGraphics = 0; |
|
| static void * |
static void * |
| ExposerFunction (void *DummyArg) /* {{{ */ |
ExposerFunction (void *DummyArg) /* {{{ */ |
| { |
{ |
| KeySym Key; |
XSelectInput(TcDisplay, TcWindow, X11_BGI_INPUT_MASK); |
| char Text[32]; |
ExposerFunctionLoop(); |
| |
return NULL; |
| |
} /* }}} */ |
| |
|
| |
static void |
| |
ExposerFunctionLoop(void) /* {{{ */ |
| |
{ |
| XEvent Event; |
XEvent Event; |
| int i, j; |
int i, j; |
| XSelectInput (TcDisplay, TcWindow, |
#if defined(X11_BGI_USE_XKeycodeToKeysym) && X11_BGI_USE_XKeycodeToKeysym |
| ExposureMask | KeyPressMask | SubstructureNotifyMask); |
/* nothing needed */ |
| while (1) |
#else |
| { |
char Text[32]; |
| |
KeySym Key; |
| |
#endif |
| |
#if defined(X11_BGI_USE_SELECT) && X11_BGI_USE_SELECT |
| |
struct timeval tval; |
| |
fd_set readfds; |
| |
#endif |
| |
|
| |
do { |
| /* When the main thread wants to turn off graphics mode, it */ |
/* When the main thread wants to turn off graphics mode, it */ |
| /* sets TcShutdownGraphics to 1 and waits until it turns */ |
/* sets TcShutdownGraphics to 1 and waits until it turns */ |
| /* back to 0 before proceeding. */ |
/* back to 0 before proceeding. */ |
| if (TcShutdownGraphics) |
if (TcShutdownGraphics) { |
| { |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| ThreadsInitialized = 0; |
ThreadsInitialized = 0; |
| |
#endif |
| TcShutdownGraphics = 0; |
TcShutdownGraphics = 0; |
| TcGraphicsInitialized = 0; |
TcGraphicsInitialized = 0; |
| return (NULL); |
return; |
| } |
} |
| |
|
| |
#if defined(X11_BGI_USE_SELECT) && X11_BGI_USE_SELECT |
| |
/* Note: the select() call with nonzero timeout avoids CPU usage of nearly 100% */ |
| |
i = ConnectionNumber(TcDisplay); |
| |
FD_ZERO(&readfds); |
| |
FD_SET(i, &readfds); |
| |
tval.tv_sec = 0; |
| |
tval.tv_usec = 1; |
| |
i = select(i + 1, &readfds, NULL, NULL, &tval); |
| |
#else |
| |
usleep(1); |
| |
#endif |
| |
|
| XLockDisplay (TcDisplay); |
XLockDisplay (TcDisplay); |
| if (XCheckWindowEvent |
if (XCheckWindowEvent(TcDisplay, TcWindow, X11_BGI_INPUT_MASK, &Event)) { |
| (TcDisplay, TcWindow, ExposureMask | KeyPressMask | |
|
| SubstructureNotifyMask, &Event)) |
|
| switch (Event.type) |
switch (Event.type) |
| { |
{ |
| |
default: |
| |
/* XPutBackEvent(TcDisplay, &Event); */ |
| |
break; |
| case Expose: |
case Expose: |
| /* Come here after something moves in front of our window */ |
/* Come here after something moves in front of our window */ |
| /* so that we need to redraw it. */ |
/* so that we need to redraw it. */ |
| XCopyArea (TcDisplay, TcPixmaps[TcVisualPage], TcWindow, |
XCopyArea(TcDisplay, TcPixmaps[TcVisualPage], TcWindow, |
| TcGc, Event.xexpose.x, Event.xexpose.y, |
TcGc, Event.xexpose.x, Event.xexpose.y, |
| Event.xexpose.width, Event.xexpose.height, |
Event.xexpose.width, Event.xexpose.height, |
| Event.xexpose.x, Event.xexpose.y); |
Event.xexpose.x, Event.xexpose.y); |
| |
#if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| |
fprintf(stderr, "ExposerFunctionLoop(): Expose\n"); |
| |
#endif |
| break; |
break; |
| case KeyPress: |
case KeyPress: |
| |
case KeyRelease: |
| |
#if defined(X11_BGI_USE_XKeycodeToKeysym) && X11_BGI_USE_XKeycodeToKeysym |
| |
i = XKeycodeToKeysym(TcDisplay, Event.xkey.keycode, 0); |
| |
# if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| |
fprintf(stderr, "ExposerFunctionLoop(): Key%s %x (%d) [%c]\n", |
| |
Event.xkey.type == KeyPress ? "Press" : "Release", |
| |
i, i, i); |
| |
# endif |
| |
#else |
| /* This needs to be fixed up some to accomodate things */ |
/* This needs to be fixed up some to accomodate things */ |
| /* like arrows and function keys, but it works okay for */ |
/* like arrows and function keys, but it works okay for */ |
| /* regular keys as-is. */ |
/* regular keys as-is. */ |
| i = XLookupString (&Event.xkey, Text, sizeof (Text), &Key, NULL); |
i = XLookupString(&Event.xkey, Text, sizeof(Text), &Key, NULL); |
| for (j = 0; j < i; j++) |
for (j = 0; j < i; j++) { |
| /* TODO: handle this |
/* TODO: handle this |
| TcAddKeybuf (Text[j])*/; |
TcAddKeybuf(Text[j]) */ |
| break; |
# if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| |
fprintf(stderr, "ExposerFunctionLoop(): Key%s %x (%d) [%c]\n", |
| |
Event.xkey.type == KeyPress ? "Press" : "Release", |
| |
Text[j], Text[j], Text[j]); |
| |
# endif |
| |
} |
| |
#endif |
| |
break; |
| case NoExpose: |
case NoExpose: |
| |
#if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| |
fprintf(stderr, "ExposerFunctionLoop(): NoExpose\n"); |
| |
#endif |
| break; |
break; |
| case ClientMessage: |
case ClientMessage: |
| |
#if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| |
fprintf(stderr, "ExposerFunctionLoop(): ClientMessage\n"); |
| |
#endif |
| /* Come here if the user tries to manually close the graphics */ |
/* Come here if the user tries to manually close the graphics */ |
| /* window. We allow the programmer to decide what to do */ |
/* window. We allow the programmer to decide what to do */ |
| /* about it. The callback function TurboX can be provided */ |
/* about it. The callback function TurboX can be provided */ |
| Line 1222 ExposerFunction (void *DummyArg) /* {{{ |
|
| Line 1336 ExposerFunction (void *DummyArg) /* {{{ |
|
| /* just returns 1. A return value of 0 means to continue */ |
/* just returns 1. A return value of 0 means to continue */ |
| /* executing, while a non-zero value means to close down the */ |
/* executing, while a non-zero value means to close down the */ |
| /* program. */ |
/* program. */ |
| if (TurboX (0)) |
if (TurboX(0)) { |
| { |
XUnlockDisplay(TcDisplay); |
| XUnlockDisplay (TcDisplay); |
#if 0 |
| /*closegraph (); */ |
closegraph (); |
| /*kill (0, SIGTERM); */ |
kill(0, SIGTERM); |
| |
#endif |
| |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| ThreadsInitialized = 0; |
ThreadsInitialized = 0; |
| |
#endif |
| TcGraphicsInitialized = 0; |
TcGraphicsInitialized = 0; |
| /*return (NULL); */ |
/*return (NULL); */ |
| exit (2); |
exit(2); |
| } |
} |
| break; |
break; |
| default: |
|
| |
/* These event handler modifications regarding to mouse |
| |
handling was added by Nepto at 28th September 2003 */ |
| |
case MotionNotify: |
| |
MOUINFO_xpos = Event.xmotion.x; |
| |
MOUINFO_ypos = Event.xmotion.y; |
| |
#if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| |
fprintf(stderr, "ExposerFunctionLoop(): MotionNotify [%d,%d]\n", |
| |
MOUINFO_xpos, MOUINFO_ypos); |
| |
#endif |
| |
break; |
| |
|
| |
case ButtonPress: |
| |
case ButtonRelease: |
| |
#if 0 /* This is orginal algorithm |
| |
DO NOT DELETE FROM SOURCE! */ |
| |
unsigned int state = Event.state; |
| |
unsigned int mask = 0; |
| |
|
| |
switch (Event.button) { |
| |
case Button1: mask = Button1Mask; break; |
| |
case Button2: mask = Button2Mask; break; |
| |
case Button3: mask = Button3Mask; break; |
| |
} |
| |
switch (Event.type) { |
| |
case ButtonPress: state |= mask; break; |
| |
case ButtonRelease: state &= ~mask; break; |
| |
} |
| |
return ( ((state & Button1Mask) ? GR_M_LEFT : 0) |
| |
| ((state & Button2Mask) ? GR_M_MIDDLE : 0) |
| |
| ((state & Button3Mask) ? GR_M_RIGHT : 0)); |
| |
#endif |
| |
switch (Event.xbutton.button) |
| |
{ |
| |
case Button1: i = Button1Mask; j = 0; break; |
| |
case Button2: i = Button2Mask; j = 1; break; |
| |
case Button3: i = Button3Mask; j = 2; break; |
| |
default: i = 0; j = -1; break; |
| |
} |
| |
switch (Event.xbutton.type) |
| |
{ |
| |
case ButtonPress: |
| |
if (j >= 0 && j <= 2) |
| |
MOUINFO_pressed_count[j]++; |
| |
j = Event.xbutton.state | i; |
| |
break; |
| |
case ButtonRelease: |
| |
if (j >= 0 && j <= 2) |
| |
MOUINFO_released_count[j]++; |
| |
j = Event.xbutton.state & ~i; |
| |
break; |
| |
} |
| |
MOUINFO_bstat = 0 |
| |
+ ((j & Button1Mask) ? 1 : 0) |
| |
+ ((j & Button2Mask) ? 2 : 0) |
| |
+ ((j & Button3Mask) ? 0 : 0); /* Button3 disabled */ |
| |
#if defined(X11_BGI_DEBUG) && X11_BGI_DEBUG |
| |
fprintf(stderr, "ExposerFunctionLoop(): Button%s %d\n", |
| |
Event.xbutton.type == ButtonPress ? "Press" : "Release", |
| |
MOUINFO_bstat); |
| |
#endif |
| break; |
break; |
| } |
} |
| |
} |
| XUnlockDisplay (TcDisplay); |
XUnlockDisplay (TcDisplay); |
| } |
} |
| |
#if defined(X11_BGI_USE_PTHREADS) && X11_BGI_USE_PTHREADS |
| |
while (1); |
| |
#else |
| |
while (0); /* exit when not in thread */ |
| |
#endif |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* TurboC-source/line.c */ |
/* TurboC-source/line.c */ |
| Line 1524 rectangle (int x1, int y1, int x2, int y |
|
| Line 1707 rectangle (int x1, int y1, int x2, int y |
|
| y1 = y2; |
y1 = y2; |
| y2 = i; |
y2 = i; |
| } |
} |
| i = x2 - x1 + 1; |
/* -1 hack by Nepto */ |
| j = y2 - y1 + 1; |
i = x2 - x1 + 1 - 1; |
| |
j = y2 - y1 + 1 - 1; |
| /* Convert to viewport coordinates. */ |
/* Convert to viewport coordinates. */ |
| x1 += TcViewLeft; |
x1 += TcViewLeft; |
| y1 += TcViewTop; |
y1 += TcViewTop; |