Source code of Windows XP (NT5)
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.

119 lines
4.6 KiB

  1. #ifndef CALCMACR_H
  2. #define CALCMACR_H
  3. #ifndef LK_CODE_INCLUDED
  4. #include "lk_code.h"
  5. #endif
  6. /* Useful non-portable macros (on other platform they may need */
  7. /* to be redefined, though this is almost unprobable): */
  8. /* The following macros are applicable only to positive */
  9. /* integer-type values: */
  10. #define wODD(w) ((w)&1)
  11. #define wEVEN(w) (!wODD(w))
  12. #define ONE_HALF(X) ( (X) >> 1 )
  13. #define ONE_THIRD(X) ( ((X)+1) / 3 )
  14. #define TWO_THIRD(X) ( (((X)<<1)+1) / 3 )
  15. #define ONE_FOURTH(X) ( ((X)+2) >> 2 )
  16. #define ONE_FIFTH(X) ( ((X) + 2) / 5 )
  17. #define TWO_FIFTH(X) ( (((X)<<1) + 2) / 5 )
  18. #define ONE_EIGHTTH(X) ( ((X) + 4) >> 3 )
  19. #define ONE_NTH(X,N) ( ((X) + ONE_HALF(N)) / (N) )
  20. #define MULT_RATIO(X,NMR,DNM) ( ((X)*NMR + ONE_HALF(DNM)) / (DNM) )
  21. #define TWO(X) ( (X) << 1 )
  22. #define FOUR(X) ( (X) << 2 )
  23. #define EIGHT(X) ( (X) << 3 )
  24. #ifdef __cplusplus
  25. inline _INT THREE_HALF(_SHORT X) { return (X + ONE_HALF(X)); }
  26. inline _INT THREE_HALF(_INT X) { return (X + ONE_HALF(X)); }
  27. inline _LONG THREE_HALF(_LONG X) { return (X + ONE_HALF(X)); }
  28. inline _INT FOUR_THIRD(_SHORT X) { return (X + ONE_THIRD(X)); }
  29. inline _INT FOUR_THIRD(_INT X) { return (X + ONE_THIRD(X)); }
  30. inline _LONG FOUR_THIRD(_LONG X) { return (X + ONE_THIRD(X)); }
  31. inline _INT THREE_FOURTH(_SHORT X) { return (X - ONE_FOURTH(X)); }
  32. inline _INT THREE_FOURTH(_INT X) { return (X - ONE_FOURTH(X)); }
  33. inline _LONG THREE_FOURTH(_LONG X) { return (X - ONE_FOURTH(X)); }
  34. inline _INT FIVE_FOURTH(_SHORT X) { return (X + ONE_FOURTH(X)); }
  35. inline _INT FIVE_FOURTH(_INT X) { return (X + ONE_FOURTH(X)); }
  36. inline _LONG FIVE_FOURTH(_LONG X) { return (X + ONE_FOURTH(X)); }
  37. inline _INT FOUR_FIFTH(_SHORT X) { return (X - ONE_FIFTH(X)); }
  38. inline _INT FOUR_FIFTH(_INT X) { return (X - ONE_FIFTH(X)); }
  39. inline _LONG FOUR_FIFTH(_LONG X) { return (X - ONE_FIFTH(X)); }
  40. inline _INT THREE(_SHORT X) { return (X + TWO(X)); }
  41. inline _INT THREE(_INT X) { return (X + TWO(X)); }
  42. inline _LONG THREE(_LONG X) { return (X + TWO(X)); }
  43. inline _INT FIVE(_SHORT X) { return (X + FOUR(X)); }
  44. inline _INT FIVE(_INT X) { return (X + FOUR(X)); }
  45. inline _LONG FIVE(_LONG X) { return (X + FOUR(X)); }
  46. #else /* !__cplusplus */
  47. #define THREE_HALF(X) ( (X) + ONE_HALF(X) )
  48. #define FOUR_THIRD(X) ( (X) + ONE_THIRD(X) )
  49. #define THREE_FOURTH(X) ( (X) - ONE_FOURTH(X) )
  50. #define FIVE_FOURTH(X) ( (X) + ONE_FOURTH(X) )
  51. #define FOUR_FIFTH(X) ( (X) - ONE_FIFTH(X) )
  52. #define THREE(X) ( (X) + TWO(X) )
  53. #define FIVE(X) ( (X) + FOUR(X) )
  54. #endif /* !__cplusplus */
  55. #define TO_TWO_TIMES(X) {(X) <<= 1;}
  56. #define TO_THREE_TIMES(X) {(X) += ((X)<<1);}
  57. /***************************************/
  58. /* Useful portable macros: */
  59. #define DX_RECT(rect) ((rect).right - (rect).left)
  60. #define DY_RECT(rect) ((rect).bottom - (rect).top)
  61. #define XMID_RECT(rect) ONE_HALF((rect).left + (rect).right)
  62. #define YMID_RECT(rect) ONE_HALF((rect).top + (rect).bottom)
  63. #define SWAP_SHORTS(w1,w2) {_SHORT w; w=w1; w1=w2; w2=w;}
  64. #define SWAP_INTS(w1,w2) {_INT w; w=w1; w1=w2; w2=w;}
  65. #define EQ_SIGN(X,Y) (((X)>=0) == ((Y)>=0))
  66. #define TO_ABS_VALUE(X) {if ((X) < 0) (X) = -(X);}
  67. #define MEAN_OF(X,Y) ONE_HALF((X) + (Y))
  68. /***************************************/
  69. /* Useful macros for lower level: */
  70. #define MID_POINT(elem) MEAN_OF(REF(elem)->ibeg,REF(elem)->iend)
  71. #define NO_ATTR_ASSIGNED(elem) (!(REF(elem)->attr))
  72. #define CLEAR_ATTR(elem) {CHECK_PTR(elem); (elem)->attr = 0;}
  73. #define HEIGHT_OF(elem) (REF(elem)->attr & _umd_)
  74. #define ASSIGN_HEIGHT(elem,h) (elem)->attr = (REF(elem)->attr&(~_umd_)) | (((_UCHAR)(h))&_umd_) /*Should be ";"*/
  75. #define CIRCLE_DIR(elem) (REF(elem)->attr & _fb_)
  76. #define CLOCKWISE(elem) (CIRCLE_DIR(elem) == _f_)
  77. #define COUNTERCLOCKWISE(elem) (CIRCLE_DIR(elem) == _b_)
  78. #define ASSIGN_CIRCLE_DIR(elem,FB) (elem)->attr = (REF(elem)->attr&(~_fb_)) | (((_UCHAR)(FB))&_fb_) /*Should be ";"*/
  79. #define SET_CLOCKWISE(elem) ASSIGN_CIRCLE_DIR(elem,_f_)
  80. #define SET_COUNTERCLOCKWISE(elem) ASSIGN_CIRCLE_DIR(elem,_b_)
  81. #define SET_OVR(elem) {CHECK_PTR(elem); (elem)->attr |= _OVR_;}
  82. #define CLEAR_OVR(elem) {CHECK_PTR(elem); (elem)->attr &= (~_OVR_);}
  83. #endif /*CALCMACR_H*/