Advertisement
userxbw

Img.cpp Setting image to background C++

Sep 14th, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.64 KB | None | 0 0
  1. //
  2. // mh5000
  3. //
  4. // Copyright (c) 2017 Michael Heras
  5. //
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307,
  19. // USA.
  20. //
  21.  
  22. #include <fstream>
  23. #include <iostream>
  24. #include <cstring>
  25. #include <X11/Xlib.h>
  26. #include <X11/Xutil.h>
  27. #include <X11/Xatom.h>
  28. //#include </usr/include/Imlib2.h>
  29. #include <string>
  30. #include <vector>
  31. #include <pwd.h>
  32. #include <unistd.h>
  33. #include <sys/types.h>
  34. #include "options.h"
  35. #include "files.h"
  36. #include "imgfunctions.hpp"
  37. #include "img.h"
  38.  
  39. #define OPPS_IMAGE "/etc/mh5000/opps_try_001.jpg"
  40. #define VERSION "1.3.5"
  41.  
  42. imlib_data imgdata;
  43. image_data img;
  44. Color c;
  45. RandomColors rc;
  46. move_image mi;
  47. mvImage mvi;
  48.  
  49. void setup_images()
  50. {
  51.  
  52. imgdata.modifier = NULL;
  53. imgdata.context = imlib_context_new();
  54. imlib_context_push(imgdata.context);
  55. imlib_context_set_display(imgdata.display);
  56.  
  57. imgdata.vis = DefaultVisual(imgdata.display, 0);
  58. imgdata.cm = DefaultColormap(imgdata.display, 0);
  59. img.screenW = DisplayWidth(imgdata.display, 0);
  60. img.screenH = DisplayHeight(imgdata.display, 0);
  61.  
  62. img.depth = DefaultDepth(imgdata.display, 0);
  63.  
  64. imgdata.pixmap = XCreatePixmap(imgdata.display, RootWindow(imgdata.display, 0), img.screenW, img.screenH, img.depth);
  65.  
  66. imlib_context_set_display(imgdata.display);
  67. imlib_context_set_visual(imgdata.vis);
  68. imlib_context_set_colormap(imgdata.cm);
  69. imlib_context_set_drawable(imgdata.pixmap);
  70. imlib_context_set_color_range(imlib_create_color_range());
  71.  
  72. imgdata.buffer = imlib_create_image(img.screenW, img.screenH);
  73.  
  74. set_buffer();
  75.  
  76. imlib_context_set_color(0, 0, 0, 255);
  77. imlib_image_fill_rectangle(0, 0, img.screenW, img.screenH);
  78. imlib_context_set_dither(1);
  79. imlib_context_set_blend(1);
  80. imgdata.modifier = imlib_create_color_modifier();
  81. imlib_context_set_color_modifier(imgdata.modifier);
  82. }
  83.  
  84. void load_image()
  85. { //std::cout<<"in load image"<<"image mode "<<(int)img.mode<<"img.flip "<<img.flip<<std::endl;
  86. int w = 0, h = 0, top = 0, left = 0, x = 0, y = 0;
  87. int ww = 0, hh = 0;
  88. int newW = 0, newH = 0;
  89. double aspect;
  90. int destination_x = 0, destination_y = 0;
  91. int angle_x = 0, angle_y = 0;
  92.  
  93. aspect = ((double) img.screenW) / w;
  94.  
  95. left = (img.screenW - w) / 2;
  96. top = (img.screenH - h) / 2;
  97.  
  98. if (opts.single_file == 1)
  99. {
  100. if ( Load_single_Image() )
  101. {
  102. set_oops_color();
  103. warning_message();
  104. exit(1);
  105. }
  106.  
  107. }
  108. else
  109. load_image_err();
  110.  
  111. set_image();
  112. w = imlib_image_get_width();
  113. h = imlib_image_get_height();
  114. set_buffer();
  115. // std::cout<<"enting load_image"<< std::endl;
  116. switch (img.mode)
  117. {
  118. case FULLSCREEN: //f
  119. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0,w, h, 0,0, img.screenW, img.screenH);
  120. break;
  121. case FILL: //F
  122.  
  123. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  124. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  125.  
  126. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, left, top, get_adjusted_by_aspect(get_aspect(h),w), get_adjusted_by_aspect(get_aspect(h),h));
  127. break;
  128. case CENTER:
  129. if (w >= img.screenW || h >= img.screenH )
  130. {
  131. aspect = (double) img.screenH / (double) h;
  132.  
  133. top = (img.screenH - (int) (h * aspect)) / 2;
  134. left = (img.screenW - (int) (w * aspect)) / 2;
  135.  
  136. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, left, top, get_adjusted_by_aspect(get_aspect(h),w), get_adjusted_by_aspect(get_aspect(h),h));
  137. }
  138. else
  139. {
  140. top = (img.screenH - h) / 2;
  141. left = (img.screenW - w) / 2;
  142. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, left, top, w, h);
  143. }
  144. break;
  145. case TILE:
  146. //(original height / original width) x wanted size = adjusted mesurment
  147. //get 1/3 screensize image to tile
  148. if ( h > (img.screenH / 3))
  149. {
  150. newH = (get_adjusted_by_aspect(get_aspect(h),h) / 3);
  151. newW = (get_adjusted_by_aspect(get_aspect(h),w) / 3);
  152. }
  153. else
  154. {
  155. newH = h;
  156. newW = w;
  157. }
  158.  
  159. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  160. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  161.  
  162. for (; left > 0; left -= newW)
  163. {}
  164. for (; top > 0; top -= newH)
  165. {}
  166.  
  167. for (x = left; x < img.screenW; x += newW) {
  168. for (y = top; y < img.screenH; y += newH)
  169. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x, y, newW, newH);
  170. }
  171. break;
  172. case TILEH:
  173. set_image();
  174. imlib_image_flip_horizontal();
  175. set_blend();
  176. set_buffer();
  177.  
  178. //(original height / original width) x wanted size = adjusted mesurment
  179. //get 1/3 screensize image to tile
  180. if ( h > (img.screenH / 3))
  181. {
  182. newH = (get_adjusted_by_aspect(get_aspect(h),h) / 3);
  183. newW = (get_adjusted_by_aspect(get_aspect(h),w) / 3);
  184. }
  185. else
  186. {
  187. newH = h;
  188. newW = w;
  189. }
  190. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  191. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  192.  
  193.  
  194. for (; left > 0; left -= newW)
  195. {}
  196. for (; top > 0; top -= newH)
  197. {}
  198.  
  199. for (x = left; x < img.screenW; x += newW)
  200. for (y = top; y < img.screenH; y += newH)
  201.  
  202. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x,y, newW, newH);
  203. break;
  204. case TILEV:
  205. set_image();
  206. imlib_image_flip_vertical();
  207. set_blend();
  208. set_buffer();
  209.  
  210. //(original height / original width) x wanted size = adjusted mesurment
  211. //get 1/3 screensize image to tile
  212. if ( h > (img.screenH / 3))
  213. {
  214. newH = (get_adjusted_by_aspect(get_aspect(h),h) / 3);
  215. newW = (get_adjusted_by_aspect(get_aspect(h),w) / 3);
  216. }
  217. else
  218. {
  219. newH = h;
  220. newW = w;
  221. }
  222.  
  223. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  224. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  225.  
  226. for (; left > 0; left -= newW) {}
  227. for (; top > 0; top -= newH) {}
  228.  
  229. for (x = left; x < img.screenW; x += newW) {
  230. for (y = top; y < img.screenH; y += newH)
  231. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x, y, newW, newH);
  232. }
  233. break;
  234. case TILEHV:
  235. imlib_image_tile();
  236.  
  237. //(original height / original width) x wanted size = adjusted mesurment
  238. //get 1/3 screensize image to tile
  239. if ( h > (img.screenH / 3))
  240. {
  241. newH = (get_adjusted_by_aspect(get_aspect(h),h) / 3);
  242. newW = (get_adjusted_by_aspect(get_aspect(h),w) / 3);
  243. }
  244. else
  245. {
  246. newH = h;
  247. newW = w;
  248. }
  249.  
  250. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  251. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  252.  
  253. for (; left > 0; left -= newW) {}
  254. for (; top > 0; top -= newH) {}
  255.  
  256. for (x = left; x < img.screenW; x += newW)
  257. {
  258. for (y = top; y < img.screenH; y += newH)
  259. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x, y, newW, newH);
  260. }
  261. break;
  262. case TILED:
  263. set_image();
  264. imlib_image_flip_diagonal ();
  265. set_blend();
  266. set_buffer();
  267.  
  268. //(original height / original width) x wanted size = adjusted mesurment
  269. //get 1/3 screensize image to tile
  270. if ( h > (img.screenH / 3))
  271. {
  272. newW = (get_adjusted_by_aspect(get_aspect(h),h) / 3);
  273. newH = (get_adjusted_by_aspect(get_aspect(h),w) / 3);
  274. }
  275. else
  276. {
  277. newH = h;
  278. newW = w;
  279. }
  280.  
  281. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  282. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  283.  
  284. for (; left > 0; left -= newW) {}
  285. for (; top > 0; top -= newH) {}
  286.  
  287. for (x = left; x < img.screenW; x += newW)
  288. {
  289. for (y = top; y < img.screenH; y += newH)
  290. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w, x, y, newW, newH);
  291. }
  292.  
  293. break;
  294. case FLIPIMGH:
  295. set_image();
  296. imlib_image_flip_horizontal();
  297. set_blend();
  298. set_buffer();
  299.  
  300. top = (img.screenH - get_adjusted_by_aspect(get_aspect(h),h))/ 2;
  301. left = ( img.screenW - get_adjusted_by_aspect(get_aspect(h),w)) / 2;
  302. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w,h,left,top, get_adjusted_by_aspect(get_aspect(h),w) ,get_adjusted_by_aspect(get_aspect(h),h));
  303. break;
  304. case FLIPIMGV:
  305. set_image();
  306. imlib_image_flip_vertical();
  307. set_blend();
  308. set_buffer();
  309.  
  310. top = (img.screenH - get_adjusted_by_aspect(get_aspect(h),h))/ 2;
  311. left = ( img.screenW - get_adjusted_by_aspect(get_aspect(h),w)) / 2;
  312. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w,h,left,top,
  313. get_adjusted_by_aspect(get_aspect(h),w) ,
  314. get_adjusted_by_aspect(get_aspect(h),h));
  315. break;
  316. case FLIPIMGD:
  317. set_image();
  318. imlib_image_flip_diagonal ();
  319. set_blend();
  320. set_buffer();
  321.  
  322. if (h > img.screenW)
  323. {
  324. top = (img.screenH - get_adjusted_by_aspect(get_aspect(h),h))/ 2;
  325. left = ( img.screenW - get_adjusted_by_aspect(get_aspect(w),w)) / 2;
  326. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w,left,top,
  327. get_adjusted_by_aspect(get_aspect(h),h) ,
  328. get_adjusted_by_aspect(get_aspect(h),h));
  329. }
  330. else
  331. {
  332. left = (img.screenW - h) / 2;
  333. top = (img.screenH - w) / 2;
  334. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w,left,top,h,w);
  335. }
  336. break;
  337. case FLIPAH: //Experimental Flip Image on an angle
  338. set_image();
  339. imlib_image_flip_horizontal();
  340. set_blend();
  341. set_buffer();
  342.  
  343. destination_x = ((img.screenH / 2) - (img.screenW / 4.35));
  344. destination_y = (img.screenW / 2.3);
  345. angle_x = (img.screenW / 3);
  346. angle_y = (img.screenH / 2);
  347.  
  348.  
  349. // imlib_blend_image_onto_image_at_angle (Imlib_Image source_image, char merge_alpha,
  350. // int source_x, int source_y, int source_width, int source_height,
  351. // int destination_x, int destination_y, int angle_x, int angle_y)
  352.  
  353. //right side left side image
  354. imlib_blend_image_onto_image_at_angle(imgdata.image, 0, 0,0,w,h,
  355. destination_y, destination_x, angle_x , angle_y);
  356. break;
  357. case FLIPAV: //Experimental Flip Image on an angle
  358. set_image();
  359. imlib_image_flip_vertical();
  360. set_blend();
  361. set_buffer();
  362.  
  363. destination_x = ((img.screenH / 2) - (img.screenW / 4.35));
  364. destination_y = (img.screenW / 2.344);
  365. angle_x = (img.screenW / 3);
  366. angle_y = (img.screenH / 2);
  367. //right side left side image
  368. imlib_blend_image_onto_image_at_angle(imgdata.image, 0, 0,0,w,h,
  369. destination_y, destination_x, angle_x , angle_y);
  370. break;
  371. case FLIPAVTH: //Experimental Flip Image on an angle
  372. set_image();
  373. imlib_image_tile_horizontal();
  374. // imlib_image_flip_vertical();
  375. set_blend();
  376. set_buffer();
  377.  
  378. destination_x = ((img.screenH / 2) - (img.screenW / 4.35));
  379. destination_y = (img.screenW / 2.344);
  380. angle_x = (img.screenW / 3);
  381. angle_y = (img.screenH / 2);
  382. //right side left side image
  383. imlib_blend_image_onto_image_at_angle(imgdata.image, 0, 0,0,w,h,
  384. destination_y, destination_x, angle_x , angle_y);
  385. break;
  386. case FLIPAVTV: //Experimental Flip Image on an angle
  387. set_image();
  388. imlib_image_tile_vertical();
  389. // imlib_image_flip_vertical();
  390. set_blend();
  391. set_buffer();
  392.  
  393. destination_x = ((img.screenH / 2) - (img.screenW / 4.35));
  394. destination_y = (img.screenW / 2.344);
  395. angle_x = (img.screenW / 3);
  396. angle_y = (img.screenH / 2);
  397. //right side left side image
  398. imlib_blend_image_onto_image_at_angle(imgdata.image, 0, 0,0,w,h,
  399. destination_y, destination_x, angle_x , angle_y);
  400. break;
  401. case ANGLED_TITLE:
  402. angled_tiling(w,h);
  403. break;
  404. case ROTATE:
  405. moveItInCircles(w,h);
  406. break;
  407. case DCENTER:
  408. if (img.set_newimg_w >= img.screenW || img.set_newimg_h >= img.screenH )
  409. {
  410. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, 0, 0,
  411. img.screenW, img.screenH);
  412. }
  413. else
  414. {
  415. left = (img.screenW - img.set_newimg_w) / 2;
  416. top = (img.screenH - img.set_newimg_h) / 2;
  417. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, left,
  418. top, img.set_newimg_w, img.set_newimg_h);
  419. }
  420. break;
  421. case DTILE:
  422. newW = img.set_newimg_w;
  423. newH = img.set_newimg_h;
  424. if (newW > img.screenW)
  425. newW = (img.screenW / 2);
  426.  
  427. if (newH > img.screenH)
  428. newH = (img.screenH / 2);
  429.  
  430. left = (img.screenW - w) / 2;
  431. top = (img.screenH - h) /2;
  432.  
  433. for (; left > 0; left -= newW) {}
  434. for (; top > 0; top -= newH) {}
  435.  
  436. for (x = left; x < img.screenW; x += newW)
  437. {
  438. for (y = top; y < img.screenH; y += newH)
  439. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x,
  440. y, newW, newH);
  441. }
  442. break;
  443. case DTILEH:
  444. imlib_image_tile_horizontal();
  445. newH = img.set_newimg_h;
  446. newW = img.set_newimg_w;
  447.  
  448. //set imagePicture size x y
  449. left = (img.screenW - newW) / 2;
  450. top = (img.screenH - newH) /2;
  451.  
  452. for (; left > 0; left -= newW) {}
  453. for (; top > 0; top -= newH) {}
  454.  
  455. for (x = left; x < img.screenW; x += newW)
  456. for (y = top; y < img.screenH; y += newH)
  457.  
  458. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x, y, newW, newH);
  459. break;
  460. case DTILEV:
  461. set_image();
  462. imlib_image_flip_vertical();
  463. set_blend();
  464. set_buffer();
  465.  
  466. newH = img.set_newimg_h;
  467. newW = img.set_newimg_w;
  468.  
  469.  
  470. left = (img.screenW - newW) / 2;
  471. top = (img.screenH - newH) /2;
  472.  
  473. for (; left > 0; left -= newW) {}
  474. for (; top > 0; top -= newH) {}
  475.  
  476. for (x = left; x < img.screenW; x += newW)
  477. {
  478. for (y = top; y < img.screenH; y += newH)
  479. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x, y, newW, newH);
  480. }
  481. break;
  482. case DTILEHV:
  483. set_image();
  484. imlib_image_tile();
  485. imlib_image_tile_horizontal();
  486. set_blend();
  487. set_buffer();
  488.  
  489. newH = img.set_newimg_h;
  490. newW = img.set_newimg_w;
  491.  
  492. left = (img.screenW - newW) / 2;
  493. top = (img.screenH - newH) /2;
  494.  
  495. for (; left > 0; left -= newW) {}
  496. for (; top > 0; top -= newH) {}
  497.  
  498. for (x = left; x < img.screenW; x += newW)
  499. {
  500. for (y = top; y < img.screenH; y += newH)
  501. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, x, y, newW, newH);
  502. }
  503. break;
  504. case DTILED:
  505. newH = img.set_newimg_h;
  506. newW = img.set_newimg_w;
  507.  
  508. set_image();
  509. imlib_image_flip_diagonal ();
  510. set_blend();
  511. set_buffer();
  512. imlib_image_tile_vertical();
  513.  
  514. left = (img.screenW - newW) / 2;
  515. top = (img.screenH - newH) /2;
  516.  
  517. for (; left > 0; left -= newW) {}
  518. for (; top > 0; top -= newH) {}
  519.  
  520. for (x = left; x < img.screenW; x += newW)
  521. {
  522. for (y = top; y < img.screenH; y += newH)
  523. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w, x, y, newW, newH);
  524. }
  525. break;
  526. case DFLIPIMGH:
  527. set_image();
  528. imlib_image_flip_horizontal();
  529. set_blend();
  530. set_buffer();
  531. newH = img.set_newimg_h;
  532. newW = img.set_newimg_w;
  533.  
  534. // if imagePicture screenW or screenH is greater then screen then
  535. // makes imagePicture
  536. if (newW >= img.screenW || newH >= img.screenH )
  537. {
  538. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, 0, 0, img.screenW, img.screenH);
  539. }
  540. else
  541. {
  542. left = (img.screenW - newW) / 2;
  543. top = (img.screenH - newH) / 2;
  544.  
  545. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, left, top, newW, newH);
  546. }
  547. break;
  548. case DFLIPIMGV:
  549. set_image();
  550. imlib_image_flip_vertical ();
  551. set_blend();
  552. set_buffer();
  553. newH = img.set_newimg_h;
  554. newW = img.set_newimg_w;
  555.  
  556. if (w >= img.screenW || h >= img.screenH)
  557. {
  558. ww = img.screenW;
  559. hh = img.screenH;
  560.  
  561. left = (img.screenW - ww) / 2;
  562. top = (img.screenH - hh) / 2;
  563. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, left, top, ww,hh);
  564. }
  565. else
  566. {
  567. left = (img.screenW - newW) / 2;
  568. top = (img.screenH - newH) / 2;
  569. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, left, top, newW,newH);
  570. }
  571. break;
  572. case DFLIPIMGD:
  573. set_image();
  574. imlib_image_flip_diagonal ();
  575. set_blend();
  576. set_buffer();
  577. newH = img.set_newimg_h;
  578. newW = img.set_newimg_w;
  579.  
  580. if(newW > img.screenH || newH > img.screenW )
  581. {
  582. std::cout<<"Too Big "<<newW<<"x"<<newH<<std::endl;
  583. std::cout<<"You're running "<<img.screenW<<"x"<<img.screenH<<std::endl;
  584. exit(1);
  585. }
  586.  
  587. left = (img.screenW - newH) / 2;
  588. top = (img.screenH - newW) / 2;
  589. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w,left,top,newH,newW);
  590. break;
  591. case MOVEIMAGE:
  592. int newWidth, newHeight;
  593. aspect = (double) img.screenW / (double) w;
  594. if ( w >= img.screenW)
  595. {
  596. newWidth = ( w * aspect / 3);
  597. newHeight = ( h * aspect / 3);
  598. }
  599. else
  600. {
  601. newWidth = w;
  602. newHeight = h;
  603. }
  604. load_image_err();
  605.  
  606. set_image();
  607. w = imlib_image_get_width();
  608. h = imlib_image_get_height();
  609. set_buffer();
  610. mvi.move();
  611. // for X
  612. if (mvi.getX() >= img.screenW ) {
  613. mvi.setPos(img.screenW, img.screenH);
  614. mvi.changeDirecton(DOWNLEFT);
  615. printf("ckX: x %d\n", mvi.getX() ); }
  616. if (mvi.getX() <= -1 && mvi.getY() <= -1) {
  617. mvi.changeDirecton(DOWNRIGHT);
  618. printf("ckX: x %d\n", mvi.getX() ); }
  619.  
  620. if (mvi.getX() >= img.screenH )
  621. {
  622. mvi.randomDirection();
  623. printf("ckX x %d y %d\n", mvi.getX() ,mvi.getY() );
  624. }
  625.  
  626. // for Y
  627.  
  628. if (mvi.getY() >= img.screenH){
  629. mvi.changeDirecton(UPLEFT);
  630. printf("ckY y %d\n", mvi.getY() ); }
  631. if (mvi.getY() <= -1 ) {
  632. mvi.changeDirecton(LEFT);
  633. printf("ckY y %d\n", mvi.getY() ); }
  634.  
  635. if (mvi.getY() >= img.screenH) {
  636. mvi.randomDirection();
  637. printf("ckY x %d y %d\n",mvi.getX(), mvi.getY() ); }
  638.  
  639. // source_x,source_y,source_width,source_height,
  640. // destination_x, destination_y, destination_width, destination_height
  641. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, w, h, mvi.getX(), mvi.getY(), newWidth, newHeight);
  642. break;
  643. case SPACE_TILE:
  644.  
  645. if (img.set_over_ride_system == 1)
  646. Flips_Spaced_Tile_Switch();
  647.  
  648. if(img.flips_mode == 1)
  649. Flips_Spaced_Tile_Switch();
  650.  
  651. switch (img.flip)
  652. {
  653. case 1:
  654. set_image();
  655. imlib_image_flip_vertical();
  656. set_blend();
  657. set_buffer();
  658. set_flip_tile(w,h,img.flip);
  659. break;
  660. case 2:
  661. set_image();
  662. imlib_image_flip_horizontal();
  663. set_blend();
  664. set_buffer();
  665. set_flip_tile(w,h,img.flip);
  666. break;
  667. case 3:
  668. // std::cout<<"3 flip"<<std::endl;
  669. set_image();
  670. imlib_image_tile_vertical();
  671. set_blend();
  672. set_buffer();
  673.  
  674. set_flip_tile(w,h,img.flip);
  675. break;
  676. case 4:
  677. set_image();
  678. imlib_image_tile_horizontal();
  679. set_blend();
  680. set_buffer();
  681. set_flip_tile(w,h,img.flip);
  682. break;
  683. case 5:
  684. set_image();
  685. imlib_image_tile();
  686. // imlib_image_flip_diagonal();
  687. set_blend();
  688. set_buffer();
  689. set_flip_tile(w,h,img.flip);
  690.  
  691. break;
  692. case 6:
  693. set_image();
  694. imlib_image_flip_diagonal();
  695. set_blend();
  696. set_buffer();
  697. set_flip_tile(w,h,img.flip);
  698. break;
  699.  
  700. default:
  701. set_image();
  702. set_blend();
  703. set_buffer();
  704. // std::cout<<"enting load_image"<<" "<<img.flip<<std::endl;
  705. // if (imgdata.image)
  706. // std::cout<<"enting y load_image"<<" "<<img.flip<<std::endl;
  707.  
  708.  
  709. if ( h > (img.screenH / 3))
  710. {
  711. newH = (get_adjusted_by_aspect(get_aspect(h),h) / 3);
  712. newW = (get_adjusted_by_aspect(get_aspect(h),w) / 3);
  713. }
  714. else
  715. {
  716. newH = h;
  717. newW = w;
  718. }
  719. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  720. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  721.  
  722.  
  723. for (; left > 0; left -= newW) {}
  724. for (; top > 0; top -= newH) {}
  725.  
  726. for (x = left; x < img.screenW; x += newW)
  727. {
  728. for (y = top; y < img.screenH; y += newH)
  729. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w, x, y, newW / space_tile_gap((rand() % 3)) , newH / space_tile_gap((rand() % 3)));
  730. }
  731. break;
  732. } //end switch
  733. break; // for SPACE_TILE CASE
  734. default:
  735. break;
  736.  
  737. } // end switch
  738.  
  739. display_image();
  740. }
  741. void display_image()
  742. { //std::cout<<"in display_image"<<std::endl;
  743. if (imgdata.modifier != NULL) {
  744. imlib_context_set_color_modifier(imgdata.modifier);
  745. imlib_apply_color_modifier();
  746. imlib_free_color_modifier();
  747. imgdata.modifier = NULL;
  748. }
  749.  
  750. imlib_render_image_on_drawable(0, 0);
  751.  
  752. // imlib_free_image();
  753. imlib_free_image_and_decache ();
  754. imlib_free_color_range();
  755.  
  756. if (setRootAtoms () == 0)
  757. fprintf (stderr, "Couldn't create atoms...\n");
  758.  
  759. XKillClient (imgdata.display, AllTemporary);
  760. XSetCloseDownMode (imgdata.display, RetainTemporary);
  761.  
  762. XSetWindowBackgroundPixmap (imgdata.display, RootWindow (imgdata.display, 0),imgdata.pixmap);
  763. XClearWindow (imgdata.display, RootWindow (imgdata.display, 0));
  764.  
  765. XFlush (imgdata.display);
  766. XSync (imgdata.display, False);
  767.  
  768. imlib_context_pop();
  769. imlib_context_free(imgdata.context);
  770.  
  771. // std::cout<<"leaving display image"<<"\n";
  772.  
  773. }
  774. void setAlpha(void)
  775. {
  776. int o;
  777.  
  778. if (img.alpha < 255) {
  779. // Create alpha-override mask
  780. imlib_image_set_has_alpha(1);
  781. Imlib_Color_Modifier modifier = imlib_create_color_modifier();
  782. imlib_context_set_color_modifier(modifier);
  783.  
  784. DATA8 red[256], green[256], blue[256], alph[256];
  785. imlib_get_color_modifier_tables(red, green, blue, alph);
  786. for (o = 0; o < 256; o++)
  787. alph[o] = (DATA8) img.alpha;
  788. imlib_set_color_modifier_tables(red, green, blue, alph);
  789.  
  790. imlib_apply_color_modifier();
  791. imlib_free_color_modifier();
  792. }
  793. } // end setAlpha
  794.  
  795. // Adapted from fluxbox' bsetroot
  796. int setRootAtoms (void)
  797. {
  798. Atom atom_root, atom_eroot, type;
  799. unsigned char *data_root, *data_eroot;
  800. int format;
  801. unsigned long length, after;
  802.  
  803. atom_root = XInternAtom (imgdata.display, "_XROOTMAP_ID", True);
  804. atom_eroot = XInternAtom (imgdata.display, "ESETROOT_PMAP_ID", True);
  805.  
  806. // doing this to clean up after old background
  807. if (atom_root != None && atom_eroot != None)
  808. {
  809. XGetWindowProperty (imgdata.display, RootWindow (imgdata.display, 0),
  810. atom_root, 0L, 1L, False, AnyPropertyType,
  811. &type, &format, &length, &after, &data_root);
  812.  
  813. if (type == XA_PIXMAP)
  814. {
  815. XGetWindowProperty (imgdata.display, RootWindow (imgdata.display, 0),
  816. atom_eroot, 0L, 1L, False, AnyPropertyType,
  817. &type, &format, &length, &after, &data_eroot);
  818.  
  819. if (data_root && data_eroot && type == XA_PIXMAP &&
  820. *((Pixmap *) data_root) == *((Pixmap *) data_eroot))
  821. {
  822. XKillClient (imgdata.display, *((Pixmap *) data_root));
  823. }
  824. } // second if
  825. } //first if
  826.  
  827. atom_root = XInternAtom (imgdata.display, "_XROOTPMAP_ID", False);
  828. atom_eroot = XInternAtom (imgdata.display, "ESETROOT_PMAP_ID", False);
  829.  
  830. if (atom_root == None || atom_eroot == None)
  831. return 0;
  832.  
  833. // setting new background atoms
  834. XChangeProperty (imgdata.display, RootWindow (imgdata.display, 0),
  835. atom_root, XA_PIXMAP, 32, PropModeReplace,
  836. (unsigned char *) &imgdata.pixmap, 1);
  837.  
  838. XChangeProperty (imgdata.display, RootWindow (imgdata.display, 0), atom_eroot,
  839. XA_PIXMAP, 32, PropModeReplace, (unsigned char *) &imgdata.pixmap,
  840. 1);
  841.  
  842.  
  843. return 1;
  844. }
  845.  
  846.  
  847. int parse_color(char *col, int *r, int *g, int *b, int *a)
  848. {
  849. unsigned long cc, rr, gg, bb, aa;
  850. int len;
  851. len = strlen(col);
  852.  
  853. if (( strlen(col) != 7) && (strlen(col) != 9))
  854. return 1;
  855.  
  856. if (col[0] == '#')
  857. {
  858. /* #RRGGBBAA style */
  859. /* skip the '#' */
  860. col++;
  861. len = strlen(col);
  862.  
  863.  
  864. if (len == 8)
  865. {
  866. cc = (unsigned long) strtoul(col, NULL, 16);
  867. rr = (cc & 0xff000000) >> 24;
  868. gg = (cc & 0x00ff0000) >> 16;
  869. bb = (cc & 0x0000ff00) >> 8;
  870. aa = (cc & 0x000000ff);
  871.  
  872. }
  873. else if (len == 6)
  874. {
  875. cc = (unsigned long) strtoul(col, NULL, 16);
  876. rr = (cc & 0xff0000) >> 16;
  877. gg = (cc & 0x00ff00) >> 8;
  878. bb = (cc & 0x0000ff);
  879. aa = 255;
  880. }
  881. *r = rr;
  882. *g = gg;
  883. *b = bb;
  884. *a = aa;
  885.  
  886. }
  887. return 0;
  888. }
  889.  
  890. double get_aspect(int x)
  891. {
  892.  
  893. return (((double) img.screenH) / (double) x);
  894.  
  895. }
  896. int get_adjusted_by_aspect(double aspect, int x)
  897. {
  898. return (((int) (x * aspect)));
  899. }
  900.  
  901. int get_adjusted_size(int h, int w, int wantedSize)
  902. {
  903. //(oginal height / oginal width) x wanted size = adjusted measument
  904. return (( (double)h / (double)w ) * (double)wantedSize);
  905.  
  906. }
  907.  
  908.  
  909. int64_t int_or_ch(char *data)
  910. {
  911. int len = 0, i;
  912. char *endptr;
  913.  
  914. len = strlen(data);
  915.  
  916. for ( i = 0; i < len ; i++)
  917. {// if not a digit return error code -1
  918. if ( isdigit(data[i]) == 0)
  919. return -1;
  920. }
  921. return strtol(data, &endptr, 10);
  922. }
  923.  
  924.  
  925. int findX(char *whereisX, unsigned int *wantW, unsigned int *wantH)
  926. {
  927.  
  928. const char ch = 'x';
  929.  
  930. char *tok1, *tok2, *saveptr;
  931. char str1[1+strlen(whereisX)];
  932. strcpy(str1, whereisX);
  933. unsigned int giveW, giveH;
  934.  
  935. if( strrchr(whereisX, ch) == NULL)
  936. {
  937. return 1;
  938. }
  939. else
  940. {
  941. tok1 = strtok_r(whereisX, "x", &saveptr);
  942. tok2 = strtok_r(NULL, "x", &saveptr);
  943.  
  944. if ( tok2 == NULL)
  945. {
  946. return 1;
  947. }
  948. else
  949. {
  950. tok1 = strtok_r(str1, "x", &saveptr);
  951. tok2 = strtok_r(NULL, "x", &saveptr);
  952.  
  953. if ( (giveW = int_or_ch(tok1) ) == -1)
  954. return 1;
  955. else
  956. *wantW = giveW;
  957.  
  958. if ( (giveH = int_or_ch(tok2) ) == -1)
  959. return 1;
  960. else
  961. *wantH = giveH;
  962. return 0;
  963. }
  964. }
  965. } //end findX
  966.  
  967.  
  968. int findXChar(char *whereisX, char *wantW, char *wantH)
  969. {
  970.  
  971. const char ch = 'x';
  972.  
  973. char *tok1, *tok2, *saveptr;
  974. char str1[1+strlen(whereisX)];
  975. strcpy(str1, whereisX);
  976. char giveW, giveH;
  977.  
  978. if( strrchr(whereisX, ch) == NULL)
  979. {
  980. return 1;
  981. }
  982. else
  983. {
  984. wantW = strtok_r(whereisX, "x", &saveptr);
  985. wantH = strtok_r(NULL, "x", &saveptr);
  986.  
  987. if ( wantH == NULL)
  988. {
  989. return 1;
  990. }
  991. else
  992. {
  993. wantW = strtok_r(str1, "x", &saveptr);
  994. wantH = strtok_r(NULL, "x", &saveptr);
  995. giveW = atoll(tok1);
  996. giveH = atoll(tok2);
  997. // assigning the results to the output
  998. // giveW = tok1;
  999. // giveH = tok2;
  1000. wantW = tok1;
  1001. wantH = tok2;
  1002.  
  1003.  
  1004. // std::cout<<wantH<<" "<<wantW<<std::endl;
  1005.  
  1006. return 0;
  1007. }
  1008. }
  1009. } //end findX
  1010.  
  1011.  
  1012. int seconds_or_minutes(char *what_is_it)
  1013. {
  1014. const char sec = 's';
  1015. const char min = 'm';
  1016. char str1[1+strlen(what_is_it)];
  1017.  
  1018. strcpy(str1, what_is_it);
  1019. // if only s or m is present then return -1
  1020. if ( ( ( strrchr(what_is_it, sec) != NULL ) || (strrchr(what_is_it, min) != NULL) ) && strlen(what_is_it) == 1)
  1021. {
  1022. return -1;
  1023. }
  1024. else if ( strrchr(what_is_it, sec) )
  1025. {
  1026. return (atoi( strtok(str1, "s") ));
  1027. }
  1028. else if( strrchr(what_is_it, min) )
  1029. {
  1030. return (atoi(strtok(str1,"m")) * 60);
  1031. }//defaults to seconds
  1032.  
  1033. return atoi(what_is_it);
  1034. }
  1035.  
  1036.  
  1037. void set_image()
  1038. {
  1039.  
  1040. imlib_context_set_image(imgdata.image);
  1041. }
  1042. void set_buffer()
  1043. {
  1044. imlib_context_set_image(imgdata.buffer);
  1045. }
  1046. void set_blend()
  1047. {
  1048. imlib_context_set_blend(1);
  1049. }
  1050. //space tiles
  1051.  
  1052. double space_tile_gap(int which_gap)
  1053. { //std::cout<<"space_tile_gap "<<which_gap<<std::endl;
  1054. switch(which_gap)
  1055. {
  1056. case 0:
  1057. return (1.011);
  1058. break;
  1059. case 1:
  1060. return (1.1102);
  1061. break;
  1062. case 2:
  1063. return (1.013);
  1064. break;
  1065. case 3:
  1066. return (1.14);
  1067. break;
  1068. default:
  1069. return (1.015);
  1070. break;
  1071. }
  1072. return (1.2);
  1073. }
  1074.  
  1075. //space tiles
  1076. void set_flip_tile(int w, int h, int flip)
  1077. {
  1078. int newW,newH,x,y,top,left;
  1079. // std::cout<<"newW"<<newW<<" newH "<<newH<<std::endl;
  1080. if ( h > (img.screenH / 3))
  1081. {
  1082. newH = (get_adjusted_by_aspect(get_aspect(h),h) / 3);
  1083. newW = (get_adjusted_by_aspect(get_aspect(h),w) / 3);
  1084.  
  1085. }
  1086. else
  1087. {
  1088. /*
  1089. newH = h;
  1090. newW = w;
  1091. */
  1092. ;
  1093. }
  1094. top = (img.screenH - (int) (h * get_aspect(h))) / 2;
  1095. left = (img.screenW - (int) (w * get_aspect(h))) / 2;
  1096. set_blend();
  1097. set_buffer();
  1098. // std::cout<<"set_flip_tile flip "<<flip<<std::endl;
  1099. switch (flip)
  1100. {
  1101. case 1 ... 5:
  1102. newW / space_tile_gap((rand() % 4));
  1103. newH / space_tile_gap((rand() % 3));
  1104. // std::cout<<newW<<" "<<newH<<std::endl;
  1105.  
  1106. for (; left > 0; left -= newW) {}
  1107. for (; top > 0; top -= newH){}
  1108.  
  1109. for (x = left; x < img.screenW; x += newW)
  1110. for (y = top; y < img.screenH; y += newH)
  1111. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w,
  1112. x,y, newW / space_tile_gap((rand() % 4)) ,
  1113. newH / space_tile_gap((rand() % 3)) );
  1114. break;
  1115. case 6:
  1116. for (; left > 0; left -= newW)
  1117. {}
  1118. for (; top > 0; top -= newH)
  1119. {}
  1120. for (x = left; x < img.screenW; x += newW)
  1121.  
  1122. for (y = top; y < img.screenH; y += newH)
  1123. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0, h,w,
  1124. x,y, newW / space_tile_gap((rand() % 4)) ,
  1125. newH / space_tile_gap((rand() % 3)) );
  1126. break;
  1127. default:
  1128. break;
  1129. }
  1130.  
  1131. }
  1132.  
  1133. void Flips_Spaced_Tile_Switch(void)
  1134. {
  1135. // give it a little more room to play setting it to N+1
  1136. img.flip = (rand() % 7);
  1137.  
  1138. }
  1139.  
  1140. void BadFindX(char *bad)
  1141. {
  1142. std::cout << "Badly "<<bad<<" formated size"<<std::endl;
  1143. }
  1144. void BeyondMaxColors(char *c)
  1145. {
  1146. std::cout<< "Too Big a number, try a smaller one."<<c<<std::endl;
  1147. }
  1148.  
  1149. void set_oops_color(void)
  1150. {
  1151. imgdata.display = XOpenDisplay(NULL);
  1152. char oops1[8] = "#0000cc"; //blue
  1153. char oops2[8] = "#33cc00"; //green
  1154. char oops3[8] = "#ff0000"; //red
  1155. if(!imgdata.display)
  1156. return;
  1157.  
  1158. img.screenW= DisplayWidth(imgdata.display, 0);
  1159. img.screenH = DisplayHeight(imgdata.display, 0);
  1160.  
  1161. if ( parse_color(oops1, &c.r, &c.g, &c.b, &c.a) == 1)
  1162. {
  1163. NoParse(oops1);
  1164. exit(1);
  1165. }
  1166.  
  1167. setup_images();
  1168. set_color();
  1169. fill_rectangle();
  1170. display_image();
  1171.  
  1172. if ( parse_color(oops2, &c.r, &c.g, &c.b, &c.a) == 1)
  1173. {
  1174. NoParse(oops2);
  1175. exit(1);
  1176. }
  1177.  
  1178. setup_images();
  1179. set_color();
  1180. fill_rectangle();
  1181. display_image();
  1182.  
  1183. if ( parse_color(oops3, &c.r, &c.g, &c.b, &c.a) == 1)
  1184. {
  1185. NoParse(oops3);
  1186. exit(1);
  1187. }
  1188.  
  1189. setup_images();
  1190. set_color();
  1191. fill_rectangle();
  1192. display_image();
  1193. }
  1194.  
  1195. bool is_file_exist(const char *fileName)
  1196. {
  1197. std::ifstream infile(fileName);
  1198. return infile.good();
  1199. }
  1200.  
  1201. void NoParse(char *clr)
  1202. {
  1203. std::cout<<"Bad Color"<<clr<<""<<std::endl;
  1204. }
  1205.  
  1206. void Load_OOPs_Image()
  1207. {
  1208. int w,h;
  1209. setup_images();
  1210.  
  1211. // imgdata.image = imlib_load_image( (const char *)OPPS_IMAGE );
  1212. if ( is_file_exist( OPPS_IMAGE) )
  1213. imgdata.image = imlib_load_image_immediately( (const char *) OPPS_IMAGE );
  1214. else
  1215. return;
  1216.  
  1217. set_image();
  1218. //set_blend();
  1219. w = imlib_image_get_width();
  1220. h = imlib_image_get_height();
  1221. set_buffer();
  1222. imlib_blend_image_onto_image (imgdata.image, 0, 0, 0,w, h, 0,0, img.screenW, img.screenH);
  1223. display_image();
  1224.  
  1225. if(imgdata.display)
  1226. XCloseDisplay(imgdata.display);
  1227. }
  1228.  
  1229. void warning_message()
  1230. {
  1231. std::cout<<" *** WARNING WARNING WARNING ***"<<std::endl;
  1232. std::cout<<" Check your settings"<<std::endl;
  1233. std::cout<<" ERROR CODE ("<<getUserName()<<")"<<std::endl;
  1234. std::cout<<" man mh5000"<<std::endl;
  1235. std::cout<<" **** ERROR ERROR ERROR ****"<<std::endl;
  1236. exit(1);
  1237. }
  1238. char *getUserName()
  1239. {
  1240. uid_t uid = geteuid();
  1241. struct passwd *pw = getpwuid(uid);
  1242. if (pw)
  1243. {
  1244. return pw->pw_name;
  1245. }
  1246.  
  1247. return NULL;
  1248. }
  1249.  
  1250. void get_randoms(void)
  1251. {
  1252. rc.r1 = (getRany(1,255));
  1253. rc.g1 = (getRany(0,255));
  1254. rc.b1 = (getRany(0,255));
  1255. rc.a1 = (getRany(0,255));
  1256.  
  1257.  
  1258. rc.r2 = (getRany(0,255));
  1259. rc.g2 = (getRany(0,255));
  1260. rc.b2 = (getRany(0,255));
  1261. rc.a2 = 255; // brighter colors
  1262.  
  1263. img.distance = (getRany(0,120));
  1264. img.angle = (getRany(0,360));
  1265. }
  1266.  
  1267. int rotate_angle(int d)
  1268. {
  1269. if (img.rotate_angle_num > 360 )
  1270. {
  1271. img.rotate_angle_num = 10;
  1272. d = 10;
  1273. }
  1274. return ( img.rotate_angle_num += d );
  1275. }
  1276.  
  1277. void set_display()
  1278. {
  1279. imgdata.display = XOpenDisplay(NULL);
  1280. }
  1281. int get_readjusted_size(int h, int w, int wantedSize)
  1282. {
  1283. //(original height / original width) x wanted size = adjusted measurement
  1284. return (( (double)h / (double)w ) * (double)wantedSize);
  1285.  
  1286. }
  1287. void fill_rectangle(void)
  1288. {
  1289. imlib_image_fill_rectangle(0, 0, img.screenW, img.screenH);
  1290. }
  1291. void set_color(void)
  1292. {
  1293. imlib_context_set_color(c.r, c.g, c.b, c.a);
  1294. }
  1295.  
  1296. void set_one_solid_color(void)
  1297. {
  1298. if ( parse_color(img.solidColor, &c.r, &c.g, &c.b, &c.a) == 1)
  1299. {
  1300. NoParse(img.solidColor);
  1301. exit(1);
  1302. }
  1303. set_color();
  1304. fill_rectangle();
  1305.  
  1306. }
  1307. void set_two_colors(void)
  1308. {
  1309. if (parse_color(img.color1, &c.r, &c.g, &c.b, &c.a) == 1)
  1310. {
  1311. NoParse(img.color1);
  1312. exit(1);
  1313. }
  1314. imlib_context_set_color(c.r,c.g,c.b,c.a);
  1315. imlib_add_color_to_color_range(img.distance);
  1316.  
  1317. if (parse_color(img.color2, &c.r, &c.g, &c.b, &c.a) == 1)
  1318. {
  1319. NoParse(img.color1);
  1320. exit(1);
  1321. }
  1322. imlib_context_set_color(c.r,c.b,c.b,c.a);
  1323. imlib_add_color_to_color_range(img.distance);
  1324. set_buffer();
  1325. imlib_image_fill_color_range_rectangle (0, 0, img.screenW, img.screenH, img.angle);
  1326. }
  1327. void set_one_random_color(void)
  1328. {
  1329. get_randoms();
  1330. imlib_context_set_color(rc.a1,rc.g2,rc.b1,rc.a2);
  1331. imlib_image_fill_rectangle(0, 0, img.screenW, img.screenH);
  1332. }
  1333. void set_two_random_colors(void)
  1334. {
  1335. get_randoms();
  1336. imlib_context_set_color(rc.r1, rc.b1, rc.g1, rc.a1);
  1337. imlib_add_color_to_color_range(img.distance);
  1338.  
  1339. imlib_context_set_color(rc.r2,rc.b2,rc.g2,rc.a2);
  1340. get_randoms();
  1341. imlib_add_color_to_color_range(img.distance);
  1342. imlib_image_fill_color_range_rectangle (0, 0, img.screenW, img.screenH, img.angle);
  1343. }
  1344.  
  1345. void set_colors(void)
  1346. {
  1347. int i = 0;
  1348.  
  1349. if(img.angle_flag > 0)
  1350. get_randoms();
  1351.  
  1352. switch(img.color_flag)
  1353. {
  1354. case 1:
  1355. set_one_solid_color();
  1356. break;
  1357. case 2:
  1358. set_two_colors();
  1359. break;
  1360. case 3:
  1361. set_one_random_color();
  1362. break;
  1363. case 4:
  1364. for( i = 0; i < img.set_random_color_num; i++)
  1365. set_two_random_colors();
  1366. break;
  1367. default:
  1368. set_two_random_colors();
  1369. break;
  1370.  
  1371. }
  1372. }
  1373. int gettingWidthHeight(char *data, unsigned int *w, unsigned int *h)
  1374. {
  1375.  
  1376. unsigned int width = 0, height = 0;
  1377. int ret = 0;
  1378. char trail = '\0';
  1379.  
  1380. ret = sscanf(data,"%dx%d%c", &width,&height,&trail);
  1381. if (ret == 2 && trail == '\0')
  1382. {
  1383. *w = width;
  1384. *h = height;
  1385. return 0;
  1386. }
  1387. else
  1388. return -1;
  1389. }
  1390.  
  1391. int getPoints(char *data, unsigned int *x, unsigned int *y)
  1392. {
  1393. unsigned int xfactor = 0, yfactor = 0;
  1394. int ret = 0;
  1395. char tail = '\0';
  1396. ret = scanf(data, "%d,%d%c", &xfactor,&yfactor,&tail);
  1397. if (ret == 2 && tail == '\0')
  1398. {
  1399. *x = xfactor;
  1400. *y = yfactor;
  1401. return 0;
  1402. }
  1403. else
  1404. return -1;
  1405. }
  1406.  
  1407.  
  1408.  
  1409. void usage(char *argv[])
  1410. {
  1411. std::cout<<"usage:\n";
  1412. std::cout<<argv[0]<<" Version: "<<VERSION<<"\n";
  1413. std::cout<<"Michael Heras (c) 2017"<<"\n\n";
  1414. std::cout<<"Option for loading images. Either by path/Directory or file with path/filename"<<std::endl
  1415. <<"-O"<<std::endl;
  1416. std::cout<<"-c Center Image"<<std::endl<<"-c=<sizexsize> User selected image size"<<"\n"<<"-f Fullscreen"<<std::endl
  1417. <<"-st=<1-7> Selection for spaced tiles"<<std::endl<<std::endl<<"Load Images via Directory"<<"\n";
  1418.  
  1419. std::cout<<argv[0]<<" -st=3 -r -z 3m -O /path/to/directory"<<"\n"<<"Load Images via File\n";
  1420. std::cout<<argv[0]<<" -c=600x800 -rc=35 -rd -ra -O /path/to/file/filename"<<"\n"
  1421. <<"Load Single Image"<<"\n"<<argv[0]<<" -f -S /path/to/image/filename.jpg"<<"\n";
  1422. std::cout<<"man mh5000 for more options\n"<<"\n";
  1423. }
  1424.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement