* 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,
kOfflineIcon = 13,
kSearchIcon = 100,
kToolIcon = 20,
kSearchIcon = 21,
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" {
status_t

View File

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

View File

@ -9,25 +9,31 @@
*/
#include <Application.h>
#include <Button.h>
#include <Alert.h>
#include <Button.h>
#include <CardLayout.h>
#include <ListView.h>
#include <Box.h>
#include <CheckBox.h>
#include <Entry.h>
#include <GridLayout.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <CardLayout.h>
#include <GroupLayoutBuilder.h>
#include <Layout.h>
#include <GridLayout.h>
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <SpaceLayoutItem.h>
#include <ScrollView.h>
#include <StringView.h>
#include <TextControl.h>
#include <TranslationUtils.h>
#include <libinterface/BitmapUtils.h>
#include <libinterface/ToolButton.h>
#include "CayaConstants.h"
#include "CayaResources.h"
#include "CayaUtils.h"
#include "NotifyMessage.h"
#include "MainWindow.h"
#include "PreferencesDialog.h"
@ -76,20 +82,28 @@ MainWindow::MainWindow() :
BScrollView* scrollView = new BScrollView("scrollview", fListView,
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));
rosterView->AddChild(BGroupLayoutBuilder(B_HORIZONTAL)
.AddGroup(B_VERTICAL)
.AddGroup(B_HORIZONTAL)
.AddGroup(B_VERTICAL)
.Add(fStatusView)
.Add(searchBox)
.End()
.Add(wrench)
.End()
.Add(scrollView)
.End()
// Tool icon
BResources* res = CayaResources();
BBitmap* toolIcon = IconFromResources(res, kToolIcon);
delete res;
// Wrench tool button
ToolButton* wrench = new ToolButton(NULL, NULL);
wrench->SetBitmap(toolIcon);
wrench->SetMenu(wrenchMenu);
rosterView->SetLayout(new BGridLayout(5, 5));
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)
);

View File

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

View File

@ -53,16 +53,8 @@ StatusMenuItem::IsCustom() const
void
StatusMenuItem::SetIcon()
{
image_info info;
if (our_image(info) != B_OK)
return;
BFile file(info.name, B_READ_ONLY);
if (file.InitCheck() != B_OK)
return;
BResources res(&file);
if (res.InitCheck() != B_OK)
BResources* res = CayaResources();
if (!res)
return;
int32 num = 0;
@ -85,6 +77,8 @@ StatusMenuItem::SetIcon()
break;
}
BBitmap* bitmap = IconFromResources(&res, num, B_MINI_ICON);
BBitmap* bitmap = IconFromResources(res, num, B_MINI_ICON);
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 <Resources.h>
BBitmap* ReadNodeIcon(const char* name, icon_size size, bool followSymlink);
BBitmap* IconFromResources(BResources* res, int32 num, icon_size size);
BBitmap* RescaleBitmap(const BBitmap* src, int32 width, int32 height);
BBitmap* ReadNodeIcon(const char* name, icon_size size,
bool followSymlink);
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

View File

@ -24,7 +24,7 @@
const float kPopUpMarkerSize = 5.0f;
const float kPopUpMarkerTop = 0.5f;
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,
@ -128,13 +128,19 @@ ToolButton::Draw(BRect updateRect)
bounds.right -= kPopUpMarkerRect;
// 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,
kToolbarIconSize);
DrawBitmap(bitmap, _Center(bounds));
DrawBitmap(bitmap, center);
bounds.top += kToolbarIconSize + 2;
bounds.bottom += kToolbarIconSize + 2;
bounds.top = center.y + kToolbarIconSize + 2;
}
// Draw label
@ -379,8 +385,9 @@ BSize
ToolButton::_ValidatePreferredSize()
{
if (fPreferredSize.width < 0) {
float startWidth = 10.0f;
float minWidth = 25.0f;
float startWidth = 10;
float minSize = 25;
float minWidth = minSize;
if (fMenu) {
startWidth += kPopUpMarkerRect;
@ -395,12 +402,24 @@ ToolButton::_ValidatePreferredSize()
fPreferredSize.width = width;
// Height
fPreferredSize.height = 0;
if (Label()) {
font_height fontHeight;
GetFontHeight(&fontHeight);
fPreferredSize.height
= ceilf((fontHeight.ascent + fontHeight.descent) * 1.5)
+ (fBitmap ? kToolbarIconSize + 4.0f : 0);
+= ceilf((fontHeight.ascent + fontHeight.descent) * 1.5);
}
if (Bitmap())
fPreferredSize.height += kToolbarIconSize + 6;
if (Bitmap() && Label())
fPreferredSize.height += 4;
if (fPreferredSize.height < minSize)
fPreferredSize.height = minSize;
ResetLayoutInvalidation();
}