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:
parent
969ddf9c9d
commit
a45f75e0c5
66
src/apps/haikudepot/ui_generic/LinkedBitmapView.cpp
Normal file
66
src/apps/haikudepot/ui_generic/LinkedBitmapView.cpp
Normal 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);
|
||||
}
|
||||
}
|
34
src/apps/haikudepot/ui_generic/LinkedBitmapView.h
Normal file
34
src/apps/haikudepot/ui_generic/LinkedBitmapView.h
Normal 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
|
Loading…
Reference in New Issue
Block a user