region.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef __REGION_H
  2. #define __REGION_H
  3. #include <api/wnd/bitmap.h>
  4. #include <bfc/dispatch.h>
  5. class BaseWnd;
  6. class Canvas;
  7. class api_region;
  8. class RegionServer;
  9. #include "api_region.h"
  10. class RegionI : public api_region
  11. {
  12. public:
  13. RegionI();
  14. RegionI(const RegionI *copy);
  15. RegionI(const RECT *r);
  16. RegionI(int l, int t, int r, int b);
  17. RegionI(OSREGIONHANDLE region);
  18. RegionI(SkinBitmap *bitmap, RECT *r=NULL, int xoffset=0, int yoffset=0, bool inverted=false, int dothreshold=0, __int8 threshold=0, int threversed=0, int minalpha=1);
  19. RegionI(Canvas *c, RECT *defboundbox=NULL);
  20. virtual ~RegionI();
  21. api_region *clone();
  22. void disposeClone(api_region *r);
  23. bool ptInRegion(const POINT *pt);
  24. void offset(int x, int y);
  25. void getBox(RECT *r);
  26. void subtractRegion(const api_region *reg);
  27. void subtractRect(const RECT *r);
  28. void addRect(const RECT *r);
  29. void addRegion(const api_region *r);
  30. void andRegion(const api_region *r);
  31. void setRect(const RECT *r);
  32. void empty();
  33. int isEmpty();
  34. int equals(const api_region *r);
  35. int enclosed(const api_region *r, api_region *outside=NULL);
  36. int intersectRgn(const api_region *r, api_region *intersection);
  37. int doesIntersectRgn(const api_region *r);
  38. int intersectRect(const RECT *r, api_region *intersection);
  39. int doesIntersectRect(const RECT *r);
  40. int isRect();
  41. void scale(double sx, double sy, bool round=0);
  42. void debug(int async=0);
  43. // NONPORTABLE
  44. OSREGIONHANDLE makeWindowRegion(); // gives you a handle to a clone of the OSREGION object so you can insert it into a window's region with SetWindowRgn. ANY other use is prohibited
  45. OSREGIONHANDLE getOSHandle(); // avoid as much as you can, should be used only by WIN32-dependant classes
  46. // END NONPORTABLE
  47. int getNumRects();
  48. int enumRect(int n, RECT *r);
  49. OSREGIONHANDLE alphaToRegionRect(void *pbits32, int bmX, int bmY, int bmWidth, int bmHeight, int fullw, int fullh, int xoffset, int yoffset, bool portion, int _x, int _y, int _w, int _h, bool inverted, int dothreshold, unsigned __int8 threshold, int thinverse, int minalpha);
  50. private:
  51. inline void init();
  52. void optimize();
  53. void deoptimize();
  54. OSREGIONHANDLE hrgn;
  55. OSREGIONHANDLE alphaToRegionRect(SkinBitmap *bitmap, int xoffset, int yoffset, bool portion, int _x, int _y, int _w, int _h, bool inverted=false, int dothreshold=0, unsigned __int8 threshold=0, int thinverse=0, int minalpha=1/* 1..255*/);
  56. RECT overlay;
  57. int clonecount;
  58. RegionI *lastdebug;
  59. RegionServer *srv;
  60. RECT optrect;
  61. int optimized;
  62. protected:
  63. RECVS_DISPATCH;
  64. };
  65. class RegionServer : public Dispatchable {
  66. protected:
  67. RegionServer() {}
  68. virtual ~RegionServer() {}
  69. public:
  70. void addRef(void *client);
  71. void delRef(void *client);
  72. api_region *getRegion();
  73. enum {
  74. REGIONSERVER_ADDREF = 500,
  75. REGIONSERVER_DELREF = 550,
  76. REGIONSERVER_GETREGION = 600,
  77. };
  78. };
  79. inline void RegionServer::addRef(void *client) {
  80. _voidcall(REGIONSERVER_ADDREF, (api_region *)NULL, client);
  81. }
  82. inline void RegionServer::delRef(void *client) {
  83. _voidcall(REGIONSERVER_DELREF, client);
  84. }
  85. inline api_region * RegionServer::getRegion() {
  86. return _call(REGIONSERVER_GETREGION, (api_region *)NULL);
  87. }
  88. class RegionServerI : public RegionServer {
  89. public :
  90. RegionServerI() { numrefs = 0; }
  91. virtual ~RegionServerI() {}
  92. virtual void addRef(void *client) { numrefs++; }
  93. virtual void delRef(void *client) { numrefs--; }
  94. virtual api_region *getRegion()=0;
  95. virtual int getNumRefs() { return numrefs; }
  96. protected:
  97. RECVS_DISPATCH;
  98. private:
  99. int numrefs;
  100. };
  101. #endif