1*12fd6cc2SKarsten Heimrich /*****************************************************************************/ 2*12fd6cc2SKarsten Heimrich // BeUtilsTranslation.cpp 3*12fd6cc2SKarsten Heimrich // 4*12fd6cc2SKarsten Heimrich // Version: 1.0.0d1 5*12fd6cc2SKarsten Heimrich // 6*12fd6cc2SKarsten Heimrich // Several utilities for writing applications for the BeOS. It are small 7*12fd6cc2SKarsten Heimrich // very specific functions, but generally useful (could be here because of a 8*12fd6cc2SKarsten Heimrich // lack in the APIs, or just sheer lazyness :)) 9*12fd6cc2SKarsten Heimrich // 10*12fd6cc2SKarsten Heimrich // 11*12fd6cc2SKarsten Heimrich // Author 12*12fd6cc2SKarsten Heimrich // Ithamar R. Adema 13*12fd6cc2SKarsten Heimrich // Michael Pfeiffer 14*12fd6cc2SKarsten Heimrich // 15*12fd6cc2SKarsten Heimrich // This application and all source files used in its construction, except 16*12fd6cc2SKarsten Heimrich // where noted, are licensed under the MIT License, and have been written 17*12fd6cc2SKarsten Heimrich // and are: 18*12fd6cc2SKarsten Heimrich // 19*12fd6cc2SKarsten Heimrich // Copyright (c) 2001, 2002 OpenBeOS Project 20*12fd6cc2SKarsten Heimrich // 21*12fd6cc2SKarsten Heimrich // Permission is hereby granted, free of charge, to any person obtaining a 22*12fd6cc2SKarsten Heimrich // copy of this software and associated documentation files (the "Software"), 23*12fd6cc2SKarsten Heimrich // to deal in the Software without restriction, including without limitation 24*12fd6cc2SKarsten Heimrich // the rights to use, copy, modify, merge, publish, distribute, sublicense, 25*12fd6cc2SKarsten Heimrich // and/or sell copies of the Software, and to permit persons to whom the 26*12fd6cc2SKarsten Heimrich // Software is furnished to do so, subject to the following conditions: 27*12fd6cc2SKarsten Heimrich // 28*12fd6cc2SKarsten Heimrich // The above copyright notice and this permission notice shall be included 29*12fd6cc2SKarsten Heimrich // in all copies or substantial portions of the Software. 30*12fd6cc2SKarsten Heimrich // 31*12fd6cc2SKarsten Heimrich // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 32*12fd6cc2SKarsten Heimrich // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33*12fd6cc2SKarsten Heimrich // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 34*12fd6cc2SKarsten Heimrich // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35*12fd6cc2SKarsten Heimrich // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 36*12fd6cc2SKarsten Heimrich // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 37*12fd6cc2SKarsten Heimrich // DEALINGS IN THE SOFTWARE. 38*12fd6cc2SKarsten Heimrich /*****************************************************************************/ 39*12fd6cc2SKarsten Heimrich 40*12fd6cc2SKarsten Heimrich #include <Application.h> 41*12fd6cc2SKarsten Heimrich #include <Bitmap.h> 42*12fd6cc2SKarsten Heimrich #include <Messenger.h> 43*12fd6cc2SKarsten Heimrich #include <Resources.h> 44*12fd6cc2SKarsten Heimrich #include <Roster.h> 45*12fd6cc2SKarsten Heimrich #include <String.h> 46*12fd6cc2SKarsten Heimrich 47*12fd6cc2SKarsten Heimrich #include "BeUtils.h" 48*12fd6cc2SKarsten Heimrich 49*12fd6cc2SKarsten Heimrich BBitmap* LoadBitmap(const char* name, uint32 type_code) { 50*12fd6cc2SKarsten Heimrich if (type_code == B_TRANSLATOR_BITMAP) { 51*12fd6cc2SKarsten Heimrich return BTranslationUtils::GetBitmap(type_code, name); 52*12fd6cc2SKarsten Heimrich } else { 53*12fd6cc2SKarsten Heimrich BResources *res = BApplication::AppResources(); 54*12fd6cc2SKarsten Heimrich if (res != NULL) { 55*12fd6cc2SKarsten Heimrich BMessage m; 56*12fd6cc2SKarsten Heimrich size_t length; 57*12fd6cc2SKarsten Heimrich const void *bits = res->LoadResource(type_code, name, &length); 58*12fd6cc2SKarsten Heimrich if (bits && m.Unflatten((char*)bits) == B_OK) { 59*12fd6cc2SKarsten Heimrich return (BBitmap*)BBitmap::Instantiate(&m); 60*12fd6cc2SKarsten Heimrich } 61*12fd6cc2SKarsten Heimrich } 62*12fd6cc2SKarsten Heimrich return NULL; 63*12fd6cc2SKarsten Heimrich } 64*12fd6cc2SKarsten Heimrich } 65*12fd6cc2SKarsten Heimrich 66*12fd6cc2SKarsten Heimrich BPicture *BitmapToPicture(BView* view, BBitmap *bitmap) { 67*12fd6cc2SKarsten Heimrich if (bitmap) { 68*12fd6cc2SKarsten Heimrich view->BeginPicture(new BPicture()); 69*12fd6cc2SKarsten Heimrich view->DrawBitmap(bitmap); 70*12fd6cc2SKarsten Heimrich return view->EndPicture(); 71*12fd6cc2SKarsten Heimrich } 72*12fd6cc2SKarsten Heimrich return NULL; 73*12fd6cc2SKarsten Heimrich } 74*12fd6cc2SKarsten Heimrich 75*12fd6cc2SKarsten Heimrich BPicture *BitmapToGrayedPicture(BView* view, BBitmap *bitmap) { 76*12fd6cc2SKarsten Heimrich if (bitmap) { 77*12fd6cc2SKarsten Heimrich BRect rect(bitmap->Bounds()); 78*12fd6cc2SKarsten Heimrich view->BeginPicture(new BPicture()); 79*12fd6cc2SKarsten Heimrich view->DrawBitmap(bitmap); 80*12fd6cc2SKarsten Heimrich view->SetHighColor(255, 255, 255, 128); 81*12fd6cc2SKarsten Heimrich view->SetDrawingMode(B_OP_ALPHA); 82*12fd6cc2SKarsten Heimrich view->FillRect(rect); 83*12fd6cc2SKarsten Heimrich return view->EndPicture(); 84*12fd6cc2SKarsten Heimrich } 85*12fd6cc2SKarsten Heimrich return NULL; 86*12fd6cc2SKarsten Heimrich } 87