backbufferwnd.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <precomp.h>
  2. #include "backbufferwnd.h"
  3. #include <tataki/canvas/bltcanvas.h>
  4. #include <api/api.h>
  5. #include <tataki/region/region.h>
  6. // -----------------------------------------------------------------------
  7. BackBufferWnd::BackBufferWnd() {
  8. backbuffer = 0;
  9. canvas_w = -1;
  10. canvas_h = -1;
  11. back_buffer = NULL;
  12. }
  13. // -----------------------------------------------------------------------
  14. BackBufferWnd::~BackBufferWnd() {
  15. delete back_buffer;
  16. }
  17. //------------------------------------------------------------------------
  18. BltCanvas *BackBufferWnd::getBackBuffer() {
  19. return back_buffer;
  20. }
  21. // -----------------------------------------------------------------------
  22. int BackBufferWnd::onPaint(Canvas *canvas) {
  23. BBWND_PARENT::onPaint(canvas);
  24. if (!canvas) return 1;
  25. RECT r;
  26. getClientRect(&r);
  27. if (back_buffer && r.right-r.left > 0 && r.bottom -r.top > 0) {
  28. int w = r.right-r.left;
  29. int h = r.bottom-r.top;
  30. if (canvas_w != w || canvas_h != h) {
  31. delete back_buffer;
  32. back_buffer = new BltCanvas(w, h, getOsWindowHandle());
  33. canvas_w = w;
  34. canvas_h = h;
  35. }
  36. #ifdef _WIN32
  37. RegionI reg;
  38. canvas->getClipRgn(&reg);
  39. back_buffer->selectClipRgn(&reg);
  40. #else
  41. #warning port me
  42. #endif
  43. canvas->blit(r.left, r.top, back_buffer, 0, 0, w, h);
  44. back_buffer->selectClipRgn(NULL);
  45. }
  46. return 1;
  47. }
  48. int BackBufferWnd::onSiblingInvalidateRgn(api_region *r, ifc_window *who, int who_idx, int my_idx) {
  49. if (who_idx >= my_idx || !wantBackBuffer()) return 0;
  50. RECT rr;
  51. getClientRect(&rr);
  52. api_region *_r = getRegion();
  53. RegionI *__r=NULL;
  54. if (!_r) {
  55. __r = new RegionI();
  56. _r = __r;
  57. _r->setRect(&rr);
  58. } else {
  59. _r->offset(rr.left, rr.top);
  60. }
  61. int intersect = _r->doesIntersectRgn(r);
  62. if (intersect)
  63. r->addRegion(_r);
  64. delete __r;
  65. return intersect;
  66. }