draw_embed.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #include "draw.h"
  10. HBITMAP embedBM;
  11. int titlebar_font_widths[26] = {0};
  12. int titlebar_font_offsets[26] = {0};
  13. int titlebar_font_num_widths[12] = {0};
  14. int titlebar_font_num_offsets[12] = {0};
  15. int titlebar_font_unknown_width = 5;
  16. static int calcTBFontTextWidth(char *text)
  17. {
  18. int w=0;
  19. while (text && *text)
  20. {
  21. char c=*text++;
  22. if (c >= 'a' && c <= 'z') c+='A'-'a';
  23. if (c >= 'A' && c <= 'Z' && titlebar_font_widths[c-'A'])
  24. w+=titlebar_font_widths[c-'A'];
  25. else if (c >= '0' && c <= '9' && titlebar_font_widths[c-'0'] && Skin_UseGenNums)
  26. w+=titlebar_font_num_widths[c-'0'];
  27. else if (c == '-' && titlebar_font_widths[10] && Skin_UseGenNums)
  28. w+=titlebar_font_num_widths[10];
  29. else if (c == ':' && titlebar_font_widths[11] && Skin_UseGenNums)
  30. w+=titlebar_font_num_widths[11];
  31. else w+=titlebar_font_unknown_width;
  32. }
  33. return w;
  34. }
  35. static void drawTBText(HDC hdcout,int xp, int yp, char *buf, int maxw, int sel)
  36. {
  37. while (buf && *buf)
  38. {
  39. char c=*buf++;
  40. int w=titlebar_font_unknown_width;
  41. if (c >= 'a' && c <= 'z') c+='A'-'a';
  42. if (c >= 'A' && c <= 'Z' && titlebar_font_widths[c-'A'])
  43. {
  44. w=titlebar_font_widths[c-'A'];
  45. if (w > maxw) break;
  46. BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_offsets[c-'A'],88+(sel?8:0),SRCCOPY);
  47. }
  48. else if (c >= '0' && c <= '9' && titlebar_font_num_widths[c-'0'] && Skin_UseGenNums)
  49. {
  50. w=titlebar_font_num_widths[c-'0'];
  51. if (w > maxw) break;
  52. BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_num_offsets[c-'0'],72+(sel?8:0),SRCCOPY);
  53. }
  54. else if (c == '-' && titlebar_font_num_widths[10] && Skin_UseGenNums)
  55. {
  56. w=titlebar_font_num_widths[10];
  57. if (w > maxw) break;
  58. BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_num_offsets[10],72+(sel?8:0),SRCCOPY);
  59. }
  60. else if (c == ':' && titlebar_font_num_widths[11] && Skin_UseGenNums)
  61. {
  62. w=titlebar_font_num_widths[11];
  63. if (w > maxw) break;
  64. BitBlt(hdcout,xp,yp,w,7,bmDC,titlebar_font_num_offsets[11],72+(sel?8:0),SRCCOPY);
  65. }
  66. xp+=w;
  67. maxw-=w;
  68. }
  69. }
  70. void draw_embed_tbar(HWND hwnd, int state, int w)
  71. {
  72. if (!disable_skin_borders)
  73. {
  74. HDC hdcout=GetWindowDC(hwnd);
  75. char buf[32] = {0};
  76. state = state?0:21;
  77. do_palmode(hdcout);
  78. setSrcBM(embedBM);
  79. GetWindowTextA(hwnd,buf,sizeof(buf)/sizeof(char)-1);
  80. buf[31]=0;
  81. {
  82. int textw_exact=calcTBFontTextWidth(buf);
  83. int nt;
  84. int xp=0;
  85. int textw=textw_exact + 24;
  86. textw -= textw % 25;
  87. if (textw > w-100) textw=w-100;
  88. BitBlt(hdcout,xp,0,25,20,bmDC,0,state,SRCCOPY);
  89. xp+=25;
  90. nt = (w - 100 - textw)/25;
  91. if (nt)
  92. {
  93. if (nt&1)
  94. {
  95. BitBlt(hdcout,xp,0,12,20,bmDC,104,state,SRCCOPY);
  96. xp+=12;
  97. }
  98. nt/=2;
  99. while (nt-->0)
  100. {
  101. BitBlt(hdcout,xp,0,25,20,bmDC,104,state,SRCCOPY);
  102. xp+=25;
  103. }
  104. }
  105. BitBlt(hdcout,xp,0,25,20,bmDC,26,state,SRCCOPY);
  106. xp+=25;
  107. nt = textw/25;
  108. if (nt)
  109. {
  110. int xstart=xp + (textw - textw_exact)/2;
  111. if (textw != textw_exact) xstart++;
  112. while (nt-->0)
  113. {
  114. BitBlt(hdcout,xp,0,25,20,bmDC,52,state,SRCCOPY);
  115. xp+=25;
  116. }
  117. drawTBText(hdcout,xstart,4,buf,textw,state);
  118. }
  119. BitBlt(hdcout,xp,0,25,20,bmDC,78,state,SRCCOPY);
  120. xp+=25;
  121. nt = (w - 100 - textw)/25;
  122. if (nt)
  123. {
  124. if (nt&1)
  125. {
  126. BitBlt(hdcout,xp,0,13,20,bmDC,104,state,SRCCOPY);
  127. xp+=13;
  128. }
  129. nt/=2;
  130. while (nt-->0)
  131. {
  132. BitBlt(hdcout,xp,0,25,20,bmDC,104,state,SRCCOPY);
  133. xp+=25;
  134. }
  135. }
  136. nt = (w - 100 - textw) % 25;
  137. if (nt>0)
  138. {
  139. StretchBlt(hdcout,xp,0,nt,20,bmDC,104,state,25,20,SRCCOPY);
  140. xp+=nt;
  141. }
  142. BitBlt(hdcout,xp,0,25,20,bmDC,130,state,SRCCOPY);
  143. }
  144. unsetSrcBM();
  145. ReleaseDC(hwnd,hdcout);
  146. }
  147. }
  148. void draw_embed(HWND hwnd, HDC hdcout, int w, int h, int flags)
  149. {
  150. if (!disable_skin_borders)
  151. {
  152. do_palmode(hdcout);
  153. {
  154. // fg>this is here in case a child temporarily unparents itself from the embedwnd, like avs when it docks to its editor.
  155. // when the child is there, fillrect is clipped
  156. RECT r={11,20,w-8, h-14};
  157. FillRect(hdcout, &r, (HBRUSH)GetStockObject(BLACK_BRUSH));
  158. }
  159. draw_embed_tbar(hwnd,GetForegroundWindow()==hwnd?1:(config_hilite?0:1),w);
  160. setSrcBM(embedBM);
  161. {
  162. int y=(h-20-38)/29;
  163. int yp=20,x,xp;
  164. while (y-->0)
  165. {
  166. BitBlt(hdcout,0,yp,11,29,bmDC,127,42,SRCCOPY);
  167. BitBlt(hdcout,w-8,yp,8,29,bmDC,139,42,SRCCOPY);
  168. yp += 29;
  169. }
  170. y=(h-20-38)%29;
  171. if (y)
  172. {
  173. StretchBlt(hdcout,0,yp,11,y,bmDC,127,42,11,29,SRCCOPY);
  174. StretchBlt(hdcout,w-8,yp,8,y,bmDC,139,42,8,29,SRCCOPY);
  175. yp += y;
  176. }
  177. // 24 pixel lamity
  178. BitBlt(hdcout,0,yp,11,24,bmDC,158,42,SRCCOPY);
  179. BitBlt(hdcout,w-8,yp,8,24,bmDC,170,42,SRCCOPY);
  180. yp += 24;
  181. BitBlt(hdcout,0,yp,125,14,bmDC,0,42,SRCCOPY);
  182. x=(w-125-125)/25;
  183. xp=125;
  184. while (x-->0)
  185. {
  186. BitBlt(hdcout,xp,yp,25,14,bmDC,127,72,SRCCOPY);
  187. xp+=25;
  188. }
  189. x=(w-125-125)%25;
  190. if (x)
  191. {
  192. StretchBlt(hdcout,xp,yp,x,14,bmDC,127,72,25,14,SRCCOPY);
  193. xp+=x;
  194. }
  195. BitBlt(hdcout,xp,yp,125,14,bmDC,0,57,SRCCOPY);
  196. if (flags & EMBED_FLAGS_NORESIZE)
  197. {
  198. BitBlt(hdcout,xp+112,yp+2,7,7,bmDC,118,72,SRCCOPY);
  199. }
  200. }
  201. unsetSrcBM();
  202. }
  203. }
  204. void draw_paint_emb(HWND hwnd, int w, int h, int flags)
  205. {
  206. PAINTSTRUCT ps;
  207. draw_embed(hwnd,BeginPaint(hwnd,&ps),w,h,flags);
  208. EndPaint(hwnd,&ps);
  209. }
  210. void draw_embed_tbutton(HWND hwnd, int b3, int w)
  211. {
  212. if (!disable_skin_borders)
  213. {
  214. HDC hdcout=GetWindowDC(hwnd);
  215. do_palmode(hdcout);
  216. setSrcBM(embedBM);
  217. if (!b3)
  218. BitBlt(hdcout,w-11,3,9,9,bmDC,144,3,SRCCOPY);
  219. else
  220. BitBlt(hdcout,w-11,3,9,9,bmDC,148,42,SRCCOPY);
  221. unsetSrcBM();
  222. ReleaseDC(hwnd,hdcout);
  223. }
  224. }