* Now using a grid layout.

* Implemented the "wrench" menu (it needs an icon).
This commit is contained in:
plfiorini 2010-05-09 08:23:53 +00:00
parent bcc5118ba4
commit 2e8cd94f8c
9 changed files with 111 additions and 44 deletions

View File

@ -11,7 +11,8 @@ enum {
kBusyIcon = 12, kBusyIcon = 12,
kOfflineIcon = 13, kOfflineIcon = 13,
kSearchIcon = 100, kToolIcon = 20,
kSearchIcon = 21,
kProtocolSettingsTemplate = 1000 kProtocolSettingsTemplate = 1000
}; };

View File

@ -34,6 +34,27 @@ CayaStatusToString(CayaStatus status)
} }
} }
BResources*
CayaResources()
{
image_info info;
if (our_image(info) != B_OK)
return NULL;
BFile file(info.name, B_READ_ONLY);
if (file.InitCheck() != B_OK)
return NULL;
BResources* res = new BResources(&file);
if (res->InitCheck() != B_OK) {
delete res;
return NULL;
}
return res;
}
extern "C" { extern "C" {
status_t status_t

View File

@ -8,10 +8,12 @@
#include <image.h> #include <image.h>
#include <Mime.h> #include <Mime.h>
#include <Resources.h>
#include "CayaConstants.h" #include "CayaConstants.h"
const char* CayaStatusToString(CayaStatus status); const char* CayaStatusToString(CayaStatus status);
BResources* CayaResources();
extern "C" status_t our_image(image_info& image); extern "C" status_t our_image(image_info& image);

View File

@ -9,25 +9,31 @@
*/ */
#include <Application.h> #include <Application.h>
#include <Button.h>
#include <Alert.h> #include <Alert.h>
#include <Button.h>
#include <CardLayout.h>
#include <ListView.h> #include <ListView.h>
#include <Box.h> #include <Box.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <Entry.h> #include <Entry.h>
#include <GridLayout.h>
#include <GridLayoutBuilder.h> #include <GridLayoutBuilder.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <CardLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <Layout.h> #include <MenuItem.h>
#include <GridLayout.h> #include <PopUpMenu.h>
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringView.h> #include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
#include <TranslationUtils.h> #include <TranslationUtils.h>
#include <libinterface/BitmapUtils.h>
#include <libinterface/ToolButton.h>
#include "CayaConstants.h" #include "CayaConstants.h"
#include "CayaResources.h"
#include "CayaUtils.h"
#include "NotifyMessage.h" #include "NotifyMessage.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "PreferencesDialog.h" #include "PreferencesDialog.h"
@ -76,20 +82,28 @@ MainWindow::MainWindow() :
BScrollView* scrollView = new BScrollView("scrollview", fListView, BScrollView* scrollView = new BScrollView("scrollview", fListView,
B_WILL_DRAW, false, true); B_WILL_DRAW, false, true);
BButton* wrench = new BButton("wrench", new BMessage(kPreferences)); // Wrench menu
BPopUpMenu* wrenchMenu = new BPopUpMenu("Wrench");
(void)wrenchMenu->AddItem(new BMenuItem("Preferences...",
new BMessage(kPreferences)));
wrenchMenu->SetTargetForItems(this);
rosterView->SetLayout(new BGroupLayout(B_HORIZONTAL)); // Tool icon
rosterView->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) BResources* res = CayaResources();
.AddGroup(B_VERTICAL) BBitmap* toolIcon = IconFromResources(res, kToolIcon);
.AddGroup(B_HORIZONTAL) delete res;
.AddGroup(B_VERTICAL)
.Add(fStatusView) // Wrench tool button
.Add(searchBox) ToolButton* wrench = new ToolButton(NULL, NULL);
.End() wrench->SetBitmap(toolIcon);
.Add(wrench) wrench->SetMenu(wrenchMenu);
.End()
.Add(scrollView) rosterView->SetLayout(new BGridLayout(5, 5));
.End() rosterView->AddChild(BGridLayoutBuilder(5, 0)
.Add(fStatusView, 0, 0)
.Add(wrench, 1, 0)
.Add(searchBox, 0, 1)
.Add(scrollView, 0, 2, 2)
.SetInsets(5, 5, 5, 10) .SetInsets(5, 5, 5, 10)
); );

View File

@ -74,6 +74,19 @@ resource(kOfflineIcon) #'VICN' array {
$"0002408000000000000000408000C60000C60000" $"0002408000000000000000408000C60000C60000"
}; };
/*
* Misc icons
*/
// Tool icon
resource(kToolIcon) #'VICN' array {
$"6E63696602030100000200160239F20638AB65BE3DD63F501B4A4E27488B2600"
$"EBFFAD01060EA6996D062C4248304A34484238464C344F5C305E345E2C5E2C5C"
$"4F284C46030A0001001A41745D00000000000041745D442E8BCB345F15FF0117"
$"8402040A0001001A41745D00000000000041745D442E8BCB345F001501178602"
$"040A0101000241745D00000000000041745D442E8BCB345F"
};
// Search icon // Search icon
resource(kSearchIcon) #'VICN' array { resource(kSearchIcon) #'VICN' array {
$"6E6369660805010200060338D2F73CD163BF82B23B84A94B88504870C900FFEF" $"6E6369660805010200060338D2F73CD163BF82B23B84A94B88504870C900FFEF"

