Newer
Older
Import / research / ui / TweakableProperties / toolkit / include / Painter.h
#ifndef PAINTER_H
#define PAINTER_H


#include "Widget.h"
#include "Graphics.h"
#include <stdint.h>


#include "Namespace.h"
BEGIN_NAMESPACE


class Pixmap : public PaintTarget
{
public:
	Pixmap(unsigned char* a_memoryBuffer, int a_width, int a_height, int a_depth);
	Pixmap(const char* a_fileName);
	~Pixmap();

	const uint32_t* bits() const;
	uint32_t width() const;
	uint32_t height() const;

	CUTE_PaintTarget& targetBuffer();

private:
	struct PixmapData* m_data;
};


enum FontStyle
{
	FS_Normal     = 0,
	FS_Italic     = 1<<0,
	FS_Oblique    = 1<<1,
	FS_StrikeOut  = 1<<2,
	FS_UnderLine  = 1<<3,
	FS_OverLine   = 1<<4,
	FS_FixedPitch =	1<<5
};


class Font
{
public:
	Font(const char* a_family = Font::Helvetica, int a_pointSize = 12,
			int a_weight = 50, FontStyle a_style = FS_Normal, int a_stretch = 100)
	{
		family = a_family;
		pointSize = a_pointSize;
		weight = a_weight;
		style = a_style;
		stretch = a_stretch;
	}

	Property<String> family;
	Property<int> pointSize;
	Property<int> weight;           // 25 light  50 normal  75 bold
	Property<int> stretch;			// 50 very condensed  75 condensed  100 normal  125 expanded  200 very expanded
	Property<FontStyle> style;

	static const char* Helvetica;
	static const char* Times;
	static const char* Courier;
	static const char* OldEnglish;
	static const char* Monospace;
	static const char* Fantasy;
	static const char* Cursive;
	static const char* UIFont;
};


class Gradient
{
public:
	Gradient() {}
/*
struct CUTE_Gradient
{
	CUTE_GradientType	m_type;
	uint32_t			m_color1;
	uint32_t			m_color2; // TODO: gradient stops
	int					m_flags;  // reflect?
	union {
		struct {
			int			m_centerX, m_centerY;
			int			m_distance;
		} m_radial;
		struct {
			int			m_centerX, m_centerY;
		} m_conic;
		struct {
			int			m_x1, m_y1, m_x2, m_y2;
		} m_linear;
	} m_data;
};
*/
};


enum BrushStyle
{
	BS_None,
	BS_SolidColor,
	BS_Pixmap,
	BS_Gradient
};


class Brush
{
public:
	Brush() {
		Point p = { };
		Init(p);
	}
	Brush(uint32_t a_color) {
		Point p = { };
		Init(p, BS_SolidColor, a_color);
	}
	Brush(Pixmap* a_pixmap) {
		Point p = { };
		Init(p, BS_Pixmap, 0, a_pixmap);
	}
	Brush(Pixmap* a_pixmap, Point a_origin) {
		Init(a_origin, BS_Pixmap, 0, a_pixmap);
	}
	Brush(Gradient a_gradient) {
	}
	void Init(Point a_origin, BrushStyle a_style = BS_None, uint32_t a_color = 0, Pixmap* a_pixmap = 0)
	{
		style = a_style;
		color = a_color;
		pixmap = a_pixmap;
		origin = a_origin;
	}
	Property<BrushStyle> style;
	Property<uint32_t> color;
	Property<Pixmap*> pixmap;
	Property<Point> origin;
};


class Painter
{
public:
	Painter();
	Painter(PaintTarget* a_window);
	~Painter();

	// setPen with a Pen
	// setBrush with a Brush

	void setPen(uint32_t a_color);
	void setBrush(uint32_t a_color); // brush can be color or pattern / pixmap with some origin
	void setFontFamily(const char* a_fontName);
	void setFontSize(uint32_t a_size);

	// drawArc drawChord drawPie drawPolygon drawPolyline 
	void drawEllipse(int a_x, int a_y, int a_width, int a_height);
	void drawGradient(int a_x, int a_y, CUTE_Gradient a_gradient, int a_width, int a_height);
	void drawLine(int a_x, int a_y, int a_x2, int a_y2);
	// drawLines
	// drawPoint
	// drawPoints
	// drawPath
	// drawImage
	void drawPixmap(int a_x, int a_y, const Pixmap& pixmap, int a_x1 = 0, int a_y1 = 0, int a_x2 = -1, int a_y2 = -1, bool a_alphaMask = false);
	void drawPixmapAlphaBlended(int a_x, int a_y, const Pixmap& pixmap, int a_x1 = 0, int a_y1 = 0, int a_x2 = -1, int a_y2 = -1, int a_alpha = 0);

	void drawPixelBuffer(int a_x, int a_y, const uint8_t* a_pixels, int a_pixelsWidth, int a_pixelsHeight, int a_pixelsDepth);

	// drawRect
	// drawRects
	// drawRoundedRect
	// drawStaticText // optimization which caches things
	// drawTiledPixmap
	// fillRect // like drawRect, but passing in the brush and no-pen

	void drawText(int a_x, int a_y, const char* a_utf8String, ...);
	void drawRectangle(int a_x, int a_y, int a_width, int a_height, bool a_alphaBlending = false);

	void drawFocusRectangle(int a_x, int a_y, int a_width, int a_height);
	void textExtents(int& a_width, int& a_height, const char* a_utf8String, ...);
	
private:
	struct PainterData* m_data;
};


END_NAMESPACE


#endif // PAINTER_H