Quick link to menu (Bottom of page)

Java Who? Template created by www.r7designer.com

Canvas Library

Simplifying Graphics

We use following structures and classes

XPoint - Used for specifying point. 

typedef struct {
            short x, y;
} XPoint;

It stores x and y co-ordinates of a point.
Example:
    XPoint point;  // Specifies point (10, 20)
  point.x = 10;
  point.y = 20;
   
Position - Used for specifying point at floating point precision.
class Position{
  float x_dist, y_dist;
 public:
  Position(){
    x_dist = y_dist = 0.0;
  }
  Position(float x, float y){
    x_dist = x;
    y_dist = y;
  }
  float GetXDistance(){
    return x_dist;
  }
  float GetYDistance(){
    return y_dist;
  }
};

Example:
Position p(10.0, 12.5);
float x, y;
x = p.GetXDistance();  // Gives X co-ordinate of point p
y = p.GetYDistance();
 // Gives Y co-ordinate of point p


RectBox - Used to specify rectangular area on screen.
struct RectBox{
  Position top_left;
  Position bottom_right;
};
    left_top
        +---------------------+
        |                     |
        |                     |
        |                     |
        |                     |
        |                     |
        |                     |
        +---------------------+
                        bottom_right


  We have developed new easy to graphic library. It has following functions.
Function Use
int initCanvas(const char window_title[])
Initialise graphics.
Always use at the start of main().
void closeCanvas(); Cleanup graphics.
Always use at the end of main().
void drawLine(XPoint start, XPoint end, Color line_color, unsigned int line_width=0, int line_style=LineSolid, int cap_style=CapButt, int join_style=JoinMiter, int function=GXcopy)
Draws a line
void drawCircle(XPoint centre, int radius, Color fill_color, bool fill=true, unsigned int line_width=0, int line_style=LineSolid, int cap_style=CapButt, int join_style=JoinMiter, int function=GXcopy)
Draws a circle
void drawEllipse(XPoint centre, int width, int height, Color fill_color, bool fill=true, unsigned int line_width=0, int line_style=LineSolid, int cap_style=CapButt, int join_style=JoinMiter, int function=GXcopy);
Draws an ellipse
void drawPolygon(XPoint *points, int npoints, Color fill_color, bool fill=true, unsigned int line_width=0, int line_style=LineSolid, int cap_style=CapButt, int join_style=JoinMiter, int fill_rule=WindingRule, int function=GXcopy);
Draws a polygon
void drawText(XPoint position, const char *text, Color clr); Draws text on screen
Color COLOR(const char *color_string);
Specify a color using its name.
Color COLOR(unsigned short red, unsigned short green, unsigned short blue);
Specify color with RGB values

Menu:


Take me back to the top.