Add support for flags in BCountry. The flags are stored as HVIF icon resources in liblocale.so.
Test french flag took from http://www.bastisoft.de/misc/flags/ (licence is very permissive), converted to HVIF with Icon O Matic. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36314 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Binary file not shown.
@@ -10,6 +10,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include <IconUtils.h>
|
#include <IconUtils.h>
|
||||||
|
#include <Resources.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include <unicode/datefmt.h>
|
#include <unicode/datefmt.h>
|
||||||
@@ -91,10 +92,17 @@ status_t
|
|||||||
BCountry::GetIcon(BBitmap* result)
|
BCountry::GetIcon(BBitmap* result)
|
||||||
{
|
{
|
||||||
// TODO: a proper way to locate the library being used ?
|
// TODO: a proper way to locate the library being used ?
|
||||||
BNode storage("/boot/system/lib/liblocale.so");
|
BResources storage("/boot/system/lib/liblocale.so");
|
||||||
if (storage.InitCheck() != B_OK)
|
if (storage.InitCheck() != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
return BIconUtils::GetVectorIcon(&storage, Code(), result);
|
size_t size;
|
||||||
|
const void* buffer = storage.LoadResource(B_VECTOR_ICON_TYPE, Code(),
|
||||||
|
&size);
|
||||||
|
if (buffer != NULL && size != 0) {
|
||||||
|
return BIconUtils::GetVectorIcon(static_cast<const uint8*>(buffer),
|
||||||
|
size, result);
|
||||||
|
} else
|
||||||
|
return B_BAD_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
resource(2, "fr") #'VICN' array {
|
||||||
|
$"6E636966030300335B05FF03D81C3F030A04B2FBB75DCC84B75DCC84C863B2FB"
|
||||||
|
$"C8630A04BB7EB75DCC84B75DCC84C863BB7EC8630A04C401B75DCC84B75DCC84"
|
||||||
|
$"C863C401C863030A000100000A010101000A02010200"
|
||||||
|
};
|
||||||
@@ -4,6 +4,8 @@ UsePrivateHeaders libbe locale shared ;
|
|||||||
UsePublicHeaders locale storage icon ;
|
UsePublicHeaders locale storage icon ;
|
||||||
UseLibraryHeaders icu icon ;
|
UseLibraryHeaders icu icon ;
|
||||||
|
|
||||||
|
AddResources liblocale.so : CountryFlags.rdef ;
|
||||||
|
|
||||||
SharedLibrary liblocale.so
|
SharedLibrary liblocale.so
|
||||||
: cat.cpp
|
: cat.cpp
|
||||||
Catalog.cpp
|
Catalog.cpp
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "Locale.h"
|
#include "Locale.h"
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <Country.h>
|
||||||
|
|
||||||
|
|
||||||
#define MAX_DRAG_HEIGHT 200.0
|
#define MAX_DRAG_HEIGHT 200.0
|
||||||
@@ -19,6 +20,56 @@ LanguageListItem::LanguageListItem(const char* text, const char* code)
|
|||||||
BStringItem(text),
|
BStringItem(text),
|
||||||
fLanguageCode(code)
|
fLanguageCode(code)
|
||||||
{
|
{
|
||||||
|
// TODO: should probably keep the BCountry as a member of the class
|
||||||
|
BCountry myCountry(code);
|
||||||
|
BRect bounds(0, 0, 15, 15);
|
||||||
|
icon = new BBitmap(bounds, B_RGBA32);
|
||||||
|
myCountry.GetIcon(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//MediaListItem - DrawItem
|
||||||
|
void
|
||||||
|
LanguageListItem::DrawItem(BView *owner, BRect frame, bool complete)
|
||||||
|
{
|
||||||
|
rgb_color kHighlight = { 140,140,140,0 };
|
||||||
|
rgb_color kBlack = { 0,0,0,0 };
|
||||||
|
|
||||||
|
BRect r(frame);
|
||||||
|
|
||||||
|
if (IsSelected() || complete) {
|
||||||
|
rgb_color color;
|
||||||
|
if (IsSelected()) {
|
||||||
|
color = kHighlight;
|
||||||
|
} else {
|
||||||
|
color = owner->ViewColor();
|
||||||
|
}
|
||||||
|
owner->SetHighColor(color);
|
||||||
|
owner->SetLowColor(color);
|
||||||
|
owner->FillRect(r);
|
||||||
|
owner->SetHighColor(kBlack);
|
||||||
|
} else {
|
||||||
|
owner->SetLowColor(owner->ViewColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
frame.left += 4;
|
||||||
|
BRect iconFrame(frame);
|
||||||
|
iconFrame.Set(iconFrame.left, iconFrame.top+1, iconFrame.left+15, iconFrame.top+16);
|
||||||
|
|
||||||
|
owner->SetDrawingMode(B_OP_OVER);
|
||||||
|
owner->DrawBitmap(icon, iconFrame);
|
||||||
|
owner->SetDrawingMode(B_OP_COPY);
|
||||||
|
|
||||||
|
frame.left += 16 * (OutlineLevel() + 1);
|
||||||
|
owner->SetHighColor(kBlack);
|
||||||
|
|
||||||
|
BFont font = be_plain_font;
|
||||||
|
font_height finfo;
|
||||||
|
font.GetHeight(&finfo);
|
||||||
|
owner->SetFont(&font);
|
||||||
|
owner->MovePenTo(frame.left+8, frame.top + ((frame.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) +
|
||||||
|
(finfo.ascent + finfo.descent) - 1);
|
||||||
|
owner->DrawString(Text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -140,7 +191,8 @@ void LanguageListView::MessageReceived (BMessage* message)
|
|||||||
}
|
}
|
||||||
Invoke(fMsgPrefLanguagesChanged);
|
Invoke(fMsgPrefLanguagesChanged);
|
||||||
}
|
}
|
||||||
} else BOutlineListView::MessageReceived(message);
|
} else
|
||||||
|
BOutlineListView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -209,58 +261,57 @@ LanguageListView::InitiateDrag(BPoint point, int32 index, bool)
|
|||||||
}
|
}
|
||||||
BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
|
BBitmap* dragBitmap = new BBitmap(dragRect, B_RGB32, true);
|
||||||
if (dragBitmap && dragBitmap->IsValid()) {
|
if (dragBitmap && dragBitmap->IsValid()) {
|
||||||
if (BView* v = new BView(dragBitmap->Bounds(), "helper",
|
BView* v = new BView(dragBitmap->Bounds(), "helper",
|
||||||
B_FOLLOW_NONE, B_WILL_DRAW)) {
|
B_FOLLOW_NONE, B_WILL_DRAW);
|
||||||
dragBitmap->AddChild(v);
|
dragBitmap->AddChild(v);
|
||||||
dragBitmap->Lock();
|
dragBitmap->Lock();
|
||||||
BRect itemBounds(dragRect) ;
|
BRect itemBounds(dragRect) ;
|
||||||
itemBounds.bottom = 0.0;
|
itemBounds.bottom = 0.0;
|
||||||
// let all selected items, that fit into our drag_bitmap, draw
|
// let all selected items, that fit into our drag_bitmap, draw
|
||||||
for (int32 i = 0; i < numItems; i++) {
|
for (int32 i = 0; i < numItems; i++) {
|
||||||
int32 index = FullListCurrentSelection(i);
|
int32 index = FullListCurrentSelection(i);
|
||||||
LanguageListItem* item
|
LanguageListItem* item
|
||||||
= static_cast<LanguageListItem*>(FullListItemAt(index));
|
= static_cast<LanguageListItem*>(FullListItemAt(index));
|
||||||
itemBounds.bottom = itemBounds.top + ceilf(item->Height());
|
itemBounds.bottom = itemBounds.top + ceilf(item->Height());
|
||||||
if (itemBounds.bottom > dragRect.bottom)
|
if (itemBounds.bottom > dragRect.bottom)
|
||||||
itemBounds.bottom = dragRect.bottom;
|
itemBounds.bottom = dragRect.bottom;
|
||||||
item->DrawItem(v, itemBounds);
|
item->DrawItem(v, itemBounds);
|
||||||
itemBounds.top = itemBounds.bottom + 1.0;
|
itemBounds.top = itemBounds.bottom + 1.0;
|
||||||
}
|
|
||||||
// make a black frame arround the edge
|
|
||||||
v->SetHighColor(0, 0, 0, 255);
|
|
||||||
v->StrokeRect(v->Bounds());
|
|
||||||
v->Sync();
|
|
||||||
|
|
||||||
uint8* bits = (uint8*)dragBitmap->Bits();
|
|
||||||
int32 height = (int32)dragBitmap->Bounds().Height() + 1;
|
|
||||||
int32 width = (int32)dragBitmap->Bounds().Width() + 1;
|
|
||||||
int32 bpr = dragBitmap->BytesPerRow();
|
|
||||||
|
|
||||||
if (fade) {
|
|
||||||
for (int32 y = 0; y < height - ALPHA / 2;
|
|
||||||
y++, bits += bpr) {
|
|
||||||
uint8* line = bits + 3;
|
|
||||||
for (uint8* end = line + 4 * width; line < end;
|
|
||||||
line += 4)
|
|
||||||
*line = ALPHA;
|
|
||||||
}
|
|
||||||
for (int32 y = height - ALPHA / 2; y < height;
|
|
||||||
y++, bits += bpr) {
|
|
||||||
uint8* line = bits + 3;
|
|
||||||
for (uint8* end = line + 4 * width; line < end;
|
|
||||||
line += 4)
|
|
||||||
*line = (height - y) << 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int32 y = 0; y < height; y++, bits += bpr) {
|
|
||||||
uint8* line = bits + 3;
|
|
||||||
for (uint8* end = line + 4 * width; line < end;
|
|
||||||
line += 4)
|
|
||||||
*line = ALPHA;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dragBitmap->Unlock();
|
|
||||||
}
|
}
|
||||||
|
// make a black frame arround the edge
|
||||||
|
v->SetHighColor(0, 0, 0, 255);
|
||||||
|
v->StrokeRect(v->Bounds());
|
||||||
|
v->Sync();
|
||||||
|
|
||||||
|
uint8* bits = (uint8*)dragBitmap->Bits();
|
||||||
|
int32 height = (int32)dragBitmap->Bounds().Height() + 1;
|
||||||
|
int32 width = (int32)dragBitmap->Bounds().Width() + 1;
|
||||||
|
int32 bpr = dragBitmap->BytesPerRow();
|
||||||
|
|
||||||
|
if (fade) {
|
||||||
|
for (int32 y = 0; y < height - ALPHA / 2;
|
||||||
|
y++, bits += bpr) {
|
||||||
|
uint8* line = bits + 3;
|
||||||
|
for (uint8* end = line + 4 * width; line < end;
|
||||||
|
line += 4)
|
||||||
|
*line = ALPHA;
|
||||||
|
}
|
||||||
|
for (int32 y = height - ALPHA / 2; y < height;
|
||||||
|
y++, bits += bpr) {
|
||||||
|
uint8* line = bits + 3;
|
||||||
|
for (uint8* end = line + 4 * width; line < end;
|
||||||
|
line += 4)
|
||||||
|
*line = (height - y) << 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int32 y = 0; y < height; y++, bits += bpr) {
|
||||||
|
uint8* line = bits + 3;
|
||||||
|
for (uint8* end = line + 4 * width; line < end;
|
||||||
|
line += 4)
|
||||||
|
*line = ALPHA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dragBitmap->Unlock();
|
||||||
} else {
|
} else {
|
||||||
delete dragBitmap;
|
delete dragBitmap;
|
||||||
dragBitmap = NULL;
|
dragBitmap = NULL;
|
||||||
@@ -317,7 +368,6 @@ LanguageListView::MouseMoved(BPoint where, uint32 transit, const BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
BOutlineListView::MouseMoved(where, transit, msg);
|
BOutlineListView::MouseMoved(where, transit, msg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Adrien Destugues, [email protected]
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __LANGUAGE_LIST_VIEW_H
|
#ifndef __LANGUAGE_LIST_VIEW_H
|
||||||
#define __LANGUAGE_LIST_VIEW_H
|
#define __LANGUAGE_LIST_VIEW_H
|
||||||
|
|
||||||
@@ -7,8 +13,7 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
class LanguageListItem: public BStringItem
|
class LanguageListItem: public BStringItem {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
LanguageListItem(const char* text, const char* code);
|
LanguageListItem(const char* text, const char* code);
|
||||||
|
|
||||||
@@ -21,9 +26,13 @@ class LanguageListItem: public BStringItem
|
|||||||
~LanguageListItem() {};
|
~LanguageListItem() {};
|
||||||
|
|
||||||
const inline BString LanguageCode() { return fLanguageCode; }
|
const inline BString LanguageCode() { return fLanguageCode; }
|
||||||
|
|
||||||
|
//virtual void Update(BView *owner, const BFont *finfo);
|
||||||
|
virtual void DrawItem(BView *owner, BRect frame, bool complete = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const BString fLanguageCode;
|
const BString fLanguageCode;
|
||||||
|
BBitmap* icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -36,8 +45,7 @@ compare_list_items(const void* _a, const void* _b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class LanguageListView: public BOutlineListView
|
class LanguageListView: public BOutlineListView {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
LanguageListView(const char* name, list_view_type type);
|
LanguageListView(const char* name, list_view_type type);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user