PageRenderTime 36ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/Fiew/Layer.cpp

https://github.com/f055/fiew-image-viewer
C++ | 1162 lines | 998 code | 163 blank | 1 comment | 413 complexity | 6fac510d33d7df6a5c1fb3bd0fa8ba16 MD5 | raw file
  1. #include "stdafx.h"
  2. #include "Core.h"
  3. Layer::Layer(Core *core, Image *image)
  4. {
  5. this->core = core;
  6. this->cell = NULL;
  7. this->image = image;
  8. this->next = NULL;
  9. this->prev = NULL;
  10. this->scali = NULL;
  11. this->scaln = NULL;
  12. this->scalp = NULL;
  13. this->fulldraw = true;
  14. this->sidedraw = false;
  15. this->zoomdraw = false;
  16. this->passmess = false;
  17. this->fullscreen = false;
  18. this->cancel = false;
  19. this->dimension = NULL;
  20. this->frameCount = 0;
  21. this->frameThat = 0;
  22. this->Brush_Back = new SolidBrush(CLR_WHITE);
  23. this->Brush_DarkBack = new SolidBrush(CLR_DIRK);
  24. this->Brush_LiteBack = new SolidBrush(CLR_LITE);
  25. this->Pen_Border = new Pen(CLR_FRAME_LIGHT,1);
  26. this->Pen_DarkBorder = new Pen(CLR_FRAME_DARK,1);
  27. this->FontSize = FONTSIZE;
  28. this->FontFamily_Arial = new FontFamily(FONT,NULL);
  29. this->Font_Default =
  30. new Font(this->FontFamily_Arial,(REAL)this->FontSize,FontStyleRegular,UnitPixel);
  31. this->mut_image = NULL;
  32. this->mut_animloop = NULL;
  33. this->mut_terminator = NULL;
  34. this->thrd_anim = NULL;
  35. this->offset = NULL;
  36. this->menuheight = NULL;
  37. this->fitmode = FITSCREENOV;
  38. this->sidemode = NULL;
  39. this->type = TYPE_NONE;
  40. this->zoom = ZOOMINIT;
  41. this->rot = ROT_0;
  42. this->gifdir = RIGHT;
  43. this->init();
  44. this->locate(TOP);
  45. }
  46. Layer::~Layer()
  47. {
  48. this->reset();
  49. delete this->Brush_Back;
  50. delete this->Brush_DarkBack;
  51. delete this->Brush_LiteBack;
  52. delete this->Pen_Border;
  53. delete this->Pen_DarkBorder;
  54. delete this->FontFamily_Arial;
  55. delete this->Font_Default;
  56. }
  57. void Layer::init()
  58. {
  59. if( this->image == NULL )
  60. this->loadContent(DEFAULT);
  61. }
  62. void Layer::setPassmess()
  63. {
  64. this->passmess = true;
  65. }
  66. void Layer::reset()
  67. {
  68. if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ){
  69. ReleaseMutex(this->mut_terminator);
  70. WaitForSingleObject(this->mut_animloop,INFINITE);
  71. ReleaseMutex(this->mut_animloop);
  72. }
  73. if( this->mut_image != NULL )
  74. CloseHandle(this->mut_image);
  75. this->mut_image = NULL;
  76. if( this->mut_animloop != NULL )
  77. CloseHandle(this->mut_animloop);
  78. this->mut_animloop = NULL;
  79. if( this->mut_terminator != NULL )
  80. CloseHandle(this->mut_terminator);
  81. this->mut_terminator = NULL;
  82. if( this->thrd_anim != NULL )
  83. CloseHandle(this->thrd_anim);
  84. this->thrd_anim = NULL;
  85. if( this->image != NULL )
  86. delete this->image;
  87. this->image = NULL;
  88. if( this->next != NULL )
  89. delete this->next;
  90. this->next = NULL;
  91. if( this->prev != NULL )
  92. delete this->prev;
  93. this->prev = NULL;
  94. if( this->scali != NULL )
  95. delete this->scali;
  96. this->scali = NULL;
  97. if( this->scaln != NULL )
  98. delete this->scaln;
  99. this->scaln = NULL;
  100. if( this->scalp != NULL )
  101. delete this->scalp;
  102. this->scalp = NULL;
  103. if( this->dimension != NULL )
  104. delete this->dimension;
  105. this->dimension = NULL;
  106. this->frameCount = 0;
  107. this->frameThat = 0;
  108. this->gifdir = RIGHT;
  109. }
  110. void Layer::repos()
  111. {
  112. this->sidemode = NULL;
  113. this->rotateReset(true);
  114. this->setFitmode(NULL);
  115. }
  116. void Layer::loadContent(int init)
  117. {
  118. this->reset();
  119. Cacher *cacher = this->core->getCacher();
  120. if( cacher != NULL ){
  121. Cell *tmp = NULL;
  122. if( this->sidedraw == true ){
  123. if( cacher->prev() ){
  124. tmp = cacher->getThat();
  125. if( tmp != NULL )
  126. this->prev = tmp->getImage();
  127. cacher->next();
  128. }
  129. }
  130. this->cell = cacher->getThat();
  131. if( this->cell != NULL ){
  132. WaitForSingleObject(this->mut_image,INFINITE);
  133. this->image = this->cell->getImage();
  134. ReleaseMutex(this->mut_image);
  135. }
  136. if( this->sidedraw == true ){
  137. if( cacher->next() ){
  138. tmp = cacher->getThat();
  139. if( tmp != NULL )
  140. this->next = tmp->getImage();
  141. cacher->prev();
  142. }
  143. }
  144. }
  145. this->afterLoadContent(init);
  146. }
  147. void Layer::afterLoadContent(int init)
  148. {
  149. int mode = init;
  150. if( this->sidedraw == false )
  151. mode = TOP;
  152. this->rotateSet();
  153. this->locate(mode);
  154. this->setFitmode();
  155. if( this->core->getGui() != NULL && init != DEFAULT )
  156. this->core->getGui()->update();
  157. }
  158. void Layer::nextContent(int init)
  159. {
  160. Cacher *cacher = this->core->getCacher();
  161. if( cacher != NULL ){
  162. HCURSOR last = NULL;
  163. if( this->core->getGui() != NULL )
  164. last = this->core->getGui()->setCursor(CURSOR_ARRWAIT);
  165. if( cacher->next() )
  166. this->loadContent(init);
  167. if( this->core->getGui() != NULL )
  168. this->core->getGui()->setCursor(last);
  169. }
  170. }
  171. void Layer::prevContent(int init)
  172. {
  173. Cacher *cacher = this->core->getCacher();
  174. if( cacher != NULL ){
  175. HCURSOR last = NULL;
  176. if( this->core->getGui() != NULL )
  177. last = this->core->getGui()->setCursor(CURSOR_ARRWAIT);
  178. if( cacher->prev() )
  179. this->loadContent(init);
  180. if( this->core->getGui() != NULL )
  181. this->core->getGui()->setCursor(last);
  182. }
  183. }
  184. void Layer::nextImage(int x, int y)
  185. {
  186. if( this->nextFrame(false) == true ){
  187. this->offset = 0;
  188. this->nextContent(TOP);
  189. }
  190. else
  191. this->zoomend();
  192. }
  193. void Layer::prevImage(int x, int y)
  194. {
  195. if( this->prevFrame(false) == true ){
  196. this->offset = 0;
  197. this->prevContent(TOP);
  198. }
  199. else
  200. this->zoomend();
  201. }
  202. bool Layer::nextFrame(bool back)
  203. {
  204. if( this->frameCount < 2 )
  205. return true;
  206. if( back == false &&
  207. WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT )
  208. return true;
  209. bool result = false;
  210. this->frameThat++;
  211. if( this->frameThat >= this->frameCount )
  212. this->frameThat = 0;
  213. if( this->frameThat == 0 )
  214. result = true;
  215. this->image->SelectActiveFrame(this->dimension,this->frameThat);
  216. return result;
  217. }
  218. bool Layer::prevFrame(bool back)
  219. {
  220. if( this->frameCount < 2 )
  221. return true;
  222. if( back == false &&
  223. WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT )
  224. return true;
  225. bool result = false;
  226. if( this->frameThat == 0 )
  227. result = true;
  228. if( this->frameThat == 0 )
  229. this->frameThat = this->frameCount;
  230. this->frameThat--;
  231. this->image->SelectActiveFrame(this->dimension,this->frameThat);
  232. return result;
  233. }
  234. Bitmap *Layer::render()
  235. {
  236. this->locate();
  237. WaitForSingleObject(this->mut_image,INFINITE);
  238. int frame = FRAME;
  239. Bitmap *scene = NULL;
  240. if( this->fulldraw == true )
  241. scene = new Bitmap(this->cwidth + 2*frame,this->cheight + 2*frame);
  242. else
  243. scene = new Bitmap(this->width,this->height);
  244. Graphics *tmpgfx = Graphics::FromImage(scene);
  245. Image *tmp = NULL;
  246. tmpgfx->Clear(CLR_WHITE);
  247. if( this->fulldraw == true ){
  248. if( this->image != NULL ){
  249. double zoom = NULL;
  250. int width, height;
  251. if( this->scali == NULL )
  252. tmp = this->image;
  253. else
  254. tmp = this->scali;
  255. if( this->fullscreen == false )
  256. tmpgfx->DrawRectangle(this->Pen_Border,
  257. this->x - frame,
  258. this->y - frame,
  259. this->width + frame + 1,
  260. this->height + frame + 1);
  261. tmpgfx->DrawImage(tmp,
  262. Rect(this->x,
  263. this->y,
  264. this->width,
  265. this->height),
  266. 0,
  267. 0,
  268. tmp->GetWidth(),
  269. tmp->GetHeight(),
  270. UnitPixel);
  271. if( this->prev != NULL && this->sidedraw == true ){
  272. if( this->scalp == NULL )
  273. tmp = this->prev;
  274. else
  275. tmp = this->scalp;
  276. width = tmp->GetWidth();
  277. height = tmp->GetHeight();
  278. if( this->scalp == NULL )
  279. zoom = this->getZoom(width,height,this->cwidth,this->cheight);
  280. else
  281. zoom = ZOOMINIT;
  282. int pwidth = (int)(zoom * width);
  283. int pheight = (int)(zoom * height);
  284. int px = (int)((this->cwidth - pwidth)/2);
  285. if( this->sidemode == LEFT && px < 0 )
  286. px = 0;
  287. else if( this->sidemode == RIGHT && px < 0 )
  288. px = this->cwidth - pwidth;
  289. int py = this->y - pheight - MARGIN - this->offrollVer;
  290. if( this->fullscreen == false )
  291. tmpgfx->DrawRectangle(this->Pen_Border,
  292. px - frame,
  293. py - frame,
  294. pwidth + frame + 1,
  295. pheight + frame + 1);
  296. tmpgfx->DrawImage(tmp,Rect(px,py,pwidth,pheight),0,0,
  297. tmp->GetWidth(),tmp->GetHeight(),UnitPixel);
  298. }
  299. if( this->next != NULL && this->sidedraw == true ){
  300. if( this->scaln == NULL )
  301. tmp = this->next;
  302. else
  303. tmp = this->scaln;
  304. width = tmp->GetWidth();
  305. height = tmp->GetHeight();
  306. if( this->scaln == NULL )
  307. zoom = this->getZoom(width,height,this->cwidth,this->cheight);
  308. else
  309. zoom = ZOOMINIT;
  310. int nwidth = (int)(zoom * width);
  311. int nheight = (int)(zoom * height);
  312. int nx = (int)((this->cwidth - nwidth)/2);
  313. if( this->sidemode == LEFT && nx < 0 )
  314. nx = 0;
  315. else if( this->sidemode == RIGHT && nx < 0 )
  316. nx = this->cwidth - nwidth;
  317. int ny = this->y + this->height + MARGIN + this->offrollVer;
  318. if( this->fullscreen == false )
  319. tmpgfx->DrawRectangle(this->Pen_Border,
  320. nx - frame,
  321. ny - frame,
  322. nwidth + frame + 1,
  323. nheight + frame + 1);
  324. tmpgfx->DrawImage(tmp,Rect(nx,ny,nwidth,nheight),0,0,
  325. tmp->GetWidth(),tmp->GetHeight(),UnitPixel);
  326. }
  327. }
  328. this->x = 0;
  329. this->y = 0;
  330. this->width = scene->GetWidth();
  331. this->height = scene->GetHeight();
  332. }
  333. else {
  334. if( this->scali == NULL )
  335. tmp = this->image;
  336. else
  337. tmp = this->scali;
  338. tmpgfx->DrawImage(tmp,
  339. Rect(0,0,this->width,this->height),
  340. 0,0,tmp->GetWidth(),tmp->GetHeight(),
  341. UnitPixel);
  342. }
  343. ReleaseMutex(this->mut_image);
  344. this->fulldraw = true;
  345. this->animate();
  346. delete tmpgfx;
  347. return scene;
  348. }
  349. void Layer::scroll(int hor, int ver)
  350. {
  351. int invalid = 2;
  352. if( (this->rollHor == this->maxrollHor && hor > 0) ||
  353. (this->rollHor == -this->maxrollHor && hor < 0 ) || hor == 0 )
  354. invalid--;
  355. if( (((this->rollVer == this->maxrollVer && ver > 0) ||
  356. (this->rollVer == this->minrollVer && ver < 0)) &&
  357. this->sidedraw == false) || ver == 0 )
  358. invalid--;
  359. if( invalid > 0 ){
  360. this->rollHor += hor;
  361. this->rollVer += ver;
  362. this->boundRoll();
  363. this->invalidate();
  364. }
  365. }
  366. void Layer::scrollSet(int x, int y)
  367. {
  368. this->rollHor = x;
  369. this->rollVer = y;
  370. this->boundRoll();
  371. this->invalidate();
  372. }
  373. void Layer::scrollHor(int val)
  374. {
  375. if( (this->rollHor == this->maxrollHor && val > 0) ||
  376. (this->rollHor == -this->maxrollHor && val < 0 ) )
  377. return;
  378. this->rollHor += val;
  379. this->boundRoll();
  380. this->invalidate();
  381. }
  382. void Layer::scrollVer(int val)
  383. {
  384. if( ((this->rollVer == this->maxrollVer && val > 0) ||
  385. (this->rollVer == this->minrollVer && val < 0)) && this->sidedraw == false )
  386. return;
  387. this->rollVer += val;
  388. this->boundRoll();
  389. this->invalidate();
  390. }
  391. void Layer::zoomer(double val)
  392. {
  393. if( this->zoom == ZOOMSTEP && val < 0 )
  394. return;
  395. if( val == NULL )
  396. return;
  397. this->zoombegin();
  398. this->unsetFitmode();
  399. this->zoom += val;
  400. this->boundZoom();
  401. this->invalidate();
  402. }
  403. void Layer::zoomat(double val)
  404. {
  405. this->zoombegin();
  406. this->unsetFitmode();
  407. this->zoom = val;
  408. this->boundZoom();
  409. this->invalidate();
  410. }
  411. void Layer::zoombegin()
  412. {
  413. this->zoomdraw = true;
  414. }
  415. void Layer::zoomend()
  416. {
  417. this->zoomdraw = false;
  418. if( this->scali != NULL )
  419. delete this->scali;
  420. if( this->scaln != NULL )
  421. delete this->scaln;
  422. if( this->scalp != NULL )
  423. delete this->scalp;
  424. this->scali = NULL;
  425. this->scaln = NULL;
  426. this->scalp = NULL;
  427. if( this->zoom < ZOOMINIT ){
  428. this->scali = this->scale(this->image);
  429. if( this->next != NULL )
  430. this->scaln = this->scale(this->next);
  431. if( this->prev != NULL )
  432. this->scalp = this->scale(this->prev);
  433. }
  434. this->invalidate();
  435. }
  436. void Layer::rotate(Image *image)
  437. {
  438. if( image == NULL )
  439. return;
  440. switch(this->rot){
  441. case 1:
  442. image->RotateFlip(Rotate90FlipNone);
  443. break;
  444. case 2:
  445. image->RotateFlip(Rotate180FlipNone);
  446. break;
  447. case 3:
  448. image->RotateFlip(Rotate270FlipNone);
  449. break;
  450. }
  451. }
  452. void Layer::rotate(int val)
  453. {
  454. if( val == NULL )
  455. return;
  456. bool rotati = true;
  457. if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT )
  458. rotati = false;
  459. this->rot = (this->rot + val) % 4;
  460. switch(val){
  461. case 1:
  462. if( rotati == true )
  463. this->image->RotateFlip(Rotate90FlipNone);
  464. if( this->next != NULL )
  465. this->next->RotateFlip(Rotate90FlipNone);
  466. if( this->prev != NULL )
  467. this->prev->RotateFlip(Rotate90FlipNone);
  468. break;
  469. case 2:
  470. if( rotati == true )
  471. this->image->RotateFlip(Rotate180FlipNone);
  472. if( this->next != NULL )
  473. this->next->RotateFlip(Rotate180FlipNone);
  474. if( this->prev != NULL )
  475. this->prev->RotateFlip(Rotate180FlipNone);
  476. break;
  477. case 3:
  478. if( rotati == true )
  479. this->image->RotateFlip(Rotate270FlipNone);
  480. if( this->next != NULL )
  481. this->next->RotateFlip(Rotate270FlipNone);
  482. if( this->prev != NULL )
  483. this->prev->RotateFlip(Rotate270FlipNone);
  484. break;
  485. }
  486. this->setFitmode();
  487. }
  488. void Layer::rotateSet()
  489. {
  490. bool rotati = true;
  491. if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT )
  492. rotati = false;
  493. switch(this->rot){
  494. case 1:
  495. if( rotati == true )
  496. this->image->RotateFlip(Rotate90FlipNone);
  497. if( this->next != NULL )
  498. this->next->RotateFlip(Rotate90FlipNone);
  499. if( this->prev != NULL )
  500. this->prev->RotateFlip(Rotate90FlipNone);
  501. break;
  502. case 2:
  503. if( rotati == true )
  504. this->image->RotateFlip(Rotate180FlipNone);
  505. if( this->next != NULL )
  506. this->next->RotateFlip(Rotate180FlipNone);
  507. if( this->prev != NULL )
  508. this->prev->RotateFlip(Rotate180FlipNone);
  509. break;
  510. case 3:
  511. if( rotati == true )
  512. this->image->RotateFlip(Rotate270FlipNone);
  513. if( this->next != NULL )
  514. this->next->RotateFlip(Rotate270FlipNone);
  515. if( this->prev != NULL )
  516. this->prev->RotateFlip(Rotate270FlipNone);
  517. break;
  518. }
  519. }
  520. void Layer::rotateReset(bool novalid)
  521. {
  522. bool rotati = true;
  523. if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT )
  524. rotati = false;
  525. switch(this->rot){
  526. case 1:
  527. if( rotati == true )
  528. image->RotateFlip(Rotate270FlipNone);
  529. if( this->next != NULL )
  530. this->next->RotateFlip(Rotate270FlipNone);
  531. if( this->prev != NULL )
  532. this->prev->RotateFlip(Rotate270FlipNone);
  533. break;
  534. case 2:
  535. if( rotati == true )
  536. image->RotateFlip(Rotate180FlipNone);
  537. if( this->next != NULL )
  538. this->next->RotateFlip(Rotate180FlipNone);
  539. if( this->prev != NULL )
  540. this->prev->RotateFlip(Rotate180FlipNone);
  541. break;
  542. case 3:
  543. if( rotati == true )
  544. this->image->RotateFlip(Rotate90FlipNone);
  545. if( this->next != NULL )
  546. this->next->RotateFlip(Rotate90FlipNone);
  547. if( this->prev != NULL )
  548. this->prev->RotateFlip(Rotate90FlipNone);
  549. break;
  550. }
  551. this->rot = 0;
  552. if( novalid == false )
  553. this->zoomend();
  554. }
  555. int Layer::getX()
  556. {
  557. return this->x;
  558. }
  559. int Layer::getY()
  560. {
  561. return this->y;
  562. }
  563. int Layer::getWidth()
  564. {
  565. return this->width;
  566. }
  567. int Layer::getHeight()
  568. {
  569. return this->height;
  570. }
  571. int Layer::getMaxrollHor()
  572. {
  573. if( this->image == NULL )
  574. return 0;
  575. RECT client;
  576. GetClientRect(this->core->getWindowHandle(),&client);
  577. WaitForSingleObject(this->mut_image,INFINITE);
  578. int width = (int)(this->zoom * this->image->GetWidth());
  579. ReleaseMutex(this->mut_image);
  580. return abs( min((int)((client.right - width)/2),0) );
  581. }
  582. int Layer::getMaxrollVer()
  583. {
  584. if( this->image == NULL )
  585. return 0;
  586. RECT client;
  587. GetClientRect(this->core->getWindowHandle(),&client);
  588. WaitForSingleObject(this->mut_image,INFINITE);
  589. int height = (int)(this->zoom * this->image->GetHeight());
  590. ReleaseMutex(this->mut_image);
  591. return abs( min((int)((client.bottom - height)/2),0) );
  592. }
  593. File *Layer::getFile()
  594. {
  595. if( this->cell != NULL )
  596. return this->cell->getFile();
  597. return NULL;
  598. }
  599. int Layer::getImageWidth()
  600. {
  601. WaitForSingleObject(this->mut_image,INFINITE);
  602. int width = this->image->GetWidth();
  603. ReleaseMutex(this->mut_image);
  604. return width;
  605. }
  606. int Layer::getImageHeight()
  607. {
  608. WaitForSingleObject(this->mut_image,INFINITE);
  609. int height = this->image->GetHeight();
  610. ReleaseMutex(this->mut_image);
  611. return height;
  612. }
  613. double Layer::getZoom()
  614. {
  615. return this->zoom;
  616. }
  617. double Layer::getZoom(int width, int height)
  618. {
  619. if( this->fitmode == NULL )
  620. return this->zoom;
  621. RECT client = this->getClientSize();
  622. return this->getZoom(width,height,client.right,client.bottom);
  623. }
  624. double Layer::getZoom(int width, int height, int cwidth, int cheight)
  625. {
  626. if( this->fitmode == NULL )
  627. return this->zoom;
  628. width += 2 * FRAME;
  629. height += 2 * FRAME;
  630. double dx, dy;
  631. if( this->fitmode == FITSCREEN || this->fitmode == FITSCREENOV ||
  632. this->fitmode == FITWIDTH || this->fitmode == FITHEIGHT ){
  633. dx = (double)cwidth / (double)width;
  634. dy = (double)cheight / (double)height;
  635. }
  636. else if( this->fitmode == FITNUMPAD ){
  637. dx = (double)(3 * cwidth) / (double)width;
  638. dy = (double)(3 * cheight) / (double)height;
  639. dx += ZOOMINIT;
  640. dy += ZOOMINIT;
  641. }
  642. if( this->fitmode == FITSCREENOV )
  643. return min(ZOOMINIT,min(dx,dy));
  644. if( this->fitmode == FITSCREEN || this->fitmode == FITNUMPAD )
  645. return min(dx,dy);
  646. if( this->fitmode == FITWIDTH )
  647. return dy;
  648. if( this->fitmode == FITHEIGHT )
  649. return dx;
  650. return this->zoom;
  651. }
  652. bool Layer::getSidedraw()
  653. {
  654. return this->sidedraw;
  655. }
  656. int Layer::getFitmode()
  657. {
  658. return this->fitmode;
  659. }
  660. void Layer::setFitmode(int mode)
  661. {
  662. //double newzoom = ZOOMINIT;
  663. if( this->fitmode == mode || mode == NULL ){
  664. this->fitmode = NULL;
  665. this->zoom = ZOOMINIT;
  666. this->zoomend();
  667. return;
  668. }
  669. else if( mode != DEFAULT ){
  670. this->fitmode = mode;
  671. this->sidedraw = false;
  672. }
  673. WaitForSingleObject(this->mut_image,INFINITE);
  674. if( this->image != NULL )
  675. this->zoom = this->getZoom(this->image->GetWidth(),this->image->GetHeight());
  676. ReleaseMutex(this->mut_image);
  677. this->zoomend();
  678. }
  679. void Layer::unsetFitmode()
  680. {
  681. if( this->fitmode != NULL ){
  682. this->fitmode = NULL;
  683. if( this->core->getGui() != NULL )
  684. this->core->getGui()->updateMenu();
  685. }
  686. }
  687. void Layer::setSidemode(int mode)
  688. {
  689. if( this->sidemode == mode )
  690. this->sidemode = NULL;
  691. else
  692. this->sidemode = mode;
  693. if( this->sidedraw == false && this->getMaxrollHor() == 0 )
  694. return;
  695. if( this->sidemode == LEFT )
  696. this->rollHor = this->getMaxrollHor();
  697. else if( this->sidemode == RIGHT )
  698. this->rollHor = -this->getMaxrollHor();
  699. this->invalidate();
  700. }
  701. int Layer::getSidemode()
  702. {
  703. return this->sidemode;
  704. }
  705. void Layer::setSidedraw()
  706. {
  707. if( this->sidedraw == false ){
  708. this->sidedraw = true;
  709. if( this->fitmode != NULL )
  710. this->setFitmode(NULL);
  711. }
  712. else
  713. this->sidedraw = false;
  714. this->loadContent(NULL);
  715. }
  716. void Layer::setMenuheight(int val)
  717. {
  718. this->menuheight = val;
  719. }
  720. void Layer::setGifDir(int dir)
  721. {
  722. WaitForSingleObject(this->mut_image,INFINITE);
  723. if( dir == DEFAULT ){
  724. if( this->gifdir == RIGHT )
  725. this->gifdir = LEFT;
  726. else
  727. this->gifdir = RIGHT;
  728. }
  729. else {
  730. if( this->gifdir != RIGHT && this->gifdir != LEFT )
  731. this->gifdir = RIGHT;
  732. else
  733. this->gifdir = dir;
  734. }
  735. ReleaseMutex(this->mut_image);
  736. }
  737. void Layer::setCancel(bool set)
  738. {
  739. this->cancel = set;
  740. }
  741. bool Layer::setWall()
  742. {
  743. bool result = false;
  744. if( this->image != NULL && this->cell != NULL ){
  745. CLSID bmpsid;
  746. Core::getEncoder(L"image/bmp", &bmpsid);
  747. FwCHAR *path = NULL;
  748. if( this->cell->getFile()->isArchived() == true ){
  749. if( this->core->getExplorer() != NULL ){
  750. path = new FwCHAR();
  751. path->getFolderFrom( this->core->getExplorer()->getArchivePath() );
  752. path->mergeWith( this->cell->getFile()->getFileName() );
  753. }
  754. else
  755. path = new FwCHAR( this->cell->getFile()->getFileName()->toWCHAR() );
  756. }
  757. else {
  758. path = new FwCHAR( this->cell->getFile()->getFilePath()->toWCHAR() );
  759. }
  760. if( this->cell->getFile()->getType() != TYPE_BITMAP )
  761. path->mergeWith(L".bmp");
  762. this->image->Save(path->toWCHAR(),&bmpsid,NULL);
  763. result = SystemParametersInfo(SPI_SETDESKWALLPAPER,0,path->toWCHAR(),
  764. SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE );
  765. delete path;
  766. }
  767. return result;
  768. }
  769. bool Layer::isCancel()
  770. {
  771. return this->cancel;
  772. }
  773. bool Layer::isContent()
  774. {
  775. if( this->image != NULL )
  776. return true;
  777. return false;
  778. }
  779. bool Layer::isPassMess()
  780. {
  781. bool result = this->passmess;
  782. this->passmess = false;
  783. return result;
  784. }
  785. void Layer::locate(int init)
  786. {
  787. RECT client = this->getClientSize();
  788. this->cwidth = client.right;
  789. this->cheight = client.bottom;
  790. if( this->image == NULL ){
  791. this->width = this->cwidth;
  792. this->height = this->cheight;
  793. }
  794. else {
  795. WaitForSingleObject(this->mut_image,INFINITE);
  796. this->zoom = this->getZoom(this->image->GetWidth(),this->image->GetHeight(),
  797. this->cwidth,this->cheight);
  798. this->width = (int)(this->zoom * this->image->GetWidth());
  799. this->height = (int)(this->zoom * this->image->GetHeight());
  800. ReleaseMutex(this->mut_image);
  801. if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT ){
  802. if( this->rot == ROT_90 || this->rot == ROT_270 ){
  803. int tmp = this->width;
  804. this->width = this->height;
  805. this->height = tmp;
  806. }
  807. }
  808. else
  809. ReleaseMutex(this->mut_animloop);
  810. }
  811. int hodiff = this->cwidth - this->width;
  812. int vediff = this->cheight - this->height;
  813. this->x = (int)(hodiff / 2);
  814. this->y = (int)(vediff / 2);
  815. this->maxrollHor = abs( min(this->x,0) );
  816. this->maxrollVer = abs( min(this->y,0) );
  817. this->minrollVer = -this->maxrollVer;
  818. this->offrollVer = 0;//max(this->y,0);
  819. if( init != NULL ){
  820. this->rollHor = 0;
  821. if( this->sidemode == LEFT )
  822. this->rollHor = this->maxrollHor;
  823. else if( this->sidemode == RIGHT )
  824. this->rollHor = -this->maxrollHor;
  825. if( init == TOP )
  826. this->rollVer = this->maxrollVer + this->offset;
  827. else if( init == BOT )
  828. this->rollVer = this->minrollVer + this->offset;
  829. this->offset = 0;
  830. }
  831. if( this->image != NULL && this->sidedraw == true ){
  832. if( this->prev != NULL )
  833. if( this->y > 0 )
  834. this->maxrollVer = this->height;
  835. else
  836. this->maxrollVer = -this->y + this->cheight + MARGIN;
  837. if( this->next != NULL )
  838. if( this->y > 0 )
  839. this->minrollVer = -this->height;
  840. else
  841. this->minrollVer = this->y - this->cheight - MARGIN;
  842. }
  843. this->boundRoll();
  844. this->x += this->rollHor;
  845. this->y += this->rollVer - this->menuheight;
  846. }
  847. void Layer::boundRoll()
  848. {
  849. this->rollHor = min(this->rollHor,this->maxrollHor);
  850. this->rollHor = max(this->rollHor,-this->maxrollHor);
  851. if( this->rollVer > this->maxrollVer ){
  852. this->offset = this->rollVer - this->maxrollVer;
  853. this->rollVer = min(this->rollVer,this->maxrollVer);
  854. if( this->image != NULL && this->sidedraw == true )
  855. this->prevContent();
  856. }
  857. if( this->rollVer < this->minrollVer ){
  858. this->offset = this->rollVer - this->minrollVer;
  859. this->rollVer = max(this->rollVer,this->minrollVer);
  860. if( this->image != NULL && this->sidedraw == true )
  861. this->nextContent();
  862. }
  863. }
  864. void Layer::boundZoom()
  865. {
  866. this->zoom = max(this->zoom,ZOOMSTEP);
  867. }
  868. RECT Layer::getClientSize()
  869. {
  870. RECT client;
  871. client.top = 0;
  872. client.left = 0;
  873. client.right = 0;
  874. client.bottom = 0;
  875. this->fullscreen = false;
  876. if( this->core->getGui() != NULL )
  877. this->fullscreen = this->core->getGui()->isFullscreen();
  878. if( this->fullscreen == true ){
  879. client.right = GetDeviceCaps(GetDC(NULL),HORZRES);
  880. client.bottom = GetDeviceCaps(GetDC(NULL),VERTRES);
  881. }
  882. else
  883. GetClientRect(this->core->getWindowHandle(),&client);
  884. return client;
  885. }
  886. void Layer::invalidate(bool full)
  887. {
  888. this->fulldraw = full;
  889. this->core->getDrawer()->invalidate(full);
  890. }
  891. Image *Layer::scale(Image *source)
  892. {
  893. if( source == NULL )
  894. return NULL;
  895. double zoom = this->zoom;
  896. if( source != this->image )
  897. zoom = this->getZoom(source->GetWidth(),source->GetHeight());
  898. int width = (int)(zoom * source->GetWidth());
  899. int height = (int)(zoom * source->GetHeight());
  900. Bitmap *bmp = new Bitmap(width,height);
  901. Graphics *gfx = Graphics::FromImage(bmp);
  902. gfx->DrawImage(source,0,0,width,height);
  903. delete gfx;
  904. return bmp;
  905. }
  906. void Layer::animate()
  907. {
  908. if( this->isTopmost() == false )
  909. return;
  910. if( WaitForSingleObject(this->mut_animloop,0) == WAIT_TIMEOUT )
  911. return;
  912. else
  913. ReleaseMutex(this->mut_animloop);
  914. if( this->cell == NULL )
  915. return;
  916. if( this->cell->getFile() == NULL )
  917. return;
  918. this->type = this->cell->getFile()->getType();
  919. if( this->type == TYPE_TIFFINTEL || this->type == TYPE_TIFFMOTOROLA ||
  920. this->type == TYPE_GIF87a || this->type == TYPE_GIF89a ){
  921. UINT dCount = this->image->GetFrameDimensionsCount();
  922. GUID *dList = new GUID[dCount];
  923. this->image->GetFrameDimensionsList(dList,dCount);
  924. this->dimension = &dList[0];
  925. this->frameCount = this->image->GetFrameCount(dimension);
  926. for( UINT i = 1; i < dCount; i++ )
  927. delete &dList[i];
  928. if( this->frameCount < 2 ){
  929. if( this->dimension != NULL )
  930. delete this->dimension;
  931. this->dimension = NULL;
  932. return;
  933. }
  934. }
  935. else
  936. return;
  937. if( this->type != TYPE_GIF87a && this->type != TYPE_GIF89a )
  938. return;
  939. this->mut_image = CreateMutex(NULL,false,NULL);
  940. this->mut_animloop = CreateMutex(NULL,false,NULL);
  941. this->mut_terminator = CreateMutex(NULL,true,NULL);
  942. this->thrd_anim = CreateThread(NULL,NULL,
  943. (LPTHREAD_START_ROUTINE)Layer::anim,
  944. this,NULL,NULL);
  945. }
  946. DWORD WINAPI Layer::anim(LPVOID param)
  947. {
  948. Layer *that = (Layer *)param;
  949. WaitForSingleObject(that->mut_animloop,INFINITE);
  950. WaitForSingleObject(that->mut_image,INFINITE);
  951. if( that->image == NULL ){
  952. ReleaseMutex(that->mut_image);
  953. return 0;
  954. }
  955. int propertySize = that->image->GetPropertyItemSize(PropertyTagFrameDelay);
  956. PropertyItem *frameDelay = (PropertyItem*) malloc(propertySize);
  957. that->image->GetPropertyItem(PropertyTagFrameDelay,propertySize,frameDelay);
  958. ReleaseMutex(that->mut_image);
  959. long *delays = (long *)frameDelay->value;
  960. bool mode = false;
  961. while( true ){
  962. if( that->isTopmost() == false )
  963. break;
  964. if( WaitForSingleObject(that->mut_terminator,0) != WAIT_TIMEOUT ){
  965. ReleaseMutex(that->mut_terminator);
  966. ReleaseMutex(that->mut_animloop);
  967. return 0;
  968. }
  969. Sleep( max((delays[that->frameThat] * 100),MINDELAY) );
  970. WaitForSingleObject(that->mut_image,INFINITE);
  971. if( that->gifdir == RIGHT )
  972. mode = that->nextFrame();
  973. else if( that->gifdir == LEFT )
  974. mode = that->prevFrame();
  975. if( that->scali != NULL )
  976. delete that->scali;
  977. that->scali = NULL;
  978. if( that->rot != ROT_0 ){
  979. that->scali = new Bitmap(that->image->GetWidth(),that->image->GetHeight());
  980. Graphics *gfx = Graphics::FromImage(that->scali);
  981. gfx->DrawImage(that->image,0,0,that->scali->GetWidth(),that->scali->GetHeight());
  982. delete gfx;
  983. }
  984. ReleaseMutex(that->mut_image);
  985. if( that->rot != ROT_0 )
  986. that->rotate(that->scali);
  987. that->invalidate(mode);
  988. }
  989. if( frameDelay != NULL )
  990. delete frameDelay;
  991. ReleaseMutex(that->mut_animloop);
  992. return 0;
  993. }
  994. bool Layer::isTopmost()
  995. {
  996. if( this->core->getDrawer()->getTopmost() == this )
  997. return true;
  998. return false;
  999. }