View File

@ -53,16 +53,8 @@ StatusMenuItem::IsCustom() const
void void
StatusMenuItem::SetIcon() StatusMenuItem::SetIcon()
{ {
image_info info; BResources* res = CayaResources();
if (our_image(info) != B_OK) if (!res)
return;
BFile file(info.name, B_READ_ONLY);
if (file.InitCheck() != B_OK)
return;
BResources res(&file);
if (res.InitCheck() != B_OK)
return; return;
int32 num = 0; int32 num = 0;
@ -85,6 +77,8 @@ StatusMenuItem::SetIcon()
break; break;
} }
BBitmap* bitmap = IconFromResources(&res, num, B_MINI_ICON); BBitmap* bitmap = IconFromResources(res, num, B_MINI_ICON);
SetBitmap(bitmap); SetBitmap(bitmap);
delete res;
} }

BIN
data/icons/misc/Tool Normal file

Binary file not shown.

View File

@ -9,8 +9,11 @@
#include <Mime.h> #include <Mime.h>
#include <Resources.h> #include <Resources.h>
BBitmap* ReadNodeIcon(const char* name, icon_size size, bool followSymlink); BBitmap* ReadNodeIcon(const char* name, icon_size size,
BBitmap* IconFromResources(BResources* res, int32 num, icon_size size); bool followSymlink);
BBitmap* RescaleBitmap(const BBitmap* src, int32 width, int32 height); BBitmap* IconFromResources(BResources* res, int32 num,
icon_size size = B_LARGE_ICON);
BBitmap* RescaleBitmap(const BBitmap* src, int32 width,
int32 height);
#endif // _BITMAP_UTILS_H #endif // _BITMAP_UTILS_H

View File

@ -24,7 +24,7 @@
const float kPopUpMarkerSize = 5.0f; const float kPopUpMarkerSize = 5.0f;
const float kPopUpMarkerTop = 0.5f; const float kPopUpMarkerTop = 0.5f;
const float kPopUpMarkerRect = (kPopUpMarkerSize * 2) + 2; const float kPopUpMarkerRect = (kPopUpMarkerSize * 2) + 2;
const uint32 kToolbarIconSize = 24; // this should go on BControlLook const uint32 kToolbarIconSize = 16; // this should go on BControlLook
ToolButton::ToolButton(const char* name, const char* label, BMessage* message, ToolButton::ToolButton(const char* name, const char* label, BMessage* message,
@ -128,13 +128,19 @@ ToolButton::Draw(BRect updateRect)
bounds.right -= kPopUpMarkerRect; bounds.right -= kPopUpMarkerRect;
// Draw bitmap // Draw bitmap
if (fBitmap) { if (Bitmap()) {
SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
BPoint center = _Center(bounds);
center.x -= kToolbarIconSize / 2;
center.y -= kToolbarIconSize / 2;
BBitmap* bitmap = RescaleBitmap(fBitmap, kToolbarIconSize, BBitmap* bitmap = RescaleBitmap(fBitmap, kToolbarIconSize,
kToolbarIconSize); kToolbarIconSize);
DrawBitmap(bitmap, _Center(bounds)); DrawBitmap(bitmap, center);
bounds.top += kToolbarIconSize + 2; bounds.top = center.y + kToolbarIconSize + 2;
bounds.bottom += kToolbarIconSize + 2;
} }
// Draw label // Draw label
@ -379,8 +385,9 @@ BSize
ToolButton::_ValidatePreferredSize() ToolButton::_ValidatePreferredSize()
{ {
if (fPreferredSize.width < 0) { if (fPreferredSize.width < 0) {
float startWidth = 10.0f; float startWidth = 10;
float minWidth = 25.0f; float minSize = 25;
float minWidth = minSize;
if (fMenu) { if (fMenu) {
startWidth += kPopUpMarkerRect; startWidth += kPopUpMarkerRect;
@ -395,12 +402,24 @@ ToolButton::_ValidatePreferredSize()
fPreferredSize.width = width; fPreferredSize.width = width;
// Height // Height
fPreferredSize.height = 0;
if (Label()) {
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
fPreferredSize.height fPreferredSize.height
= ceilf((fontHeight.ascent + fontHeight.descent) * 1.5) += ceilf((fontHeight.ascent + fontHeight.descent) * 1.5);
+ (fBitmap ? kToolbarIconSize + 4.0f : 0); }
if (Bitmap())
fPreferredSize.height += kToolbarIconSize + 6;
if (Bitmap() && Label())
fPreferredSize.height += 4;
if (fPreferredSize.height < minSize)
fPreferredSize.height = minSize;
ResetLayoutInvalidation(); ResetLayoutInvalidation();
} }