1
0

bufferpaintwnd.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include <precomp.h>
  2. #include "bufferpaintwnd.h"
  3. #include <tataki/canvas/bltcanvas.h>
  4. // -----------------------------------------------------------------------
  5. BufferPaintWnd::BufferPaintWnd() {
  6. canvas_w = -1;
  7. canvas_h = -1;
  8. render_canvas = NULL;
  9. invalidated = 1;
  10. }
  11. // -----------------------------------------------------------------------
  12. BufferPaintWnd::~BufferPaintWnd() {
  13. delete render_canvas;
  14. }
  15. // -----------------------------------------------------------------------
  16. int BufferPaintWnd::onInit() {
  17. BUFFERPAINTWND_PARENT::onInit();
  18. return 1;
  19. }
  20. // -----------------------------------------------------------------------
  21. void BufferPaintWnd::bufferPaint() {
  22. updateCanvas();
  23. if (render_canvas != NULL)
  24. onBufferPaint(render_canvas, canvas_w, canvas_h);
  25. }
  26. void BufferPaintWnd::invalidateBuffer() {
  27. invalidated = 1;
  28. invalidate();
  29. }
  30. // -----------------------------------------------------------------------
  31. void BufferPaintWnd::getBufferPaintSize(int *w, int *h) {
  32. RECT r;
  33. getClientRect(&r);
  34. if (w) *w = r.right-r.left;
  35. if (h) *h = r.bottom-r.top;
  36. }
  37. // -----------------------------------------------------------------------
  38. void BufferPaintWnd::getBufferPaintSource(RECT *r) {
  39. ASSERT(r != NULL);
  40. r->left = 0;
  41. r->right = canvas_w;
  42. r->top = 0;
  43. r->bottom = canvas_h;
  44. }
  45. // -----------------------------------------------------------------------
  46. void BufferPaintWnd::getBufferPaintDest(RECT *r) {
  47. ASSERT(r != NULL);
  48. getClientRect(r);
  49. }
  50. // -----------------------------------------------------------------------
  51. int BufferPaintWnd::onPaint(Canvas *canvas) {
  52. BUFFERPAINTWND_PARENT::onPaint(canvas);
  53. if (invalidated) bufferPaint();
  54. invalidated = 0;
  55. RECT r;
  56. getBufferPaintDest(&r);
  57. RECT sr;
  58. getBufferPaintSource(&sr);
  59. render_canvas->/*getSkinBitmap()->*/stretchToRectAlpha(canvas, &sr, &r, getPaintingAlpha());
  60. return 1;
  61. }
  62. // -----------------------------------------------------------------------
  63. int BufferPaintWnd::onResize() {
  64. if (!BUFFERPAINTWND_PARENT::onResize()) return 0;
  65. if (updateCanvas()) {
  66. invalidated = 1;
  67. invalidate();
  68. }
  69. return 1;
  70. }
  71. // -----------------------------------------------------------------------
  72. int BufferPaintWnd::updateCanvas() {
  73. int w, h;
  74. getBufferPaintSize(&w, &h);
  75. if (wantEvenAlignment()) {
  76. if (w & 1) w++;
  77. if (h & 1) h++;
  78. }
  79. if (w == 0 || h == 0) return 0;
  80. int newone = 0;
  81. if (canvas_w != w || canvas_h != h) {
  82. if (render_canvas)
  83. render_canvas->DestructiveResize(w, wantNegativeHeight() ? -h : h);
  84. else
  85. render_canvas = new BltCanvas(w, wantNegativeHeight() ? -h : h, getOsWindowHandle());
  86. canvas_w = w;
  87. canvas_h = h;
  88. newone = 1;
  89. onNewBuffer(canvas_w, canvas_h);
  90. }
  91. return newone;
  92. }