-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvstgui.cpp
7495 lines (6440 loc) · 193 KB
/
vstgui.cpp
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
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
//-----------------------------------------------------------------------------
// VST Plug-Ins SDK
// VSTGUI: Graphical User Interface Framework for VST plugins :
//
// Version 2.2 Date : 14/05/03
//
// First version : Wolfgang Kundrus 06.97
// Added Motif/Windows vers.: Yvan Grabit 01.98
// Added Mac version : Charlie Steinberg 02.98
// Added BeOS version : Georges-Edouard Berenger 05.99
// Added new functions : Matthias Juwan 12.01
// Added MacOSX version : Arne Scheffler 02.03
//
//-----------------------------------------------------------------------------
// VSTGUI LICENSE
// © 2003, Steinberg Media Technologies, All Rights Reserved
//-----------------------------------------------------------------------------
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Steinberg Media Technologies nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//-----------------------------------------------------------------------------
#include "stdafx.h"
#ifndef __vstgui__
#include "vstgui.h"
#endif
#if !PLUGGUI
#ifndef __audioeffectx__
#include "audioeffectx.h"
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#if USE_NAMESPACE
#define VSTGUI_CFrame VSTGUI::CFrame
#define VSTGUI_CPoint VSTGUI::CPoint
#define VSTGUI_kDropFiles VSTGUI::kDropFiles
#define VSTGUI_kDropText VSTGUI::kDropText
#define VSTGUI_CTextEdit VSTGUI::CTextEdit
#define VSTGUI_CColor VSTGUI::CColor
#define VSTGUI_CDrawContext VSTGUI::CDrawContext
#define VSTGUI_COptionMenu VSTGUI::COptionMenu
#define VSTGUI_COptionMenuScheme VSTGUI::COptionMenuScheme
#else
#define VSTGUI_CFrame CFrame
#define VSTGUI_CPoint CPoint
#define VSTGUI_kDropFiles kDropFiles
#define VSTGUI_kDropText kDropText
#define VSTGUI_CTextEdit CTextEdit
#define VSTGUI_CColor CColor
#define VSTGUI_CDrawContext CDrawContext
#define VSTGUI_COptionMenu COptionMenu
#define VSTGUI_COptionMenuScheme COptionMenuScheme
#endif
#if !WINDOWS
#define USE_GLOBAL_CONTEXT 1
#endif
#ifdef DEBUG //---For Debugging------------------------
long gNbCBitmap = 0;
long gNbCView = 0;
long gNbCDrawContext = 0;
long gNbCOffscreenContext = 0;
long gBitmapAllocation = 0;
long gNbDC = 0;
#include <stdarg.h>
void FDebugPrint (char *format, ...);
void FDebugPrint (char *format, ...)
{
char string[300];
va_list marker;
va_start (marker, format);
vsprintf (string, format, marker);
if (!string)
strcpy (string, "Empty string\n");
#if MAC
// printf (string);
#elif WINDOWS
OutputDebugString (string);
#else
fprintf (stderr, string);
#endif
}
#endif //---For Debugging------------------------
#if WINDOWS
static bool swapped_mouse_buttons = false;
#define DYNAMICALPHABLEND 1
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#include <shlobj.h>
#include <shellapi.h>
#if DYNAMICALPHABLEND
typedef BOOL (WINAPI *PFNALPHABLEND)(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of upper-left corner
int nYOriginDest, // y-coord of upper-left corner
int nWidthDest, // destination width
int nHeightDest, // destination height
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of upper-left corner
int nYOriginSrc, // y-coord of upper-left corner
int nWidthSrc, // source width
int nHeightSrc, // source height
BLENDFUNCTION blendFunction // alpha-blending function
);
PFNALPHABLEND pfnAlphaBlend = NULL;
typedef BOOL (WINAPI *PFNTRANSPARENTBLT)(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int hHeightDest, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
UINT crTransparent // color to make transparent
);
PFNTRANSPARENTBLT pfnTransparentBlt = NULL;
#endif
#if PLUGGUI
extern HINSTANCE ghInst;
inline HINSTANCE GetInstance () { return ghInst; }
#else
extern void* hInstance;
inline HINSTANCE GetInstance () { return (HINSTANCE)hInstance; }
#endif
long useCount = 0;
char className[20];
bool InitWindowClass ();
void ExitWindowClass ();
LONG WINAPI WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
static HANDLE CreateMaskBitmap (CDrawContext* pContext, VSTGUI::CRect& rect, CColor transparentColor);
static void DrawTransparent (CDrawContext* pContext, VSTGUI::CRect& rect, const VSTGUI::CPoint& offset, HDC hdcBitmap, POINT ptSize, HBITMAP pMask, COLORREF color);
static bool checkResolveLink (const char* nativePath, char* resolved);
static void *createDropTarget (VSTGUI_CFrame* pFrame);
BEGIN_NAMESPACE_VSTGUI
long standardFontSize[] = { 12, 18, 14, 12, 11, 10, 9, 13 };
const char* standardFontName[] = {
"Arial", "Arial", "Arial",
"Arial", "Arial", "Arial",
"Arial", "Symbol" };
END_NAMESPACE_VSTGUI
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#elif MOTIF
#define USE_XPM 0
#define TEST_REGION 0
#if USE_XPM
#include <X11/xpm.h>
#endif
#include <X11/Xlib.h>
#include <Xm/DrawingA.h>
#include <assert.h>
#include <Xm/MwmUtil.h>
#include <Xm/DialogS.h>
#include <time.h>
#if SGI
#include <sys/syssgi.h>
#elif SUN
#elif LINUX
#endif
#define XDRAWPARAM pDisplay, (Window)pWindow, (GC)pSystemContext
#define XWINPARAM pDisplay, (Window)pWindow
#define XGCPARAM pDisplay, (GC)pSystemContext
// init the static variable about font
bool fontInit = false;
XFontStruct *fontStructs[] = {0, 0, 0, 0, 0, 0, 0};
struct SFontTable {char* name; char* string;};
static SFontTable fontTable[] = {
{"SystemFont", "-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*"}, // kSystemFont
{"NormalFontVeryBig", "-adobe-helvetica-medium-r-*-*-18-*-*-*-*-*-*-*"}, // kNormalFontVeryBig
{"NormalFontBig", "-adobe-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*"}, // kNormalFontBig
{"NormalFont", "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*"}, // kNormalFont
{"NormalFontSmall", "-adobe-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*"}, // kNormalFontSmall
{"NormalFontSmaller", "-adobe-helvetica-medium-r-*-*-9-*-*-*-*-*-*-*"}, // kNormalFontSmaller
{"NormalFontVerySmall", "-adobe-helvetica-medium-r-*-*-8-*-*-*-*-*-*-*"}, // kNormalFontVerySmall
{"SymbolFont", "-adobe-symbol-medium-r-*-*-12-*-*-*-*-*-*-*"} // kSymbolFont
};
long standardFontSize[] = { 12, 16, 14, 12, 10, 9, 8, 10 };
//-----------------------------------------------------------------------------
// declaration of different local functions
long convertPoint2Angle (VSTGUI::CPoint &pm, VSTGUI::CPoint &pt);
// callback for the frame
void _drawingAreaCallback (Widget widget, XtPointer clientData, XtPointer callData);
void _eventHandler (Widget w, XtPointer clientData, XEvent *event, char *p);
void _destroyCallback (Widget widget, XtPointer clientData, XtPointer callData);
// stuff for color
long getIndexColor8Bit (CColor color, Display *pDisplay, Colormap colormap);
long CDrawContext::nbNewColor = 0;
static CColor paletteNewColor[256];
//------ our user-defined XPM functions
bool xpmGetValues (char **ppDataXpm, long *pWidth, long *pHeight, long *pNcolor, long *pCpp);
#if !USE_XPM
#include "xpmloader.cpp"
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#elif MAC
#if MACX
//-----------------------------------------------------------------------------
#include <QuickTime/ImageCompression.h>
const unsigned char* macXfontNames[] = {
"\pArial",
"\pArial",
"\pArial",
"\pArial",
"\pArial",
"\pArial",
"\pArial",
"\pSymbol"
};
//-----------------------------------------------------------------------------
#else
#include <QDOffscreen.h>
#include <StandardFile.h>
#include <Navigation.h>
#include <PictUtils.h>
#endif
long standardFontSize[] = { 12, 18, 14, 12, 10, 9, 9, 12 };
long convertPoint2Angle (VSTGUI::CPoint &pm, VSTGUI::CPoint &pt);
void RectNormalize (Rect& rect);
void CRect2Rect (const VSTGUI::CRect &cr, Rect &rr);
void Rect2CRect (Rect &rr, VSTGUI::CRect &cr);
void CColor2RGBColor (const CColor &cc, RGBColor &rgb);
void RGBColor2CColor (const RGBColor &rgb, CColor &cc);
static void install_drop (CFrame *frame);
static void remove_drop (CFrame *frame);
//-----------------------------------------------------------------------------
void RectNormalize (Rect& rect)
{
if (rect.left > rect.right)
{
long temp = rect.right;
rect.right = rect.left;
rect.left = temp;
}
if (rect.top > rect.bottom)
{
long temp = rect.bottom;
rect.bottom = rect.top;
rect.top = temp;
}
}
//-----------------------------------------------------------------------------
void CRect2Rect (const VSTGUI::CRect &cr, Rect &rr)
{
rr.left = cr.left;
rr.right = cr.right;
rr.top = cr.top;
rr.bottom = cr.bottom;
RectNormalize (rr);
}
//-----------------------------------------------------------------------------
void Rect2CRect (Rect &rr, VSTGUI::CRect &cr)
{
cr.left = rr.left;
cr.right = rr.right;
cr.top = rr.top;
cr.bottom = rr.bottom;
}
//-----------------------------------------------------------------------------
void CColor2RGBColor (const CColor &cc, RGBColor &rgb)
{
rgb.red = cc.red * 257;
rgb.green = cc.green * 257;
rgb.blue = cc.blue * 257;
}
//-----------------------------------------------------------------------------
void RGBColor2CColor (const RGBColor &rgb, CColor &cc)
{
cc.red = rgb.red / 257;
cc.green = rgb.green / 257;
cc.blue = rgb.blue / 257;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#elif BEOS
#include <TranslationUtils.h>
#include <Resources.h>
#include <Bitmap.h>
#include <Region.h>
#include <View.h>
#include <Window.h>
#include <Message.h>
#include <Entry.h>
#include <Path.h>
//--------------------------
class PlugView: public BView
{
public:
PlugView (BRect frame, CFrame* cframe);
void Draw (BRect updateRect);
void MouseDown (BPoint where);
void MessageReceived (BMessage *msg);
private:
CFrame* cframe;
};
long convertPoint2Angle (VSTGUI::CPoint &pm, VSTGUI::CPoint &pt);
drawing_mode modeToPlatform [] = {
// kCopyMode kOrMode kXorMode
B_OP_COPY, B_OP_OVER, B_OP_INVERT
};
long standardFontSize[] = { 12, 18, 14, 12, 11, 10, 9, 12 };
const char* standardFont = "Swis721 BT";
const char* standardFontS = "Roman";
const char* systemFont = "Swis721 BT";
const char* systemFontS = "Bold";
const char* standardFontName[] = { systemFont,
standardFont, standardFont, standardFont, standardFont, standardFont,
standardFont };
const char* standardFontStyle[] = { systemFontS,
standardFontS, standardFontS, standardFontS, standardFontS, standardFontS,
standardFontS };
#endif
//-----------------------------------------------------------------------------
bool VSTGUI::CRect::pointInside (const VSTGUI::CPoint& where) const
{
return where.h >= left && where.h < right && where.v >= top && where.v < bottom;
}
//-----------------------------------------------------------------------------
bool VSTGUI::CRect::isEmpty () const
{
if (right <= left)
return true;
if (bottom <= top)
return true;
return false;
}
//-----------------------------------------------------------------------------
void VSTGUI::CRect::bound (const VSTGUI::CRect& rect)
{
if (left < rect.left)
left = rect.left;
if (top < rect.top)
top = rect.top;
if (right > rect.right)
right = rect.right;
if (bottom > rect.bottom)
bottom = rect.bottom;
if (bottom < top)
bottom = top;
if (right < left)
right = left;
}
BEGIN_NAMESPACE_VSTGUI
CColor kTransparentCColor = {255, 255, 255, 0};
CColor kBlackCColor = {0, 0, 0, 0};
CColor kWhiteCColor = {255, 255, 255, 0};
CColor kGreyCColor = {127, 127, 127, 0};
CColor kRedCColor = {255, 0, 0, 0};
CColor kGreenCColor = {0 , 255, 0, 0};
CColor kBlueCColor = {0 , 0, 255, 0};
CColor kYellowCColor = {255, 255, 0, 0};
CColor kMagentaCColor= {255, 0, 255, 0};
CColor kCyanCColor = {0 , 255, 255, 0};
#define kDragDelay 0
//-----------------------------------------------------------------------------
// CDrawContext Implementation
//-----------------------------------------------------------------------------
CDrawContext::CDrawContext (CFrame *pFrame, void *pSystemContext, void *pWindow)
: pSystemContext (pSystemContext), pWindow (pWindow), pFrame (pFrame),
frameWidth (1), lineStyle (kLineSolid), drawMode (kCopyMode)
#if WINDOWS
,pBrush (0), pFont (0), pPen (0), pOldBrush (0), pOldPen (0), pOldFont (0)
#elif MAC
,bInitialized (false)
#endif
{
#ifdef DEBUG
gNbCDrawContext++;
#endif
// initialize values
if (pFrame)
pFrame->getViewSize (clipRect);
else
clipRect (0, 0, 1000, 1000);
frameColor = kWhiteCColor;
fillColor = kBlackCColor;
fontColor = kWhiteCColor;
// offsets use by offscreen
offset (0, 0);
offsetScreen (0, 0);
#if WINDOWS
if (pSystemContext)
{
pOldBrush = GetCurrentObject ((HDC)pSystemContext, OBJ_BRUSH);
pOldPen = GetCurrentObject ((HDC)pSystemContext, OBJ_PEN);
pOldFont = GetCurrentObject ((HDC)pSystemContext, OBJ_FONT);
SetBkMode ((HDC)pSystemContext, TRANSPARENT);
}
iPenStyle = PS_SOLID;
// get position
if (pWindow)
{
RECT rctTempWnd;
GetWindowRect ((HWND)pWindow, &rctTempWnd);
offsetScreen.h = rctTempWnd.left;
offsetScreen.v = rctTempWnd.top;
}
#elif MOTIF
if (pFrame)
pDisplay = pFrame->getDisplay ();
// set the current font
if (pSystemContext)
setFont (kNormalFont);
else
fprintf (stderr, "Error in CDrawContext::CDrawContext : pSystemContext must not be Null!!!\n");
#elif BEOS
pView = (BView*) pSystemContext;
if (pView)
pView->LockLooper ();
#endif
if (pSystemContext)
{
// set the default values
setFrameColor (frameColor);
setLineStyle (lineStyle);
#if !MOTIF
setFillColor (fillColor);
setFontColor (fontColor);
#endif
}
}
//-----------------------------------------------------------------------------
CDrawContext::~CDrawContext ()
{
#ifdef DEBUG
gNbCDrawContext--;
#endif
#if WINDOWS
if (pOldBrush)
SelectObject ((HDC)pSystemContext, pOldBrush);
if (pOldPen)
SelectObject ((HDC)pSystemContext, pOldPen);
if (pOldFont)
SelectObject ((HDC)pSystemContext, pOldFont);
if (pBrush)
DeleteObject (pBrush);
if (pPen)
DeleteObject (pPen);
if (pFont)
DeleteObject (pFont);
#elif MAC
#elif MOTIF
#elif BEOS
if (pView)
{
pView->Flush ();
pView->UnlockLooper ();
}
#endif
}
//-----------------------------------------------------------------------------
void CDrawContext::moveTo (const VSTGUI::CPoint &_point)
{
VSTGUI::CPoint point (_point);
point.offset (offset.h, offset.v);
#if WINDOWS
MoveToEx ((HDC)pSystemContext, point.h, point.v, NULL);
#elif MAC
CGrafPtr OrigPort;
GDHandle OrigDevice;
GetGWorld (&OrigPort, &OrigDevice); // get current GrafPort
SetGWorld (getPort (), NULL); // activate our GWorld
MoveTo (point.h, point.v);
SetGWorld (OrigPort, OrigDevice);
penLoc = point;
#elif MOTIF || BEOS
penLoc = point;
#endif
}
//-----------------------------------------------------------------------------
void CDrawContext::lineTo (const VSTGUI::CPoint& _point)
{
VSTGUI::CPoint point (_point);
point.offset (offset.h, offset.v);
#if WINDOWS
LineTo ((HDC)pSystemContext, point.h, point.v);
#elif MAC
CGrafPtr OrigPort;
GDHandle OrigDevice;
GetGWorld (&OrigPort, &OrigDevice); // get current GrafPort
SetGWorld (getPort (), NULL); // activate our GWorld
RGBColor col;
CColor2RGBColor (frameColor, col);
RGBForeColor (&col);
#if 1
if (point.v == penLoc.v)
{
VSTGUI::CPoint old = point;
if (point.h > penLoc.h)
point.h--;
else
point.h++;
penLoc = old;
LineTo (point.h, point.v);
MoveTo (penLoc.h, penLoc.v);
}
else if (point.h == penLoc.h)
{
VSTGUI::CPoint old = point;
if (point.v > penLoc.v)
point.v--;
else
point.v++;
penLoc = old;
LineTo (point.h, point.v);
MoveTo (penLoc.h, penLoc.v);
}
else
{
penLoc = point;
LineTo (point.h, point.v);
}
#else
if (point.v > penLoc.v)
point.v--;
else if (point.v < penLoc.v)
point.v++;
if (point.h > penLoc.h)
point.h--;
else if (point.h < penLoc.h)
point.h++;
penLoc = point;
LineTo (point.h, point.v);
#endif
SetGWorld (OrigPort, OrigDevice);
#elif MOTIF
VSTGUI::CPoint start (penLoc);
VSTGUI::CPoint end (point);
if (start.h == end.h)
{
if (start.v < -5)
start.v = -5;
else if (start.v > 10000)
start.v = 10000;
if (end.v < -5)
end.v = -5;
else if (end.v > 10000)
end.v = 10000;
}
if (start.v == end.v)
{
if (start.h < -5)
start.h = -5;
else if (start.h > 10000)
start.h = 10000;
if (end.h < -5)
end.h = -5;
else if (end.h > 10000)
end.h = 10000;
}
XDrawLine (XDRAWPARAM, start.h, start.v, end.h, end.v);
// keep trace of the new position
penLoc = point;
#elif BEOS
rgb_color c = { frameColor.red, frameColor.green, frameColor.blue, 255 };
pView->SetHighColor (c);
pView->SetDrawingMode (modeToPlatform [drawMode]);
pView->SetPenSize (frameWidth);
lineFromTo (penLoc, point);
penLoc = point;
#endif
}
//-----------------------------------------------------------------------------
void CDrawContext::polyLine (const VSTGUI::CPoint *pPoints, long numberOfPoints)
{
#if WINDOWS
POINT points[30];
POINT *polyPoints;
bool allocated = false;
if (numberOfPoints > 30)
{
polyPoints = (POINT*)new char [numberOfPoints * sizeof (POINT)];
if (!polyPoints)
return;
allocated = true;
}
else
polyPoints = points;
for (long i = 0; i < numberOfPoints; i++)
{
polyPoints[i].x = pPoints[i].h + offset.h;
polyPoints[i].y = pPoints[i].v + offset.v;
}
Polyline ((HDC)pSystemContext, polyPoints, numberOfPoints);
if (allocated)
delete[] polyPoints;
#elif MAC
CGrafPtr OrigPort;
GDHandle OrigDevice;
GetGWorld (&OrigPort, &OrigDevice);
SetGWorld (getPort (), NULL);
RGBColor col;
CColor2RGBColor (frameColor, col);
RGBForeColor (&col);
MoveTo (pPoints[0].h, pPoints[0].v);
for (long i = 1; i < numberOfPoints; i++)
LineTo (pPoints[i].h + offset.h, pPoints[i].v + offset.v);
SetGWorld (OrigPort, OrigDevice);
#elif MOTIF
XPoint* pt = (XPoint*)malloc (numberOfPoints * sizeof (XPoint));
if (!pt)
return;
for (long i = 0; i < numberOfPoints; i++)
{
pt[i].x = (short)pPoints[i].h + offset.h;
pt[i].y = (short)pPoints[i].v + offset.v;
}
XDrawLines (XDRAWPARAM, pt, numberOfPoints, CoordModeOrigin);
free (pt);
#elif BEOS
rgb_color c = { frameColor.red, frameColor.green, frameColor.blue, 255 };
pView->SetHighColor (c);
pView->SetDrawingMode (modeToPlatform [drawMode]);
pView->SetPenSize (frameWidth);
VSTGUI::CPoint begin (pPoints[0]);
begin.offset (offset.h, offset.v);
VSTGUI::CPoint end;
for (long i = 1; i < numberOfPoints; i++)
{
end = pPoints[i];
end.offset (offset.h, offset.v);
lineFromTo (begin, end);
begin = end;
}
#endif
}
//-----------------------------------------------------------------------------
void CDrawContext::setLineStyle (CLineStyle style)
{
lineStyle = style;
#if WINDOWS
switch (lineStyle)
{
case kLineOnOffDash:
iPenStyle = PS_DOT;
break;
default:
iPenStyle = PS_SOLID;
break;
}
LOGPEN logPen = {iPenStyle, {frameWidth, frameWidth},
RGB (frameColor.red, frameColor.green, frameColor.blue)};
HANDLE newPen = CreatePenIndirect (&logPen);
SelectObject ((HDC)pSystemContext, newPen);
if (pPen)
DeleteObject (pPen);
pPen = newPen;
#elif MAC
CGrafPtr OrigPort;
GDHandle OrigDevice;
if (pWindow)
{
GetGWorld (&OrigPort, &OrigDevice);
SetGWorld (getPort (), NULL);
PenState penState;
GetPenState (&penState);
switch (lineStyle)
{
case kLineOnOffDash:
StuffHex (&penState.pnPat, "\pF0F0F0F00F0F0F0F"); // dashed line 4 pixel
break;
default:
StuffHex (&penState.pnPat, "\pFFFFFFFFFFFFFFFF");
break;
}
SetPenState (&penState);
SetGWorld (OrigPort, OrigDevice);
}
#elif MOTIF
long line_width;
long line_style;
if (frameWidth == 1)
line_width = 0;
else
line_width = frameWidth;
switch (lineStyle)
{
case kLineOnOffDash:
line_style = LineOnOffDash;
break;
default:
line_style = LineSolid;
break;
}
XSetLineAttributes (XGCPARAM, line_width, line_style, CapNotLast, JoinRound);
#endif
}
//-----------------------------------------------------------------------------
void CDrawContext::setLineWidth (long width)
{
frameWidth = width;
#if WINDOWS
LOGPEN logPen = {iPenStyle, {frameWidth, frameWidth},
RGB (frameColor.red, frameColor.green, frameColor.blue)};
HANDLE newPen = CreatePenIndirect (&logPen);
SelectObject ((HDC)pSystemContext, newPen);
if (pPen)
DeleteObject (pPen);
pPen = newPen;
#elif MAC
CGrafPtr OrigPort;
GDHandle OrigDevice;
if (pWindow)
{
GetGWorld (&OrigPort, &OrigDevice);
SetGWorld (getPort (), NULL);
PenState penState;
GetPenState (&penState);
penState.pnSize.h = width;
penState.pnSize.v = width;
SetPenState (&penState);
SetGWorld (OrigPort, OrigDevice);
}
#elif MOTIF
setLineStyle (lineStyle);
#endif
}
//-----------------------------------------------------------------------------
void CDrawContext::setDrawMode (CDrawMode mode)
{
if (drawMode == mode)
return;
drawMode = mode;
#if WINDOWS
long iMode = 0;
switch (drawMode)
{
case kXorMode :
iMode = R2_NOTXORPEN; // Pixel is the inverse of the R2_XORPEN color (final pixel = ~ (pen ^ screen pixel)).
break;
case kOrMode :
iMode = R2_MERGEPEN; // Pixel is a combination of the pen color and the screen color (final pixel = pen | screen pixel).
break;
default:
iMode = R2_COPYPEN;
break;
}
SetROP2 ((HDC)pSystemContext, iMode);
#elif MAC
if (pWindow)
{
CGrafPtr OrigPort;
GDHandle OrigDevice;
GetGWorld (&OrigPort, &OrigDevice);
SetGWorld (getPort (), NULL);
long iMode = 0;
switch (drawMode)
{
case kXorMode :
iMode = patXor;
break;
case kOrMode :
iMode = patOr;
break;
default:
iMode = patCopy;
}
PenMode (mode);
SetGWorld (OrigPort, OrigDevice);
}
#elif MOTIF
long iMode = 0;
switch (drawMode)
{
case kXorMode :
iMode = GXinvert;
break;
case kOrMode :
iMode = GXor;
break;
default:
iMode = GXcopy;
}
((XGCValues*)pSystemContext)->function = iMode;
XChangeGC (XGCPARAM, GCFunction, (XGCValues*)pSystemContext);
#endif
}
//------------------------------------------------------------------------------
void CDrawContext::setClipRect (const VSTGUI::CRect &clip)
{
clipRect = clip;
#if MAC
Rect r;
CRect2Rect (clip, r);
CGrafPtr OrigPort;
GDHandle OrigDevice;
GetGWorld (&OrigPort, &OrigDevice);
SetGWorld (getPort (), NULL);
ClipRect (&r);
SetGWorld (OrigPort, OrigDevice);
#elif WINDOWS
RECT r = {clip.left, clip.top, clip.right, clip.bottom};
HRGN hRgn = CreateRectRgn (r.left, r.top, r.right, r.bottom);
SelectClipRgn ((HDC)pSystemContext, hRgn);
DeleteObject (hRgn);
#elif MOTIF
XRectangle r;
r.x = 0;
r.y = 0;
r.width = clip.right - clip.left;
r.height = clip.bottom - clip.top;
XSetClipRectangles (XGCPARAM, clip.left, clip.top, &r, 1, Unsorted);
#elif BEOS
clipping_rect r = {clip.left, clip.top, clip.right - 1, clip.bottom - 1};
BRegion region;
region.Set (r);
pView->ConstrainClippingRegion (®ion);
#endif
}
//------------------------------------------------------------------------------
void CDrawContext::resetClipRect ()
{
VSTGUI::CRect newClip;
if (pFrame)
pFrame->getViewSize (newClip);
else
newClip (0, 0, 1000, 1000);
#if MAC || WINDOWS || MOTIF
setClipRect (newClip);
#elif BEOS
pView->ConstrainClippingRegion (NULL);
#endif
clipRect = newClip;
}
//-----------------------------------------------------------------------------
void CDrawContext::fillPolygon (const VSTGUI::CPoint *pPoints, long numberOfPoints)
{
// Don't draw boundary
#if WINDOWS
POINT points[30];
POINT *polyPoints;
bool allocated = false;
if (numberOfPoints > 30)
{
polyPoints = (POINT*)new char [numberOfPoints * sizeof (POINT)];
if (!polyPoints)
return;
allocated = true;
}
else
polyPoints = points;
for (long i = 0; i < numberOfPoints; i++)
{