tagging release
[dasher.git] / Src / Gtk2 / Canvas.h
blob97e345dc4f8e58490f1393d5be8cd86a26c9e520
1 #ifndef __canvas_h__
2 #define __canvas_h__
4 #include "../DasherCore/DasherScreen.h"
5 #include "../DasherCore/DasherTypes.h"
7 #include <gtk/gtk.h>
8 #include <gdk/gdk.h>
9 #include "PangoCache.h"
11 #include <iostream>
13 #if WITH_CAIRO
15 /* Cairo drawing backend */
16 #include <gdk/gdkcairo.h>
18 typedef struct {
19 double r, g, b;
20 } my_cairo_colour_t;
23 #define BEGIN_DRAWING_BACKEND \
24 cairo_save(cr)
26 #define END_DRAWING_BACKEND \
27 cairo_restore(cr)
29 #define SET_COLOR_BACKEND(c) \
30 do { \
31 my_cairo_colour_t _c = cairo_colours[(c)]; \
32 cairo_set_source_rgb(cr, _c.r, _c.g, _c.b); \
33 } while (0)
35 #else /* WITHOUT_CAIRO */
37 #define BEGIN_DRAWING_BACKEND \
38 GdkGCValues origvalues; \
39 gdk_gc_get_values(graphics_context,&origvalues)
41 #define END_DRAWING_BACKEND \
42 gdk_gc_set_values(graphics_context,&origvalues,GDK_GC_FOREGROUND)
44 #define SET_COLOR_BACKEND(c) \
45 do { \
46 GdkColor _c = colours[(c)]; \
47 gdk_colormap_alloc_color(colormap, &_c, FALSE, TRUE); \
48 gdk_gc_set_foreground (graphics_context, &_c); \
49 } while (0)
51 #endif /* WITH_CAIRO */
53 // Some other useful macros (for all backends)
55 #define BEGIN_DRAWING \
56 BEGIN_DRAWING_BACKEND
58 #define END_DRAWING \
59 END_DRAWING_BACKEND
61 #define SET_COLOR(c) \
62 SET_COLOR_BACKEND(c)
64 using namespace Dasher;
66 /// CCanvas
67 ///
68 /// Method definitions for CCanvas, implementing the CDasherScreen
69 /// interface. Please think very carefully before implementing new
70 /// functionality in this class. Anything which isn't a 'drawing
71 /// primitive' should really not be here - higher level drawing
72 /// functions belong in CDasherView.
74 class CCanvas:public Dasher::CDasherScreen {
76 public:
78 ///
79 /// \param pCanvas The GTK drawing area used by the canvas
80 /// \param pPangoCache A cache for precomputed Pango layouts
81 ///
83 CCanvas(GtkWidget * pCanvas, CPangoCache * pPangoCache);
84 ~CCanvas();
86 ///
87 /// GTK signal handler for exposure of the canvas - cause a redraw to the screen from the buffer.
88 ///
90 bool ExposeEvent( GtkWidget *pWidget, GdkEventExpose *pEvent);
93 // CDasherScreen methods
95 ///
96 /// Set the font used to render the Dasher display
97 /// \param Name The name of the font.
98 /// \todo This needs to be reimplemented for 4.0
99 /// \deprecated In Linux - now handled by the pango cache, but need to think how this fits in with Windows
100 ///
102 void SetFont(std::string Name) {
106 /// Set the font size for rendering
107 /// \param fontsize The font size to use
108 /// \deprecated Obsolete
111 void SetFontSize(Dasher::Opts::FontSize fontsize) {
116 /// Get the current font size
117 /// \deprecated To be removed before 4.0 release
118 /// \todo We should not be relying on locally cached variables - check to see whether this is still used or not
121 Dasher::Opts::FontSize GetFontSize() {
122 return Dasher::Opts::FontSize(1);
126 /// Return the physical extent of a given string being rendered at a given size.
127 /// \param String The string to be rendered
128 /// \param Width Pointer to a variable to be filled with the width
129 /// \param Height Pointer to a variable to be filled with the height
130 /// \param Size Size at which the string will be rendered (units?)
133 void TextSize(const std::string &String, screenint *Width, screenint *Height, int Size);
136 /// Draw a text string
137 /// \param String The string to be rendered
138 /// \param x1 The x coordinate at which to draw the text (be more precise)
139 /// \param y1 The y coordinate at which to draw the text (be more precise)
140 /// \param Size The size at which to render the rectangle (units?)
143 void DrawString(const std::string &String, screenint x1, screenint y1, int Size);
146 /// Draw a rectangle
147 /// \param x1 x coordiate of the top left corner
148 /// \param y1 y coordiate of the top left corner
149 /// \param x2 x coordiate of the bottom right corner
150 /// \param y2 y coordiate of the bottom right corner
151 /// \param Color Colour to draw the rectangle
152 /// \param ColorScheme Which of the alternating colour schemes to use (be more precise)
153 /// \param bDrawOutline Whether or not to draw outlines for the boxes
156 void DrawRectangle(screenint x1, screenint y1, screenint x2, screenint y2, int Color, int iOutlineColour, Opts::ColorSchemes ColorScheme, bool bDrawOutine, bool bFill, int iThickness);
158 void DrawCircle(screenint iCX, screenint iCY, screenint iR, int iColour, int iFillColour, int iThickness, bool bFill);
161 /// Send a marker to indicate phases of the redraw process. This is
162 /// done so that we can do tripple buffering to minimise the amount
163 /// of costly font rendering which needs to be done. Marker 1
164 /// indicates that start of a new frame. Marker 2 indicates that we
165 /// are now drawing decoration (such as mouse cursors etc.) rather
166 /// than tne background. Only marker 2 will be send while Dasher is
167 /// paused.
168 /// \param iMarker ID of the marker being sent.
171 void SendMarker(int iMarker);
173 ///
174 /// Draw a coloured polyline
175 /// \param Points Array of vertices
176 /// \param Number Size of 'Points' array
177 /// \param Colour Colour with which to draw the line
180 void Polyline(point * Points, int Number, int iWidth, int Colour);
182 ///
183 /// Like polyline, but fill the shape
184 /// \todo See comments for DrawPolygon
187 void Polygon(point *Points, int Number, int Colour, int iWidth);
190 /// \todo Not implemented
191 /// \todo One of these two routines must be redundant - find out which and kill the other
194 void DrawPolygon(point *Points, int Number, int Color, Opts::ColorSchemes ColorScheme) {
195 // not implemented
198 ///
199 /// Blank the diplay
202 void Blank();
204 ///
205 /// Marks the end of the display process - at this point the offscreen buffer is copied onscreen.
208 void Display();
211 /// Update the colour definitions
212 /// \param Colours New colours to use
215 void SetColourScheme(const CColourIO::ColourInfo *pColourScheme);
217 ///
218 /// Gets the location and size of our canvas.
219 /// Returns true on success, false otherwise.
220 bool GetCanvasSize(GdkRectangle *pRectangle);
222 void SetLoadBackground(bool bValue) {
223 // Not required in this model
226 void SetCaptureBackground(bool bValue) {
227 // Not required in this model
230 ///
231 /// Canvas width
234 int m_iWidth;
237 /// Canvas height
240 int m_iHeight;
242 private:
245 /// The GTK drawing area for the canvas
248 GtkWidget *m_pCanvas;
250 #if WITH_CAIRO
252 cairo_surface_t *m_pDisplaySurface;
253 cairo_surface_t *m_pDecorationSurface;
254 cairo_surface_t *m_pOnscreenSurface;
256 cairo_surface_t *m_pOffscreenbuffer;
258 #else
261 /// The offscreen buffer containing the 'background'
264 GdkPixmap *m_pDisplayBuffer;
266 ///
267 /// The offscreen buffer containing the full display. This is
268 /// constructed by first copying the display buffer across and then
269 /// drawing decorations such as the mouse cursor on top.
272 GdkPixmap *m_pDecorationBuffer;
275 /// The onscreen buffer - copied onscreen whenever an expose event occurs.
278 GdkPixmap *m_pOnscreenBuffer;
281 /// Pointer to which of the offscreen buffers is currently active.
284 GdkPixmap *m_pOffscreenBuffer;
285 GdkPixmap *m_pDummyBuffer;
287 #endif
289 ///
290 /// The Pango cache - used to store pre-computed pango layouts as
291 /// they are costly to regenerate every time they are needed.
294 CPangoCache *m_pPangoCache;
297 /// Holder for Pango layout extents.
300 PangoRectangle *m_pPangoInk;
302 #if WITH_CAIRO
303 cairo_t *display_cr;
304 cairo_t *decoration_cr;
305 cairo_t *onscreen_cr; // TODO: do we need to do our own double buffering?
307 cairo_t *widget_cr;
309 cairo_t *cr;
310 my_cairo_colour_t *cairo_colours;
311 #else
312 GdkColor *colours;
313 #endif
317 #endif