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

Last change on this file since 89 was 89, checked in by aubourg, 28 years ago

Mac

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