Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb::TBRenderer Class Referenceabstract

TBRenderer is a minimal interface for painting strings and bitmaps. More...

#include <tb_renderer.h>

Public Types

enum  BATCH_HINT { BATCH_HINT_DRAW_BITMAP_FRAGMENT }
 Defines the hint given to BeginBatchHint. More...
 

Public Member Functions

virtual void BeginPaint (int render_target_w, int render_target_h)=0
 Should be called before invoking paint on any widget. More...
 
virtual void EndPaint ()=0
 
virtual void Translate (int dx, int dy)=0
 Translate all drawing with the given offset.
 
virtual void SetOpacity (float opacity)=0
 Set the current opacity that should apply to all drawing (0.f-1.f). More...
 
virtual float GetOpacity ()=0
 
virtual TBRect SetClipRect (const TBRect &rect, bool add_to_current)=0
 Set a clip rect to the renderer. More...
 
virtual TBRect GetClipRect ()=0
 Get the current clip rect. More...
 
virtual void DrawBitmap (const TBRect &dst_rect, const TBRect &src_rect, TBBitmapFragment *bitmap_fragment)=0
 Draw the src_rect part of the fragment stretched to dst_rect. More...
 
virtual void DrawBitmap (const TBRect &dst_rect, const TBRect &src_rect, TBBitmap *bitmap)=0
 Draw the src_rect part of the bitmap stretched to dst_rect. More...
 
virtual void DrawBitmapColored (const TBRect &dst_rect, const TBRect &src_rect, const TBColor &color, TBBitmapFragment *bitmap_fragment)=0
 Draw the src_rect part of the fragment stretched to dst_rect. More...
 
virtual void DrawBitmapColored (const TBRect &dst_rect, const TBRect &src_rect, const TBColor &color, TBBitmap *bitmap)=0
 Draw the src_rect part of the bitmap stretched to dst_rect. More...
 
virtual void DrawBitmapTile (const TBRect &dst_rect, TBBitmap *bitmap)=0
 Draw the bitmap tiled into dst_rect. More...
 
virtual void DrawBitmapTileColored (const TBRect &dst_rect, const TBColor &color, TBBitmap *bitmap)=0
 Draw the bitmap tiled into dst_rect. More...
 
virtual void FlushBitmapFragment (TBBitmapFragment *bitmap_fragment)=0
 Make sure the given bitmap fragment is flushed from any batching, because it may be changed or deleted after this call. More...
 
virtual TBBitmapCreateBitmap (int width, int height, uint32_t *data)=0
 Create a new TBBitmap from the given data (in BGRA32 format). More...
 
void AddListener (TBRendererListener *listener)
 Add a listener to this renderer. More...
 
void RemoveListener (TBRendererListener *listener)
 Remove a listener from this renderer. More...
 
void InvokeContextLost ()
 Invoke OnContextLost on all listeners. More...
 
void InvokeContextRestored ()
 Invoke OnContextRestored on all listeners. More...
 
virtual void BeginBatchHint (BATCH_HINT)
 A hint to batching renderers that the following set of draw calls are of the same type so batching might be optimized. More...
 
virtual void EndBatchHint ()
 End the hint scope started with BeginBatchHint. More...
 

Detailed Description

TBRenderer is a minimal interface for painting strings and bitmaps.

Member Enumeration Documentation

Defines the hint given to BeginBatchHint.

Enumerator
BATCH_HINT_DRAW_BITMAP_FRAGMENT 

All calls are either DrawBitmap or DrawBitmapColored with the same bitmap fragment.

Member Function Documentation

void tb::TBRenderer::AddListener ( TBRendererListener listener)
inline

Add a listener to this renderer.

Does not take ownership.

virtual void tb::TBRenderer::BeginBatchHint ( BATCH_HINT  )
inlinevirtual

A hint to batching renderers that the following set of draw calls are of the same type so batching might be optimized.

