Origin C supports all the ANSI C data types
: char , short , int , float , double and void . In addition, you can have an array of, and a pointer to, each of these data types.char name[50]; // Declare an array of characters unsigned char age; // Declare an unsigned 8-bit integer unsigned short year; // Declare an unsigned 16-bit integer
Although the C syntax for declaring an array is supported, Origin C provides string , vector and matrix classes to simplify working with data types in one or two dimensional arrays. These data types include char, byte, short, word, int, uint, complex. A vector can be of type string for a string array , but a matrix cannot. A matrix can be of numerical types only.
string str = "hello, world\n"; // Declare and initialize a string vector<double> vA1 = {1.5, 1.8, 1.1}; // Declare and initialize doubles vector vA2 = {2.5, 2.8, 2.1, 2.4}; vector<string> vs(3); // Declare a string array vs[0] = "This "; // Assign string to each string array item vs[1] = "is "; vs[2] = "test"; matrix<int> mA1; // Declare a matrix of integers matrix mA2; // Declare a matrix of doubles // NOTE: The double data type is implied when a data type is not // specified in the declaration of vector and matrix variables.
Another useful class provided by Origin C is the complex class. The complex class supports numeric data containing both a real
and an imaginary component.complex cc(4.5, 7.8); // Declare a complex value. // The real component is set to 4.5 and // the imaginary component is set to 7.8 out_complex("value = ", cc); // Output the complex value
Colors in Origin C are represented with a DWORD value. These values can be an index into Origin's internal color palette
or an actual color composed of red, green, and blue components.Origin's internal Palette contains 24 colors. An index into Origin's internal color palette is a zero based value from 0 to 23. Origin C provides named constants for each of these colors. Each name begins with the prefix SYSCOLOR_ followed by the name of the color. The following table lists the 24 color names and their indices.
Index | Name | Index | Name |
---|---|---|---|
0 | SYSCOLOR_BLACK | 12 | SYSCOLOR_DKCYAN |
1 | SYSCOLOR_RED | 13 | SYSCOLOR_ROYAL |
2 | SYSCOLOR_GREEN | 14 | SYSCOLOR_ORANGE |
3 | SYSCOLOR_BLUE | 15 | SYSCOLOR_VIOLET |
4 | SYSCOLOR_CYAN | 16 | SYSCOLOR_PINK |
5 | SYSCOLOR_MAGENTA | 17 | SYSCOLOR_WHITE |
6 | SYSCOLOR_YELLOW | 18 | SYSCOLOR_LTGRAY |
7 | SYSCOLOR_DKYELLOW | 19 | SYSCOLOR_GRAY |
8 | SYSCOLOR_NAVY | 20 | SYSCOLOR_LTYELLOW |
9 | SYSCOLOR_PURPLE | 21 | SYSCOLOR_LTCYAN |
10 | SYSCOLOR_WINE | 22 | SYSCOLOR_LTMAGENTA |
11 | SYSCOLOR_OLIVE | 23 | SYSCOLOR_DKGRAY |
DWORD dwColor = SYSCOLOR_ORANGE;
There is a special color index referred to as Auto. When this index is used the element will be colored using the same color as its parent. Not all elements support the Auto index. See Origin's graphical user interface for the element to determine if the Auto index is supported.
The INDEX_COLOR_AUTOMATIC macro is used when the Auto index value is needed.
DWORD dwColor = INDEX_COLOR_AUTOMATIC;
An Origin color value can also represent an RGB value. RGB values are made up of 8-bit red, green, and blue components. These values can easily be made using the RGB macro}.
DWORD brown = RGB(139,69,19); // saddle brown
The values returned from the RGB macro cannot be directly used as Origin color values. You will need to use the RGB2OCOLOR macro to convert the RGB values to Origin color values.
DWORD brown = RGB2OCOLOR(RGB(139,69,19)); // saddle brown
If you ever need to know whether an Origin color value represents an RGB value or an index into a palette then you can use the OCOLOR_IS_RGB macro. This macro returns true if the value represents an RGB value and returns false otherwise.
if( OCOLOR_IS_RGB(ocolor) ) out_str("color value represents an RGB color"); else out_str("color value represents a color index");
Once you determine that an Origin color value represents an RGB value, then you can use the GET_CRF_FROM_RGBOCOLOR macro to extract the RGB value from the Origin color value.
if( OCOLOR_IS_RGB(ocolor) ) { DWORD rgb = GET_CRF_FROM_RGBOCOLOR(ocolor); printf("red = %d, green = %d, blue = %d\n", GetRValue(rgb), GetGValue(rgb), GetBValue(rgb)); }