1
0

canvas.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. //NONPORTABLE: the interface is portable, but the implementation sure isn't
  2. #ifndef _CANVAS_H
  3. #define _CANVAS_H
  4. #if defined _WIN64 || defined _WIN32
  5. #include <ddraw.h>
  6. #endif
  7. //#include <bfc/common.h>
  8. #include <tataki/export.h>
  9. class Canvas;
  10. class MemCanvasBmp;
  11. class BaseWnd;
  12. class ifc_window;
  13. class api_region;
  14. class SkinBitmap;
  15. #include <bfc/stack.h>
  16. #include <api/service/svcs/svc_font.h> // for STDFONT_* stuff. should make a std_font thingy later
  17. #include <bfc/dispatch.h>
  18. enum {
  19. #ifdef WIN32
  20. PENSTYLE_SOLID = PS_SOLID,
  21. PENSTYLE_DASH = PS_DASH,
  22. PENSTYLE_DOT = PS_DOT,
  23. #else
  24. PENSTYLE_SOLID = LineSolid,
  25. PENSTYLE_DASH = LineDoubleDash,
  26. PENSTYLE_DOT = LineDoubleDash,
  27. #endif
  28. };
  29. #include <tataki/canvas/ifc_canvas.h>
  30. class ifc_canvas;
  31. class RegionI;
  32. typedef struct
  33. {
  34. int style;
  35. int width;
  36. COLORREF color;
  37. HPEN hpen;
  38. }
  39. penstruct;
  40. class TATAKIAPI NOVTABLE Canvas : public ifc_canvas
  41. {
  42. protected:
  43. Canvas();
  44. public:
  45. virtual ~Canvas();
  46. // ifc_canvas stuff
  47. HDC getHDC();
  48. ifc_window *getRootWnd();
  49. void *getBits();
  50. void getOffsets(int *x, int *y);
  51. bool isFixedCoords();
  52. bool getDim(int *w, int *h, int *p);
  53. void setBaseWnd(BaseWnd *b);
  54. // end ifc_canvas stuff
  55. virtual BaseWnd *getBaseWnd();
  56. // graphics commands
  57. void fillRect(const RECT *r, COLORREF color);
  58. void fillRectAlpha(const RECT *r, COLORREF color, int alpha);
  59. void fillRgn(RegionI *r, COLORREF color);
  60. void drawRect(const RECT *r, int solid, COLORREF color, int alpha = 255);
  61. // text commands
  62. const wchar_t *getTextFont();
  63. int getTextSize();
  64. int getTextBold();
  65. int getTextAntialias();
  66. int getTextOpaque();
  67. int getTextUnderline();
  68. int getTextItalic();
  69. int getTextAlign();
  70. COLORREF getTextColor();
  71. COLORREF getTextBkColor();
  72. void pushPen(COLORREF color);
  73. void pushPen(int style, int width, COLORREF color);
  74. void popPen();
  75. int getPenStyle();
  76. COLORREF getPenColor();
  77. int getPenWidth();
  78. // normal text
  79. void textOut(int x, int y, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
  80. void textOut(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
  81. void textOutEllipsed(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
  82. // returns height used
  83. void textOutWrapped(int x, int y, int w, int h, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
  84. void textOutWrappedPathed(int x, int y, int w, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
  85. void textOutCentered(RECT *r, const wchar_t *txt, const Wasabi::FontInfo *fontInfo);
  86. int getTextWidth(const wchar_t *text, const Wasabi::FontInfo *fontInfo);
  87. int getTextHeight(const wchar_t *text, const Wasabi::FontInfo *fontInfo);
  88. void getTextExtent(const wchar_t *text, int *w, int *h, const Wasabi::FontInfo *fontInfo);
  89. int getTextHeight(const Wasabi::FontInfo *fontInfo)
  90. {
  91. return getTextHeight(L"M", fontInfo);
  92. }
  93. void selectClipRgn(api_region *r);
  94. int getClipBox(RECT *r); // returns 0 if no clipping region
  95. int getClipRgn(api_region *r); // returns 0 if no clipping region
  96. // Deprecated?
  97. void moveTo(int x, int y);
  98. void lineTo(int x, int y);
  99. void lineDraw(int fromX, int fromY, int toX, int toY);
  100. void drawSysObject(const RECT *r, int sysobj, int alpha = 255);
  101. void blit(int srcx, int srcy, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
  102. void blitAlpha(ifc_canvas *canvas, int x, int y, int alpha = 255);
  103. void blitToRect(ifc_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
  104. void stretch(ifc_canvas *canvas, int x, int y, int w, int h);
  105. // src* are in 16.16 fixed point
  106. void stretchblit(int srcx, int srcy, int srcw, int srch, Canvas *dest, int dstx, int dsty, int dstw, int dsth);
  107. void stretchToRectAlpha(ifc_canvas *canvas, RECT *src, RECT *dst, int alpha = 255);
  108. void antiAliasTo(Canvas *dest, int w, int h, int aafactor);
  109. int getXOffset() const
  110. {
  111. return xoffset;
  112. }
  113. int getYOffset() const
  114. {
  115. return yoffset;
  116. }
  117. void offsetRect(RECT *r);
  118. void debug();
  119. void colorToColor(COLORREF from, COLORREF to, RECT *r);
  120. double getSystemFontScale();
  121. static void premultiply(ARGB32 *m_pBits, int nwords, int newalpha = -1);
  122. protected:
  123. const Wasabi::FontInfo *getFontInfo()
  124. {
  125. if (userFontInfo)
  126. return userFontInfo;
  127. else
  128. return &canvasFontInfo;
  129. }
  130. RECVS_DISPATCH;
  131. HDC hdc;
  132. void *bits;
  133. int width, height, pitch;
  134. bool fcoord;
  135. int xoffset, yoffset;
  136. BaseWnd *srcwnd;
  137. Wasabi::FontInfo canvasFontInfo; // to hold our defaults
  138. const Wasabi::FontInfo *userFontInfo; // passed from someone calling this function. usually is NULL
  139. private:
  140. Stack<penstruct> penstack;
  141. int penstyle;
  142. COLORREF pencolor;
  143. int penwidth;
  144. #ifdef WIN32
  145. HPEN defpen;
  146. HPEN curpen;
  147. #endif
  148. #ifdef LINUX
  149. int raster_x, raster_y;
  150. #endif
  151. };
  152. namespace DrawSysObj
  153. {
  154. enum {
  155. BUTTON, BUTTON_PUSHED, BUTTON_DISABLED,
  156. OSBUTTON, OSBUTTON_PUSHED, OSBUTTON_DISABLED,
  157. OSBUTTON_CLOSE, OSBUTTON_CLOSE_PUSHED, OSBUTTON_CLOSE_DISABLED,
  158. OSBUTTON_MINIMIZE, OSBUTTON_MINIMIZE_PUSHED, OSBUTTON_MINIMIZE_DISABLED,
  159. OSBUTTON_MAXIMIZE, OSBUTTON_MAXIMIZE_PUSHED, OSBUTTON_MAXIMIZE_DISABLED,
  160. };
  161. };
  162. class TATAKIAPI WndCanvas : public Canvas
  163. {
  164. public:
  165. WndCanvas();
  166. WndCanvas(BaseWnd *basewnd);
  167. virtual ~WndCanvas();
  168. // address client area
  169. int attachToClient(BaseWnd *basewnd);
  170. //CUT // address entire window
  171. //CUT int attachToWnd(HWND _hWnd); // NONPORTABLE: avoid! mostly for mainwnd
  172. private:
  173. HWND hWnd;
  174. };
  175. class TATAKIAPI PaintCanvas : public Canvas
  176. {
  177. public:
  178. PaintCanvas();
  179. virtual ~PaintCanvas();
  180. int beginPaint(BaseWnd *basewnd);
  181. int beginPaint(HWND wnd);
  182. void getRcPaint(RECT *r);
  183. private: // NONPORTABLE
  184. HWND hWnd;
  185. PAINTSTRUCT ps;
  186. };
  187. class BltCanvas;
  188. class TATAKIAPI PaintBltCanvas : public Canvas
  189. {
  190. public:
  191. PaintBltCanvas();
  192. virtual ~PaintBltCanvas();
  193. int beginPaint(BaseWnd *basewnd);
  194. int beginPaintNC(BaseWnd *basewnd);
  195. void *getBits();
  196. void getRcPaint(RECT *r);
  197. private: // NONPORTABLE
  198. HWND hWnd;
  199. PAINTSTRUCT ps;
  200. HDC wnddc;
  201. HBITMAP hbmp, prevbmp;
  202. bool nonclient;
  203. #ifdef LINUX
  204. BltCanvas *blitter;
  205. #endif
  206. };
  207. class TATAKIAPI MemCanvas : public Canvas
  208. {
  209. public:
  210. MemCanvas();
  211. virtual ~MemCanvas();
  212. int createCompatible(Canvas *canvas);
  213. private:
  214. };
  215. class TATAKIAPI DCCanvas : public Canvas
  216. {
  217. public:
  218. DCCanvas(HDC clone = NULL, BaseWnd *srcWnd = NULL);
  219. virtual ~DCCanvas();
  220. int cloneDC(HDC clone, BaseWnd *srcWnd = NULL);
  221. };
  222. class TATAKIAPI SysCanvas : public Canvas
  223. {
  224. public:
  225. SysCanvas();
  226. virtual ~SysCanvas();
  227. };
  228. /* benski>
  229. a quick Canvas class to be created on-the-fly when you need to retrieve information about fonts
  230. e.g. getTextExtent
  231. don't try to draw with it or bad things will happen.
  232. */
  233. class TATAKIAPI TextInfoCanvas : public Canvas
  234. {
  235. public:
  236. TextInfoCanvas(BaseWnd *basewnd);
  237. virtual ~TextInfoCanvas();
  238. private:
  239. HWND hWnd;
  240. };
  241. class TATAKIAPI DCBltCanvas : public Canvas
  242. {
  243. public:
  244. DCBltCanvas();
  245. virtual ~DCBltCanvas();
  246. int cloneDC(HDC clone, RECT *r, BaseWnd *srcWnd = NULL);
  247. int setOrigDC(HDC neworigdc); // set to null to prevent commitdc on delete, non null to change destination dc
  248. int commitDC(void); // allows commit to DC without deleting
  249. #if 0
  250. int cloneCanvas(ifc_canvas *clone, RECT *r);
  251. #endif
  252. protected:
  253. HDC origdc;
  254. RECT rect;
  255. HBITMAP hbmp, prevbmp;
  256. };
  257. class TATAKIAPI DCExBltCanvas : public DCBltCanvas
  258. {
  259. public:
  260. DCExBltCanvas(HWND hWnd, HRGN hrgnClip, DWORD flags);
  261. ~DCExBltCanvas();
  262. private:
  263. HWND hwnd;
  264. };
  265. // note: getBaseWnd() returns NULL for this class
  266. class TATAKIAPI BaseCloneCanvas : public Canvas
  267. {
  268. public:
  269. BaseCloneCanvas(ifc_canvas *cloner = NULL);
  270. virtual ~BaseCloneCanvas();
  271. int clone(ifc_canvas *cloner);
  272. };
  273. #ifdef WIN32
  274. class TATAKIAPI DDSurfaceCanvas : public Canvas
  275. {
  276. public:
  277. DDSurfaceCanvas(LPDIRECTDRAWSURFACE surface, int w, int h);
  278. virtual ~DDSurfaceCanvas();
  279. int isready();
  280. void enter();
  281. void exit();
  282. private:
  283. LPDIRECTDRAWSURFACE surf;
  284. int _w, _h;
  285. };
  286. #endif
  287. class TATAKIAPI BitsCanvas : public Canvas
  288. {
  289. public:
  290. BitsCanvas(void *_bits, int _w, int _h)
  291. {
  292. bits=_bits;
  293. width=_w;
  294. height=_h;
  295. pitch=_w;
  296. }
  297. };
  298. enum
  299. {
  300. ALIGN_LEFT,
  301. ALIGN_CENTER,
  302. ALIGN_RIGHT
  303. };
  304. #endif