autobitmap.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef _AUTOBITMAP_H
  2. #define _AUTOBITMAP_H
  3. #include "bitmap.h"
  4. #include <api/syscb/callbacks/syscb.h>
  5. #include <api/syscb/callbacks/skincb.h>
  6. #include <tataki/export.h>
  7. #ifdef DROP_BITMAP_ON_IDLE
  8. #include <api/timer/timerclient.h>
  9. #define DROP_BITMAP_ANCESTOR , public TimerClientDI
  10. #else
  11. #define DROP_BITMAP_ANCESTOR
  12. #endif
  13. class TATAKIAPI AutoSkinBitmap : public SysCallback DROP_BITMAP_ANCESTOR {
  14. public:
  15. AutoSkinBitmap(const wchar_t *_name=NULL);
  16. virtual ~AutoSkinBitmap();
  17. const wchar_t *setBitmap(const wchar_t *_name=NULL);
  18. int setBitmap(int _id=0);
  19. // call this when you get freeResources called on you
  20. // doesn't hurt to call as much as you want
  21. void reset();
  22. void reload() { getBitmap(); } // force a reload
  23. // this loads the bitmap if necessary
  24. SkinBitmap *getBitmap();
  25. operator SkinBitmap *() { return getBitmap(); }
  26. const wchar_t *operator =(const wchar_t *_name) { return setBitmap(_name); }
  27. int operator =(int _id) { return setBitmap(_id); }
  28. const wchar_t *getBitmapName();
  29. void setHInstanceBitmapColorGroup(const wchar_t *_colorgroup);
  30. enum
  31. {
  32. RESAMPLING_MODE_NONE = 0,
  33. RESAMPLING_MODE_SUPERSAMPLING = 1,
  34. };
  35. void setResamplingMode(int mode);
  36. int getResamplingMode();
  37. // feel free to add more methods here to help make using this class
  38. // transparent...
  39. int getWidth() { return getBitmap()->getWidth(); };
  40. int getHeight() { return getBitmap()->getHeight(); };
  41. void stretchToRectAlpha(ifc_canvas *canvas, RECT *r, int alpha=255) {
  42. getBitmap()->stretchToRectAlpha(canvas, r, alpha);
  43. }
  44. void stretchToRectAlpha(ifc_canvas *canvas, RECT *r, RECT *dest, int alpha=255) {
  45. getBitmap()->stretchToRectAlpha(canvas, r, dest, alpha);
  46. }
  47. void stretchToRect(ifc_canvas *canvas, RECT *r) {
  48. getBitmap()->stretchToRect(canvas, r);
  49. }
  50. void blitAlpha(ifc_canvas *canvas, int x, int y, int alpha=255) {
  51. getBitmap()->blitAlpha(canvas, x, y, alpha);
  52. }
  53. #ifdef _WIN32
  54. void setHInstance(HINSTANCE hinstance); // use this if you use autoskinbitmap and resource in a wac
  55. #endif
  56. #ifdef DROP_BITMAP_ON_IDLE
  57. virtual void timerclient_timerCallback(int id);
  58. #endif
  59. protected:
  60. FOURCC getEventType() { return SysCallback::SKINCB; }
  61. int notify(int msg, intptr_t param1 = 0, intptr_t param2 = 0)
  62. {
  63. if (msg == SkinCallback::RESET)
  64. return skincb_onReset();
  65. else
  66. return 0;
  67. }
  68. int skincb_onReset();
  69. #ifdef DROP_BITMAP_ON_IDLE
  70. virtual void tryUnload();
  71. #endif
  72. private:
  73. int use;
  74. int id;
  75. wchar_t *name;
  76. wchar_t *colorgroup;
  77. SkinBitmap *bitmap;
  78. int resamplingMode;
  79. #ifdef _WIN32
  80. HINSTANCE myInstance;
  81. #endif
  82. #ifdef DROP_BITMAP_ON_IDLE
  83. uint32_t lastuse;
  84. #endif
  85. protected:
  86. RECVS_DISPATCH;
  87. };
  88. #endif