Made the PictureTest more useful: now it displays 2 views, one which
draws some stuff directly, the other draws the same stuff using a BPicture. This shows that BPicture doesn't support BShapes yet, and it has some problems with pen size. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19129 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,22 +1,84 @@
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <Box.h>
|
||||
#include <View.h>
|
||||
#include <Shape.h>
|
||||
#include <Picture.h>
|
||||
#include <Shape.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
|
||||
|
||||
class OriginalView : public BBox {
|
||||
public:
|
||||
OriginalView(BRect frame);
|
||||
virtual void Draw(BRect update);
|
||||
};
|
||||
|
||||
|
||||
class PictureView : public BBox {
|
||||
public:
|
||||
PictureView(BRect frame);
|
||||
~PictureView();
|
||||
|
||||
virtual void Draw(BRect update);
|
||||
virtual void AllAttached(void);
|
||||
private:
|
||||
BPicture *fPicture;
|
||||
public:
|
||||
PictureView(BRect frame);
|
||||
~PictureView();
|
||||
|
||||
virtual void Draw(BRect update);
|
||||
virtual void AllAttached();
|
||||
|
||||
private:
|
||||
BPicture *fPicture;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
DrawStuff(BView *view)
|
||||
{
|
||||
// StrokeShape
|
||||
BShape shape;
|
||||
BPoint bezier[3] = {BPoint(100,0), BPoint(100, 100), BPoint(25, 50)};
|
||||
shape.MoveTo(BPoint(150,0));
|
||||
shape.LineTo(BPoint(200,100));
|
||||
shape.BezierTo(bezier);
|
||||
shape.Close();
|
||||
view->StrokeShape(&shape);
|
||||
|
||||
// Stroke/FillRect, Push/PopState, SetHighColor, SetLineMode, SetPenSize
|
||||
view->PushState();
|
||||
const rgb_color blue = { 0, 0, 240, 0 };
|
||||
view->SetHighColor(blue);
|
||||
view->SetLineMode(B_BUTT_CAP, B_BEVEL_JOIN);
|
||||
view->SetPenSize(7);
|
||||
view->StrokeRect(BRect(10, 220, 50, 260));
|
||||
view->FillRect(BRect(65, 245, 120, 300));
|
||||
view->PopState();
|
||||
|
||||
// Stroke/FillEllipse
|
||||
view->StrokeEllipse(BPoint(50, 150), 50, 50);
|
||||
view->FillEllipse(BPoint(100, 120), 50, 50);
|
||||
|
||||
// Stroke/FillArc
|
||||
view->StrokeArc(BRect(0, 200, 50, 250), 180, 180);
|
||||
view->FillArc(BPoint(150, 250), 50, 50, 0, 125);
|
||||
|
||||
// DrawString, SetHighColor, SetFontSize
|
||||
const rgb_color red = { 240, 0, 0, 0 };
|
||||
view->SetHighColor(red);
|
||||
view->SetFontSize(20);
|
||||
view->DrawString("BPicture test", BPoint(30, 20));
|
||||
}
|
||||
|
||||
|
||||
// OriginalView
|
||||
OriginalView::OriginalView(BRect frame)
|
||||
: BBox(frame, "original_view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
OriginalView::Draw(BRect updateRect)
|
||||
{
|
||||
DrawStuff(this);
|
||||
}
|
||||
|
||||
|
||||
// PictureView
|
||||
PictureView::PictureView(BRect frame)
|
||||
: BBox(frame, "pict_view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
|
||||
fPicture(NULL)
|
||||
@@ -29,40 +91,11 @@ PictureView::~PictureView()
|
||||
}
|
||||
|
||||
void
|
||||
PictureView::AllAttached(void)
|
||||
PictureView::AllAttached()
|
||||
{
|
||||
BeginPicture(new BPicture);
|
||||
|
||||
BShape shape;
|
||||
BPoint bezier[3] = {BPoint(100,0), BPoint(100, 100), BPoint(25, 50)};
|
||||
shape.MoveTo(BPoint(150,0));
|
||||
shape.LineTo(BPoint(200,100));
|
||||
shape.BezierTo(bezier);
|
||||
shape.Close();
|
||||
StrokeShape(&shape);
|
||||
|
||||
PushState();
|
||||
const rgb_color blue = { 0, 0, 240, 0 };
|
||||
SetHighColor(blue);
|
||||
SetLineMode(B_BUTT_CAP, B_BEVEL_JOIN);
|
||||
SetPenSize(7);
|
||||
StrokeRect(BRect(10, 220, 50, 260));
|
||||
|
||||
FillRect(BRect(65, 245, 120, 300));
|
||||
PopState();
|
||||
|
||||
StrokeEllipse(BPoint(50, 150), 50, 50);
|
||||
|
||||
FillEllipse(BPoint(100, 120), 50, 50);
|
||||
|
||||
StrokeArc(BRect(0, 200, 50, 250), 180, 180);
|
||||
|
||||
FillArc(BPoint(150, 250), 50, 50, 0, 125);
|
||||
|
||||
const rgb_color red = { 240, 0, 0, 0 };
|
||||
SetHighColor(red);
|
||||
SetFontSize(20);
|
||||
DrawString("BPicture test", BPoint(30, 20));
|
||||
DrawStuff(this);
|
||||
|
||||
fPicture = EndPicture();
|
||||
}
|
||||
@@ -75,19 +108,28 @@ PictureView::Draw(BRect update)
|
||||
}
|
||||
|
||||
|
||||
// main
|
||||
int
|
||||
main(void)
|
||||
main()
|
||||
{
|
||||
BApplication *pictureApp = new BApplication("application/x-vnd.picture");
|
||||
BWindow *pictureWindow = new BWindow(BRect(100, 100, 300, 400), "BPicture test",
|
||||
B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
|
||||
PictureView *pictureView = new PictureView(pictureWindow->Bounds());
|
||||
BApplication pictureApp("application/x-vnd.picture");
|
||||
BWindow *pictureWindow = new BWindow(BRect(100, 100, 500, 400),
|
||||
"BPicture test", B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE|B_NOT_ZOOMABLE|B_QUIT_ON_WINDOW_CLOSE);
|
||||
|
||||
BRect rect(pictureWindow->Bounds());
|
||||
rect.right -= (rect.Width() + 1) / 2;
|
||||
OriginalView *testView = new OriginalView(rect);
|
||||
|
||||
rect.OffsetBy(rect.Width() + 1, 0);
|
||||
PictureView *pictureView = new PictureView(rect);
|
||||
|
||||
pictureWindow->AddChild(testView);
|
||||
pictureWindow->AddChild(pictureView);
|
||||
|
||||
pictureWindow->Show();
|
||||
pictureApp->Run();
|
||||
|
||||
delete pictureApp;
|
||||
pictureApp.Run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user