Tscope5
graphics.c File Reference

Definitions of graphics parameter functions. More...

Go to the source code of this file.

Functions

Coordinate functions

There are two coordinate systems and two coordinate scales available in Tscope5.

  • There is a Display coordinate system, with the origin (0,0) in the upper left corner of the display, with increasing coordinate values to the right of and below the origin.
  • There is also a Cartesian system, with the origin (0,0) in the center of the display, increasing coordinate values to the right and above the origin and decreasing (negative) values to the left and below the origin.
  • Default is the Cartesian system.
  • There is an absolute coordinate scale where coordinates are interpreted as pixel values.
  • There is a relative coordinate scale where coordinates are interpreted relative to the display size.
  • The default is the absolute system.

Some helper functions that (can help you) convert between the coordinate scales/systems are available, 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)
 Set the coordinate system. More...
 
int ts5_get_coordinate_system ()
 Get the coordinate system. More...
 
int ts5_set_coordinate_scale (const int coordinate_scale)
 Set the coordinate scale. More...
 
int ts5_get_coordinate_scale ()
 Get the coordinate scale. More...
 
double ts5_relative_to_absolute_coordinate_x (const double x)
 Convert a relative horizontal coordinate into an absolute horizontal coordinate. More...
 
double ts5_relative_to_absolute_coordinate_y (const double y)
 Convert a relative vertical coordinate into an absolute vertical coordinate. More...
 
double ts5_absolute_to_relative_coordinate_x (const double x)
 Convert an absolute horizontal coordinate into a relative horizontal coordinate. More...
 
double ts5_absolute_to_relative_coordinate_y (const double y)
 Convert an absolute vertical coordinate into a relative vertical coordinate. More...
 
double ts5_cartesian_to_display_coordinate_x (const double x)
 Convert a horizontal Cartesian coordinate into a horizontal display coordinate. More...
 
double ts5_cartesian_to_display_coordinate_y (const double y)
 Convert a vertical Cartesian coordinate into a vertical display coordinate. More...
 
double ts5_display_to_cartesian_coordinate_x (const double x)
 Convert a horizontal display coordinate into a horizontal Cartisian coordinate. More...
 
double ts5_display_to_cartesian_coordinate_y (const double y)
 Convert a vertical display coordinate into a vertical Cartisian coordinate. More...
 
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)
 Generate a color specification based on an RGB triplet plus an alpha channel. More...
 
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. More...
 
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. More...
 
TS5_COLOR ts5_make_named_color (const char *name, const double a)
 Return a color that corresponds to name. More...
 
Graphics parameter functions

This part contains functions to change the graphics parameters of the text output and primitives drawing functions.

  • By default, text appears 20pt Courier Bold.
  • Primitives are not filled, and drawn with hairline thickness.
  • All drawing is done in white against a black background.

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)
 Set the foreground color. More...
 
TS5_COLOR ts5_get_foreground_color ()
 Get the foreground color. More...
 
TS5_COLOR ts5_set_background_color (const TS5_COLOR background_color)
 Set the background color. More...
 
TS5_COLOR ts5_get_background_color ()
 Get the background color. More...
 
double ts5_set_drawing_thickness (double drawing_thickness)
 Set the drawing thickness. More...
 
double ts5_get_drawing_thickness ()
 Get the drawing thickness. More...
 
int ts5_set_fill_mode (const int fill_mode)
 Set the fill mode. More...
 
int ts5_get_fill_mode ()
 Get the fill mode. More...
 
int ts5_set_font_type (const int font_type)
 Set the font type. More...
 
int ts5_get_font_type ()
 Get the font type. More...
 
int ts5_set_font_style (const int font_style)
 Set the font style. More...
 
int ts5_get_font_style ()
 Get the font style. More...
 
int ts5_set_font_size (int font_size)
 Set the font size. More...
 
int ts5_get_font_size ()
 Get the font size. More...
 
int ts5_set_font_index (const int font_index)
 Set the font index. More...
 
int ts5_get_font_index ()
 Get the font index. More...
 
