1 /* 2 * Copyright (C) 2009 Stephan Aßmus <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 6 #include "DrawingModeToString.h" 7 8 #include <string.h> 9 10 11 struct DrawingModeString { 12 const char* string; 13 drawing_mode mode; 14 }; 15 16 17 static const DrawingModeString kDrawingModes[] = { 18 { "B_OP_COPY", B_OP_COPY }, 19 { "B_OP_OVER", B_OP_OVER }, 20 { "B_OP_ERASE", B_OP_ERASE }, 21 { "B_OP_INVERT", B_OP_INVERT }, 22 { "B_OP_ADD", B_OP_ADD }, 23 { "B_OP_SUBTRACT", B_OP_SUBTRACT }, 24 { "B_OP_BLEND", B_OP_BLEND }, 25 { "B_OP_MIN", B_OP_MIN }, 26 { "B_OP_MAX", B_OP_MAX }, 27 { "B_OP_SELECT", B_OP_SELECT }, 28 { "B_OP_ALPHA", B_OP_ALPHA } 29 }; 30 31 32 bool ToDrawingMode(const char* string, drawing_mode& mode) 33 { 34 int entries = sizeof(kDrawingModes) / sizeof(DrawingModeString); 35 for (int32 i = 0; i < entries; i++) { 36 if (strcmp(kDrawingModes[i].string, string) == 0) { 37 mode = kDrawingModes[i].mode; 38 return true; 39 } 40 } 41 return false; 42 } 43 44 45 bool ToString(drawing_mode mode, const char*& string) 46 { 47 int entries = sizeof(kDrawingModes) / sizeof(DrawingModeString); 48 for (int32 i = 0; i < entries; i++) { 49 if (kDrawingModes[i].mode == mode) { 50 string = kDrawingModes[i].string; 51 return true; 52 } 53 } 54 return false; 55 } 56