SkinCursorElement.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "api.h"
  2. #include "SkinCursorElement.h"
  3. #include "PaletteManager.h"
  4. #include <tataki/canvas/bltcanvas.h>
  5. SkinCursorElement::SkinCursorElement(const wchar_t *_id, const wchar_t *_bitmapid, int _x, int _y, int script_id, int secondarycounter, const wchar_t *path, ifc_xmlreaderparams *p)
  6. {
  7. id = _id;
  8. bitmap = _bitmapid;
  9. x = _x;
  10. y = _y;
  11. icon = NULL;
  12. scriptid = script_id;
  13. seccount = secondarycounter;
  14. if (p != NULL)
  15. {
  16. for (size_t i = 0;i != p->getNbItems();i++)
  17. params.addItem(p->getItemName(i), p->getItemValue(i));
  18. }
  19. rootpath = path;
  20. }
  21. SkinCursorElement::~SkinCursorElement()
  22. {
  23. if (icon != 0)
  24. {
  25. #ifdef WIN32
  26. DestroyIcon(icon);
  27. #else
  28. DebugString("portme: ~skincursorelement\n");
  29. #endif
  30. }
  31. }
  32. void SkinCursorElement::makeCursor()
  33. {
  34. if (icon)
  35. {
  36. #ifdef WIN32
  37. DestroyIcon(icon);
  38. #else
  39. DebugString("portme: skincursorelement::makeCursor\n");
  40. #endif
  41. icon = NULL;
  42. }
  43. #ifdef WIN32
  44. ICONINFO info;
  45. info.fIcon = FALSE;
  46. info.xHotspot = x;
  47. info.yHotspot = y;
  48. // make AND bitmask from alpha channel
  49. SkinBitmap bm(bitmap);
  50. int *bits = (int *)bm.getBits();
  51. int _x = bm.getX();
  52. int _y = bm.getY();
  53. int w = bm.getWidth();
  54. int h = bm.getHeight();
  55. int fw = bm.getFullWidth();
  56. //CUT: int fh = bm.getFullHeight();
  57. BltCanvas c(w, h, NULL, 8);
  58. unsigned __int8 *d = (unsigned __int8 *)c.getBits();
  59. for (int i = 0;i < h;i++)
  60. {
  61. int *p = bits + _x + x + (_y + y) * fw;
  62. int j = w;
  63. while (j--)
  64. {
  65. int a = (*p++ & 0xFF000000) >> 24;
  66. *d++ = (a > 0x7F) ? 0xFF : 0;
  67. }
  68. }
  69. // copy bits onto a canvas to get hbitmap
  70. BltCanvas cc(w, h);
  71. bm.blit(&cc, 0, 0);
  72. info.hbmMask = c.getBitmap();
  73. info.hbmColor = cc.getBitmap();
  74. // create cursor
  75. icon = CreateIconIndirect(&info);
  76. #else
  77. DebugString("portme: skincursorelement::makeCursor\n");
  78. #endif
  79. }
  80. OSCURSOR SkinCursorElement::getCursor()
  81. {
  82. if (icon == INVALIDOSCURSORHANDLE)
  83. makeCursor();
  84. return icon;
  85. }
  86. SkinItem *SkinCursorElement::getAncestor()
  87. {
  88. return WASABI_API_PALETTE->getCursorAncestor(this);
  89. }