1
0

gradientwnd.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <precomp.h>
  2. #include "gradientwnd.h"
  3. // NOTE
  4. // works now ;)
  5. GradientWnd::GradientWnd()
  6. : bitmap(4,4, getOsWindowHandle())
  7. {
  8. cache_w = cache_h = 4;
  9. last_w = last_h = -1;
  10. recreate = 1;
  11. setReverseColors(TRUE);
  12. }
  13. GradientWnd::~GradientWnd()
  14. {
  15. WASABI_API_SYSCB->syscb_deregisterCallback(static_cast<SkinCallbackI*>(this));
  16. }
  17. int GradientWnd::onInit ()
  18. {
  19. int r = GRADIENTWND_PARENT::onInit();
  20. WASABI_API_SYSCB->syscb_registerCallback(static_cast<SkinCallbackI*>(this));
  21. return r;
  22. }
  23. int GradientWnd::onPaint(Canvas *canvas)
  24. {
  25. ASSERT(canvas != NULL);
  26. RECT cr = clientRect();
  27. int w = cr.right - cr.left, h = cr.bottom - cr.top;
  28. if (w && h)
  29. {
  30. if (w != last_w || h != last_h)
  31. {
  32. recreate=1;
  33. }
  34. if (w > cache_w || h > cache_h)
  35. {
  36. cache_w = max(w, cache_w);
  37. cache_h = max(h, cache_h);
  38. // round up to nearest 4
  39. cache_w = (cache_w+3) & ~3;
  40. cache_h = (cache_h+3) & ~3;
  41. bitmap.DestructiveResize(cache_w,cache_h,32);
  42. recreate = 1;
  43. }
  44. if (recreate)
  45. {
  46. ARGB32 *bits = static_cast<ARGB32*>(bitmap.getBits());
  47. renderGradient(bits, w, h, /*pitch=*/cache_w);
  48. last_w = w;
  49. last_h = h;
  50. recreate=0;
  51. }
  52. RECT src = {0,0,w,h};
  53. bitmap./*getSkinBitmap()->*/blitToRect(canvas, &src, &cr, getPaintingAlpha());
  54. //bitmap./*getSkinBitmap()->*/blitAlpha(canvas, cr.left, cr.top, getPaintingAlpha());
  55. }
  56. return 1;
  57. }
  58. void GradientWnd::onParamChange()
  59. {
  60. invalidate();
  61. recreate = 1;
  62. }
  63. int GradientWnd::skincb_onColorThemeChanged(const wchar_t *newcolortheme)
  64. {
  65. // TODO: This will refresh after ca 1 sec - we need an instand redraw
  66. invalidate();
  67. recreate = 1;
  68. return 0;
  69. }