2 #include "LinePathBuilder.h"
3 #include <InterfaceKit.h>
5 class ShapeLPB
: public LinePathBuilder
10 virtual void MoveTo(BPoint p
);
11 virtual void LineTo(BPoint p
);
12 virtual void BezierTo(BPoint
* p
);
13 virtual void ClosePath(void);
16 ShapeLPB(SubPath
*subPath
, float penSize
, cap_mode capMode
, join_mode joinMode
, float miterLimit
);
17 BShape
*Shape() { return &fShape
; }
20 ShapeLPB::ShapeLPB(SubPath
*subPath
, float penSize
, cap_mode capMode
, join_mode joinMode
, float miterLimit
)
21 : LinePathBuilder(subPath
, penSize
, capMode
, joinMode
, miterLimit
)
25 void ShapeLPB::MoveTo(BPoint p
)
30 void ShapeLPB::LineTo(BPoint p
)
35 void ShapeLPB::BezierTo(BPoint p
[3])
40 void ShapeLPB::ClosePath(void)
45 PathView::PathView(BRect rect
)
46 : BView(rect
, NULL
, B_FOLLOW_ALL_SIDES
, B_WILL_DRAW
| B_FULL_UPDATE_ON_RESIZE
| B_SUBPIXEL_PRECISE
) {
47 //SetViewColor(B_TRANSPARENT_COLOR);
53 void PathView::Draw(BRect updateRect
) {
54 if (fMode
== kDrawOutline
) {
56 } else if (fMode
== kStroke
) {
57 const int n
= fPath
.CountPoints();
59 for (int i
= 0; i
< n
; i
++) {
61 shape
.MoveTo(fPath
.PointAt(i
));
63 shape
.LineTo(fPath
.PointAt(i
));
65 if (fPath
.IsClosed()) shape
.Close();
69 ShapeLPB
path(&fPath
, fWidth
, LineCapMode(), LineJoinMode(), LineMiterLimit());
70 path
.CreateLinePath();
74 BeginPicture(&picture
);
75 FillShape(path
.Shape());
79 ClipToPicture(&picture
);
80 SetHighColor(0, 255, 0);
85 SetHighColor(255, 0, 0);
86 StrokeShape(path
.Shape());
91 void PathView::MouseDown(BPoint point
) {
93 GetMouse(&point
, &buttons
, false);
95 if (buttons
== B_SECONDARY_MOUSE_BUTTON
) {
96 fCurPoint
= fPath
.CountPoints();
97 fPath
.AddPoint(point
);
99 float d
= 100000000000.0;
100 for (int i
= 0; i
< fPath
.CountPoints(); i
++) {
101 BPoint p
= point
- fPath
.PointAt(i
);
102 float e
= p
.x
*p
.x
+ p
.y
*p
.y
;
103 if (e
< d
) { fCurPoint
= i
; d
= e
; }
105 fPath
.AtPut(fCurPoint
, point
);
110 void PathView::MouseMoved(BPoint point
, uint32 transit
, const BMessage
*message
) {
111 if (fCurPoint
!= -1) {
112 fPath
.AtPut(fCurPoint
, point
);
117 void PathView::MouseUp(BPoint point
) {
121 void PathView::SetClose(bool close
) {
122 if (close
) fPath
.Close();