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