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

Last change on this file since 369 was 369, checked in by ercodmgr, 26 years ago

pour le mac

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