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