SDL2_gfxutils defined types

Following types are define by SDL2_gfxutils:

typedef struct Color_ {
  uint8_t r ;
  uint8_t g ;
  uint8_t b ;
  uint8_t a ;
} Color ;


typedef struct Pixel_ {
  float x ;
  float y ;
} Pixel ;

typedef struct Segment_ {
  Pixel xy1   ;
  Pixel xy2   ;
  Color color ;
} Line ;

typedef struct Coords_ {
  float *x ;
  float *y ;
} Coords ;

typedef struct Polygon_ {
  Coords         coords      ;
  Pixel          center      ;
  Color          color       ;
  uint16_t       count       ;
  float          length      ;
  float          real_length ;
  float          orientation ;
} Polygon ;

typedef Polygon Arc          ;
typedef Polygon Hexagram     ;
typedef Polygon Pentagram    ;
typedef Polygon Star         ;
typedef Polygon Spiral       ;


typedef Polygon         Form ;
typedef Arc             Form ;
typedef Hexagram        Form ;
typedef Pentagram       Form ;
typedef Spiral          Form ;
typedef Star            Form ;

The Color type

The Color is used for holding datas about colors channels:

typedef struct Color_ {
  uint8_t r ;
  uint8_t g ;
  uint8_t b ;
  uint8_t a ;
} Color ;

The Pixel type

The Pixel type is used for holding the datas about an pixel:

the x and y coordinate values.

The Pixel type is used by functions which return a single pixel.

typedef struct Pixel_ {
  float x ;
  float y ;
} Pixel ;

Like the function get_middle_from_line().

The Line type

The Line type is used for holding the datas about a line:

  • The line start Pixel.
  • The line end Pixel.
  • The color of the line as red, green, blue and alpha values.

The Line type is used by functions which return a segment.

typedef struct Segment_ {
  Pixel xy1   ;
  Pixel xy2   ;
  Color color ;
} Line ;

Like the function generate_segment().

Or as argument from a function per example to get the middle of a line.

The Coords type

The Coords type in only used internally to be a member of the Polygon type.

typedef struct Coords_ {
  float *x ;
  float *y ;
} Coords ;

The Coords is used for performing computation.

Note

By displaying operations the float array members are converted to int16_t (the SDL2_gfx coordinates arrays standart type for displaying) in this way:

int c ;

for (c=0 ; c < form->count-2 ; c++) {

  ret=lineRGBA(pRenderer,
               (int16_t) roundf(form->coords.x[c]),
               (int16_t) roundf(form->coords.y[c]),
               (int16_t) roundf(form->coords.x[c+1]),
               (int16_t) roundf(form->coords.y[c+1]),
               form->color.r,
               form->color.g,
               form->color.b,
               form->color.a) ;
}
note:After using a Form, Wenn you do not need it in the future, you can free the form.

The Polygon type

The Polygon is used for holding all datas about a form.

  • The coordinates for computing the form generation and used by the animation functions: the Coords struct.
  • The center of the form: the Pixel struct.
  • The color of the form: the r, g, b, a members.
  • The count of coordinates number: the count member.
  • The length often the radius needed from the animating functions: the length member.
  • The length between the center and the most distant coordinate from the center: the real_length member.
  • The offset defining the incline of a form: the orientation.
typedef struct Polygon_ {
  Coords         coords      ;
  Pixel          center      ;
  Color          color       ;
  uint16_t       count       ;
  float          length      ;
  float          real_length ;
  float          orientation ;
} Polygon ;
note:All derived types are define as an Form type so that you don’t need to cast it if you use a Form generic function.

Note

Dynamically settings.

All forms generating functions set the count, length, center, orientation and the real_length member from the Polygon type.

Generic Form type.

There are many forms representing derivated types from the Polygon type.

typedef Polygon Arc          ;
typedef Polygon Hexagram     ;
typedef Polygon Pentagram    ;
typedef Polygon Star         ;
typedef Polygon Spiral       ;

All derivated types are define as a generic Form type.

typedef Polygon         Form ;
typedef Arc             Form ;
typedef Hexagram        Form ;
typedef Pentagram       Form ;
typedef Spiral          Form ;
typedef Star            Form ;

Notice

Note

Compatiblity with others libraries than SDL2:

The only purpose of the SDL2_gfx library is the form displaying functionality.

So I think it’s possible to adapt easily SDL2_gfxutils to be resusable with others libraries.

You only have to implement the displaying functions adapted to the target library.

If the coordinates arrays from type float does it for the target library, because

it’s easy to round and cast the float in the target type, like this:

int x = (int) roundf(form->coords.x[c]) ;
int y = (int) roundf(form->coords.y[c]) ;

Else the colors are coded on uint8_t values.

And the other members from the Form structure are used for computing.

Thank’s to notify me at <mrcyberfighter@gmail.com> if you want to do so.

Table Of Contents

Previous topic

SDL2_gfxutils presentation

Next topic

Base functions

This Page