1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem, Chris Breeze
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dcclient.h"
14 #include "wx/dcclient.h"
15 #include "wx/dcmemory.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
29 static GdkPixmap
*hatches
[num_hatches
];
30 static GdkPixmap
**hatch_bitmap
= (GdkPixmap
**) NULL
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 #define RAD2DEG 57.2957795131
38 //-----------------------------------------------------------------------------
39 // temporary implementation of the missing GDK function
40 //-----------------------------------------------------------------------------
41 #include "gdk/gdkprivate.h"
42 void gdk_draw_bitmap (GdkDrawable
*drawable
,
52 GdkWindowPrivate
*drawable_private
;
53 GdkWindowPrivate
*src_private
;
54 GdkGCPrivate
*gc_private
;
56 g_return_if_fail (drawable
!= NULL
);
57 g_return_if_fail (src
!= NULL
);
58 g_return_if_fail (gc
!= NULL
);
60 drawable_private
= (GdkWindowPrivate
*) drawable
;
61 src_private
= (GdkWindowPrivate
*) src
;
62 if (drawable_private
->destroyed
|| src_private
->destroyed
)
65 gc_private
= (GdkGCPrivate
*) gc
;
67 if (width
== -1) width
= src_private
->width
;
68 if (height
== -1) height
= src_private
->height
;
70 XCopyPlane( drawable_private
->xdisplay
,
72 drawable_private
->xwindow
,
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
84 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxDC
)
86 wxPaintDC::wxPaintDC(void)
88 m_penGC
= (GdkGC
*) NULL
;
89 m_brushGC
= (GdkGC
*) NULL
;
90 m_textGC
= (GdkGC
*) NULL
;
91 m_bgGC
= (GdkGC
*) NULL
;
92 m_cmap
= (GdkColormap
*) NULL
;
96 wxPaintDC::wxPaintDC( wxWindow
*window
)
98 m_penGC
= (GdkGC
*) NULL
;
99 m_brushGC
= (GdkGC
*) NULL
;
100 m_textGC
= (GdkGC
*) NULL
;
101 m_bgGC
= (GdkGC
*) NULL
;
102 m_cmap
= (GdkColormap
*) NULL
;
105 GtkWidget
*widget
= window
->m_wxwindow
;
107 m_window
= widget
->window
;
108 if (!m_window
) return;
109 if (window
->m_wxwindow
)
110 m_cmap
= gtk_widget_get_colormap( window
->m_wxwindow
);
112 m_cmap
= gtk_widget_get_colormap( window
->m_widget
);
119 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_pen
.GetStyle() != wxTRANSPARENT
)
142 gdk_draw_line( m_window
, m_penGC
,
143 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
146 CalcBoundingBox(x1
, y1
);
147 CalcBoundingBox(x2
, y2
);
150 void wxPaintDC::CrossHair( long x
, long y
)
154 if (m_pen
.GetStyle() != wxTRANSPARENT
)
159 long xx
= XLOG2DEV(x
);
160 long yy
= YLOG2DEV(y
);
161 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
162 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
166 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
170 long xx1
= XLOG2DEV(x1
);
171 long yy1
= YLOG2DEV(y1
);
172 long xx2
= XLOG2DEV(x2
);
173 long yy2
= YLOG2DEV(y2
);
174 long xxc
= XLOG2DEV((long)xc
);
175 long yyc
= YLOG2DEV((long)yc
);
176 double dx
= xx1
- xxc
;
177 double dy
= yy1
- yyc
;
178 double radius
= sqrt(dx
*dx
+dy
*dy
);
179 long r
= (long)radius
;
180 double radius1
, radius2
;
182 if (xx1
== xx2
&& yy1
== yy2
)
190 radius1
= radius2
= 0.0;
194 radius1
= (xx1
- xxc
== 0) ?
195 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
196 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
197 radius2
= (xx2
- xxc
== 0) ?
198 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
199 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
201 long alpha1
= long(radius1
* 64.0);
202 long alpha2
= long((radius2
- radius1
) * 64.0);
203 while (alpha2
<= 0) alpha2
+= 360*64;
204 while (alpha1
> 360*64) alpha1
-= 360*64;
206 if (m_brush
.GetStyle() != wxTRANSPARENT
)
207 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
209 if (m_pen
.GetStyle() != wxTRANSPARENT
)
210 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
212 CalcBoundingBox (x1
, y1
);
213 CalcBoundingBox (x2
, y2
);
216 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
220 long xx
= XLOG2DEV(x
);
221 long yy
= YLOG2DEV(y
);
222 long ww
= m_signX
* XLOG2DEVREL(width
);
223 long hh
= m_signY
* YLOG2DEVREL(height
);
225 // CMB: handle -ve width and/or height
226 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
227 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
229 long start
= long(sa
* 64.0);
230 long end
= long(ea
* 64.0);
231 if (m_brush
.GetStyle() != wxTRANSPARENT
)
232 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
234 if (m_pen
.GetStyle() != wxTRANSPARENT
)
235 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
237 CalcBoundingBox (x
, y
);
238 CalcBoundingBox (x
+ width
, y
+ height
);
241 void wxPaintDC::DrawPoint( long x
, long y
)
245 if (m_pen
.GetStyle() != wxTRANSPARENT
)
246 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
248 CalcBoundingBox (x
, y
);
251 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
255 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
258 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
260 for (int i
= 0; i
< n
-1; i
++)
262 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
263 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
264 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
265 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
266 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
268 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
272 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
276 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
278 wxNode
*node
= points
->First();
281 wxPoint
*pt
= (wxPoint
*)node
->Data();
282 CalcBoundingBox( pt
->x
+ xoffset
, pt
->y
+ yoffset
);
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 a waste again...
291 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
292 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
295 CalcBoundingBox( npoint
->x
+ xoffset
, npoint
->y
+ yoffset
);
299 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
305 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
307 for (i
= 0 ; i
< n
; i
++)
309 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
310 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
312 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
315 if (m_brush
.GetStyle() != wxTRANSPARENT
)
316 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
320 if (m_pen
.GetStyle() != wxTRANSPARENT
)
321 for (i
= 0 ; i
< n
; i
++)
323 gdk_draw_line( m_window
, m_penGC
,
326 gdkpoints
[(i
+1)%n
].x
,
327 gdkpoints
[(i
+1)%n
].y
);
333 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
337 int n
= lines
->Number();
340 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
341 wxNode
*node
= lines
->First();
345 wxPoint
*p
= (wxPoint
*) node
->Data();
346 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
347 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
351 CalcBoundingBox( p
->x
+ xoffset
, p
->y
+ yoffset
);
354 if (m_brush
.GetStyle() != wxTRANSPARENT
)
355 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
359 if (m_pen
.GetStyle() != wxTRANSPARENT
)
362 for (i
= 0 ; i
< n
; i
++)
364 gdk_draw_line( m_window
, m_penGC
,
367 gdkpoints
[(i
+1)%n
].x
,
368 gdkpoints
[(i
+1)%n
].y
);
374 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
378 long xx
= XLOG2DEV(x
);
379 long yy
= YLOG2DEV(y
);
380 long ww
= m_signX
* XLOG2DEVREL(width
);
381 long hh
= m_signY
* YLOG2DEVREL(height
);
383 // CMB: draw nothing if transformed w or h is 0
384 if (ww
== 0 || hh
== 0) return;
386 // CMB: handle -ve width and/or height
387 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
388 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
390 if (m_brush
.GetStyle() != wxTRANSPARENT
)
391 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
393 if (m_pen
.GetStyle() != wxTRANSPARENT
)
394 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
396 CalcBoundingBox( x
, y
);
397 CalcBoundingBox( x
+ width
, y
+ height
);
400 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
404 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
406 long xx
= XLOG2DEV(x
);
407 long yy
= YLOG2DEV(y
);
408 long ww
= m_signX
* XLOG2DEVREL(width
);
409 long hh
= m_signY
* YLOG2DEVREL(height
);
410 long rr
= XLOG2DEVREL((long)radius
);
412 // CMB: handle -ve width and/or height
413 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
414 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
416 // CMB: if radius is zero use DrawRectangle() instead to avoid
417 // X drawing errors with small radii
420 DrawRectangle( x
, y
, width
, height
);
424 // CMB: draw nothing if transformed w or h is 0
425 if (ww
== 0 || hh
== 0) return;
427 // CMB: adjust size if outline is drawn otherwise the result is
428 // 1 pixel too wide and high
429 if (m_pen
.GetStyle() != wxTRANSPARENT
)
435 // CMB: ensure dd is not larger than rectangle otherwise we
436 // get an hour glass shape
438 if (dd
> ww
) dd
= ww
;
439 if (dd
> hh
) dd
= hh
;
442 if (m_brush
.GetStyle() != wxTRANSPARENT
)
444 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
445 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
446 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
447 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
448 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
449 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
452 if (m_pen
.GetStyle() != wxTRANSPARENT
)
454 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
455 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
456 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
457 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
458 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
459 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
460 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
461 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
464 // this ignores the radius
465 CalcBoundingBox( x
, y
);
466 CalcBoundingBox( x
+ width
, y
+ height
);
469 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
473 long xx
= XLOG2DEV(x
);
474 long yy
= YLOG2DEV(y
);
475 long ww
= m_signX
* XLOG2DEVREL(width
);
476 long hh
= m_signY
* YLOG2DEVREL(height
);
478 // CMB: handle -ve width and/or height
479 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
480 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
482 if (m_brush
.GetStyle() != wxTRANSPARENT
)
483 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
485 if (m_pen
.GetStyle() != wxTRANSPARENT
)
486 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
488 CalcBoundingBox( x
, y
);
489 CalcBoundingBox( x
+ width
, y
+ height
);
492 bool wxPaintDC::CanDrawBitmap(void) const
497 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
501 if (!icon
.Ok()) return;
503 int xx
= XLOG2DEV(x
);
504 int yy
= YLOG2DEV(y
);
506 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
507 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
511 gdk_gc_set_clip_mask( m_penGC
, mask
);
512 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
515 GdkPixmap
*pm
= icon
.GetPixmap();
516 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
520 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
521 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
524 CalcBoundingBox( x
, y
);
525 int width
= icon
.GetWidth();
526 int height
= icon
.GetHeight();
527 CalcBoundingBox( x
+ width
, y
+ height
);
530 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
531 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool useMask
)
533 if (!Ok()) return FALSE
;
535 CalcBoundingBox( xdest
, ydest
);
536 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
538 wxClientDC
*csrc
= (wxClientDC
*)source
;
542 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
543 GdkPixmap
* bmap
= srcDC
->m_selected
.GetPixmap();
546 long xx
= XLOG2DEV(xdest
);
547 long yy
= YLOG2DEV(ydest
);
549 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
550 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
554 gdk_gc_set_clip_mask( m_penGC
, mask
);
555 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
558 gdk_draw_pixmap( m_window
, m_penGC
, bmap
,
559 source
->DeviceToLogicalX(xsrc
),
560 source
->DeviceToLogicalY(ysrc
),
563 source
->DeviceToLogicalXRel(width
),
564 source
->DeviceToLogicalYRel(height
) );
568 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
569 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
576 gdk_window_copy_area ( m_window
, m_penGC
,
577 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
579 source
->DeviceToLogicalX(xsrc
),
580 source
->DeviceToLogicalY(ysrc
),
581 source
->DeviceToLogicalXRel(width
),
582 source
->DeviceToLogicalYRel(height
) );
585 gdk_window_copy_area ( m_window, m_penGC,
586 XLOG2DEV(xdest), YLOG2DEV(ydest),
595 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
599 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
604 // CMB 21/5/98: draw text background if mode is wxSOLID
605 if (m_backgroundMode
== wxSOLID
)
607 long width
= gdk_string_width( font
, text
);
608 long height
= font
->ascent
+ font
->descent
;
609 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
610 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
611 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
613 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
615 // CMB 17/7/98: simple underline: ignores scaling and underlying
616 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
617 // properties (see wxXt implementation)
618 if (m_font
.GetUnderlined())
620 long width
= gdk_string_width( font
, text
);
621 long ul_y
= y
+ font
->ascent
;
622 if (font
->descent
> 0) ul_y
++;
623 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
627 GetTextExtent (text
, &w
, &h
);
628 CalcBoundingBox (x
+ w
, y
+ h
);
629 CalcBoundingBox (x
, y
);
632 bool wxPaintDC::CanGetTextExtent(void) const
637 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
638 long *descent
, long *externalLeading
,
639 wxFont
*theFont
, bool WXUNUSED(use16
) )
643 wxFont fontToUse
= m_font
;
644 if (theFont
) fontToUse
= *theFont
;
646 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
647 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
648 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
649 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
650 if (externalLeading
) (*externalLeading
) = 0; // ??
653 long wxPaintDC::GetCharWidth(void)
657 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
658 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
661 long wxPaintDC::GetCharHeight(void)
665 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
666 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
669 void wxPaintDC::Clear(void)
675 gdk_window_clear( m_window
);
680 GetSize( &width
, &height
);
681 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
685 void wxPaintDC::SetFont( const wxFont
&font
)
692 void wxPaintDC::SetPen( const wxPen
&pen
)
696 if (m_pen
== pen
) return;
700 if (!m_pen
.Ok()) return;
702 gint width
= m_pen
.GetWidth();
703 // CMB: if width is non-zero scale it with the dc
710 // X doesn't allow different width in x and y and so we take
712 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
716 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
717 switch (m_pen
.GetStyle())
719 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
720 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
721 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
722 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
723 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
726 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
727 switch (m_pen
.GetCap())
729 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
730 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
731 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
734 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
735 switch (m_pen
.GetJoin())
737 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
738 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
739 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
742 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
744 m_pen
.GetColour().CalcPixel( m_cmap
);
745 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
748 void wxPaintDC::SetBrush( const wxBrush
&brush
)
752 if (m_brush
== brush
) return;
756 if (!m_brush
.Ok()) return;
758 m_brush
.GetColour().CalcPixel( m_cmap
);
759 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
761 GdkFill fillStyle
= GDK_SOLID
;
762 switch (m_brush
.GetStyle())
768 fillStyle
= GDK_STIPPLED
;
771 gdk_gc_set_fill( m_brushGC
, fillStyle
);
773 if (m_brush
.GetStyle() == wxSTIPPLE
)
775 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
778 if (IS_HATCH(m_brush
.GetStyle()))
780 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
781 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
785 // CMB 21/7/98: Added SetBackground. Sets background brush
786 // for Clear() and bg colour for shapes filled with cross-hatch brush
787 void wxPaintDC::SetBackground( const wxBrush
&brush
)
791 if (m_backgroundBrush
== brush
) return;
793 m_backgroundBrush
= brush
;
795 if (!m_backgroundBrush
.Ok()) return;
797 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
798 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
799 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
801 GdkFill fillStyle
= GDK_SOLID
;
802 switch (m_backgroundBrush
.GetStyle())
808 fillStyle
= GDK_STIPPLED
;
811 gdk_gc_set_fill( m_bgGC
, fillStyle
);
813 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
815 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
818 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
820 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
821 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
825 void wxPaintDC::SetLogicalFunction( int function
)
827 if (m_logicalFunction
== function
) return;
828 GdkFunction mode
= GDK_COPY
;
831 case wxXOR
: mode
= GDK_INVERT
; break;
832 case wxINVERT
: mode
= GDK_INVERT
; break;
835 m_logicalFunction
= function
;
836 gdk_gc_set_function( m_penGC
, mode
);
837 gdk_gc_set_function( m_brushGC
, mode
);
840 void wxPaintDC::SetTextForeground( const wxColour
&col
)
844 if (m_textForegroundColour
== col
) return;
846 m_textForegroundColour
= col
;
847 if (!m_textForegroundColour
.Ok()) return;
849 m_textForegroundColour
.CalcPixel( m_cmap
);
850 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
853 void wxPaintDC::SetTextBackground( const wxColour
&col
)
857 if (m_textBackgroundColour
== col
) return;
859 m_textBackgroundColour
= col
;
860 if (!m_textBackgroundColour
.Ok()) return;
862 m_textBackgroundColour
.CalcPixel( m_cmap
);
863 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
866 void wxPaintDC::SetBackgroundMode( int mode
)
868 m_backgroundMode
= mode
;
870 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
871 // transparent/solid background mode
872 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
874 gdk_gc_set_fill( m_brushGC
,
875 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
879 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
883 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
885 wxDC::SetClippingRegion( x
, y
, width
, height
);
888 rect
.x
= XLOG2DEV(x
);
889 rect
.y
= YLOG2DEV(y
);
890 rect
.width
= XLOG2DEVREL(width
);
891 rect
.height
= YLOG2DEVREL(height
);
892 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
893 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
894 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
895 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
898 void wxPaintDC::DestroyClippingRegion(void)
900 wxDC::DestroyClippingRegion();
902 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
903 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
904 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
905 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
908 void wxPaintDC::SetUpDC(void)
912 m_logicalFunction
= wxCOPY
;
913 m_penGC
= gdk_gc_new( m_window
);
914 m_brushGC
= gdk_gc_new( m_window
);
915 m_textGC
= gdk_gc_new( m_window
);
916 m_bgGC
= gdk_gc_new( m_window
);
917 SetTextForeground( m_textForegroundColour
);
918 SetTextBackground( m_textBackgroundColour
);
923 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
927 hatch_bitmap
= hatches
;
928 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
929 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
930 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
931 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
932 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
933 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
937 void wxPaintDC::Destroy(void)
939 if (m_penGC
) gdk_gc_unref( m_penGC
);
940 m_penGC
= (GdkGC
*) NULL
;
941 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
942 m_brushGC
= (GdkGC
*) NULL
;
943 if (m_textGC
) gdk_gc_unref( m_textGC
);
944 m_textGC
= (GdkGC
*) NULL
;
945 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
946 m_bgGC
= (GdkGC
*) NULL
;
949 GdkWindow
*wxPaintDC::GetWindow(void)
954 // ----------------------------------- spline code ----------------------------------------
956 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
957 double a3
, double b3
, double a4
, double b4
);
958 void wx_clear_stack(void);
959 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
960 double *y3
, double *x4
, double *y4
);
961 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
962 double x4
, double y4
);
963 static bool wx_spline_add_point(double x
, double y
);
964 static void wx_spline_draw_point_array(wxDC
*dc
);
966 wxList wx_spline_point_list
;
968 #define half(z1, z2) ((z1+z2)/2.0)
971 /* iterative version */
973 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
976 register double xmid
, ymid
;
977 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
980 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
982 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
983 xmid
= (double)half(x2
, x3
);
984 ymid
= (double)half(y2
, y3
);
985 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
986 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
987 wx_spline_add_point( x1
, y1
);
988 wx_spline_add_point( xmid
, ymid
);
990 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
991 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
992 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
993 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
998 /* utilities used by spline drawing routines */
1000 typedef struct wx_spline_stack_struct
{
1001 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1004 #define SPLINE_STACK_DEPTH 20
1005 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
1006 static Stack
*wx_stack_top
;
1007 static int wx_stack_count
;
1009 void wx_clear_stack(void)
1011 wx_stack_top
= wx_spline_stack
;
1015 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
1017 wx_stack_top
->x1
= x1
;
1018 wx_stack_top
->y1
= y1
;
1019 wx_stack_top
->x2
= x2
;
1020 wx_stack_top
->y2
= y2
;
1021 wx_stack_top
->x3
= x3
;
1022 wx_stack_top
->y3
= y3
;
1023 wx_stack_top
->x4
= x4
;
1024 wx_stack_top
->y4
= y4
;
1029 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
1030 double *x3
, double *y3
, double *x4
, double *y4
)
1032 if (wx_stack_count
== 0)
1036 *x1
= wx_stack_top
->x1
;
1037 *y1
= wx_stack_top
->y1
;
1038 *x2
= wx_stack_top
->x2
;
1039 *y2
= wx_stack_top
->y2
;
1040 *x3
= wx_stack_top
->x3
;
1041 *y3
= wx_stack_top
->y3
;
1042 *x4
= wx_stack_top
->x4
;
1043 *y4
= wx_stack_top
->y4
;
1047 static bool wx_spline_add_point(double x
, double y
)
1049 wxPoint
*point
= new wxPoint
;
1052 wx_spline_point_list
.Append((wxObject
*)point
);
1056 static void wx_spline_draw_point_array(wxDC
*dc
)
1058 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
1059 wxNode
*node
= wx_spline_point_list
.First();
1062 wxPoint
*point
= (wxPoint
*)node
->Data();
1065 node
= wx_spline_point_list
.First();
1069 void wxPaintDC::DrawSpline( wxList
*points
)
1072 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1073 double x1
, y1
, x2
, y2
;
1075 wxNode
*node
= points
->First();
1076 p
= (wxPoint
*)node
->Data();
1081 node
= node
->Next();
1082 p
= (wxPoint
*)node
->Data();
1086 cx1
= (double)((x1
+ x2
) / 2);
1087 cy1
= (double)((y1
+ y2
) / 2);
1088 cx2
= (double)((cx1
+ x2
) / 2);
1089 cy2
= (double)((cy1
+ y2
) / 2);
1091 wx_spline_add_point(x1
, y1
);
1093 while ((node
= node
->Next()) != NULL
)
1095 p
= (wxPoint
*)node
->Data();
1100 cx4
= (double)(x1
+ x2
) / 2;
1101 cy4
= (double)(y1
+ y2
) / 2;
1102 cx3
= (double)(x1
+ cx4
) / 2;
1103 cy3
= (double)(y1
+ cy4
) / 2;
1105 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1109 cx2
= (double)(cx1
+ x2
) / 2;
1110 cy2
= (double)(cy1
+ y2
) / 2;
1113 wx_spline_add_point( cx1
, cy1
);
1114 wx_spline_add_point( x2
, y2
);
1116 wx_spline_draw_point_array( this );