xref: /haiku/src/libs/icon/transformer/TransformerFactory.cpp (revision a1163de83ea633463a79de234b8742ee106531b2)
1 /*
2  * Copyright 2006-2007, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "TransformerFactory.h"
10 
11 #include "AffineTransformer.h"
12 #include "ContourTransformer.h"
13 #include "PerspectiveTransformer.h"
14 #include "StrokeTransformer.h"
15 
16 #ifdef ICON_O_MATIC
17 # include <Message.h>
18 #endif
19 
20 using namespace BPrivate::Icon;
21 
22 
23 // TransformerFor
24 Transformer*
25 TransformerFactory::TransformerFor(uint32 type, VertexSource& source)
26 {
27 	switch (type) {
28 		case 0:
29 			return new AffineTransformer(source);
30 		case 1:
31 			return new PerspectiveTransformer(source);
32 		case 2:
33 			return new ContourTransformer(source);
34 		case 3:
35 			return new StrokeTransformer(source);
36 	}
37 
38 	return NULL;
39 }
40 
41 // TransformerFor
42 Transformer*
43 TransformerFactory::TransformerFor(BMessage* message,
44 								   VertexSource& source)
45 {
46 	switch (message->what) {
47 		case AffineTransformer::archive_code:
48 			return new AffineTransformer(source, message);
49 		case PerspectiveTransformer::archive_code:
50 			return new PerspectiveTransformer(source, message);
51 		case ContourTransformer::archive_code:
52 			return new ContourTransformer(source, message);
53 		case StrokeTransformer::archive_code:
54 			return new StrokeTransformer(source, message);
55 	}
56 
57 	return NULL;
58 }
59 
60 #ifdef ICON_O_MATIC
61 
62 // NextType
63 bool
64 TransformerFactory::NextType(int32* cookie, uint32* type, BString* name)
65 {
66 	*type = *cookie;
67 	*cookie = *cookie + 1;
68 
69 	switch (*type) {
70 		case 0:
71 			*name = "Transformation";
72 			return true;
73 		case 1:
74 			*name = "Perspective";
75 			return true;
76 		case 2:
77 			*name = "Contour";
78 			return true;
79 		case 3:
80 			*name = "Stroke";
81 			return true;
82 	}
83 
84 	return false;
85 }
86 #endif // ICON_O_MATIC
87