Changeset 88 in Sophya for trunk/SophyaPI/PI/pibwdgmac.cc


Ignore:
Timestamp:
Mar 5, 1998, 1:58:53 PM (28 years ago)
Author:
aubourg
Message:

Mac 050398

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/pibwdgmac.cc

    r69 r88  
    77#include <string.h>
    88
     9#define mGraphic mWGrC 
     10
    911// Les methodes de la classe  PIBWdgGen
    1012 
     
    1214PIBaseWdgMac::PIBaseWdgMac(PIContainerGen *par, char *nom,
    1315                       int sx, int sy, int px, int py) :
    14 PIBaseWdgGen(par, nom, sx, sy, px, py),
    15 mFCol(PI_Black), mBCol(PI_White)
     16PIBaseWdgGen(par, nom, sx, sy, px, py)
    1617{
     18    mGraphic = new PIGraphicMac(this);
     19
    1720    mAdapter->AddAttachment(new PIUpdAttachment(this));
    1821    mPane->AddAttachment(new PIUpdAttachment(this));
    1922    cursor = NULL;
     23   
     24
    2025}
    2126
     
    5964}
    6065
    61 /* --Methode-- */
    62 void PIBaseWdgMac::DrawString(int x, int y, char* s, int /*pos*/)
    63 {
    64   if (mPane->FocusDraw()) {
    65     LocalToMacPortPoint(x, y, x, y);
    66     ::MoveTo(x, y);
    67     LStr255 ps = s;
    68     ::TextFont(applFont);
    69     ::DrawString(ps);
    70   }
    71 }
     66
    7267
    7368/* --Methode-- */
    74 void PIBaseWdgMac::DrawOpaqueString(int x, int y, char* s, int /*pos*/)
     69void PIBaseWdgMac::SelPointerShape(PIPointer ptr)
    7570{
     71  CursHandle c;
    7672  if (mPane->FocusDraw()) {
    77     LocalToMacPortPoint(x, y, x, y);
    78     ::MoveTo(x, y);
    79     LStr255 ps = s;
    80     ::TextFont(applFont);
    81         Rect box;
    82         box.left = x;
    83         box.bottom = y;
    84         int iWidth = TextWidth(s,0,strlen(s));
    85         box.right = box.left + iWidth;
    86         int z;
    87         box.top = box.bottom + GetFontHeight(z,z);
    88     ::TETextBox(s,strlen(s),&box,teForceLeft);
     73    switch(ptr) {
     74      case PI_ArrowPointer:
     75        cursor = &qd.arrow;
     76        break;
     77      case PI_CrossPointer:
     78        c = GetCursor(crossCursor);
     79        HLock((Handle)c);
     80        cursor = c ? *c : NULL;
     81        break;
     82      case PI_HandPointer:
     83        c = GetCursor(128);
     84        HLock((Handle)c);
     85        cursor = c ? *c : NULL;
     86        break;
     87    }
    8988  }
    90 }
    91 
    92 /* --Methode-- */
    93 void PIBaseWdgMac::DrawMarker(int x0, int y0)
    94 {
    95 int hmsz = mMrkSz/2;
    96 int dmsz = mMrkSz-hmsz;
    97 int x[4],y[4];
    98 PILineAtt clatt;
    99 
    100 if (mMrk == PI_DotMarker) {
    101     LocalToMacPortPoint(x0, y0, x0, y0);
    102   ::MoveTo( x0, y0);
    103   ::Line(0,0);
    104 }
    105 
    106 else
    107   {
    108   clatt = mLAtt;
    109   SelLine(PI_ThinLine);
    110   switch (mMrk)
    111     {
    112     case  PI_PlusMarker :
    113       DrawLine(x0-hmsz, y0, x0+dmsz, y0);
    114       DrawLine(x0, y0-hmsz, x0, y0+dmsz);
    115       break;
    116     case  PI_CrossMarker :
    117       DrawLine(x0-hmsz, y0-hmsz, x0+dmsz, y0+dmsz);
    118       DrawLine(x0-hmsz, y0+dmsz, x0+dmsz, y0-hmsz);
    119       break; 
    120     case PI_CircleMarker :
    121       DrawCircle(x0, y0, hmsz);
    122       break;
    123     case PI_FCircleMarker :
    124       DrawFCircle(x0, y0, hmsz);
    125       break;
    126     case PI_BoxMarker :
    127       DrawBox(x0-hmsz, y0-hmsz, mMrkSz, mMrkSz);
    128       break;
    129     case PI_FBoxMarker :
    130       DrawFBox(x0-hmsz, y0-hmsz, mMrkSz, mMrkSz);
    131       break;
    132     case  PI_TriangleMarker :
    133       x[1] = mMrkSz; y[1] = 0; x[2] = -hmsz; y[2] = -mMrkSz;
    134       x[3] = -dmsz; y[3] = +mMrkSz; x[0] = x0-hmsz; y[0] = y0+hmsz; 
    135       DrawPolygon(x, y, 4);
    136       break;
    137     case  PI_FTriangleMarker :
    138       x[1] = mMrkSz; y[1] = 0; x[2] = -hmsz; y[2] = -mMrkSz;
    139       x[3] = -dmsz; y[3] = +mMrkSz; x[0] = x0-hmsz; y[0] = y0+hmsz; 
    140       DrawFPolygon(x, y, 4);
    141       break;
    142     default :
    143       ::MoveTo( x0, y0);
    144       ::Line(0,0);
    145       break;
    146     }
    147   SelLine(clatt);
    148   }
    149 return;
    150 }
    151 
    152 /* --Methode-- */
    153 void PIBaseWdgMac::DrawMarkers(int *x, int *y, int n)
    154 {
    155 int i;
    156 
    157 if (n <= 0)  return;
    158 for(i=0; i<n; i++) DrawMarker(x[i], y[i]);
    159 }
    160 
    161 /* --Methode-- */
    162 int PIBaseWdgMac::CalcStringWidth(char const* s)
    163 {
    164   if (mPane->FocusDraw())
    165     ::TextFont(applFont);
    166   return ::TextWidth(s,0,strlen(s));
    167 }
    168 
    169 void PIBaseWdgMac::LocalToMacPortPoint(int x, int y, int& xm, int& ym)
    170 {
    171     Point pt = {y,x};
    172     //mPane->LocalToPortPoint(pt);
    173 //      SPoint32 loc;
    174 //      mPane->GetFrameLocation(loc);
    175 //    xm = pt.h + loc.h;
    176 //    ym = pt.v + loc.v;  // Ou bien ne pas utiliser de Pane, que des View ?
    177     xm = pt.h;
    178     ym = pt.v;
     89  mPtrS = ptr;
    17990}
    18091
    18192
    182 /* --Methode-- */
    183 void PIBaseWdgMac::DrawLine(int x1, int y1, int x2, int y2)
    184 {
    185   if (mPane->FocusDraw()) {
    186     int x,y;
    187     LocalToMacPortPoint(x1, y1, x, y);
    188     ::MoveTo(x,y);
    189     LocalToMacPortPoint(x2, y2, x, y);
    190     ::LineTo(x,y);
    191   }
    192 }
    19393
    19494/* --Methode-- */
    195 void PIBaseWdgMac::DrawBox(int x0, int y0, int dx, int dy)
     95PIPointer  PIBaseWdgMac::GetPointerShape()
    19696{
    197   if (mPane->FocusDraw()) {
    198     int x,y;
    199     LocalToMacPortPoint(x0, y0, x, y);
    200     Rect r = {y, x, y+dy, x+dx};
    201     if (r.top  > r.bottom) swap(r.top,  r.bottom);
    202     if (r.left > r.right)  swap(r.left, r.right);
    203     r.right++; r.bottom++;
    204     ::FrameRect(&r);
    205   }
     97return (mPtrS);
    20698}
    20799
    208100
     101
    209102/* --Methode-- */
    210 void PIBaseWdgMac::DrawFBox(int x0, int y0, int dx, int dy)
     103bool PIBaseWdgMac::AdjustCursor()
    211104{
    212   if (mPane->FocusDraw()) {
    213     int x,y;
    214     LocalToMacPortPoint(x0, y0, x, y);
    215     Rect r = {y, x, y+dy, x+dx};
    216     if (r.top  > r.bottom) swap(r.top,  r.bottom);
    217     if (r.left > r.right)  swap(r.left, r.right);
    218     r.right++; r.bottom++;
    219     ::PaintRect(&r);
     105  if (cursor) {
     106    ::SetCursor(cursor);
     107    return true;
    220108  }
     109  return false;
    221110}
    222111
    223 /* --Methode-- */
    224 void PIBaseWdgMac::DrawCircle(int x0, int y0, int r)
     112/* --Methode--
     113void PIBaseWdgMac::Refresh()
    225114{
    226   if (mPane->FocusDraw()) {
    227     int x,y;
    228     LocalToMacPortPoint(x0, y0, x, y);
    229     Rect rr = {y-r, x-r, y+r, x+r};
    230     if (rr.top  > rr.bottom) swap(rr.top,  rr.bottom);
    231     if (rr.left > rr.right)  swap(rr.left, rr.right);
    232     ::FrameOval(&rr);
    233   }
     115if (mPane->IsVisible())
     116  Draw();
    234117}
    235 
    236 /* --Methode-- */
    237 void PIBaseWdgMac::DrawFCircle(int x0, int y0, int r)
    238 {
    239   if (mPane->FocusDraw()) {
    240     int x,y;
    241     LocalToMacPortPoint(x0, y0, x, y);
    242     Rect rr = {y-r, x-r, y+r, x+r};
    243     if (rr.top  > rr.bottom) swap(rr.top,  rr.bottom);
    244     if (rr.left > rr.right)  swap(rr.left, rr.right);
    245     ::PaintOval(&rr);
    246   }
    247 }
    248 
    249 /* --Methode-- */
    250 void PIBaseWdgMac::DrawPolygon(int *x, int *y, int n)
    251 {
    252   PolyHandle h = MakePoly(x,y,n);
    253   if (h) {
    254     ::FramePoly(h);
    255     ::KillPoly(h);
    256   }
    257 }
     118   J'ai mis cette fonction ds PIWdgMac::IsVisible()    Reza $CHECK$  01/12/97
     119*/
    258120
    259121
    260 /* --Methode-- */
    261 void PIBaseWdgMac::DrawFPolygon(int *x, int *y, int n)
    262 {
    263   PolyHandle h = MakePoly(x,y,n);
    264   if (h) {
    265     ::PaintPoly(h);
    266     ::KillPoly(h);
    267   }
    268 }
    269 /* --Methode-- */
    270 PolyHandle PIBaseWdgMac::MakePoly(int *x, int *y, int n)
    271 {
    272   if (mPane->FocusDraw()) {
    273     PolyHandle h = ::OpenPoly();
    274     int xx,yy;
    275     LocalToMacPortPoint(x[0], y[0], xx, yy);
    276     ::MoveTo(xx, yy);
    277     for (int i=1; i<n; i++) {
    278       LocalToMacPortPoint(x[i], y[i], xx, yy);
    279       ::LineTo(xx, yy);
    280     }
    281     LocalToMacPortPoint(x[0], y[0], xx, yy);
    282     ::MoveTo(xx, yy);
    283     ClosePoly();
    284     return h;
    285   }
    286   return NULL;
    287 }
    288122
    289 
    290 /* --Methode-- */
    291 void PIBaseWdgMac::SelForeground(PIColors col)
    292 {
    293   if (mPane->FocusDraw()) {
    294     long color;
    295     switch (col) {
    296       case PI_Black:
    297         color = blackColor;
    298         break;
    299       case PI_White:
    300         color = whiteColor;
    301         break;
    302       case PI_Red:
    303         color = redColor;
    304         break;
    305       case PI_Blue:
    306         color = blueColor;
    307         break;
    308       case PI_Green:
    309         color = greenColor;
    310         break;
    311       case PI_Yellow:
    312         color = yellowColor;
    313         break;
    314       default:
    315         color = blackColor;
    316     }
    317     ::ForeColor(color);
    318     mFCol = col;
    319   }
    320 }
    321 
    322 /* --Methode-- */
    323 void PIBaseWdgMac::SelBackground(PIColors col)
     123void PIBaseWdgMac::SetBackgroundColor(PIColors col)
    324124{
    325125  if (mPane->FocusDraw()) {
     
    352152}
    353153
    354 /* --Methode-- */
    355 void PIBaseWdgMac::SelGOMode(PIGOMode mod)
    356 {
    357 if (mod == mGOm)  return;
    358   if (mPane->FocusDraw())
    359     switch (mod)
    360     {
    361       case PI_GOCopy :
    362         ::PenMode(patCopy);
    363         mGOm = mod;
    364         break;
    365       case PI_GOXOR :
    366         ::PenMode(patXor);
    367         mGOm = mod;
    368         break;
    369     }
    370 return;
    371 }
    372 
    373 
    374 /* --Methode-- */
    375 void PIBaseWdgMac::SelFont(PIFontSize sz, PIFontAtt att)
    376 {
    377   switch(sz) {
    378       case PI_SmallSizeFont:
    379         SelFontSzPt(9, att);
    380         break;
    381       case PI_NormalSizeFont:
    382         SelFontSzPt(12, att);
    383         break;
    384       case PI_BigSizeFont:
    385         SelFontSzPt(14, att);
    386         break;
    387   }
    388 }
    389 
    390 /* --Methode-- */
    391 void PIBaseWdgMac::SelFontSzPt(int npt, PIFontAtt att)
    392 {
    393   if (mPane->FocusDraw()) {
    394     ::TextFont(applFont);
    395     ::TextSize(npt);
    396     switch(att) {
    397       case PI_RomanFont:
    398         ::TextFace(0);
    399         break;
    400       case PI_BoldFont:
    401         ::TextFace(bold);
    402         break;
    403       case PI_ItalicFont:
    404         ::TextFace(italic);
    405         break;
    406     }
    407   }
    408   mFSize = npt;
    409   mFAtt  = att;
    410 }
    411 
    412 /* --Methode-- */
    413 void PIBaseWdgMac::SelLine(PILineAtt att)
    414 {
    415   if (mPane->FocusDraw()) {
    416     switch(att) {
    417       case PI_NormalLine:
    418         ::PenSize(1,1);
    419         break;
    420       case PI_ThinLine:
    421         ::PenSize(1,1);  // Mettre en pointille, ou bien commentaire pour Laser ?
    422         break;
    423       case PI_ThickLine:
    424         ::PenSize(2,2);
    425         break;
    426     }
    427   }
    428   mLAtt = att;
    429 }
    430 
    431 /* --Methode-- */
    432 void PIBaseWdgMac::SelPointerShape(PIPointer ptr)
    433 {
    434   CursHandle c;
    435   if (mPane->FocusDraw()) {
    436     switch(ptr) {
    437       case PI_ArrowPointer:
    438         cursor = &qd.arrow;
    439         break;
    440       case PI_CrossPointer:
    441         c = GetCursor(crossCursor);
    442         HLock((Handle)c);
    443         cursor = c ? *c : NULL;
    444         break;
    445       case PI_HandPointer:
    446         c = GetCursor(128);
    447         HLock((Handle)c);
    448         cursor = c ? *c : NULL;
    449         break;
    450     }
    451   }
    452   mPtrS = ptr;
    453 }
    454 
    455 /* --Methode-- */
    456 void PIBaseWdgMac::SelMarker(int msz, PIMarker mrk)
    457 {
    458 if (msz > 1)  { mMrk = mrk;  mMrkSz = msz; }
    459 else  { mMrk = PI_DotMarker;  mMrkSz = 1; }
    460 return;
    461 }
    462 
    463 /* --Methode-- */
    464 PIColors  PIBaseWdgMac::GetForeground()
    465 {
    466 return (mFCol);
    467 }
    468 
    469 /* --Methode-- */
    470 PIColors  PIBaseWdgMac::GetBackground()
     154PIColors  PIBaseWdgMac::GetBackgroundColor()
    471155{
    472156return (mBCol);
    473157}
    474 
    475 
    476 /* --Methode-- */
    477 PIGOMode   PIBaseWdgMac::GetGOMode()
    478 {
    479 return (mGOm);
    480 }
    481 
    482 /* --Methode-- */
    483 PIFontAtt  PIBaseWdgMac::GetFontAtt()
    484 {
    485 return (mFAtt);
    486 }
    487 
    488 /* --Methode-- */
    489 int        PIBaseWdgMac::GetFontSize()
    490 {
    491 return (mFSize);
    492 }
    493 
    494 /* --Methode-- */
    495 PILineAtt  PIBaseWdgMac::GetLineAtt()
    496 {
    497 return (mLAtt);
    498 }
    499 
    500 /* --Methode-- */
    501 PIPointer  PIBaseWdgMac::GetPointerShape()
    502 {
    503 return (mPtrS);
    504 }
    505 
    506 /* --Methode-- */
    507 PIMarker   PIBaseWdgMac::GetMarker()
    508 {
    509 return (mMrk);
    510 }
    511 
    512 /* --Methode-- */
    513 int        PIBaseWdgMac::GetMarkerSize()
    514 {
    515 return (mMrkSz);
    516 }
    517 
    518 
    519 
    520 /* --Methode-- */
    521 bool PIBaseWdgMac::AdjustCursor()
    522 {
    523   if (cursor) {
    524     ::SetCursor(cursor);
    525     return true;
    526   }
    527   return false;
    528 }
    529 
    530 /* --Methode--
    531 void PIBaseWdgMac::Refresh()
    532 {
    533 if (mPane->IsVisible())
    534   Draw();
    535 }
    536    J'ai mis cette fonction ds PIWdgMac::IsVisible()    Reza $CHECK$  01/12/97
    537 */
    538 
    539 
    540 
    541 void PIBaseWdgMac::DrawPixmap(int x, int y, unsigned char *pix,
    542                             int sx, int sy, PIColorMap* cmap)
    543 {
    544   Rect  frame;
    545   SetRect(&frame, 0, 0, sx, sy);
    546   Rect dstFrame;
    547   SetRect(&dstFrame, x, y, sx, sy);
    548   GWorldPtr gWorld;
    549   ThrowIfOSErr_(NewGWorld(&gWorld, 8, &frame, cmap->GetCTab(), nil, 0));
    550   PixMapHandle pmh = GetGWorldPixMap(gWorld);
    551   ::LockPixels (pmh);
    552   Ptr pmap = GetPixBaseAddr(pmh);
    553   memcpy(pmap, pix, sx*sy);
    554   ::ForeColor (blackColor);
    555   ::BackColor (whiteColor);
    556   ::CopyBits((BitMap *) (*pmh),
    557                                 &mPane->GetMacPort()->portBits,
    558                                 &frame, &dstFrame, srcCopy, nil);
    559   ::UnlockPixels (pmh);
    560   DisposeGWorld(gWorld);
    561 }
    562 
    563 void PIBaseWdgMac::SetClipRectangle(int x0, int y0, int dx, int dy)
    564 {  // $CHECK$
    565 }
    566 
    567 void PIBaseWdgMac::ClearClipRectangle()
    568 { // $CHECK$
    569 }
    570 
    571 /* --Methode-- */
    572 int PIBaseWdgMac::GetFontHeight(int& asc, int& desc)   
    573 {
    574   if (mPane->FocusDraw()) {
    575     FontInfo info;
    576     GetFontInfo(&info);
    577     asc = info.ascent;
    578     desc = info.descent;
    579     return (asc + desc);
    580   } else {
    581     return 0;
    582   }
    583 }
Note: See TracChangeset for help on using the changeset viewer.