- Add method in DeviceClass to draw something representative for the kind of device

- Adopt it in Preferences
(Joerg Meyer & me)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30405 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2009-04-25 18:40:00 +00:00
parent 57e7daa5a4
commit 155fa31ec6
5 changed files with 136 additions and 76 deletions
+7
View File
@@ -6,6 +6,7 @@
#define _DEVICE_CLASS_H #define _DEVICE_CLASS_H
#include <String.h> #include <String.h>
#include <View.h>
namespace Bluetooth { namespace Bluetooth {
@@ -15,6 +16,10 @@ namespace Bluetooth {
class DeviceClass { class DeviceClass {
public: public:
static const uint8 PixelsForIcon = 32;
static const uint8 IconInsets = 5;
DeviceClass(uint8 record[3]) DeviceClass(uint8 record[3])
{ {
SetRecord(record); SetRecord(record);
@@ -68,6 +73,8 @@ public:
void DumpDeviceClass(BString&); void DumpDeviceClass(BString&);
void Draw(BView* view, const BPoint& point);
private: private:
uint32 record; uint32 record;
+87
View File
@@ -312,4 +312,91 @@ DeviceClass::DumpDeviceClass(BString& string)
string << "."; string << ".";
} }
void
DeviceClass::Draw(BView* view, const BPoint& point)
{
rgb_color kBlack = { 0,0,0,0 };
rgb_color kBlue = { 28,110,157,0 };
rgb_color kWhite = { 255,255,255,0 };
view->SetHighColor(kBlue);
view->FillRoundRect(BRect(point.x + IconInsets, point.y + IconInsets,
point.x + IconInsets + PixelsForIcon, point.y + IconInsets + PixelsForIcon), 5, 5);
view->SetHighColor(kWhite);
switch (GetMajorDeviceClass()) {
case 2: // phone
view->StrokeRoundRect(BRect(point.x + IconInsets + uint(PixelsForIcon/4),
point.y + IconInsets + 6,
point.x + IconInsets + uint(PixelsForIcon*3/4),
point.y + IconInsets + PixelsForIcon - 2), 2, 2);
view->StrokeRect(BRect(point.x + IconInsets + uint(PixelsForIcon/4) + 4,
point.y + IconInsets + 10,
point.x + IconInsets + uint(PixelsForIcon*3/4) - 4,
point.y + IconInsets + uint(PixelsForIcon*3/4)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/4) + 4,
point.y + IconInsets + PixelsForIcon - 6),
BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4) - 4,
point.y + IconInsets + PixelsForIcon - 6));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/4) + 4,
point.y + IconInsets + PixelsForIcon - 4),
BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4) - 4,
point.y + IconInsets + PixelsForIcon - 4));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/4) + 4,
point.y + IconInsets + 2),
BPoint(point.x + IconInsets + uint(PixelsForIcon/4) + 4,
point.y + IconInsets + 6));
break;
case 3: // LAN
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/4),
point.y + IconInsets + uint(PixelsForIcon*3/8)),
BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4),
point.y + IconInsets + uint(PixelsForIcon*3/8)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon*5/8),
point.y + IconInsets + uint(PixelsForIcon/8)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4),
point.y + IconInsets + uint(PixelsForIcon*5/8)),
BPoint(point.x + IconInsets + uint(PixelsForIcon/4),
point.y + IconInsets + uint(PixelsForIcon*5/8)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon*3/8),
point.y + IconInsets + uint(PixelsForIcon*7/8)));
break;
case 4: // audio/video
view->StrokeRect(BRect(point.x + IconInsets + uint(PixelsForIcon/4),
point.y + IconInsets + uint(PixelsForIcon*3/8),
point.x + IconInsets + uint(PixelsForIcon*3/8),
point.y + IconInsets + uint(PixelsForIcon*5/8)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon*3/8),
point.y + IconInsets + uint(PixelsForIcon*3/8)),
BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4),
point.y + IconInsets + uint(PixelsForIcon/8)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4),
point.y + IconInsets + uint(PixelsForIcon*7/8)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon*3/8),
point.y + IconInsets + uint(PixelsForIcon*5/8)));
break;
default: // Bluetooth Logo
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/4),
point.y + IconInsets + uint(PixelsForIcon*3/4)),
BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4),
point.y + IconInsets + uint(PixelsForIcon/4)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/2),
point.y + IconInsets +2));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/2),
point.y + IconInsets + PixelsForIcon - 2));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon*3/4),
point.y + IconInsets + uint(PixelsForIcon*3/4)));
view->StrokeLine(BPoint(point.x + IconInsets + uint(PixelsForIcon/4),
point.y + IconInsets + uint(PixelsForIcon/4)));
break;
}
view->SetHighColor(kBlack);
}
} }
@@ -22,7 +22,6 @@ BluetoothDeviceView::BluetoothDeviceView(BRect frame, BluetoothDevice* bDevice,
{ {
SetViewColor(B_TRANSPARENT_COLOR); SetViewColor(B_TRANSPARENT_COLOR);
SetLowColor(0,0,0); SetLowColor(0,0,0);
//BRect iDontCare(0,0,0,0);
SetLayout(new BGroupLayout(B_VERTICAL)); SetLayout(new BGroupLayout(B_VERTICAL));
@@ -40,14 +39,14 @@ BluetoothDeviceView::BluetoothDeviceView(BRect frame, BluetoothDevice* bDevice,
fManufacturerProperties = new BStringView("manufacturer", ""); fManufacturerProperties = new BStringView("manufacturer", "");
fBuffersProperties = new BStringView("buffers", ""); fBuffersProperties = new BStringView("buffers", "");
fIcon = new BitmapView(new BBitmap(BRect(0, 0, 64 - 1, 64 - 1), B_RGBA32)); fIcon = new BView(BRect(0, 0, 32 - 1, 32 - 1),"Icon", B_FOLLOW_ALL, B_WILL_DRAW);
fIcon->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fIcon->SetViewColor(0,0,0);
SetBluetoothDevice(bDevice); SetBluetoothDevice(bDevice);
AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10) AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10)
.Add(fIcon) .Add(fIcon)
.AddGlue()
.Add(BGroupLayoutBuilder(B_VERTICAL) .Add(BGroupLayoutBuilder(B_VERTICAL)
.Add(fName) .Add(fName)
.AddGlue() .AddGlue()
@@ -100,6 +99,7 @@ BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice)
bDevice->GetDeviceClass().GetMinorDeviceClass(str); bDevice->GetDeviceClass().GetMinorDeviceClass(str);
fClass->SetText(str.String()); fClass->SetText(str.String());
bDevice->GetDeviceClass().Draw(fIcon, BPoint(Bounds().left, Bounds().top));
uint32 value; uint32 value;
@@ -5,11 +5,11 @@
#ifndef BLUETOOTHDEVICEVIEW_H_ #ifndef BLUETOOTHDEVICEVIEW_H_
#define BLUETOOTHDEVICEVIEW_H_ #define BLUETOOTHDEVICEVIEW_H_
#include <View.h>
#include <Message.h>
#include <Invoker.h>
#include <Box.h> #include <Box.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Invoker.h>
#include <Message.h>
#include <View.h>
#include <bluetooth/BluetoothDevice.h> #include <bluetooth/BluetoothDevice.h>
@@ -45,7 +45,7 @@ protected:
BStringView* fBuffersProperties; BStringView* fBuffersProperties;
BitmapView* fIcon; BView* fIcon;
}; };
@@ -84,6 +84,4 @@ class BitmapView : public BView
}; };
#endif #endif
+20 -52
View File
@@ -8,33 +8,31 @@
#include <bluetooth/bdaddrUtils.h> #include <bluetooth/bdaddrUtils.h>
#include <bluetooth/BluetoothDevice.h> #include <bluetooth/BluetoothDevice.h>
#include "../media/iconfile.h" /*#include "../media/iconfile.h"*/
#include "DeviceListItem.h" #include "DeviceListItem.h"
#define PIXELS_FOR_ICON 32
#define INSETS 5 #define INSETS 5
#define TEXT_ROWS 2 #define TEXT_ROWS 2
namespace Bluetooth { namespace Bluetooth {
DeviceListItem::DeviceListItem(BluetoothDevice* bDevice) DeviceListItem::DeviceListItem(BluetoothDevice* bDevice)
: BListItem(), : BListItem()
fDevice(bDevice) , fDevice(bDevice)
{ {
SetDevice(fDevice); SetDevice(fDevice);
} }
DeviceListItem::DeviceListItem(bdaddr_t bdaddr, DeviceClass dClass, int32 rssi) DeviceListItem::DeviceListItem(bdaddr_t bdaddr, DeviceClass dClass, int32 rssi)
: BListItem(), : BListItem()
fDevice(NULL), , fDevice(NULL)
fAddress(bdaddr), , fAddress(bdaddr)
fClass(dClass), , fClass(dClass)
fName("unknown"), , fName("unknown")
fRSSI(rssi) , fRSSI(rssi)
{ {
} }
@@ -81,7 +79,7 @@ DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete)
font_height finfo; font_height finfo;
be_plain_font->GetHeight(&finfo); be_plain_font->GetHeight(&finfo);
BPoint point = BPoint(itemRect.left + PIXELS_FOR_ICON + 2*INSETS, itemRect.bottom - finfo.descent + 1); BPoint point = BPoint(itemRect.left + DeviceClass::PixelsForIcon + 2*INSETS, itemRect.bottom - finfo.descent + 1);
owner->SetFont(be_fixed_font); owner->SetFont(be_fixed_font);
owner->SetHighColor(kBlack); owner->SetHighColor(kBlack);
owner->MovePenTo(point); owner->MovePenTo(point);
@@ -95,13 +93,15 @@ DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete)
owner->DrawString(secondLine.String()); owner->DrawString(secondLine.String());
point -= BPoint(0, (finfo.ascent + finfo.descent + finfo.leading)); point -= BPoint(0, (finfo.ascent + finfo.descent + finfo.leading) + INSETS);
owner->SetFont(be_plain_font); owner->SetFont(be_plain_font);
owner->MovePenTo(point); owner->MovePenTo(point);
owner->DrawString(fName.String()); owner->DrawString(fName.String());
// TODO: Generalize this fClass.Draw(owner, BPoint(itemRect.left, itemRect.top));
#if 0
switch (fClass.GetMajorDeviceClass()) { switch (fClass.GetMajorDeviceClass()) {
case 1: case 1:
{ {
@@ -122,44 +122,11 @@ DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete)
itemRect.left + INSETS + PIXELS_FOR_ICON, itemRect.top + INSETS + PIXELS_FOR_ICON)); itemRect.left + INSETS + PIXELS_FOR_ICON, itemRect.top + INSETS + PIXELS_FOR_ICON));
} }
break; break;
case 2: // phone
owner->StrokeRoundRect(BRect(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4),
itemRect.top + INSETS + 6,
itemRect.left + INSETS + uint(PIXELS_FOR_ICON*3/4),
itemRect.top + INSETS + PIXELS_FOR_ICON - 2), 2, 2);
owner->StrokeRect(BRect(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4) + 4,
itemRect.top + INSETS + 10,
itemRect.left + INSETS + uint(PIXELS_FOR_ICON*3/4) - 4,
itemRect.top + INSETS + uint(PIXELS_FOR_ICON*3/4)));
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4) + 4,
itemRect.top + INSETS + PIXELS_FOR_ICON - 6),
BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON*3/4) - 4,
itemRect.top + INSETS + PIXELS_FOR_ICON - 6));
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4) + 4,
itemRect.top + INSETS + PIXELS_FOR_ICON - 4),
BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON*3/4) - 4,
itemRect.top + INSETS + PIXELS_FOR_ICON - 4));
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4) + 4,
itemRect.top + INSETS + 2),
BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4) + 4,
itemRect.top + INSETS + 6));
break;
default: // Bluetooth Logo
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4),
itemRect.top + INSETS + uint(PIXELS_FOR_ICON*3/4)),
BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON*3/4),
itemRect.top + INSETS + uint(PIXELS_FOR_ICON/4)));
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/2),
itemRect.top + INSETS +2));
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/2),
itemRect.top + INSETS + PIXELS_FOR_ICON - 2));
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON*3/4),
itemRect.top + INSETS + uint(PIXELS_FOR_ICON*3/4)));
owner->StrokeLine(BPoint(itemRect.left + INSETS + uint(PIXELS_FOR_ICON/4),
itemRect.top + INSETS + uint(PIXELS_FOR_ICON/4)));
}
// TODO: Draw rssi }
#endif
owner->SetHighColor(kBlack);
} }
@@ -171,7 +138,8 @@ DeviceListItem::Update(BView *owner, const BFont *font)
font_height height; font_height height;
font->GetHeight(&height); font->GetHeight(&height);
SetHeight((height.ascent + height.descent + height.leading) * TEXT_ROWS + TEXT_ROWS*INSETS); SetHeight(MAX((height.ascent + height.descent + height.leading) * TEXT_ROWS + (TEXT_ROWS+1)*INSETS,
DeviceClass::PixelsForIcon + 2 * INSETS));
} }