The hint defines what operations are allowed between BeginBatchHint until EndBatchHint is called. All other draw operations are invalid. It's not valid to nest calls to BeginBatchHint.

virtual void tb::TBRenderer::BeginPaint ( int  render_target_w,
int  render_target_h 
)
pure virtual

Should be called before invoking paint on any widget.

render_target_w and render_target_h should be the size of the render target that the renderer renders to. I.e window size, screen size or frame buffer object.

virtual TBBitmap* tb::TBRenderer::CreateBitmap ( int  width,
int  height,
uint32_t *  data 
)
pure virtual

Create a new TBBitmap from the given data (in BGRA32 format).

Width and height must be a power of two. Return nullptr if fail.

virtual void tb::TBRenderer::DrawBitmap ( const TBRect dst_rect,
const TBRect src_rect,
TBBitmapFragment bitmap_fragment 
)
pure virtual

Draw the src_rect part of the fragment stretched to dst_rect.

dst_rect or src_rect can have negative width and height to achieve horizontal and vertical flip.

virtual void tb::TBRenderer::DrawBitmap ( const TBRect dst_rect,
const TBRect src_rect,
TBBitmap bitmap 
)
pure virtual

Draw the src_rect part of the bitmap stretched to dst_rect.

dst_rect or src_rect can have negative width and height to achieve horizontal and vertical flip.

virtual void tb::TBRenderer::DrawBitmapColored ( const TBRect dst_rect,
const TBRect src_rect,
const TBColor color,
TBBitmapFragment bitmap_fragment 
)
pure virtual

Draw the src_rect part of the fragment stretched to dst_rect.

The bitmap will be used as a mask for the color. dst_rect or src_rect can have negative width and height to achieve horizontal and vertical flip.

virtual void tb::TBRenderer::DrawBitmapColored ( const TBRect dst_rect,
const TBRect src_rect,
const TBColor color,
TBBitmap bitmap 
)
pure virtual

Draw the src_rect part of the bitmap stretched to dst_rect.

The bitmap will be used as a mask for the color. dst_rect or src_rect can have negative width and height to achieve horizontal and vertical flip.

virtual void tb::TBRenderer::DrawBitmapTile ( const TBRect dst_rect,
TBBitmap bitmap 
)
pure virtual

Draw the bitmap tiled into dst_rect.

virtual void tb::TBRenderer::DrawBitmapTileColored ( const TBRect dst_rect,
const TBColor color,
TBBitmap bitmap 
)
pure virtual

Draw the bitmap tiled into dst_rect.

The bitmap will be used as a mask for the color

virtual void tb::TBRenderer::EndBatchHint ( )
inlinevirtual

End the hint scope started with BeginBatchHint.

virtual void tb::TBRenderer::FlushBitmapFragment ( TBBitmapFragment bitmap_fragment)
pure virtual

Make sure the given bitmap fragment is flushed from any batching, because it may be changed or deleted after this call.

virtual TBRect tb::TBRenderer::GetClipRect ( )
pure virtual

Get the current clip rect.

Note: This may be different from the rect sent to SetClipRect, due to intersecting with the previous cliprect!

void tb::TBRenderer::InvokeContextLost ( )

Invoke OnContextLost on all listeners.

Call when bitmaps should be forgotten.

void tb::TBRenderer::InvokeContextRestored ( )

Invoke OnContextRestored on all listeners.

Call when bitmaps can safely be restored.

void tb::TBRenderer::RemoveListener ( TBRendererListener listener)
inline

Remove a listener from this renderer.

virtual TBRect tb::TBRenderer::SetClipRect ( const TBRect rect,
bool  add_to_current 
)
pure virtual

Set a clip rect to the renderer.

add_to_current should be true when pushing a new cliprect that should clip inside the last clip rect, and false when restoring. It will return the clip rect that was in use before this call.

virtual void tb::TBRenderer::SetOpacity ( float  opacity)
pure virtual

Set the current opacity that should apply to all drawing (0.f-1.f).


The documentation for this class was generated from the following files: