]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/dc.mm
fixed export of hex values
[wxWidgets.git] / src / cocoa / dc.mm
CommitLineData
a24aff65 1/////////////////////////////////////////////////////////////////////////////
891d0563
DE
2// Name: src/cocoa/dc.mm
3// Purpose: wxDC
4// Author: David Elliott
a24aff65 5// Modified by:
891d0563 6// Created: 2003/04/01
a24aff65 7// RCS-ID: $Id$
891d0563 8// Copyright: (c) 2003 David Elliott
065e208e 9// Licence: wxWidgets licence
a24aff65
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673
DE
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14 #include "wx/log.h"
15 #include "wx/dc.h"
16#endif //WX_PRECOMP
a24aff65 17
7fc77f30 18#include "wx/cocoa/autorelease.h"
b0c0a393 19#include "wx/cocoa/string.h"
7fc77f30 20
891d0563
DE
21#import <AppKit/NSBezierPath.h>
22#import <AppKit/NSTextStorage.h>
23#import <AppKit/NSLayoutManager.h>
24#import <AppKit/NSTextContainer.h>
25#import <AppKit/NSGraphicsContext.h>
26#import <AppKit/NSAffineTransform.h>
27#import <AppKit/NSColor.h>
f910a887 28#import <AppKit/NSTypesetter.h>
1fd17880 29#import <AppKit/NSImage.h>
891d0563 30
d8418952 31#include "wx/listimpl.cpp"
fe8f7943
DE
32WX_DEFINE_LIST(wxCocoaDCStack);
33
a24aff65 34IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
891d0563
DE
35WX_NSTextStorage wxDC::sm_cocoaNSTextStorage = nil;
36WX_NSLayoutManager wxDC::sm_cocoaNSLayoutManager = nil;
37WX_NSTextContainer wxDC::sm_cocoaNSTextContainer = nil;
fe8f7943 38wxCocoaDCStack wxDC::sm_cocoaDCStack;
891d0563 39
5eb5a0ac
DE
40inline void CocoaSetPenForNSBezierPath(wxPen &pen, NSBezierPath *bezpath)
41{
42 [pen.GetNSColor() set];
43 const float *pattern;
44 [bezpath setLineDash:pattern count:pen.GetCocoaLineDash(&pattern) phase:0.0];
45 [bezpath setLineWidth:pen.GetWidth()];
46 switch(pen.GetJoin())
47 {
48 case wxJOIN_BEVEL:
49 [bezpath setLineJoinStyle:NSBevelLineJoinStyle];
50 break;
51 case wxJOIN_ROUND:
52 [bezpath setLineJoinStyle:NSRoundLineJoinStyle];
53 break;
54 case wxJOIN_MITER:
55 [bezpath setLineJoinStyle:NSMiterLineJoinStyle];
56 break;
57 }
58 switch(pen.GetCap())
59 {
60 case wxCAP_ROUND:
61 [bezpath setLineCapStyle:NSRoundLineCapStyle];
62 break;
63 case wxCAP_PROJECTING:
64 [bezpath setLineCapStyle:NSSquareLineCapStyle];
65 break;
66 case wxCAP_BUTT:
67 [bezpath setLineCapStyle:NSButtLineCapStyle];
68 break;
69 }
70}
71
891d0563
DE
72void wxDC::CocoaInitializeTextSystem()
73{
2b030203 74 wxASSERT_MSG(!sm_cocoaNSTextStorage && !sm_cocoaNSLayoutManager && !sm_cocoaNSTextContainer,wxT("Text system already initalized! BAD PROGRAMMER!"));
891d0563
DE
75
76 sm_cocoaNSTextStorage = [[NSTextStorage alloc] init];
77
78 sm_cocoaNSLayoutManager = [[NSLayoutManager alloc] init];
79 [sm_cocoaNSTextStorage addLayoutManager:sm_cocoaNSLayoutManager];
80 // NSTextStorage retains NSLayoutManager, but so do we
81 // [sm_cocoaNSLayoutManager release]; [sm_cocoaNSLayoutManager retain];
82
83 // NOTE: initWithContainerSize is the designated initializer, but the
84 // Apple CircleView sample gets away with just calling init, which
85 // is all we really need for our purposes.
86 sm_cocoaNSTextContainer = [[NSTextContainer alloc] init];
87 [sm_cocoaNSLayoutManager addTextContainer:sm_cocoaNSTextContainer];
88 // NSLayoutManager retains NSTextContainer, but so do we
89 // [sm_cocoaNSTextContainer release]; [sm_cocoaNSTextContainer retain];
90}
91
92void wxDC::CocoaShutdownTextSystem()
93{
94 [sm_cocoaNSTextContainer release]; sm_cocoaNSTextContainer = nil;
95 [sm_cocoaNSLayoutManager release]; sm_cocoaNSLayoutManager = nil;
96 [sm_cocoaNSTextStorage release]; sm_cocoaNSTextStorage = nil;
97}
98
fe8f7943
DE
99void wxDC::CocoaUnwindStackAndLoseFocus()
100{
7ce8248b 101 wxCocoaDCStack::compatibility_iterator ourNode=sm_cocoaDCStack.Find(this);
fe8f7943
DE
102 if(ourNode)
103 {
7ce8248b 104 wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst();
fe8f7943
DE
105 for(;node!=ourNode; node=sm_cocoaDCStack.GetFirst())
106 {
107 wxDC *dc = node->GetData();
108 wxASSERT(dc);
109 wxASSERT(dc!=this);
110 if(!dc->CocoaUnlockFocus())
111 {
2b030203 112 wxFAIL_MSG(wxT("Unable to unlock focus on higher-level DC!"));
fe8f7943 113 }
7ce8248b 114 sm_cocoaDCStack.Erase(node);
fe8f7943
DE
115 }
116 wxASSERT(node==ourNode);
117 wxASSERT(ourNode->GetData() == this);
118 ourNode->GetData()->CocoaUnlockFocus();
7ce8248b 119 sm_cocoaDCStack.Erase(ourNode);
fe8f7943
DE
120 }
121}
122
123bool wxDC::CocoaUnwindStackAndTakeFocus()
124{
7ce8248b 125 wxCocoaDCStack::compatibility_iterator node=sm_cocoaDCStack.GetFirst();
fe8f7943
DE
126 for(;node;node = sm_cocoaDCStack.GetFirst())
127 {
128 wxDC *dc = node->GetData();
129 wxASSERT(dc);
130 // If we're on the stack, then it's unwound enough and we have focus
131 if(dc==this)
132 return true;
133 // If unable to unlockFocus (e.g. wxPaintDC) stop here
134 if(!dc->CocoaUnlockFocus())
135 break;
7ce8248b 136 sm_cocoaDCStack.Erase(node);
fe8f7943
DE
137 }
138 return CocoaLockFocus();
139}
140
891d0563
DE
141wxDC::wxDC(void)
142{
db8512fe 143 m_cocoaWxToBoundsTransform = nil;
5eb5a0ac 144 m_pen = *wxBLACK_PEN;
891d0563
DE
145}
146
147wxDC::~wxDC(void)
148{
149}
150
fe8f7943
DE
151bool wxDC::CocoaLockFocus()
152{
153 return false;
154}
155
156bool wxDC::CocoaUnlockFocus()
157{
158 return false;
159}
160
4db3c8ac 161/*static*/ WX_NSAffineTransform wxDC::CocoaGetWxToBoundsTransform(bool isFlipped, float height)
fe8f7943 162{
4db3c8ac 163 NSAffineTransform *transform = nil;
fe8f7943 164 // This transform flips the graphics since wxDC uses top-left origin
4db3c8ac 165 if(!isFlipped)
fe8f7943
DE
166 {
167 // The transform is auto released
4db3c8ac 168 transform = [NSAffineTransform transform];
fe8f7943
DE
169 /* x' = 1x + 0y + 0
170 y' = 0x + -1y + window's height
171 */
172 NSAffineTransformStruct matrix = {
173 1, 0
174 , 0, -1
4db3c8ac 175 , 0, height
fe8f7943
DE
176 };
177 [transform setTransformStruct: matrix];
fe8f7943 178 }
4db3c8ac
DE
179 return transform;
180}
181
182void wxDC::CocoaApplyTransformations()
183{
184 [m_cocoaWxToBoundsTransform concat];
185 // TODO: Apply device/logical/user position/scaling transformations
fe8f7943
DE
186}
187
891d0563
DE
188void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
189{
1b1f8b2d 190 wxAutoNSAutoreleasePool pool;
fe8f7943 191 if(!CocoaTakeFocus()) return;
891d0563 192 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,width,height)];
5eb5a0ac 193 CocoaSetPenForNSBezierPath(m_pen,bezpath);
891d0563 194 [bezpath stroke];
c3b0c2c3
DE
195 [m_brush.GetNSColor() set];
196 [bezpath fill];
891d0563
DE
197}
198
199void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
200{
1b1f8b2d 201 wxAutoNSAutoreleasePool pool;
fe8f7943 202 if(!CocoaTakeFocus()) return;
891d0563
DE
203 NSBezierPath *bezpath = [NSBezierPath bezierPath];
204 [bezpath moveToPoint:NSMakePoint(x1,y1)];
205 [bezpath lineToPoint:NSMakePoint(x2,y2)];
c3b0c2c3 206
5eb5a0ac 207 CocoaSetPenForNSBezierPath(m_pen,bezpath);
891d0563
DE
208 [bezpath stroke];
209}
210
211void wxDC::DoGetTextExtent(const wxString& text, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, wxFont *theFont) const
212{
7fc77f30 213 wxAutoNSAutoreleasePool pool;
891d0563 214// FIXME: Cache this so it can be used for DoDrawText
2b030203 215 wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!"));
891d0563 216 NSAttributedString *attributedString = [[NSAttributedString alloc]
b0c0a393 217 initWithString:wxNSStringWithWxString(text.c_str())];
891d0563
DE
218 [sm_cocoaNSTextStorage setAttributedString:attributedString];
219 [attributedString release];
220
221 NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer];
222 NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer];
223 if(x)
dc483f61 224 *x=(int)usedRect.size.width;
891d0563 225 if(y)
dc483f61 226 *y=(int)usedRect.size.height;
891d0563
DE
227 if(descent)
228 *descent=0;
229 if(externalLeading)
230 *externalLeading=0;
231}
232
233void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
234{
1b1f8b2d 235 wxAutoNSAutoreleasePool pool;
fe8f7943 236 if(!CocoaTakeFocus()) return;
2b030203 237 wxASSERT_MSG(sm_cocoaNSTextStorage && sm_cocoaNSLayoutManager && sm_cocoaNSTextContainer, wxT("Text system has not been initialized. BAD PROGRAMMER!"));
891d0563 238 NSAttributedString *attributedString = [[NSAttributedString alloc]
b0c0a393 239 initWithString:wxNSStringWithWxString(text.c_str())];
891d0563
DE
240 [sm_cocoaNSTextStorage setAttributedString:attributedString];
241 [attributedString release];
242
c0440c78
DE
243 // Set the color (and later font) attributes
244 NSColor *fgColor = m_textForegroundColour.GetNSColor();
245 NSColor *bgColor = m_textBackgroundColour.GetNSColor();
246 if(!fgColor)
247 fgColor = [NSColor clearColor];
248 if(!bgColor)
249 bgColor = [NSColor clearColor];
250 NSDictionary *attrDict = [[NSDictionary alloc] initWithObjectsAndKeys:
251 fgColor, NSForegroundColorAttributeName,
252 bgColor, NSBackgroundColorAttributeName,
253 nil];
254 [sm_cocoaNSTextStorage addAttributes: attrDict range:NSMakeRange(0,[sm_cocoaNSTextStorage length])];
255 [attrDict release];
256
891d0563
DE
257 NSRange glyphRange = [sm_cocoaNSLayoutManager glyphRangeForTextContainer:sm_cocoaNSTextContainer];
258 NSRect usedRect = [sm_cocoaNSLayoutManager usedRectForTextContainer:sm_cocoaNSTextContainer];
13fc3db4
DE
259 // NOTE: We'll crash trying to get the location of glyphAtIndex:0 if
260 // there is no length or we don't start at zero
261 if(!glyphRange.length)
262 return;
2b030203 263 wxASSERT_MSG(glyphRange.location==0,wxT("glyphRange must begin at zero"));
891d0563
DE
264
265 NSAffineTransform *transform = [NSAffineTransform transform];
266 [transform translateXBy:x yBy:y];
267
268 NSAffineTransform *flipTransform = [NSAffineTransform transform];
269 /* x' = 1x + 0y + 0
270 y' = 0x + -1y + window's height
271 */
272 NSAffineTransformStruct matrix = {
273 1, 0
274 , 0, -1
275 , 0, usedRect.size.height
276 };
277 [flipTransform setTransformStruct: matrix];
278
279 NSGraphicsContext *context = [NSGraphicsContext currentContext];
280 [context saveGraphicsState];
281 [transform concat];
282 [flipTransform concat];
c3b0c2c3 283 #if 0
891d0563 284 // Draw+fill a rectangle so we can see where the shit is supposed to be.
48580976 285 wxLogTrace(wxTRACE_COCOA,wxT("(%f,%f) (%fx%f)"),usedRect.origin.x,usedRect.origin.y,usedRect.size.width,usedRect.size.height);
891d0563
DE
286 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(0,0,usedRect.size.width,usedRect.size.height)];
287 [[NSColor blackColor] set];
288 [bezpath stroke];
289 [[NSColor blueColor] set];
290 [bezpath fill];
c3b0c2c3 291 #endif
891d0563
DE
292
293 NSPoint layoutLocation = [sm_cocoaNSLayoutManager locationForGlyphAtIndex:0];
294 layoutLocation.x = 0.0;
295 layoutLocation.y *= -1.0;
296 layoutLocation.y += [[sm_cocoaNSLayoutManager typesetter] baselineOffsetInLayoutManager:sm_cocoaNSLayoutManager glyphIndex:0];
c0440c78
DE
297 if(m_backgroundMode==wxSOLID)
298 [sm_cocoaNSLayoutManager drawBackgroundForGlyphRange:glyphRange atPoint:NSZeroPoint];
891d0563
DE
299 [sm_cocoaNSLayoutManager drawGlyphsForGlyphRange:glyphRange atPoint:layoutLocation];
300
301 [context restoreGraphicsState];
302}
303
2894667f
DE
304// wxDCBase functions
305int wxDCBase::DeviceToLogicalX(int x) const
306{
307 return x;
308}
309
310int wxDCBase::DeviceToLogicalY(int y) const
311{
312 return y;
313}
314
276a1256
DE
315int wxDCBase::DeviceToLogicalXRel(int x) const
316{
317 return x;
318}
319
320int wxDCBase::DeviceToLogicalYRel(int y) const
321{
322 return y;
323}
324
2894667f
DE
325int wxDCBase::LogicalToDeviceX(int x) const
326{
327 return x;
328}
329
330int wxDCBase::LogicalToDeviceY(int y) const
331{
332 return y;
333}
334
276a1256
DE
335int wxDCBase::LogicalToDeviceXRel(int x) const
336{
337 return x;
338}
339
340int wxDCBase::LogicalToDeviceYRel(int y) const
341{
342 return y;
343}
344
891d0563
DE
345///////////////////////////////////////////////////////////////////////////
346// cut here, the rest is stubs
347///////////////////////////////////////////////////////////////////////////
a24aff65
DE
348
349//-----------------------------------------------------------------------------
350// constants
351//-----------------------------------------------------------------------------
352
353#define mm2inches 0.0393700787402
354#define inches2mm 25.4
355#define mm2twips 56.6929133859
356#define twips2mm 0.0176388888889
357#define mm2pt 2.83464566929
358#define pt2mm 0.352777777778
359
360//-----------------------------------------------------------------------------
361// wxDC
362//-----------------------------------------------------------------------------
363
a24aff65
DE
364void wxDC::DoDrawIcon( const wxIcon &WXUNUSED(icon), int WXUNUSED(x), int WXUNUSED(y) )
365{
366};
367
368void wxDC::DoDrawPoint( int x, int y )
369{
370};
371
372void wxDC::DoDrawPolygon( int, wxPoint *, int, int, int)
373{
374};
375
376void wxDC::DoDrawLines( int, wxPoint *, int, int )
377{
378}
379
a24aff65
DE
380int wxDC::GetDepth() const
381{
382 return 0;
383}
384
385wxSize wxDC::GetPPI() const
386{
387 return wxSize(0,0);
388}
389
390bool wxDC::CanGetTextExtent() const
391{
392 return false;
393}
394
a24aff65
DE
395wxCoord wxDC::GetCharHeight() const
396{
397 return 0;
398}
399
400wxCoord wxDC::GetCharWidth() const
401{
402 return 0;
403}
404
405bool wxDC::CanDrawBitmap() const
406{
1fd17880 407 return true;
a24aff65
DE
408}
409
410bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
411{
412 return false;
413}
414
415void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
416{
417}
418
419void wxDC::SetPen(const wxPen& pen)
420{
5eb5a0ac 421 m_pen = pen;
a24aff65
DE
422}
423
424void wxDC::SetBrush(const wxBrush& brush)
425{
c3b0c2c3 426 m_brush = brush;
a24aff65
DE
427}
428
429void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
430{
431}
432
433void wxDC::DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
434{
435}
436
437void wxDC::DestroyClippingRegion()
438{
439}
440
441void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
442{
443}
444
445void wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
446{
447}
448
449void wxDC::DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h, double sa, double ea)
450{
451}
452
a24aff65
DE
453void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
454{
455}
456
457void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
458{
1b1f8b2d 459 wxAutoNSAutoreleasePool pool;
fe8f7943 460 if(!CocoaTakeFocus()) return;
1fd17880
DE
461 if(!bmp.Ok())
462 return;
463
464#if 0
465 // Draw a rect so we can see where it's supposed to be
48580976 466 wxLogTrace(wxTRACE_COCOA,wxT("image at (%d,%d) size %dx%d"),x,y,bmp.GetWidth(),bmp.GetHeight());
1fd17880
DE
467 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:NSMakeRect(x,y,bmp.GetWidth(),bmp.GetHeight())];
468 [[NSColor blackColor] set];
469 [bezpath stroke];
470 [[NSColor blueColor] set];
471 [bezpath fill];
472#endif // 0
473
474 NSAffineTransform *transform = [NSAffineTransform transform];
475 [transform translateXBy:x yBy:y];
476
477 NSAffineTransform *flipTransform = [NSAffineTransform transform];
478 /* x' = 1x + 0y + 0
479 y' = 0x + -1y + window's height
480 */
481 NSAffineTransformStruct matrix = {
482 1, 0
483 , 0, -1
484 , 0, bmp.GetHeight()
485 };
486 [flipTransform setTransformStruct: matrix];
487
488 NSGraphicsContext *context = [NSGraphicsContext currentContext];
489 [context saveGraphicsState];
490 [transform concat];
491 [flipTransform concat];
492
a00daa65
DE
493 NSImage *nsimage = [bmp.GetNSImage(useMask) retain];
494
1fd17880
DE
495 [nsimage drawAtPoint: NSMakePoint(0,0)
496 fromRect: NSMakeRect(0.0,0.0,bmp.GetWidth(),bmp.GetHeight())
a00daa65 497 operation: NSCompositeSourceOver
1fd17880
DE
498 fraction: 1.0];
499
500 [nsimage release];
501 [context restoreGraphicsState];
a24aff65
DE
502}
503
504bool wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style)
505{
506 return false;
507}
508
509void wxDC::DoCrossHair(wxCoord x, wxCoord y)
510{
511}
512
a24aff65
DE
513
514bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask , wxCoord xsrcMask, wxCoord ysrcMask)
2c23fe91
DE
515{
516 if(!CocoaTakeFocus()) return false;
517 if(!source) return false;
518 return source->CocoaDoBlitOnFocusedDC(xdest,ydest,width,height,
519 xsrc, ysrc, rop, useMask, xsrcMask, ysrcMask);
520}
521
522bool wxDC::CocoaDoBlitOnFocusedDC(wxCoord xdest, wxCoord ydest,
523 wxCoord width, wxCoord height, wxCoord xsrc, wxCoord ysrc,
524 int logicalFunc, bool useMask, wxCoord xsrcMask, wxCoord ysrcMask)
a24aff65
DE
525{
526 return false;
527}
528
529void wxDC::DoGetSize( int* width, int* height ) const
530{
531 *width = m_maxX-m_minX;
532 *height = m_maxY-m_minY;
533};
534
535void wxDC::DoGetSizeMM( int* width, int* height ) const
536{
537 int w = 0;
538 int h = 0;
539 GetSize( &w, &h );
540};
541
542void wxDC::SetTextForeground( const wxColour &col )
543{
544 if (!Ok()) return;
545 m_textForegroundColour = col;
546};
547
548void wxDC::SetTextBackground( const wxColour &col )
549{
550 if (!Ok()) return;
551 m_textBackgroundColour = col;
552};
553
554void wxDC::Clear()
555{
556}
557
7bc429ef 558void wxDC::SetBackground(const wxBrush& brush)
a24aff65 559{
7bc429ef 560 m_backgroundBrush = brush;
a24aff65
DE
561}
562
563void wxDC::SetPalette(const wxPalette&)
564{
565}
566
567void wxDC::SetLogicalFunction(int)
568{
569}
570
571
572void wxDC::SetMapMode( int mode )
573{
574 switch (mode)
575 {
576 case wxMM_TWIPS:
577 break;
578 case wxMM_POINTS:
579 break;
580 case wxMM_METRIC:
581 break;
582 case wxMM_LOMETRIC:
583 break;
584 default:
585 case wxMM_TEXT:
586 SetLogicalScale( 1.0, 1.0 );
587 break;
588 };
589 if (mode != wxMM_TEXT)
590 {
591 };
592};
593
594void wxDC::SetUserScale( double x, double y )
595{
596 // allow negative ? -> no
597 m_userScaleX = x;
598 m_userScaleY = y;
599 ComputeScaleAndOrigin();
600};
601
602void wxDC::SetLogicalScale( double x, double y )
603{
604 // allow negative ?
605 m_logicalScaleX = x;
606 m_logicalScaleY = y;
607 ComputeScaleAndOrigin();
608};
609
610void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
611{
612 m_logicalOriginX = x * m_signX; // is this still correct ?
613 m_logicalOriginY = y * m_signY;
614 ComputeScaleAndOrigin();
615};
616
617void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
618{
619 ComputeScaleAndOrigin();
620};
621
622void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
623{
624 m_signX = (xLeftRight ? 1 : -1);
625 m_signY = (yBottomUp ? -1 : 1);
626 ComputeScaleAndOrigin();
627};
628
629void wxDC::ComputeScaleAndOrigin(void)
630{
631 // CMB: copy scale to see if it changes
632 double origScaleX = m_scaleX;
633 double origScaleY = m_scaleY;
634
635 m_scaleX = m_logicalScaleX * m_userScaleX;
636 m_scaleY = m_logicalScaleY * m_userScaleY;
637
638 // CMB: if scale has changed call SetPen to recalulate the line width
639 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
640 {
641 // this is a bit artificial, but we need to force wxDC to think
642 // the pen has changed
10c5f652 643 const wxPen* pen = & GetPen();
a24aff65
DE
644 wxPen tempPen;
645 m_pen = tempPen;
646 SetPen(* pen);
647 }
648};
649