Copyright 1999, Be Incorporated. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#include "BitmapMenuItem.h"
#include "constants.h"
BitmapMenuItem::BitmapMenuItem(const char* name, const BBitmap& bitmap,
BMessage* message, char shortcut, uint32 modifiers)
: BMenuItem(name, message, shortcut, modifiers),
m_bitmap(bitmap.Bounds(), bitmap.ColorSpace())
{
m_bitmap.SetBits(bitmap.Bits(), bitmap.BitsLength(),
0, bitmap.ColorSpace());
}
void BitmapMenuItem::Draw(void)
{
BMenu* menu = Menu();
if (menu) {
BRect itemFrame = Frame();
BRect bitmapFrame = itemFrame;
bitmapFrame.InsetBy(2, 2);
menu->SetDrawingMode(B_OP_COPY);
menu->SetHighColor(BKG_GREY);
menu->FillRect(itemFrame);
menu->DrawBitmap(&m_bitmap, bitmapFrame);
if (IsSelected()) {
menu->SetDrawingMode(B_OP_INVERT);
menu->SetHighColor(0,0,0);
menu->FillRect(itemFrame);
}
}
}
void BitmapMenuItem::GetContentSize(float* width, float* height)
{
GetBitmapSize(width, height);
}
void BitmapMenuItem::GetBitmapSize(float* width, float* height)
{
BRect r = m_bitmap.Bounds();
*width = r.Width() + 4;
*height = r.Height() + 4;
}