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
This commit is contained in:
parent
1841471ea4
commit
8a8da59c02
|
@ -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 <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
|
@ -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 <View.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
#include <NodeInfo.h>
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in New Issue