Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.6 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: linedda.c
  3. *
  4. * (Brief description)
  5. *
  6. * Created: 04-Jan-1991 09:23:30
  7. * Author: Eric Kutter [erick]
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. *
  11. * (General description of its use)
  12. *
  13. * Dependencies:
  14. *
  15. * (#defines)
  16. *
  17. \**************************************************************************/
  18. #include "precomp.h"
  19. #pragma hdrstop
  20. /******************************Public*Routine******************************\
  21. * BOOL WINAPI InnerLineDDA(x1,y1,x2,y2,pfn,pvUserData)
  22. *
  23. * This routine is basic version of Bressenhams Algorithm for drawing lines.
  24. * For each point, pfn is called with that point and the user passed in
  25. * data pointer, pvUserData. This call is device independant and does no
  26. * scaling or rotating. This wouldn't be possible since there is no
  27. * DC passed in. It is probably an old artifact of Windows 1.0. It is
  28. * strictly a client side function.
  29. *
  30. * return value is TRUE unless pfn is NULL.
  31. *
  32. * History:
  33. * 07-Jan-1991 -by- Eric Kutter [erick]
  34. * Wrote it.
  35. \**************************************************************************/
  36. BOOL WINAPI LineDDA(
  37. int x1,
  38. int y1,
  39. int x2,
  40. int y2,
  41. LINEDDAPROC pfn,
  42. LPARAM UserData)
  43. {
  44. int dx;
  45. int xinc;
  46. int dy;
  47. int yinc;
  48. int iError;
  49. int cx;
  50. if (pfn == (LINEDDAPROC)NULL)
  51. return(FALSE);
  52. dx = x2 - x1;
  53. xinc = 1;
  54. if (dx <= 0)
  55. {
  56. xinc = -xinc;
  57. dx = -dx;
  58. }
  59. // prepare for ascending y
  60. dy = y2 - y1;
  61. yinc = 1;
  62. iError = 0;
  63. // if decending
  64. if (dy <= 0)
  65. {
  66. yinc = -yinc;
  67. dy = -dy;
  68. //iError = 0; // in the win3.0 version, this is a 1 but it seems
  69. } // to give wierd results.
  70. // y Major
  71. if (dy >= dx)
  72. {
  73. iError = (iError + dy) / 2;
  74. cx = dy;
  75. while (cx--)
  76. {
  77. (*pfn)(x1,y1,UserData);
  78. y1 += yinc;
  79. iError -= dx;
  80. if (iError < 0)
  81. {
  82. iError += dy;
  83. x1 += xinc;
  84. }
  85. }
  86. }
  87. else
  88. {
  89. // x Major
  90. iError = (iError + dx) / 2;
  91. cx = dx;
  92. while (cx--)
  93. {
  94. (*pfn)(x1,y1,UserData);
  95. x1 += xinc;
  96. iError -= dy;
  97. if (iError < 0)
  98. {
  99. iError += dx;
  100. y1 += yinc;
  101. }
  102. }
  103. }
  104. return(TRUE);
  105. }