112fd6cc2SKarsten Heimrich /*****************************************************************************/
212fd6cc2SKarsten Heimrich // BeUtilsTranslation.cpp
312fd6cc2SKarsten Heimrich //
412fd6cc2SKarsten Heimrich // Version: 1.0.0d1
512fd6cc2SKarsten Heimrich //
612fd6cc2SKarsten Heimrich // Several utilities for writing applications for the BeOS. It are small
712fd6cc2SKarsten Heimrich // very specific functions, but generally useful (could be here because of a
812fd6cc2SKarsten Heimrich // lack in the APIs, or just sheer lazyness :))
912fd6cc2SKarsten Heimrich //
1012fd6cc2SKarsten Heimrich //
1112fd6cc2SKarsten Heimrich // Author
1212fd6cc2SKarsten Heimrich // Ithamar R. Adema
1312fd6cc2SKarsten Heimrich // Michael Pfeiffer
1412fd6cc2SKarsten Heimrich //
1512fd6cc2SKarsten Heimrich // This application and all source files used in its construction, except
1612fd6cc2SKarsten Heimrich // where noted, are licensed under the MIT License, and have been written
1712fd6cc2SKarsten Heimrich // and are:
1812fd6cc2SKarsten Heimrich //
19*2ca13760SColdfirex // Copyright (c) 2001, 2002 Haiku Project
2012fd6cc2SKarsten Heimrich //
2112fd6cc2SKarsten Heimrich // Permission is hereby granted, free of charge, to any person obtaining a
2212fd6cc2SKarsten Heimrich // copy of this software and associated documentation files (the "Software"),
2312fd6cc2SKarsten Heimrich // to deal in the Software without restriction, including without limitation
2412fd6cc2SKarsten Heimrich // the rights to use, copy, modify, merge, publish, distribute, sublicense,
2512fd6cc2SKarsten Heimrich // and/or sell copies of the Software, and to permit persons to whom the
2612fd6cc2SKarsten Heimrich // Software is furnished to do so, subject to the following conditions:
2712fd6cc2SKarsten Heimrich //
2812fd6cc2SKarsten Heimrich // The above copyright notice and this permission notice shall be included
2912fd6cc2SKarsten Heimrich // in all copies or substantial portions of the Software.
3012fd6cc2SKarsten Heimrich //
3112fd6cc2SKarsten Heimrich // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3212fd6cc2SKarsten Heimrich // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3312fd6cc2SKarsten Heimrich // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
3412fd6cc2SKarsten Heimrich // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3512fd6cc2SKarsten Heimrich // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3612fd6cc2SKarsten Heimrich // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
3712fd6cc2SKarsten Heimrich // DEALINGS IN THE SOFTWARE.
3812fd6cc2SKarsten Heimrich /*****************************************************************************/
3912fd6cc2SKarsten Heimrich
4012fd6cc2SKarsten Heimrich #include <Application.h>
4112fd6cc2SKarsten Heimrich #include <Bitmap.h>
4212fd6cc2SKarsten Heimrich #include <Messenger.h>
4312fd6cc2SKarsten Heimrich #include <Resources.h>
4412fd6cc2SKarsten Heimrich #include <Roster.h>
4512fd6cc2SKarsten Heimrich #include <String.h>
4612fd6cc2SKarsten Heimrich
4712fd6cc2SKarsten Heimrich #include "BeUtils.h"
4812fd6cc2SKarsten Heimrich
LoadBitmap(const char * name,uint32 type_code)4912fd6cc2SKarsten Heimrich BBitmap* LoadBitmap(const char* name, uint32 type_code) {
5012fd6cc2SKarsten Heimrich if (type_code == B_TRANSLATOR_BITMAP) {
5112fd6cc2SKarsten Heimrich return BTranslationUtils::GetBitmap(type_code, name);
5212fd6cc2SKarsten Heimrich } else {
5312fd6cc2SKarsten Heimrich BResources *res = BApplication::AppResources();
5412fd6cc2SKarsten Heimrich if (res != NULL) {
5512fd6cc2SKarsten Heimrich BMessage m;
5612fd6cc2SKarsten Heimrich size_t length;
5712fd6cc2SKarsten Heimrich const void *bits = res->LoadResource(type_code, name, &length);
5812fd6cc2SKarsten Heimrich if (bits && m.Unflatten((char*)bits) == B_OK) {
5912fd6cc2SKarsten Heimrich return (BBitmap*)BBitmap::Instantiate(&m);
6012fd6cc2SKarsten Heimrich }
6112fd6cc2SKarsten Heimrich }
6212fd6cc2SKarsten Heimrich return NULL;
6312fd6cc2SKarsten Heimrich }
6412fd6cc2SKarsten Heimrich }
6512fd6cc2SKarsten Heimrich
BitmapToPicture(BView * view,BBitmap * bitmap)6612fd6cc2SKarsten Heimrich BPicture *BitmapToPicture(BView* view, BBitmap *bitmap) {
6712fd6cc2SKarsten Heimrich if (bitmap) {
6812fd6cc2SKarsten Heimrich view->BeginPicture(new BPicture());
6912fd6cc2SKarsten Heimrich view->DrawBitmap(bitmap);
7012fd6cc2SKarsten Heimrich return view->EndPicture();
7112fd6cc2SKarsten Heimrich }
7212fd6cc2SKarsten Heimrich return NULL;
7312fd6cc2SKarsten Heimrich }
7412fd6cc2SKarsten Heimrich
BitmapToGrayedPicture(BView * view,BBitmap * bitmap)7512fd6cc2SKarsten Heimrich BPicture *BitmapToGrayedPicture(BView* view, BBitmap *bitmap) {
7612fd6cc2SKarsten Heimrich if (bitmap) {
7712fd6cc2SKarsten Heimrich BRect rect(bitmap->Bounds());
7812fd6cc2SKarsten Heimrich view->BeginPicture(new BPicture());
7912fd6cc2SKarsten Heimrich view->DrawBitmap(bitmap);
8012fd6cc2SKarsten Heimrich view->SetHighColor(255, 255, 255, 128);
8112fd6cc2SKarsten Heimrich view->SetDrawingMode(B_OP_ALPHA);
8212fd6cc2SKarsten Heimrich view->FillRect(rect);
8312fd6cc2SKarsten Heimrich return view->EndPicture();
8412fd6cc2SKarsten Heimrich }
8512fd6cc2SKarsten Heimrich return NULL;
8612fd6cc2SKarsten Heimrich }
87