pseudodc.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: pseudodc.h
  3. // Purpose: gwxPseudoDC class
  4. // Author: Paul Lanier
  5. // Modified by: Glynn Clements 2009-01-14
  6. // Created: 05/25/06
  7. // RCS-ID: $Id: pseudodc.h 49047 2007-10-05 18:08:39Z RD $
  8. // Copyright: (c) wxWidgets team
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _GWX_PSUEDO_DC_H_BASE_
  12. #define _GWX_PSUEDO_DC_H_BASE_
  13. //----------------------------------------------------------------------------
  14. // Base class for all gpdcOp classes
  15. //----------------------------------------------------------------------------
  16. class gpdcOp
  17. {
  18. public:
  19. // Constructor and Destructor
  20. gpdcOp() {}
  21. virtual ~gpdcOp() {}
  22. // Virtual Drawing Methods
  23. virtual void DrawToDC(wxDC *dc, bool grey=false)=0;
  24. virtual void Translate(wxCoord dx, wxCoord dy) {}
  25. virtual void CacheGrey() {}
  26. };
  27. //----------------------------------------------------------------------------
  28. // declare a list class for list of gpdcOps
  29. //----------------------------------------------------------------------------
  30. WX_DECLARE_LIST(gpdcOp, gpdcOpList);
  31. //----------------------------------------------------------------------------
  32. // Helper functions used for drawing greyed out versions of objects
  33. //----------------------------------------------------------------------------
  34. wxColour &gwxMakeColourGrey(const wxColour &c);
  35. wxBrush &gwxGetGreyBrush(wxBrush &brush);
  36. wxPen &gwxGetGreyPen(wxPen &pen);
  37. wxIcon &gwxGetGreyIcon(wxIcon &icon);
  38. wxBitmap &gwxGetGreyBitmap(wxBitmap &bmp);
  39. void gwxGreyOutImage(wxImage &img);
  40. //----------------------------------------------------------------------------
  41. // Classes derived from gpdcOp
  42. // There is one class for each method mirrored from wxDC to gwxPseudoDC
  43. //----------------------------------------------------------------------------
  44. class gpdcSetFontOp : public gpdcOp
  45. {
  46. public:
  47. gpdcSetFontOp(const wxFont& font)
  48. {m_font=font;}
  49. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetFont(m_font);}
  50. protected:
  51. wxFont m_font;
  52. };
  53. class gpdcSetBrushOp : public gpdcOp
  54. {
  55. public:
  56. gpdcSetBrushOp(const wxBrush& brush)
  57. {m_greybrush=m_brush=brush;}
  58. virtual void DrawToDC(wxDC *dc, bool grey=false)
  59. {
  60. if (!grey) dc->SetBrush(m_brush);
  61. else dc->SetBrush(m_greybrush);
  62. }
  63. virtual void CacheGrey() {m_greybrush=gwxGetGreyBrush(m_brush);}
  64. protected:
  65. wxBrush m_brush;
  66. wxBrush m_greybrush;
  67. };
  68. class gpdcSetBackgroundOp : public gpdcOp
  69. {
  70. public:
  71. gpdcSetBackgroundOp(const wxBrush& brush)
  72. {m_greybrush=m_brush=brush;}
  73. virtual void DrawToDC(wxDC *dc, bool grey=false)
  74. {
  75. if (!grey) dc->SetBackground(m_brush);
  76. else dc->SetBackground(m_greybrush);
  77. }
  78. virtual void CacheGrey() {m_greybrush=gwxGetGreyBrush(m_brush);}
  79. protected:
  80. wxBrush m_brush;
  81. wxBrush m_greybrush;
  82. };
  83. class gpdcSetPenOp : public gpdcOp
  84. {
  85. public:
  86. gpdcSetPenOp(const wxPen& pen)
  87. {m_greypen=m_pen=pen;}
  88. virtual void DrawToDC(wxDC *dc, bool grey=false)
  89. {
  90. if (!grey) dc->SetPen(m_pen);
  91. else dc->SetPen(m_greypen);
  92. }
  93. virtual void CacheGrey() {m_greypen=gwxGetGreyPen(m_pen);}
  94. protected:
  95. wxPen m_pen;
  96. wxPen m_greypen;
  97. };
  98. class gpdcSetTextBackgroundOp : public gpdcOp
  99. {
  100. public:
  101. gpdcSetTextBackgroundOp(const wxColour& colour)
  102. {m_colour=colour;}
  103. virtual void DrawToDC(wxDC *dc, bool grey=false)
  104. {
  105. if (!grey) dc->SetTextBackground(m_colour);
  106. else dc->SetTextBackground(gwxMakeColourGrey(m_colour));
  107. }
  108. protected:
  109. wxColour m_colour;
  110. };
  111. class gpdcSetTextForegroundOp : public gpdcOp
  112. {
  113. public:
  114. gpdcSetTextForegroundOp(const wxColour& colour)
  115. {m_colour=colour;}
  116. virtual void DrawToDC(wxDC *dc, bool grey=false)
  117. {
  118. if (!grey) dc->SetTextForeground(m_colour);
  119. else dc->SetTextForeground(gwxMakeColourGrey(m_colour));
  120. }
  121. protected:
  122. wxColour m_colour;
  123. };
  124. class gpdcDrawRectangleOp : public gpdcOp
  125. {
  126. public:
  127. gpdcDrawRectangleOp(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
  128. {m_x=x; m_y=y; m_w=w; m_h=h;}
  129. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawRectangle(m_x,m_y,m_w,m_h);}
  130. virtual void Translate(wxCoord dx, wxCoord dy)
  131. {m_x+=dx;m_y+=dy;}
  132. protected:
  133. wxCoord m_x,m_y,m_w,m_h;
  134. };
  135. class gpdcDrawLineOp : public gpdcOp
  136. {
  137. public:
  138. gpdcDrawLineOp(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
  139. {m_x1=x1; m_y1=y1; m_x2=x2; m_y2=y2;}
  140. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawLine(m_x1,m_y1,m_x2,m_y2);}
  141. virtual void Translate(wxCoord dx, wxCoord dy)
  142. {m_x1+=dx; m_y1+=dy; m_x2+=dx; m_y2+=dy;}
  143. protected:
  144. wxCoord m_x1,m_y1,m_x2,m_y2;
  145. };
  146. class gpdcSetBackgroundModeOp : public gpdcOp
  147. {
  148. public:
  149. gpdcSetBackgroundModeOp(int mode) {m_mode=mode;}
  150. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetBackgroundMode(m_mode);}
  151. protected:
  152. int m_mode;
  153. };
  154. class gpdcDrawTextOp : public gpdcOp
  155. {
  156. public:
  157. gpdcDrawTextOp(const wxString& text, wxCoord x, wxCoord y)
  158. {m_text=text; m_x=x; m_y=y;}
  159. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawText(m_text, m_x, m_y);}
  160. virtual void Translate(wxCoord dx, wxCoord dy)
  161. {m_x+=dx; m_y+=dy;}
  162. protected:
  163. wxString m_text;
  164. wxCoord m_x, m_y;
  165. };
  166. class gpdcClearOp : public gpdcOp
  167. {
  168. public:
  169. gpdcClearOp() {}
  170. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->Clear();}
  171. };
  172. class gpdcBeginDrawingOp : public gpdcOp
  173. {
  174. public:
  175. gpdcBeginDrawingOp() {}
  176. virtual void DrawToDC(wxDC *dc, bool grey=false) {}
  177. };
  178. class gpdcEndDrawingOp : public gpdcOp
  179. {
  180. public:
  181. gpdcEndDrawingOp() {}
  182. virtual void DrawToDC(wxDC *dc, bool grey=false) {}
  183. };
  184. class gpdcFloodFillOp : public gpdcOp
  185. {
  186. public:
  187. gpdcFloodFillOp(wxCoord x, wxCoord y, const wxColour& col,
  188. int style) {m_x=x; m_y=y; m_col=col; m_style=style;}
  189. virtual void DrawToDC(wxDC *dc, bool grey=false)
  190. {
  191. if (!grey) dc->FloodFill(m_x,m_y,m_col,m_style);
  192. else dc->FloodFill(m_x,m_y,gwxMakeColourGrey(m_col),m_style);
  193. }
  194. virtual void Translate(wxCoord dx, wxCoord dy)
  195. {m_x+=dx; m_y+=dy;}
  196. protected:
  197. wxCoord m_x,m_y;
  198. wxColour m_col;
  199. int m_style;
  200. };
  201. class gpdcCrossHairOp : public gpdcOp
  202. {
  203. public:
  204. gpdcCrossHairOp(wxCoord x, wxCoord y) {m_x=x; m_y=y;}
  205. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->CrossHair(m_x,m_y);}
  206. virtual void Translate(wxCoord dx, wxCoord dy)
  207. {m_x+=dx; m_y+=dy;}
  208. protected:
  209. wxCoord m_x,m_y;
  210. };
  211. class gpdcDrawArcOp : public gpdcOp
  212. {
  213. public:
  214. gpdcDrawArcOp(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
  215. wxCoord xc, wxCoord yc)
  216. {m_x1=x1; m_y1=y1; m_x2=x2; m_y2=y2; m_xc=xc; m_yc=yc;}
  217. virtual void DrawToDC(wxDC *dc, bool grey=false)
  218. {dc->DrawArc(m_x1,m_y1,m_x2,m_y2,m_xc,m_yc);}
  219. virtual void Translate(wxCoord dx, wxCoord dy)
  220. {m_x1+=dx; m_x2+=dx; m_y1+=dy; m_y2+=dy;}
  221. protected:
  222. wxCoord m_x1,m_x2,m_xc;
  223. wxCoord m_y1,m_y2,m_yc;
  224. };
  225. class gpdcDrawCheckMarkOp : public gpdcOp
  226. {
  227. public:
  228. gpdcDrawCheckMarkOp(wxCoord x, wxCoord y,
  229. wxCoord width, wxCoord height)
  230. {m_x=x; m_y=y; m_w=width; m_h=height;}
  231. virtual void DrawToDC(wxDC *dc, bool grey=false)
  232. {dc->DrawCheckMark(m_x,m_y,m_w,m_h);}
  233. virtual void Translate(wxCoord dx, wxCoord dy)
  234. {m_x+=dx; m_y+=dy;}
  235. protected:
  236. wxCoord m_x,m_y,m_w,m_h;
  237. };
  238. class gpdcDrawEllipticArcOp : public gpdcOp
  239. {
  240. public:
  241. gpdcDrawEllipticArcOp(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
  242. double sa, double ea)
  243. {m_x=x; m_y=y; m_w=w; m_h=h; m_sa=sa; m_ea=ea;}
  244. virtual void DrawToDC(wxDC *dc, bool grey=false)
  245. {dc->DrawEllipticArc(m_x,m_y,m_w,m_h,m_sa,m_ea);}
  246. virtual void Translate(wxCoord dx, wxCoord dy)
  247. {m_x+=dx; m_y+=dy;}
  248. protected:
  249. wxCoord m_x,m_y,m_w,m_h;
  250. double m_sa,m_ea;
  251. };
  252. class gpdcDrawPointOp : public gpdcOp
  253. {
  254. public:
  255. gpdcDrawPointOp(wxCoord x, wxCoord y)
  256. {m_x=x; m_y=y;}
  257. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawPoint(m_x,m_y);}
  258. virtual void Translate(wxCoord dx, wxCoord dy)
  259. {m_x+=dx; m_y+=dy;}
  260. protected:
  261. wxCoord m_x,m_y;
  262. };
  263. class gpdcDrawRoundedRectangleOp : public gpdcOp
  264. {
  265. public:
  266. gpdcDrawRoundedRectangleOp(wxCoord x, wxCoord y, wxCoord width,
  267. wxCoord height, double radius)
  268. {m_x=x; m_y=y; m_w=width; m_h=height; m_r=radius;}
  269. virtual void DrawToDC(wxDC *dc, bool grey=false)
  270. {dc->DrawRoundedRectangle(m_x,m_y,m_w,m_h,m_r);}
  271. virtual void Translate(wxCoord dx, wxCoord dy)
  272. {m_x+=dx; m_y+=dy;}
  273. protected:
  274. wxCoord m_x,m_y,m_w,m_h;
  275. double m_r;
  276. };
  277. class gpdcDrawEllipseOp : public gpdcOp
  278. {
  279. public:
  280. gpdcDrawEllipseOp(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
  281. {m_x=x; m_y=y; m_w=width; m_h=height;}
  282. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawEllipse(m_x,m_y,m_w,m_h);}
  283. virtual void Translate(wxCoord dx, wxCoord dy)
  284. {m_x+=dx; m_y+=dy;}
  285. protected:
  286. wxCoord m_x,m_y,m_w,m_h;
  287. };
  288. class gpdcDrawIconOp : public gpdcOp
  289. {
  290. public:
  291. gpdcDrawIconOp(const wxIcon& icon, wxCoord x, wxCoord y)
  292. {m_icon=icon; m_x=x; m_y=y;}
  293. virtual void DrawToDC(wxDC *dc, bool grey=false)
  294. {
  295. if (grey) dc->DrawIcon(m_greyicon,m_x,m_y);
  296. else dc->DrawIcon(m_icon,m_x,m_y);
  297. }
  298. virtual void CacheGrey() {m_greyicon=gwxGetGreyIcon(m_icon);}
  299. virtual void Translate(wxCoord dx, wxCoord dy)
  300. {m_x+=dx; m_y+=dy;}
  301. protected:
  302. wxIcon m_icon;
  303. wxIcon m_greyicon;
  304. wxCoord m_x,m_y;
  305. };
  306. class gpdcDrawLinesOp : public gpdcOp
  307. {
  308. public:
  309. gpdcDrawLinesOp(int n, wxPoint points[],
  310. wxCoord xoffset = 0, wxCoord yoffset = 0);
  311. virtual ~gpdcDrawLinesOp();
  312. virtual void DrawToDC(wxDC *dc, bool grey=false)
  313. {dc->DrawLines(m_n,m_points,m_xoffset,m_yoffset);}
  314. virtual void Translate(wxCoord dx, wxCoord dy)
  315. {
  316. for(int i=0; i<m_n; i++)
  317. {
  318. m_points[i].x+=dx;
  319. m_points[i].y+=dy;
  320. }
  321. }
  322. protected:
  323. int m_n;
  324. wxPoint *m_points;
  325. wxCoord m_xoffset,m_yoffset;
  326. };
  327. class gpdcDrawPolygonOp : public gpdcOp
  328. {
  329. public:
  330. gpdcDrawPolygonOp(int n, wxPoint points[],
  331. wxCoord xoffset = 0, wxCoord yoffset = 0,
  332. int fillStyle = wxODDEVEN_RULE);
  333. virtual ~gpdcDrawPolygonOp();
  334. virtual void DrawToDC(wxDC *dc, bool grey=false)
  335. {dc->DrawPolygon(m_n,m_points,m_xoffset,m_yoffset,m_fillStyle);}
  336. virtual void Translate(wxCoord dx, wxCoord dy)
  337. {
  338. for(int i=0; i<m_n; i++)
  339. {
  340. m_points[i].x+=dx;
  341. m_points[i].y+=dy;
  342. }
  343. }
  344. protected:
  345. int m_n;
  346. wxPoint *m_points;
  347. wxCoord m_xoffset,m_yoffset;
  348. int m_fillStyle;
  349. };
  350. class gpdcDrawPolyPolygonOp : public gpdcOp
  351. {
  352. public:
  353. gpdcDrawPolyPolygonOp(int n, int count[], wxPoint points[],
  354. wxCoord xoffset = 0, wxCoord yoffset = 0,
  355. int fillStyle = wxODDEVEN_RULE);
  356. virtual ~gpdcDrawPolyPolygonOp();
  357. virtual void DrawToDC(wxDC *dc, bool grey=false)
  358. {dc->DrawPolyPolygon(m_n,m_count,m_points,
  359. m_xoffset,m_yoffset,m_fillStyle);}
  360. virtual void Translate(wxCoord dx, wxCoord dy)
  361. {
  362. for(int i=0; i<m_totaln; i++)
  363. {
  364. m_points[i].x += dx;
  365. m_points[i].y += dy;
  366. }
  367. }
  368. protected:
  369. int m_n;
  370. int m_totaln;
  371. int *m_count;
  372. wxPoint *m_points;
  373. wxCoord m_xoffset, m_yoffset;
  374. int m_fillStyle;
  375. };
  376. class gpdcDrawRotatedTextOp : public gpdcOp
  377. {
  378. public:
  379. gpdcDrawRotatedTextOp(const wxString& text, wxCoord x, wxCoord y, double angle)
  380. {m_text=text; m_x=x; m_y=y; m_angle=angle;}
  381. virtual void DrawToDC(wxDC *dc, bool grey=false)
  382. {dc->DrawRotatedText(m_text,m_x,m_y,m_angle);}
  383. virtual void Translate(wxCoord dx, wxCoord dy)
  384. {m_x+=dx; m_y+=dy;}
  385. protected:
  386. wxString m_text;
  387. wxCoord m_x,m_y;
  388. double m_angle;
  389. };
  390. class gpdcDrawBitmapOp : public gpdcOp
  391. {
  392. public:
  393. gpdcDrawBitmapOp(const wxBitmap &bmp, wxCoord x, wxCoord y,
  394. bool useMask = false)
  395. {m_bmp=bmp; m_x=x; m_y=y; m_useMask=useMask;}
  396. virtual void DrawToDC(wxDC *dc, bool grey=false)
  397. {
  398. if (grey) dc->DrawBitmap(m_greybmp,m_x,m_y,m_useMask);
  399. else dc->DrawBitmap(m_bmp,m_x,m_y,m_useMask);
  400. }
  401. virtual void CacheGrey() {m_greybmp=gwxGetGreyBitmap(m_bmp);}
  402. virtual void Translate(wxCoord dx, wxCoord dy)
  403. {m_x+=dx; m_y+=dy;}
  404. protected:
  405. wxBitmap m_bmp;
  406. wxBitmap m_greybmp;
  407. wxCoord m_x,m_y;
  408. bool m_useMask;
  409. };
  410. class gpdcDrawLabelOp : public gpdcOp
  411. {
  412. public:
  413. gpdcDrawLabelOp(const wxString& text,
  414. const wxBitmap& image,
  415. const wxRect& rect,
  416. int alignment = wxALIGN_LEFT | wxALIGN_TOP,
  417. int indexAccel = -1)
  418. {m_text=text; m_image=image; m_rect=rect;
  419. m_align=alignment; m_iAccel=indexAccel;}
  420. virtual void DrawToDC(wxDC *dc, bool grey=false)
  421. {dc->DrawLabel(m_text,m_image,m_rect,m_align,m_iAccel);}
  422. virtual void Translate(wxCoord dx, wxCoord dy)
  423. {m_rect.x+=dx; m_rect.y+=dy;}
  424. protected:
  425. wxString m_text;
  426. wxBitmap m_image;
  427. wxRect m_rect;
  428. int m_align;
  429. int m_iAccel;
  430. };
  431. #if wxUSE_SPLINES
  432. class gpdcDrawSplineOp : public gpdcOp
  433. {
  434. public:
  435. gpdcDrawSplineOp(int n, wxPoint points[]);
  436. virtual ~gpdcDrawSplineOp();
  437. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->DrawSpline(m_n,m_points);}
  438. virtual void Translate(wxCoord dx, wxCoord dy)
  439. {
  440. int i;
  441. for(i=0; i<m_n; i++)
  442. m_points[i].x+=dx; m_points[i].y+=dy;
  443. }
  444. protected:
  445. wxPoint *m_points;
  446. int m_n;
  447. };
  448. #endif // wxUSE_SPLINES
  449. #if wxUSE_PALETTE
  450. class gpdcSetPaletteOp : public gpdcOp
  451. {
  452. public:
  453. gpdcSetPaletteOp(const wxPalette& palette) {m_palette=palette;}
  454. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetPalette(m_palette);}
  455. protected:
  456. wxPalette m_palette;
  457. };
  458. #endif // wxUSE_PALETTE
  459. class gpdcSetLogicalFunctionOp : public gpdcOp
  460. {
  461. public:
  462. gpdcSetLogicalFunctionOp(int function) {m_function=function;}
  463. virtual void DrawToDC(wxDC *dc, bool grey=false) {dc->SetLogicalFunction(m_function);}
  464. protected:
  465. int m_function;
  466. };
  467. //----------------------------------------------------------------------------
  468. // gpdcObject type to contain list of operations for each real (Python) object
  469. //----------------------------------------------------------------------------
  470. class gpdcObject
  471. {
  472. public:
  473. gpdcObject(int id)
  474. {m_id=id; m_bounded=false; m_oplist.DeleteContents(true);
  475. m_greyedout=false;}
  476. virtual ~gpdcObject() {m_oplist.Clear();}
  477. // Protected Member Access
  478. void SetId(int id) {m_id=id;}
  479. int GetId() {return m_id;}
  480. void SetBounds(wxRect& rect) {m_bounds=rect; m_bounded=true;}
  481. wxRect GetBounds() {return m_bounds;}
  482. void SetBounded(bool bounded) {m_bounded=bounded;}
  483. bool IsBounded() {return m_bounded;}
  484. void SetGreyedOut(bool greyout=true);
  485. bool GetGreyedOut() {return m_greyedout;}
  486. // Op List Management Methods
  487. void Clear() {m_oplist.Clear();}
  488. void AddOp(gpdcOp *op)
  489. {
  490. m_oplist.Append(op);
  491. if (m_greyedout) op->CacheGrey();
  492. }
  493. int GetLen() {return m_oplist.GetCount();}
  494. virtual void Translate(wxCoord dx, wxCoord dy);
  495. // Drawing Method
  496. virtual void DrawToDC(wxDC *dc);
  497. protected:
  498. int m_id; // id of object (associates this gpdcObject
  499. // with a Python object with same id)
  500. wxRect m_bounds; // bounding rect of this object
  501. bool m_bounded; // true if bounds is valid, false by default
  502. gpdcOpList m_oplist; // list of operations for this object
  503. bool m_greyedout; // if true then draw this object in greys only
  504. };
  505. //----------------------------------------------------------------------------
  506. // Declare a wxList to hold all the objects. List order reflects drawing
  507. // order (Z order) and is the same order as objects are added to the list
  508. //----------------------------------------------------------------------------
  509. class gpdcObjectList;
  510. WX_DECLARE_LIST(gpdcObject, gpdcObjectList);
  511. //Declare a hashmap that maps from ids to nodes in the object list.
  512. WX_DECLARE_HASH_MAP(
  513. int,
  514. gpdcObject *,
  515. wxIntegerHash,
  516. wxIntegerEqual,
  517. gpdcObjectHash
  518. );
  519. // ----------------------------------------------------------------------------
  520. // gwxPseudoDC class
  521. // ----------------------------------------------------------------------------
  522. // This is the actual PseudoDC class
  523. // This class stores a list of recorded dc operations in m_list
  524. // and plays them back to a real dc using DrawToDC or DrawToDCClipped.
  525. // Drawing methods are mirrored from wxDC but add nodes to m_list
  526. // instead of doing any real drawing.
  527. // ----------------------------------------------------------------------------
  528. class gwxPseudoDC : public wxObject
  529. {
  530. public:
  531. gwxPseudoDC()
  532. {m_currId=-1; m_lastObject=NULL; m_objectlist.DeleteContents(true);m_objectIndex.clear();}
  533. ~gwxPseudoDC();
  534. // ------------------------------------------------------------------------
  535. // List managment methods
  536. //
  537. void RemoveAll();
  538. int GetLen();
  539. // ------------------------------------------------------------------------
  540. // methods for managing operations by ID
  541. //
  542. // Set the Id for all subsequent operations (until SetId is called again)
  543. void SetId(int id) {m_currId = id;}
  544. // Remove all the operations associated with an id so it can be redrawn
  545. void ClearId(int id);
  546. // Remove the object node (and all operations) associated with an id
  547. void RemoveId(int id);
  548. // Set the bounding rect of a given object
  549. // This will create an object node if one doesn't exist
  550. void SetIdBounds(int id, wxRect& rect);
  551. void GetIdBounds(int id, wxRect& rect);
  552. // Translate all the operations for this id
  553. void TranslateId(int id, wxCoord dx, wxCoord dy);
  554. // Grey-out an object
  555. void SetIdGreyedOut(int id, bool greyout=true);
  556. bool GetIdGreyedOut(int id);
  557. // Find Objects at a point. Returns Python list of id's
  558. // sorted in reverse drawing order (result[0] is top object)
  559. // This version looks at drawn pixels
  560. PyObject *FindObjects(wxCoord x, wxCoord y,
  561. wxCoord radius=1, const wxColor& bg=*wxWHITE);
  562. // This version only looks at bounding boxes
  563. PyObject *FindObjectsByBBox(wxCoord x, wxCoord y);
  564. // ------------------------------------------------------------------------
  565. // Playback Methods
  566. //
  567. // draw to dc but skip objects known to be outside of rect
  568. // This is a coarse level of clipping to speed things up
  569. // when lots of objects are off screen and doesn't affect the dc level
  570. // clipping
  571. void DrawToDCClipped(wxDC *dc, const wxRect& rect);
  572. void DrawToDCClippedRgn(wxDC *dc, const wxRegion& region);
  573. // draw to dc with no clipping (well the dc will still clip)
  574. void DrawToDC(wxDC *dc);
  575. // draw a single object to the dc
  576. void DrawIdToDC(int id, wxDC *dc);
  577. // ------------------------------------------------------------------------
  578. // Hit Detection Methods
  579. //
  580. // returns list of object with a drawn pixel within radius pixels of (x,y)
  581. // the list is in reverse draw order so last drawn is first in list
  582. // PyObject *HitTest(wxCoord x, wxCoord y, double radius)
  583. // returns list of objects whose bounding boxes include (x,y)
  584. // PyObject *HitTestBB(wxCoord x, wxCoord y)
  585. // ------------------------------------------------------------------------
  586. // Methods mirrored from wxDC
  587. //
  588. void FloodFill(wxCoord x, wxCoord y, const wxColour& col,
  589. int style = wxFLOOD_SURFACE)
  590. {AddToList(new gpdcFloodFillOp(x,y,col,style));}
  591. void FloodFill(const wxPoint& pt, const wxColour& col,
  592. int style = wxFLOOD_SURFACE)
  593. { FloodFill(pt.x, pt.y, col, style); }
  594. void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
  595. {AddToList(new gpdcDrawLineOp(x1, y1, x2, y2));}
  596. void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
  597. { DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
  598. void CrossHair(wxCoord x, wxCoord y)
  599. {AddToList(new gpdcCrossHairOp(x,y));}
  600. void CrossHair(const wxPoint& pt)
  601. { CrossHair(pt.x, pt.y); }
  602. void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
  603. wxCoord xc, wxCoord yc)
  604. {AddToList(new gpdcDrawArcOp(x1,y1,x2,y2,xc,yc));}
  605. void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
  606. { DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
  607. void DrawCheckMark(wxCoord x, wxCoord y,
  608. wxCoord width, wxCoord height)
  609. {AddToList(new gpdcDrawCheckMarkOp(x,y,width,height));}
  610. void DrawCheckMark(const wxRect& rect)
  611. { DrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
  612. void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
  613. double sa, double ea)
  614. {AddToList(new gpdcDrawEllipticArcOp(x,y,w,h,sa,ea));}
  615. void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
  616. double sa, double ea)
  617. { DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
  618. void DrawPoint(wxCoord x, wxCoord y)
  619. {AddToList(new gpdcDrawPointOp(x,y));}
  620. void DrawPoint(const wxPoint& pt)
  621. { DrawPoint(pt.x, pt.y); }
  622. void DrawPolygon(int n, wxPoint points[],
  623. wxCoord xoffset = 0, wxCoord yoffset = 0,
  624. int fillStyle = wxODDEVEN_RULE)
  625. {AddToList(new gpdcDrawPolygonOp(n,points,xoffset,yoffset,fillStyle));}
  626. void DrawPolyPolygon(int n, int count[], wxPoint points[],
  627. wxCoord xoffset = 0, wxCoord yoffset = 0,
  628. int fillStyle = wxODDEVEN_RULE)
  629. {AddToList(new gpdcDrawPolyPolygonOp(n,count,points,xoffset,yoffset,fillStyle));}
  630. void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
  631. {AddToList(new gpdcDrawRectangleOp(x, y, width, height));}
  632. void DrawRectangle(const wxPoint& pt, const wxSize& sz)
  633. { DrawRectangle(pt.x, pt.y, sz.x, sz.y); }
  634. void DrawRectangle(const wxRect& rect)
  635. { DrawRectangle(rect.x, rect.y, rect.width, rect.height); }
  636. void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
  637. double radius)
  638. {AddToList(new gpdcDrawRoundedRectangleOp(x,y,width,height,radius));}
  639. void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
  640. double radius)
  641. { DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
  642. void DrawRoundedRectangle(const wxRect& r, double radius)
  643. { DrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
  644. void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
  645. { DrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
  646. void DrawCircle(const wxPoint& pt, wxCoord radius)
  647. { DrawCircle(pt.x, pt.y, radius); }
  648. void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
  649. {AddToList(new gpdcDrawEllipseOp(x,y,width,height));}
  650. void DrawEllipse(const wxPoint& pt, const wxSize& sz)
  651. { DrawEllipse(pt.x, pt.y, sz.x, sz.y); }
  652. void DrawEllipse(const wxRect& rect)
  653. { DrawEllipse(rect.x, rect.y, rect.width, rect.height); }
  654. void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
  655. {AddToList(new gpdcDrawIconOp(icon,x,y));}
  656. void DrawIcon(const wxIcon& icon, const wxPoint& pt)
  657. { DrawIcon(icon, pt.x, pt.y); }
  658. void DrawLines(int n, wxPoint points[],
  659. wxCoord xoffset = 0, wxCoord yoffset = 0)
  660. {AddToList(new gpdcDrawLinesOp(n,points,xoffset,yoffset));}
  661. void DrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
  662. bool useMask = false)
  663. {AddToList(new gpdcDrawBitmapOp(bmp,x,y,useMask));}
  664. void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
  665. bool useMask = false)
  666. { DrawBitmap(bmp, pt.x, pt.y, useMask); }
  667. void DrawText(const wxString& text, wxCoord x, wxCoord y)
  668. {AddToList(new gpdcDrawTextOp(text, x, y));}
  669. void DrawText(const wxString& text, const wxPoint& pt)
  670. { DrawText(text, pt.x, pt.y); }
  671. void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
  672. {AddToList(new gpdcDrawRotatedTextOp(text,x,y,angle));}
  673. void DrawRotatedText(const wxString& text, const wxPoint& pt, double angle)
  674. { DrawRotatedText(text, pt.x, pt.y, angle); }
  675. // this version puts both optional bitmap and the text into the given
  676. // rectangle and aligns is as specified by alignment parameter; it also
  677. // will emphasize the character with the given index if it is != -1
  678. void DrawLabel(const wxString& text,
  679. const wxBitmap& image,
  680. const wxRect& rect,
  681. int alignment = wxALIGN_LEFT | wxALIGN_TOP,
  682. int indexAccel = -1)
  683. {AddToList(new gpdcDrawLabelOp(text,image,rect,alignment,indexAccel));}
  684. void DrawLabel(const wxString& text, const wxRect& rect,
  685. int alignment = wxALIGN_LEFT | wxALIGN_TOP,
  686. int indexAccel = -1)
  687. { DrawLabel(text, wxNullBitmap, rect, alignment, indexAccel); }
  688. /*?????? I don't think that the source dc would stick around
  689. void Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
  690. wxDC *source, wxCoord xsrc, wxCoord ysrc,
  691. int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
  692. {AddToList(new gpdcBlitOp(xdest,ydest,width,height,source,xsrc,
  693. ysrc,rop,useMask,xsrcMask,ysrcMask));}
  694. void Blit(const wxPoint& destPt, const wxSize& sz,
  695. wxDC *source, const wxPoint& srcPt,
  696. int rop = wxCOPY, bool useMask = false, const wxPoint& srcPtMask = wxDefaultPosition)
  697. {
  698. Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y,
  699. rop, useMask, srcPtMask.x, srcPtMask.y);
  700. }
  701. ??????*/
  702. #if wxUSE_SPLINES
  703. void DrawSpline(int n, wxPoint points[])
  704. {AddToList(new gpdcDrawSplineOp(n,points));}
  705. #endif // wxUSE_SPLINES
  706. #if wxUSE_PALETTE
  707. void SetPalette(const wxPalette& palette)
  708. {AddToList(new gpdcSetPaletteOp(palette));}
  709. #endif // wxUSE_PALETTE
  710. void SetLogicalFunction(int function)
  711. {AddToList(new gpdcSetLogicalFunctionOp(function));}
  712. void SetFont(const wxFont& font)
  713. {AddToList(new gpdcSetFontOp(font));}
  714. void SetPen(const wxPen& pen)
  715. {AddToList(new gpdcSetPenOp(pen));}
  716. void SetBrush(const wxBrush& brush)
  717. {AddToList(new gpdcSetBrushOp(brush));}
  718. void SetBackground(const wxBrush& brush)
  719. {AddToList(new gpdcSetBackgroundOp(brush));}
  720. void SetBackgroundMode(int mode)
  721. {AddToList(new gpdcSetBackgroundModeOp(mode));}
  722. void SetTextBackground(const wxColour& colour)
  723. {AddToList(new gpdcSetTextBackgroundOp(colour));}
  724. void SetTextForeground(const wxColour& colour)
  725. {AddToList(new gpdcSetTextForegroundOp(colour));}
  726. void Clear()
  727. {AddToList(new gpdcClearOp());}
  728. void BeginDrawing()
  729. {AddToList(new gpdcBeginDrawingOp());}
  730. void EndDrawing()
  731. {AddToList(new gpdcEndDrawingOp());}
  732. protected:
  733. // ------------------------------------------------------------------------
  734. // protected helper methods
  735. void AddToList(gpdcOp *newOp);
  736. gpdcObject *FindObject(int id, bool create=false);
  737. // ------------------------------------------------------------------------
  738. // Data members
  739. //
  740. int m_currId; // id to use for operations done on the PseudoDC
  741. gpdcObject *m_lastObject; // used to find last used object quickly
  742. gpdcObjectList m_objectlist; // list of objects
  743. gpdcObjectHash m_objectIndex; //id->object lookup index
  744. };
  745. #endif