From ffbcecd4894c27f62075a6e70ff3bae0caa51356 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 15 Apr 2010 18:52:20 +0000 Subject: [PATCH] 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 --- data/artwork/icons/flags/France | Bin 0 -> 3268 bytes src/kits/locale/Country.cpp | 12 +- src/kits/locale/CountryFlags.rdef | 6 + src/kits/locale/Jamfile | 2 + src/preferences/locale/LanguageListView.cpp | 158 +++++++++++++------- src/preferences/locale/LanguageListView.h | 16 +- 6 files changed, 134 insertions(+), 60 deletions(-) create mode 100644 data/artwork/icons/flags/France create mode 100644 src/kits/locale/CountryFlags.rdef diff --git a/data/artwork/icons/flags/France b/data/artwork/icons/flags/France new file mode 100644 index 0000000000000000000000000000000000000000..8aa952f273e283f6b4d88d7651199ead2d3e74da GIT binary patch literal 3268 zcmeHIJ#W)c6urizEl}|>bSe@a7!X20Rm4=KG(ZDV(g2BA7?3e;W8v6QY*4dxWvGx? znAi{lD+?JA5)=FYB$)UM{DW}LvtO_SB_1QSPr9=2dH3txd*6Mx>&@z|`udV!8KB`F z>&m={iT%=;3|OUS$c$90%{p!TI7~FLWytIZKXXXrC-(4x&L8|7jFx5-`K}$eBl!lY zB2o1rM~^xx?NuMbzz(BgnFcX@EXLY!YEWqCnC!SLy1lTH`}t`obD#lT`Pmg9#J z`Tdpq*Sqi5bk6mcIVYaWeKA4iev;%t?$f?s8k`^Xdp7sPbGa`j$lOno{7>$qxbM4> zEMjgH89kqHuX(jO9=LezvrA81j++4mvAD0?$O~{qyevYFgG^6RS^%p&^Pf{x4>&vn zY7ysvt8O%Ebj-nY3PfBDpgAxrDvq)^p&#}{mLCkKEF?xdWg&e(y*iBAb{Ac876mC% zzb{C>?h>8|na_1fwo5*>jhgP9WSt+d6Do}?knS-iK!Cm1^A613S6jkLnV-oY@ literal 0 HcmV?d00001 diff --git a/src/kits/locale/Country.cpp b/src/kits/locale/Country.cpp index 2a119eda7e..9ca5d0cf24 100644 --- a/src/kits/locale/Country.cpp +++ b/src/kits/locale/Country.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -91,10 +92,17 @@ status_t BCountry::GetIcon(BBitmap* result) { // 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) 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(buffer), + size, result); + } else + return B_BAD_DATA; } diff --git a/src/kits/locale/CountryFlags.rdef b/src/kits/locale/CountryFlags.rdef new file mode 100644 index 0000000000..f552a7f94b --- /dev/null +++ b/src/kits/locale/CountryFlags.rdef @@ -0,0 +1,6 @@ + +resource(2, "fr") #'VICN' array { + $"6E636966030300335B05FF03D81C3F030A04B2FBB75DCC84B75DCC84C863B2FB" + $"C8630A04BB7EB75DCC84B75DCC84C863BB7EC8630A04C401B75DCC84B75DCC84" + $"C863C401C863030A000100000A010101000A02010200" +}; diff --git a/src/kits/locale/Jamfile b/src/kits/locale/Jamfile index c7c8b3a703..794d113729 100644 --- a/src/kits/locale/Jamfile +++ b/src/kits/locale/Jamfile @@ -4,6 +4,8 @@ UsePrivateHeaders libbe locale shared ; UsePublicHeaders locale storage icon ; UseLibraryHeaders icu icon ; +AddResources liblocale.so : CountryFlags.rdef ; + SharedLibrary liblocale.so : cat.cpp Catalog.cpp diff --git a/src/preferences/locale/LanguageListView.cpp b/src/preferences/locale/LanguageListView.cpp index bba621f166..c5bd1889ba 100644 --- a/src/preferences/locale/LanguageListView.cpp +++ b/src/preferences/locale/LanguageListView.cpp @@ -7,6 +7,7 @@ #include "Locale.h" #include +#include #define MAX_DRAG_HEIGHT 200.0 @@ -19,6 +20,56 @@ LanguageListItem::LanguageListItem(const char* text, const char* code) BStringItem(text), 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); } - } 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); if (dragBitmap && dragBitmap->IsValid()) { - if (BView* v = new BView(dragBitmap->Bounds(), "helper", - B_FOLLOW_NONE, B_WILL_DRAW)) { - dragBitmap->AddChild(v); - dragBitmap->Lock(); - BRect itemBounds(dragRect) ; - itemBounds.bottom = 0.0; - // let all selected items, that fit into our drag_bitmap, draw - for (int32 i = 0; i < numItems; i++) { - int32 index = FullListCurrentSelection(i); - LanguageListItem* item - = static_cast(FullListItemAt(index)); - itemBounds.bottom = itemBounds.top + ceilf(item->Height()); - if (itemBounds.bottom > dragRect.bottom) - itemBounds.bottom = dragRect.bottom; - item->DrawItem(v, itemBounds); - 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(); + BView* v = new BView(dragBitmap->Bounds(), "helper", + B_FOLLOW_NONE, B_WILL_DRAW); + dragBitmap->AddChild(v); + dragBitmap->Lock(); + BRect itemBounds(dragRect) ; + itemBounds.bottom = 0.0; + // let all selected items, that fit into our drag_bitmap, draw + for (int32 i = 0; i < numItems; i++) { + int32 index = FullListCurrentSelection(i); + LanguageListItem* item + = static_cast(FullListItemAt(index)); + itemBounds.bottom = itemBounds.top + ceilf(item->Height()); + if (itemBounds.bottom > dragRect.bottom) + itemBounds.bottom = dragRect.bottom; + item->DrawItem(v, itemBounds); + 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(); } else { delete dragBitmap; dragBitmap = NULL; @@ -317,7 +368,6 @@ LanguageListView::MouseMoved(BPoint where, uint32 transit, const BMessage* msg) break; } } - } else { + } else BOutlineListView::MouseMoved(where, transit, msg); - } } diff --git a/src/preferences/locale/LanguageListView.h b/src/preferences/locale/LanguageListView.h index a062403caa..330ee1d1ab 100644 --- a/src/preferences/locale/LanguageListView.h +++ b/src/preferences/locale/LanguageListView.h @@ -1,3 +1,9 @@ +/* + * Copyright 2010, Adrien Destugues, pulkomandy@gmail.com + * All rights reserved. Distributed under the terms of the MIT License. +*/ + + #ifndef __LANGUAGE_LIST_VIEW_H #define __LANGUAGE_LIST_VIEW_H @@ -7,8 +13,7 @@ #include -class LanguageListItem: public BStringItem -{ +class LanguageListItem: public BStringItem { public: LanguageListItem(const char* text, const char* code); @@ -21,9 +26,13 @@ class LanguageListItem: public BStringItem ~LanguageListItem() {}; 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: 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: LanguageListView(const char* name, list_view_type type);