octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

long colornames


From: Kai Habel
Subject: long colornames
Date: Thu, 21 Jun 2007 23:27:36 +0000
User-agent: IceDove 1.5.0.12 (X11/20070607)

Hello,

the following patch allows to use the long colornames
black, blue, red, green, white, magenta, cyan and yellow in addition
to the short colornames (e.g. 'k' for black color).

Example: plot([1 2],'color','magenta')

I have tried to be compatible with matlab that means:
* For example 'c' 'cy' 'cya' and 'cyan' set the color to cyan, while 'cy1' does not (it causes an error) * In case of 'b' and 'bl' - those could be 'black' or 'blue' - the blue color is being chosen.

Kai


2007-06-21  Kai Habel

* graphics.cc, graphics.h : allow usage of long colornames (e.g. 'yellow') in color_value
class.

--- graphics.h.orig     2007-06-21 22:44:23.000000000 +0000
+++ graphics.h  2007-06-21 22:44:12.000000000 +0000
@@ -144,9 +144,9 @@
     validate ();
   }
 
-  color_values (const char c)
+  color_values (std::string str)
   {
-    if (! c2rgb (c))
+    if (! str2rgb (str))
       error ("invalid color specification");
   }
 
@@ -187,7 +187,7 @@
 private:
   double xrgb[3];
 
-  bool c2rgb (char c);
+  bool str2rgb (std::string str);
 };
 
 
--- graphics.cc.orig    2007-06-15 21:50:26.000000000 +0000
+++ graphics.cc 2007-06-21 22:29:00.000000000 +0000
@@ -96,47 +96,30 @@
 }
 
 bool
-color_values::c2rgb (char c)
+color_values::str2rgb (std::string str)
 {
   double tmp_rgb[3] = {0, 0, 0};
   bool retval = true;
+  unsigned int len = str.length();
 
-  switch(c) 
-    {
-    case 'k':
-      break;
-
-    case 'r':
-      tmp_rgb[0] = 1;  
-      break;   
-
-    case 'g': 
-      tmp_rgb[1] = 1;
-      break;
-
-    case 'b':
-      tmp_rgb[2] = 1; 
-      break;
-
-    case 'c':  
-      tmp_rgb[1] = tmp_rgb[2] = 1;
-      break;
-
-    case 'm':
-      tmp_rgb[0] = tmp_rgb[2] = 1;
-      break;
-
-    case 'y': 
-      tmp_rgb[0] = tmp_rgb[1] = 1;
-      break;
-
-    case 'w': 
-      tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1;
-      break;
-
-    default:
-      retval = false;
-    }
+  if (str.compare(0, len, "blue", 0, len) == 0)
+    tmp_rgb[2] = 1;
+  else if (str.compare(0, len, "black", 0, len) == 0 || str.compare(0, len, 
"w", 0, len) == 0)
+    tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 0;
+  else if (str.compare(0, len, "red", 0, len) == 0)
+    tmp_rgb[0] = 1;
+  else if (str.compare(0, len, "green", 0, len) == 0)
+    tmp_rgb[1] = 1;
+  else if (str.compare(0, len, "yellow", 0, len) == 0)
+    tmp_rgb[0] = tmp_rgb[1] = 1;
+  else if (str.compare(0, len, "magenta", 0, len) == 0)
+    tmp_rgb[0] = tmp_rgb[2] = 1;
+  else if (str.compare(0, len, "cyan", 0, len) == 0)
+    tmp_rgb[1] = tmp_rgb[2] = 1;
+  else if (str.compare(0, len, "white", 0, len) == 0)
+    tmp_rgb[0] = tmp_rgb[1] = tmp_rgb[2] = 1;
+  else 
+    retval = false;
 
   if (retval)
     {
@@ -147,7 +130,6 @@
   return retval;
 }
 
-
 color_property::color_property (const octave_value& val)
   : radio_val (), current_val ()
 {
@@ -159,7 +141,7 @@
 
       if (! s.empty ())
        {
-         color_values col (s[0]);
+         color_values col (s);
          if (! error_state)
            {
              color_val = col;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]