2 * Copyright 1999-2010, Be Incorporated. All Rights Reserved.
3 * This file may be used under the terms of the Be Sample Code License.
5 * OverlayImage is based on the code presented in this article:
6 * http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer
11 * Humdinger <humdingerb@gmail.com>
14 #include "OverlayView.h"
17 #include <InterfaceDefs.h>
23 #undef B_TRANSLATION_CONTEXT
24 #define B_TRANSLATION_CONTEXT "Main view"
26 const float kDraggerSize
= 7;
29 OverlayView::OverlayView(BRect frame
)
31 BView(frame
, "OverlayImage", B_FOLLOW_NONE
, B_WILL_DRAW
)
36 frame
.left
= frame
.right
- kDraggerSize
;
37 frame
.top
= frame
.bottom
- kDraggerSize
;
38 BDragger
*dragger
= new BDragger(frame
, this, B_FOLLOW_RIGHT
| B_FOLLOW_BOTTOM
);
41 SetViewColor(B_TRANSPARENT_COLOR
);
43 fText
= new BTextView(Bounds(), "bgView", Bounds(), B_FOLLOW_ALL
, B_WILL_DRAW
);
44 fText
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
45 rgb_color color
= ui_color(B_PANEL_TEXT_COLOR
);
46 fText
->SetFontAndColor(be_plain_font
, B_FONT_ALL
, &color
);
50 "Enable \"Show replicants\" in Deskbar.\n"
51 "Drag & drop an image.\n"
52 "Drag the replicant to the Desktop.");
54 fText
->SetAlignment(B_ALIGN_CENTER
);
55 fText
->MakeEditable(false);
56 fText
->MakeSelectable(false);
57 fText
->MoveBy(0, (Bounds().bottom
- fText
->TextRect().bottom
) / 2);
61 OverlayView::OverlayView(BMessage
*archive
)
66 fBitmap
= new BBitmap(archive
);
70 OverlayView::~OverlayView()
77 OverlayView::Draw(BRect
)
79 SetDrawingMode(B_OP_ALPHA
);
80 SetViewColor(B_TRANSPARENT_COLOR
);
83 DrawBitmap(fBitmap
, B_ORIGIN
);
88 OverlayView::MessageReceived(BMessage
*msg
)
97 msg
->FindRef("refs", &ref
);
102 fBitmap
= BTranslationUtils::GetBitmap(path
.Path());
104 if (fBitmap
!= NULL
) {
110 BRect rect
= fBitmap
->Bounds();
112 Window()->ResizeTo(rect
.right
, rect
.bottom
);
113 Window()->Activate(true);
115 ResizeTo(rect
.right
, rect
.bottom
);
120 case B_ABOUT_REQUESTED
:
121 OverlayAboutRequested();
123 case B_COLORS_UPDATED
:
126 if (msg
->FindColor(ui_color_name(B_PANEL_TEXT_COLOR
), &color
)
128 fText
->SetFontAndColor(be_plain_font
, B_FONT_ALL
, &color
);
132 BView::MessageReceived(msg
);
138 BArchivable
*OverlayView::Instantiate(BMessage
*data
)
140 return new OverlayView(data
);
145 OverlayView::Archive(BMessage
*archive
, bool deep
) const
147 BView::Archive(archive
, deep
);
149 archive
->AddString("add_on", "application/x-vnd.Haiku-OverlayImage");
150 archive
->AddString("class", "OverlayImage");
154 fBitmap
->Archive(archive
);
157 //archive->PrintToStream();
164 OverlayView::OverlayAboutRequested()
166 BAlert
*alert
= new BAlert("about",
168 "Copyright 1999-2010\n\n\t"
169 "originally by Seth Flaxman\n\t"
170 "modified by Hartmuth Reh\n\t"
171 "further modified by Humdinger\n",
173 BTextView
*view
= alert
->TextView();
175 view
->SetStylable(true);
176 view
->GetFont(&font
);
177 font
.SetSize(font
.Size() + 7.0f
);
178 font
.SetFace(B_BOLD_FACE
);
179 view
->SetFontAndColor(0, 12, &font
);
180 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);