HaikuDepot: LinkedBitmapView derived from BitmapView

Sends a BMessage when clicked and enabled, shows the link cursor
when hovered with the mouse.
This commit is contained in:
Stephan Aßmus 2014-11-29 16:34:13 +01:00
parent 969ddf9c9d
commit a45f75e0c5
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,66 @@
/*
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "LinkedBitmapView.h"
#include <Cursor.h>
LinkedBitmapView::LinkedBitmapView(const char* name, BMessage* message)
:
BitmapView(name),
BInvoker(message, NULL),
fEnabled(true),
fMouseInside(false)
{
}
void
LinkedBitmapView::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
// TODO: Check that no buttons are pressed, don't indicate clickable
// link if a button is held.
if (transit == B_ENTERED_VIEW) {
fMouseInside = true;
_UpdateViewCursor();
} else if (transit == B_EXITED_VIEW) {
fMouseInside = false;
_UpdateViewCursor();
}
}
void
LinkedBitmapView::MouseDown(BPoint where)
{
if (fEnabled)
Invoke(Message());
}
void
LinkedBitmapView::SetEnabled(bool enabled)
{
if (fEnabled != enabled) {
fEnabled = enabled;
_UpdateViewCursor();
}
}
void
LinkedBitmapView::_UpdateViewCursor()
{
if (fEnabled && fMouseInside) {
BCursor cursor(B_CURSOR_ID_FOLLOW_LINK);
SetViewCursor(&cursor, true);
} else {
BCursor cursor(B_CURSOR_SYSTEM_DEFAULT);
SetViewCursor(&cursor, true);
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef LINKED_BITMAP_VIEW_H
#define LINKED_BITMAP_VIEW_H
#include <Invoker.h>
#include "BitmapView.h"
class LinkedBitmapView : public BitmapView, public BInvoker {
public:
LinkedBitmapView(const char* name,
BMessage* message);
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage);
virtual void MouseDown(BPoint where);
void SetEnabled(bool enabled);
private:
void _UpdateViewCursor();
private:
bool fEnabled;
bool fMouseInside;
};
#endif // LINKED_BITMAP_VIEW_H