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
;
97 wxPaintDC::wxPaintDC( wxWindow
*window
)
99 m_penGC
= (GdkGC
*) NULL
;
100 m_brushGC
= (GdkGC
*) NULL
;
101 m_textGC
= (GdkGC
*) NULL
;
102 m_bgGC
= (GdkGC
*) NULL
;
103 m_cmap
= (GdkColormap
*) NULL
;
106 GtkWidget
*widget
= window
->m_wxwindow
;
108 m_window
= widget
->window
;
109 if (!m_window
) return;
110 if (window
->m_wxwindow
)
111 m_cmap
= gtk_widget_get_colormap( window
->m_wxwindow
);
113 m_cmap
= gtk_widget_get_colormap( window
->m_widget
);
120 wxPaintDC::~wxPaintDC(void)
124 void wxPaintDC::FloodFill( long WXUNUSED(x1
), long WXUNUSED(y1
),
125 wxColour
*WXUNUSED(col
), int WXUNUSED(style
) )
127 wxFAIL_MSG( "wxPaintDC::FloodFill not implemented" );
130 bool wxPaintDC::GetPixel( long WXUNUSED(x1
), long WXUNUSED(y1
), wxColour
*WXUNUSED(col
) ) const
132 wxFAIL_MSG( "wxPaintDC::GetPixel not implemented" );
136 void wxPaintDC::DrawLine( long x1
, long y1
, long x2
, long y2
)
140 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
142 if (m_pen
.GetStyle() != wxTRANSPARENT
)
144 gdk_draw_line( m_window
, m_penGC
,
145 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
149 void wxPaintDC::CrossHair( long x
, long y
)
153 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
155 if (m_pen
.GetStyle() != wxTRANSPARENT
)
160 long xx
= XLOG2DEV(x
);
161 long yy
= YLOG2DEV(y
);
162 gdk_draw_line( m_window
, m_penGC
,
163 0, yy
, XLOG2DEVREL(w
), yy
);
164 gdk_draw_line( m_window
, m_penGC
,
165 xx
, 0, xx
, YLOG2DEVREL(h
) );
169 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
173 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
175 long xx1
= XLOG2DEV(x1
);
176 long yy1
= YLOG2DEV(y1
);
177 long xx2
= XLOG2DEV(x2
);
178 long yy2
= YLOG2DEV(y2
);
179 long xxc
= XLOG2DEV((long)xc
);
180 long yyc
= YLOG2DEV((long)yc
);
181 double dx
= xx1
- xxc
;
182 double dy
= yy1
- yyc
;
183 double radius
= sqrt(dx
*dx
+dy
*dy
);
184 long r
= (long)radius
;
185 double radius1
, radius2
;
187 if (xx1
== xx2
&& yy1
== yy2
)
195 radius1
= radius2
= 0.0;
199 radius1
= (xx1
- xxc
== 0) ?
200 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
201 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
202 radius2
= (xx2
- xxc
== 0) ?
203 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
204 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
206 long alpha1
= long(radius1
* 64.0);
207 long alpha2
= long((radius2
- radius1
) * 64.0);
208 while (alpha2
<= 0) alpha2
+= 360*64;
209 while (alpha1
> 360*64) alpha1
-= 360*64;
211 if (m_brush
.GetStyle() != wxTRANSPARENT
)
212 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
214 if (m_pen
.GetStyle() != wxTRANSPARENT
)
215 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
219 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
223 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
225 long xx
= XLOG2DEV(x
);
226 long yy
= YLOG2DEV(y
);
227 long ww
= m_signX
* XLOG2DEVREL(width
);
228 long hh
= m_signY
* YLOG2DEVREL(height
);
230 // CMB: handle -ve width and/or height
231 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
232 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
234 long start
= long(sa
* 64.0);
235 long end
= long(ea
* 64.0);
236 if (m_brush
.GetStyle() != wxTRANSPARENT
)
237 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
239 if (m_pen
.GetStyle() != wxTRANSPARENT
)
240 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
243 void wxPaintDC::DrawPoint( long x
, long y
)
247 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
249 if (m_pen
.GetStyle() != wxTRANSPARENT
)
250 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
253 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
257 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
259 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
261 for (int i
= 0; i
< n
-1; i
++)
263 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
264 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
265 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
266 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
267 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
271 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
275 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
277 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
279 wxNode
*node
= points
->First();
282 wxPoint
*point
= (wxPoint
*)node
->Data();
283 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
284 long x1
= XLOG2DEV(point
->x
+ xoffset
);
285 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
286 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
287 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
288 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
293 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
297 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
299 if (!n
) return; // Nothing to draw
300 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
302 for (i
= 0 ; i
< n
; i
++)
304 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
305 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
307 if (m_brush
.GetStyle() != wxTRANSPARENT
)
308 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
310 if (m_pen
.GetStyle() != wxTRANSPARENT
)
311 for (i
= 0 ; i
< n
; i
++)
312 gdk_draw_line( m_window
, m_penGC
,
315 gdkpoints
[(i
+1)%n
].x
,
316 gdkpoints
[(i
+1)%n
].y
);
320 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
324 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
326 int n
= lines
->Number();
327 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
328 wxNode
*node
= lines
->First();
332 wxPoint
*p
= (wxPoint
*) node
->Data();
333 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
334 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
338 if (m_brush
.GetStyle() != wxTRANSPARENT
)
339 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
341 if (m_pen
.GetStyle() != wxTRANSPARENT
)
344 for (i
= 0 ; i
< n
; i
++)
345 gdk_draw_line( m_window
, m_penGC
,
348 gdkpoints
[(i
+1)%n
].x
,
349 gdkpoints
[(i
+1)%n
].y
);
354 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
358 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
360 long xx
= XLOG2DEV(x
);
361 long yy
= YLOG2DEV(y
);
362 long ww
= m_signX
* XLOG2DEVREL(width
);
363 long hh
= m_signY
* YLOG2DEVREL(height
);
365 // CMB: draw nothing if transformed w or h is 0
366 if (ww
== 0 || hh
== 0) return;
368 // CMB: handle -ve width and/or height
369 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
370 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
372 if (m_brush
.GetStyle() != wxTRANSPARENT
)
373 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
375 if (m_pen
.GetStyle() != wxTRANSPARENT
)
376 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
379 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
383 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
385 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
387 long xx
= XLOG2DEV(x
);
388 long yy
= YLOG2DEV(y
);
389 long ww
= m_signX
* XLOG2DEVREL(width
);
390 long hh
= m_signY
* YLOG2DEVREL(height
);
391 long rr
= XLOG2DEVREL((long)radius
);
393 // CMB: handle -ve width and/or height
394 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
395 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
397 // CMB: if radius is zero use DrawRectangle() instead to avoid
398 // X drawing errors with small radii
401 DrawRectangle( x
, y
, width
, height
);
405 // CMB: draw nothing if transformed w or h is 0
406 if (ww
== 0 || hh
== 0) return;
408 // CMB: adjust size if outline is drawn otherwise the result is
409 // 1 pixel too wide and high
410 if (m_pen
.GetStyle() != wxTRANSPARENT
)
416 // CMB: ensure dd is not larger than rectangle otherwise we
417 // get an hour glass shape
419 if (dd
> ww
) dd
= ww
;
420 if (dd
> hh
) dd
= hh
;
423 if (m_brush
.GetStyle() != wxTRANSPARENT
)
425 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
426 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
427 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
428 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
429 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
430 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
433 if (m_pen
.GetStyle() != wxTRANSPARENT
)
435 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
436 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
437 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
438 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
439 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
440 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
441 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
442 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
446 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
450 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
452 long xx
= XLOG2DEV(x
);
453 long yy
= YLOG2DEV(y
);
454 long ww
= m_signX
* XLOG2DEVREL(width
);
455 long hh
= m_signY
* YLOG2DEVREL(height
);
457 // CMB: handle -ve width and/or height
458 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
459 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
461 if (m_brush
.GetStyle() != wxTRANSPARENT
)
462 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
464 if (m_pen
.GetStyle() != wxTRANSPARENT
)
465 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
468 bool wxPaintDC::CanDrawBitmap(void) const
473 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
477 if (!icon
.Ok()) return;
479 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
481 int xx
= XLOG2DEV(x
);
482 int yy
= YLOG2DEV(y
);
484 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
485 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
489 gdk_gc_set_clip_mask( m_penGC
, mask
);
490 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
493 GdkPixmap
*pm
= icon
.GetPixmap();
494 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
498 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
499 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
503 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
504 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
506 if (!Ok()) return FALSE
;
508 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
510 // CMB 20/5/98: add blitting of bitmaps
511 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)))
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_isDrawable
) ((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_isDrawable
) ((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::DrawOpenSpline( 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 );