Added a new demo: OverlayImage is based on the code presented in this article:

http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer

I applied Haiku's code style, added support for transparent images, a tool tip and
limited localization (how does one make it work in the replicant's about alert?)
Since I'm a c++ newbie, corrections are probably needed and welcome.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37222 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Joachim Seemer 2010-06-22 17:58:12 +00:00
parent c5e722714e
commit 99b6a9f151
9 changed files with 388 additions and 0 deletions

View File

@ -36,6 +36,7 @@ HaikuSubInclude mediaconverter ;
HaikuSubInclude mediaplayer ;
HaikuSubInclude midiplayer ;
HaikuSubInclude networkstatus ;
HaikuSubInclude overlayimage ;
HaikuSubInclude packageinstaller ;
HaikuSubInclude pairs ;
HaikuSubInclude people ;

View File

@ -0,0 +1,16 @@
SubDir HAIKU_TOP src apps overlayimage ;
Application OverlayImage :
OverlayApp.cpp
OverlayView.cpp
OverlayWindow.cpp
: be liblocale.so libtranslation.so $(TARGET_LIBSTDC++)
: OverlayImage.rdef
;
DoCatalogs OverlayImage :
x-vnd.Haiku-OverlayImage
:
OverlayWindow.cpp
;

View File

@ -0,0 +1,34 @@
/*
* Copyright 1999-2010, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* OverlayImage is based on the code presented in this article:
* http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer
*
* Authors:
* Seth Flexman
* Hartmuth Reh
* Humdinger <humdingerb@gmail.com>
*/
#include "OverlayApp.h"
#include "OverlayWindow.h"
OverlayApp::OverlayApp()
: BApplication("application/x-vnd.Haiku-OverlayImage")
{
be_locale->GetAppCatalog(&fCatalog);
OverlayWindow *theWindow = new OverlayWindow();
theWindow->Show();
}
int
main()
{
OverlayApp theApp;
theApp.Run();
return (0);
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 1999-2010, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* OverlayImage is based on the code presented in this article:
* http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer
*
* Authors:
* Seth Flexman
* Hartmuth Reh
* Humdinger <humdingerb@gmail.com>
*/
#ifndef OVERLAY_APP_H
#define OVERLAY_APP_H
#include <Application.h>
#include <Catalog.h>
#include <Locale.h>
class OverlayApp : public BApplication {
public:
OverlayApp();
private:
BCatalog fCatalog;
};
#endif // OVERLAY_APP_H

View File

@ -0,0 +1,35 @@
resource app_signature "application/x-vnd.Haiku-OverlayImage";
resource app_flags B_MULTIPLE_LAUNCH;
resource app_version {
major = 0,
middle = 9,
minor = 0,
/* 0 = development 1 = alpha 2 = beta
3 = gamma 4 = golden master 5 = final */
variety = 5,
internal = 0,
short_info = "Replicantable Image Viewer",
long_info = "View an image and put it as replicant e.g. on the Desktop"
};
resource vector_icon {
$"6E6369660502000603399E0F3D9C0ABF82B23B84A84B88504870C900F0D733BC"
$"FFFEEAFFE0F154050105FF04019203FF00A7050606AE0B284033C3AE2A44BE00"
$"C5EC4454543C4430C5A6BACF3E2E3C28020ABB1EBB84BB1EBB84BB1EBB842E3A"
$"3038B784BE6B2C40B68DBF7130413A423243404044404242C222BEF54C3E4E40"
$"C43EBEAA4E3CC3EFBE67C6B9BDE84A36C673BC10C0FDBB773A3ABF31BC71363C"
$"323C343CB8EDBDDB020248404A404640484444444C440202C65EBE74C6D2BE67"
$"C5EDBE81C653BF0DC5C5BEDAC6DEBF400A04304A30504250424A080A03010002"
$"4014CABE1A903E2F65402966C834CE48FF1D0A01010012BC3AE4C02527402527"
$"BC3AE443BD604C697101178400040A00010002BC3FE0C029F24029F2BC3FE043"
$"99B24C6BC80A0403010203023F66E5B3B70FB829F03FF40743681746AB1E0A02"
$"0104023CF34B3F5F71BFB7D13CAD2B4B19BAC8C4530A010104123CF34B3F5F71"
$"BFB7D13CAD2B4B19BAC8C45301178200040A02010402BF34E93E641CBE641CBF"
$"34E94CFF874AC2190A01010412BF34E93E641CBE641CBF34E94CFF874AC21901"
$"17820004"
};

View File

@ -0,0 +1,146 @@
/*
* Copyright 1999-2010, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* OverlayImage is based on the code presented in this article:
* http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer
*
* Authors:
* Seth Flexman
* Hartmuth Reh
* Humdinger <humdingerb@gmail.com>
*/
#include "OverlayView.h"
#include <InterfaceDefs.h>
#include <TextView.h>
const float kDraggerSize = 7;
OverlayView::OverlayView(BRect frame)
:
BView(frame, "OverlayImage", B_FOLLOW_NONE, B_WILL_DRAW)
{
fBitmap = NULL;
fReplicated = false;
frame.left = frame.right - kDraggerSize;
frame.top = frame.bottom - kDraggerSize;
BDragger *dragger = new BDragger(frame, this, B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
AddChild(dragger);
SetViewColor(B_TRANSPARENT_COLOR);
}
OverlayView::OverlayView(BMessage *archive)
:
BView(archive)
{
fReplicated = true;
fBitmap = new BBitmap(archive);
}
OverlayView::~OverlayView()
{
delete fBitmap;
}
void
OverlayView::Draw(BRect)
{
SetDrawingMode(B_OP_ALPHA);
SetViewColor(B_TRANSPARENT_COLOR);
if (fBitmap)
DrawBitmap(fBitmap, B_ORIGIN);
}
void
OverlayView::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case B_SIMPLE_DATA:
{
if (fReplicated)
break;
entry_ref ref;
msg->FindRef("refs", &ref);
BEntry entry(&ref);
BPath path(&entry);
delete fBitmap;
fBitmap = BTranslationUtils::GetBitmap(path.Path());
if (fBitmap != NULL) {
BRect rect = fBitmap->Bounds();
if (!fReplicated)
Window()->ResizeTo(rect.right, rect.bottom);
ResizeTo(rect.right, rect.bottom);
Invalidate();
}
break;
}
case B_ABOUT_REQUESTED:
OverlayAboutRequested();
break;
default:
BView::MessageReceived(msg);
break;
}
}
BArchivable *OverlayView::Instantiate(BMessage *data)
{
return new OverlayView(data);
}
status_t
OverlayView::Archive(BMessage *archive, bool deep) const
{
BView::Archive(archive, deep);
archive->AddString("add_on", "application/x-vnd.Haiku-OverlayImage");
archive->AddString("class", "OverlayImage");
if (fBitmap) {
fBitmap->Lock();
fBitmap->Archive(archive);
fBitmap->Unlock();
}
//archive->PrintToStream();
return B_OK;
}
void
OverlayView::OverlayAboutRequested()
{
BAlert *alert = new BAlert("about",
"OverlayImage\n"
"Copyright 1999-2010" "\n\n\t"
"originally by Seth Flaxman" "\n\t"
"modified by Hartmuth Reh" "\n\t"
"further modified by Humdinger" "\n",
"OK");
BTextView *view = alert->TextView();
BFont font;
view->SetStylable(true);
view->GetFont(&font);
font.SetSize(font.Size() + 4);
font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, 9, &font);
alert->Go();
}

