tb_skin_util.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #include "tb_skin_util.h"
  6. namespace tb {
  7. static int GetFadeoutSize(int scrolled_distance, int fadeout_length)
  8. {
  9. // Make it appear gradually
  10. //float factor = scrolled_distance / 10.f;
  11. //factor = CLAMP(factor, 0.5f, 1);
  12. //return (int)(fadeout_length * factor);
  13. return scrolled_distance > 0 ? fadeout_length : 0;
  14. }
  15. void DrawEdgeFadeout(const TBRect &dst_rect, TBID skin_x, TBID skin_y,
  16. int left, int top, int right, int bottom)
  17. {
  18. if (TBSkinElement *skin = g_tb_skin->GetSkinElement(skin_x))
  19. {
  20. if (skin->bitmap)
  21. {
  22. int bw = skin->bitmap->Width();
  23. int bh = skin->bitmap->Height();
  24. int dw;
  25. if ((dw = GetFadeoutSize(left, bw)) > 0)
  26. g_renderer->DrawBitmap(TBRect(dst_rect.x, dst_rect.y, dw, dst_rect.h), TBRect(0, 0, bw, bh), skin->bitmap);
  27. if ((dw = GetFadeoutSize(right, bw)) > 0)
  28. g_renderer->DrawBitmap(TBRect(dst_rect.x + dst_rect.w - dw, dst_rect.y, dw, dst_rect.h), TBRect(bw, 0, -bw, bh), skin->bitmap);
  29. }
  30. }
  31. if (TBSkinElement *skin = g_tb_skin->GetSkinElement(skin_y))
  32. {
  33. if (skin->bitmap)
  34. {
  35. int bw = skin->bitmap->Width();
  36. int bh = skin->bitmap->Height();
  37. int dh;
  38. if ((dh = GetFadeoutSize(top, bh)) > 0)
  39. g_renderer->DrawBitmap(TBRect(dst_rect.x, dst_rect.y, dst_rect.w, dh), TBRect(0, 0, bw, bh), skin->bitmap);
  40. if ((dh = GetFadeoutSize(bottom, bh)) > 0)
  41. g_renderer->DrawBitmap(TBRect(dst_rect.x, dst_rect.y + dst_rect.h - dh, dst_rect.w, dh), TBRect(0, bh, bw, -bh), skin->bitmap);
  42. }
  43. }
  44. }
  45. }; // namespace tb