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
)
64 gc_private
= (GdkGCPrivate
*) gc
;
67 width
= src_private
->width
;
69 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
) );
148 void wxPaintDC::CrossHair( long x
, long y
)
152 if (m_pen
.GetStyle() != wxTRANSPARENT
)
157 long xx
= XLOG2DEV(x
);
158 long yy
= YLOG2DEV(y
);
159 gdk_draw_line( m_window
, m_penGC
,
160 0, yy
, XLOG2DEVREL(w
), yy
);
161 gdk_draw_line( m_window
, m_penGC
,
162 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
);
214 void wxPaintDC::DrawEllipticArc( long x
, long y
, long width
, long height
, double sa
, double ea
)
218 long xx
= XLOG2DEV(x
);
219 long yy
= YLOG2DEV(y
);
220 long ww
= m_signX
* XLOG2DEVREL(width
);
221 long hh
= m_signY
* YLOG2DEVREL(height
);
223 // CMB: handle -ve width and/or height
224 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
225 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
227 long start
= long(sa
* 64.0);
228 long end
= long(ea
* 64.0);
229 if (m_brush
.GetStyle() != wxTRANSPARENT
)
230 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, start
, end
);
232 if (m_pen
.GetStyle() != wxTRANSPARENT
)
233 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, start
, end
);
236 void wxPaintDC::DrawPoint( long x
, long y
)
240 if (m_pen
.GetStyle() != wxTRANSPARENT
)
241 gdk_draw_point( m_window
, m_penGC
, XLOG2DEV(x
), YLOG2DEV(y
) );
244 void wxPaintDC::DrawLines( int n
, wxPoint points
[], long xoffset
, long yoffset
)
248 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
250 for (int i
= 0; i
< n
-1; i
++)
252 long x1
= XLOG2DEV(points
[i
].x
+ xoffset
);
253 long x2
= XLOG2DEV(points
[i
+1].x
+ xoffset
);
254 long y1
= YLOG2DEV(points
[i
].y
+ yoffset
); // oh, what a waste
255 long y2
= YLOG2DEV(points
[i
+1].y
+ yoffset
);
256 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
260 void wxPaintDC::DrawLines( wxList
*points
, long xoffset
, long yoffset
)
264 if (m_pen
.GetStyle() == wxTRANSPARENT
) return;
266 wxNode
*node
= points
->First();
269 wxPoint
*point
= (wxPoint
*)node
->Data();
270 wxPoint
*npoint
= (wxPoint
*)node
->Next()->Data();
271 long x1
= XLOG2DEV(point
->x
+ xoffset
);
272 long x2
= XLOG2DEV(npoint
->x
+ xoffset
);
273 long y1
= YLOG2DEV(point
->y
+ yoffset
); // and again...
274 long y2
= YLOG2DEV(npoint
->y
+ yoffset
);
275 gdk_draw_line( m_window
, m_penGC
, x1
, y1
, x2
, y2
);
280 void wxPaintDC::DrawPolygon( int n
, wxPoint points
[], long xoffset
, long yoffset
, int WXUNUSED(fillStyle
) )
284 if (!n
) return; // Nothing to draw
285 GdkPoint
*gdkpoints
= new GdkPoint
[n
+1];
287 for (i
= 0 ; i
< n
; i
++)
289 gdkpoints
[i
].x
= XLOG2DEV(points
[i
].x
+ xoffset
);
290 gdkpoints
[i
].y
= YLOG2DEV(points
[i
].y
+ yoffset
);
292 if (m_brush
.GetStyle() != wxTRANSPARENT
)
293 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
295 if (m_pen
.GetStyle() != wxTRANSPARENT
)
296 for (i
= 0 ; i
< n
; i
++)
297 gdk_draw_line( m_window
, m_penGC
,
300 gdkpoints
[(i
+1)%n
].x
,
301 gdkpoints
[(i
+1)%n
].y
);
305 void wxPaintDC::DrawPolygon( wxList
*lines
, long xoffset
, long yoffset
, int WXUNUSED(fillStyle
))
309 int n
= lines
->Number();
310 GdkPoint
*gdkpoints
= new GdkPoint
[n
];
311 wxNode
*node
= lines
->First();
315 wxPoint
*p
= (wxPoint
*) node
->Data();
316 gdkpoints
[cnt
].x
= XLOG2DEV(p
->x
+ xoffset
);
317 gdkpoints
[cnt
].y
= YLOG2DEV(p
->y
+ yoffset
);
321 if (m_brush
.GetStyle() != wxTRANSPARENT
)
322 gdk_draw_polygon (m_window
, m_brushGC
, TRUE
, gdkpoints
, n
);
324 if (m_pen
.GetStyle() != wxTRANSPARENT
)
327 for (i
= 0 ; i
< n
; i
++)
328 gdk_draw_line( m_window
, m_penGC
,
331 gdkpoints
[(i
+1)%n
].x
,
332 gdkpoints
[(i
+1)%n
].y
);
337 void wxPaintDC::DrawRectangle( long x
, long y
, long width
, long height
)
341 long xx
= XLOG2DEV(x
);
342 long yy
= YLOG2DEV(y
);
343 long ww
= m_signX
* XLOG2DEVREL(width
);
344 long hh
= m_signY
* YLOG2DEVREL(height
);
346 // CMB: draw nothing if transformed w or h is 0
347 if (ww
== 0 || hh
== 0) return;
349 // CMB: handle -ve width and/or height
350 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
351 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
353 if (m_brush
.GetStyle() != wxTRANSPARENT
)
354 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
);
356 if (m_pen
.GetStyle() != wxTRANSPARENT
)
357 gdk_draw_rectangle( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
-1, hh
-1 );
360 void wxPaintDC::DrawRoundedRectangle( long x
, long y
, long width
, long height
, double radius
)
364 if (radius
< 0.0) radius
= - radius
* ((width
< height
) ? width
: height
);
366 long xx
= XLOG2DEV(x
);
367 long yy
= YLOG2DEV(y
);
368 long ww
= m_signX
* XLOG2DEVREL(width
);
369 long hh
= m_signY
* YLOG2DEVREL(height
);
370 long rr
= XLOG2DEVREL((long)radius
);
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 // CMB: if radius is zero use DrawRectangle() instead to avoid
377 // X drawing errors with small radii
380 DrawRectangle( x
, y
, width
, height
);
384 // CMB: draw nothing if transformed w or h is 0
385 if (ww
== 0 || hh
== 0) return;
387 // CMB: adjust size if outline is drawn otherwise the result is
388 // 1 pixel too wide and high
389 if (m_pen
.GetStyle() != wxTRANSPARENT
)
395 // CMB: ensure dd is not larger than rectangle otherwise we
396 // get an hour glass shape
398 if (dd
> ww
) dd
= ww
;
399 if (dd
> hh
) dd
= hh
;
402 if (m_brush
.GetStyle() != wxTRANSPARENT
)
404 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
+rr
, yy
, ww
-dd
+1, hh
);
405 gdk_draw_rectangle( m_window
, m_brushGC
, TRUE
, xx
, yy
+rr
, ww
, hh
-dd
+1 );
406 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
407 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
408 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
409 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
412 if (m_pen
.GetStyle() != wxTRANSPARENT
)
414 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
, xx
+ww
-rr
, yy
);
415 gdk_draw_line( m_window
, m_penGC
, xx
+rr
, yy
+hh
, xx
+ww
-rr
, yy
+hh
);
416 gdk_draw_line( m_window
, m_penGC
, xx
, yy
+rr
, xx
, yy
+hh
-rr
);
417 gdk_draw_line( m_window
, m_penGC
, xx
+ww
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
418 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, dd
, dd
, 90*64, 90*64 );
419 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
, dd
, dd
, 0, 90*64 );
420 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
+ww
-dd
, yy
+hh
-dd
, dd
, dd
, 270*64, 90*64 );
421 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
+hh
-dd
, dd
, dd
, 180*64, 90*64 );
425 void wxPaintDC::DrawEllipse( long x
, long y
, long width
, long height
)
429 long xx
= XLOG2DEV(x
);
430 long yy
= YLOG2DEV(y
);
431 long ww
= m_signX
* XLOG2DEVREL(width
);
432 long hh
= m_signY
* YLOG2DEVREL(height
);
434 // CMB: handle -ve width and/or height
435 if (ww
< 0) { ww
= -ww
; xx
= xx
- ww
; }
436 if (hh
< 0) { hh
= -hh
; yy
= yy
- hh
; }
438 if (m_brush
.GetStyle() != wxTRANSPARENT
)
439 gdk_draw_arc( m_window
, m_brushGC
, TRUE
, xx
, yy
, ww
, hh
, 0, 360*64 );
441 if (m_pen
.GetStyle() != wxTRANSPARENT
)
442 gdk_draw_arc( m_window
, m_penGC
, FALSE
, xx
, yy
, ww
, hh
, 0, 360*64 );
445 bool wxPaintDC::CanDrawBitmap(void) const
450 void wxPaintDC::DrawIcon( const wxIcon
&icon
, long x
, long y
, bool useMask
)
454 if (!icon
.Ok()) return;
456 int xx
= XLOG2DEV(x
);
457 int yy
= YLOG2DEV(y
);
459 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
460 if (icon
.GetMask()) mask
= icon
.GetMask()->GetBitmap();
464 gdk_gc_set_clip_mask( m_penGC
, mask
);
465 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
468 GdkPixmap
*pm
= icon
.GetPixmap();
469 gdk_draw_pixmap( m_window
, m_penGC
, pm
, 0, 0, xx
, yy
, -1, -1 );
473 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
474 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
478 bool wxPaintDC::Blit( long xdest
, long ydest
, long width
, long height
,
479 wxDC
*source
, long xsrc
, long ysrc
, int WXUNUSED(logical_func
), bool useMask
)
481 if (!Ok()) return FALSE
;
483 wxClientDC
*csrc
= (wxClientDC
*)source
;
487 wxMemoryDC
* srcDC
= (wxMemoryDC
*)source
;
488 GdkPixmap
* bmap
= srcDC
->m_selected
.GetPixmap();
491 long xx
= XLOG2DEV(xdest
);
492 long yy
= YLOG2DEV(ydest
);
494 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
495 if (srcDC
->m_selected
.GetMask()) mask
= srcDC
->m_selected
.GetMask()->GetBitmap();
499 gdk_gc_set_clip_mask( m_penGC
, mask
);
500 gdk_gc_set_clip_origin( m_penGC
, xx
, yy
);
503 gdk_draw_pixmap( m_window
, m_penGC
, bmap
,
504 source
->DeviceToLogicalX(xsrc
),
505 source
->DeviceToLogicalY(ysrc
),
508 source
->DeviceToLogicalXRel(width
),
509 source
->DeviceToLogicalYRel(height
) );
513 gdk_gc_set_clip_mask( m_penGC
, (GdkBitmap
*) NULL
);
514 gdk_gc_set_clip_origin( m_penGC
, 0, 0 );
521 gdk_window_copy_area ( m_window
, m_penGC
,
522 XLOG2DEV(xdest
), YLOG2DEV(ydest
),
524 source
->DeviceToLogicalX(xsrc
), source
->DeviceToLogicalY(ysrc
),
525 source
->DeviceToLogicalXRel(width
), source
->DeviceToLogicalYRel(height
) );
528 gdk_window_copy_area ( m_window, m_penGC,
529 XLOG2DEV(xdest), YLOG2DEV(ydest),
538 void wxPaintDC::DrawText( const wxString
&text
, long x
, long y
, bool WXUNUSED(use16
) )
542 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
547 // CMB 21/5/98: draw text background if mode is wxSOLID
548 if (m_backgroundMode
== wxSOLID
)
550 long width
= gdk_string_width( font
, text
);
551 long height
= font
->ascent
+ font
->descent
;
552 gdk_gc_set_foreground( m_textGC
, m_textBackgroundColour
.GetColor() );
553 gdk_draw_rectangle( m_window
, m_textGC
, TRUE
, x
, y
, width
, height
);
554 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
556 gdk_draw_string( m_window
, font
, m_textGC
, x
, y
+ font
->ascent
, text
);
558 // CMB 17/7/98: simple underline: ignores scaling and underlying
559 // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS
560 // properties (see wxXt implementation)
561 if (m_font
.GetUnderlined())
563 long width
= gdk_string_width( font
, text
);
564 long ul_y
= y
+ font
->ascent
;
565 if (font
->descent
> 0) ul_y
++;
566 gdk_draw_line( m_window
, m_textGC
, x
, ul_y
, x
+ width
, ul_y
);
570 bool wxPaintDC::CanGetTextExtent(void) const
575 void wxPaintDC::GetTextExtent( const wxString
&string
, long *width
, long *height
,
576 long *descent
, long *externalLeading
,
577 wxFont
*theFont
, bool WXUNUSED(use16
) )
581 wxFont fontToUse
= m_font
;
582 if (theFont
) fontToUse
= *theFont
;
584 GdkFont
*font
= fontToUse
.GetInternalFont( m_scaleY
);
585 if (width
) (*width
) = long(gdk_string_width( font
, string
) / m_scaleX
);
586 if (height
) (*height
) = long((font
->ascent
+ font
->descent
) / m_scaleY
);
587 if (descent
) (*descent
) = long(font
->descent
/ m_scaleY
);
588 if (externalLeading
) (*externalLeading
) = 0; // ??
591 long wxPaintDC::GetCharWidth(void)
595 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
596 return long(gdk_string_width( font
, "H" ) / m_scaleX
);
599 long wxPaintDC::GetCharHeight(void)
603 GdkFont
*font
= m_font
.GetInternalFont( m_scaleY
);
604 return long((font
->ascent
+ font
->descent
) / m_scaleY
);
607 void wxPaintDC::Clear(void)
613 gdk_window_clear( m_window
);
619 GetSize( &width
, &height
);
620 gdk_draw_rectangle( m_window
, m_bgGC
, TRUE
, 0, 0, width
, height
);
624 void wxPaintDC::SetFont( const wxFont
&font
)
631 void wxPaintDC::SetPen( const wxPen
&pen
)
635 if (m_pen
== pen
) return;
639 if (!m_pen
.Ok()) return;
641 gint width
= m_pen
.GetWidth();
642 // CMB: if width is non-zero scale it with the dc
649 // X doesn't allow different width in x and y and so we take
651 double w
= 0.5 + (abs(XLOG2DEVREL(width
)) + abs(YLOG2DEVREL(width
))) / 2.0;
655 GdkLineStyle lineStyle
= GDK_LINE_SOLID
;
656 switch (m_pen
.GetStyle())
658 case wxSOLID
: { lineStyle
= GDK_LINE_SOLID
; break; }
659 case wxDOT
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
660 case wxLONG_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
661 case wxSHORT_DASH
: { lineStyle
= GDK_LINE_ON_OFF_DASH
; break; }
662 case wxDOT_DASH
: { lineStyle
= GDK_LINE_DOUBLE_DASH
; break; }
665 GdkCapStyle capStyle
= GDK_CAP_ROUND
;
666 switch (m_pen
.GetCap())
668 case wxCAP_ROUND
: { capStyle
= (width
<= 1) ? GDK_CAP_NOT_LAST
: GDK_CAP_ROUND
; break; }
669 case wxCAP_PROJECTING
: { capStyle
= GDK_CAP_PROJECTING
; break; }
670 case wxCAP_BUTT
: { capStyle
= GDK_CAP_BUTT
; break; }
673 GdkJoinStyle joinStyle
= GDK_JOIN_ROUND
;
674 switch (m_pen
.GetJoin())
676 case wxJOIN_BEVEL
: { joinStyle
= GDK_JOIN_BEVEL
; break; }
677 case wxJOIN_ROUND
: { joinStyle
= GDK_JOIN_ROUND
; break; }
678 case wxJOIN_MITER
: { joinStyle
= GDK_JOIN_MITER
; break; }
681 gdk_gc_set_line_attributes( m_penGC
, width
, lineStyle
, capStyle
, joinStyle
);
683 m_pen
.GetColour().CalcPixel( m_cmap
);
684 gdk_gc_set_foreground( m_penGC
, m_pen
.GetColour().GetColor() );
687 void wxPaintDC::SetBrush( const wxBrush
&brush
)
691 if (m_brush
== brush
) return;
695 if (!m_brush
.Ok()) return;
697 m_brush
.GetColour().CalcPixel( m_cmap
);
698 gdk_gc_set_foreground( m_brushGC
, m_brush
.GetColour().GetColor() );
700 GdkFill fillStyle
= GDK_SOLID
;
701 switch (m_brush
.GetStyle())
707 fillStyle
= GDK_STIPPLED
;
710 gdk_gc_set_fill( m_brushGC
, fillStyle
);
712 if (m_brush
.GetStyle() == wxSTIPPLE
)
714 gdk_gc_set_stipple( m_brushGC
, m_brush
.GetStipple()->GetPixmap() );
717 if (IS_HATCH(m_brush
.GetStyle()))
719 int num
= m_brush
.GetStyle() - wxBDIAGONAL_HATCH
;
720 gdk_gc_set_stipple( m_brushGC
, hatches
[num
] );
724 // CMB 21/7/98: Added SetBackground. Sets background brush
725 // for Clear() and bg colour for shapes filled with cross-hatch brush
726 void wxPaintDC::SetBackground( const wxBrush
&brush
)
730 if (m_backgroundBrush
== brush
) return;
732 m_backgroundBrush
= brush
;
734 if (!m_backgroundBrush
.Ok()) return;
736 m_backgroundBrush
.GetColour().CalcPixel( m_cmap
);
737 gdk_gc_set_background( m_brushGC
, m_backgroundBrush
.GetColour().GetColor() );
738 gdk_gc_set_foreground( m_bgGC
, m_backgroundBrush
.GetColour().GetColor() );
740 GdkFill fillStyle
= GDK_SOLID
;
741 switch (m_backgroundBrush
.GetStyle())
747 fillStyle
= GDK_STIPPLED
;
750 gdk_gc_set_fill( m_bgGC
, fillStyle
);
752 if (m_backgroundBrush
.GetStyle() == wxSTIPPLE
)
754 gdk_gc_set_stipple( m_bgGC
, m_backgroundBrush
.GetStipple()->GetPixmap() );
757 if (IS_HATCH(m_backgroundBrush
.GetStyle()))
759 int num
= m_backgroundBrush
.GetStyle() - wxBDIAGONAL_HATCH
;
760 gdk_gc_set_stipple( m_bgGC
, hatches
[num
] );
764 void wxPaintDC::SetLogicalFunction( int function
)
766 if (m_logicalFunction
== function
) return;
767 GdkFunction mode
= GDK_COPY
;
770 case wxXOR
: mode
= GDK_INVERT
; break;
771 case wxINVERT
: mode
= GDK_INVERT
; break;
774 m_logicalFunction
= function
;
775 gdk_gc_set_function( m_penGC
, mode
);
776 gdk_gc_set_function( m_brushGC
, mode
);
779 void wxPaintDC::SetTextForeground( const wxColour
&col
)
783 if (m_textForegroundColour
== col
) return;
785 m_textForegroundColour
= col
;
786 if (!m_textForegroundColour
.Ok()) return;
788 m_textForegroundColour
.CalcPixel( m_cmap
);
789 gdk_gc_set_foreground( m_textGC
, m_textForegroundColour
.GetColor() );
792 void wxPaintDC::SetTextBackground( const wxColour
&col
)
796 if (m_textBackgroundColour
== col
) return;
798 m_textBackgroundColour
= col
;
799 if (!m_textBackgroundColour
.Ok()) return;
801 m_textBackgroundColour
.CalcPixel( m_cmap
);
802 gdk_gc_set_background( m_textGC
, m_textBackgroundColour
.GetColor() );
805 void wxPaintDC::SetBackgroundMode( int mode
)
807 m_backgroundMode
= mode
;
809 // CMB 21/7/98: fill style of cross-hatch brushes is affected by
810 // transparent/solid background mode
811 if (m_brush
.GetStyle() != wxSOLID
&& m_brush
.GetStyle() != wxTRANSPARENT
)
813 gdk_gc_set_fill( m_brushGC
,
814 (m_backgroundMode
== wxTRANSPARENT
) ? GDK_STIPPLED
: GDK_OPAQUE_STIPPLED
);
818 void wxPaintDC::SetPalette( const wxPalette
& WXUNUSED(palette
) )
822 void wxPaintDC::SetClippingRegion( long x
, long y
, long width
, long height
)
824 wxDC::SetClippingRegion( x
, y
, width
, height
);
827 rect
.x
= XLOG2DEV(x
);
828 rect
.y
= YLOG2DEV(y
);
829 rect
.width
= XLOG2DEVREL(width
);
830 rect
.height
= YLOG2DEVREL(height
);
831 gdk_gc_set_clip_rectangle( m_penGC
, &rect
);
832 gdk_gc_set_clip_rectangle( m_brushGC
, &rect
);
833 gdk_gc_set_clip_rectangle( m_textGC
, &rect
);
834 gdk_gc_set_clip_rectangle( m_bgGC
, &rect
);
838 void wxPaintDC::DestroyClippingRegion(void)
840 wxDC::DestroyClippingRegion();
842 gdk_gc_set_clip_rectangle( m_penGC
, (GdkRectangle
*) NULL
);
843 gdk_gc_set_clip_rectangle( m_brushGC
, (GdkRectangle
*) NULL
);
844 gdk_gc_set_clip_rectangle( m_textGC
, (GdkRectangle
*) NULL
);
845 gdk_gc_set_clip_rectangle( m_bgGC
, (GdkRectangle
*) NULL
);
848 void wxPaintDC::SetUpDC(void)
852 m_logicalFunction
= wxCOPY
;
853 m_penGC
= gdk_gc_new( m_window
);
854 m_brushGC
= gdk_gc_new( m_window
);
855 m_textGC
= gdk_gc_new( m_window
);
856 m_bgGC
= gdk_gc_new( m_window
);
857 SetTextForeground( m_textForegroundColour
);
858 SetTextBackground( m_textBackgroundColour
);
863 gdk_gc_set_background( m_penGC
, wxWHITE
->GetColor() );
867 hatch_bitmap
= hatches
;
868 hatch_bitmap
[0] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, bdiag_bits
, bdiag_width
, bdiag_height
);
869 hatch_bitmap
[1] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cdiag_bits
, cdiag_width
, cdiag_height
);
870 hatch_bitmap
[2] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, fdiag_bits
, fdiag_width
, fdiag_height
);
871 hatch_bitmap
[3] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, cross_bits
, cross_width
, cross_height
);
872 hatch_bitmap
[4] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, horiz_bits
, horiz_width
, horiz_height
);
873 hatch_bitmap
[5] = gdk_bitmap_create_from_data( (GdkWindow
*) NULL
, verti_bits
, verti_width
, verti_height
);
877 void wxPaintDC::Destroy(void)
879 if (m_penGC
) gdk_gc_unref( m_penGC
);
880 m_penGC
= (GdkGC
*) NULL
;
881 if (m_brushGC
) gdk_gc_unref( m_brushGC
);
882 m_brushGC
= (GdkGC
*) NULL
;
883 if (m_textGC
) gdk_gc_unref( m_textGC
);
884 m_textGC
= (GdkGC
*) NULL
;
885 if (m_bgGC
) gdk_gc_unref( m_bgGC
);
886 m_bgGC
= (GdkGC
*) NULL
;
889 GdkWindow
*wxPaintDC::GetWindow(void)
894 // ----------------------------------- spline code ----------------------------------------
896 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
,
897 double a3
, double b3
, double a4
, double b4
);
898 void wx_clear_stack(void);
899 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
, double *x3
,
900 double *y3
, double *x4
, double *y4
);
901 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
,
902 double x4
, double y4
);
903 static bool wx_spline_add_point(double x
, double y
);
904 static void wx_spline_draw_point_array(wxDC
*dc
);
906 wxList wx_spline_point_list
;
908 #define half(z1, z2) ((z1+z2)/2.0)
911 /* iterative version */
913 void wx_quadratic_spline(double a1
, double b1
, double a2
, double b2
, double a3
, double b3
, double a4
,
916 register double xmid
, ymid
;
917 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
920 wx_spline_push(a1
, b1
, a2
, b2
, a3
, b3
, a4
, b4
);
922 while (wx_spline_pop(&x1
, &y1
, &x2
, &y2
, &x3
, &y3
, &x4
, &y4
)) {
923 xmid
= (double)half(x2
, x3
);
924 ymid
= (double)half(y2
, y3
);
925 if (fabs(x1
- xmid
) < THRESHOLD
&& fabs(y1
- ymid
) < THRESHOLD
&&
926 fabs(xmid
- x4
) < THRESHOLD
&& fabs(ymid
- y4
) < THRESHOLD
) {
927 wx_spline_add_point( x1
, y1
);
928 wx_spline_add_point( xmid
, ymid
);
930 wx_spline_push(xmid
, ymid
, (double)half(xmid
, x3
), (double)half(ymid
, y3
),
931 (double)half(x3
, x4
), (double)half(y3
, y4
), x4
, y4
);
932 wx_spline_push(x1
, y1
, (double)half(x1
, x2
), (double)half(y1
, y2
),
933 (double)half(x2
, xmid
), (double)half(y2
, ymid
), xmid
, ymid
);
938 /* utilities used by spline drawing routines */
940 typedef struct wx_spline_stack_struct
{
941 double x1
, y1
, x2
, y2
, x3
, y3
, x4
, y4
;
944 #define SPLINE_STACK_DEPTH 20
945 static Stack wx_spline_stack
[SPLINE_STACK_DEPTH
];
946 static Stack
*wx_stack_top
;
947 static int wx_stack_count
;
949 void wx_clear_stack(void)
951 wx_stack_top
= wx_spline_stack
;
955 void wx_spline_push(double x1
, double y1
, double x2
, double y2
, double x3
, double y3
, double x4
, double y4
)
957 wx_stack_top
->x1
= x1
;
958 wx_stack_top
->y1
= y1
;
959 wx_stack_top
->x2
= x2
;
960 wx_stack_top
->y2
= y2
;
961 wx_stack_top
->x3
= x3
;
962 wx_stack_top
->y3
= y3
;
963 wx_stack_top
->x4
= x4
;
964 wx_stack_top
->y4
= y4
;
969 int wx_spline_pop(double *x1
, double *y1
, double *x2
, double *y2
,
970 double *x3
, double *y3
, double *x4
, double *y4
)
972 if (wx_stack_count
== 0)
976 *x1
= wx_stack_top
->x1
;
977 *y1
= wx_stack_top
->y1
;
978 *x2
= wx_stack_top
->x2
;
979 *y2
= wx_stack_top
->y2
;
980 *x3
= wx_stack_top
->x3
;
981 *y3
= wx_stack_top
->y3
;
982 *x4
= wx_stack_top
->x4
;
983 *y4
= wx_stack_top
->y4
;
987 static bool wx_spline_add_point(double x
, double y
)
989 wxPoint
*point
= new wxPoint
;
992 wx_spline_point_list
.Append((wxObject
*)point
);
996 static void wx_spline_draw_point_array(wxDC
*dc
)
998 dc
->DrawLines(&wx_spline_point_list
, 0, 0 );
999 wxNode
*node
= wx_spline_point_list
.First();
1002 wxPoint
*point
= (wxPoint
*)node
->Data();
1005 node
= wx_spline_point_list
.First();
1009 void wxPaintDC::DrawSpline( wxList
*points
)
1012 double cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
;
1013 double x1
, y1
, x2
, y2
;
1015 wxNode
*node
= points
->First();
1016 p
= (wxPoint
*)node
->Data();
1021 node
= node
->Next();
1022 p
= (wxPoint
*)node
->Data();
1026 cx1
= (double)((x1
+ x2
) / 2);
1027 cy1
= (double)((y1
+ y2
) / 2);
1028 cx2
= (double)((cx1
+ x2
) / 2);
1029 cy2
= (double)((cy1
+ y2
) / 2);
1031 wx_spline_add_point(x1
, y1
);
1033 while ((node
= node
->Next()) != NULL
)
1035 p
= (wxPoint
*)node
->Data();
1040 cx4
= (double)(x1
+ x2
) / 2;
1041 cy4
= (double)(y1
+ y2
) / 2;
1042 cx3
= (double)(x1
+ cx4
) / 2;
1043 cy3
= (double)(y1
+ cy4
) / 2;
1045 wx_quadratic_spline(cx1
, cy1
, cx2
, cy2
, cx3
, cy3
, cx4
, cy4
);
1049 cx2
= (double)(cx1
+ x2
) / 2;
1050 cy2
= (double)(cy1
+ y2
) / 2;
1053 wx_spline_add_point( cx1
, cy1
);
1054 wx_spline_add_point( x2
, y2
);
1056 wx_spline_draw_point_array( this );