View File

@ -0,0 +1,47 @@
/*
* Copyright 1999-2010, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* OverlayImage is based on the code presented in this article:
* http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer
*
* Authors:
* Seth Flexman
* Hartmuth Reh
* Humdinger <humdingerb@gmail.com>
*/
#ifndef OVERLAY_VIEW_H
#define OVERLAY_VIEW_H
#include <stdio.h>
#include <Alert.h>
#include <Bitmap.h>
#include <Dragger.h>
#include <Entry.h>
#include <Path.h>
#include <TranslationUtils.h>
#include <View.h>
#include <Window.h>
class _EXPORT OverlayView;
class OverlayView : public BView {
public:
OverlayView(BRect frame);
OverlayView(BMessage *data);
~OverlayView();
virtual void Draw(BRect);
virtual void MessageReceived(BMessage *msg);
static BArchivable *Instantiate(BMessage *archive);
virtual status_t Archive(BMessage *data, bool deep = true) const;
void OverlayAboutRequested();
private:
BBitmap *fBitmap;
bool fReplicated;
};
#endif // OVERLAY_VIEW_H

View File

@ -0,0 +1,54 @@
/*
* Copyright 1999-2010, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* OverlayImage is based on the code presented in this article:
* http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer
*
* Authors:
* Seth Flexman
* Hartmuth Reh
* Humdinger <humdingerb@gmail.com>
*/
#include "OverlayView.h"
#include "OverlayWindow.h"
#include <Application.h>
#include <Catalog.h>
#include <Locale.h>
#include <String.h>
#include <TextView.h>
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Main window"
OverlayWindow::OverlayWindow()
:
BWindow(BRect(100, 100, 450, 350), "OverlayImage",
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
{
OverlayView *replView = new OverlayView(Bounds());
AddChild(replView);
BView *bgView = new BView(Bounds(), "bgView", B_FOLLOW_ALL, B_WILL_DRAW);
bgView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(bgView);
BString text;
text << B_TRANSLATE("Enable \"Show replicants\" in Deskbar.");
text << "\n";
text << B_TRANSLATE("Drag & drop an image.");
text << "\n";
text << B_TRANSLATE("Drag the replicant to the Desktop.");
replView->SetToolTip(text);
}
bool
OverlayWindow::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}

View File

@ -0,0 +1,26 @@
/*
* Copyright 1999-2010, Be Incorporated. All Rights Reserved.
* This file may be used under the terms of the Be Sample Code License.
*
* OverlayImage is based on the code presented in this article:
* http://www.haiku-os.org/documents/dev/replishow_a_replicable_image_viewer
*
* Authors:
* Seth Flexman
* Hartmuth Reh
* Humdinger
*/
#ifndef OVERLAY_WINDOW_H
#define OVERLAY_WINDOW_H
#include <Window.h>
class OverlayWindow : public BWindow {
public:
OverlayWindow();
virtual bool QuitRequested();
};
#endif // OVERLAY_WINDOW_H