From 8a8da59c0289616ead6d1fb87829c754323a53ab Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Sun, 7 Nov 2004 16:56:58 +0000 Subject: [PATCH] Moved icon drawing out of the BWindow class and into this BView class to fix the repainting issues. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9828 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/datatranslations/IconView.cpp | 66 +++++++++++++++++++++++++ src/prefs/datatranslations/IconView.h | 37 ++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/prefs/datatranslations/IconView.cpp create mode 100644 src/prefs/datatranslations/IconView.h 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