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"
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
)
66 gc_private
= (GdkGCPrivate
*) gc
;
68 if (width
== -1) width
= src_private
->width
;
69 if (height
== -1) height
= src_private
->height
;
71 XCopyPlane( drawable_private
->xdisplay
,
73 drawable_private
->xwindow
,
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC
,wxDC
)
87 wxPaintDC::wxPaintDC(void)
89 m_penGC
= (GdkGC
*) NULL
;
90 m_brushGC
= (GdkGC
*) NULL
;
91 m_textGC
= (GdkGC
*) NULL
;
92 m_bgGC
= (GdkGC
*) NULL
;
93 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)
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_pen
.GetStyle() != wxTRANSPARENT
)
143 gdk_draw_line( m_window
, m_penGC
,
144 XLOG2DEV(x1
), YLOG2DEV(y1
), XLOG2DEV(x2
), YLOG2DEV(y2
) );
147 CalcBoundingBox(x1
, y1
);
148 CalcBoundingBox(x2
, y2
);
151 void wxPaintDC::CrossHair( long x
, long y
)
155 if (m_pen
.GetStyle() != wxTRANSPARENT
)
160 long xx
= XLOG2DEV(x
);
161 long yy
= YLOG2DEV(y
);
162 gdk_draw_line( m_window
, m_penGC
, 0, yy
, XLOG2DEVREL(w
), yy
);
163 gdk_draw_line( m_window
, m_penGC
, xx
, 0, xx
, YLOG2DEVREL(h
) );
167 void wxPaintDC::DrawArc( long x1
, long y1
, long x2
, long y2
, double xc
, double yc
)
171 long xx1
= XLOG2DEV(x1
);
172 long yy1
= YLOG2DEV(y1
);
173 long xx2
= XLOG2DEV(x2
);
174 long yy2
= YLOG2DEV(y2
);
175 long xxc
= XLOG2DEV((long)xc
);
176 long yyc
= YLOG2DEV((long)yc
);
177 double dx
= xx1
- xxc
;
178 double dy
= yy1
- yyc
;
179 double radius
= sqrt(dx
*dx
+dy
*dy
);
180 long r
= (long)radius
;
181 double radius1
, radius2
;
183 if (xx1
== xx2
&& yy1
== yy2
)
191 radius1
= radius2
= 0.0;
195 radius1
= (xx1
- xxc
== 0) ?
196 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
197 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
198 radius2
= (xx2
- xxc
== 0) ?
199 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
200 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
202 long alpha1
= long(radius1
* 64.0);
203 long alpha2
= long((radius2
- radius1
) * 64.0);
204 while (alpha2
<= 0) alpha2
+= 360*64;
205 while (alpha1
> 360*64) alpha1
-= 360*64;
207 if (m_brush
.GetStyle() != wxTRANSPARENT
)
208 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
210 if (m_pen
.GetStyle() != wxTRANSPARENT
)
211 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xxc
-r
, yyc
-r
, 2*r
,2*r
, alpha1
, alpha2
);
213 CalcBoundingBox (x1
, y1
);
214 CalcBoundingBox (x2
, y2
);
217 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
221 long xx
= XLOG2DEV(x
);
222 long yy
= YLOG2DEV(y
);
223 long ww
= m_signX
* XLOG2DEVREL(width
);
224 long hh
= m_signY
* YLOG2DEVREL(height
);
226 // CMB: handle -ve width and/or height
227 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
228 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
230 long start
= long(sa
* 64.0);
231 long end
= long(ea
* 64.0);
232 if (m_brush
.GetStyle() != wxTRANSPARENT
)
233 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
235 if (m_pen
.GetStyle() != wxTRANSPARENT
)
236 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
238 CalcBoundingBox (x
, y
);
239 CalcBoundingBox (x
+ width
, y
+ height
);
242 void wxPaintDC::DrawPoint( long x
, long y
)
246 if (m_pen
.GetStyle() != wxTRANSPARENT
)
247 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
249 CalcBoundingBox (x
, y
);
252 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
256 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
259 CalcBoundingBox( points
[0].x
+ xoffset
, points
[0].y
+ yoffset
);
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
);
269 CalcBoundingBox( points
[i
+1].x
+ xoffset
, points
[i
+1].y
+ yoffset
);
273 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
277 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
279 wxNode
*node
= points
->First();
282 wxPoint
*pt
= (wxPoint
*)node
->Data();
283 CalcBoundingBox( pt
->x
+ xoffset
, pt
->y
+ yoffset
);
287 wxPoint
*point
= (wxPoint
*)node
->Data();
288 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
289 long x1
= XLOG2DEV(point
->x
+ xoffset
);
290 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
291 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and a waste again...
292 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
293 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
296 CalcBoundingBox( npoint
->x
+ xoffset
, npoint
->y
+ yoffset
);
300 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
306 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
308 for (i
= 0 ; i
< n
; i
++)
310 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
311 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
313 CalcBoundingBox( points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
316 if (m_brush
.GetStyle() != wxTRANSPARENT
)
317 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
321 if (m_pen
.GetStyle() != wxTRANSPARENT
)
322 for (i
= 0 ; i
< n
; i
++)
324 gdk_draw_line( m_window
, m_penGC
,
327 gdkpoints
[(i
+1)%n
].x
,
328 gdkpoints
[(i
+1)%n
].y
);
334 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
338 int n
= lines
->Number();
341 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
342 wxNode
*node
= lines
->First();
346 wxPoint
*p
= (wxPoint
*) node
->Data();
347 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
348 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
352 CalcBoundingBox( p
->x
+ xoffset
, p
->y
+ yoffset
);
355 if (m_brush
.GetStyle() != wxTRANSPARENT
)
356 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
360 if (m_pen
.GetStyle() != wxTRANSPARENT
)
363 for (i
= 0 ; i
< n
; i
++)
365 gdk_draw_line( m_window
, m_penGC
,
368 gdkpoints
[(i
+1)%n
].x
,
369 gdkpoints
[(i
+1)%n
].y
);
375 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
379 long xx
= XLOG2DEV(x
);
380 long yy
= YLOG2DEV(y
);
381 long ww
= m_signX
* XLOG2DEVREL(width
);
382 long hh
= m_signY
* YLOG2DEVREL(height
);
384 // CMB: draw nothing if transformed w or h is 0
385 if (ww
== 0 || hh
== 0) return;
387 // CMB: handle -ve width and/or height
388 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
389 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
391 if (m_brush
.GetStyle() != wxTRANSPARENT
)
392 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
394 if (m_pen
.GetStyle() != wxTRANSPARENT
)
395 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
397 CalcBoundingBox( x
, y
);
398 CalcBoundingBox( x
+ width
, y
+ height
);
401 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
405 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
407 long xx
= XLOG2DEV(x
);
408 long yy
= YLOG2DEV(y
);
409 long ww
= m_signX
* XLOG2DEVREL(width
);
410 long hh
= m_signY
* YLOG2DEVREL(height
);
411 long rr
= XLOG2DEVREL((long)radius
);
413 // CMB: handle -ve width and/or height
414 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
415 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
417 // CMB: if radius is zero use DrawRectangle() instead to avoid
418 // X drawing errors with small radii
421 DrawRectangle( x
, y
, width
, height
);
425 // CMB: draw nothing if transformed w or h is 0
426 if (ww
== 0 || hh
== 0) return;
428 // CMB: adjust size if outline is drawn otherwise the result is
429 // 1 pixel too wide and high
430 if (m_pen
.GetStyle() != wxTRANSPARENT
)
436 // CMB: ensure dd is not larger than rectangle otherwise we
437 // get an hour glass shape
439 if (dd
> ww
) dd
= ww
;
440 if (dd
> hh
) dd
= hh
;
443 if (m_brush
.GetStyle() != wxTRANSPARENT
)
445 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
446 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
447 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
448 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
449 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
450 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
453 if (m_pen
.GetStyle() != wxTRANSPARENT
)
455 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
456 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
457 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
458 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
459 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
460 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
461 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
462 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
465 // this ignores the radius
466 CalcBoundingBox( x
, y
);
467 CalcBoundingBox( x
+ width
, y
+ height
);
470 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
474 long xx
= XLOG2DEV(x
);
475 long yy
= YLOG2DEV(y
);
476 long ww
= m_signX
* XLOG2DEVREL(width
);
477 long hh
= m_signY
* YLOG2DEVREL(height
);
479 // CMB: handle -ve width and/or height
480 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
481 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
483 if (m_brush
.GetStyle() != wxTRANSPARENT
)
484 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
486 if (m_pen
.GetStyle() != wxTRANSPARENT
)
487 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
489 CalcBoundingBox( x
, y
);
490 CalcBoundingBox( x
+ width
, y
+ height
);
493 bool wxPaintDC::CanDrawBitmap(void) const
498 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
502 if (!icon
.Ok()) return;
504 int xx
= XLOG2DEV(x
);
505 int yy
= YLOG2DEV(y
);
507 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
508 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
512 gdk_gc_set_clip_mask( m_penGC
, mask
);
513 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
516 GdkPixmap
*pm
= icon
.GetPixmap();
517 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
521 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
522 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
525 CalcBoundingBox( x
, y
);
526 int width
= icon
.GetWidth();
527 int height
= icon
.GetHeight();
528 CalcBoundingBox( x
+ width
, y
+ height
);
531 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
532 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool useMask
)
534 if (!Ok()) return FALSE
;
536 CalcBoundingBox( xdest
, ydest
);
537 CalcBoundingBox( xdest
+ width
, ydest
+ height
);
539 wxClientDC
*csrc
= (wxClientDC
*)source
;
543 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
544 GdkPixmap
* bmap
= srcDC
->m_selected
.GetPixmap();
547 long xx
= XLOG2DEV(xdest
);
548 long yy
= YLOG2DEV(ydest
);
550 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
551 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
555 gdk_gc_set_clip_mask( m_penGC
, mask
);
556 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
559 gdk_draw_pixmap( m_window
, m_penGC
, bmap
,
560 source
->DeviceToLogicalX(xsrc
),
561 source
->DeviceToLogicalY(ysrc
),
564 source
->DeviceToLogicalXRel(width
),
565 source
->DeviceToLogicalYRel(height
) );
569 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
570 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
577 gdk_window_copy_area ( m_window
, m_penGC
,
578 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
580 source
->DeviceToLogicalX(xsrc
),
581 source
->DeviceToLogicalY(ysrc
),
582 source
->DeviceToLogicalXRel(width
),
583 source
->DeviceToLogicalYRel(height
) );
586 gdk_window_copy_area ( m_window, m_penGC,
587 XLOG2DEV(xdest), YLOG2DEV(ydest),
596 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
600 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
605 // CMB 21/5/98: draw text background if mode is wxSOLID
606 if (m_backgroundMode
== wxSOLID
)
608 long width
= gdk_string_width( font
, text
);
609 long height
= font
->ascent
+ font
->descent
;
610 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
611 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
612 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
614 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
616 // CMB 17/7/98: simple underline: ignores scaling and underlying
617 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
618 // properties (see wxXt implementation)
619 if (m_font
.GetUnderlined())
621 long width
= gdk_string_width( font
, text
);
622 long ul_y
= y
+ font
->ascent
;
623 if (font
->descent
> 0) ul_y
++;
624 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
628 GetTextExtent (text
, &w
, &h
);
629 CalcBoundingBox (x
+ w
, y
+ h
);
630 CalcBoundingBox (x
, y
);
633 bool wxPaintDC::CanGetTextExtent(void) const
638 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
639 long *descent
, long *externalLeading
,
640 wxFont
*theFont
, bool WXUNUSED(use16
) )
644 wxFont fontToUse
= m_font
;
645 if (theFont
) fontToUse
= *theFont
;
647 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
648 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
649 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
650 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
651 if (externalLeading
) (*externalLeading
) = 0; // ??
654 long wxPaintDC::GetCharWidth(void)
658 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
659 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
662 long wxPaintDC::GetCharHeight(void)
666 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
667 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
670 void wxPaintDC::Clear(void)
676 gdk_window_clear( m_window
);
681 GetSize( &width
, &height
);
682 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
686 void wxPaintDC::SetFont( const wxFont
&font
)
693 void wxPaintDC::SetPen( const wxPen
&pen
)
697 if (m_pen
== pen
) return;
701 if (!m_pen
.Ok()) return;
703 gint width
= m_pen
.GetWidth();
704 // CMB: if width is non-zero scale it with the dc
711 // X doesn't allow different width in x and y and so we take
713 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
717 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
718 switch (m_pen
.GetStyle())
720 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
721 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
722 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
723 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
724 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
727 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
728 switch (m_pen
.GetCap())
730 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
731 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
732 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
735 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
736 switch (m_pen
.GetJoin())
738 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
739 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
740 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
743 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
745 m_pen
.GetColour().CalcPixel( m_cmap
);
746 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
749 void wxPaintDC::SetBrush( const wxBrush
&brush
)
753 if (m_brush
== brush
) return;
757 if (!m_brush
.Ok()) return;
759 m_brush
.GetColour().CalcPixel( m_cmap
);
760 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
762 GdkFill fillStyle
= GDK_SOLID
;
763 switch (m_brush
.GetStyle())
769 fillStyle
= GDK_STIPPLED
;
772 gdk_gc_set_fill( m_brushGC
, fillStyle
);
774 if (m_brush
.GetStyle() == wxSTIPPLE
)
776 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
779 if (IS_HATCH(m_brush
.GetStyle()))
781 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
782 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
786 // CMB 21/7/98: Added SetBackground. Sets background brush
787 // for Clear() and bg colour for shapes filled with cross-hatch brush
788 void wxPaintDC::SetBackground( const wxBrush
&brush
)
792 if (m_backgroundBrush
== brush
) return;
794 m_backgroundBrush
= brush
;
796 if (!m_backgroundBrush
.Ok()) return;
798 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
799 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
800 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
802 GdkFill fillStyle
= GDK_SOLID
;
803 switch (m_backgroundBrush
.GetStyle())
809 fillStyle
= GDK_STIPPLED
;
812 gdk_gc_set_fill( m_bgGC
, fillStyle
);
814 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
816 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
819 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
821 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
822 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
826 void wxPaintDC::SetLogicalFunction( int function
)
828 if (m_logicalFunction
== function
) return;
829 GdkFunction mode
= GDK_COPY
;
832 case wxXOR
: mode
= GDK_INVERT
; break;
833 case wxINVERT
: mode
= GDK_INVERT
; break;
836 m_logicalFunction
= function
;
837 gdk_gc_set_function( m_penGC
, mode
);
838 gdk_gc_set_function( m_brushGC
, mode
);
841 void wxPaintDC::SetTextForeground( const wxColour
&col
)
845 if (m_textForegroundColour
== col
) return;
847 m_textForegroundColour
= col
;
848 if (!m_textForegroundColour
.Ok()) return;
850 m_textForegroundColour
.CalcPixel( m_cmap
);
851 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
854 void wxPaintDC::SetTextBackground( const wxColour
&col
)
858 if (m_textBackgroundColour
== col
) return;
860 m_textBackgroundColour
= col
;
861 if (!m_textBackgroundColour
.Ok()) return;
863 m_textBackgroundColour
.CalcPixel( m_cmap
);
864 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
867 void wxPaintDC::SetBackgroundMode( int mode
)
869 m_backgroundMode
= mode
;
871 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
872 // transparent/solid background mode
873 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
875 gdk_gc_set_fill( m_brushGC
,
876 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
880 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
884 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
886 wxDC::SetClippingRegion( x
, y
, width
, height
);
889 rect
.x
= XLOG2DEV(x
);
890 rect
.y
= YLOG2DEV(y
);
891 rect
.width
= XLOG2DEVREL(width
);
892 rect
.height
= YLOG2DEVREL(height
);
893 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
894 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
895 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
896 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
899 void wxPaintDC::DestroyClippingRegion(void)
901 wxDC::DestroyClippingRegion();
903 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
904 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
905 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
906 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
909 void wxPaintDC::SetUpDC(void)
913 m_logicalFunction
= wxCOPY
;
914 m_penGC
= gdk_gc_new( m_window
);
915 m_brushGC
= gdk_gc_new( m_window
);
916 m_textGC
= gdk_gc_new( m_window
);
917 m_bgGC
= gdk_gc_new( m_window
);
918 SetTextForeground( m_textForegroundColour
);
919 SetTextBackground( m_textBackgroundColour
);
924 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
928 hatch_bitmap
= hatches
;
929 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
930 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
931 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
932 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
933 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
934 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
938 void wxPaintDC::Destroy(void)
940 if (m_penGC
) gdk_gc_unref( m_penGC
);
941 m_penGC
= (GdkGC
*) NULL
;
942 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
943 m_brushGC
= (GdkGC
*) NULL
;
944 if (m_textGC
) gdk_gc_unref( m_textGC
);
945 m_textGC
= (GdkGC
*) NULL
;
946 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
947 m_bgGC
= (GdkGC
*) NULL
;
950 GdkWindow
*wxPaintDC::GetWindow(void)
955 // ----------------------------------- spline code ----------------------------------------
957 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
958 double a3
, double b3
, double a4
, double b4
);
959 void wx_clear_stack(void);
960 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
961 double *y3
, double *x4
, double *y4
);
962 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
963 double x4
, double y4
);
964 static bool wx_spline_add_point(double x
, double y
);
965 static void wx_spline_draw_point_array(wxDC
*dc
);
967 wxList wx_spline_point_list
;
969 #define half(z1, z2) ((z1+z2)/2.0)
972 /* iterative version */
974 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
977 register double xmid
, ymid
;
978 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
981 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
983 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
984 xmid
= (double)half(x2
, x3
);
985 ymid
= (double)half(y2
, y3
);
986 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
987 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
988 wx_spline_add_point( x1
, y1
);
989 wx_spline_add_point( xmid
, ymid
);
991 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
992 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
993 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
994 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
999 /* utilities used by spline drawing routines */
1001 typedef struct wx_spline_stack_struct
{
1002 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
1005 #define SPLINE_STACK_DEPTH 20
1006 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
1007 static Stack
*wx_stack_top
;
1008 static int wx_stack_count
;
1010 void wx_clear_stack(void)
1012 wx_stack_top
= wx_spline_stack
;
1016 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
1018 wx_stack_top
->x1
= x1
;
1019 wx_stack_top
->y1
= y1
;
1020 wx_stack_top
->x2
= x2
;
1021 wx_stack_top
->y2
= y2
;
1022 wx_stack_top
->x3
= x3
;
1023 wx_stack_top
->y3
= y3
;
1024 wx_stack_top
->x4
= x4
;
1025 wx_stack_top
->y4
= y4
;
1030 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
1031 double *x3
, double *y3
, double *x4
, double *y4
)
1033 if (wx_stack_count
== 0)
1037 *x1
= wx_stack_top
->x1
;
1038 *y1
= wx_stack_top
->y1
;
1039 *x2
= wx_stack_top
->x2
;
1040 *y2
= wx_stack_top
->y2
;
1041 *x3
= wx_stack_top
->x3
;
1042 *y3
= wx_stack_top
->y3
;
1043 *x4
= wx_stack_top
->x4
;
1044 *y4
= wx_stack_top
->y4
;
1048 static bool wx_spline_add_point(double x
, double y
)
1050 wxPoint
*point
= new wxPoint
;
1053 wx_spline_point_list
.Append((wxObject
*)point
);
1057 static void wx_spline_draw_point_array(wxDC
*dc
)
1059 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
1060 wxNode
*node
= wx_spline_point_list
.First();
1063 wxPoint
*point
= (wxPoint
*)node
->Data();
1066 node
= wx_spline_point_list
.First();
1070 void wxPaintDC::DrawSpline( wxList
*points
)
1073 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1074 double x1
, y1
, x2
, y2
;
1076 wxNode
*node
= points
->First();
1077 p
= (wxPoint
*)node
->Data();
1082 node
= node
->Next();
1083 p
= (wxPoint
*)node
->Data();
1087 cx1
= (double)((x1
+ x2
) / 2);
1088 cy1
= (double)((y1
+ y2
) / 2);
1089 cx2
= (double)((cx1
+ x2
) / 2);
1090 cy2
= (double)((cy1
+ y2
) / 2);
1092 wx_spline_add_point(x1
, y1
);
1094 while ((node
= node
->Next()) != NULL
)
1096 p
= (wxPoint
*)node
->Data();
1101 cx4
= (double)(x1
+ x2
) / 2;
1102 cy4
= (double)(y1
+ y2
) / 2;
1103 cx3
= (double)(x1
+ cx4
) / 2;
1104 cy3
= (double)(y1
+ cy4
) / 2;
1106 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1110 cx2
= (double)(cx1
+ x2
) / 2;
1111 cy2
= (double)(cy1
+ y2
) / 2;
1114 wx_spline_add_point( cx1
, cy1
);
1115 wx_spline_add_point( x2
, y2
);
1117 wx_spline_draw_point_array( this );