tb_image_widget.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef TB_IMAGE_WIDGET_H
  6. #define TB_IMAGE_WIDGET_H
  7. #include "../tb_widgets.h"
  8. #ifdef TB_IMAGE
  9. #include "tb_image_manager.h"
  10. namespace tb {
  11. /** TBImageWidget is a widget showing a image loaded by TBImageManager,
  12. constrained in size to its skin.
  13. If you need to show a image from the skin, you can use TBSkinImage. */
  14. class TBImageWidget : public TBWidget
  15. {
  16. public:
  17. // For safe typecasting
  18. TBOBJECT_SUBCLASS(TBImageWidget, TBWidget);
  19. TBImageWidget() {}
  20. void SetImage(const TBImage &image) { m_image = image; }
  21. void SetImage(const char *filename) { m_image = g_image_manager->GetImage(filename); }
  22. int32 GetImageWidth() { return m_image.Width(); }
  23. int32 GetImageHeight() { return m_image.Height(); }
  24. virtual PreferredSize OnCalculatePreferredContentSize(const SizeConstraints &constraints);
  25. virtual void OnInflate(const INFLATE_INFO &info);
  26. virtual void OnPaint(const PaintProps &paint_props);
  27. private:
  28. TBImage m_image;
  29. };
  30. }; // namespace tb
  31. #endif // TB_IMAGE
  32. #endif // TB_IMAGE_WIDGET_H