bx-lib : the Basic X11 Library tuned for C beginners  1.0
Functions
Drawing simple shapes (points, lines, boxes, circles...)
Drawing (what you can do with a pen on a canvas)

Functions

void bx_draw_point (bx_window win, int x, int y)
void bx_draw_line (bx_window win, int x1, int y1, int x2, int y2)
void bx_draw_box (bx_window win, int x, int y, unsigned w, unsigned h, bx_fill filled)
void bx_draw_circle (bx_window win, int x, int y, unsigned w, unsigned h, bx_fill filled)
void bx_draw_arc (bx_window win, int x, int y, unsigned w, unsigned h, double angle, double dangle, bx_fill filled)

Detailed Description

Function Documentation

void bx_draw_point ( bx_window  win,
int  x,
int  y 
)

Draws a point on the canvas of a window.

Parameters
winthe window owning the targeted canvas.
x,ythe coordinates of the point to draw.
Returns
nothing
Remarks
  • the coordinates are relative to the top-left corner of the canvas.
  • the y-axis is oriented downward.
  • the updated canvas will be shown after the next call to bx_show_canvas().
  • the color is set with bx_set_color() or bx_set_rgb().
void bx_draw_line ( bx_window  win,
int  x1,
int  y1,
int  x2,
int  y2 
)

Draws a line segment on the canvas of a window.

Parameters
winthe window owning the targeted canvas.
x1,y1the coordinates of the 1st end-point of the segment.
x2,y2the coordinates of the 2nd end-point of the segment.
Returns
nothing
Remarks
bx_draw_line.jpg
#include <bx.h>
int main (void)
{
bx_window win;
int w=300, h= 100;
int x= w/2, y= h/2;
int r1= 20, r2= w/2-10, r3= h/2-10, k;
bx_init ();
win= bx_create_window ("bx_draw_line", 10 , 10, w, h);
for (k= 0; k < 360; k+=10) {
double angle= (k+ 0) / 180.0 * 3.1415;
bx_draw_line (win,
x + r1 * cos (angle), y + r1 * sin (angle),
x + r2 * cos (angle), y + r3 * sin (angle));
}
bx_show_canvas (win, 0);
return 0;
}
void bx_draw_box ( bx_window  win,
int  x,
int  y,
unsigned  w,
unsigned  h,
bx_fill  filled 
)

Draws a rectangle on the canvas of a window, whose interior may be filled or left empty.

Parameters
winthe window owning the targeted canvas.
x,ythe coordinates of the top left corner of the rectangle.
w,hthe width and height (minus 1) of the rectangle, so that the bottom-right corner of the bounding-box is located at (x+w, y+h).
filledwhether the interior of the rectangle is filled (no-zero) or left empty (zero)
Returns
nothing
Remarks
void bx_draw_circle ( bx_window  win,
int  x,
int  y,
unsigned  w,
unsigned  h,
bx_fill  filled 
)

Draws an ellipse on the canvas of a window, whose interior may be filled or left empty.

Parameters
winthe window owning the targeted canvas.
x,ythe coordinates of the top left corner of the bounding box of the ellipse.
w,hthe width and height (minus 1) of the bounding box of the ellipse, so that the bottom-right corner of the bounding-box is located at (x+w, y+h).
filledwhether theellipse is filled (non zero) or empty (zero)
Returns
nothing
Remarks
void bx_draw_arc ( bx_window  win,
int  x,
int  y,
unsigned  w,
unsigned  h,
double  angle,
double  dangle,
bx_fill  filled 
)

Draws an arc on the canvas of a window, that is a portion of an ellipse between two angles, and whose interior may be filled (to look as a pie slice) or left empty.

Parameters
winthe window owning the targeted canvas.
x,ythe coordinates of the top left corner of the bounding box of the underlying ellipse of the arc.
w,hthe width and height (minus 1) of the bounding box of the underlying ellipse of the arc, so that the bottom-right corner of the box is located at (x+w, y+h).
anglethe starting angle of the arc, expressed in degrees from the 3 o'clock position on the underlying ellipse of the arc.
danglethe angle between the starting angle and the ending angle of the arc expressed in degrees
filledwhether theellipse is filled (non zero) or empty (zero)
Returns
nothing
Remarks
  • the coordinates are relative to the top-left corner of the canvas.
  • the y-axis is oriented downward.
  • positive angles indicate counterclockwise motion while negative ones indeicate clockwise motion.
  • if the underlying ellipse is not a circle, then the angles must be thought as skewed in the coordinate system of the bounding box of underlying ellipse, that is, an angle of 45*64 units will point toward the top right corner of bounding box of the underlying ellipse of the arc.
  • the updated canvas will be shown after the next call to bx_show_canvas().
  • the color is set with bx_set_color() or bx_set_rgb().
  • the line width is set with bx_set_line_width().