From 155fa31ec619414bb0e0fb1ffe9ad913e4ecd398 Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Sat, 25 Apr 2009 18:40:00 +0000 Subject: [PATCH] - 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 --- headers/os/bluetooth/DeviceClass.h | 7 ++ src/kits/bluetooth/DeviceClass.cpp | 87 +++++++++++++++++++ .../bluetooth/BluetoothDeviceView.cpp | 10 +-- .../bluetooth/BluetoothDeviceView.h | 26 +++--- src/preferences/bluetooth/DeviceListItem.cpp | 82 ++++++----------- 5 files changed, 136 insertions(+), 76 deletions(-) diff --git a/headers/os/bluetooth/DeviceClass.h b/headers/os/bluetooth/DeviceClass.h index ce89278d4a..b2df2e8eb3 100644 --- a/headers/os/bluetooth/DeviceClass.h +++ b/headers/os/bluetooth/DeviceClass.h @@ -6,6 +6,7 @@ #define _DEVICE_CLASS_H #include +#include namespace Bluetooth { @@ -15,6 +16,10 @@ namespace Bluetooth { class DeviceClass { public: + + static const uint8 PixelsForIcon = 32; + static const uint8 IconInsets = 5; + DeviceClass(uint8 record[3]) { SetRecord(record); @@ -67,6 +72,8 @@ public: void GetMinorDeviceClass(BString&); void DumpDeviceClass(BString&); + + void Draw(BView* view, const BPoint& point); private: uint32 record; diff --git a/src/kits/bluetooth/DeviceClass.cpp b/src/kits/bluetooth/DeviceClass.cpp index ff445010ce..da1d2cae8f 100644 --- a/src/kits/bluetooth/DeviceClass.cpp +++ b/src/kits/bluetooth/DeviceClass.cpp @@ -312,4 +312,91 @@ DeviceClass::DumpDeviceClass(BString& 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); +} + + } diff --git a/src/preferences/bluetooth/BluetoothDeviceView.cpp b/src/preferences/bluetooth/BluetoothDeviceView.cpp index ace956ec0b..408052f5c5 100644 --- a/src/preferences/bluetooth/BluetoothDeviceView.cpp +++ b/src/preferences/bluetooth/BluetoothDeviceView.cpp @@ -22,7 +22,6 @@ BluetoothDeviceView::BluetoothDeviceView(BRect frame, BluetoothDevice* bDevice, { SetViewColor(B_TRANSPARENT_COLOR); SetLowColor(0,0,0); - //BRect iDontCare(0,0,0,0); SetLayout(new BGroupLayout(B_VERTICAL)); @@ -40,17 +39,17 @@ BluetoothDeviceView::BluetoothDeviceView(BRect frame, BluetoothDevice* bDevice, fManufacturerProperties = new BStringView("manufacturer", ""); fBuffersProperties = new BStringView("buffers", ""); - fIcon = new BitmapView(new BBitmap(BRect(0, 0, 64 - 1, 64 - 1), B_RGBA32)); - - fIcon->SetViewColor(0,0,0); + 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)); SetBluetoothDevice(bDevice); AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10) .Add(fIcon) + .AddGlue() .Add(BGroupLayoutBuilder(B_VERTICAL) .Add(fName) - .AddGlue() + .AddGlue() .Add(fBdaddr) .AddGlue() .AddGlue() @@ -100,6 +99,7 @@ BluetoothDeviceView::SetBluetoothDevice(BluetoothDevice* bDevice) bDevice->GetDeviceClass().GetMinorDeviceClass(str); fClass->SetText(str.String()); + bDevice->GetDeviceClass().Draw(fIcon, BPoint(Bounds().left, Bounds().top)); uint32 value; diff --git a/src/preferences/bluetooth/BluetoothDeviceView.h b/src/preferences/bluetooth/BluetoothDeviceView.h index c388b90883..3316aff2aa 100644 --- a/src/preferences/bluetooth/BluetoothDeviceView.h +++ b/src/preferences/bluetooth/BluetoothDeviceView.h @@ -5,11 +5,11 @@ #ifndef BLUETOOTHDEVICEVIEW_H_ #define BLUETOOTHDEVICEVIEW_H_ -#include -#include -#include #include #include +#include +#include +#include #include @@ -34,18 +34,18 @@ public: protected: BluetoothDevice* fDevice; - BStringView* fName; - BStringView* fBdaddr; - BStringView* fClassService; - BStringView* fClass; + BStringView* fName; + BStringView* fBdaddr; + BStringView* fClassService; + BStringView* fClass; - BStringView* fHCIVersionProperties; - BStringView* fLMPVersionProperties; - BStringView* fManufacturerProperties; + BStringView* fHCIVersionProperties; + BStringView* fLMPVersionProperties; + BStringView* fManufacturerProperties; - BStringView* fBuffersProperties; + BStringView* fBuffersProperties; - BitmapView* fIcon; + BView* fIcon; }; @@ -84,6 +84,4 @@ class BitmapView : public BView }; - - #endif diff --git a/src/preferences/bluetooth/DeviceListItem.cpp b/src/preferences/bluetooth/DeviceListItem.cpp index 99a06086f8..510841c235 100644 --- a/src/preferences/bluetooth/DeviceListItem.cpp +++ b/src/preferences/bluetooth/DeviceListItem.cpp @@ -8,34 +8,32 @@ #include #include -#include "../media/iconfile.h" +/*#include "../media/iconfile.h"*/ #include "DeviceListItem.h" - -#define PIXELS_FOR_ICON 32 #define INSETS 5 #define TEXT_ROWS 2 namespace Bluetooth { -DeviceListItem::DeviceListItem(BluetoothDevice* bDevice) - : BListItem(), - fDevice(bDevice) +DeviceListItem::DeviceListItem(BluetoothDevice* bDevice) + : BListItem() + , fDevice(bDevice) { - SetDevice(fDevice); + SetDevice(fDevice); } DeviceListItem::DeviceListItem(bdaddr_t bdaddr, DeviceClass dClass, int32 rssi) - : BListItem(), - fDevice(NULL), - fAddress(bdaddr), - fClass(dClass), - fName("unknown"), - fRSSI(rssi) -{ + : BListItem() + , fDevice(NULL) + , fAddress(bdaddr) + , fClass(dClass) + , fName("unknown") + , fRSSI(rssi) +{ } @@ -81,7 +79,7 @@ DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete) font_height 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->SetHighColor(kBlack); owner->MovePenTo(point); @@ -95,13 +93,15 @@ DeviceListItem::DrawItem(BView* owner, BRect itemRect, bool complete) 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->DrawString(fName.String()); + owner->DrawString(fName.String()); - // TODO: Generalize this + fClass.Draw(owner, BPoint(itemRect.left, itemRect.top)); + +#if 0 switch (fClass.GetMajorDeviceClass()) { 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)); } 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->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)); }