haiku/headers/private/servers/app/Painter.h
Stephan Aßmus 97dba15f78 more support functions
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12047 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-03-26 22:03:49 +00:00

330 lines
8.7 KiB
C++

// Painter.h
#ifndef PAINTER_H
#define PAINTER_H
#include <Font.h>
#include <Rect.h>
#include "defines.h"
#include "forwarding_pixfmt.h"
#include "RGBColor.h"
class AGGTextRenderer;
class BBitmap;
class BRegion;
class DrawData;
class PatternHandler;
class RenderingBuffer;
class ServerBitmap;
class ServerFont;
class Painter {
public:
Painter();
virtual ~Painter();
// frame buffer stuff
void AttachToBuffer(RenderingBuffer* buffer);
void DetachFromBuffer();
void ConstrainClipping(const BRegion& region);
void SetDrawData(const DrawData* data);
// object settings
void SetHighColor(const rgb_color& color);
inline void SetHighColor(uint8 r, uint8 g, uint8 b, uint8 a = 255);
inline void SetHighColor(const RGBColor& color)
{ SetHighColor(color.GetColor32()); }
void SetLowColor(const rgb_color& color);
inline void SetLowColor(uint8 r, uint8 g, uint8 b, uint8 a = 255);
inline void SetLowColor(const RGBColor& color)
{ SetLowColor(color.GetColor32()); }
void SetScale(float scale);
void SetPenSize(float size);
void SetOrigin(const BPoint& origin);
void SetDrawingMode(drawing_mode mode);
void SetBlendingMode(source_alpha alphaSrcMode,
alpha_function alphaFncMode);
void SetPenLocation(const BPoint& location);
void SetFont(const BFont& font);
void SetFont(const ServerFont& font);
// BView API compatibility (for easier testing)
void Sync() {}
inline void MovePenTo(const BPoint& location)
{ SetPenLocation(location); }
inline void SetFont(const BFont* font)
{ if (font) SetFont(*font); }
// painting functions
// lines
void StrokeLine( BPoint a,
BPoint b,
const pattern& p = B_SOLID_HIGH);
void StrokeLine( BPoint b,
const pattern& p = B_SOLID_HIGH);
// triangles
void StrokeTriangle( BPoint pt1,
BPoint pt2,
BPoint pt3,
const pattern& p = B_SOLID_HIGH) const;
void FillTriangle( BPoint pt1,
BPoint pt2,
BPoint pt3,
const pattern& p = B_SOLID_HIGH) const;
// polygons
void StrokePolygon( const BPoint* ptArray,
int32 numPts,
bool closed = true,
const pattern& p = B_SOLID_HIGH) const;
void FillPolygon( const BPoint* ptArray,
int32 numPts,
bool closed = true,
const pattern& p = B_SOLID_HIGH) const;
// bezier curves
void StrokeBezier( const BPoint* controlPoints,
const pattern& p = B_SOLID_HIGH) const;
void FillBezier( const BPoint* controlPoints,
const pattern& p = B_SOLID_HIGH) const;
// shapes
void StrokeShape( /*const */BShape* shape,
const pattern& p = B_SOLID_HIGH) const;
void FillShape( /*const */BShape* shape,
const pattern& p = B_SOLID_HIGH) const;
// rects
void StrokeRect( const BRect& r,
const pattern& p = B_SOLID_HIGH) const;
void FillRect( const BRect& r,
const pattern& p = B_SOLID_HIGH) const;
// round rects
void StrokeRoundRect(const BRect& r,
float xRadius,
float yRadius,
const pattern& p = B_SOLID_HIGH) const;
void FillRoundRect( const BRect& r,
float xRadius,
float yRadius,
const pattern& p = B_SOLID_HIGH) const;
// ellipses
void StrokeEllipse( BPoint center,
float xRadius,
float yRadius,
const pattern& p = B_SOLID_HIGH) const;
void FillEllipse( BPoint center,
float xRadius,
float yRadius,
const pattern& p = B_SOLID_HIGH) const;
// arcs
void StrokeArc( BPoint center,
float xRadius,
float yRadius,
float angle,
float span,
const pattern& p = B_SOLID_HIGH) const;
void FillArc( BPoint center,
float xRadius,
float yRadius,
float angle,
float span,
const pattern& p = B_SOLID_HIGH) const;
// strings
void DrawChar( char aChar);
void DrawChar( char aChar,
BPoint baseLine);
void DrawString( const char* utf8String,
uint32 length,
const escapement_delta* delta = NULL);
void DrawString( const char* utf8String,
uint32 length,
BPoint baseLine,
const escapement_delta* delta = NULL);
void DrawString( const char* utf8String,
const escapement_delta* delta = NULL);
void DrawString( const char* utf8String,
BPoint baseLine,
const escapement_delta* delta = NULL);
// bitmaps
void DrawBitmap( const BBitmap* bitmap,
BRect bitmapRect,
BRect viewRect) const;
void DrawBitmap( const ServerBitmap* bitmap,
BRect bitmapRect,
BRect viewRect) const;
// some convenience stuff
void FillRegion( const BRegion* region,
const pattern& p = B_SOLID_HIGH) const;
void InvertRect( const BRect& r) const;
BRect BoundingBox( const char* utf8String,
uint32 length,
const BPoint& baseLine) const;
// MISSING (?):
/*
// "screen blits"
void CopyBits( BRect src, BRect dst);
*/
private:
void _MakeEmpty();
void _Transform(BPoint* point,
bool centerOffset = true) const;
BPoint _Transform(const BPoint& point,
bool centerOffset = true) const;
void _Transform(float* width) const;
float _Transform(const float& width) const;
void _Transform(BRect* rect) const;
void _RebuildClipping();
void _UpdateFont();
void _UpdateLineWidth();
// drawing functions stroke/fill
void _DrawTriangle( BPoint pt1,
BPoint pt2,
BPoint pt3,
const pattern& p,
bool fill) const;
void _DrawEllipse( BPoint center,
float xRadius,
float yRadius,
const pattern& p,
bool fill) const;
void _DrawShape( /*const */BShape* shape,
const pattern& p,
bool fill) const;
void _DrawPolygon( const BPoint* ptArray,
int32 numPts,
bool closed,
const pattern& p,
bool fill) const;
void _DrawBitmap( const agg::rendering_buffer& srcBuffer,
color_space format,
BRect actualBitmapRect,
BRect bitmapRect,
BRect viewRect) const;
void _DrawBitmap32( const agg::rendering_buffer& srcBuffer,
BRect actualBitmapRect,
BRect bitmapRect,
BRect viewRect) const;
void _InvertRect32(BRect r) const;
template<class VertexSource>
void _StrokePath(VertexSource& path,
const pattern& p) const;
template<class VertexSource>
void _FillPath(VertexSource& path,
const pattern& p) const;
void _SetPattern(const pattern& p) const;
void _SetRendererColor(const rgb_color& color) const;
agg::rendering_buffer* fBuffer;
// AGG rendering and rasterization classes
pixfmt* fPixelFormat;
renderer_base* fBaseRenderer;
outline_renderer_type* fOutlineRenderer;
outline_rasterizer_type* fOutlineRasterizer;
scanline_type* fScanline;
rasterizer_type* fRasterizer;
renderer_type* fRenderer;
font_renderer_solid_type* fFontRendererSolid;
font_renderer_bin_type* fFontRendererBin;
agg::line_profile_aa fLineProfile;
// for internal coordinate rounding/transformation,
// does not concern rendering
bool fSubpixelPrecise;
float fScale;
float fPenSize;
BPoint fOrigin;
BRegion* fClippingRegion; // NULL indicates no clipping at all
drawing_mode fDrawingMode;
source_alpha fAlphaSrcMode;
alpha_function fAlphaFncMode;
BPoint fPenLocation;
PatternHandler* fPatternHandler;
BFont fFont;
// a class handling rendering and caching of glyphs
// it is setup to load from a specific Freetype supported
// font file, it uses the FontManager to locate a file
// by Family and Style
AGGTextRenderer* fTextRenderer;
};
// SetHighColor
inline void
Painter::SetHighColor(uint8 r, uint8 g, uint8 b, uint8 a)
{
rgb_color color;
color.red = r;
color.green = g;
color.blue = b;
color.alpha = a;
SetHighColor(color);
}
// SetLowColor
inline void
Painter::SetLowColor(uint8 r, uint8 g, uint8 b, uint8 a)
{
rgb_color color;
color.red = r;
color.green = g;
color.blue = b;
color.alpha = a;
SetLowColor(color);
}
#endif // PAINTER_H