xref: /haiku/src/add-ons/input_server/methods/pen/PenInputInkWindow.cpp (revision a94e61350c94119de9924f3de6c704a10a96c0d6)
1 /*
2 	Copyright 2007, Francois Revol.   All Rights Reserved.
3 	This file may be used under the terms of the Be Sample Code License.
4 */
5 
6 #include <OS.h>
7 #include <Debug.h>
8 #include <View.h>
9 
10 #if DEBUG
11 //#include <File.h>
12 #include <Alert.h>
13 #include <Button.h>
14 #include <TextView.h>
15 #include <StringIO.h>
16 #include "DumpMessage.h"
17 #endif
18 
19 #include "PenInputInkWindow.h"
20 #include "PenInputLooper.h"
21 #include "PenInputStrings.h"
22 
23 const rgb_color kInkColor = { 100, 100, 255, 0 };
24 
25 class PenInputInkView : public BView {
26 public:
27 	PenInputInkView(BRect frame, PenInputInkWindow *window);
28 	virtual ~PenInputInkView();
29 	virtual void Draw(BRect udpateRect);
30 private:
31 	PenInputInkWindow *fWindow;
32 };
33 
PenInputInkView(BRect frame,PenInputInkWindow * window)34 PenInputInkView::PenInputInkView(BRect frame, PenInputInkWindow *window)
35 	: BView(frame, "PenInkView", B_FOLLOW_ALL, B_WILL_DRAW),
36 	  fWindow(window)
37 {
38 
39 }
40 
~PenInputInkView()41 PenInputInkView::~PenInputInkView()
42 {
43 }
Draw(BRect udpateRect)44 void PenInputInkView::Draw(BRect udpateRect)
45 {
46 	/* ugh ? */
47 	if (!fWindow)
48 		return;
49 
50 	StrokeShape(&fWindow->fStrokes);
51 	//DEBUG:StrokeRect(fWindow->fStrokes.Bounds());
52 }
53 
54 
55 
PenInputInkWindow(BRect frame)56 PenInputInkWindow::PenInputInkWindow(BRect frame)
57 	: BWindow(frame, "PenInputInkWindow",
58 			  B_NO_BORDER_WINDOW_LOOK,
59 			  B_FLOATING_ALL_WINDOW_FEEL,
60 			  B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE |
61 			  B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_AVOID_FOCUS,
62 			  B_ALL_WORKSPACES),
63 	  fStrokeCount(0)
64 {
65 	PRINT(("%s\n", __FUNCTION__));
66 	fInkView = new PenInputInkView(Bounds(), this);
67 	fInkView->SetViewColor(B_TRANSPARENT_32_BIT);
68 	fInkView->SetLowColor(B_TRANSPARENT_32_BIT);
69 	//fInkView->SetHighColor(0,255,0);
70 	fInkView->SetHighColor(kInkColor);
71 	fInkView->SetPenSize(2.0);
72 	AddChild(fInkView);
73 }
74 
~PenInputInkWindow()75 PenInputInkWindow::~PenInputInkWindow()
76 {
77 	PRINT(("%s\n", __FUNCTION__));
78 }
79 
MessageReceived(BMessage * message)80 void PenInputInkWindow::MessageReceived(BMessage *message)
81 {
82 	BPoint where;
83 	switch (message->what) {
84 	case MSG_BEGIN_INK:
85 		fStrokeCount = 0;
86 		fStrokes.Clear();
87 		// fall through
88 	case MSG_SHOW_WIN:
89 		if (IsHidden())
90 			Show();
91 		break;
92 	case MSG_END_INK:
93 	case MSG_HIDE_WIN:
94 		if (!IsHidden())
95 			Hide();
96 		break;
97 	case B_MOUSE_MOVED:
98 		if (message->FindPoint("where", &where) == B_OK) {
99 			fStrokes.LineTo(where);
100 			fStrokeCount++;
101 			//fInkView->Invalidate(fStrokes.Bounds()); // XXX
102 			fInkView->Invalidate(Bounds()); // XXX
103 		}
104 		break;
105 	case B_MOUSE_UP:
106 		if (message->FindPoint("where", &where) == B_OK) {
107 			fStrokes.LineTo(where);
108 			fStrokeCount++;
109 			//fInkView->Invalidate(fStrokes.Bounds()); // XXX
110 			fInkView->Invalidate(Bounds()); // XXX
111 		}
112 		break;
113 	case B_MOUSE_DOWN:
114 		if (message->FindPoint("where", &where) == B_OK) {
115 			fStrokes.MoveTo(where);
116 			//fStrokeCount++;
117 			//fInkView->Invalidate(fStrokes.Bounds()); // XXX
118 			fInkView->Invalidate(Bounds()); // XXX
119 		}
120 		break;
121 	default:
122 		BWindow::MessageReceived(message);
123 		return;
124 	}
125 }
126 
127