4 #include "../DasherCore/DasherScreen.h"
5 #include "../DasherCore/DasherTypes.h"
6 #include "../DasherCore/CustomColours.h"
10 #include "PangoCache.h"
16 /* Cairo drawing backend */
17 #include <gdk/gdkcairo.h>
24 #define BEGIN_DRAWING_BACKEND \
27 #define END_DRAWING_BACKEND \
30 #define SET_COLOR_BACKEND(c) \
32 my_cairo_colour_t _c = cairo_colours[(c)]; \
33 cairo_set_source_rgb(cr, _c.r, _c.g, _c.b); \
36 #else /* WITHOUT_CAIRO */
38 #define BEGIN_DRAWING_BACKEND \
39 GdkGCValues origvalues; \
40 gdk_gc_get_values(graphics_context,&origvalues)
42 #define END_DRAWING_BACKEND \
43 gdk_gc_set_values(graphics_context,&origvalues,GDK_GC_FOREGROUND)
45 #define SET_COLOR_BACKEND(c) \
47 GdkColor _c = colours[(c)]; \
48 gdk_colormap_alloc_color(colormap, &_c, FALSE, TRUE); \
49 gdk_gc_set_foreground (graphics_context, &_c); \
52 #endif /* WITH_CAIRO */
54 // Some other useful macros (for all backends)
56 #define BEGIN_DRAWING \
62 #define SET_COLOR(c) \
65 using namespace Dasher
;
69 /// Method definitions for CCanvas, implementing the CDasherScreen
70 /// interface. Please think very carefully before implementing new
71 /// functionality in this class. Anything which isn't a 'drawing
72 /// primitive' should really not be here - higher level drawing
73 /// functions belong in CDasherView.
75 class CCanvas
:public Dasher::CDasherScreen
{
80 /// \param pCanvas The GTK drawing area used by the canvas
81 /// \param pPangoCache A cache for precomputed Pango layouts
84 CCanvas(GtkWidget
* pCanvas
, CPangoCache
* pPangoCache
);
88 /// GTK signal handler for exposure of the canvas - cause a redraw to the screen from the buffer.
91 bool ExposeEvent( GtkWidget
*pWidget
, GdkEventExpose
*pEvent
);
94 // CDasherScreen methods
97 /// Set the font used to render the Dasher display
98 /// \param Name The name of the font.
99 /// \todo This needs to be reimplemented for 4.0
100 /// \deprecated In Linux - now handled by the pango cache, but need to think how this fits in with Windows
103 void SetFont(std::string Name
) {
107 /// Set the font size for rendering
108 /// \param fontsize The font size to use
109 /// \deprecated Obsolete
112 void SetFontSize(Dasher::Opts::FontSize fontsize
) {
117 /// Get the current font size
118 /// \deprecated To be removed before 4.0 release
119 /// \todo We should not be relying on locally cached variables - check to see whether this is still used or not
122 Dasher::Opts::FontSize
GetFontSize() {
123 return Dasher::Opts::FontSize(1);
127 /// Return the physical extent of a given string being rendered at a given size.
128 /// \param String The string to be rendered
129 /// \param Width Pointer to a variable to be filled with the width
130 /// \param Height Pointer to a variable to be filled with the height
131 /// \param Size Size at which the string will be rendered (units?)
134 void TextSize(const std::string
&String
, screenint
*Width
, screenint
*Height
, int Size
);
137 /// Draw a text string
138 /// \param String The string to be rendered
139 /// \param x1 The x coordinate at which to draw the text (be more precise)
140 /// \param y1 The y coordinate at which to draw the text (be more precise)
141 /// \param Size The size at which to render the rectangle (units?)
144 void DrawString(const std::string
&String
, screenint x1
, screenint y1
, int Size
);
148 /// \param x1 x coordiate of the top left corner
149 /// \param y1 y coordiate of the top left corner
150 /// \param x2 x coordiate of the bottom right corner
151 /// \param y2 y coordiate of the bottom right corner
152 /// \param Color Colour to draw the rectangle
153 /// \param ColorScheme Which of the alternating colour schemes to use (be more precise)
154 /// \param bDrawOutline Whether or not to draw outlines for the boxes
157 void DrawRectangle(screenint x1
, screenint y1
, screenint x2
, screenint y2
, int Color
, int iOutlineColour
, Opts::ColorSchemes ColorScheme
, bool bDrawOutine
, bool bFill
, int iThickness
);
159 void DrawCircle(screenint iCX
, screenint iCY
, screenint iR
, int iColour
, int iFillColour
, int iThickness
, bool bFill
);
162 /// Send a marker to indicate phases of the redraw process. This is
163 /// done so that we can do tripple buffering to minimise the amount
164 /// of costly font rendering which needs to be done. Marker 1
165 /// indicates that start of a new frame. Marker 2 indicates that we
166 /// are now drawing decoration (such as mouse cursors etc.) rather
167 /// than tne background. Only marker 2 will be send while Dasher is
169 /// \param iMarker ID of the marker being sent.
172 void SendMarker(int iMarker
);
175 /// Draw a coloured polyline
176 /// \param Points Array of vertices
177 /// \param Number Size of 'Points' array
178 /// \param Colour Colour with which to draw the line
181 void Polyline(point
* Points
, int Number
, int iWidth
, int Colour
);
184 /// Like polyline, but fill the shape
185 /// \todo See comments for DrawPolygon
188 void Polygon(point
*Points
, int Number
, int Colour
, int iWidth
);
191 /// \todo Not implemented
192 /// \todo One of these two routines must be redundant - find out which and kill the other
195 void DrawPolygon(point
*Points
, int Number
, int Color
, Opts::ColorSchemes ColorScheme
) {
206 /// Marks the end of the display process - at this point the offscreen buffer is copied onscreen.
212 /// Update the colour definitions
213 /// \param Colours New colours to use
216 void SetColourScheme(const CCustomColours
*Colours
);
219 /// Gets the location and size of our canvas.
220 /// Returns true on success, false otherwise.
221 bool GetCanvasSize(GdkRectangle
*pRectangle
);
238 /// The GTK drawing area for the canvas
241 GtkWidget
*m_pCanvas
;
244 /// The offscreen buffer containing the 'background'
247 GdkPixmap
*m_pDisplayBuffer
;
250 /// The offscreen buffer containing the full display. This is
251 /// constructed by first copying the display buffer across and then
252 /// drawing decorations such as the mouse cursor on top.
255 GdkPixmap
*m_pDecorationBuffer
;
258 /// The onscreen buffer - copied onscreen whenever an expose event occurs.
261 GdkPixmap
*m_pOnscreenBuffer
;
264 /// Pointer to which of the offscreen buffers is currently active.
267 GdkPixmap
*m_pOffscreenBuffer
;
268 GdkPixmap
*m_pDummyBuffer
;
271 /// The Pango cache - used to store pre-computed pango layouts as
272 /// they are costly to regenerate every time they are needed.
275 CPangoCache
*m_pPangoCache
;
278 /// Holder for Pango layout extents.
281 PangoRectangle
*m_pPangoInk
;
284 /// The signal handler ID for the expose callback - stored so it can
285 /// be disconnected when the CCanvas object is destroyed (which will
286 /// happen whenever the canvas is resized).
289 gulong lSignalHandler
;
293 cairo_t
*decoration_cr
;
295 my_cairo_colour_t
*cairo_colours
;