Copyright 2007, Francois Revol. All Rights Reserved.
This file may be used under the terms of the Be Sample Code License.
*/
#include <OS.h>
#include <Debug.h>
#include <View.h>
#if DEBUG
#include <Alert.h>
#include <Button.h>
#include <TextView.h>
#include <StringIO.h>
#include "DumpMessage.h"
#endif
#include "PenInputInkWindow.h"
#include "PenInputLooper.h"
#include "PenInputStrings.h"
const rgb_color kInkColor = { 100, 100, 255, 0 };
class PenInputInkView : public BView {
public:
PenInputInkView(BRect frame, PenInputInkWindow *window);
virtual ~PenInputInkView();
virtual void Draw(BRect udpateRect);
private:
PenInputInkWindow *fWindow;
};
PenInputInkView::PenInputInkView(BRect frame, PenInputInkWindow *window)
: BView(frame, "PenInkView", B_FOLLOW_ALL, B_WILL_DRAW),
fWindow(window)
{
}
PenInputInkView::~PenInputInkView()
{
}
void PenInputInkView::Draw(BRect udpateRect)
{
if (!fWindow)
return;
StrokeShape(&fWindow->fStrokes);
}
PenInputInkWindow::PenInputInkWindow(BRect frame)
: BWindow(frame, "PenInputInkWindow",
B_NO_BORDER_WINDOW_LOOK,
B_FLOATING_ALL_WINDOW_FEEL,
B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE |
B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_AVOID_FOCUS,
B_ALL_WORKSPACES),
fStrokeCount(0)
{
PRINT(("%s\n", __FUNCTION__));
fInkView = new PenInputInkView(Bounds(), this);
fInkView->SetViewColor(B_TRANSPARENT_32_BIT);
fInkView->SetLowColor(B_TRANSPARENT_32_BIT);
fInkView->SetHighColor(kInkColor);
fInkView->SetPenSize(2.0);
AddChild(fInkView);
}
PenInputInkWindow::~PenInputInkWindow()
{
PRINT(("%s\n", __FUNCTION__));
}
void PenInputInkWindow::MessageReceived(BMessage *message)
{
BPoint where;
switch (message->what) {
case MSG_BEGIN_INK:
fStrokeCount = 0;
fStrokes.Clear();
case MSG_SHOW_WIN:
if (IsHidden())
Show();
break;
case MSG_END_INK:
case MSG_HIDE_WIN:
if (!IsHidden())
Hide();
break;
case B_MOUSE_MOVED:
if (message->FindPoint("where", &where) == B_OK) {
fStrokes.LineTo(where);
fStrokeCount++;
fInkView->Invalidate(Bounds());
}
break;
case B_MOUSE_UP:
if (message->FindPoint("where", &where) == B_OK) {
fStrokes.LineTo(where);
fStrokeCount++;
fInkView->Invalidate(Bounds());
}
break;
case B_MOUSE_DOWN:
if (message->FindPoint("where", &where) == B_OK) {
fStrokes.MoveTo(where);
fInkView->Invalidate(Bounds());
}
break;
default:
BWindow::MessageReceived(message);
return;
}
}