1.2.1 Data Types and Variables
ANSI C Data Types
Origin C supports all the ANSI C Data Types: char char Type, short short Type, int Integer Type, float float Type, double double Type, and void void Return Type. In addition, you can declare arrays of, and pointers Pointer to, each of these 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
Origin C Composite Data Types
Array, One-DimensionalArray, Two-Dimensional
Although C-style array syntax is supported, Origin C provides the string string, vector vector, and matrix matrix classes to simplify working with one- and two-dimensional data. Supported element types include char, byte, short, word, int, uint, and complex. A vector can be of type string (string array String Array), but a matrix cannot; matrix is numeric 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}; // 'double' implied
vector<string> vs(3); // Declare a string array
vs[0] = "This ";
vs[1] = "is ";
vs[2] = "test";
matrix<int> mA1; // Matrix of integers
matrix mA2; // Matrix of doubles (implied)
// NOTE: If no element type is specified, vector/matrix default to double.
Another useful class is complex. It stores a real Complex, Real Component and an imaginary Complex, Imaginary Component component.
complex cc(4.5, 7.8); // real = 4.5, imaginary = 7.8
out_complex("value = ", cc); // Output the complex value
Color
Colors in Origin C are represented by a DWORD value. This can be either an index into Origin’s internal color palette Color Palette or an RGB color composed of red, green, and blue components.
Palette Index
Origin’s internal Palette contains 24 colors. A palette index is zero-based (0–23). Origin C provides named constants, each beginning with SYSCOLOR_.
| 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;
Auto Color Color, Auto Color
A special palette index, Auto, colors an element using the same color as its parent (when supported by that element’s UI).
Use the INDEX_COLOR_AUTOMATIC macro to specify Auto:
DWORD dwColor = INDEX_COLOR_AUTOMATIC;
RGB RGB
An Origin color can also represent an RGB value (8-bit red, green, and blue components). Use the RGB macro to create an RGB value, then convert it to an Origin color with RGB2OCOLOR.
DWORD brown = RGB2OCOLOR(RGB(139,69,19)); // saddle brown
Color, Check as RGB Value or Palette IndexTo test whether a color is RGB vs. palette index, use OCOLOR_IS_RGB:
if ( OCOLOR_IS_RGB(ocolor) )
out_str("color value represents an RGB color");
else
out_str("color value represents a color index");
Color, Extract Single Color from RGBTo extract component values from an RGB-based Origin color, first get the RGB with GET_CRF_FROM_RGBOCOLOR, then query components:
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));
}
|