Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Saturday, October 24, 2026

Diff for games/_shared/x11-bgi.c between version 1.1 and 1.2

version 1.1, 2003/08/12 20:50:59 version 1.2, 2003/09/07 20:26:30
Line 24 
Line 24 
 #include "x11-bgi.h"  #include "x11-bgi.h"
   
 #include <stdlib.h>  #include <stdlib.h>
   #include <string.h>
   
 /* TurboC-source/TurboX.c */  /* TurboC-source/TurboX.c */
   
Line 35  TurboX (int Forced) /* {{{ */
Line 36  TurboX (int Forced) /* {{{ */
   
 /* TurboC-source/freeTurbo.c */  /* TurboC-source/freeTurbo.c */
   
 // This is the stuff for the linked list of allocated memory blocks  /* This is the stuff for the linked list of allocated memory blocks */
 // associated with Pixmaps.  /* associated with Pixmaps. */
 struct PixmappedBlock /* {{{ */  struct PixmappedBlock /* {{{ */
 {  {
         void *Object;                   // Pointer created by malloc/calloc.          void *Object;                   /* Pointer created by malloc/calloc. */
         Pixmap Pix;                     // The Pixmap's handle.          Pixmap Pix;                     /* The Pixmap's handle. */
         struct PixmappedBlock *Next;          struct PixmappedBlock *Next;
 }; /* }}} */  }; /* }}} */
 static struct PixmappedBlock *PixmappedRoot = NULL;  static struct PixmappedBlock *PixmappedRoot = NULL;
   
 // This is the function which is called by getimage to associate a Pixmap  /* This is the function which is called by getimage to associate a Pixmap */
 // with an already-allocated memory block.  If the block is not in the  /* with an already-allocated memory block.  If the block is not in the */
 // list already, it will be added.  If the block *is* in the list, its old  /* list already, it will be added.  If the block *is* in the list, its old */
 // Pixmap will be freed and then the new one added.  Returns 0 on success,  /* Pixmap will be freed and then the new one added.  Returns 0 on success, */
 // non-zero if out of memory.  /* non-zero if out of memory. */
         extern int          extern int
 AssociatePixmap (void *object, Pixmap handle) /* {{{ */  AssociatePixmap (void *object, Pixmap handle) /* {{{ */
 {  {
         struct PixmappedBlock *Block, *LastBlock;          struct PixmappedBlock *Block, *LastBlock;
         // If the list is empty, just add the new block.          /* If the list is empty, just add the new block. */
         if (PixmappedRoot == NULL)          if (PixmappedRoot == NULL)
         {          {
                 PixmappedRoot =                  PixmappedRoot =
Line 66  AssociatePixmap (void *object, Pixmap ha
Line 67  AssociatePixmap (void *object, Pixmap ha
                 PixmappedRoot->Next = NULL;                  PixmappedRoot->Next = NULL;
                 return (0);                  return (0);
         }          }
         // Navigate the linked list to see if this block is already in it!          /* Navigate the linked list to see if this block is already in it! */
         // Note that this is guaranteed to iterate at least once, so if it falls          /* Note that this is guaranteed to iterate at least once, so if it falls */
         // through, we know that LastBlock has been initialized.          /* through, we know that LastBlock has been initialized. */
         for (Block = PixmappedRoot; Block != NULL;          for (Block = PixmappedRoot; Block != NULL;
                         LastBlock = Block, Block = Block->Next)                          LastBlock = Block, Block = Block->Next)
                 if (Block->Object == object)                  if (Block->Object == object)
                 {                  {
                         if (Block->Pix != handle)                          if (Block->Pix != handle)
                         {                          {
                                 // The block *is* already defined, but is associated with                                  /* The block *is* already defined, but is associated with */
                                 // a different Pixmap.  So free the old Pixmap and associate                                  /* a different Pixmap.  So free the old Pixmap and associate */
                                 // a new one!                                  /* a new one! */
                                 XFreePixmap (TcDisplay, Block->Pix);                                  XFreePixmap (TcDisplay, Block->Pix);
                                 Block->Pix = handle;                                  Block->Pix = handle;
                         }                          }
                         return (0);                          return (0);
                 }                  }
         // The block wasn't in the list, so add it.          /* The block wasn't in the list, so add it. */
         Block = (struct PixmappedBlock *) malloc (sizeof (struct PixmappedBlock));          Block = (struct PixmappedBlock *) malloc (sizeof (struct PixmappedBlock));
         if (Block == NULL)          if (Block == NULL)
                 return (1);                  return (1);
Line 375  bar (int x1, int y1, int x2, int y2) /*
Line 376  bar (int x1, int y1, int x2, int y2) /*
         }          }
         i = x2 - x1 + 1;          i = x2 - x1 + 1;
         j = y2 - y1 + 1;          j = y2 - y1 + 1;
         // Convert to viewport coordinates.          /* Convert to viewport coordinates. */
         x1 += TcViewLeft;          x1 += TcViewLeft;
         y1 += TcViewTop;          y1 += TcViewTop;
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XSetFillStyle (TcDisplay, TcGc, FillTiled);          XSetFillStyle (TcDisplay, TcGc, FillTiled);
         XSetTile (TcDisplay, TcGc, TcTile);          XSetTile (TcDisplay, TcGc, TcTile);
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XFillRectangle (TcDisplay, TcPixmaps[TcActivePage], TcGc, x1, y1, i, j);          XFillRectangle (TcDisplay, TcPixmaps[TcActivePage], TcGc, x1, y1, i, j);
         if (TcActivePage == TcVisualPage)          if (TcActivePage == TcVisualPage)
         {          {
Line 397  bar3d (int x1, int y1, int x2, int y2, i
Line 398  bar3d (int x1, int y1, int x2, int y2, i
 {  {
         int dx, dy;          int dx, dy;
         int i1, i2, j1, j2;          int i1, i2, j1, j2;
         // Order the coordinates correctly.          /* Order the coordinates correctly. */
         if (x1 > x2)          if (x1 > x2)
         {          {
                 i1 = x1;                  i1 = x1;
Line 410  bar3d (int x1, int y1, int x2, int y2, i
Line 411  bar3d (int x1, int y1, int x2, int y2, i
                 y1 = y2;                  y1 = y2;
                 y2 = j1;                  y2 = j1;
         }          }
         // Draw the innards of the bar.          /* Draw the innards of the bar. */
         bar (x1, y1, x2, y2);          bar (x1, y1, x2, y2);
         // Put an outline around the bar.          /* Put an outline around the bar. */
         line (x1, y1, x2, y1);          line (x1, y1, x2, y1);
         line (x2, y1, x2, y2);          line (x2, y1, x2, y2);
         line (x2, y2, x1, y2);          line (x2, y2, x1, y2);
         line (x1, y2, x1, y1);          line (x1, y2, x1, y1);
         // Calculate the x,y offsets associated with the depth.  I assume          /* Calculate the x,y offsets associated with the depth.  I assume */
         // a 60-degree angle.          /* a 60-degree angle. */
         if (depth <= 0)          if (depth <= 0)
                 return;                  return;
         dy = (depth + 1) / 2;           // dy = depth * sin(30)          dy = (depth + 1) / 2;           /* dy = depth * sin(30) */
         dx = (depth * 866 + 500) / 1000;        // dx = depth * cos(30);          dx = (depth * 866 + 500) / 1000;        /* dx = depth * cos(30); */
         // Draw the right-hand side.          /* Draw the right-hand side. */
         i1 = x1 + dx;          i1 = x1 + dx;
         j1 = y1 - dy;          j1 = y1 - dy;
         i2 = x2 + dx;          i2 = x2 + dx;
         j2 = y2 - dy;          j2 = y2 - dy;
         line (x2, y2, i2, j2);          line (x2, y2, i2, j2);
         line (i2, j2, i2, j1);          line (i2, j2, i2, j1);
         // Draw the top.          /* Draw the top. */
         if (topflag)          if (topflag)
         {          {
                 line (x2, y1, i2, j1);                  line (x2, y1, i2, j1);
Line 462  clearviewport (void) /* {{{ */
Line 463  clearviewport (void) /* {{{ */
         Mode = TcWritemode;          Mode = TcWritemode;
         setwritemode (COPY_PUT);          setwritemode (COPY_PUT);
         XSetForeground (TcDisplay, TcGc, TcXbackground.pixel);          XSetForeground (TcDisplay, TcGc, TcXbackground.pixel);
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XFillRectangle (TcDisplay, TcPixmaps[TcActivePage], TcGc, TcViewLeft,          XFillRectangle (TcDisplay, TcPixmaps[TcActivePage], TcGc, TcViewLeft,
                         TcViewTop, TcViewRight - TcViewLeft + 1,                          TcViewTop, TcViewRight - TcViewLeft + 1,
Line 498  closegraph (void) /* {{{ */
Line 499  closegraph (void) /* {{{ */
                                 TcPixmapPool[i].Allocated = 0;                                  TcPixmapPool[i].Allocated = 0;
                                 XFreePixmap (TcDisplay, TcPixmapPool[i].Region);                                  XFreePixmap (TcDisplay, TcPixmapPool[i].Region);
                         }                          }
 #endif // 0  #endif /* 0 */
                 XFreePixmap (TcDisplay, TcTile);                  XFreePixmap (TcDisplay, TcTile);
                 XFreeGC (TcDisplay, TcGc);                  XFreeGC (TcDisplay, TcGc);
                 XUnmapWindow (TcDisplay, TcWindow);                  XUnmapWindow (TcDisplay, TcWindow);
Line 512  closegraph (void) /* {{{ */
Line 513  closegraph (void) /* {{{ */
         }          }
 } /* }}} */  } /* }}} */
   
 // restorecrtmode can be the same as closegraph because the textmode window  /* restorecrtmode can be the same as closegraph because the textmode window */
 // never actually goes away, and therefore never needs to be restored.  /* never actually goes away, and therefore never needs to be restored. */
         void          void
 restorecrtmode (void) /* {{{ */  restorecrtmode (void) /* {{{ */
 {  {
Line 522  restorecrtmode (void) /* {{{ */
Line 523  restorecrtmode (void) /* {{{ */
   
 /*TurboC-source/detectgraph.c */  /*TurboC-source/detectgraph.c */
   
 // We make the graphics screen this (integer) percentage of the full  /* We make the graphics screen this (integer) percentage of the full */
 // screen size, or less.  /* screen size, or less. */
 #define SHRINK_PERCENT 90  #define SHRINK_PERCENT 90
   
         void          void
Line 550  detectgraph (int *graphdriver, int *grap
Line 551  detectgraph (int *graphdriver, int *grap
         }          }
         ScreenWidth = (SHRINK_PERCENT * ScreenWidth + 50) / 100;          ScreenWidth = (SHRINK_PERCENT * ScreenWidth + 50) / 100;
         ScreenHeight = (SHRINK_PERCENT * ScreenHeight + 50) / 100;          ScreenHeight = (SHRINK_PERCENT * ScreenHeight + 50) / 100;
         // Now find the "best" mode that fits.  Of course, what's "best" depends          /* Now find the "best" mode that fits.  Of course, what's "best" depends */
         // on your criteria ...          /* on your criteria ... */
         if (ScreenWidth >= 1024 && ScreenHeight >= 768)          if (ScreenWidth >= 1024 && ScreenHeight >= 768)
         {          {
                 *graphdriver = IBM8514;                  *graphdriver = IBM8514;
Line 584  detectgraph (int *graphdriver, int *grap
Line 585  detectgraph (int *graphdriver, int *grap
         void          void
 fillellipse (int x, int y, int xradius, int yradius) /* {{{ */  fillellipse (int x, int y, int xradius, int yradius) /* {{{ */
 {  {
         // Convert to viewport coordinates.          /* Convert to viewport coordinates. */
         x += TcViewLeft - xradius;          x += TcViewLeft - xradius;
         y += TcViewTop - yradius;          y += TcViewTop - yradius;
         xradius *= 2;          xradius *= 2;
         yradius *= 2;          yradius *= 2;
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XSetFillStyle (TcDisplay, TcGc, FillTiled);          XSetFillStyle (TcDisplay, TcGc, FillTiled);
         XSetTile (TcDisplay, TcGc, TcTile);          XSetTile (TcDisplay, TcGc, TcTile);
Line 649  getimage (int left, int top, int right,
Line 650  getimage (int left, int top, int right,
         Bottom = TcViewBottom;          Bottom = TcViewBottom;
         Clip = TcViewClip;          Clip = TcViewClip;
         setviewport (0, 0, TcXresolution - 1, TcYresolution - 1, 0);          setviewport (0, 0, TcXresolution - 1, TcYresolution - 1, 0);
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XCopyArea (TcDisplay, TcWindow, Buffer->Handle,          XCopyArea (TcDisplay, TcWindow, Buffer->Handle,
                         TcGc, left, top, Buffer->Width, Buffer->Height, 0, 0);                          TcGc, left, top, Buffer->Width, Buffer->Height, 0, 0);
Line 678  putimage (int left, int top, void *bitma
Line 679  putimage (int left, int top, void *bitma
         Bottom = TcViewBottom;          Bottom = TcViewBottom;
         Clip = TcViewClip;          Clip = TcViewClip;
         setviewport (0, 0, TcXresolution - 1, TcYresolution - 1, 0);          setviewport (0, 0, TcXresolution - 1, TcYresolution - 1, 0);
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XCopyArea (TcDisplay, Buffer->Handle, TcPixmaps[TcVisualPage],          XCopyArea (TcDisplay, Buffer->Handle, TcPixmaps[TcVisualPage],
                         TcGc, 0, 0, Buffer->Width, Buffer->Height, left, top);                          TcGc, 0, 0, Buffer->Width, Buffer->Height, left, top);
Line 714  getmaxcolor (void) /* {{{ */
Line 715  getmaxcolor (void) /* {{{ */
                 default:                  default:
                         break;                          break;
         }          }
         // Shouldn't be possible to get here, but still ...          /* Shouldn't be possible to get here, but still ... */
         return (0);          return (0);
 } /* }}} */  } /* }}} */
   
Line 778  getpixel (int x, int y) /* {{{ */
Line 779  getpixel (int x, int y) /* {{{ */
         XColor Color;          XColor Color;
         unsigned RetVal = 0;          unsigned RetVal = 0;
         XImage *Image;          XImage *Image;
         // Convert to viewport coordinates.          /* Convert to viewport coordinates. */
         x += TcViewLeft;          x += TcViewLeft;
         y += TcViewTop;          y += TcViewTop;
         // Now do the interrogating.          /* Now do the interrogating. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         Image = XGetImage (TcDisplay, TcPixmaps[TcVisualPage], x, y, 1, 1,          Image = XGetImage (TcDisplay, TcPixmaps[TcVisualPage], x, y, 1, 1,
                         ~0L, XYPixmap);                          ~0L, XYPixmap);
Line 789  getpixel (int x, int y) /* {{{ */
Line 790  getpixel (int x, int y) /* {{{ */
         {          {
                 Color.pixel = XGetPixel (Image, 0, 0);                  Color.pixel = XGetPixel (Image, 0, 0);
                 XDestroyImage (Image);                  XDestroyImage (Image);
                 // Look up the rgb components of the raw pixel we've read back.                  /* Look up the rgb components of the raw pixel we've read back. */
                 XQueryColor (TcDisplay, TcColormap, &Color);                  XQueryColor (TcDisplay, TcColormap, &Color);
                 XUnlockDisplay (TcDisplay);                  XUnlockDisplay (TcDisplay);
                 // Find the closest-match color in our current palette.  Since the                  /* Find the closest-match color in our current palette.  Since the */
                 // colors in our palette are generally so far apart from each other,                  /* colors in our palette are generally so far apart from each other, */
                 // we can save a lot of execution time by using a taxi-cab metric                  /* we can save a lot of execution time by using a taxi-cab metric */
                 // rather than a Euclidean metric.                  /* rather than a Euclidean metric. */
                 ClosestS = 1000000;                  ClosestS = 1000000;
                 maxi = getmaxcolor ();                  maxi = getmaxcolor ();
                 for (i = 0; i <= maxi; i++)                  for (i = 0; i <= maxi; i++)
Line 850  TcGraphDefaults (void) /* {{{ */
Line 851  TcGraphDefaults (void) /* {{{ */
         setusercharsize (1, 1, 1, 1);          setusercharsize (1, 1, 1, 1);
 } /* }}} */  } /* }}} */
   
 // Sets the default colors for a given palette type.  Returns 0 on success.  /* Sets the default colors for a given palette type.  Returns 0 on success. */
         int          int
 TcDefaultColors (int Pal) /* {{{ */  TcDefaultColors (int Pal) /* {{{ */
 {  {
Line 943  grapherrormsg (int errorcode) /* {{{ */
Line 944  grapherrormsg (int errorcode) /* {{{ */
 {  {
         static char ErrorMessage[61];          static char ErrorMessage[61];
         if (errorcode < 0 || errorcode >= NUM_MESSAGES)          if (errorcode < 0 || errorcode >= NUM_MESSAGES)
                 strcpy (ErrorMessage, "Unknown error");                  strcpy(ErrorMessage, "Unknown error");
         else          else
                 strcpy (ErrorMessage, ErrorMessages[errorcode]);                  strcpy(ErrorMessage, ErrorMessages[errorcode]);
         return (ErrorMessage);          return ErrorMessage;
 } /* }}} */  } /* }}} */
   
 /* TurboC-source/graphresult.c */  /* TurboC-source/graphresult.c */
Line 970  static pthread_t ExposerThread;
Line 971  static pthread_t ExposerThread;
 static int ThreadsInitialized = 0;  static int ThreadsInitialized = 0;
 static void *ExposerFunction (void *);  static void *ExposerFunction (void *);
   
 //#include "graphics.h"  /*#include "graphics.h" */
 //#include "conio.h"  /*#include "conio.h" */
   
         extern void          extern void
 setgraphmode (int mode) /* {{{ */  setgraphmode (int mode) /* {{{ */
Line 981  setgraphmode (int mode) /* {{{ */
Line 982  setgraphmode (int mode) /* {{{ */
         initgraph (&graphdriver, &mode, "");          initgraph (&graphdriver, &mode, "");
 } /* }}} */  } /* }}} */
   
 // Borland Turbo C relies on loading a "graphics driver" ("*.BGI" files,  /* Borland Turbo C relies on loading a "graphics driver" ("*.BGI" files, */
 // which are like a plug-in) at runtime.  The pathtodriver variable is  /* which are like a plug-in) at runtime.  The pathtodriver variable is  */
 // supposed to specify the directory in which these driver files are located.  /* supposed to specify the directory in which these driver files are located.   */
 // The TurboC library, on the other hand, doesn't rely on the "driver" concept,  /* The TurboC library, on the other hand, doesn't rely on the "driver" concept,  */
 // and so the pathtodriver variables and graphdriver are unused.  /* and so the pathtodriver variables and graphdriver are unused. */
 // The TurboC library will allow any graphics mode (graphmode) to be applied  /* The TurboC library will allow any graphics mode (graphmode) to be applied */
 // to any "driver".  /* to any "driver". */
         extern void          extern void
 initgraph (int *graphdriver, int *graphmode, char *pathtodriver) /* {{{ */  initgraph (int *graphdriver, int *graphmode, char *pathtodriver) /* {{{ */
 {  {
Line 1002  initgraph (int *graphdriver, int *graphm
Line 1003  initgraph (int *graphdriver, int *graphm
         }          }
         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.   */
         // Since the conio.h functionality of the TurboC library (implemented          /* Since the conio.h functionality of the TurboC library (implemented  */
         // in ncurses) is accessible remotely, it would be consistent to implement          /* in ncurses) is accessible remotely, it would be consistent to implement  */
         // this.  If/when I figure this out, I'll fix it up.          /* this.  If/when I figure this out, I'll fix it up. */
         if (*graphdriver == 0)          if (*graphdriver == 0)
                 detectgraph (graphdriver, graphmode);                  detectgraph (graphdriver, graphmode);
         TcDisplay = XOpenDisplay (NULL);          TcDisplay = XOpenDisplay (NULL);
Line 1100  initgraph (int *graphdriver, int *graphm
Line 1101  initgraph (int *graphdriver, int *graphm
         TcWindow = XCreateSimpleWindow (TcDisplay,          TcWindow = XCreateSimpleWindow (TcDisplay,
                         DefaultRootWindow (TcDisplay),                          DefaultRootWindow (TcDisplay),
                         0, 0, Xres, Yres, 0, White, Black);                          0, 0, Xres, Yres, 0, White, Black);
         // Beg the window manager not to allow the window to be resized.          /* Beg the window manager not to allow the window to be resized.                                 */
         XSetNormalHints (TcDisplay, TcWindow, SizeHints);          XSetNormalHints (TcDisplay, TcWindow, SizeHints);
         // Tell the window manager we don't want the graphics window          /* Tell the window manager we don't want the graphics window  */
         // arbitrarily closed on us -- we want a signal instead.          /* arbitrarily closed on us -- we want a signal instead. */
         wm_delete_window = XInternAtom (TcDisplay, "WM_DELETE_WINDOW", False);          wm_delete_window = XInternAtom (TcDisplay, "WM_DELETE_WINDOW", False);
         XSetWMProtocols (TcDisplay, TcWindow, &wm_delete_window, 1);          XSetWMProtocols (TcDisplay, TcWindow, &wm_delete_window, 1);
         TcGc = XCreateGC (TcDisplay, TcWindow, 0, 0);          TcGc = XCreateGC (TcDisplay, TcWindow, 0, 0);
Line 1118  initgraph (int *graphdriver, int *graphm
Line 1119  initgraph (int *graphdriver, int *graphm
                 XFillRectangle (TcDisplay, TcPixmaps[i], TcGc, 0, 0, Xres, Yres);                  XFillRectangle (TcDisplay, TcPixmaps[i], TcGc, 0, 0, Xres, Yres);
         }          }
         XFree (SizeHints);          XFree (SizeHints);
         // Save what minimal info we need about the palette.          /* Save what minimal info we need about the palette. */
         Pal = (*graphmode / TCXYG) % TCP;          Pal = (*graphmode / TCXYG) % TCP;
         // Set up the default colors in the palette.          /* Set up the default colors in the palette.   */
         if (TcDefaultColors (Pal))          if (TcDefaultColors (Pal))
         {          {
                 for (i = 0; i < Pcnt; i++)                  for (i = 0; i < Pcnt; i++)
Line 1171  ExposerFunction (void *DummyArg) /* {{{
Line 1172  ExposerFunction (void *DummyArg) /* {{{
                         ExposureMask | KeyPressMask | SubstructureNotifyMask);                          ExposureMask | KeyPressMask | SubstructureNotifyMask);
         while (1)          while (1)
         {          {
                 // 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)
                 {                  {
                         ThreadsInitialized = 0;                          ThreadsInitialized = 0;
Line 1188  ExposerFunction (void *DummyArg) /* {{{
Line 1189  ExposerFunction (void *DummyArg) /* {{{
                         switch (Event.type)                          switch (Event.type)
                         {                          {
                                 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);
                                         break;                                          break;
                                 case KeyPress:                                  case KeyPress:
                                         // 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
Line 1207  ExposerFunction (void *DummyArg) /* {{{
Line 1208  ExposerFunction (void *DummyArg) /* {{{
                                 case NoExpose:                                  case NoExpose:
                                         break;                                          break;
                                 case ClientMessage:                                  case ClientMessage:
                                         // 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 */
                                         // by the programmer, but we also provide a default version that                                          /* by the programmer, but we also provide a default version that */
                                         // 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);
                                                 //closegraph ();                                                  /*closegraph (); */
                                                 //kill (0, SIGTERM);                                                  /*kill (0, SIGTERM); */
                                                 ThreadsInitialized = 0;                                                  ThreadsInitialized = 0;
                                                 TcGraphicsInitialized = 0;                                                  TcGraphicsInitialized = 0;
                                                 //return (NULL);                                                  /*return (NULL); */
                                                 exit (2);                                                  exit (2);
                                         }                                          }
                                         break;                                          break;
Line 1237  ExposerFunction (void *DummyArg) /* {{{
Line 1238  ExposerFunction (void *DummyArg) /* {{{
         void          void
 line (int x1, int y1, int x2, int y2) /* {{{ */  line (int x1, int y1, int x2, int y2) /* {{{ */
 {  {
         // Convert to viewport coordinates.          /* Convert to viewport coordinates. */
         x1 += TcViewLeft;          x1 += TcViewLeft;
         x2 += TcViewLeft;          x2 += TcViewLeft;
         y1 += TcViewTop;          y1 += TcViewTop;
         y2 += TcViewTop;          y2 += TcViewTop;
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XDrawLine (TcDisplay, TcPixmaps[TcActivePage], TcGc, x1, y1, x2, y2);          XDrawLine (TcDisplay, TcPixmaps[TcActivePage], TcGc, x1, y1, x2, y2);
         if (TcActivePage == TcVisualPage)          if (TcActivePage == TcVisualPage)
Line 1307  outtextxy (int x, int y, char * textstri
Line 1308  outtextxy (int x, int y, char * textstri
         int RowX, RowY, DeltaRowX, DeltaRowY, DeltaX, DeltaY;          int RowX, RowY, DeltaRowX, DeltaRowY, DeltaX, DeltaY;
         int OffX, OffY;          int OffX, OffY;
         int i, j, Mask;          int i, j, Mask;
         // We need to convert x,y to where it is the upper-left corner of the          /* We need to convert x,y to where it is the upper-left corner of the */
         // first character of the string (if viewed comfortably for reading).          /* first character of the string (if viewed comfortably for reading). */
         if (TcTextDirection == HORIZ_DIR)          if (TcTextDirection == HORIZ_DIR)
         {          {
                 switch (TcTextHoriz)                  switch (TcTextHoriz)
Line 1334  outtextxy (int x, int y, char * textstri
Line 1335  outtextxy (int x, int y, char * textstri
                                 break;                                  break;
                 }                  }
         }          }
         else                            // VERT_DIR          else                            /* VERT_DIR */
         {          {
                 switch (TcTextHoriz)                  switch (TcTextHoriz)
                 {                  {
                         case LEFT_TEXT:                          case LEFT_TEXT:
                                 // This does not actually work in true Turbo C 2.x.                                  /* This does not actually work in true Turbo C 2.x. */
                                 // The text ends up right-justified in my tests.                                  /* The text ends up right-justified in my tests.   */
                                 // I'm not sure if I should duplicate Borland's bug or not ....                                  /* I'm not sure if I should duplicate Borland's bug or not .... */
                                 // No, I guess I'll make it work the way it's documented,                                  /* No, I guess I'll make it work the way it's documented, */
                                 // since Borland may have fixed it in later versions.                                  /* since Borland may have fixed it in later versions. */
                                 break;                                  break;
                         case CENTER_TEXT:                          case CENTER_TEXT:
                                 x -= textheight (textstring) / 2;                                  x -= textheight (textstring) / 2;
Line 1364  outtextxy (int x, int y, char * textstri
Line 1365  outtextxy (int x, int y, char * textstri
                                 break;                                  break;
                 }                  }
         }          }
         // Convert to viewport coordinates.          /* Convert to viewport coordinates. */
         CharX = x + TcViewLeft;          CharX = x + TcViewLeft;
         CharY = y + TcViewTop;          CharY = y + TcViewTop;
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
   
         // The bitmapped font ...          /* The bitmapped font ... */
         if (TcTextFont == DEFAULT_FONT)          if (TcTextFont == DEFAULT_FONT)
         {          {
                 if (TcTextDirection == HORIZ_DIR)                  if (TcTextDirection == HORIZ_DIR)
Line 1392  outtextxy (int x, int y, char * textstri
Line 1393  outtextxy (int x, int y, char * textstri
                 }                  }
                 for (; *textstring; textstring++)                  for (; *textstring; textstring++)
                 {                  {
                         // Here's the basic idea.  For each character, we set up the                          /* Here's the basic idea.  For each character, we set up the */
                         // Points array to contain all of the visible pixels in the char.                          /* Points array to contain all of the visible pixels in the char. */
                         // This entire set of pixels is drawn at once with XDrawPoints.                          /* This entire set of pixels is drawn at once with XDrawPoints. */
                         // If the chracter size has been magnified, so that each                          /* If the chracter size has been magnified, so that each  */
                         // "pixel" is really an NxN block of pixels, we modify the                          /* "pixel" is really an NxN block of pixels, we modify the */
                         // coordinates in Points NxN times and use XDrawPoints NxN times.                          /* coordinates in Points NxN times and use XDrawPoints NxN times. */
                         // First, though, there is the initial setup of Points.                          /* First, though, there is the initial setup of Points. */
                         NumPoints = 0;                          NumPoints = 0;
                         i = (guchar) *textstring;                          i = (guchar) *textstring;
                         RowX = CharX;                          RowX = CharX;
Line 1411  outtextxy (int x, int y, char * textstri
Line 1412  outtextxy (int x, int y, char * textstri
                                 {                                  {
                                         if (0 != (Mask & 128))                                          if (0 != (Mask & 128))
                                         {                                          {
                                                 // Note that this CAN'T overflow the array.                                                  /* Note that this CAN'T overflow the array. */
                                                 Points[NumPoints].x = x;                                                  Points[NumPoints].x = x;
                                                 Points[NumPoints].y = y;                                                  Points[NumPoints].y = y;
                                                 NumPoints++;                                                  NumPoints++;
Line 1422  outtextxy (int x, int y, char * textstri
Line 1423  outtextxy (int x, int y, char * textstri
                                 RowX += DeltaRowX;                                  RowX += DeltaRowX;
                                 RowY += DeltaRowY;                                  RowY += DeltaRowY;
                         }                          }
                         //  Now, draw the points                          /*  Now, draw the points */
                         if (TcTextCharsize == 1)                          if (TcTextCharsize == 1)
                         {                          {
                                 XDrawPoints (TcDisplay, TcPixmaps[TcActivePage], TcGc, Points, NumPoints, CoordModeOrigin);                                  XDrawPoints (TcDisplay, TcPixmaps[TcActivePage], TcGc, Points, NumPoints, CoordModeOrigin);
Line 1482  putpixel (int x, int y, int color) /* {{
Line 1483  putpixel (int x, int y, int color) /* {{
         OldColor = TcForegroundColor;          OldColor = TcForegroundColor;
         if (color != OldColor)          if (color != OldColor)
                 setcolor (color);                  setcolor (color);
         // Convert to viewport coordinates.          /* Convert to viewport coordinates. */
         x += TcViewLeft;          x += TcViewLeft;
         y += TcViewTop;          y += TcViewTop;
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XDrawPoint (TcDisplay, TcPixmaps[TcActivePage], TcGc, x, y);          XDrawPoint (TcDisplay, TcPixmaps[TcActivePage], TcGc, x, y);
         if (TcActivePage == TcVisualPage)          if (TcActivePage == TcVisualPage)
Line 1518  rectangle (int x1, int y1, int x2, int y
Line 1519  rectangle (int x1, int y1, int x2, int y
         }          }
         i = x2 - x1 + 1;          i = x2 - x1 + 1;
         j = y2 - y1 + 1;          j = y2 - y1 + 1;
         // Convert to viewport coordinates.          /* Convert to viewport coordinates. */
         x1 += TcViewLeft;          x1 += TcViewLeft;
         y1 += TcViewTop;          y1 += TcViewTop;
         // Now do the actual drawing.          /* Now do the actual drawing. */
         XLockDisplay (TcDisplay);          XLockDisplay (TcDisplay);
         XDrawRectangle (TcDisplay, TcPixmaps[TcActivePage], TcGc, x1, y1, i, j);          XDrawRectangle (TcDisplay, TcPixmaps[TcActivePage], TcGc, x1, y1, i, j);
         if (TcActivePage == TcVisualPage)          if (TcActivePage == TcVisualPage)
Line 1559  Error:
Line 1560  Error:
                 case TC_PAL_C1:                  case TC_PAL_C1:
                 case TC_PAL_C2:                  case TC_PAL_C2:
                 case TC_PAL_C3:                  case TC_PAL_C3:
                         // I treat these all similarly to CGA 4-color palettes.                          /* I treat these all similarly to CGA 4-color palettes. */
                         // The Turbo C docs indicate somehow that in CGA "hi-res"                          /* The Turbo C docs indicate somehow that in CGA "hi-res" */
                         // mode, the background and foreground colors are reversed.                          /* mode, the background and foreground colors are reversed. */
                         // I don't deal with this as of yet, because I don't grasp                          /* I don't deal with this as of yet, because I don't grasp */
                         // what it means.                          /* what it means. */
                         if (color >= 16)                          if (color >= 16)
                                 goto Error;                                  goto Error;
                         Color.red = TcColors16[color].r;                          Color.red = TcColors16[color].r;
Line 1572  Error:
Line 1573  Error:
                         TcCurrentPalette.colors[0] = color;                          TcCurrentPalette.colors[0] = color;
                         break;                          break;
                 case TC_PAL_16:                  case TC_PAL_16:
                         // I treat these all similarly to EGA 16-color palettes.                          /* I treat these all similarly to EGA 16-color palettes. */
                         if (color >= 16)                          if (color >= 16)
                                 goto Error;                                  goto Error;
                         Color.red = TcColors[color].r;                          Color.red = TcColors[color].r;
Line 1593  Error:
Line 1594  Error:
         TcBackgroundColor = color;          TcBackgroundColor = color;
         TcXbackground = Color;          TcXbackground = Color;
         XSetBackground (TcDisplay, TcGc, Color.pixel);          XSetBackground (TcDisplay, TcGc, Color.pixel);
         // The background color will now presumably be inconsistent with          /* The background color will now presumably be inconsistent with */
         // any tile that has previously been generated for fills.  We therefore          /* any tile that has previously been generated for fills.  We therefore */
         // need to regenerate the tile.  This same problem *does not*          /* need to regenerate the tile.  This same problem *does not* */
         // exist for setcolor, since fills don't use the foreground color.          /* exist for setcolor, since fills don't use the foreground color. */
         setfillstyle (TcFillStyle, TcFillColor);          setfillstyle (TcFillStyle, TcFillColor);
 } /* }}} */  } /* }}} */
   
Line 1671  RawTile (char *pattern) /* {{{ */
Line 1672  RawTile (char *pattern) /* {{{ */
         int i, j, k, Match;          int i, j, k, Match;
         int OldColor;          int OldColor;
         OldColor = TcForegroundColor;          OldColor = TcForegroundColor;
         // This loop draws  all of the background-color pixels on the first          /* This loop draws  all of the background-color pixels on the first */
         // pass, and all of the fill-color pixels on the second.          /* pass, and all of the fill-color pixels on the second. */
         for (Match = 0; Match < 0x100; Match += 0x80)          for (Match = 0; Match < 0x100; Match += 0x80)
         {          {
                 if (Match)                  if (Match)
Line 1712  getfillpattern (char *upattern) /* {{{ *
Line 1713  getfillpattern (char *upattern) /* {{{ *
                 upattern[i] = TcUserFillPattern[i];                  upattern[i] = TcUserFillPattern[i];
 } /* }}} */  } /* }}} */
   
 // These are setfillpattern-compatible arrays for all of the tiling patterns.  /* These are setfillpattern-compatible arrays for all of the tiling patterns. */
 static guchar FillStyles[12][8] = { /* {{{ */  static guchar FillStyles[12][8] = { /* {{{ */
         {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},          {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
         {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},          {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
Line 1731  static guchar FillStyles[12][8] = { /* {
Line 1732  static guchar FillStyles[12][8] = { /* {
         void          void
 setfillstyle (int pattern, int color) /* {{{ */  setfillstyle (int pattern, int color) /* {{{ */
 {  {
         // An input value of USER_FILL isn't actually legal, but it's convenient          /* An input value of USER_FILL isn't actually legal, but it's convenient */
         // for us to use it (in conjunction with setbkcolor).          /* for us to use it (in conjunction with setbkcolor). */
         if (pattern < 0 || pattern > USER_FILL)          if (pattern < 0 || pattern > USER_FILL)
         {          {
                 TcGraphResult = grError;                  TcGraphResult = grError;
Line 1887  Error:
Line 1888  Error:
                         if (colornum < 0 || colornum > 15 || color > 63)                          if (colornum < 0 || colornum > 15 || color > 63)
                                 goto Error;                                  goto Error;
 Palette16:  Palette16:
                         // We *assume* that the allowable colors (0-63) are just                          /* We *assume* that the allowable colors (0-63) are just */
                         // scaled versions of the usual 16 colors.                          /* scaled versions of the usual 16 colors. */
                         Scale = 0x40 * (1 + (color / 16));                          Scale = 0x40 * (1 + (color / 16));
                         color = color % 16;                          color = color % 16;
                         TcColors[colornum].r = (TcColors16[color].r / 0x100) * Scale;                          TcColors[colornum].r = (TcColors16[color].r / 0x100) * Scale;
Line 1986  setviewport (int left, int top, int righ
Line 1987  setviewport (int left, int top, int righ
         TcViewMaxy = bottom - top;          TcViewMaxy = bottom - top;
         TcViewClip = clip;          TcViewClip = clip;
         Tcx = Tcy = 0;          Tcx = Tcy = 0;
         // Account for clipping.  Fortunately, this can be done entirely          /* Account for clipping.  Fortunately, this can be done entirely */
         // within X, by setting the clipping region within the graphics          /* within X, by setting the clipping region within the graphics */
         // context.          /* context. */
         if (clip)          if (clip)
         {          {
                 Rectangle.x = left;                  Rectangle.x = left;
Line 2038  setwritemode (int mode) /* {{{ */
Line 2039  setwritemode (int mode) /* {{{ */
         int          int
 textwidth (char * textstring) /* {{{ */  textwidth (char * textstring) /* {{{ */
 {  {
         // Handle the bitmapped font separately, since it's so easy.          /* Handle the bitmapped font separately, since it's so easy. */
         if (TcTextFont == DEFAULT_FONT)          if (TcTextFont == DEFAULT_FONT)
                 return (8 * strlen (textstring) * TcTextCharsize);                  return (8 * strlen (textstring) * TcTextCharsize);
         // Handle the stroke fonts here.          /* Handle the stroke fonts here. */
         //#warning Stroke fonts not implemented yet. Ignore warnings about textwidth.          /*#warning Stroke fonts not implemented yet. Ignore warnings about textwidth. */
         return 0;          return 0;
 } /* }}} */  } /* }}} */
   
         int          int
 textheight (char * textstring) /* {{{ */  textheight (char * textstring) /* {{{ */
 {  {
         // Handle the bitmapped font separately, since it's so easy.          /* Handle the bitmapped font separately, since it's so easy. */
         if (TcTextFont == DEFAULT_FONT)          if (TcTextFont == DEFAULT_FONT)
                 return (8 * TcTextCharsize);                  return (8 * TcTextCharsize);
         // Handle the stroke fonts here.          /* Handle the stroke fonts here. */
         //#warning Stroke fonts not implemented yet. Ignore warnings about textheight.          /*#warning Stroke fonts not implemented yet. Ignore warnings about textheight. */
         return 0;          return 0;
 } /* }}} */  } /* }}} */
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top