1
0

DOCK.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "main.h"
  9. void FixMainWindowRect(RECT *r)
  10. {
  11. if (r->right-r->left > 280)
  12. {
  13. if (r->bottom-r->top < 200)
  14. r->bottom=r->top+14*2;
  15. }
  16. else
  17. {
  18. if (r->bottom-r->top < 100)
  19. r->bottom=r->top+14;
  20. }
  21. }
  22. void EstMainWindowRect( RECT *r )
  23. {
  24. r->left = config_wx;
  25. r->top = config_wy;
  26. r->right = config_wx + ( WINDOW_WIDTH << ( config_dsize ? 1 : 0 ) );
  27. r->bottom = config_wy + ( ( config_windowshade ? 14 : WINDOW_HEIGHT ) << ( config_dsize ? 1 : 0 ) );
  28. }
  29. void EstEQWindowRect( RECT *r )
  30. {
  31. r->left = config_eq_wx;
  32. r->top = config_eq_wy;
  33. r->right = config_eq_wx + ( WINDOW_WIDTH << ( config_dsize && config_eqdsize ? 1 : 0 ) );
  34. r->bottom = config_eq_wy + ( ( config_eq_ws ? 14 : WINDOW_HEIGHT ) << ( config_dsize && config_eqdsize ? 1 : 0 ) );
  35. }
  36. void EstPLWindowRect( RECT *r )
  37. {
  38. r->left = config_pe_wx;
  39. r->top = config_pe_wy;
  40. r->right = config_pe_wx + config_pe_width;
  41. r->bottom = config_pe_wy + config_pe_height;
  42. }
  43. void EstVidWindowRect( RECT *r )
  44. {
  45. r->left = config_video_wx;
  46. r->top = config_video_wy;
  47. r->right = config_video_wx + config_video_width;
  48. r->bottom = config_video_wy + config_video_height;
  49. }
  50. void SetMainWindowRect(RECT *r)
  51. {
  52. config_wx=r->left;
  53. config_wy=r->top;
  54. }
  55. void SetEQWindowRect(RECT *r)
  56. {
  57. config_eq_wx=r->left;
  58. config_eq_wy=r->top;
  59. }
  60. void SetPLWindowRect(RECT *r)
  61. {
  62. config_pe_wx=r->left;
  63. config_pe_wy=r->top;
  64. }
  65. void SetVidWindowRect(RECT *r)
  66. {
  67. config_video_wx=r->left;
  68. config_video_wy=r->top;
  69. }
  70. void MoveRect(RECT *r, int x, int y)
  71. {
  72. r->left+=x;
  73. r->right+=x;
  74. r->top+=y;
  75. r->bottom+=y;
  76. }
  77. int IsWindowAttached(RECT rc, RECT rc2)
  78. {
  79. #define INREG(x,l,h) ((x) >= (l) && (x) <= (h))
  80. int r=0;
  81. if (rc2.right == rc.left || rc2.left == rc.right)
  82. {
  83. if (INREG(rc.top,rc2.top,rc2.bottom) || INREG(rc.bottom,rc2.top,rc2.bottom) ||
  84. INREG(rc2.top,rc.top,rc.bottom) || INREG(rc2.bottom,rc.top,rc.bottom))
  85. r|=1;
  86. }
  87. if (rc2.bottom == rc.top || rc2.top == rc.bottom)
  88. {
  89. if (INREG(rc2.left,rc.left,rc.right) || INREG(rc2.right,rc.left,rc.right) ||
  90. INREG(rc.left,rc2.left,rc2.right) || INREG(rc.right,rc2.left,rc2.right))
  91. r|=2;
  92. }
  93. #undef INREG
  94. return r;
  95. }
  96. void SnapWindowToWindow(RECT *rcSrc, RECT rcDest)
  97. {
  98. #define INREG(x,l,h) ((x) >= (l) && (x) <= (h))
  99. #define IRR(l1,r1,l2,r2) (INREG(l1,l2,r2)||INREG(r1,l2,r2)||INREG(l2,l1,r1)||INREG(r2,l1,r1))
  100. #define CLOSETO(x,t) INREG(x,t-config_snaplen,t+config_snaplen)
  101. if (IRR(rcDest.left,rcDest.right,rcSrc->left,rcSrc->right))
  102. {
  103. if (CLOSETO(rcSrc->top,rcDest.bottom))
  104. {
  105. rcSrc->bottom+=rcDest.bottom-rcSrc->top;
  106. rcSrc->top=rcDest.bottom;
  107. }
  108. else if (CLOSETO(rcSrc->bottom,rcDest.top))
  109. {
  110. rcSrc->top=rcDest.top-(rcSrc->bottom-rcSrc->top);
  111. rcSrc->bottom=rcDest.top;
  112. }
  113. }
  114. if (IRR(rcDest.top,rcDest.bottom,rcSrc->top,rcSrc->bottom))
  115. {
  116. if (CLOSETO(rcSrc->right,rcDest.left))
  117. {
  118. rcSrc->left = rcDest.left-(rcSrc->right-rcSrc->left);
  119. rcSrc->right= rcDest.left;
  120. }
  121. else if (CLOSETO(rcSrc->left,rcDest.right))
  122. {
  123. rcSrc->right += (rcDest.right-rcSrc->left);
  124. rcSrc->left=rcDest.right;
  125. }
  126. }
  127. if (rcSrc->right == rcDest.left || rcSrc->left== rcDest.right)
  128. {
  129. if (CLOSETO(rcSrc->top,rcDest.top))
  130. {
  131. rcSrc->bottom += rcDest.top-rcSrc->top;
  132. rcSrc->top = rcDest.top;
  133. }
  134. else if (CLOSETO(rcSrc->bottom,rcDest.bottom))
  135. {
  136. rcSrc->top += rcDest.bottom-rcSrc->bottom;
  137. rcSrc->bottom=rcDest.bottom;
  138. }
  139. }
  140. if (rcSrc->bottom == rcDest.top || rcSrc->top == rcDest.bottom)
  141. {
  142. if (CLOSETO(rcSrc->left,rcDest.left))
  143. {
  144. rcSrc->right += rcDest.left-rcSrc->left;
  145. rcSrc->left = rcDest.left;
  146. }
  147. else if (CLOSETO(rcSrc->right,rcDest.right))
  148. {
  149. rcSrc->left += rcDest.right-rcSrc->right;
  150. rcSrc->right = rcDest.right;
  151. }
  152. }
  153. #undef INREG
  154. #undef IRR
  155. #undef CLOSETO
  156. }
  157. void AdjustSnap(RECT old1, RECT old2, RECT *new1, RECT *new2)
  158. {
  159. #define INREG(x,l,h) ((x) >= (l) && (x) < (h))
  160. if (INREG(old1.top,old2.top,old2.bottom) || INREG(old2.top,old1.top,old1.bottom)) {
  161. #undef INREG
  162. // xpos
  163. if (old1.right >= old2.left && old1.left < old2.right) // old1/old2
  164. {
  165. MoveRect(new1,(new2->left-(new1->right-new1->left)) - new1->left,0);
  166. }
  167. else if (old2.right >= old1.left && old2.left < old1.right) // old2/old1
  168. {
  169. MoveRect(new2,(new1->left-(new2->right-new2->left)) - new2->left,0);
  170. }
  171. }
  172. #define INREG(x,l,h) ((x) >= (l) && (x) < (h))
  173. if (INREG(old1.left,old2.left,old2.right) || INREG(old2.left,old1.left,old1.right)) {
  174. #undef INREG
  175. // ypos
  176. if (old1.bottom >= old2.top && old1.top < old2.bottom) // old1/old2
  177. {
  178. MoveRect(new1,0,(new2->top-(new1->bottom-new1->top)) - new1->top);
  179. }
  180. else if (old2.bottom >= old1.top && old2.top < old1.bottom) // old2/old1
  181. {
  182. MoveRect(new2,0,(new1->top-(new2->bottom-new2->top)) - new2->top);
  183. }
  184. }
  185. }
  186. int IsPointInRect(int x, int y, RECT *r)
  187. {
  188. if (x >= r->left && x < r->right && y >= r->top && y < r->bottom)
  189. return 1;
  190. return 0;
  191. }
  192. void FixOverlaps(RECT *r1, RECT *r2)
  193. {
  194. if (r1->left >= r2->left) // r1 - r2
  195. {
  196. RECT *t=r1;
  197. r1=r2;
  198. r2=t;
  199. }
  200. {
  201. if (IsPointInRect(r2->left,r2->top,r1))
  202. {
  203. if (r1->right-r2->left < r1->bottom-r2->top)
  204. {
  205. MoveRect(r2,r1->right-r2->left,0);
  206. }
  207. else
  208. {
  209. MoveRect(r2,0,r1->bottom-r2->top);
  210. }
  211. }
  212. }
  213. }