Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb_renderer.h
1 // ================================================================================
2 // == This file is a part of Turbo Badger. (C) 2011-2014, Emil SegerÃ¥s ==
3 // == See tb_core.h for more information. ==
4 // ================================================================================
5 
6 #ifndef TB_RENDERER_H
7 #define TB_RENDERER_H
8 
9 #include "tb_core.h"
10 #include "tb_geometry.h"
11 #include "tb_color.h"
12 #include "tb_linklist.h"
13 
14 namespace tb {
15 
16 class TBBitmapFragment;
17 
19 class TBRendererListener : public TBLinkOf<TBRendererListener>
20 {
21 public:
22  virtual ~TBRendererListener() {}
23 
27  virtual void OnContextLost() = 0;
28 
31  virtual void OnContextRestored() = 0;
32 };
33 
36 class TBBitmap
37 {
38 public:
41  virtual ~TBBitmap() {}
42 
43  virtual int Width() = 0;
44  virtual int Height() = 0;
45 
49  virtual void SetData(uint32_t *data) = 0;
50 };
51 
55 {
56 public:
57  virtual ~TBRenderer() {}
58 
62  virtual void BeginPaint(int render_target_w, int render_target_h) = 0;
63  virtual void EndPaint() = 0;
64 
66  virtual void Translate(int dx, int dy) = 0;
67 
69  virtual void SetOpacity(float opacity) = 0;
70  virtual float GetOpacity() = 0;
71 
76  virtual TBRect SetClipRect(const TBRect &rect, bool add_to_current) = 0;
77 
80  virtual TBRect GetClipRect() = 0;
81 
84  virtual void DrawBitmap(const TBRect &dst_rect, const TBRect &src_rect, TBBitmapFragment *bitmap_fragment) = 0;
85 
88  virtual void DrawBitmap(const TBRect &dst_rect, const TBRect &src_rect, TBBitmap *bitmap) = 0;
89 
93  virtual void DrawBitmapColored(const TBRect &dst_rect, const TBRect &src_rect, const TBColor &color, TBBitmapFragment *bitmap_fragment) = 0;
94 
98  virtual void DrawBitmapColored(const TBRect &dst_rect, const TBRect &src_rect, const TBColor &color, TBBitmap *bitmap) = 0;
99 
101  virtual void DrawBitmapTile(const TBRect &dst_rect, TBBitmap *bitmap) = 0;
102 
105  virtual void DrawBitmapTileColored(const TBRect &dst_rect, const TBColor &color, TBBitmap *bitmap) = 0;
106 
109  virtual void FlushBitmapFragment(TBBitmapFragment *bitmap_fragment) = 0;
110 
114  virtual TBBitmap *CreateBitmap(int width, int height, uint32_t *data) = 0;
115 
117  void AddListener(TBRendererListener *listener) { m_listeners.AddLast(listener); }
118 
120  void RemoveListener(TBRendererListener *listener) { m_listeners.Remove(listener); }
121 
124  void InvokeContextLost();
125 
128  void InvokeContextRestored();
129 
131  enum BATCH_HINT {
135  };
136 
142  virtual void BeginBatchHint(BATCH_HINT /*hint*/) {}
143 
145  virtual void EndBatchHint() {}
146 private:
148 };
149 
150 } // namespace tb
151 
152 #endif // TB_RENDERER_H
void InvokeContextLost()
Invoke OnContextLost on all listeners.
Definition: tb_renderer.cpp:12
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.
void AddListener(TBRendererListener *listener)
Add a listener to this renderer.
Definition: tb_renderer.h:117
virtual void Translate(int dx, int dy)=0
Translate all drawing with the given offset.
virtual void OnContextRestored()=0
Called when the context has been restored again, and new TBBitmaps can be created again...
virtual void FlushBitmapFragment(TBBitmapFragment *bitmap_fragment)=0
Make sure the given bitmap fragment is flushed from any batching, because it may be changed or delete...
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.
virtual TBBitmap * CreateBitmap(int width, int height, uint32_t *data)=0
Create a new TBBitmap from the given data (in BGRA32 format).
virtual void BeginBatchHint(BATCH_HINT)
A hint to batching renderers that the following set of draw calls are of the same type so batching mi...
Definition: tb_renderer.h:142
TBRendererListener is a listener for TBRenderer.
Definition: tb_renderer.h:19
virtual TBRect SetClipRect(const TBRect &rect, bool add_to_current)=0
Set a clip rect to the renderer.
TBBitmapFragment represents a sub part of a TBBitmap.
Definition: tb_bitmap_fragment.h:140
virtual TBRect GetClipRect()=0
Get the current clip rect.
TBBitmap is a minimal interface for bitmap to be painted by TBRenderer.
Definition: tb_renderer.h:36
All calls are either DrawBitmap or DrawBitmapColored with the same bitmap fragment.
Definition: tb_renderer.h:134
virtual void SetOpacity(float opacity)=0
Set the current opacity that should apply to all drawing (0.f-1.f).
Simple rectangle class.
Definition: tb_geometry.h:25
virtual ~TBBitmap()
Note: Implementations for batched renderers should call TBRenderer::FlushBitmap to make sure any acti...
Definition: tb_renderer.h:41
virtual void BeginPaint(int render_target_w, int render_target_h)=0
Should be called before invoking paint on any widget.
virtual void EndBatchHint()
End the hint scope started with BeginBatchHint.
Definition: tb_renderer.h:145
TBColor contains a 32bit color.
Definition: tb_color.h:21
virtual void SetData(uint32_t *data)=0
Update the bitmap with the given data (in BGRA32 format).
virtual void DrawBitmapTile(const TBRect &dst_rect, TBBitmap *bitmap)=0
Draw the bitmap tiled into dst_rect.
void RemoveListener(TBRendererListener *listener)
Remove a listener from this renderer.
Definition: tb_renderer.h:120
virtual void DrawBitmapTileColored(const TBRect &dst_rect, const TBColor &color, TBBitmap *bitmap)=0
Draw the bitmap tiled into dst_rect.
BATCH_HINT
Defines the hint given to BeginBatchHint.
Definition: tb_renderer.h:131
virtual void OnContextLost()=0
Called when the context has been lost and all TBBitmaps need to be deleted.
void InvokeContextRestored()
Invoke OnContextRestored on all listeners.
Definition: tb_renderer.cpp:19
TBRenderer is a minimal interface for painting strings and bitmaps.
Definition: tb_renderer.h:54