cleaned up a bit the code, shaped it into a SVG2PictureView class. Added

a window to the PictureTest which should show the svg lion, but doesn't 
work yet for some reason


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19243 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-11-09 22:58:09 +00:00
parent 0976f53cef
commit c087e0e364
6 changed files with 576 additions and 2109 deletions

View File

@ -1,136 +0,0 @@
#include <Application.h>
#include <Box.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();
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)
{
}
PictureView::~PictureView()
{
delete fPicture;
}
void
PictureView::AllAttached()
{
BeginPicture(new BPicture);
DrawStuff(this);
fPicture = EndPicture();
}
void
PictureView::Draw(BRect update)
{
if (fPicture)
DrawPicture(fPicture, B_ORIGIN);
}
// main
int
main()
{
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();
return 0;
}

View File

@ -1,6 +1,25 @@
SubDir HAIKU_TOP src tests kits interface picture ;
# libicon.a source directories
local iconSourceDirs =
icon
icon/flat_icon
icon/shape
icon/style
icon/transformable
icon/transformer
;
local iconSourceDir ;
for iconSourceDir in $(iconSourceDirs) {
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src libs $(iconSourceDir) ] ;
}
# system headers
UseLibraryHeaders agg expat ;
SimpleTest PictureTest :
PictureTest.cpp
: be
SVGViewView.cpp
: be translation libexpat.a
;

View File

@ -5,6 +5,17 @@
#include <View.h>
#include <Window.h>
#include "SVGViewView.h"
class Svg2PictureWindow : public BWindow {
public:
Svg2PictureWindow(BRect frame, const char *filename)
: BWindow(frame, "Svg2Picture", B_TITLED_WINDOW, 0) {
BView *view = new Svg2PictureView(Bounds(), filename);
AddChild(view);
}
};
class OriginalView : public BBox {
public:
@ -117,6 +128,9 @@ main()
"BPicture test", B_TITLED_WINDOW,
B_NOT_RESIZABLE|B_NOT_ZOOMABLE|B_QUIT_ON_WINDOW_CLOSE);
BWindow *svgWindow = new Svg2PictureWindow(BRect(300, 300, 600, 600), "/boot/beos/etc/artwork/lion.svg");
BRect rect(pictureWindow->Bounds());
rect.right -= (rect.Width() + 1) / 2;
OriginalView *testView = new OriginalView(rect);
@ -128,7 +142,8 @@ main()
pictureWindow->AddChild(pictureView);
pictureWindow->Show();
svgWindow->Show();
pictureApp.Run();
return 0;

File diff suppressed because it is too large Load Diff

View File

@ -1,97 +1,22 @@
#ifndef _SVG_VIEW_VIEW_H
#define _SVG_VIEW_VIEW_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <String.h>
#include <View.h>
// Project Includes ------------------------------------------------------------
#include "tinyxml.h"
#include "Matrix.h"
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
enum {
STROKE_FLAG = 0x01,
FILL_FLAG = 0x02,
STROKE_WIDTH_FLAG = 0x04,
LINE_MODE_FLAG = 0x08,
FONT_SIZE_FLAG = 0x10,
MATRIX_FLAG = 0x20,
};
struct _state_ {
_state_() { set_default_values(); }
_state_(_state_ &state) { *this = state; }
void set_default_values()
{
fFlags = 0;
fStrokeColor.red = 0; fStrokeColor.green = 0;
fStrokeColor.blue = 0; fStrokeColor.alpha = 255;
fStroke = false;
fFillColor.red = 0; fFillColor.green = 0;
fFillColor.blue = 0; fFillColor.alpha = 255;
fFill = true;
fStrokeWidth = 1.0f;
fLineCap = B_BUTT_CAP;
fLineJoin = B_MITER_JOIN;
fLineMiterLimit = B_DEFAULT_MITER_LIMIT;
fFontSize = 9.0f;
}
uint32 fFlags;
rgb_color fStrokeColor;
bool fStroke;
rgb_color fFillColor;
bool fFill;
float fStrokeWidth;
cap_mode fLineCap;
join_mode fLineJoin;
float fLineMiterLimit;
float fFontSize;
BMatrix fMatrix;
};
struct named_color {
const char *name;
rgb_color color;
};
// SVGViewWindow class ------------------------------------------------------
class SVGViewView : public BView {
class BPicture;
class Svg2PictureView : public BView {
public:
SVGViewView(BRect frame, const char *name,
const char *file);
virtual ~SVGViewView();
Svg2PictureView(BRect frame, const char *filename);
~Svg2PictureView();
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow();
virtual void Draw(BRect updateRect);
private:
rgb_color GetColor(const char *name, uint8 alpha);
named_color *GetGradient(TiXmlElement *element);
void CheckAttributes(TiXmlElement *element);
void DrawNode(TiXmlNode *node);
void Push();
void Pop();
_state_ fState;
BList fStack;
BList fGradients;
BPicture *fPicture;
TiXmlDocument fDoc;
BString fFilename;
BPicture *fPicture;
};
//------------------------------------------------------------------------------
#endif // _SVG_VIEW_VIEW_H

File diff suppressed because it is too large Load Diff