Blob Blame Raw
#ifndef HELI_DRAWING_H
#define HELI_DRAWING_H


#include "common.h"
#include "colors.h"
#include "animation.h"


typedef enum _StateFlags {
	STATE_FILL_COLOR         = 1 <<  0,
	STATE_FILL_TEXTURE       = 1 <<  1,
	
	STATE_STROKE_COLOR       = 1 <<  2,
	STATE_STROKE_TEXTURE     = 1 <<  3,
	STATE_STROKE_WIDTH       = 1 <<  4,
	
	STATE_TEXT_ALIGN         = 1 <<  5,
	STATE_TEXT_SIZE          = 1 <<  6,
	STATE_TEXT_FONT          = 1 <<  7,
	
	STATE_TARGET_FRAMEBUFFER = 1 <<  8,
	STATE_TARGET_VIEWPORT    = 1 <<  9,
	STATE_TARGET_PROJECTION  = 1 << 10,
	
	STATE_BACKGROUND         = 1 << 11,
	STATE_TRANSFORM          = 1 << 12,
	STATE_CLIP               = 1 << 13,
	STATE_ANTIALIASING       = 1 << 14,
	
	STATE_FILL   = STATE_FILL_COLOR
	             | STATE_FILL_TEXTURE,
	STATE_STROKE = STATE_STROKE_COLOR
	             | STATE_STROKE_TEXTURE
	             | STATE_STROKE_WIDTH,
	STATE_TEXT   = STATE_TEXT_ALIGN
	             | STATE_TEXT_SIZE
	             | STATE_TEXT_FONT,
	STATE_TARGET = STATE_TARGET_FRAMEBUFFER
	             | STATE_TARGET_VIEWPORT
	             | STATE_TARGET_PROJECTION,
	
	STATE_ALL    = STATE_FILL
	             | STATE_STROKE
	             | STATE_TEXT
	             | STATE_TARGET
	             | STATE_BACKGROUND
	             | STATE_TRANSFORM
	             | STATE_CLIP
	             | STATE_TARGET
	             | STATE_ANTIALIASING,
} StateFlags;


void background(unsigned int colorCode);
void clear();

void fill(unsigned int colorCode);
void fillTexture(Animation animation, double x, double y, double width, double height, int fixed);
void noFill();
void noFillColor();
void noFillTexture();
void stroke(unsigned int colorCode);
void strokeTexture(Animation animation, double x, double y, double width, double height, int fixed);
void noStroke();
void noStrokeColor();
void noStrokeTexture();
void strokeWidth(double width);

void enableAntialiasing();
void disableAntialiasing();

void translate(double x, double y);
void rotate(double angle);
void zoom(double z);
void scale(double x, double y);
void noTransform();

void cliprect(double x, double y, double width, double height);
void noClip();

void projectionByViewport();
void viewportByFramebuffer(Framebuffer framebuffer);
void viewportByWindow();
void targetEx(Framebuffer framebuffer, int updateViewport, int updateProjection);
void target(Framebuffer framebuffer);
void noTarget();

void resetState();
void resetStateEx(unsigned int flags);
void saveState();
void saveStateEx(unsigned int flags);
void restoreState();


unsigned int colorWithAlpha(unsigned int colorCode, double a);

unsigned int colorByName(const char *colorName);
unsigned int colorByNameA(const char *colorName, double a);
unsigned int colorByRGB(double r, double g, double b);
unsigned int colorByRGBA(double r, double g, double b, double a);
unsigned int colorByHSV(double h, double s, double v);
unsigned int colorByHSVA(double h, double s, double v, double a);
unsigned int colorByYUV(double y, double u, double v);
unsigned int colorByYUVA(double y, double u, double v, double a);

double colorGetRed(unsigned int colorCode);
double colorGetGreen(unsigned int colorCode);
double colorGetBlue(unsigned int colorCode);
double colorGetAlpha(unsigned int colorCode);

double colorGetHue(unsigned int colorCode);
double colorGetSaturation(unsigned int colorCode);
double colorGetValue(unsigned int colorCode);

double colorGetYLuminance(unsigned int colorCode);
double colorGetUChrominance(unsigned int colorCode);
double colorGetVChrominance(unsigned int colorCode);


void rect(double x, double y, double width, double height);
void rectRounded(double x, double y, double width, double height, double radius);
void rectTextured(Animation animation, double x, double y, double width, double height);
void ellipse(double x, double y, double width, double height);
void circle(double x, double y, double radius);
void arc(double x, double y, double w, double h, double start, double stop);
void arcPath(double x, double y, double w, double h, double start, double stop);
void line(double x1, double y1, double x2, double y2);
void point(double x, double y);
void regularPolygon(double x, double y, int sides, double radius, double angle);

void moveTo(double x, double y);
void lineTo(double x, double y);
void resetPath();
void closePath();
void strokePath();


#endif