Changeset 1896 in Sophya


Ignore:
Timestamp:
Feb 7, 2002, 7:22:56 PM (24 years ago)
Author:
ansari
Message:

Implementation de DrawCompString() et test ds pist.cc - Reza 07/02/2002

Location:
trunk/SophyaPI/PI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/Tests/pist.cc

    r1854 r1896  
    4848                         int sx=10, int sy=10, int px=0, int py=0);
    4949  virtual         ~StringPosDrawWdg();
     50
     51// Traitement des evenements   
     52//  virtual void   Resize();
     53  virtual void   Draw(PIGraphic* g, int x0, int y0, int dx, int dy);
     54
     55protected:
     56};
     57
     58// ---- Declaration de la classe CompStringDrawWdg --------
     59class CompStringDrawWdg : public StringDrawWdg
     60{
     61public:
     62// Les methodes ...
     63
     64                  CompStringDrawWdg(PIContainerGen *par, char *nom,
     65                                    int sx=10, int sy=10, int px=0, int py=0);
     66  virtual         ~CompStringDrawWdg();
    5067
    5168// Traitement des evenements   
     
    419436
    420437/* ........................................................... */
     438/*     Classe CompStringDrawWdg (Implementation des methodes)             */
     439/* ........................................................... */
     440
     441/* --Methode-- */
     442CompStringDrawWdg::CompStringDrawWdg(PIContainerGen *par, char *nom,
     443                       int sx, int sy, int px, int py)
     444: StringDrawWdg(par, nom, sx, sy, px, py)
     445
     446{
     447}
     448
     449/* --Methode-- */
     450CompStringDrawWdg::~CompStringDrawWdg()
     451{
     452}
     453 
     454
     455/* --Methode-- */
     456void CompStringDrawWdg::Draw(PIGraphicGen* g, int /*x0*/, int /*y0*/, int /*dx*/, int /*dy*/)
     457{
     458PIFontAtt att[4] = { PI_RomanFont, PI_BoldFont, PI_ItalicFont, PI_BoldItalicFont};
     459PIFontSize fsz[5] = { PI_TinySizeFont, PI_SmallSizeFont, PI_NormalSizeFont,
     460                      PI_BigSizeFont, PI_HugeSizeFont };
     461PIFontName fn[4] = { PI_CourierFont, PI_HelveticaFont,
     462                     PI_TimesFont, PI_SymbolFont};
     463char * fnstr[4] = { "Courier-Font", "Helvetica-Font",
     464                     "Times-Font", "Symbol-Font"};
     465char * attstr[4] = { "RomanFont" , "BoldFont", "ItalicFont", "BoldItalicFont"};
     466char * fszstr[5] = { "TinySizeFont", "SmallSizeFont", "NormalSizeFont",
     467                      "BigSizeFont", "HugeSizeFont" };
     468
     469if (g->kind() != PI_PSFileGraphics ) EraseWindow();
     470
     471
     472int ia=0, js=0;
     473int k;
     474for(k=0; k<4; k++)
     475  if (att[k] == mFAtt)  {ia = k; break; }
     476for(k=0; k<5; k++)
     477  if (fsz[k] == mFSize)  {js = k; break; }
     478
     479if ((mFSize != mSFSize) || (mFAtt != mSFAtt))
     480  for(k=0; k<10; k++)
     481    mSL[k] = mSH[k] = 0;
     482PIFont f(14, PI_DefaultFont, mFAtt);
     483g->SelFont(f);
     484g->SelForeground(PI_Black);
     485g->SelLine(PI_ThinLine);
     486
     487g->DrawString(20,24,"StringDraw");
     488g->DrawString(XSize()/5,24,attstr[ia]);
     489g->DrawString(XSize()/3,24,fszstr[js]);
     490
     491
     492PIFont fx(14,fn[2]);
     493fx.SetFontSz(mFSize);
     494fx.SetFontAtt(mFAtt);
     495g->SelFont(fx);
     496int fh,fa,fd;
     497fh = fx.GetFontHeight(fa, fd);
     498cout << " FontSize= " << f.GetFontSize() << " FontHeight= " << fh << endl;
     499
     500g->DrawCompString(XSize()/2,40,"10","-34",NULL);
     501g->DrawCompString(XSize()/2+60,40,"10","+78",NULL);
     502g->DrawCompString(XSize()/2+120,40, "10", NULL, "a");
     503
     504int xpos, ypos;
     505char *s, *su, *sd;
     506
     507// --------------- Vertical Top -----------------
     508
     509xpos = 30;  ypos = 75;
     510s = "HLeftVTop";
     511su = "824";
     512sd = "ij";
     513g->SelForeground(PI_Red);
     514g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     515g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     516g->SelForeground(PI_Black);
     517g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalLeft|PI_VerticalTop);
     518
     519xpos = XSize()/2;  ypos = 75;
     520s = "HCenVTop";
     521su = "76843";
     522sd = "abc";
     523g->SelForeground(PI_Red);
     524g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     525g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     526g->SelForeground(PI_Black);
     527g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalCenter|PI_VerticalTop);
     528
     529xpos = XSize()-30;  ypos = 75;
     530s = "HRigVTop";
     531su = "76843";
     532sd = "abc";
     533g->SelForeground(PI_Red);
     534g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     535g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     536g->SelForeground(PI_Black);
     537g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalRight|PI_VerticalTop);
     538
     539// --------------- Vertical Center -----------------
     540xpos = 30;  ypos = 150;
     541s = "HLeftVCen";
     542su = "32987";
     543sd = NULL;
     544g->SelForeground(PI_Red);
     545g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     546g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     547g->SelForeground(PI_Black);
     548g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalLeft|PI_VerticalCenter);
     549
     550xpos = XSize()/2;  ypos = 150;
     551s = "HCenVCen";
     552su = "32987";
     553sd = "klm";
     554g->SelForeground(PI_Red);
     555g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     556g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     557g->SelForeground(PI_Black);
     558g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalCenter|PI_VerticalCenter);
     559
     560xpos = XSize()-30;  ypos = 150;
     561s = "HRigVCen";
     562su = "2";
     563sd = "alpha";
     564g->SelForeground(PI_Red);
     565g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     566g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     567g->SelForeground(PI_Black);
     568g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalRight|PI_VerticalCenter);
     569
     570// --------------- Vertical BaseLine -----------------
     571xpos = 30;  ypos = 250;
     572s = "HLeftVBas";
     573su = "3";
     574sd = "beta";
     575g->SelForeground(PI_Red);
     576g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     577g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     578g->SelForeground(PI_Black);
     579g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalLeft|PI_VerticalBaseLine);
     580
     581xpos = XSize()/2;  ypos = 250;
     582s = "HCenVBas";
     583su = "gamma";
     584sd = "44";
     585g->SelForeground(PI_Red);
     586g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     587g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     588g->SelForeground(PI_Black);
     589g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalCenter|PI_VerticalBaseLine);
     590
     591xpos = XSize()-30;  ypos = 250;
     592s = "HRigVBas";
     593su = "55";
     594sd = "alpha";
     595g->SelForeground(PI_Red);
     596g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     597g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     598g->SelForeground(PI_Black);
     599g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalRight|PI_VerticalBaseLine);
     600
     601// --------------- Vertical Bottom -----------------
     602xpos = 30;  ypos = 325;
     603s = "HLeftVBot";
     604su = "abc";
     605sd = "6";
     606g->SelForeground(PI_Red);
     607g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     608g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     609g->SelForeground(PI_Black);
     610g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalLeft|PI_VerticalBottom);
     611
     612xpos = XSize()/2;  ypos = 325;
     613s = "HCentVBot";
     614su = NULL;
     615sd = "lm";
     616g->SelForeground(PI_Red);
     617g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     618g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     619g->SelForeground(PI_Black);
     620g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalCenter|PI_VerticalBottom);
     621
     622xpos = XSize()-30;  ypos = 325;
     623s = "HLeftVBot";
     624su = NULL;
     625sd = NULL;
     626g->SelForeground(PI_Red);
     627g->DrawLine(xpos-50, ypos, xpos+50, ypos);
     628g->DrawLine(xpos, ypos-10, xpos, ypos+10);
     629g->SelForeground(PI_Black);
     630g->DrawCompString(xpos, ypos, s, su, sd, PI_HorizontalRight|PI_VerticalBottom);
     631 
     632return;
     633}
     634
     635/* ........................................................... */
    421636/*                       Classe PITApp                         */
    422637/* ........................................................... */
     
    447662m[0]->AppendItem("StringDrawWdg", 10101);
    448663m[0]->AppendItem("StringPosDrawWdg", 10102);
     664m[0]->AppendItem("CompStringDrawWdg", 10103);
    449665m[0]->AppendItem("->eps", 10111);
    450666m[0]->AppendItem("->ps", 10112);
     
    521737      wp->SetAutoDelChilds(true);
    522738      StringPosDrawWdg* exb  = new StringPosDrawWdg(wp, "sposdrawwdg", 600, 400, 0, 0);
     739      exb->SetBinding(PIBK_fixed,PIBK_elastic,PIBK_elastic,PIBK_elastic);
     740      wp->SetUserData(exb);
     741      wp->Show();
     742      }
     743    break;
     744
     745    case 10103: // Creation d'un StringPosDrawWdg
     746      {
     747      nbwin++;
     748      sprintf(strg, "Creation CompStringDrawWdg   \n Fenetre No %d ", nbwin);
     749      sprintf(strg,"CompStringDrawWdg - %d", nbwin);
     750      PIWindow* wp = new PIWindow(this, strg, PIWK_normal,  600, 400, 150, 150);
     751      wp->SetAutoDelChilds(true);
     752      CompStringDrawWdg* exb  = new CompStringDrawWdg(wp, "compposdrawwdg", 600, 400, 0, 0);
    523753      exb->SetBinding(PIBK_fixed,PIBK_elastic,PIBK_elastic,PIBK_elastic);
    524754      wp->SetUserData(exb);
  • trunk/SophyaPI/PI/pigraphgen.cc

    r1893 r1896  
    196196                             const char* s_up, const char* s_dn, int pos)
    197197{
    198   // AFAIREREZA012002
     198  if ((s_up == NULL) && (s_dn == NULL)) {
     199    if (s != NULL)  DrawString(x,y,s,pos);
     200    return;
     201  }
     202
     203  int fh,fas,fds;
     204  fh = myFont.GetFontHeight(fas, fds);
     205  int sw_s = 0;
     206  if (s != NULL) sw_s = myFont.GetStringWidth(s);
     207
     208  PIFont fnt_save(myFont);
     209  PIFont fnt_ss(myFont);
     210  fnt_ss.SetFontSzPt(2*myFont.GetFontSize()/3);
     211
     212  int sw_sup = 0;
     213  if (s_up != NULL) sw_sup = fnt_ss.GetStringWidth(s_up);
     214  int sw_sdn = 0;
     215  if (s_dn != NULL) sw_sdn = fnt_ss.GetStringWidth(s_dn);
     216
     217  PIGrCoord xs,ys;
     218  int posh = pos & PI_HorizontalPosition;
     219  int posv = pos & PI_VerticalPosition;
     220
     221  int dyu, dyd;
     222  dyu = -fh/2;  dyd = fh/2-fh/5;
     223  if (posv == PI_VerticalBaseLine) {
     224    dyu = -fh/2;  dyd = fh/2-fh/5;
     225    }
     226  else if (posv == PI_VerticalBottom) {
     227    dyu = -fh/2-fds;  dyd = fh/2-fh/5-fds;
     228    }
     229  else if (posv == PI_VerticalCenter) {
     230    dyu = -fds;  dyd = fh-fh/5-fds;
     231  }
     232  else if (posv == PI_VerticalTop) {
     233    dyu = fh/2-fds;  dyd = 3*fh/2-fh/5-fds;
     234  }
     235
     236  int deltaposx = ((fh/8) > 0) ? fh/8 : 1;
     237
     238
     239  if ((pos == 0) || ((posh == PI_HorizontalLeft) && (posv == PI_VerticalBaseLine))) {
     240    if (s != NULL)  DrawString(x, y, s, 0);
     241    xs = (int)x+sw_s+deltaposx;
     242    ys = (int)y+dyu;
     243    SelFont(fnt_ss);
     244    if (s_up != NULL) DrawString(xs, ys, s_up, 0);
     245    ys = (int)y+dyd;
     246    if (s_dn != NULL) DrawString(xs, ys, s_dn, 0);
     247  }
     248  else {
     249    if (posh == PI_HorizontalRight) {
     250      int sw_ss_max = ( sw_sup > sw_sdn ) ? sw_sup : sw_sdn;
     251      xs = (int)x-sw_ss_max-deltaposx;
     252      if (s != NULL)  DrawString(xs, y, s, PI_HorizontalRight | posv);
     253      SelFont(fnt_ss);
     254      xs = (int)xs+deltaposx;
     255      ys = (int)y+dyu;
     256      if (s_up != NULL) DrawString(xs, ys, s_up, 0);
     257      ys = (int)y+dyd;
     258      if (s_dn != NULL) DrawString(xs, ys, s_dn, 0);     
     259    }
     260    else if (posh == PI_HorizontalCenter) {
     261      int sw_tot = sw_sup+sw_sdn+sw_s+deltaposx;
     262      xs = (int)x-sw_tot/2+sw_s;
     263      if (s != NULL)  DrawString(xs, y, s, PI_HorizontalRight | posv);
     264      SelFont(fnt_ss);
     265      xs = (int)xs+deltaposx;
     266      ys = (int)y+dyu;
     267      if (s_up != NULL) DrawString(xs, ys, s_up, 0);
     268      ys = (int)y+dyd;
     269      if (s_dn != NULL) DrawString(xs, ys, s_dn, 0);           
     270    }
     271    else {
     272      if (s != NULL)  DrawString(x, y, s, posv);
     273      SelFont(fnt_ss);
     274      xs = (int)x+sw_s+deltaposx;
     275      ys = (int)y+dyu;
     276      if (s_up != NULL) DrawString(xs, ys, s_up, 0);
     277      ys = (int)y+dyd;
     278      if (s_dn != NULL) DrawString(xs, ys, s_dn, 0);
     279    }
     280  }
     281  SelFont(fnt_save);
     282  return;
    199283}
    200284
     
    564648//      Des constructeurs et des méthodes de conversion à partir
    565649//      et vers des "int", "float" et "double" sont définis.
    566 //      L'objet conserve le type effectif de l'argument lors de la
    567 //      création ou de la dernière affectation.
     650//      La valeur entiere d'un objet PIGrCoord construite à partir
     651//      d'une valeur flottante (ou suite à une affectation) correpond
     652//      à l'entier le plus proche.
    568653//
    569 //|     PIGrCoord gco;
    570 //|     gco = 3.141596 ;
     654//|     PIGrCoord gco = 3.14;
    571655//|     int ic = gco;     // ic -> 3
    572 //|     float fc = gco;   // fc -> 3.141596
     656//|     float fc = gco;   // fc -> 3.14
     657//|     gco = 1.1;        // (int)gco -> 1
     658//|     gco = 1.6;        // (int)gco -> 2
     659//|     gco = -0.4;       // (int)gco -> 0
     660//|     gco = -0.7;       // (int)gco -> -1
    573661//--
    574662//++
Note: See TracChangeset for help on using the changeset viewer.