1457f9cf8SStephan Aßmus /*
2457f9cf8SStephan Aßmus * Copyright (C) 2009 Stephan Aßmus <superstippi@gmx.de>
3457f9cf8SStephan Aßmus * All rights reserved. Distributed under the terms of the MIT license.
4457f9cf8SStephan Aßmus */
5457f9cf8SStephan Aßmus
6457f9cf8SStephan Aßmus #include "DrawingModeToString.h"
7457f9cf8SStephan Aßmus
8*6ed1dfa1SStephan Aßmus #include <string.h>
9*6ed1dfa1SStephan Aßmus
10*6ed1dfa1SStephan Aßmus
11457f9cf8SStephan Aßmus struct DrawingModeString {
12457f9cf8SStephan Aßmus const char* string;
13457f9cf8SStephan Aßmus drawing_mode mode;
14457f9cf8SStephan Aßmus };
15457f9cf8SStephan Aßmus
16457f9cf8SStephan Aßmus
17457f9cf8SStephan Aßmus static const DrawingModeString kDrawingModes[] = {
18457f9cf8SStephan Aßmus { "B_OP_COPY", B_OP_COPY },
19457f9cf8SStephan Aßmus { "B_OP_OVER", B_OP_OVER },
20457f9cf8SStephan Aßmus { "B_OP_ERASE", B_OP_ERASE },
21457f9cf8SStephan Aßmus { "B_OP_INVERT", B_OP_INVERT },
22457f9cf8SStephan Aßmus { "B_OP_ADD", B_OP_ADD },
23457f9cf8SStephan Aßmus { "B_OP_SUBTRACT", B_OP_SUBTRACT },
24457f9cf8SStephan Aßmus { "B_OP_BLEND", B_OP_BLEND },
25457f9cf8SStephan Aßmus { "B_OP_MIN", B_OP_MIN },
26457f9cf8SStephan Aßmus { "B_OP_MAX", B_OP_MAX },
27457f9cf8SStephan Aßmus { "B_OP_SELECT", B_OP_SELECT },
28457f9cf8SStephan Aßmus { "B_OP_ALPHA", B_OP_ALPHA }
29457f9cf8SStephan Aßmus };
30457f9cf8SStephan Aßmus
31457f9cf8SStephan Aßmus
ToDrawingMode(const char * string,drawing_mode & mode)32457f9cf8SStephan Aßmus bool ToDrawingMode(const char* string, drawing_mode& mode)
33457f9cf8SStephan Aßmus {
34457f9cf8SStephan Aßmus int entries = sizeof(kDrawingModes) / sizeof(DrawingModeString);
35457f9cf8SStephan Aßmus for (int32 i = 0; i < entries; i++) {
36457f9cf8SStephan Aßmus if (strcmp(kDrawingModes[i].string, string) == 0) {
37457f9cf8SStephan Aßmus mode = kDrawingModes[i].mode;
38457f9cf8SStephan Aßmus return true;
39457f9cf8SStephan Aßmus }
40457f9cf8SStephan Aßmus }
41457f9cf8SStephan Aßmus return false;
42457f9cf8SStephan Aßmus }
43457f9cf8SStephan Aßmus
44457f9cf8SStephan Aßmus
ToString(drawing_mode mode,const char * & string)45457f9cf8SStephan Aßmus bool ToString(drawing_mode mode, const char*& string)
46457f9cf8SStephan Aßmus {
47457f9cf8SStephan Aßmus int entries = sizeof(kDrawingModes) / sizeof(DrawingModeString);
48457f9cf8SStephan Aßmus for (int32 i = 0; i < entries; i++) {
49457f9cf8SStephan Aßmus if (kDrawingModes[i].mode == mode) {
50457f9cf8SStephan Aßmus string = kDrawingModes[i].string;
51457f9cf8SStephan Aßmus return true;
52457f9cf8SStephan Aßmus }
53457f9cf8SStephan Aßmus }
54457f9cf8SStephan Aßmus return false;
55457f9cf8SStephan Aßmus }
56