source: Sophya/trunk/SophyaPI/PI/pigraphmac.cc@ 2615

Last change on this file since 2615 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 11.1 KB
Line 
1#include <stdio.h>
2
3#include "sopnamsp.h"
4#include "pigraphmac.h"
5#include "UDrawingState.h"
6
7
8
9// #define DEBUG_PIBWDGX Flag pour impression de debug etc ...
10
11/* --Methode-- */
12PIGraphicMac::PIGraphicMac(PIWdg* wdg)
13: PIGraphicGen(wdg)
14{
15 mPane = wdg->mPane;
16}
17
18/* --Methode-- */
19PIGraphicMac::~PIGraphicMac()
20{
21}
22
23/* --Methode-- */
24void PIGraphicMac::Erase(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
25{
26 if (mPane->FocusDraw()) {
27 Rect theRect = {(int)y0, (int)x0, (int)y0+(int)dy, (int)x0+(int)dx};
28 ::EraseRect(&theRect);
29 }
30}
31
32/* --Methode-- */
33void PIGraphicMac::DrawString(PIGrCoord x, PIGrCoord y, char const* s, int /*pos*/)
34{
35 if (!mPane->FocusDraw()) {
36 ::MoveTo(x, y);
37 LStr255 ps = s;
38 StTextState saver;
39 myFont.Apply();
40 ::DrawString(ps);
41 }
42}
43
44/* --Methode-- */
45void PIGraphicMac::DrawOpaqueString(PIGrCoord x, PIGrCoord y, char const* s, int /*pos*/)
46{
47 if (mPane->FocusDraw()) {
48 ::MoveTo(x, y);
49 LStr255 ps = s;
50 StTextState saver;
51 myFont.Apply();
52 Rect box;
53 box.left = x;
54 box.bottom = y;
55 int iWidth = TextWidth(s,0,strlen(s));
56 box.right = box.left + iWidth;
57 int z;
58 box.top = box.bottom + myFont.GetFontHeight(z,z);
59 ::TETextBox(s,strlen(s),&box,teForceLeft);
60 }
61}
62
63
64/* --Methode-- */
65void PIGraphicMac::DrawLine(PIGrCoord x1, PIGrCoord y1, PIGrCoord x2, PIGrCoord y2)
66{
67 if (mPane->FocusDraw()) {
68 ::MoveTo(x1,y1);
69 ::LineTo(x2,y2);
70 }
71}
72
73
74/* --Methode-- */
75void PIGraphicMac::DrawBox(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
76{
77 if (mPane->FocusDraw()) {
78 Rect r = {y0, x0, (int)y0+(int)dy, (int)x0+(int)dx};
79 if (r.top > r.bottom) swap(r.top, r.bottom);
80 if (r.left > r.right) swap(r.left, r.right);
81 r.right++; r.bottom++;
82 ::FrameRect(&r);
83 }
84}
85
86/* --Methode-- */
87void PIGraphicMac::DrawFBox(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
88{
89 if (mPane->FocusDraw()) {
90 Rect r = {y0, x0, (int)y0+(int)dy, (int)x0+(int)dx};
91 if (r.top > r.bottom) swap(r.top, r.bottom);
92 if (r.left > r.right) swap(r.left, r.right);
93 r.right++; r.bottom++;
94 ::PaintRect(&r);
95 }
96}
97
98/* --Methode-- */
99void PIGraphicMac::DrawCircle(PIGrCoord x0, PIGrCoord y0, PIGrCoord r)
100{
101 if (mPane->FocusDraw()) {
102 Rect rr = {(int)y0-(int)r, (int)x0-(int)r, (int)y0+(int)r, (int)x0+(int)r};
103 if (rr.top > rr.bottom) swap(rr.top, rr.bottom);
104 if (rr.left > rr.right) swap(rr.left, rr.right);
105 ::FrameOval(&rr);
106 }
107}
108
109/* --Methode-- */
110void PIGraphicMac::DrawFCircle(PIGrCoord x0, PIGrCoord y0, PIGrCoord r)
111{
112 if (mPane->FocusDraw()) {
113 Rect rr = {(int)y0-(int)r, (int)x0-(int)r, (int)y0+(int)r, (int)x0+(int)r};
114 if (rr.top > rr.bottom) swap(rr.top, rr.bottom);
115 if (rr.left > rr.right) swap(rr.left, rr.right);
116 ::PaintOval(&rr);
117 }
118}
119
120/* --Methode-- */
121void PIGraphicMac::DrawOval(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
122{
123 if (mPane->FocusDraw()) {
124 Rect rr = {(int)y0-(int)dy, (int)x0-(int)dx, (int)y0+(int)dy, (int)x0+(int)dx};
125 if (rr.top > rr.bottom) swap(rr.top, rr.bottom);
126 if (rr.left > rr.right) swap(rr.left, rr.right);
127 ::FrameOval(&rr);
128 }
129}
130
131/* --Methode-- */
132void PIGraphicMac::DrawFOval(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
133{
134 if (mPane->FocusDraw()) {
135 Rect rr = {(int)y0-(int)dy, (int)x0-(int)dx, (int)y0+(int)dy, (int)x0+(int)dx};
136 if (rr.top > rr.bottom) swap(rr.top, rr.bottom);
137 if (rr.left > rr.right) swap(rr.left, rr.right);
138 ::PaintOval(&rr);
139 }
140}
141
142
143/* --Methode-- */
144void PIGraphicMac::DrawPolygon(PIGrCoord *x, PIGrCoord *y, int n, bool cinc)
145{
146 PolyHandle h = MakePoly(x,y,n);
147 if (h) {
148 ::FramePoly(h);
149 ::KillPoly(h);
150 }
151
152}
153
154/* --Methode-- */
155void PIGraphicMac::DrawFPolygon(PIGrCoord *x, PIGrCoord *y, int n, bool cinc)
156{
157 PolyHandle h = MakePoly(x,y,n);
158 if (h) {
159 ::PaintPoly(h);
160 ::KillPoly(h);
161 }
162}
163
164
165/* --Methode-- */
166void PIGraphicMac::DrawArc(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy,
167 double degdeb, double deltadeg)
168{
169 if (mPane->FocusDraw()) {
170 Rect rr = {(int)y0-(int)dy, (int)x0-(int)dx, (int)y0+(int)dy, (int)x0+(int)dx};
171 if (rr.top > rr.bottom) swap(rr.top, rr.bottom);
172 if (rr.left > rr.right) swap(rr.left, rr.right);
173 ::FrameArc(&rr, degdeb, deltadeg);
174 }
175}
176
177/* --Methode-- */
178void PIGraphicMac::DrawFArc(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy,
179 double degdeb, double deltadeg)
180{
181 if (mPane->FocusDraw()) {
182 Rect rr = {(int)y0-(int)dy, (int)x0-(int)dx, (int)y0+(int)dy, (int)x0+(int)dx};
183 if (rr.top > rr.bottom) swap(rr.top, rr.bottom);
184 if (rr.left > rr.right) swap(rr.left, rr.right);
185 ::PaintArc(&rr, degdeb, deltadeg);
186 }
187}
188
189
190/* --Methode-- */
191PolyHandle PIGraphicMac::MakePoly(PIGrCoord *x, PIGrCoord *y, int n)
192{
193 if (mPane->FocusDraw()) {
194 PolyHandle h = ::OpenPoly();
195 ::MoveTo(x[0], y[0]);
196 for (int i=1; i<n; i++) {
197 ::LineTo(x[i], y[i]);
198 }
199 ::MoveTo(x[0], y[0]);
200 ClosePoly();
201 return h;
202 }
203 return NULL;
204}
205
206
207/* --Methode-- */
208void PIGraphicMac::DrawMarker(PIGrCoord x0, PIGrCoord y0)
209{
210int hmsz = mMrkSz/2;
211int dmsz = mMrkSz-hmsz;
212PIGrCoord x[4],y[4];
213PILineAtt clatt;
214
215if (mMrk == PI_DotMarker) {
216 ::MoveTo( x0, y0);
217 ::Line(0,0);
218}
219
220else
221 {
222 clatt = mLAtt;
223 SelLine(PI_ThinLine);
224 switch (mMrk)
225 {
226 case PI_PlusMarker :
227 DrawLine((int)x0-hmsz, y0, (int)x0+dmsz, y0);
228 DrawLine(x0, (int)y0-hmsz, x0, (int)y0+dmsz);
229 break;
230 case PI_CrossMarker :
231 DrawLine((int)x0-hmsz, (int)y0-hmsz, (int)x0+dmsz, (int)y0+dmsz);
232 DrawLine((int)x0-hmsz, (int)y0+dmsz, (int)x0+dmsz, (int)y0-hmsz);
233 break;
234 case PI_CircleMarker :
235 DrawCircle(x0, y0, hmsz);
236 break;
237 case PI_FCircleMarker :
238 DrawFCircle(x0, y0, hmsz);
239 break;
240 case PI_BoxMarker :
241 DrawBox((int)x0-hmsz, (int)y0-hmsz, mMrkSz, mMrkSz);
242 break;
243 case PI_FBoxMarker :
244 DrawFBox((int)x0-hmsz, (int)y0-hmsz, mMrkSz, mMrkSz);
245 break;
246 case PI_TriangleMarker :
247 x[1] = mMrkSz; y[1] = 0; x[2] = -hmsz; y[2] = -mMrkSz;
248 x[3] = -dmsz; y[3] = +mMrkSz; x[0] = (int)x0-hmsz; y[0] = (int)y0+hmsz;
249 DrawPolygon(x, y, 4);
250 break;
251 case PI_FTriangleMarker :
252 x[1] = mMrkSz; y[1] = 0; x[2] = -hmsz; y[2] = -mMrkSz;
253 x[3] = -dmsz; y[3] = +mMrkSz; x[0] = (int)x0-hmsz; y[0] = (int)y0+hmsz;
254 DrawFPolygon(x, y, 4);
255 break;
256 default :
257 ::MoveTo( x0, y0);
258 ::Line(0,0);
259 break;
260 }
261 SelLine(clatt);
262 }
263return;
264}
265
266/* --Methode-- */
267void PIGraphicMac::DrawMarkers(PIGrCoord *x, PIGrCoord *y, int n)
268{
269int i;
270
271if (n <= 0) return;
272for(i=0; i<n; i++) DrawMarker(x[i], y[i]);
273}
274
275
276/* --Methode-- */
277void PIGraphicMac::DrawPixmap(PIGrCoord x, PIGrCoord y, unsigned char *pix,
278 int sx, int sy, PIColorMap* cmap)
279{
280 Rect frame;
281 SetRect(&frame, 0, 0, sx, sy);
282 Rect dstFrame;
283 SetRect(&dstFrame, x, y, sx, sy);
284 GWorldPtr gWorld;
285 ThrowIfOSErr_(NewGWorld(&gWorld, 8, &frame, cmap->GetCTab(), nil, 0));
286 PixMapHandle pmh = GetGWorldPixMap(gWorld);
287 ::LockPixels (pmh);
288 Ptr pmap = GetPixBaseAddr(pmh);
289 memcpy(pmap, pix, sx*sy);
290 ::ForeColor (blackColor);
291 ::BackColor (whiteColor);
292 ::CopyBits((BitMap *) (*pmh),
293 &mPane->GetMacPort()->portBits,
294 &frame, &dstFrame, srcCopy, nil);
295 ::UnlockPixels (pmh);
296 DisposeGWorld(gWorld);
297}
298
299
300
301/* --Methode-- */
302void PIGraphicMac::SelForeground(PIColors col)
303{
304 if (mPane->FocusDraw()) {
305 long color;
306 switch (col) {
307 case PI_Black:
308 color = blackColor;
309 break;
310 case PI_White:
311 color = whiteColor;
312 break;
313 case PI_Red:
314 color = redColor;
315 break;
316 case PI_Blue:
317 color = blueColor;
318 break;
319 case PI_Green:
320 color = greenColor;
321 break;
322 case PI_Yellow:
323 color = yellowColor;
324 break;
325 default:
326 color = blackColor;
327 }
328 ::ForeColor(color);
329 mFCol = col;
330 }
331}
332
333/* --Methode-- */
334void PIGraphicMac::SelBackground(PIColors col)
335{
336 if (mPane->FocusDraw()) {
337 long color;
338 switch (col) {
339 case PI_Black:
340 color = blackColor;
341 break;
342 case PI_White:
343 color = whiteColor;
344 break;
345 case PI_Red:
346 color = redColor;
347 break;
348 case PI_Blue:
349 color = blueColor;
350 break;
351 case PI_Green:
352 color = greenColor;
353 break;
354 case PI_Yellow:
355 color = yellowColor;
356 break;
357 default:
358 color = blackColor;
359 }
360 mBCol = col;
361 ::BackColor(color);
362 }
363}
364
365/* --Methode-- */
366void PIGraphicMac::SelForeground(PIColorMap& cmap, int cid)
367{
368 if (mPane->FocusDraw()) {
369 PIColor picol = cmap.GetColor(cid);
370 RGBColor qdCol;
371
372 qdCol.red = picol.red;
373 qdCol.green = picol.green;
374 qdCol.blue = picol.blue;
375
376 ::RGBForeColor(&qdCol);
377 }
378}
379
380/* --Methode-- */
381void PIGraphicMac::SelBackground(PIColorMap& cmap, int cid)
382{
383 if (mPane->FocusDraw()) {
384 PIColor picol = cmap.GetColor(cid);
385 RGBColor qdCol;
386
387 qdCol.red = picol.red;
388 qdCol.green = picol.green;
389 qdCol.blue = picol.blue;
390
391 ::RGBBackColor(&qdCol);
392 }
393}
394
395/* --Methode-- */
396void PIGraphicMac::SelGOMode(PIGOMode mod)
397{
398if (mod == mGOm) return;
399 if (mPane->FocusDraw())
400 switch (mod)
401 {
402 case PI_GOCopy :
403 ::PenMode(patCopy);
404 mGOm = mod;
405 break;
406 case PI_GOXOR :
407 ::PenMode(patXor);
408 mGOm = mod;
409 break;
410 }
411return;
412}
413
414
415/* --Methode-- */
416void PIGraphicMac::SelFontSzPt(int npt, PIFontAtt att)
417{
418 myFont.SetFontSzPt(npt);
419 myFont.SetFontAtt(att);
420}
421
422/* --Methode-- */
423void PIGraphicMac::SelFont(PIFontSize sz, PIFontAtt att)
424{
425 myFont.SetFontSz(sz);
426 myFont.SetFontAtt(att);
427}
428
429/* --Methode-- */
430void PIGraphicMac::SelFont(PIFont & fnt)
431{
432 myFont = fnt;
433}
434
435
436/* --Methode-- */
437void PIGraphicMac::SelLine(PILineAtt const & att)
438{
439 if (mPane->FocusDraw()) {
440 switch(att) {
441 case PI_NormalLine:
442 ::PenSize(1,1);
443 break;
444 case PI_ThinLine:
445 ::PenSize(1,1); // Mettre en pointille, ou bien commentaire pour Laser ?
446 break;
447 case PI_ThickLine:
448 ::PenSize(2,2);
449 break;
450 }
451 }
452 mLAtt = att;
453}
454
455
456/* --Methode-- */
457void PIGraphicMac::SelMarker(int msz, PIMarker mrk)
458{
459if (msz > 1) { mMrk = mrk; mMrkSz = msz; }
460else { mMrk = PI_DotMarker; mMrkSz = 1; }
461return;
462}
463
464
465/* --Methode-- */
466void PIGraphicMac::SetClipRectangle(PIGrCoord x0, PIGrCoord y0, PIGrCoord dx, PIGrCoord dy)
467{
468//$CHECK
469}
470
471/* --Methode-- */
472void PIGraphicMac::ClearClipRectangle()
473{
474//$CHECK
475}
476
477/* --Methode-- */
478PIColors PIGraphicMac::GetForeground()
479{
480return (mFCol);
481}
482
483/* --Methode-- */
484PIColors PIGraphicMac::GetBackground()
485{
486return (mBCol);
487}
488
489
490/* --Methode-- */
491PIGOMode PIGraphicMac::GetGOMode()
492{
493return (mGOm);
494}
495
496/* --Methode-- */
497PIFontAtt PIGraphicMac::GetFontAtt()
498{
499return (myFont.GetFontAtt());
500}
501
502/* --Methode-- */
503int PIGraphicMac::GetFontSize()
504{
505return (myFont.GetFontSize());
506}
507
508/* --Methode-- */
509PILineAtt PIGraphicMac::GetLineAtt()
510{
511return (mLAtt);
512}
513
514/* --Methode-- */
515PIMarker PIGraphicMac::GetMarker()
516{
517return (mMrk);
518}
519
520/* --Methode-- */
521int PIGraphicMac::GetMarkerSize()
522{
523return (mMrkSz);
524}
525
526
Note: See TracBrowser for help on using the repository browser.