diff --git a/src/prefs/datatranslations/IconView.cpp b/src/prefs/datatranslations/IconView.cpp new file mode 100644 index 0000000000..b4569eeb4f --- /dev/null +++ b/src/prefs/datatranslations/IconView.cpp @@ -0,0 +1,66 @@ +/*****************************************************************************/ +// IconView +// IconView.cpp +// Author: Michael Wilber +// +// +// This BView based object displays an icon +// +// +// Copyright (C) Haiku, uses the MIT license +/*****************************************************************************/ + +#include +#include +#include "IconView.h" + +IconView::IconView(const BRect &frame, const char *name, + uint32 resize, uint32 flags) + : BView(frame, name, resize, flags) +{ + fDrawIcon = false; + + SetDrawingMode(B_OP_OVER); + // to preserve transparent areas of the icon + + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + fIconBitmap = new BBitmap(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_CMAP8); +} + +IconView::~IconView() +{ + delete fIconBitmap; + fIconBitmap = NULL; +} + +bool +IconView::SetIconFromNodeInfo(BNodeInfo &info) +{ + fDrawIcon = false; + if (info.GetTrackerIcon(fIconBitmap) != B_OK) + return false; + + fDrawIcon = true; + Invalidate(); + return true; +} + +bool +IconView::DrawIcon(bool draw) +{ + bool prev = fDrawIcon; + fDrawIcon = draw; + if (prev != fDrawIcon) + Invalidate(); + + return prev; +} + +void +IconView::Draw(BRect area) +{ + if (fDrawIcon) + DrawBitmap(fIconBitmap); +} + diff --git a/src/prefs/datatranslations/IconView.h b/src/prefs/datatranslations/IconView.h new file mode 100644 index 0000000000..fe84912993 --- /dev/null +++ b/src/prefs/datatranslations/IconView.h @@ -0,0 +1,37 @@ +/*****************************************************************************/ +// IconView +// IconView.h +// Author: Michael Wilber +// +// This BView based object displays an icon +// +// Copyright (C) Haiku, uses the MIT license +/*****************************************************************************/ + +#ifndef ICONVIEW_H +#define ICONVIEW_H + +#include +#include +#include + +class IconView : public BView { +public: + IconView(const BRect &frame, const char *name, uint32 resize, uint32 flags); + // sets up the view + ~IconView(); + + bool DrawIcon(bool draw); + + bool SetIconFromNodeInfo(BNodeInfo &info); + + virtual void Draw(BRect area); + // draws the icon +private: + BBitmap *fIconBitmap; + // the icon + bool fDrawIcon; + // whether or not the icon is drawn +}; + +#endif // #ifndef ICONVIEW_H