Tscope5
|
Go to the source code of this file.
Functions | |
Coordinate functions | |
There are two coordinate systems and two coordinate scales available in Tscope5.
Some helper functions that (can help you) convert between the coordinate scales/systems, but most of the time you will only need to choose the coordinate system/scale and Tscop5 will automatically do the transormations that are necessary. | |
int | ts5_set_coordinate_system (const int coordinate_system) |
int | ts5_get_coordinate_system () |
int | ts5_set_coordinate_scale (const int coordinate_scale) |
int | ts5_get_coordinate_scale () |
void | ts5_get_target_size (double *w, double *h) |
double | ts5_get_target_width () |
double | ts5_get_target_height () |
double | ts5_relative_to_absolute_coordinate_x (const double x) |
double | ts5_relative_to_absolute_coordinate_y (const double y) |
double | ts5_absolute_to_relative_coordinate_x (const double x) |
double | ts5_absolute_to_relative_coordinate_y (const double y) |
double | ts5_cartesian_to_display_coordinate_x (const double x) |
double | ts5_cartesian_to_display_coordinate_y (const double y) |
double | ts5_display_to_cartesian_coordinate_x (const double x) |
double | ts5_display_to_cartesian_coordinate_y (const double y) |
Color definitions | |
Tscope5 describes colors in a structure (TS5_COLOR) containing red (r), green (g), blue (b) and alpha (a, transparency) values between 0.0 and 1.0. The functions below generate such a color structure using the RGB, HSL or HSV color specification or using the w3c naming system. Please note that the color structure is a structure, not a variable (they can only be assigned at the moment of declaration, not afterwards). See the examples for instructions on how to use them. | |
TS5_COLOR | ts5_make_rgb_color (const double r, const double g, const double b, const double a) |
TS5_COLOR | ts5_make_hsl_color (const double h, const double s, const double l, const double a) |
TS5_COLOR | ts5_make_hsv_color (const double h, const double s, const double v, const double a) |
TS5_COLOR | ts5_make_named_color (const char *name, const double a) |
Graphics parameter functions | |
This part contains functions to change the graphics parameters of the text output and primitives drawing functions.
The text and drawing functions do not have arguments to alter the graphics parameters. This is done with the parameter functions below. They all change one parameter, e.g. the foreground color. Once a parameter value is changed, that value is used for all further drawing until it is changed again. The parameter functions all return the previous parameter setting. This can be useful when you want to change some parameters in one part of a program, do some drawing and set the previous parameters again without causing undesired parameter changes to other parts of the program. | |
TS5_COLOR | ts5_set_foreground_color (const TS5_COLOR foreground_color) |
TS5_COLOR | ts5_get_foreground_color () |
TS5_COLOR | ts5_set_background_color (const TS5_COLOR background_color) |
TS5_COLOR | ts5_get_background_color () |
double | ts5_set_drawing_thickness (double drawing_thickness) |
double | ts5_get_drawing_thickness () |
int | ts5_set_fill_mode (const int fill_mode) |
int | ts5_get_fill_mode () |
int | ts5_set_font_type (const int font_type) |
int | ts5_get_font_type () |
int | ts5_set_font_style (const int font_style) |
int | ts5_get_font_style () |
int | ts5_set_font_size (int font_size) |
int | ts5_get_font_size () |
int | ts5_set_font_index (const int font_index) |
int | ts5_get_font_index () |
int | ts5_set_text_alignment (const int text_alignment) |
int | ts5_get_text_alignment () |
Definition in file graphics.c.
int ts5_set_coordinate_system | ( | const int | coordinate_system | ) |
Set the coordinate system.
coordinate_system | Coordinate system to be used. Can be TS5_CARTESIAN_COORDINATES and TS5_DISPLAY_COORDINATES. Default is TS5_CARTESIAN_COORDINATES. |
The TS5_DISPLAY_COORDINATES system has the origin (0,0) in the upper left corner of the display and increasing coordinate values to the left of and below the origin.
The TS5_CARTESIAN_COORDINATES system has the origin (0,0) in the center of the display and increasing coordinate values to the left of and above the origin, and decreasing (negative) values to the right of and below the origin. This is the default coordinate system.
Definition at line 60 of file graphics.c.
int ts5_get_coordinate_system | ( | ) |
int ts5_set_coordinate_scale | ( | const int | coordinate_scale | ) |
Set the coordinate scale.
coordinate_scale | Coordinate scale to be used. Can be TS5_RELATIVE_COORDINATES and TS5_ABSOLUTE_COORDINATES. Default is TS5_ABSOLUTE_COORDINATES. |
In the TS5_ABSOLUTE_COORDINATES scale coordinates are absolute pixel values. This is the default coordinate scale.
In the TS5_RELATIVE_COORDINATES scale coordinates vary from -1.0 to 1.0 in the TS5_CARTESIAN_COORDINATES system en from 0.0 to 1.0 in the TS5_DISPLAY_COORDINATES system.
Using the TS5_RELATIVE_COORDINATES scale has an influence on position but also on sizes.
Circle diameters are computed relative to the x axis.
Font size and drawing thickness are always set in pixels.
Definition at line 112 of file graphics.c.
int ts5_get_coordinate_scale | ( | ) |
void ts5_get_target_size | ( | double * | w, |
double * | h | ||
) |
Get the total size of the drawing target in pixels.
w | Variable that will store the width. |
h | Variable that will store the height. |
The drawing target can be either a display or a memory bitmap.
You can pass NULL for values you are not interested in.
Definition at line 156 of file graphics.c.
double ts5_get_target_width | ( | ) |
Get the total width of the drawing target in pixels.
The drawing target can be either a display or a memory bitmap.
Definition at line 189 of file graphics.c.
double ts5_get_target_height | ( | ) |
Get the total height of the drawing target in pixels.
The drawing target can be either a display or a memory bitmap.
Definition at line 208 of file graphics.c.
double ts5_relative_to_absolute_coordinate_x | ( | const double | x | ) |
Convert a relative horizontal coordinate into an absolute horizontal coordinate.
This function can be called using the macro ax(x)
x | Horizontal coordinate value as a proportion. |
Its behavior depends on the coordinate system used.
It is possible to call this function as a parameter to a drawing function (e.g.: when using the Cartesian coordinate system, ts5_putpixel (ts5_relative_to_absolute_coordinate_x(.5), 0); writes a pixel eighty pixels to the right of the center in the case of a 320x240 sized display, or 160 pixels to the right in the case of a 640x480 sized display).
Definition at line 240 of file graphics.c.
double ts5_relative_to_absolute_coordinate_y | ( | const double | y | ) |
Convert a relative vertical coordinate into an absolute vertical coordinate.
This function can be called using the macro ay(y)
y | Vertical coordinate value as a proportion. |
Its behaviour completely parallells that of ts5_relative_to_absolute_coordinate_x().
Definition at line 269 of file graphics.c.
double ts5_absolute_to_relative_coordinate_x | ( | const double | x | ) |
Convert an absolute horizontal coordinate into a relative horizontal coordinate.
x | Horizontal coordinate value in pixels. |
Mainly for internal use by Tscope5 itself.
Definition at line 295 of file graphics.c.
double ts5_absolute_to_relative_coordinate_y | ( | const double | y | ) |
Convert an absolute vertical coordinate into a relative vertical coordinate.
y | Vertical coordinate value in pixels. |
Mainly for internal use by Tscope5 itself.
Definition at line 322 of file graphics.c.
double ts5_cartesian_to_display_coordinate_x | ( | const double | x | ) |
Convert a horizontal Cartesian coordinate into a horizontal display coordinate.
x | Horizontal coordinate value in the Cartesian coordinate system. |
Mainly for internal use by Tscope5 itself.
Definition at line 349 of file graphics.c.
double ts5_cartesian_to_display_coordinate_y | ( | const double | y | ) |
Convert a vertical Cartesian coordinate into a vertical display coordinate.
y | Vertical coordinate value in the Cartesian coordinate system. |
Mainly for internal use by Tscope5 itself.
Definition at line 367 of file graphics.c.
double ts5_display_to_cartesian_coordinate_x | ( | const double | x | ) |
Convert a horizontal display coordinate into a horizontal Cartisian coordinate.
x | Horizontal coordinate value in the display coordinate system. |
Mainly for internal use by Tscope5 itself.
Definition at line 385 of file graphics.c.
double ts5_display_to_cartesian_coordinate_y | ( | const double | y | ) |
Convert a vertical display coordinate into a vertical Cartisian coordinate.
y | Vertical coordinate value in the display coordinate system. |
Mainly for internal use by Tscope5 itself.
Definition at line 403 of file graphics.c.
TS5_COLOR ts5_make_rgb_color | ( | const double | r, |
const double | g, | ||
const double | b, | ||
const double | a | ||
) |
Generate a color specification based on an RGB triplet plus an alpha channel.
r | Red. Range from 0.0 to 1.0. |
g | Green. Range from 0.0 to 1.0. |
b | Blue. Range from 0.0 to 1.0. |
a | Alpha. 0.0 is completely transparant and 1.0 is completely opaque. |
Definition at line 442 of file graphics.c.
TS5_COLOR ts5_make_hsl_color | ( | const double | h, |
const double | s, | ||
const double | l, | ||
const double | a | ||
) |
Generate a color specification based on an HSL triplet plus an alpha channel.
h | Hue. Range from 0.0 to 360.0. |
s | Saturation. Range from 0.0 to 1.0. |
l | Lightness. Range from 0.0 to 1.0. |
a | Alpha. 0.0 is completely transparant and 1.0 is completely opaque. |
Definition at line 465 of file graphics.c.
TS5_COLOR ts5_make_hsv_color | ( | const double | h, |
const double | s, | ||
const double | v, | ||
const double | a | ||
) |
Generate a color specification based on an HSV triplet plus an alpha channel.
h | Hue. Range from 0.0 to 360.0. |
s | Saturation. Range from 0.0 to 1.0. |
v | Value Range from 0.0 to 1.0. |
a | Alpha. 0.0 is completely transparant and 1.0 is completely opaque. |
Definition at line 491 of file graphics.c.
TS5_COLOR ts5_make_named_color | ( | const char * | name, |
const double | a | ||
) |
Return a color that corresponds to name.
name | Name of the color. |
a | Alpha. 0.0 is completely transparant and 1.0 is completely opaque. |
There recognized names are: aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque, black, blanchedalmond, blue, blueviolet, brown, burlywood, cadetblue, chartreuse, chocolate, coral, cornflowerblue, cornsilk, crimson, cyan, darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkturquoise, darkviolet, deeppink, deepskyblue, dimgray, dodgerblue, firebrick, floralwhite, forestgreen, fuchsia, gainsboro, ghostwhite, goldenrod, gold, gray, green, greenyellow, honeydew, hotpink, indianred, indigo, ivory, khaki, lavenderblush, lavender, lawngreen, lemonchiffon, lightblue, lightcoral, lightcyan, lightgoldenrodyellow, lightgreen, lightgrey, lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightsteelblue, lightyellow, lime, limegreen, linen, magenta, maroon, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, avajowhite, navy, oldlace, olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, purple, purwablue, red, rosybrown, royalblue, saddlebrown, salmon, sandybrown, seagreen, seashell, sienna, silver, skyblue, slateblue, slategray, snow, springgreen, steelblue, tan, teal, thistle, tomato, turquoise, violet, wheat, white, whitesmoke, yellow and yellowgreen.
Colors are taken from http://www.w3.org/TR/2010/PR-css3-color-20101028/#svg-color.
If the color is not found then black is returned.
Definition at line 537 of file graphics.c.
TS5_COLOR ts5_set_foreground_color | ( | const TS5_COLOR | foreground_color | ) |
Set the foreground color.
foreground_color | TS5_COLOR color specification. |
Changes the drawing color of all subsequent drawing operations. The default color is white. Once a color is set, it remains active until another color is set.
Tscope5 represents colors in an opaque structure (TS5_COLOR). Several functions exist for generating such a color definition (see above).
Definition at line 590 of file graphics.c.
TS5_COLOR ts5_get_foreground_color | ( | ) |
TS5_COLOR ts5_set_background_color | ( | const TS5_COLOR | background_color | ) |
Set the background color.
background_color | TS5_COLOR color specification. |
Changes the background color of all new drawing targets or when a drawing target is cleared.
The default color is black. Once a color is set, it remains active until another color is set.
Definition at line 634 of file graphics.c.
TS5_COLOR ts5_get_background_color | ( | ) |
double ts5_set_drawing_thickness | ( | double | drawing_thickness | ) |
Set the drawing thickness.
drawing_thickness | Drawing thickness in pixels. |
Changes thickness of lines for all drawing operations.
The default thickness is 0 (hairline).
Definition at line 678 of file graphics.c.
double ts5_get_drawing_thickness | ( | ) |
Get the drawing thickness.
Definition at line 703 of file graphics.c.
int ts5_set_fill_mode | ( | const int | fill_mode | ) |
Set the fill mode.
fill_mode | Fill mode. Can be TS5_FILL_ON or TS5_FILL_OFF. |
Changes the fill mode for future drawing operations.
The default fill mode is TS5_FILL_OFF.
Definition at line 723 of file graphics.c.
int ts5_get_fill_mode | ( | ) |
int ts5_set_font_type | ( | const int | font_type | ) |
Set the font type.
font_type | Font type. Can be TS5_COURIER, TS5_ARIAL and TS5_TIMES. |
The default font type is TS5_COURIER.
Definition at line 766 of file graphics.c.
int ts5_get_font_type | ( | ) |
int ts5_set_font_style | ( | const int | font_style | ) |
Set the font style.
font_style | Font style. Can be TS5_REGULAR, TS5_BOLD, TS5_ITALIC or TS5_BOLD_ITALIC. |
The default font style is TS5_BOLD.
Definition at line 814 of file graphics.c.
int ts5_get_font_style | ( | ) |
int ts5_set_font_size | ( | int | font_size | ) |
Set the font size.
font_size | Font size. Can be any value between 8 and 107. |
The default font size is 20.
Definition at line 864 of file graphics.c.
int ts5_get_font_size | ( | ) |
Get the font size.
Definition at line 894 of file graphics.c.
int ts5_set_font_index | ( | const int | font_index | ) |
Set the font index.
font_index | Font index. Can be any integer between 0 and TS5_NFONTS-1. |
Sets the font type, style and width at once.
Definition at line 913 of file graphics.c.
int ts5_get_font_index | ( | ) |
int ts5_set_text_alignment | ( | const int | text_alignment | ) |
Set the alignment of text.
text_alignment | Text alignment. Can be TS5_ALIGN_LEFT, TS5_ALIGN_CENTER or TS5_ALIGN_RIGHT. |
The default aligment is TS5_ALIGN_CENTER.
Definition at line 961 of file graphics.c.
int ts5_get_text_alignment | ( | ) |
Get the alignment of text.
Definition at line 989 of file graphics.c.