1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dcclient.h"
15 #include "wx/dcclient.h"
16 #include "wx/dcmemory.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
30 static GdkPixmap
*hatches
[num_hatches
];
31 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 #define RAD2DEG 57.2957795131
39 //-----------------------------------------------------------------------------
40 // temporary implementation of the missing GDK function
41 //-----------------------------------------------------------------------------
42 #include "gdk/gdkprivate.h"
43 void gdk_draw_bitmap (GdkDrawable
*drawable
,
53 GdkWindowPrivate
*drawable_private
;
54 GdkWindowPrivate
*src_private
;
55 GdkGCPrivate
*gc_private
;
57 g_return_if_fail (drawable
!= NULL
);
58 g_return_if_fail (src
!= NULL
);
59 g_return_if_fail (gc
!= NULL
);
61 drawable_private
= (GdkWindowPrivate
*) drawable
;
62 src_private
= (GdkWindowPrivate
*) src
;
63 if (drawable_private
->destroyed
|| src_private
->destroyed
)
65 gc_private
= (GdkGCPrivate
*) gc
;
68 width
= src_private
->width
;
70 height
= src_private
->height
;
72 XCopyPlane (drawable_private
->xdisplay
,
74 drawable_private
->xwindow
,
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxDC
)
88 wxPaintDC::wxPaintDC(void)
90 m_penGC
= (GdkGC
*) NULL
;
91 m_brushGC
= (GdkGC
*) NULL
;
92 m_textGC
= (GdkGC
*) NULL
;
93 m_bgGC
= (GdkGC
*) NULL
;
94 m_cmap
= (GdkColormap
*) NULL
;
98 wxPaintDC::wxPaintDC( wxWindow
*window
)
100 m_penGC
= (GdkGC
*) NULL
;
101 m_brushGC
= (GdkGC
*) NULL
;
102 m_textGC
= (GdkGC
*) NULL
;
103 m_bgGC
= (GdkGC
*) NULL
;
104 m_cmap
= (GdkColormap
*) NULL
;
107 GtkWidget
*widget
= window
->m_wxwindow
;
109 m_window
= widget
->window
;
110 if (!m_window
) return;
111 if (window
->m_wxwindow
)
112 m_cmap
= gtk_widget_get_colormap( window
->m_wxwindow
);
114 m_cmap
= gtk_widget_get_colormap( window
->m_widget
);
121 wxPaintDC::~wxPaintDC(void)
125 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
126 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
128 wxFAIL_MSG( "wxPaintDC::FloodFill not implemented" );
131 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
133 wxFAIL_MSG( "wxPaintDC::GetPixel not implemented" );
137 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
141 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
143 if (m_pen
.GetStyle() != wxTRANSPARENT
)
145 gdk_draw_line( m_window
, m_penGC
,
146 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
150 void wxPaintDC::CrossHair( long x
, long y
)
154 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
156 if (m_pen
.GetStyle() != wxTRANSPARENT
)
161 long xx
= XLOG2DEV(x
);
162 long yy
= YLOG2DEV(y
);
163 gdk_draw_line( m_window
, m_penGC
,
164 0, yy
, XLOG2DEVREL(w
), yy
);
165 gdk_draw_line( m_window
, m_penGC
,
166 xx
, 0, xx
, YLOG2DEVREL(h
) );
170 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
174 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
176 long xx1
= XLOG2DEV(x1
);
177 long yy1
= YLOG2DEV(y1
);
178 long xx2
= XLOG2DEV(x2
);
179 long yy2
= YLOG2DEV(y2
);
180 long xxc
= XLOG2DEV((long)xc
);
181 long yyc
= YLOG2DEV((long)yc
);
182 double dx
= xx1
- xxc
;
183 double dy
= yy1
- yyc
;
184 double radius
= sqrt(dx
*dx
+dy
*dy
);
185 long r
= (long)radius
;
186 double radius1
, radius2
;
188 if (xx1
== xx2
&& yy1
== yy2
)
196 radius1
= radius2
= 0.0;
200 radius1
= (xx1
- xxc
== 0) ?
201 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
202 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
203 radius2
= (xx2
- xxc
== 0) ?
204 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
205 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
207 long alpha1
= long(radius1
* 64.0);
208 long alpha2
= long((radius2
- radius1
) * 64.0);
209 while (alpha2
<= 0) alpha2
+= 360*64;
210 while (alpha1
> 360*64) alpha1
-= 360*64;
212 if (m_brush
.GetStyle() != wxTRANSPARENT
)
213 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
215 if (m_pen
.GetStyle() != wxTRANSPARENT
)
216 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
220 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
224 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
226 long xx
= XLOG2DEV(x
);
227 long yy
= YLOG2DEV(y
);
228 long ww
= m_signX
* XLOG2DEVREL(width
);
229 long hh
= m_signY
* YLOG2DEVREL(height
);
231 // CMB: handle -ve width and/or height
232 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
233 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
235 long start
= long(sa
* 64.0);
236 long end
= long(ea
* 64.0);
237 if (m_brush
.GetStyle() != wxTRANSPARENT
)
238 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
240 if (m_pen
.GetStyle() != wxTRANSPARENT
)
241 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
244 void wxPaintDC::DrawPoint( long x
, long y
)
248 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
250 if (m_pen
.GetStyle() != wxTRANSPARENT
)
251 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
254 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
258 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
260 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
262 for (int i
= 0; i
< n
-1; i
++)
264 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
265 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
266 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
267 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
268 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
272 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
276 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
278 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
280 wxNode
*node
= points
->First();
283 wxPoint
*point
= (wxPoint
*)node
->Data();
284 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
285 long x1
= XLOG2DEV(point
->x
+ xoffset
);
286 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
287 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
288 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
289 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
294 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
298 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
300 if (!n
) return; // Nothing to draw
301 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
303 for (i
= 0 ; i
< n
; i
++)
305 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
306 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
308 if (m_brush
.GetStyle() != wxTRANSPARENT
)
309 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
311 if (m_pen
.GetStyle() != wxTRANSPARENT
)
312 for (i
= 0 ; i
< n
; i
++)
313 gdk_draw_line( m_window
, m_penGC
,
316 gdkpoints
[(i
+1)%n
].x
,
317 gdkpoints
[(i
+1)%n
].y
);
321 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
325 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
327 int n
= lines
->Number();
328 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
329 wxNode
*node
= lines
->First();
333 wxPoint
*p
= (wxPoint
*) node
->Data();
334 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
335 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
339 if (m_brush
.GetStyle() != wxTRANSPARENT
)
340 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
342 if (m_pen
.GetStyle() != wxTRANSPARENT
)
345 for (i
= 0 ; i
< n
; i
++)
346 gdk_draw_line( m_window
, m_penGC
,
349 gdkpoints
[(i
+1)%n
].x
,
350 gdkpoints
[(i
+1)%n
].y
);
355 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
359 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
361 long xx
= XLOG2DEV(x
);
362 long yy
= YLOG2DEV(y
);
363 long ww
= m_signX
* XLOG2DEVREL(width
);
364 long hh
= m_signY
* YLOG2DEVREL(height
);
366 // CMB: draw nothing if transformed w or h is 0
367 if (ww
== 0 || hh
== 0) return;
369 // CMB: handle -ve width and/or height
370 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
371 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
373 if (m_brush
.GetStyle() != wxTRANSPARENT
)
374 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
376 if (m_pen
.GetStyle() != wxTRANSPARENT
)
377 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
380 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
384 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
386 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
388 long xx
= XLOG2DEV(x
);
389 long yy
= YLOG2DEV(y
);
390 long ww
= m_signX
* XLOG2DEVREL(width
);
391 long hh
= m_signY
* YLOG2DEVREL(height
);
392 long rr
= XLOG2DEVREL((long)radius
);
394 // CMB: handle -ve width and/or height
395 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
396 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
398 // CMB: if radius is zero use DrawRectangle() instead to avoid
399 // X drawing errors with small radii
402 DrawRectangle( x
, y
, width
, height
);
406 // CMB: draw nothing if transformed w or h is 0
407 if (ww
== 0 || hh
== 0) return;
409 // CMB: adjust size if outline is drawn otherwise the result is
410 // 1 pixel too wide and high
411 if (m_pen
.GetStyle() != wxTRANSPARENT
)
417 // CMB: ensure dd is not larger than rectangle otherwise we
418 // get an hour glass shape
420 if (dd
> ww
) dd
= ww
;
421 if (dd
> hh
) dd
= hh
;
424 if (m_brush
.GetStyle() != wxTRANSPARENT
)
426 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
427 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
428 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
429 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
430 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
431 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
434 if (m_pen
.GetStyle() != wxTRANSPARENT
)
436 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
437 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
438 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
439 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
440 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
441 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
442 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
443 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
447 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
451 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
453 long xx
= XLOG2DEV(x
);
454 long yy
= YLOG2DEV(y
);
455 long ww
= m_signX
* XLOG2DEVREL(width
);
456 long hh
= m_signY
* YLOG2DEVREL(height
);
458 // CMB: handle -ve width and/or height
459 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
460 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
462 if (m_brush
.GetStyle() != wxTRANSPARENT
)
463 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
465 if (m_pen
.GetStyle() != wxTRANSPARENT
)
466 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
469 bool wxPaintDC::CanDrawBitmap(void) const
474 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
478 if (!icon
.Ok()) return;
480 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
482 int xx
= XLOG2DEV(x
);
483 int yy
= YLOG2DEV(y
);
485 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
486 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
490 gdk_gc_set_clip_mask( m_penGC
, mask
);
491 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
494 GdkPixmap
*pm
= icon
.GetPixmap();
495 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
499 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
500 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
504 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
505 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
507 if (!Ok()) return FALSE
;
509 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
513 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
514 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
517 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
518 source
->DeviceToLogicalX(xsrc
),
519 source
->DeviceToLogicalY(ysrc
),
522 source
->DeviceToLogicalXRel(width
),
523 source
->DeviceToLogicalYRel(height
) );
528 wxClientDC
*csrc
= (wxClientDC
*)source
;
529 gdk_window_copy_area ( m_window
, m_penGC
,
530 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
532 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
533 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
536 gdk_window_copy_area ( m_window, m_penGC,
537 XLOG2DEV(xdest), YLOG2DEV(ydest),
546 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
550 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
552 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
557 // CMB 21/5/98: draw text background if mode is wxSOLID
558 if (m_backgroundMode
== wxSOLID
)
560 long width
= gdk_string_width( font
, text
);
561 long height
= font
->ascent
+ font
->descent
;
562 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
563 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
564 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
566 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
568 // CMB 17/7/98: simple underline: ignores scaling and underlying
569 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
570 // properties (see wxXt implementation)
571 if (m_font
.GetUnderlined())
573 long width
= gdk_string_width( font
, text
);
574 long ul_y
= y
+ font
->ascent
;
575 if (font
->descent
> 0) ul_y
++;
576 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
580 bool wxPaintDC::CanGetTextExtent(void) const
585 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
586 long *descent
, long *externalLeading
,
587 wxFont
*theFont
, bool WXUNUSED(use16
) )
591 wxFont fontToUse
= m_font
;
592 if (theFont
) fontToUse
= *theFont
;
594 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
595 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
596 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
597 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
598 if (externalLeading
) (*externalLeading
) = 0; // ??
601 long wxPaintDC::GetCharWidth(void)
605 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
606 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
609 long wxPaintDC::GetCharHeight(void)
613 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
614 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
617 void wxPaintDC::Clear(void)
621 if (m_isMemDC
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
625 gdk_window_clear( m_window
);
631 GetSize( &width
, &height
);
632 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
636 void wxPaintDC::SetFont( const wxFont
&font
)
643 void wxPaintDC::SetPen( const wxPen
&pen
)
647 if (m_pen
== pen
) return;
651 if (!m_pen
.Ok()) return;
653 gint width
= m_pen
.GetWidth();
654 // CMB: if width is non-zero scale it with the dc
661 // X doesn't allow different width in x and y and so we take
663 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
667 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
668 switch (m_pen
.GetStyle())
670 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
671 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
672 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
673 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
674 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
677 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
678 switch (m_pen
.GetCap())
680 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
681 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
682 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
685 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
686 switch (m_pen
.GetJoin())
688 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
689 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
690 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
693 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
695 m_pen
.GetColour().CalcPixel( m_cmap
);
696 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
699 void wxPaintDC::SetBrush( const wxBrush
&brush
)
703 if (m_brush
== brush
) return;
707 if (!m_brush
.Ok()) return;
709 m_brush
.GetColour().CalcPixel( m_cmap
);
710 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
712 GdkFill fillStyle
= GDK_SOLID
;
713 switch (m_brush
.GetStyle())
719 fillStyle
= GDK_STIPPLED
;
722 gdk_gc_set_fill( m_brushGC
, fillStyle
);
724 if (m_brush
.GetStyle() == wxSTIPPLE
)
726 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
729 if (IS_HATCH(m_brush
.GetStyle()))
731 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
732 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
736 // CMB 21/7/98: Added SetBackground. Sets background brush
737 // for Clear() and bg colour for shapes filled with cross-hatch brush
738 void wxPaintDC::SetBackground( const wxBrush
&brush
)
742 if (m_backgroundBrush
== brush
) return;
744 m_backgroundBrush
= brush
;
746 if (!m_backgroundBrush
.Ok()) return;
748 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
749 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
750 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
752 GdkFill fillStyle
= GDK_SOLID
;
753 switch (m_backgroundBrush
.GetStyle())
759 fillStyle
= GDK_STIPPLED
;
762 gdk_gc_set_fill( m_bgGC
, fillStyle
);
764 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
766 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
769 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
771 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
772 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
776 void wxPaintDC::SetLogicalFunction( int function
)
778 if (m_logicalFunction
== function
) return;
779 GdkFunction mode
= GDK_COPY
;
782 case wxXOR
: mode
= GDK_INVERT
; break;
783 case wxINVERT
: mode
= GDK_INVERT
; break;
786 m_logicalFunction
= function
;
787 gdk_gc_set_function( m_penGC
, mode
);
788 gdk_gc_set_function( m_brushGC
, mode
);
791 void wxPaintDC::SetTextForeground( const wxColour
&col
)
795 if (m_textForegroundColour
== col
) return;
797 m_textForegroundColour
= col
;
798 if (!m_textForegroundColour
.Ok()) return;
800 m_textForegroundColour
.CalcPixel( m_cmap
);
801 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
804 void wxPaintDC::SetTextBackground( const wxColour
&col
)
808 if (m_textBackgroundColour
== col
) return;
810 m_textBackgroundColour
= col
;
811 if (!m_textBackgroundColour
.Ok()) return;
813 m_textBackgroundColour
.CalcPixel( m_cmap
);
814 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
817 void wxPaintDC::SetBackgroundMode( int mode
)
819 m_backgroundMode
= mode
;
821 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
822 // transparent/solid background mode
823 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
825 gdk_gc_set_fill( m_brushGC
,
826 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
830 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
834 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
836 wxDC::SetClippingRegion( x
, y
, width
, height
);
839 rect
.x
= XLOG2DEV(x
);
840 rect
.y
= YLOG2DEV(y
);
841 rect
.width
= XLOG2DEVREL(width
);
842 rect
.height
= YLOG2DEVREL(height
);
843 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
844 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
845 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
846 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
850 void wxPaintDC::DestroyClippingRegion(void)
852 wxDC::DestroyClippingRegion();
854 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
855 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
856 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
857 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
860 void wxPaintDC::SetUpDC(void)
863 m_logicalFunction
= wxCOPY
;
864 if (m_penGC
) gdk_gc_unref( m_penGC
);
865 m_penGC
= gdk_gc_new( m_window
);
866 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
867 m_brushGC
= gdk_gc_new( m_window
);
868 if (m_textGC
) gdk_gc_unref( m_textGC
);
869 m_textGC
= gdk_gc_new( m_window
);
870 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
871 m_bgGC
= gdk_gc_new( m_window
);
872 SetTextForeground( m_textForegroundColour
);
873 SetTextBackground( m_textBackgroundColour
);
878 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
882 hatch_bitmap
= hatches
;
883 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
884 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
885 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
886 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
887 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
888 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
892 GdkWindow
*wxPaintDC::GetWindow(void)
897 // ----------------------------------- spline code ----------------------------------------
899 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
900 double a3
, double b3
, double a4
, double b4
);
901 void wx_clear_stack(void);
902 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
903 double *y3
, double *x4
, double *y4
);
904 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
905 double x4
, double y4
);
906 static bool wx_spline_add_point(double x
, double y
);
907 static void wx_spline_draw_point_array(wxDC
*dc
);
909 wxList wx_spline_point_list
;
911 #define half(z1, z2) ((z1+z2)/2.0)
914 /* iterative version */
916 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
919 register double xmid
, ymid
;
920 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
923 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
925 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
926 xmid
= (double)half(x2
, x3
);
927 ymid
= (double)half(y2
, y3
);
928 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
929 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
930 wx_spline_add_point( x1
, y1
);
931 wx_spline_add_point( xmid
, ymid
);
933 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
934 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
935 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
936 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
941 /* utilities used by spline drawing routines */
943 typedef struct wx_spline_stack_struct
{
944 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
947 #define SPLINE_STACK_DEPTH 20
948 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
949 static Stack
*wx_stack_top
;
950 static int wx_stack_count
;
952 void wx_clear_stack(void)
954 wx_stack_top
= wx_spline_stack
;
958 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
960 wx_stack_top
->x1
= x1
;
961 wx_stack_top
->y1
= y1
;
962 wx_stack_top
->x2
= x2
;
963 wx_stack_top
->y2
= y2
;
964 wx_stack_top
->x3
= x3
;
965 wx_stack_top
->y3
= y3
;
966 wx_stack_top
->x4
= x4
;
967 wx_stack_top
->y4
= y4
;
972 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
973 double *x3
, double *y3
, double *x4
, double *y4
)
975 if (wx_stack_count
== 0)
979 *x1
= wx_stack_top
->x1
;
980 *y1
= wx_stack_top
->y1
;
981 *x2
= wx_stack_top
->x2
;
982 *y2
= wx_stack_top
->y2
;
983 *x3
= wx_stack_top
->x3
;
984 *y3
= wx_stack_top
->y3
;
985 *x4
= wx_stack_top
->x4
;
986 *y4
= wx_stack_top
->y4
;
990 static bool wx_spline_add_point(double x
, double y
)
992 wxPoint
*point
= new wxPoint
;
995 wx_spline_point_list
.Append((wxObject
*)point
);
999 static void wx_spline_draw_point_array(wxDC
*dc
)
1001 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
1002 wxNode
*node
= wx_spline_point_list
.First();
1005 wxPoint
*point
= (wxPoint
*)node
->Data();
1008 node
= wx_spline_point_list
.First();
1012 void wxPaintDC::DrawSpline( wxList
*points
)
1015 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1016 double x1
, y1
, x2
, y2
;
1018 wxNode
*node
= points
->First();
1019 p
= (wxPoint
*)node
->Data();
1024 node
= node
->Next();
1025 p
= (wxPoint
*)node
->Data();
1029 cx1
= (double)((x1
+ x2
) / 2);
1030 cy1
= (double)((y1
+ y2
) / 2);
1031 cx2
= (double)((cx1
+ x2
) / 2);
1032 cy2
= (double)((cy1
+ y2
) / 2);
1034 wx_spline_add_point(x1
, y1
);
1036 while ((node
= node
->Next()) != NULL
)
1038 p
= (wxPoint
*)node
->Data();
1043 cx4
= (double)(x1
+ x2
) / 2;
1044 cy4
= (double)(y1
+ y2
) / 2;
1045 cx3
= (double)(x1
+ cx4
) / 2;
1046 cy3
= (double)(y1
+ cy4
) / 2;
1048 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1052 cx2
= (double)(cx1
+ x2
) / 2;
1053 cy2
= (double)(cy1
+ y2
) / 2;
1056 wx_spline_add_point( cx1
, cy1
);
1057 wx_spline_add_point( x2
, y2
);
1059 wx_spline_draw_point_array( this );