AlbumArtContainer.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "AlbumArtContainer.h"
  2. #include "api__ml_local.h"
  3. #include <tataki/bitmap/bitmap.h>
  4. #include <tataki/canvas/canvas.h>
  5. #include <assert.h>
  6. #include "AlbumArtCache.h"
  7. #include "../nde/nde.h"
  8. #include <commctrl.h>
  9. AlbumArtContainer::AlbumArtContainer() :filename(0)
  10. {
  11. references = 1;
  12. cached = CACHE_UNKNOWN;
  13. cache = 0;
  14. updateMsg.hwnd = NULL;
  15. }
  16. void AlbumArtContainer::AddRef()
  17. {
  18. references++;
  19. }
  20. void AlbumArtContainer::Release()
  21. {
  22. if (--references == 0)
  23. delete this;
  24. }
  25. AlbumArtContainer::~AlbumArtContainer()
  26. {
  27. ndestring_release(filename);
  28. if (cache) cache->Release();
  29. }
  30. void AlbumArtContainer::Reset()
  31. {
  32. if (cache)
  33. cache->Release();
  34. cache = 0;
  35. cached = AlbumArtContainer::CACHE_UNKNOWN;
  36. }
  37. void AlbumArtContainer::SetCache(SkinBitmap *bitmap, CacheStatus status)
  38. {
  39. if (cache)
  40. cache->Release();
  41. cache = bitmap;
  42. cached = status;
  43. // lets post the update message
  44. if(updateMsg.hwnd && (CACHE_CACHED == cached || CACHE_UNKNOWN == cached)) PostMessageW(updateMsg.hwnd,updateMsg.message,updateMsg.wParam,updateMsg.lParam);
  45. }
  46. int AlbumArtContainer::drawArt(DCCanvas *pCanvas, RECT *prcDst)
  47. {
  48. switch (cached)
  49. {
  50. case CACHE_NOTFOUND:
  51. return DRAW_NOART;
  52. case CACHE_LOADING:
  53. return DRAW_LOADING;
  54. case CACHE_UNKNOWN:
  55. cached = CACHE_LOADING;
  56. CreateCache(this, prcDst->right - prcDst->left, prcDst->bottom - prcDst->top);
  57. return DRAW_LOADING;
  58. case CACHE_CACHED:
  59. {
  60. if (cache->getWidth() != (prcDst->right - prcDst->left) || cache->getHeight() != (prcDst->bottom - prcDst->top))
  61. {
  62. cached = CACHE_LOADING;
  63. CreateCache(this, prcDst->right - prcDst->left, prcDst->bottom - prcDst->top);
  64. return DRAW_LOADING;
  65. }
  66. if (pCanvas) cache->blitAlpha(pCanvas, prcDst->left, prcDst->top);
  67. return DRAW_SUCCESS;
  68. }
  69. default:
  70. return DRAW_NOART; // shouldn't reach this;
  71. }
  72. }