int ts5_set_text_alignment (const int text_alignment)
 Set the alignment of text. More...
 
int ts5_get_text_alignment ()
 Get the alignment of text. More...
 

Detailed Description

Definitions of graphics parameter functions.

Definition in file graphics.c.

Function Documentation

int ts5_set_coordinate_system ( const int  coordinate_system)

Set the coordinate system.

Parameters
coordinate_systemCoordinate system to be used. Can be TS5_CARTESIAN_COORDINATES and TS5_DISPLAY_COORDINATES. Default is TS5_CARTESIAN_COORDINATES.
Returns
The previous coordinate system.

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, 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.

Examples:
bitmaps03.c, bitmaps04.c, cedrusbox01.c, display06.c, graphics03.c, graphics04.c, joystick01.c, keyboard01.c, mouse01.c, parport01.c, primitives03.c, primitives04.c, randomizer01.c, randomizer02.c, randomizer03.c, serialport01.c, textio04.c, and textio05.c.

Definition at line 81 of file graphics.c.

int ts5_get_coordinate_system ( )

Get the coordinate system.

Returns
The coordinate system.

Definition at line 113 of file graphics.c.

int ts5_set_coordinate_scale ( const int  coordinate_scale)

Set the coordinate scale.

Parameters
coordinate_scaleCoordinate scale to be used. Can be TS5_RELATIVE_COORDINATES and TS5_ABSOLUTE_COORDINATES. Default is TS5_ABSOLUTE_COORDINATES.
Returns
The previous coordinate scale.

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 between -1.0 and 1.0 in the TS5_CARTESIAN_COORDINATES system and between 0.0 abd 1.0 in the TS5_DISPLAY_COORDINATES system.

Using the TS5_RELATIVE_COORDINATES scale has an influence on position but also on sizes:

  • Display sizes are computed relative to the display adapter.
  • Bitmap sizes are computed relative to the active display.
  • Circle diameters are computed relative to the x axis.
  • Font size and drawing thickness are always set in pixels.
  • When querying the size of the display (adapter), drawing target or a bitmap the size in pixels is returned.
Examples:
bitmaps02.c, bitmaps04.c, cedrusbox01.c, graphics02.c, graphics04.c, graphics05.c, graphics06.c, graphics07.c, graphics08.c, graphics09.c, graphics10.c, joystick01.c, keyboard01.c, mouse01.c, mouse02.c, parport01.c, primitives02.c, primitives04.c, and serialport01.c.

Definition at line 147 of file graphics.c.

int ts5_get_coordinate_scale ( )

Get the coordinate scale.

Returns
The coordinate scale.

Definition at line 175 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)

Parameters
xHorizontal coordinate value as a proportion.
Returns
Horizontal coordinate value in pixels.

Its behavior depends on the coordinate system used.

  • With the Cartesian system x=0 refers to the center of the display, x=1 refers the to right-hand side border and x=-1 refers to the left-hand side border.
  • With the display system x=0 refers to the right-hand side border and x=1 refers to the left-hand side border.

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 80 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).

Examples:
randomizer01.c, randomizer02.c, and randomizer03.c.

Definition at line 208 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)

Parameters
yVertical coordinate value as a proportion.
Returns
Vertical coordinate value in pixels.

Its behaviour completely parallells that of ts5_relative_to_absolute_coordinate_x().

Examples:
randomizer01.c, randomizer02.c, and randomizer03.c.

Definition at line 240 of file graphics.c.

double ts5_absolute_to_relative_coordinate_x ( const double  x)

Convert an absolute horizontal coordinate into a relative horizontal coordinate.

This function can be called using the macro rx(x)

Parameters
xHorizontal coordinate value in pixels.
Returns
Horizontal coordinate value as a proportion.

Mainly for internal use by Tscope5 itself.

Definition at line 271 of file graphics.c.

double ts5_absolute_to_relative_coordinate_y ( const double  y)

Convert an absolute vertical coordinate into a relative vertical coordinate.

This function can be called using the macro ry(y)

Parameters
yVertical coordinate value in pixels.
Returns
Vertical coordinate value as a proportion.

