data.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. #include <thread.h>
  13. #include <cursor.h>
  14. #include <mouse.h>
  15. #include <keyboard.h>
  16. #include <frame.h>
  17. #include <fcall.h>
  18. #include <jay.h>
  19. #include "dat.h"
  20. #include "fns.h"
  21. Cursor crosscursor = {
  22. {-7, -7},
  23. {0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
  24. 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE,
  25. 0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
  26. 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, },
  27. {0x01, 0x80, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
  28. 0x02, 0x40, 0x02, 0x40, 0x7E, 0x7E, 0x80, 0x01,
  29. 0x80, 0x01, 0x7E, 0x7E, 0x02, 0x40, 0x02, 0x40,
  30. 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x01, 0x80, },
  31. };
  32. Cursor boxcursor = {
  33. {-7, -7},
  34. {0x00, 0x00, 0x01, 0x80, 0x03, 0xC0, 0x01, 0x80,
  35. 0x01, 0x80, 0x01, 0x80, 0x21, 0x84, 0x7E, 0x7E,
  36. 0x7E, 0x7E, 0x21, 0x84, 0x01, 0x80, 0x01, 0x80,
  37. 0x01, 0x80, 0x03, 0xC0, 0x01, 0x80, 0x00, 0x00, },
  38. {0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x06, 0x60,
  39. 0x02, 0x40, 0x32, 0x4C, 0x5E, 0x7A, 0x80, 0x01,
  40. 0x80, 0x01, 0x5E, 0x7A, 0x32, 0x4C, 0x02, 0x40,
  41. 0x06, 0x60, 0x04, 0x20, 0x02, 0x40, 0x01, 0x80,}
  42. };
  43. Cursor sightcursor = {
  44. {-7, -7},
  45. {0x00, 0x00, 0x78, 0x1E, 0x40, 0x02, 0x40, 0x02,
  46. 0x41, 0x82, 0x01, 0x80, 0x01, 0x80, 0x0F, 0xF0,
  47. 0x0F, 0xF0, 0x01, 0x80, 0x01, 0x80, 0x41, 0x82,
  48. 0x40, 0x02, 0x40, 0x02, 0x78, 0x1E, 0x00, 0x00, },
  49. {0x78, 0x1E, 0x84, 0x21, 0xB8, 0x1D, 0xA1, 0x85,
  50. 0xA2, 0x45, 0x42, 0x42, 0x0E, 0x70, 0x10, 0x08,
  51. 0x10, 0x08, 0x0E, 0x70, 0x42, 0x42, 0xA2, 0x45,
  52. 0xA1, 0x85, 0xB8, 0x1D, 0x84, 0x21, 0x78, 0x1E, },
  53. };
  54. Cursor whitearrow = {
  55. {-2, 0},
  56. {0x20, 0x00, 0x30, 0x00, 0x28, 0x00, 0x24, 0x00,
  57. 0x22, 0x00, 0x21, 0x00, 0x20, 0x80, 0x20, 0x40,
  58. 0x20, 0x20, 0x20, 0x10, 0x21, 0xF8, 0x22, 0x00,
  59. 0x24, 0x00, 0x28, 0x00, 0x30, 0x00, 0x20, 0x00, },
  60. {0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x18, 0x00,
  61. 0x1C, 0x00, 0x1E, 0x00, 0x1F, 0x00, 0x1F, 0x80,
  62. 0x1F, 0xC0, 0x1F, 0xE0, 0x1E, 0x00, 0x1C, 0x00,
  63. 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, },
  64. };
  65. Cursor defcursor = {
  66. {-2, 0},
  67. {0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x18, 0x00,
  68. 0x1C, 0x00, 0x1E, 0x00, 0x1F, 0x00, 0x1F, 0x80,
  69. 0x1F, 0xC0, 0x1F, 0xE0, 0x1E, 0x00, 0x1C, 0x00,
  70. 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, },
  71. {0x20, 0x00, 0x30, 0x00, 0x28, 0x00, 0x24, 0x00,
  72. 0x22, 0x00, 0x21, 0x00, 0x20, 0x80, 0x20, 0x40,
  73. 0x20, 0x20, 0x20, 0x10, 0x21, 0xF8, 0x22, 0x00,
  74. 0x24, 0x00, 0x28, 0x00, 0x30, 0x00, 0x20, 0x00, },
  75. };
  76. Cursor query = {
  77. {-7,-7},
  78. {0x0f, 0xf0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe,
  79. 0x7c, 0x7e, 0x78, 0x7e, 0x00, 0xfc, 0x01, 0xf8,
  80. 0x03, 0xf0, 0x07, 0xe0, 0x07, 0xc0, 0x07, 0xc0,
  81. 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, },
  82. {0x00, 0x00, 0x0f, 0xf0, 0x1f, 0xf8, 0x3c, 0x3c,
  83. 0x38, 0x1c, 0x00, 0x3c, 0x00, 0x78, 0x00, 0xf0,
  84. 0x01, 0xe0, 0x03, 0xc0, 0x03, 0x80, 0x03, 0x80,
  85. 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x00, }
  86. };
  87. Cursor tl = {
  88. {-6, -6},
  89. {0x00, 0x00, 0x78, 0x00, 0x60, 0x00, 0x50, 0x00,
  90. 0x48, 0x00, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00,
  91. 0x00, 0x00, 0x00, 0x40, 0x00, 0x20, 0x00, 0x12,
  92. 0x00, 0x0A, 0x00, 0x06, 0x00, 0x1E, 0x00, 0x00, },
  93. {0xFC, 0x00, 0x84, 0x00, 0x9C, 0x00, 0xAC, 0x00,
  94. 0xB6, 0x00, 0xFB, 0x00, 0x0D, 0x00, 0x07, 0x00,
  95. 0x00, 0xE0, 0x00, 0xB0, 0x00, 0xDF, 0x00, 0x6D,
  96. 0x00, 0x35, 0x00, 0x39, 0x00, 0x21, 0x00, 0x3F, },
  97. };
  98. Cursor t = {
  99. {-7, -8},
  100. {0x00, 0x00, 0x01, 0x80, 0x03, 0xC0, 0x01, 0x80,
  101. 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00,
  102. 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
  103. 0x01, 0x80, 0x03, 0xC0, 0x01, 0x80, 0x00, 0x00, },
  104. {0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x06, 0x60,
  105. 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x01, 0x80,
  106. 0x01, 0x80, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
  107. 0x06, 0x60, 0x04, 0x20, 0x02, 0x40, 0x01, 0x80, }
  108. };
  109. Cursor tr = {
  110. {-9, -6},
  111. {0x00, 0x00, 0x00, 0x1E, 0x00, 0x06, 0x00, 0x0A,
  112. 0x00, 0x12, 0x00, 0x20, 0x00, 0x40, 0x00, 0x00,
  113. 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x48, 0x00,
  114. 0x50, 0x00, 0x60, 0x00, 0x78, 0x00, 0x00, 0x00, },
  115. {0x00, 0x3F, 0x00, 0x21, 0x00, 0x39, 0x00, 0x35,
  116. 0x00, 0x6D, 0x00, 0xDF, 0x00, 0xB0, 0x00, 0xE0,
  117. 0x07, 0x00, 0x0D, 0x00, 0xFB, 0x00, 0xB6, 0x00,
  118. 0xAC, 0x00, 0x9C, 0x00, 0x84, 0x00, 0xFC, 0x00, },
  119. };
  120. Cursor r = {
  121. {-8, -7},
  122. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  123. 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x7E, 0x7E,
  124. 0x7E, 0x7E, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00,
  125. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
  126. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  127. 0x00, 0x00, 0x30, 0x0C, 0x5E, 0x7A, 0x81, 0x81,
  128. 0x81, 0x81, 0x5E, 0x7A, 0x30, 0x0C, 0x00, 0x00,
  129. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }
  130. };
  131. Cursor br = {
  132. {-9, -9},
  133. {0x00, 0x00, 0x78, 0x00, 0x60, 0x00, 0x50, 0x00,
  134. 0x48, 0x00, 0x04, 0x00, 0x02, 0x00, 0x00, 0x00,
  135. 0x00, 0x00, 0x00, 0x40, 0x00, 0x20, 0x00, 0x12,
  136. 0x00, 0x0A, 0x00, 0x06, 0x00, 0x1E, 0x00, 0x00, },
  137. {0xFC, 0x00, 0x84, 0x00, 0x9C, 0x00, 0xAC, 0x00,
  138. 0xB6, 0x00, 0xFB, 0x00, 0x0D, 0x00, 0x07, 0x00,
  139. 0x00, 0xE0, 0x00, 0xB0, 0x00, 0xDF, 0x00, 0x6D,
  140. 0x00, 0x35, 0x00, 0x39, 0x00, 0x21, 0x00, 0x3F, },
  141. };
  142. Cursor b = {
  143. {-7, -7},
  144. {0x00, 0x00, 0x01, 0x80, 0x03, 0xC0, 0x01, 0x80,
  145. 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00,
  146. 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
  147. 0x01, 0x80, 0x03, 0xC0, 0x01, 0x80, 0x00, 0x00, },
  148. {0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x06, 0x60,
  149. 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x01, 0x80,
  150. 0x01, 0x80, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
  151. 0x06, 0x60, 0x04, 0x20, 0x02, 0x40, 0x01, 0x80, }
  152. };
  153. Cursor bl = {
  154. {-6, -9},
  155. {0x00, 0x00, 0x00, 0x1E, 0x00, 0x06, 0x00, 0x0A,
  156. 0x00, 0x12, 0x00, 0x20, 0x00, 0x40, 0x00, 0x00,
  157. 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x48, 0x00,
  158. 0x50, 0x00, 0x60, 0x00, 0x78, 0x00, 0x00, 0x00, },
  159. {0x00, 0x3F, 0x00, 0x21, 0x00, 0x39, 0x00, 0x35,
  160. 0x00, 0x6D, 0x00, 0xDF, 0x00, 0xB0, 0x00, 0xE0,
  161. 0x07, 0x00, 0x0D, 0x00, 0xFB, 0x00, 0xB6, 0x00,
  162. 0xAC, 0x00, 0x9C, 0x00, 0x84, 0x00, 0xFC, 0x00, }
  163. };
  164. Cursor l = {
  165. {-7, -7},
  166. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  167. 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x7E, 0x7E,
  168. 0x7E, 0x7E, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00,
  169. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
  170. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  171. 0x00, 0x00, 0x30, 0x0C, 0x5E, 0x7A, 0x81, 0x81,
  172. 0x81, 0x81, 0x5E, 0x7A, 0x30, 0x0C, 0x00, 0x00,
  173. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }
  174. };
  175. Cursor *corners[9] = {
  176. &tl, &t, &tr,
  177. &l, nil, &r,
  178. &bl, &b, &br,
  179. };
  180. int
  181. gettitleheight(){
  182. Point p = stringsize(font, "Á");
  183. return 2 * Borderwidth + p.y;
  184. }
  185. void
  186. initclosebutton(){
  187. int n = gettitleheight() - (2 * Borderwidth);
  188. Rectangle r = Rect(0, 0, n, n);
  189. //closebutton = allocimage(display, r, CMAP8, 1, DRed);
  190. closebutton = allocimage(display, r, CMAP8, 1, jayconfig->windowTitleColor);
  191. closebuttonhoover = allocimage(display, r, CMAP8, 1, 0xD8D8D8FF);
  192. fillellipse(closebutton, Pt((r.min.x + r.max.x)/2,(r.min.y + r.max.y)/2), Dx(r)/2 - 1, Dx(r)/2 - 1, closebuttonhoover, r.min);
  193. //border3d(closebutton, r, 1, wht, blk, r.min);
  194. line(closebutton, Pt(r.min.x + Borderwidth, r.min.y + Borderwidth ), Pt(r.max.x - Borderwidth, r.max.y - Borderwidth), 0, 0, 0, blk, r.min);
  195. line(closebutton, Pt(r.max.x - Borderwidth, r.min.y + Borderwidth ), Pt(r.min.x + Borderwidth, r.max.y - Borderwidth), 0, 0, 0, blk, r.min);
  196. draw(closebuttonhoover, closebutton->r, closebutton, nil, closebutton->r.min);
  197. border3d(closebuttonhoover, r, 1, blk, wht, r.min);
  198. }
  199. void
  200. initmaximizebutton() {
  201. int n = gettitleheight() - (2 * Borderwidth);
  202. Rectangle r = Rect(0, 0, n, n);
  203. //maximizebutton = allocimage(display, r, CMAP8, 1, DGreen);
  204. maximizebutton = allocimage(display, r, CMAP8, 1, jayconfig->windowTitleColor);
  205. maximizebuttonhoover = allocimage(display, r, CMAP8, 1, 0xD8D8D8FF);
  206. fillellipse(maximizebutton, Pt((r.min.x + r.max.x)/2,(r.min.y + r.max.y)/2), Dx(r)/2 - 1, Dx(r)/2 - 1, maximizebuttonhoover, r.min);
  207. ellipse(maximizebutton, Pt((r.min.x + r.max.x)/2,(r.min.y + r.max.y)/2), Dx(r)/2 - 4, Dx(r)/2 - 4, 0, display->black, r.min);
  208. //border3d(maximizebutton, r, 1, wht, blk, r.min);
  209. /*Point x1 = Pt((r.min.x + r.max.x)/2 -1, r.min.y + 2);
  210. Point y1 = Pt((r.min.x + r.max.x)/2 -1, r.max.y - 3);
  211. Point x2 = Pt(r.min.x + 2, (r.min.y + r.max.y)/2 - 1);l
  212. Point y2 = Pt(r.max.x - 3, (r.min.y + r.max.y)/2 - 1);
  213. line(maximizebutton, x1, y1, Endsquare, 0, 1, blk, r.min);
  214. line(maximizebutton, x2, y2, Endsquare, 0, 1, blk, r.min);
  215. line(maximizebutton, Pt(r.min.x+4, r.min.y + 3), Pt(r.max.x-4, r.min.y + 3),Endsquare, 0, 1, blk, r.min);
  216. line(maximizebutton, Pt(r.min.x+4, r.max.y - 3), Pt(r.max.x-4, r.max.y - 3),Endsquare, 0, 1, blk, r.min);
  217. line(maximizebutton, Pt(r.min.x+4, r.min.y + 3), Pt(r.min.x+4, r.max.y - 3),Endsquare, 0, 1, blk, r.min);
  218. line(maximizebutton, Pt(r.max.x-4, r.min.y + 3), Pt(r.max.x-4, r.max.y - 3),Endsquare, 0, 1, blk, r.min);*/
  219. draw(maximizebuttonhoover, maximizebutton->r, maximizebutton, nil, maximizebutton->r.min);
  220. border3d(maximizebuttonhoover, r, 1, blk, wht, r.min);
  221. }
  222. void
  223. initminimizebutton(){
  224. int n = gettitleheight() - (2 * Borderwidth);
  225. Rectangle r = Rect(0, 0, n, n);
  226. //minimizebutton = allocimage(display, r, CMAP8, 1, DYellow);
  227. minimizebutton = allocimage(display, r, CMAP8, 1, jayconfig->windowTitleColor);
  228. minimizebuttonhoover = allocimage(display, r, CMAP8, 1, 0xD8D8D8FF);
  229. fillellipse(minimizebutton, Pt((r.min.x + r.max.x)/2,(r.min.y + r.max.y)/2), Dx(r)/2 - 1, Dx(r)/2 - 1, minimizebuttonhoover, r.min);
  230. //border3d(minimizebutton, r, 1, wht, blk, r.min);
  231. int y = r.max.y - Borderwidth;
  232. line(minimizebutton, Pt(r.min.x + Borderwidth, y), Pt(r.max.x - Borderwidth, y), 0, 0, 0, blk, r.min);
  233. draw(minimizebuttonhoover, minimizebutton->r, minimizebutton, nil, minimizebutton->r.min);
  234. border3d(minimizebuttonhoover, r, 1, blk, wht, r.min);
  235. }
  236. static int
  237. setbackimg(){
  238. if (jayconfig->backgroundimgpath == nil){
  239. return 0;
  240. }
  241. int fd = open(jayconfig->backgroundimgpath, OREAD);
  242. if (fd > 0){
  243. background = readimage(display, fd, 0);
  244. close(fd);
  245. return 1;
  246. }
  247. return 0;
  248. }
  249. static void
  250. seticoninit(void){
  251. initclosebutton();
  252. initmaximizebutton();
  253. initminimizebutton();
  254. if (!setbackimg()){
  255. background = allocimage(display, Rect(0,0,1,1), RGB24, 1, jayconfig->backgroundColor);
  256. }
  257. setmenucolor(jayconfig->menuBackColor, jayconfig->menuHighColor, jayconfig->menuBorderColor, jayconfig->menuTextColor, jayconfig->menuSelTextColor);
  258. }
  259. void
  260. iconinit(void)
  261. {
  262. initdefaultconfig();
  263. blk = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DBlack);
  264. wht = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DWhite);
  265. red = allocimage(display, Rect(0,0,1,1), RGB24, 1, 0xDD0000FF);
  266. seticoninit();
  267. }
  268. void
  269. iconreinit(void) {
  270. freeimage(background);
  271. freeimage(closebutton);
  272. freeimage(closebuttonhoover);
  273. freeimage(minimizebutton);
  274. freeimage(maximizebutton);
  275. freeimage(maximizebuttonhoover);
  276. seticoninit();
  277. }