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 // FIXME: is this right? Causes a segfault on my system and doesn't
141 // seem right: wxPaintDC does not inherit from wxMemoryDC
142 // if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage();
144 if (m_pen
.GetStyle() != wxTRANSPARENT
)
146 gdk_draw_line( m_window
, m_penGC
,
147 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
151 void wxPaintDC::CrossHair( long x
, long y
)
155 // FIXME: is this right? Causes a segfault on my system and doesn't
156 // seem right: wxPaintDC does not inherit from wxMemoryDC
157 // if (!m_isDrawable) ((wxMemoryDC*)this)->m_selected.DestroyImage();
159 if (m_pen
.GetStyle() != wxTRANSPARENT
)
164 long xx
= XLOG2DEV(x
);
165 long yy
= YLOG2DEV(y
);
166 gdk_draw_line( m_window
, m_penGC
,
167 0, yy
, XLOG2DEVREL(w
), yy
);
168 gdk_draw_line( m_window
, m_penGC
,
169 xx
, 0, xx
, YLOG2DEVREL(h
) );
173 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
177 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
179 long xx1
= XLOG2DEV(x1
);
180 long yy1
= YLOG2DEV(y1
);
181 long xx2
= XLOG2DEV(x2
);
182 long yy2
= YLOG2DEV(y2
);
183 long xxc
= XLOG2DEV((long)xc
);
184 long yyc
= YLOG2DEV((long)yc
);
185 double dx
= xx1
- xxc
;
186 double dy
= yy1
- yyc
;
187 double radius
= sqrt(dx
*dx
+dy
*dy
);
188 long r
= (long)radius
;
189 double radius1
, radius2
;
191 if (xx1
== xx2
&& yy1
== yy2
)
199 radius1
= radius2
= 0.0;
203 radius1
= (xx1
- xxc
== 0) ?
204 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
205 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
206 radius2
= (xx2
- xxc
== 0) ?
207 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
208 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
210 long alpha1
= long(radius1
* 64.0);
211 long alpha2
= long((radius2
- radius1
) * 64.0);
212 while (alpha2
<= 0) alpha2
+= 360*64;
213 while (alpha1
> 360*64) alpha1
-= 360*64;
215 if (m_brush
.GetStyle() != wxTRANSPARENT
)
216 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
218 if (m_pen
.GetStyle() != wxTRANSPARENT
)
219 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
223 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
227 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
229 long xx
= XLOG2DEV(x
);
230 long yy
= YLOG2DEV(y
);
231 long ww
= m_signX
* XLOG2DEVREL(width
);
232 long hh
= m_signY
* YLOG2DEVREL(height
);
234 // CMB: handle -ve width and/or height
235 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
236 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
238 long start
= long(sa
* 64.0);
239 long end
= long(ea
* 64.0);
240 if (m_brush
.GetStyle() != wxTRANSPARENT
)
241 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
243 if (m_pen
.GetStyle() != wxTRANSPARENT
)
244 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
247 void wxPaintDC::DrawPoint( long x
, long y
)
251 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
253 if (m_pen
.GetStyle() != wxTRANSPARENT
)
254 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
257 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
261 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
263 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
265 for (int i
= 0; i
< n
-1; i
++)
267 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
268 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
269 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
270 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
271 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
275 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
279 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
281 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
283 wxNode
*node
= points
->First();
286 wxPoint
*point
= (wxPoint
*)node
->Data();
287 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
288 long x1
= XLOG2DEV(point
->x
+ xoffset
);
289 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
290 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
291 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
292 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
297 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
301 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
303 if (!n
) return; // Nothing to draw
304 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
306 for (i
= 0 ; i
< n
; i
++)
308 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
309 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
311 if (m_brush
.GetStyle() != wxTRANSPARENT
)
312 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
314 if (m_pen
.GetStyle() != wxTRANSPARENT
)
315 for (i
= 0 ; i
< n
; i
++)
316 gdk_draw_line( m_window
, m_penGC
,
319 gdkpoints
[(i
+1)%n
].x
,
320 gdkpoints
[(i
+1)%n
].y
);
324 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
328 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
330 int n
= lines
->Number();
331 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
332 wxNode
*node
= lines
->First();
336 wxPoint
*p
= (wxPoint
*) node
->Data();
337 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
338 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
342 if (m_brush
.GetStyle() != wxTRANSPARENT
)
343 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
345 if (m_pen
.GetStyle() != wxTRANSPARENT
)
348 for (i
= 0 ; i
< n
; i
++)
349 gdk_draw_line( m_window
, m_penGC
,
352 gdkpoints
[(i
+1)%n
].x
,
353 gdkpoints
[(i
+1)%n
].y
);
358 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
362 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
364 long xx
= XLOG2DEV(x
);
365 long yy
= YLOG2DEV(y
);
366 long ww
= m_signX
* XLOG2DEVREL(width
);
367 long hh
= m_signY
* YLOG2DEVREL(height
);
369 // CMB: draw nothing if transformed w or h is 0
370 if (ww
== 0 || hh
== 0) return;
372 // CMB: handle -ve width and/or height
373 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
374 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
376 if (m_brush
.GetStyle() != wxTRANSPARENT
)
377 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
379 if (m_pen
.GetStyle() != wxTRANSPARENT
)
380 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
383 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
387 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
389 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
391 long xx
= XLOG2DEV(x
);
392 long yy
= YLOG2DEV(y
);
393 long ww
= m_signX
* XLOG2DEVREL(width
);
394 long hh
= m_signY
* YLOG2DEVREL(height
);
395 long rr
= XLOG2DEVREL((long)radius
);
397 // CMB: handle -ve width and/or height
398 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
399 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
401 // CMB: if radius is zero use DrawRectangle() instead to avoid
402 // X drawing errors with small radii
405 DrawRectangle( x
, y
, width
, height
);
409 // CMB: draw nothing if transformed w or h is 0
410 if (ww
== 0 || hh
== 0) return;
412 // CMB: adjust size if outline is drawn otherwise the result is
413 // 1 pixel too wide and high
414 if (m_pen
.GetStyle() != wxTRANSPARENT
)
420 // CMB: ensure dd is not larger than rectangle otherwise we
421 // get an hour glass shape
423 if (dd
> ww
) dd
= ww
;
424 if (dd
> hh
) dd
= hh
;
427 if (m_brush
.GetStyle() != wxTRANSPARENT
)
429 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
430 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
431 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
432 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
433 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
434 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
437 if (m_pen
.GetStyle() != wxTRANSPARENT
)
439 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
440 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
441 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
442 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
443 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
444 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
445 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
446 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
450 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
454 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
456 long xx
= XLOG2DEV(x
);
457 long yy
= YLOG2DEV(y
);
458 long ww
= m_signX
* XLOG2DEVREL(width
);
459 long hh
= m_signY
* YLOG2DEVREL(height
);
461 // CMB: handle -ve width and/or height
462 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
463 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
465 if (m_brush
.GetStyle() != wxTRANSPARENT
)
466 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
468 if (m_pen
.GetStyle() != wxTRANSPARENT
)
469 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
472 bool wxPaintDC::CanDrawBitmap(void) const
477 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
481 if (!icon
.Ok()) return;
483 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
485 int xx
= XLOG2DEV(x
);
486 int yy
= YLOG2DEV(y
);
488 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
489 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
493 gdk_gc_set_clip_mask( m_penGC
, mask
);
494 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
497 GdkPixmap
*pm
= icon
.GetPixmap();
498 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
502 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
503 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
507 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
508 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool WXUNUSED(useMask
) )
510 if (!Ok()) return FALSE
;
512 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
514 // CMB 20/5/98: add blitting of bitmaps
515 if (source
->IsKindOf(CLASSINFO(wxMemoryDC
)))
517 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
518 GdkBitmap
* bmap
= srcDC
->m_selected
.GetBitmap();
521 gdk_draw_bitmap( m_window
, m_textGC
, bmap
,
522 source
->DeviceToLogicalX(xsrc
),
523 source
->DeviceToLogicalY(ysrc
),
526 source
->DeviceToLogicalXRel(width
),
527 source
->DeviceToLogicalYRel(height
) );
532 wxClientDC
*csrc
= (wxClientDC
*)source
;
533 gdk_window_copy_area ( m_window
, m_penGC
,
534 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
536 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
537 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
540 gdk_window_copy_area ( m_window, m_penGC,
541 XLOG2DEV(xdest), YLOG2DEV(ydest),
550 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
554 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
556 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
561 // CMB 21/5/98: draw text background if mode is wxSOLID
562 if (m_backgroundMode
== wxSOLID
)
564 long width
= gdk_string_width( font
, text
);
565 long height
= font
->ascent
+ font
->descent
;
566 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
567 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
568 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
570 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
572 // CMB 17/7/98: simple underline: ignores scaling and underlying
573 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
574 // properties (see wxXt implementation)
575 if (m_font
.GetUnderlined())
577 long width
= gdk_string_width( font
, text
);
578 long ul_y
= y
+ font
->ascent
;
579 if (font
->descent
> 0) ul_y
++;
580 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
584 bool wxPaintDC::CanGetTextExtent(void) const
589 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
590 long *descent
, long *externalLeading
,
591 wxFont
*theFont
, bool WXUNUSED(use16
) )
595 wxFont fontToUse
= m_font
;
596 if (theFont
) fontToUse
= *theFont
;
598 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
599 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
600 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
601 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
602 if (externalLeading
) (*externalLeading
) = 0; // ??
605 long wxPaintDC::GetCharWidth(void)
609 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
610 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
613 long wxPaintDC::GetCharHeight(void)
617 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
618 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
621 void wxPaintDC::Clear(void)
625 if (!m_isDrawable
) ((wxMemoryDC
*)this)->m_selected
.DestroyImage();
629 gdk_window_clear( m_window
);
635 GetSize( &width
, &height
);
636 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
640 void wxPaintDC::SetFont( const wxFont
&font
)
647 void wxPaintDC::SetPen( const wxPen
&pen
)
651 if (m_pen
== pen
) return;
655 if (!m_pen
.Ok()) return;
657 gint width
= m_pen
.GetWidth();
658 // CMB: if width is non-zero scale it with the dc
665 // X doesn't allow different width in x and y and so we take
667 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
671 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
672 switch (m_pen
.GetStyle())
674 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
675 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
676 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
677 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
678 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
681 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
682 switch (m_pen
.GetCap())
684 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
685 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
686 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
689 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
690 switch (m_pen
.GetJoin())
692 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
693 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
694 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
697 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
699 m_pen
.GetColour().CalcPixel( m_cmap
);
700 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
703 void wxPaintDC::SetBrush( const wxBrush
&brush
)
707 if (m_brush
== brush
) return;
711 if (!m_brush
.Ok()) return;
713 m_brush
.GetColour().CalcPixel( m_cmap
);
714 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
716 GdkFill fillStyle
= GDK_SOLID
;
717 switch (m_brush
.GetStyle())
723 fillStyle
= GDK_STIPPLED
;
726 gdk_gc_set_fill( m_brushGC
, fillStyle
);
728 if (m_brush
.GetStyle() == wxSTIPPLE
)
730 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
733 if (IS_HATCH(m_brush
.GetStyle()))
735 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
736 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
740 // CMB 21/7/98: Added SetBackground. Sets background brush
741 // for Clear() and bg colour for shapes filled with cross-hatch brush
742 void wxPaintDC::SetBackground( const wxBrush
&brush
)
746 if (m_backgroundBrush
== brush
) return;
748 m_backgroundBrush
= brush
;
750 if (!m_backgroundBrush
.Ok()) return;
752 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
753 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
754 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
756 GdkFill fillStyle
= GDK_SOLID
;
757 switch (m_backgroundBrush
.GetStyle())
763 fillStyle
= GDK_STIPPLED
;
766 gdk_gc_set_fill( m_bgGC
, fillStyle
);
768 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
770 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
773 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
775 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
776 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
780 void wxPaintDC::SetLogicalFunction( int function
)
782 if (m_logicalFunction
== function
) return;
783 GdkFunction mode
= GDK_COPY
;
786 case wxXOR
: mode
= GDK_INVERT
; break;
787 case wxINVERT
: mode
= GDK_INVERT
; break;
790 m_logicalFunction
= function
;
791 gdk_gc_set_function( m_penGC
, mode
);
792 gdk_gc_set_function( m_brushGC
, mode
);
795 void wxPaintDC::SetTextForeground( const wxColour
&col
)
799 if (m_textForegroundColour
== col
) return;
801 m_textForegroundColour
= col
;
802 if (!m_textForegroundColour
.Ok()) return;
804 m_textForegroundColour
.CalcPixel( m_cmap
);
805 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
808 void wxPaintDC::SetTextBackground( const wxColour
&col
)
812 if (m_textBackgroundColour
== col
) return;
814 m_textBackgroundColour
= col
;
815 if (!m_textBackgroundColour
.Ok()) return;
817 m_textBackgroundColour
.CalcPixel( m_cmap
);
818 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
821 void wxPaintDC::SetBackgroundMode( int mode
)
823 m_backgroundMode
= mode
;
825 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
826 // transparent/solid background mode
827 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
829 gdk_gc_set_fill( m_brushGC
,
830 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
834 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
838 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
840 wxDC::SetClippingRegion( x
, y
, width
, height
);
843 rect
.x
= XLOG2DEV(x
);
844 rect
.y
= YLOG2DEV(y
);
845 rect
.width
= XLOG2DEVREL(width
);
846 rect
.height
= YLOG2DEVREL(height
);
847 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
848 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
849 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
850 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
854 void wxPaintDC::DestroyClippingRegion(void)
856 wxDC::DestroyClippingRegion();
858 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
859 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
860 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
861 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
864 void wxPaintDC::SetUpDC(void)
867 m_logicalFunction
= wxCOPY
;
868 if (m_penGC
) gdk_gc_unref( m_penGC
);
869 m_penGC
= gdk_gc_new( m_window
);
870 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
871 m_brushGC
= gdk_gc_new( m_window
);
872 if (m_textGC
) gdk_gc_unref( m_textGC
);
873 m_textGC
= gdk_gc_new( m_window
);
874 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
875 m_bgGC
= gdk_gc_new( m_window
);
876 SetTextForeground( m_textForegroundColour
);
877 SetTextBackground( m_textBackgroundColour
);
882 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
886 hatch_bitmap
= hatches
;
887 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
888 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
889 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
890 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
891 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
892 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
896 GdkWindow
*wxPaintDC::GetWindow(void)
901 // ----------------------------------- spline code ----------------------------------------
903 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
904 double a3
, double b3
, double a4
, double b4
);
905 void wx_clear_stack(void);
906 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
907 double *y3
, double *x4
, double *y4
);
908 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
909 double x4
, double y4
);
910 static bool wx_spline_add_point(double x
, double y
);
911 static void wx_spline_draw_point_array(wxDC
*dc
);
913 wxList wx_spline_point_list
;
915 #define half(z1, z2) ((z1+z2)/2.0)
918 /* iterative version */
920 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
923 register double xmid
, ymid
;
924 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
927 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
929 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
930 xmid
= (double)half(x2
, x3
);
931 ymid
= (double)half(y2
, y3
);
932 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
933 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
934 wx_spline_add_point( x1
, y1
);
935 wx_spline_add_point( xmid
, ymid
);
937 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
938 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
939 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
940 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
945 /* utilities used by spline drawing routines */
947 typedef struct wx_spline_stack_struct
{
948 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
951 #define SPLINE_STACK_DEPTH 20
952 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
953 static Stack
*wx_stack_top
;
954 static int wx_stack_count
;
956 void wx_clear_stack(void)
958 wx_stack_top
= wx_spline_stack
;
962 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
964 wx_stack_top
->x1
= x1
;
965 wx_stack_top
->y1
= y1
;
966 wx_stack_top
->x2
= x2
;
967 wx_stack_top
->y2
= y2
;
968 wx_stack_top
->x3
= x3
;
969 wx_stack_top
->y3
= y3
;
970 wx_stack_top
->x4
= x4
;
971 wx_stack_top
->y4
= y4
;
976 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
977 double *x3
, double *y3
, double *x4
, double *y4
)
979 if (wx_stack_count
== 0)
983 *x1
= wx_stack_top
->x1
;
984 *y1
= wx_stack_top
->y1
;
985 *x2
= wx_stack_top
->x2
;
986 *y2
= wx_stack_top
->y2
;
987 *x3
= wx_stack_top
->x3
;
988 *y3
= wx_stack_top
->y3
;
989 *x4
= wx_stack_top
->x4
;
990 *y4
= wx_stack_top
->y4
;
994 static bool wx_spline_add_point(double x
, double y
)
996 wxPoint
*point
= new wxPoint
;
999 wx_spline_point_list
.Append((wxObject
*)point
);
1003 static void wx_spline_draw_point_array(wxDC
*dc
)
1005 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
1006 wxNode
*node
= wx_spline_point_list
.First();
1009 wxPoint
*point
= (wxPoint
*)node
->Data();
1012 node
= wx_spline_point_list
.First();
1016 void wxPaintDC::DrawSpline( wxList
*points
)
1019 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1020 double x1
, y1
, x2
, y2
;
1022 wxNode
*node
= points
->First();
1023 p
= (wxPoint
*)node
->Data();
1028 node
= node
->Next();
1029 p
= (wxPoint
*)node
->Data();
1033 cx1
= (double)((x1
+ x2
) / 2);
1034 cy1
= (double)((y1
+ y2
) / 2);
1035 cx2
= (double)((cx1
+ x2
) / 2);
1036 cy2
= (double)((cy1
+ y2
) / 2);
1038 wx_spline_add_point(x1
, y1
);
1040 while ((node
= node
->Next()) != NULL
)
1042 p
= (wxPoint
*)node
->Data();
1047 cx4
= (double)(x1
+ x2
) / 2;
1048 cy4
= (double)(y1
+ y2
) / 2;
1049 cx3
= (double)(x1
+ cx4
) / 2;
1050 cy3
= (double)(y1
+ cy4
) / 2;
1052 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1056 cx2
= (double)(cx1
+ x2
) / 2;
1057 cy2
= (double)(cy1
+ y2
) / 2;
1060 wx_spline_add_point( cx1
, cy1
);
1061 wx_spline_add_point( x2
, y2
);
1063 wx_spline_draw_point_array( this );