Mainly for internal use by Tscope5 itself.

Definition at line 302 of file graphics.c.

double ts5_cartesian_to_display_coordinate_x ( const double  x)

Convert a horizontal Cartesian coordinate into a horizontal display coordinate.

This function can be called using the macro dx(x)

Parameters
xHorizontal coordinate value in the Cartesian coordinate system.
Returns
The coordinate value in the display coordinate system.

Mainly for internal use by Tscope5 itself.

Definition at line 333 of file graphics.c.

double ts5_cartesian_to_display_coordinate_y ( const double  y)

Convert a vertical Cartesian coordinate into a vertical display coordinate.

This function can be called using the macro dy(y)

Parameters
yVertical coordinate value in the Cartesian coordinate system.
Returns
The coordinate value in the display coordinate system.

Mainly for internal use by Tscope5 itself.

Definition at line 354 of file graphics.c.

double ts5_display_to_cartesian_coordinate_x ( const double  x)

Convert a horizontal display coordinate into a horizontal Cartisian coordinate.

This function can be called using the macro cx(x)

Parameters
xHorizontal coordinate value in the display coordinate system.
Returns
The coordinate value in the Cartesian coordinate system.

Mainly for internal use by Tscope5 itself.

Definition at line 375 of file graphics.c.

double ts5_display_to_cartesian_coordinate_y ( const double  y)

Convert a vertical display coordinate into a vertical Cartisian coordinate.

This function can be called using the macro cy(y)

Parameters
yVertical coordinate value in the display coordinate system.
Returns
The coordinate value in the Cartesian coordinate system.

Mainly for internal use by Tscope5 itself.

Definition at line 396 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.

Parameters
rRed. Range from 0.0 to 1.0.
gGreen. Range from 0.0 to 1.0.
bBlue. Range from 0.0 to 1.0.
aAlpha. 0.0 is completely transparant and 1.0 is completely opaque.
Returns
TS5_COLOR structure.
Examples:
graphics05.c.

Definition at line 436 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.

Parameters
hHue. Range from 0.0 to 360.0.
sSaturation. Range from 0.0 to 1.0.
lLightness. Range from 0.0 to 1.0.
aAlpha. 0.0 is completely transparant and 1.0 is completely opaque.
Returns
TS5_COLOR sctructure.
Examples:
graphics06.c.

Definition at line 463 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.

Parameters
hHue. Range from 0.0 to 360.0.
sSaturation. Range from 0.0 to 1.0.
vValue Range from 0.0 to 1.0.
aAlpha. 0.0 is completely transparant and 1.0 is completely opaque.
Returns
TS5_COLOR sctructure.
Examples:
graphics07.c.

Definition at line 493 of file graphics.c.

TS5_COLOR ts5_make_named_color ( const char *  name,
const double  a 
)

Return a color that corresponds to name.

Parameters
nameName of the color.
aAlpha. 0.0 is completely transparant and 1.0 is completely opaque.
Returns
TS5_COLOR sctructure.

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.

Examples:
bitmaps01.c, bitmaps02.c, bitmaps03.c, bitmaps04.c, graphics01.c, graphics02.c, graphics03.c, graphics04.c, graphics08.c, and graphics09.c.

Definition at line 549 of file graphics.c.

TS5_COLOR ts5_set_foreground_color ( const TS5_COLOR  foreground_color)

Set the foreground color.

Parameters
foreground_colorTS5_COLOR color specification.
Returns
The previous foreground color.

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).

Examples:
graphics01.c, graphics02.c, graphics03.c, graphics04.c, graphics05.c, graphics06.c, graphics07.c, graphics08.c, and graphics09.c.

Definition at line 607 of file graphics.c.

TS5_COLOR ts5_get_foreground_color ( )

Get the foreground color.

Returns
The foreground color.

Definition at line 632 of file graphics.c.

TS5_COLOR ts5_set_background_color ( const TS5_COLOR  background_color)

Set the background color.

Parameters
background_colorTS5_COLOR color specification.
Returns
The previous background color.

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.

