Repository navigation
Expand file tree
/
Copy pathdc.cpp
More file actions
2733 lines (2431 loc) · 86.8 KB
/
Copy pathdc.cpp
File metadata and controls
2733 lines (2431 loc) · 86.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
10BC8
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/////////////////////////////////////////////////////////////////////////////
// Name: src/os2/dc.cpp
// Purpose: wxDC class
// Author: David Webster
// Modified by:
// Created: 10/14/99
// RCS-ID: $Id$
// Copyright: (c) David Webster
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/window.h"
#include "wx/dc.h"
#include "wx/utils.h"
#include "wx/dialog.h"
#include "wx/app.h"
#include "wx/bitmap.h"
#include "wx/dcmemory.h"
#include "wx/log.h"
#include "wx/icon.h"
#include "wx/msgdlg.h"
#include "wx/dcprint.h"
#include "wx/statusbr.h"
#include "wx/module.h"
#endif
#include <string.h>
#include "wx/os2/dc.h"
#include "wx/os2/dcclient.h"
#include "wx/os2/private.h"
IMPLEMENT_ABSTRACT_CLASS(wxPMDCImpl, wxDCImpl)
//
// wxWidgets uses the Microsoft convention that the origin is the UPPER left.
// Native OS/2 however in the GPI and PM define the origin as the LOWER left.
// In order to map OS/2 GPI/PM y coordinates to wxWidgets coordinates we must
// perform the following transformation:
//
// Parent object height: POBJHEIGHT
// Desried origin: WXORIGINY
// Object to place's height: OBJHEIGHT
//
// To get the OS2 position from the wxWidgets one:
//
// OS2Y = POBJHEIGHT - (WXORIGINY + OBJHEIGHT)
//
// For OS/2 wxDC's we will always determine m_vRclPaint as the size of the
// OS/2 Presentation Space associated with the device context. y is the
// desired application's y coordinate of the origin in wxWidgets space.
// objy is the height of the object we are going to draw.
//
#define OS2Y(y, objy) ((m_vRclPaint.yTop - m_vRclPaint.yBottom) - (y + objy))
// ---------------------------------------------------------------------------
// constants
// ---------------------------------------------------------------------------
static const int VIEWPORT_EXTENT = 1000;
static const int MM_POINTS = 9;
static const int MM_METRIC = 10;
// ---------------------------------------------------------------------------
// private functions
// ---------------------------------------------------------------------------
// convert degrees to radians
static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
int SetTextColor(
HPS hPS
, int nForegroundColour
)
{
CHARBUNDLE vCbnd;
vCbnd.lColor = nForegroundColour;
::GpiSetAttrs( hPS // presentation-space handle
,PRIM_CHAR // Char primitive.
,CBB_COLOR // sets color.
,0 //
,&vCbnd // buffer for attributes.
);
return 0;
}
int QueryTextBkColor(
HPS hPS
)
{
CHARBUNDLE vCbnd;
::GpiQueryAttrs( hPS // presentation-space handle
,PRIM_CHAR // Char primitive.
,CBB_BACK_COLOR // Background color.
,&vCbnd // buffer for attributes.
);
return vCbnd.lBackColor;
}
int SetTextBkColor(<
8
/div>
HPS hPS
, int nBackgroundColour
)
{
CHARBUNDLE vCbnd;
int rc;
rc = QueryTextBkColor(hPS);
vCbnd.lBackColor = nBackgroundColour;
::GpiSetAttrs(hPS, // presentation-space handle
PRIM_CHAR, // Char primitive.
CBB_BACK_COLOR, // sets color.
0,
&vCbnd // buffer for attributes.
);
return rc;
}
int SetBkMode(
HPS hPS
, int nBackgroundMode
)
{
if(nBackgroundMode == wxTRANSPARENT)
::GpiSetBackMix( hPS
,BM_LEAVEALONE
);
else
// the background of the primitive takes over whatever is underneath.
::GpiSetBackMix( hPS
,BM_OVERPAINT
);
return 0;
}
// ===========================================================================
// implementation
// ===========================================================================
#if wxUSE_DC_CACHEING
/*
* This implementation is a bit ugly and uses the old-fashioned wxList class, so I will
* improve it in due course, either using arrays, or simply storing pointers to one
* entry for the bitmap, and two for the DCs. -- JACS
*/
// ---------------------------------------------------------------------------
// wxDCCacheEntry
// ---------------------------------------------------------------------------
wxList wxPMDCImpl::m_svBitmapCache;
wxList wxPMDCImpl::m_svDCCache;
wxDCCacheEntry::wxDCCacheEntry(
WXHBITMAP hBitmap
, int nWidth
, int nHeight
, int nDepth
)
{
m_hBitmap = hBitmap;
m_hPS = NULLHANDLE;
m_nWidth = nWidth;
m_nHeight = nHeight;
m_nDepth = nDepth;
} // end of wxDCCacheEntry::wxDCCacheEntry
wxDCCacheEntry::wxDCCacheEntry(
HPS hPS
, int nDepth
)
{
m_hBitmap = NULLHANDLE;
m_hPS = hPS;
m_nWidth = 0;
m_nHeight = 0;
m_nDepth = nDepth;
} // end of wxDCCacheEntry::wxDCCacheEntry
wxDCCacheEntry::~wxDCCacheEntry()
{
if (m_hBitmap)
::GpiDeleteBitmap(m_hBitmap);
if (m_hPS)
::GpiDestroyPS(m_hPS);
} // end of wxDCCacheEntry::~wxDCCacheEntry
wxDCCacheEntry* wxPMDCImpl::FindBitmapInCache(
HPS hPS
, int nWidth
, int nHeight
)
{
int nDepth = 24; // we'll fix this later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
wxNode* pNode = m_svBitmapCache.First();
BITMAPINFOHEADER2 vBmpHdr;
while(pNode)
{
wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data();
if (pEntry->m_nDepth == nDepth)
{
memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
if (pEntry->m_nWidth < nWidth || pEntry->m_nHeight < nHeight)
{
::GpiDeleteBitmap((HBITMAP)pEntry->m_hBitmap);
vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
vBmpHdr.cx = nWidth;
vBmpHdr.cy = nHeight;
vBmpHdr.cPlanes = 1;
vBmpHdr.cBitCount = (USHORT)nDepth;
pEntry->m_hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS
,&vBmpHdr
,0L, NULL, NULL
);
if (!pEntry->m_hBitmap)
{
wxLogLastError(wxT("CreateCompatibleBitmap"));
}
pEntry->m_nWidth = nWidth;
pEntry->m_nHeight = nHeight;
return pEntry;
}
return pEntry;
}
pNode = pNode->Next();
}
memset(&vBmpHdr, 0, sizeof(BITMAPINFOHEADER2));
vBmpHdr.cbFix = sizeof(BITMAPINFOHEADER2);
vBmpHdr.cx = nWidth;
vBmpHdr.cy = nHeight;
vBmpHdr.cPlanes = 1;
vBmpHdr.cBitCount = (USHORT)nDepth;
WXHBITMAP hBitmap = (WXHBITMAP) ::GpiCreateBitmap( hPS
,&vBmpHdr
,0L, NULL, NULL
);
if (!hBitmap)
{
wxLogLastError(wxT("CreateCompatibleBitmap"));
}
wxDCCacheEntry* pEntry = new wxDCCacheEntry( hBitmap
,nWidth
,nHeight
,nDepth
);
AddToBitmapCache(pEntry);
return pEntry;
} // end of FindBitmapInCache
wxDCCacheEntry* wxPMDCImpl::FindDCInCache(
wxDCCacheEntry* pNotThis
, HPS hPS
)
{
int nDepth = 24; // we'll fix this up later ::GetDeviceCaps((HDC) dc, PLANES) * ::GetDeviceCaps((HDC) dc, BITSPIXEL);
wxNode* pNode = m_svDCCache.First();
while(pNode)
{
wxDCCacheEntry* pEntry = (wxDCCacheEntry*)pNode->Data();
//
// Don't return the same one as we already have
//
if (!pNotThis || (pNotThis != pEntry))
{
if (pEntry->m_nDepth == nDepth)
{
return pEntry;
}
}
pNode = pNode->Next();
}
wxDCCacheEntry* pEntry = new wxDCCacheEntry( hPS
,nDepth
);
AddToDCCache(pEntry);
return pEntry;
} // end of wxPMDCImpl::FindDCInCache
void wxPMDCImpl::AddToBitmapCache(
wxDCCacheEntry* pEntry
)
{
m_svBitmapCache.Append(pEntry);
} // end of wxPMDCImpl::AddToBitmapCache
void wxPMDCImpl::AddToDCCache(
wxDCCacheEntry* pEntry
)
{
m_svDCCache.Append(pEntry);
} // end of wxPMDCImpl::AddToDCCache
void wxPMDCImpl::ClearCache()
{
m_svBitmapCache.DeleteContents(true);
m_svBitmapCache.Clear();
m_svBitmapCache.DeleteContents(false);
m_svDCCache.DeleteContents(true);
m_svDCCache.Clear();
m_svDCCache.DeleteContents(false);
} // end of wxPMDCImpl::ClearCache
// Clean up cache at app exit
class wxDCModule : public wxModule
{
public:
virtual bool OnInit() { return true; }
virtual void OnExit() { wxPMDCImpl::ClearCache(); }
private:
DECLARE_DYNAMIC_CLASS(wxDCModule)
}; // end of CLASS wxDCModule
IMPLEMENT_DYNAMIC_CLASS(wxDCModule, wxModule)
#endif // ndef for wxUSE_DC_CACHEING
// ---------------------------------------------------------------------------
// wxDC
// ---------------------------------------------------------------------------
wxPMDCImpl::wxPMDCImpl( wxDC *owner, WXHDC hDC ) :
wxDCImpl( owner )
{
Init();
m_hDC = hDC;
} // end of wxPMDCImpl::wxPMDCImpl
wxPMDCImpl::~wxPMDCImpl(void)
{
if ( m_hDC != 0 )
{
SelectOldObjects(m_hDC);
// if we own the HDC, we delete it, otherwise we just release it
if (m_bOwnsDC)
{
if(m_hPS)
{
::GpiAssociate(m_hPS, NULLHANDLE);
::GpiDestroyPS(m_hPS);
}
m_hPS = NULLHANDLE;
::DevCloseDC((HDC)m_hDC);
}
else
{
//
// Just Dissacociate, not destroy if we don't own the DC
//
if(m_hPS)
{
::GpiAssociate(m_hPS, NULLHANDLE);
}
}
}
} // end of wxPMDCImpl::~wxDC
// This will select current objects out of the DC,
// which is what you have to do before deleting the
// DC.
void wxPMDCImpl::SelectOldObjects(
WXHDC hPS
)
{
if (hPS)
{
if (m_hOldBitmap)
{
::GpiSetBitmap(hPS, (HBITMAP) m_hOldBitmap);
if (m_vSelectedBitmap.Ok())
{
m_vSelectedBitmap.SetSelectedInto(NULL);
}
}
m_hOldBitmap = 0;
//
// OS/2 has no other native GDI objects to set in a PS/DC like windows
//
m_hOldPen = 0;
m_hOldBrush = 0;
m_hOldFont = 0;
m_hOldPalette = 0;
}
m_brush = wxNullBrush;
m_pen = wxNullPen;
m_palette = wxNullPalette;
m_font = wxNullFont;
m_backgroundBrush = wxNullBrush;
m_vSelectedBitmap = wxNullBitmap;
} // end of wxPMDCImpl::SelectOldObjects
// ---------------------------------------------------------------------------
// clipping
// ---------------------------------------------------------------------------
#define DO_SET_CLIPPING_BOX() \
{ \
RECTL rect; \
\
::GpiQueryClipBox(m_hPS, &rect); \
\
m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
}
void wxPMDCImpl::DoSetClippingRegion(
wxCoord vX
, wxCoord vY
, wxCoord vWidth
, wxCoord vHeight
)
{
RECTL vRect;
vY = OS2Y(vY,vHeight);
m_clipping = true;
vRect.xLeft = vX;
vRect.yTop = vY + vHeight;
vRect.xRight = vX + vWidth;
vRect.yBottom = vY;
::GpiIntersectClipRectangle(m_hPS, &vRect);
DO_SET_CLIPPING_BOX()
} // end of wxPMDCImpl::DoSetClippingRegion
void wxPMDCImpl::DoSetDeviceClippingRegion(
const wxRegion& rRegion
)
{
wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region"));
HRGN hRgnOld;
m_clipping = true;
::GpiSetClipRegion( m_hPS
,(HRGN)rRegion.GetHRGN()
,&hRgnOld
);
DO_SET_CLIPPING_BOX()
} // end of wxPMDCImpl::DoSetDeviceClippingRegion
void wxPMDCImpl::DestroyClippingRegion(void)
{
if (m_clipping && m_hPS)
{
HRGN hRgnOld;
RECTL vRect;
// TODO: this should restore the previous clipped region
// so that OnPaint processing works correctly, and
// the update doesn't get destroyed after the first
// DestroyClippingRegion
vRect.xLeft = XLOG2DEV(0);
vRect.yTop = YLOG2DEV(32000);
vRect.xRight = XLOG2DEV(32000);
vRect.yBottom = YLOG2DEV(0);
HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect);
::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld);
}
ResetClipping();
} // end of wxPMDCImpl::DestroyClippingRegion
// ---------------------------------------------------------------------------
// query capabilities
// ---------------------------------------------------------------------------
bool wxPMDCImpl::CanDrawBitmap() const
{
return true;
}
bool wxPMDCImpl::CanGetTextExtent() const
{
LONG lTechnology = 0L;
::DevQueryCaps(GetHDC(), CAPS_TECHNOLOGY, 1L, &lTechnology);
return (lTechnology == CAPS_TECH_RASTER_DISPLAY) || (lTechnology == CAPS_TECH_RASTER_PRINTER);
} // end of wxPMDCImpl::CanGetTextExtent
int wxPMDCImpl::GetDepth() const
{
LONG lCapsColorBitcount;
int nBitsPerPixel = 0;
if(::DevQueryCaps( GetHDC()
,CAPS_COLOR_BITCOUNT
,1L
,&lCapsColorBitcount
))
{
nBitsPerPixel = (int)lCapsColorBitcount;
}
return nBitsPerPixel;
} // end of wxPMDCImpl::GetDepth
// ---------------------------------------------------------------------------
// drawing
// ---------------------------------------------------------------------------
void wxPMDCImpl::Clear()
{
//
// If this is a canvas DC then just fill with the background color
// Otherwise purge the whole thing
//
if (m_pCanvas)
{
RECTL vRect;
::GpiQueryClipBox(m_hPS, &vRect);
::WinFillRect(m_hPS, &vRect, ::GpiQueryBackColor(m_hPS));
}
else
::GpiErase(m_hPS);
} // end of wxPMDCImpl::Clear
bool wxPMDCImpl::DoFloodFill(
wxCoord vX
, wxCoord vY
, const wxColour& rCol
, wxFloodFillStyle nStyle
)
{
POINTL vPtlPos;
LONG lColor;
LONG lOptions;
LONG lHits;
bool bSuccess = false;
vPtlPos.x = vX; // Loads x-coordinate
vPtlPos.y = OS2Y(vY,0); // Loads y-coordinate
::GpiMove(m_hPS, &vPtlPos); // Sets current position
lColor = rCol.GetPixel();
lOptions = FF_BOUNDARY;
if(wxFLOOD_SURFACE == nStyle)
lOptions = FF_SURFACE;
if ((lHits = ::GpiFloodFill(m_hPS, lOptions, lColor)) != GPI_ERROR)
bSuccess = true;
return bSuccess;
} // end of wxPMDCImpl::DoFloodFill
bool wxPMDCImpl::DoGetPixel(
wxCoord vX
, wxCoord vY
, wxColour* pCol
) const
{
POINTL vPoint;
LONG lColor;
vPoint.x = vX;
vPoint.y = OS2Y(vY,0);
lColor = ::GpiQueryPel(m_hPS, &vPoint);
//
// return the color of the pixel
//
if(pCol)
pCol->Set( GetRValue(lColor)
,GetGValue(lColor)
,GetBValue(lColor)
);
return true;
} // end of wxPMDCImpl::DoGetPixel
void wxPMDCImpl::DoCrossHair(
wxCoord vX
, wxCoord vY
)
{
vY = OS2Y(vY,0);
wxCoord vX1 = vX - VIEWPORT_EXTENT;
wxCoord vY1 = vY - VIEWPORT_EXTENT;
wxCoord vX2 = vX + VIEWPORT_EXTENT;
wxCoord vY2 = vY + VIEWPORT_EXTENT;
POINTL vPoint[4];
vPoint[0].x = vX1;
vPoint[0].y = vY;
vPoint[1].x = vX2;
vPoint[1].y = vY;
::GpiMove(m_hPS, &vPoint[0]);
::GpiLine(m_hPS, &vPoint[1]);
vPoint[2].x = vX;
vPoint[2].y = vY1;
vPoint[3].x = vX;
vPoint[3].y = vY2;
::GpiMove(m_hPS, &vPoint[2]);
::GpiLine(m_hPS, &vPoint[3]);
CalcBoundingBox(vX1, vY1);
CalcBoundingBox(vX2, vY2);
} // end of wxPMDCImpl::DoCrossHair
void wxPMDCImpl::DoDrawLine(
wxCoord vX1
, wxCoord vY1
, wxCoord vX2
, wxCoord vY2
)
{
POINTL vPoint[2];
COLORREF vColor = 0x00ffffff;
//
// Might be a memory DC with no Paint rect.
//
if (!(m_vRclPaint.yTop == 0 &&
m_vRclPaint.yBottom == 0 &&
m_vRclPaint.xRight == 0 &&
m_vRclPaint.xLeft == 0))
{
vY1 = OS2Y(vY1,0);
vY2 = OS2Y(vY2,0);
}
else
{
if (m_vSelectedBitmap.Ok())
{
m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
10BC8
vY1 = OS2Y(vY1,0);
vY2 = OS2Y(vY2,0);
}
}
vPoint[0].x = vX1;
vPoint[0].y = vY1;
vPoint[1].x = vX2;
vPoint[1].y = vY2;
if (m_pen.Ok())
{
vColor = m_pen.GetColour().GetPixel();
}
::GpiSetColor(m_hPS, vColor);
::GpiMove(m_hPS, &vPoint[0]);
::GpiLine(m_hPS, &vPoint[1]);
CalcBoundingBox(vX1, vY1);
CalcBoundingBox(vX2, vY2);
} // end of wxPMDCImpl::DoDrawLine
//////////////////////////////////////////////////////////////////////////////
// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
// and ending at (x2, y2). The current pen is used for the outline and the
// current brush for filling the shape. The arc is drawn in an anticlockwise
// direction from the start point to the end point.
//////////////////////////////////////////////////////////////////////////////
void wxPMDCImpl::DoDrawArc(
wxCoord vX1
, wxCoord vY1
, wxCoord vX2
, wxCoord vY2
, wxCoord vXc
, wxCoord vYc
)
{
POINTL vPtlPos;
POINTL vPtlArc[2]; // Structure for current position
double dRadius;
double dAngl1;
double dAngl2;
double dAnglmid;
wxCoord vXm;
wxCoord vYm;
ARCPARAMS vArcp; // Structure for arc parameters
if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
return; // Draw point ??
dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
,(double)(vX1 - vXc)
) +
hypot( (double)(vY2 - vYc)
,(double)(vX2 - vXc)
)
);
dAngl1 = atan2( (double)(vY1 - vYc)
,(double)(vX1 - vXc)
);
dAngl2 = atan2( (double)(vY2 - vYc)
,(double)(vX2 - vXc)
);
if(dAngl2 < dAngl1)
dAngl2 += M_PI * 2;
//
// GpiPointArc can't draw full arc
//
if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
{
//
// Medium point
//
dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
DoDrawArc( vX1, vY1
,vXm, vYm
,vXc, vYc
);
DoDrawArc( vXm, vYm
,vX2, vY2
,vXc, vYc
);
return;
}
//
// Medium point
//
dAnglmid = (dAngl1 + dAngl2)/2.;
vXm = (wxCoord)(vXc + dRadius * cos(dAnglmid));
vYm = (wxCoord)(vYc + dRadius * sin(dAnglmid));
//
// Ellipse main axis (r,q), (p,s) with center at (0,0) */
//
vArcp.lR = 0;
vArcp.lQ = 1;
vArcp.lP = 1;
vArcp.lS = 0;
::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
vPtlPos.x = vX1; // Loads x-coordinate
vPtlPos.y = vY1; // Loads y-coordinate
::GpiMove(m_hPS, &vPtlPos); // Sets current position
vPtlArc[0].x = vXm;
vPtlArc[0].y = vYm;
vPtlArc[1].x = vX2;
vPtlArc[1].y = vY2;
::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
CalcBoundingBox( (wxCoord)(vXc - dRadius)
,(wxCoord)(vYc - dRadius)
);
CalcBoundingBox( (wxCoord)(vXc + dRadius)
,(wxCoord)(vYc + dRadius)
);
} // end of wxPMDCImpl::DoDrawArc
void wxPMDCImpl::DoDrawCheckMark(
wxCoord vX1
, wxCoord vY1
, wxCoord vWidth
, wxCoord vHeight
)
{
POINTL vPoint[2];
vY1 = OS2Y(vY1,vHeight);
vPoint[0].x = vX1;
vPoint[0].y = vY1;
vPoint[1].x = vX1 + vWidth;
vPoint[1].y = vY1 + vHeight;
::GpiMove(m_hPS, &vPoint[0]);
::GpiBox( m_hPS // handle to a presentation space
,DRO_OUTLINE // draw the box outline ? or ?
,&vPoint[1] // address of the corner
,0L // horizontal corner radius
,0L // vertical corner radius
);
if(vWidth > 4 && vHeight > 4)
{
int nTmp;
vPoint[0].x += 2; vPoint[0].y += 2;
vPoint[1].x -= 2; vPoint[1].y -= 2;
::GpiMove(m_hPS, &vPoint[0]);
::GpiLine(m_hPS, &vPoint[1]);
nTmp = vPoint[0].x;
vPoint[0].x = vPoint[1].x;
vPoint[1].x = nTmp;
::GpiMove(m_hPS, &vPoint[0]);
::GpiLine(m_hPS, &vPoint[1]);
}
CalcBoundingBox( vX1
,vY1
);
wxCoord vX2 = vX1 + vWidth;
wxCoord vY2 = vY1 + vHeight;
CalcBoundingBox( vX2
,vY2
);
} // end of wxPMDCImpl::DoDrawCheckMark
void wxPMDCImpl::DoDrawPoint(
wxCoord vX
, wxCoord vY
)
{
POINTL vPoint;
COLORREF vColor = 0x00ffffff;
if (m_pen.Ok())
{
vColor = m_pen.GetColour().GetPixel();
}
::GpiSetColor(m_hPS, vColor);
vPoint.x = vX;
vPoint.y = OS2Y(vY,0);
::GpiSetPel(m_hPS, &vPoint);
CalcBoundingBox( vX
,vY
);
} // end of wxPMDCImpl::DoDrawPoint
void wxPMDCImpl::DoDrawPolygon( int n,
wxPoint vPoints[],
wxCoord vXoffset,
wxCoord vYoffset,
wxPolygonFillMode nFillStyle )
{
ULONG ulCount = 1; // Number of polygons.
POLYGON vPlgn; // polygon.
ULONG flOptions = 0L; // Drawing options.
//////////////////////////////////////////////////////////////////////////////
// This contains fields of option bits... to draw boundary lines as well as
// the area interior.
//
// Drawing boundary lines:
// POLYGON_NOBOUNDARY Does not draw boundary lines.
// POLYGON_BOUNDARY Draws boundary lines (the default).
//
// Construction of the area interior:
// POLYGON_ALTERNATE Constructs interior in alternate mode
// (the default).
// POLYGON_WINDING Constructs interior in winding mode.
//////////////////////////////////////////////////////////////////////////////
ULONG flModel = POLYGON_INCL; // Drawing model.
//////////////////////////////////////////////////////////////////////////////
// Drawing model.
// POLYGON_INCL Fill is inclusive of bottom right (the default).
// POLYGON_EXCL Fill is exclusive of bottom right.
// This is provided to aid migration from other graphics models.
//////////////////////////////////////////////////////////////////////////////
LONG lHits = 0L; // Correlation/error indicator.
int i;
int nIsTRANSPARENT = 0;
LONG lBorderColor = 0L;
LONG lColor = 0L;
lBorderColor = m_pen.GetColour().GetPixel();
lColor = m_brush.GetColour().GetPixel();
if(m_brush.GetStyle() == wxTRANSPARENT)
nIsTRANSPARENT = 1;
vPlgn.ulPoints = n;
vPlgn.aPointl = (POINTL*) calloc( n + 1
,sizeof(POINTL)
); // well, new will call malloc
for(i = 0; i < n; i++)
{
vPlgn.aPointl[i].x = vPoints[i].x+vXoffset;
vPlgn.aPointl[i].y = OS2Y(vPoints[i].y+vYoffset,0);
}
flOptions = POLYGON_BOUNDARY;
if(nFillStyle == wxWINDING_RULE)
flOptions |= POLYGON_WINDING;
else
flOptions |= POLYGON_ALTERNATE;
::GpiSetColor(m_hPS, lBorderColor);
::GpiMove(m_hPS, &vPlgn.aPointl[0]);
lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
free(vPlgn.aPointl);
} // end of wxPMDCImpl::DoDrawPolygon
void wxPMDCImpl::DoDrawLines(
int n
, wxPoint vPoints[]
, wxCoord vXoffset
, wxCoord vYoffset
)
{
POINTL vPoint;
if (vXoffset != 0L || vXoffset != 0L)
{
int i;
vPoint.x = vPoints[0].x + vXoffset;
vPoint.y = OS2Y(vPoints[0].y + vYoffset,0);
::GpiMove(m_hPS, &vPoint);
LONG lBorderColor = m_pen.GetColour().GetPixel();
::GpiSetColor(m_hPS, lBorderColor);
for(i = 1; i < n; i++)
{
vPoint.x = vPoints[i].x + vXoffset;
vPoint.y = OS2Y(vPoints[i].y + vYoffset,0);
::GpiLine(m_hPS, &vPoint);
}
}
else
{
int i;
CalcBoundingBox( vPoints[0].x
,vPoints[0].y
);
vPoint.x = vPoints[0].x;
vPoint.y = OS2Y(vPoints[0].y,0);
::GpiMove(m_hPS, &vPoint);
for (i = 0; i < n; i++)
{
CalcBoundingBox( vPoints[i].x
,vPoints[i].y
);
vPoint.x = vPoints[i].x;
vPoint.y = OS2Y(vPoints[i].y,0);
::GpiLine(m_hPS, &vPoint);
}
}
} // end of wxPMDCImpl::DoDrawLines
void wxPMDCImpl::DoDrawRectangle(
wxCoord vX
, wxCoord vY
, wxCoord vWidth
, wxCoord vHeight
)
{
POINTL vPoint[2];
LONG lControl;
LONG lColor;
LONG lBorderColor;
int nIsTRANSPARENT = 0;
//
// Might be a memory DC with no Paint rect.
//
if (!(m_vRclPaint.yTop == 0 &&
m_vRclPaint.yBottom == 0 &&
m_vRclPaint.xRight == 0 &&
m_vRclPaint.xLeft == 0))
vY = OS2Y(vY,vHeight);
else
{
if (m_vSelectedBitmap.Ok())
{
m_vRclPaint.yTop = m_vSelectedBitmap.GetHeight();
m_vRclPaint.xRight = m_vSelectedBitmap.GetWidth();
vY = OS2Y(vY,vHeight);
}
}
wxCoord vX2 = vX + vWidth;
wxCoord vY2 = vY + vHeight;
vPoint[0].x = vX;
vPoint[0].y = vY;
vPoint[1].x = vX + vWidth - 1;
vPoint[1].y = vY + vHeight - 1;
::GpiMove(m_hPS, &vPoint[0]);
lColor = m_brush.GetColour().GetPixel();
lBorderColor = m_pen.GetColour().GetPixel();
if (m_brush.GetStyle() == wxTRANSPARENT)
nIsTRANSPARENT = 1;
if(lColor == lBorderColor || nIsTRANSPARENT)
{
lControl = DRO_OUTLINEFILL; //DRO_FILL;
if(m_brush.GetStyle() == wxTRANSPARENT)
You can’t perform that action at this time.