PictureView.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2009, Pier Luigi Fiorini. All rights reserved.
  3. * Distributed under the terms of the MIT License.
  4. *
  5. * Authors:
  6. * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
  7. */
  8. #include <Bitmap.h>
  9. #include <TranslationUtils.h>
  10. #include "PictureView.h"
  11. PictureView::PictureView(const char* name, const char* filename, uint32 flags)
  12. : BView(name, flags),
  13. fBitmap(NULL),
  14. fWidth(0.0f),
  15. fHeight(0.0f)
  16. {
  17. // Set transparent
  18. SetViewColor(B_TRANSPARENT_COLOR);
  19. // Try to get the image
  20. fBitmap = BTranslationUtils::GetBitmap(filename);
  21. if (fBitmap) {
  22. BRect frame(fBitmap->Bounds());
  23. fWidth = frame.Width();
  24. fHeight = frame.Height();
  25. } else
  26. return;
  27. ResizeTo(fWidth, fHeight);
  28. }
  29. PictureView::~PictureView()
  30. {
  31. delete fBitmap;
  32. fBitmap = NULL;
  33. }
  34. status_t
  35. PictureView::InitCheck()
  36. {
  37. if (fBitmap != NULL)
  38. return B_OK;
  39. return B_ERROR;
  40. }
  41. BSize
  42. PictureView::MinSize()
  43. {
  44. return BSize(fWidth, fHeight);
  45. }
  46. BSize
  47. PictureView::MaxSize()
  48. {
  49. return MinSize();
  50. }
  51. BSize
  52. PictureView::PreferredSize()
  53. {
  54. return MinSize();
  55. }
  56. void
  57. PictureView::Draw(BRect frame)
  58. {
  59. if (fBitmap) {
  60. SetDrawingMode(B_OP_ALPHA);
  61. SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
  62. DrawBitmap(fBitmap, fBitmap->Bounds(),
  63. Bounds(), B_FILTER_BITMAP_BILINEAR);
  64. }
  65. }