Examples:
graphics01.c, graphics02.c, graphics03.c, graphics04.c, and graphics09.c.

Definition at line 654 of file graphics.c.

TS5_COLOR ts5_get_background_color ( )

Get the background color.

Returns
The background color.

Definition at line 678 of file graphics.c.

double ts5_set_drawing_thickness ( double  drawing_thickness)

Set the drawing thickness.

Parameters
drawing_thicknessDrawing thickness in pixels.
Returns
The previous thickness.

Changes thickness of lines for all drawing operations.

The default thickness is 0 (hairline).

Examples:
bitmaps05.c, display06.c, and graphics09.c.

Definition at line 698 of file graphics.c.

double ts5_get_drawing_thickness ( )

Get the drawing thickness.

Returns
The drawing thickness.

Definition at line 726 of file graphics.c.

int ts5_set_fill_mode ( const int  fill_mode)

Set the fill mode.

Parameters
fill_modeFill mode. Can be TS5_FILL_ON or TS5_FILL_OFF.
Returns
The previous fill mode.

Changes the fill mode for future drawing operations.

The default fill mode is TS5_FILL_OFF.

Examples:
graphics01.c, graphics02.c, graphics03.c, graphics04.c, graphics05.c, graphics06.c, graphics07.c, and graphics08.c.

Definition at line 746 of file graphics.c.

int ts5_get_fill_mode ( )

Get the fill mode.

Returns
The fill mode.

Definition at line 772 of file graphics.c.

int ts5_set_font_type ( const int  font_type)

Set the font type.

Parameters
font_typeFont type. Can be TS5_COURIER, TS5_ARIAL and TS5_TIMES.
Returns
The previous font type.

The default font type is TS5_COURIER.

Examples:
graphics10.c, and textio03.c.

Definition at line 790 of file graphics.c.

int ts5_get_font_type ( )

Get the font type.

Returns
The font type.

Definition at line 824 of file graphics.c.

int ts5_set_font_style ( const int  font_style)

Set the font style.

Parameters
font_styleFont style. Can be TS5_REGULAR, TS5_BOLD, TS5_ITALIC or TS5_BOLD_ITALIC.
Returns
The previous font style.

The default font style is TS5_BOLD.

Examples:
graphics10.c, and textio03.c.

Definition at line 843 of file graphics.c.

int ts5_get_font_style ( )

Get the font style.

Returns
The font style.

Definition at line 879 of file graphics.c.

int ts5_set_font_size ( int  font_size)

Set the font size.

Parameters
font_sizeFont size. Can be any value between 8 and 107.
Returns
The previous font size.

The default font size is 20.

Examples:
graphics10.c, and textio03.c.

Definition at line 897 of file graphics.c.

int ts5_get_font_size ( )

Get the font size.

Returns
The font size.
Examples:
textio03.c.

Definition at line 927 of file graphics.c.

int ts5_set_font_index ( const int  font_index)

Set the font index.

Parameters
font_indexFont index. Can be any integer between 0 and TS5_NFONTS-1.
Returns
The previous font index.

Sets the font type, style and width at once.

Definition at line 948 of file graphics.c.

int ts5_get_font_index ( )

Get the font index.

Returns
The font index.

Definition at line 985 of file graphics.c.

int ts5_set_text_alignment ( const int  text_alignment)

Set the alignment of text.

Parameters
text_alignmentText alignment. Can be TS5_ALIGN_LEFT, TS5_ALIGN_CENTER or TS5_ALIGN_RIGHT.
Returns
The previous alignment setting.

The default aligment is TS5_ALIGN_CENTER.

Examples:
cedrusbox01.c, joystick01.c, keyboard01.c, mouse01.c, parport01.c, randomizer01.c, randomizer02.c, randomizer03.c, serialport01.c, textio01.c, textio04.c, textio05.c, and timer04.c.

Definition at line 1004 of file graphics.c.

int ts5_get_text_alignment ( )

Get the alignment of text.

Returns
The alignment setting.

Definition at line 1035 of file graphics.c.