Newer
Older
Import / research / ui / toolkit / include / Graphics.h
#pragma once
#include "Common.h"
BEGIN_NAMESPACE


enum PixelFormat
{
	PF_ARGB8888,
	PF_ABGR8888,
	PF_RGBA8888,
	PF_BGRA8888,
	PF_XRGB8888,
	PF_XBGR8888,
	PF_RGBX8888,
	PF_BGRX8888,
	PF_RGB888,
	PF_BGR888,
	PF_RGB565,
	PF_XRGB1555,
	PF_ARGB1555,
	PF_YUV422,
	PF_PAL8,
	PF_PAL4,
};


//  PixelBuffers
//  ------------
//    A pixel buffer can be something like an image where there are
//    the image bits and a width and height. But a pixel buffer can
//    be more than this. A pixel buffer can also be a view in to
//    another pixel buffer thanks to the strideBytes variable.
//    In this case the stride will be larger than the width, and it
//    is important to use the stride when indexing in to the pixels.
//    Possibly m_pixels would be better as a shared_ptr for this, but
//    the current usage of this is with widgets having views in to
//    the window which is always the owner of the pixels.
struct PixelBuffer
{
  uint32_t*   m_pixels;
  int				  m_strideBytes;
  int				  m_width;
  int				  m_height;
  PixelFormat m_format;
  bool        m_isRetina; //  = false;
};


enum LogLevel
{
	LL_FATAL_ERROR = 0,
	LL_CRITICAL_ERROR,
	LL_ERROR,
	LL_WARNING,
	LL_DEBUG,
	LL_VERBOSE_DEBUG
};


struct FontMetrics
{
	int m_ascent;
	int m_descent;
	int m_xHeight;
	int m_capHeight;
	int m_lineGap;
};


struct GlyphMetrics
{
	int m_advanceWidth;
	int m_leftSideBearing;
	int m_rightSideBearing;
  int m_minX;
  int m_minY;
  int m_maxX;
  int m_maxY;
};


/*
enum MouseButtonFlags
{
	NO_MOUSE_BUTTONS = 0,
	LEFT_MOUSE_BUTTON = 1,
	MIDDLE_MOUSE_BUTTON = 2,
	RIGHT_MOUSE_BUTTON = 4
};


struct MouseState
{
	int						   m_mouseX;
	int						   m_mouseY;
	int						   m_mouseWheelDelta;
	MouseButtonFlags m_buttons;
};


enum KeyFlags
{
	KEY_UP = 0,
	KEY_DOWN = 1,
	KEY_REPEAT = 3
};


struct KeyState
{
	int				m_keyCode;
	KeyFlags	m_state;
};
*/

enum GradientType
{
	RADIAL_GRADIENT,
	CONICAL_GRADIENT,
	LINEAR_GRADIENT
};


struct GradientStop
{
	uint32_t			m_color;
  float         m_position; 
};


struct Gradient
{
	GradientType	m_type;
  std::vector<GradientStop> m_gradientStops;
//	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;
};


void GetTextExtents(PixelBuffer* a_target, const char* a_fontFamily, int a_size, const char* a_utf8String, int& a_width, int& a_height);
FontMetrics GetFontMetrics();
GlyphMetrics GetGlyphMetrics(uint32_t a_unicodeCharacter);
void DrawText(PixelBuffer* a_target, uint32_t a_color, const char* a_fontFamily, int a_size, int a_x, int a_y, const char* a_formattedUtf8String, int a_flags = 0);
void LogMessage(LogLevel a_level, const char* a_formatString, ...);
void DrawRectangleAlpha(PixelBuffer* a_target, uint32_t a_color, int a_x, int a_y, int a_width, int a_height);
void DrawRectangle(PixelBuffer* a_target, uint32_t a_color, int a_x, int a_y, int a_width, int a_height, bool a_setAlpha);
void DrawEllipse(PixelBuffer* a_target, uint32_t a_color, int a_x, int a_y, int a_width, int a_height, bool a_smoothEdge);
void DrawGradient(PixelBuffer* a_target, const Gradient& a_gradient, int a_x, int a_y, int a_width, int a_height);
void DrawLine(PixelBuffer* a_target, uint32_t a_color, int a_x1, int a_y1, int a_x2, int a_y2, bool a_blend);
void DrawPixels(PixelBuffer* a_target, uint32_t* a_bits, int a_x, int a_y, int a_width, int a_height, int a_xOffset, int a_yOffset, int a_pixelsWidth, int a_pixelsHeight);
void DrawPixelsAlpha(PixelBuffer* a_target, uint32_t* a_bits, int a_x, int a_y, int a_width, int a_height, int a_xOffset, int a_yOffset, int a_pixelsWidth, int a_pixelsHeight);
void DrawPixelsAlphaBlended(PixelBuffer* a_target, uint32_t* a_bits, int a_x, int a_y, int a_width, int a_height, int a_xOffset, int a_yOffset, int a_pixelsWidth, int a_pixelsHeight, int a_alpha);


END_NAMESPACE