[181] | 1 | #include <stdlib.h>
|
---|
| 2 | #include <stdio.h>
|
---|
| 3 | #include <string.h>
|
---|
| 4 |
|
---|
| 5 | #include <iostream.h>
|
---|
| 6 |
|
---|
| 7 | #include "pisysdep.h"
|
---|
| 8 | #include PIAPP_H
|
---|
| 9 | #include PIWIN_H
|
---|
| 10 | #include PIMENU_H
|
---|
| 11 | #include PISTDWDG_H
|
---|
| 12 | #include PIBWDG_H
|
---|
| 13 | #include "piscdrawwdg.h"
|
---|
| 14 | #include "pievthandler.h"
|
---|
| 15 | #include "parradapter.h"
|
---|
| 16 |
|
---|
[1933] | 17 | #include "piyfxdrw.h"
|
---|
[181] | 18 |
|
---|
| 19 | /* Exemple d'utilisation PIBaseWdg - Creation d'une nouvelle composante graphique */
|
---|
| 20 |
|
---|
| 21 | // ---- Declaration de la classe ExBWdg --------
|
---|
| 22 | class ExBWdg : public PIBaseWdg
|
---|
| 23 | {
|
---|
| 24 | public:
|
---|
| 25 | // Les methodes ...
|
---|
| 26 |
|
---|
| 27 | ExBWdg(PIContainerGen *par, char *nom,
|
---|
| 28 | int sx=10, int sy=10, int px=0, int py=0);
|
---|
| 29 | virtual ~ExBWdg();
|
---|
| 30 |
|
---|
| 31 | // Traitement des evenements
|
---|
| 32 | // virtual void Resize();
|
---|
| 33 | virtual void Draw(PIGraphic* g, int x0, int y0, int dx, int dy);
|
---|
| 34 |
|
---|
| 35 | virtual void But1Press(int x, int y);
|
---|
| 36 | virtual void But1Release(int x, int y);
|
---|
| 37 | virtual void But2Press(int x, int y);
|
---|
| 38 | virtual void But2Release(int x, int y);
|
---|
| 39 | virtual void But3Press(int x, int y);
|
---|
| 40 | virtual void But3Release(int x, int y);
|
---|
| 41 | virtual void Keyboard(int key, PIKeyModifier kmod);
|
---|
| 42 |
|
---|
| 43 | protected:
|
---|
| 44 | int mfnt, mmrk;
|
---|
| 45 | int nc;
|
---|
| 46 | char str[32];
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | /* ........................................................... */
|
---|
| 51 | /* Classe ExBWdg (Implementation des methodes) */
|
---|
| 52 | /* ........................................................... */
|
---|
| 53 |
|
---|
| 54 | /* --Methode-- */
|
---|
| 55 | ExBWdg::ExBWdg(PIContainerGen *par, char *nom,
|
---|
| 56 | int sx, int sy, int px, int py)
|
---|
| 57 | : PIBaseWdg(par, nom, sx, sy, px, py)
|
---|
| 58 |
|
---|
| 59 | {
|
---|
| 60 | mmrk = mfnt = nc = 0;
|
---|
| 61 | strcpy(str, "Hello !");
|
---|
| 62 | for(int i=strlen(str); i<20; i++) str[i] = ' ';
|
---|
| 63 | str[20] = '\0';
|
---|
| 64 |
|
---|
| 65 | ActivateKeyboard();
|
---|
| 66 | ActivateButton(1);
|
---|
| 67 | ActivateButton(2);
|
---|
| 68 | ActivateButton(3);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /* --Methode-- */
|
---|
| 72 | ExBWdg::~ExBWdg()
|
---|
| 73 | {
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /* --Methode--
|
---|
| 77 | void ExBWdg::Resize()
|
---|
| 78 | {
|
---|
| 79 | }
|
---|
| 80 | */
|
---|
| 81 |
|
---|
| 82 | /* --Methode-- */
|
---|
| 83 | void ExBWdg::Draw(PIGraphicGen* g, int /*x0*/, int /*y0*/, int /*dx*/, int /*dy*/)
|
---|
| 84 | {
|
---|
[1563] | 85 | PIFontAtt att[4] = { PI_RomanFont, PI_BoldFont, PI_ItalicFont, PI_BoldItalicFont};
|
---|
[2138] | 86 | PIFontSize fsz[4] = { PI_TinySizeFont, PI_SmallSizeFont, PI_NormalSizeFont, PI_LargeSizeFont};
|
---|
[403] | 87 | PIMarker pmk[11] = { PI_DotMarker , PI_PlusMarker, PI_CrossMarker,
|
---|
[181] | 88 | PI_CircleMarker, PI_FCircleMarker,
|
---|
| 89 | PI_BoxMarker, PI_FBoxMarker,
|
---|
[403] | 90 | PI_TriangleMarker, PI_FTriangleMarker,
|
---|
| 91 | PI_StarMarker, PI_FStarMarker };
|
---|
[1563] | 92 |
|
---|
| 93 | if (g->kind() != PI_PSFileGraphics ) EraseWindow();
|
---|
| 94 |
|
---|
[181] | 95 | g->SelMarker(8, pmk[mmrk]);
|
---|
| 96 |
|
---|
| 97 | g->SelLine(PI_NormalLine);
|
---|
| 98 | g->DrawBox(10,10, XSize()-20, YSize()-20);
|
---|
| 99 |
|
---|
| 100 | g->SelLine(PI_ThinLine);
|
---|
| 101 | g->DrawFBox(20, 20, 20, 20);
|
---|
| 102 | g->DrawCircle(30, 30, 15);
|
---|
| 103 |
|
---|
| 104 | g->SelForeground(PI_Red);
|
---|
| 105 | g->DrawFCircle(70, 30, 15);
|
---|
| 106 |
|
---|
| 107 | g->SelForeground(PI_Yellow);
|
---|
| 108 | g->DrawFBox(10, 60, 120, 20);
|
---|
| 109 |
|
---|
[382] | 110 | PIFont f0;
|
---|
| 111 | g->SelFont(f0);
|
---|
[181] | 112 | g->SelForeground(PI_Black);
|
---|
| 113 | g->DrawString(20, 110, str);
|
---|
[382] | 114 | PIFont f(PI_TimesFont);
|
---|
[1563] | 115 | f.SetFontSz(fsz[mfnt]);
|
---|
[382] | 116 | g->SelFont(f);
|
---|
| 117 | g->DrawString(20, 130, "Times-Font");
|
---|
[1563] | 118 | PIFont f2(14,PI_CourierFont, att[mfnt]);
|
---|
[382] | 119 | g->SelFont(f2);
|
---|
[1563] | 120 | g->SelForeground(PI_Red);
|
---|
| 121 | g->DrawString(20, 150, "Courier-Font");
|
---|
| 122 | PIFont f3(14,PI_TimesFont, att[mfnt]);
|
---|
[382] | 123 | g->SelFont(f3);
|
---|
[1563] | 124 | g->SelForeground(PI_Blue);
|
---|
| 125 | g->DrawString(20, 170, "Times-Font");
|
---|
| 126 | PIFont f4(14,PI_HelveticaFont, att[mfnt]);
|
---|
[382] | 127 | g->SelFont(f4);
|
---|
[1563] | 128 | g->SelForeground(PI_Black);
|
---|
| 129 | g->DrawString(20, 190, "Helvetica-Font");
|
---|
[403] | 130 | PIFont f5(14,PI_SymbolFont);
|
---|
[382] | 131 | g->SelFont(f5);
|
---|
| 132 | g->DrawString(20, 210, "Symbol-Font");
|
---|
[402] | 133 | g->SelFont(f0);
|
---|
[181] | 134 |
|
---|
[382] | 135 |
|
---|
[181] | 136 | g->SelLine(PI_ThinLine);
|
---|
| 137 | g->DrawLine(20, 140, 50, 130);
|
---|
| 138 | g->SelLine(PI_NormalLine);
|
---|
| 139 | g->DrawLine(50, 140, 80, 130);
|
---|
| 140 | g->SelLine(PI_ThickLine);
|
---|
| 141 | g->DrawLine(80, 140, 110, 130);
|
---|
| 142 |
|
---|
| 143 | g->SelForeground(PI_Magenta);
|
---|
| 144 | g->DrawFCircle(120, 30, 15);
|
---|
| 145 | g->SelForeground(PI_Grey);
|
---|
| 146 | g->DrawFCircle(120, 60, 15);
|
---|
| 147 |
|
---|
[382] | 148 |
|
---|
| 149 |
|
---|
| 150 |
|
---|
[403] | 151 | PIGrCoord x[5] = { 150, 165, 180, 195, 210 };
|
---|
| 152 | PIGrCoord y[5] = { 50, 50, 50, 50, 50 };
|
---|
[181] | 153 |
|
---|
| 154 | g->SelForeground(PI_Black);
|
---|
| 155 | g->DrawMarkers(x, y, 5);
|
---|
| 156 | return;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 |
|
---|
| 160 | static char strbuff[128];
|
---|
| 161 | /* --Methode-- */
|
---|
| 162 | void ExBWdg::But1Press(int x, int y)
|
---|
| 163 | {
|
---|
| 164 | SelPointerShape(PI_CrossPointer);
|
---|
| 165 | sprintf(strbuff,"Pos X= %d Y= %d", x, y);
|
---|
| 166 | mWGrC->SelFont(PI_NormalSizeFont, PI_BoldFont);
|
---|
| 167 | mWGrC->DrawString(x+10, y, strbuff);
|
---|
| 168 | Send(Msg(), PIMsg_Active);
|
---|
| 169 | return;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | /* --Methode-- */
|
---|
| 173 | void ExBWdg::But1Release(int x, int y)
|
---|
| 174 | {
|
---|
| 175 | SelPointerShape(PI_ArrowPointer);
|
---|
| 176 | Refresh();
|
---|
| 177 | return;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | /* --Methode-- */
|
---|
| 181 | void ExBWdg::But2Press(int x, int y)
|
---|
| 182 | {
|
---|
[1563] | 183 | if (++mfnt > 3) mfnt = 0;
|
---|
[403] | 184 | if (++mmrk > 10) mmrk = 0;
|
---|
[181] | 185 | return;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | /* --Methode-- */
|
---|
| 189 | void ExBWdg::But2Release(int x, int y)
|
---|
| 190 | {
|
---|
| 191 | Refresh();
|
---|
| 192 | return;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | /* --Methode-- */
|
---|
| 196 | void ExBWdg::But3Press(int x, int y)
|
---|
| 197 | {
|
---|
| 198 | SelPointerShape(PI_HandPointer);
|
---|
| 199 | mWGrC->SelForeground(PI_Blue);
|
---|
| 200 | mWGrC->DrawFBox(XSize()/3, YSize()/3, XSize()/8, YSize()/8);
|
---|
| 201 | return;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | /* --Methode-- */
|
---|
| 205 | void ExBWdg::But3Release(int x, int y)
|
---|
| 206 | {
|
---|
| 207 | mWGrC->SelForeground(PI_White);
|
---|
| 208 | mWGrC->DrawFBox(XSize()/3, YSize()/3, XSize()/8, YSize()/8);
|
---|
| 209 | mWGrC->SelForeground(PI_Black);
|
---|
| 210 | SelPointerShape(PI_ArrowPointer);
|
---|
| 211 | return;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | /* --Methode-- */
|
---|
| 215 | void ExBWdg::Keyboard(int key, PIKeyModifier kmod)
|
---|
| 216 | {
|
---|
| 217 | str[nc] = key; str[nc+1] = '\0';
|
---|
| 218 | if (++nc > 30) nc = 0;
|
---|
| 219 | char buf[16];
|
---|
| 220 |
|
---|
| 221 | if (key == PIK_Return) { Refresh(); nc = 0; return; }
|
---|
| 222 | mWGrC->SelFont(PI_NormalSizeFont, PI_BoldFont);
|
---|
| 223 | sprintf(buf," %c (%3d) ", (char) key, key, (int)kmod);
|
---|
| 224 | mWGrC->DrawOpaqueString(20, 75, buf);
|
---|
| 225 |
|
---|
| 226 | if ( (kmod == PIKM_Alt) && (key == 'c') ) {
|
---|
| 227 | printf("ExBWdg::Keyboard: Test-Copy ... \n");
|
---|
| 228 | ClaimSelection();
|
---|
| 229 | }
|
---|
| 230 | if ( (kmod == PIKM_Alt) && (key == 'v') ) {
|
---|
| 231 | printf("ExBWdg::Keyboard: Test-Paste ... \n");
|
---|
| 232 | RequestSelection();
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | return;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | // ----- Exemple d'une classe heritant de PIScDrawWdg ----
|
---|
| 239 | /* ........................................................... */
|
---|
| 240 | /* Classe ScSample */
|
---|
| 241 | /* ........................................................... */
|
---|
| 242 |
|
---|
| 243 | class ScSample : public PIScDrawWdg {
|
---|
| 244 | public:
|
---|
| 245 | ScSample(PIContainerGen *par, char *nom,
|
---|
| 246 | int sx=10, int sy=10, int px=0, int py=0);
|
---|
| 247 | virtual ~ScSample();
|
---|
| 248 | };
|
---|
| 249 |
|
---|
| 250 | static double fpol(double x) {return (0.3*x*x*x-x*x+7.);}
|
---|
| 251 | static float xpts[10] = {-2.4, -2 , -1., 1., 1.7, 2.2, 3., 3.75, 4.3, 4.8};
|
---|
| 252 | static float ypts[10] = {-5 , -1.5, 2.5, 5., 8.0, 12., 9., 6.00, 2.2, -3.0};
|
---|
| 253 |
|
---|
| 254 | ScSample::ScSample(PIContainerGen *par, char *nom,
|
---|
| 255 | int sx, int sy, int px, int py)
|
---|
| 256 | :PIScDrawWdg(par, nom, sx, sy, px, py)
|
---|
| 257 |
|
---|
| 258 | {
|
---|
| 259 | // Definition des limites
|
---|
| 260 | SetLimits(-3,5,-10,15);
|
---|
| 261 |
|
---|
| 262 | // Creation et ajout d'un drawer de fonctions
|
---|
| 263 | PIFuncDrawer* mfd = new PIFuncDrawer(fpol);
|
---|
[1933] | 264 | mfd->GetGraphicAtt().SetColAtt(PI_Blue);
|
---|
| 265 | mfd->GetGraphicAtt().SetLineAtt(PI_NormalLine);
|
---|
[181] | 266 | AddScDrawer(mfd,true);
|
---|
| 267 |
|
---|
| 268 | // Creation et ajout d'un drawer de points
|
---|
| 269 | PIYfXDrawer* mxyd = new PIYfXDrawer(new P1DAdapter<float>(xpts, 10, false),
|
---|
| 270 | new P1DAdapter<float>(ypts, 10, false), true);
|
---|
[1933] | 271 | mxyd->GetGraphicAtt().SetColAtt(PI_Magenta);
|
---|
| 272 | mxyd->GetGraphicAtt().SetMarkerAtt(7, PI_FBoxMarker);
|
---|
[181] | 273 | AddScDrawer(mxyd, true);
|
---|
| 274 |
|
---|
| 275 | // Ajout de texte
|
---|
[1933] | 276 | BaseDrawer()->GetGraphicAtt().SetFontAtt(PI_NormalSizeFont, PI_BoldFont);
|
---|
[2302] | 277 | PIGraphicAtt gatt;
|
---|
| 278 | gatt.SetColAtt(PI_Red);
|
---|
| 279 | BaseDrawer()->ElDrwMgr().ElAddText(-2.8, 12., "---- ScSample ----", gatt, 0);
|
---|
| 280 | BaseDrawer()->ElDrwMgr().ElAddText(-2.8, 10., "f(x)=0.3*x^3-x^2+7.", gatt, 0);
|
---|
[181] | 281 |
|
---|
| 282 | SetAxesFlags(kAxesDflt);
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | ScSample::~ScSample()
|
---|
| 286 | {
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | // ----------- Une classe EventHandler ----------
|
---|
| 290 | class MyEvHandler : public PIEventHandler {
|
---|
| 291 | public :
|
---|
| 292 | MyEvHandler();
|
---|
| 293 | ~MyEvHandler();
|
---|
| 294 | virtual void Draw(PIGraphic* g, int x0, int y0, int dx, int dy);
|
---|
| 295 | virtual void ProcessEvent();
|
---|
| 296 | inline bool GrabOK() { return(grabok); }
|
---|
| 297 |
|
---|
| 298 | protected :
|
---|
| 299 | PIScreenBuffer* mscb;
|
---|
| 300 | int mposx, mposy;
|
---|
| 301 | int mposx2, mposy2;
|
---|
| 302 | int msx, msy;
|
---|
| 303 | bool grabok;
|
---|
| 304 | };
|
---|
| 305 |
|
---|
| 306 | /* --Methode-- */
|
---|
| 307 | MyEvHandler::MyEvHandler()
|
---|
| 308 | : PIEventHandler()
|
---|
| 309 | {
|
---|
| 310 | mscb = new PIScreenBuffer(100, 100);
|
---|
| 311 | msx = 100; msy = 100;
|
---|
| 312 | mposx = mposy = 0;
|
---|
| 313 | mposx2 = mposy2 = 0;
|
---|
| 314 | grabok = false;
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | /* --Methode-- */
|
---|
| 318 | MyEvHandler::~MyEvHandler()
|
---|
| 319 | {
|
---|
| 320 | delete mscb;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | /* --Methode-- */
|
---|
| 324 | void MyEvHandler::Draw(PIGraphic* g, int, int, int, int)
|
---|
| 325 | {
|
---|
| 326 | if (GrabOK()) {
|
---|
| 327 | printf("MyEvHandler::Draw() : Copying from ScreenBuffer to wdg (%lx) \n", (unsigned long)CurrentWdg());
|
---|
| 328 | mscb->CopyToWdg(CurrentWdg(), 0, 0, msx, msy, CurrentWdg()->XSize()/2, CurrentWdg()->YSize()/2);
|
---|
| 329 | }
|
---|
| 330 | else printf("MyEvHandler::Draw() : Grab first from source \n");
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | /* --Methode-- */
|
---|
| 334 | void MyEvHandler::ProcessEvent()
|
---|
| 335 | {
|
---|
| 336 | printf("MyEvHandler::ProcessEvent() \n");
|
---|
| 337 | switch (EventType()) {
|
---|
| 338 |
|
---|
| 339 | case PIEvent_But3Press :
|
---|
| 340 | mposx = GetPosX();
|
---|
| 341 | mposy = GetPosY();
|
---|
| 342 | break;
|
---|
| 343 |
|
---|
| 344 | case PIEvent_But3Release :
|
---|
| 345 | mposx2 = GetPosX();
|
---|
| 346 | mposy2 = GetPosY();
|
---|
| 347 | printf("MyEvHandler::ProcessEvent(): Rectangle(%d,%d - %d,%d) \n", mposx, mposy, mposx2, mposy2);
|
---|
| 348 | // ((PIBaseWdg*)CurrentWdg())->WindowGraphic()->DrawBox(mposx, mposy, (mposx2-mposx), (mposy2-mposy));
|
---|
| 349 | break;
|
---|
| 350 |
|
---|
| 351 | case PIEvent_Keyboard :
|
---|
| 352 | if ((GetKeyMod() == PIKM_Alt) && ((GetKey() == 'G') || (GetKey() == 'g')) ) {
|
---|
| 353 | printf("MyEvHandler::ProcessEvent(): Grabbing(%dx%d) from Wdg(%lx)@(%d,%d) \n",
|
---|
| 354 | msx, msy, (unsigned long)CurrentWdg(), mposx, mposy);
|
---|
| 355 | mscb->CopyFromWdg(CurrentWdg(), mposx, mposy, msx, msy, 0, 0);
|
---|
| 356 | grabok = true;
|
---|
| 357 | }
|
---|
| 358 | break;
|
---|
| 359 |
|
---|
| 360 | default :
|
---|
| 361 | printf("MyEvHandler::ProcessEvent(): Unexpected Event (Type = %d) received \n", (int)EventType());
|
---|
| 362 | break;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | return;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | /* ........................................................... */
|
---|
| 369 | /* Classe PITApp */
|
---|
| 370 | /* ........................................................... */
|
---|
| 371 | class PITApp : public PIApplication {
|
---|
| 372 | public:
|
---|
| 373 | PITApp(int narg=0, char* arg[]=NULL);
|
---|
| 374 | ~PITApp();
|
---|
| 375 | virtual void Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
|
---|
| 376 | private :
|
---|
| 377 | PIMenu* m[2];
|
---|
| 378 | PIText* txt;
|
---|
| 379 | MyEvHandler* evh;
|
---|
| 380 | PIWindow* mcurwin;
|
---|
| 381 | PIWdg* mdrhw;
|
---|
| 382 | PIWdg* mevhw;
|
---|
| 383 | PIWdg* mcurw;
|
---|
| 384 | };
|
---|
| 385 |
|
---|
| 386 |
|
---|
| 387 | /* --Methode-- */
|
---|
| 388 | PITApp::PITApp(int narg, char* arg[])
|
---|
| 389 | : PIApplication(300, 100, narg, arg)
|
---|
| 390 | {
|
---|
| 391 |
|
---|
| 392 | // Menus, les numeros ds AppendItem sont les numeros de messages
|
---|
| 393 | // qui seront passes a Process() et permettent d'identifier l'action
|
---|
| 394 |
|
---|
| 395 | // Creation du premier menu
|
---|
| 396 |
|
---|
| 397 | m[0] = new PIMenu(Menubar(),"Actions");
|
---|
| 398 | m[0]->AppendItem("Info", 10101);
|
---|
| 399 | m[0]->AppendItem("New ExBwdg", 10102);
|
---|
| 400 | m[0]->AppendItem("New ScSample", 10103);
|
---|
[382] | 401 | m[0]->AppendItem("->eps", 10111);
|
---|
[181] | 402 | m[0]->AppendItem("Exit", 10105);
|
---|
| 403 | // On accroche le menu au Menubar
|
---|
| 404 | AppendMenu(m[0]);
|
---|
| 405 |
|
---|
| 406 | m[1] = new PIMenu(Menubar(),"Edit");
|
---|
| 407 | m[1]->AppendItem("Copy", 10201);
|
---|
| 408 | m[1]->AppendItem("Paste", 10202);
|
---|
| 409 | // On accroche le menu au Menubar
|
---|
| 410 | AppendMenu(m[1]);
|
---|
| 411 |
|
---|
| 412 | // Creation d' zone texte multiligne
|
---|
[323] | 413 | txt = new PIText(MainWin(), "mltext", true, true, 290, 90, 5, 5);
|
---|
[181] | 414 | txt->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
|
---|
[323] | 415 | // txt->SetMutiLineMode(true);
|
---|
[181] | 416 | txt->SetTextEditable(false);
|
---|
| 417 | txt->SetText("");
|
---|
| 418 |
|
---|
| 419 | evh = new MyEvHandler;
|
---|
| 420 | mcurwin = NULL;
|
---|
| 421 | mcurw = NULL;
|
---|
| 422 | mdrhw = NULL;
|
---|
| 423 | mdrhw = NULL;
|
---|
| 424 | SetReady();
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | /* --Methode-- */
|
---|
| 428 | PITApp::~PITApp()
|
---|
| 429 | {
|
---|
| 430 | delete m[0]; delete m[1]; delete txt;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
[382] | 433 | static int numpsf = 0;
|
---|
[181] | 434 | static int nbwin = 0;
|
---|
| 435 | /* --Methode-- */
|
---|
| 436 | void PITApp::Process(PIMessage msg, PIMsgHandler* sender, void* /*data*/)
|
---|
| 437 | {
|
---|
| 438 |
|
---|
| 439 | char strg[256];
|
---|
| 440 |
|
---|
| 441 | // Gestion des actions en fonctions des messages
|
---|
| 442 |
|
---|
| 443 | if ( ( ModMsg(msg) == PIMsg_Active) || (ModMsg(msg) == PIMsg_Close) ) {
|
---|
| 444 | PIWdg *sndw;
|
---|
| 445 | sndw = (PIWdg *)sender;
|
---|
| 446 | if (sndw->kind() == PIWindow::ClassId) {
|
---|
| 447 | if (ModMsg(msg) == PIMsg_Close) {
|
---|
| 448 | // printf("PITApp::Process()/Debug : Closing Window %lx \n", (long)sender);
|
---|
| 449 | if (mcurwin->UserData() == mcurw) mcurw = NULL;
|
---|
| 450 | if (mcurwin->UserData() == mdrhw) mdrhw = NULL;
|
---|
| 451 | if (mcurwin->UserData() == mevhw) mevhw = NULL;
|
---|
| 452 | delete (PIWindow *)sender;
|
---|
| 453 | mcurwin = NULL;
|
---|
| 454 | }
|
---|
| 455 | else mcurwin = (PIWindow *)sender;
|
---|
| 456 | }
|
---|
| 457 | else if ( ModMsg(msg) == PIMsg_Active) mcurw = sndw;
|
---|
| 458 | }
|
---|
| 459 |
|
---|
| 460 | else switch(UserMsg(msg)) {
|
---|
| 461 |
|
---|
| 462 | case 10101: // Info
|
---|
| 463 | txt->SetText("pit1: PITApp \n PIBaseWdg - PIScDrawWdg test \n ExBWdg (:PIBaseWdg) Creation \n ScSample (:PIScDrawWdg) creation");
|
---|
| 464 | break;
|
---|
| 465 |
|
---|
| 466 | case 10102: // Creation d'un ExBWdg
|
---|
| 467 | {
|
---|
| 468 | nbwin++;
|
---|
| 469 | sprintf(strg, "Creation ExBwdg \n Fenetre No %d \n Test keyborard, button 1/2/3", nbwin);
|
---|
| 470 | txt->SetText(strg);
|
---|
| 471 | sprintf(strg,"Window %d - ExBwdg", nbwin);
|
---|
| 472 | PIWindow* wp = new PIWindow(this, strg, PIWK_normal, 250, 250, 150, 150);
|
---|
| 473 | wp->SetAutoDelChilds(true);
|
---|
| 474 | ExBWdg* exb = new ExBWdg(wp, "bwdg", 250, 250, 0, 0);
|
---|
| 475 | exb->SetBinding(PIBK_fixed,PIBK_elastic,PIBK_elastic,PIBK_elastic);
|
---|
| 476 | wp->SetUserData(exb);
|
---|
| 477 | wp->Show();
|
---|
| 478 | }
|
---|
| 479 | break;
|
---|
| 480 |
|
---|
| 481 | case 10103: // Creation d'un ScSample
|
---|
| 482 | {
|
---|
| 483 | nbwin++;
|
---|
| 484 | sprintf(strg, "Creation Scsample \n Fenetre No %d \n Button 1 -> mouse position \n Button 2 -> Zoom \n keyboard <Alt>O <Alt>V", nbwin);
|
---|
| 485 | txt->SetText(strg);
|
---|
| 486 | sprintf(strg,"Window %d - ScSample", nbwin);
|
---|
| 487 | PIWindow* wp = new PIWindow(this, strg, PIWK_normal, 400, 400, 200, 200);
|
---|
| 488 | wp->SetAutoDelChilds(true);
|
---|
| 489 | ScSample* sc = new ScSample(wp, "scsample", 400, 400, 0, 0);
|
---|
| 490 | sc->SetBinding(PIBK_elastic,PIBK_elastic,PIBK_elastic,PIBK_elastic);
|
---|
| 491 | wp->SetUserData(sc);
|
---|
| 492 | wp->Show();
|
---|
| 493 | }
|
---|
| 494 | break;
|
---|
| 495 |
|
---|
[382] | 496 | case 10111: // -> eps
|
---|
| 497 | if (mcurwin) {
|
---|
| 498 | char buff[64];
|
---|
| 499 | sprintf(buff, "pit_%d.eps", numpsf); numpsf++;
|
---|
| 500 | printf("Creating EPS File %s (Encapsulated PostScript) \n", buff);
|
---|
| 501 | PSFile *mps;
|
---|
| 502 | mps = new PSFile(buff);
|
---|
| 503 | mcurwin->PSPrint(mps,0,0);
|
---|
| 504 | delete mps;
|
---|
| 505 | }
|
---|
| 506 | break;
|
---|
[181] | 507 | case 10105: // Sortie d'application
|
---|
| 508 | Stop();
|
---|
| 509 | break;
|
---|
| 510 |
|
---|
| 511 |
|
---|
| 512 | case 10201: // 2 eme menu Copy
|
---|
| 513 | if (mcurw == NULL) { printf("PITApp::Process()/Warning : Select a window for copy \n");
|
---|
| 514 | sprintf(strg, "Warning : Select a window for copy");
|
---|
| 515 | txt->SetText(strg);
|
---|
| 516 | }
|
---|
| 517 | else {
|
---|
| 518 | printf("Adding EventHandler to Wdg %lx", (long)mcurw);
|
---|
| 519 | sprintf(strg, "Adding EventHandler to Wdg %lx \n, Use button 3 to select copy zone \n, <Alt>G to Get copy",
|
---|
| 520 | (long)mcurw);
|
---|
| 521 | txt->SetText(strg);
|
---|
| 522 | if (mevhw != NULL) mevhw->RemoveEventHandler(evh); mevhw = NULL;
|
---|
| 523 | mcurw->AddEventHandler(evh, PIEvent_But3Press | PIEvent_But3Release | PIEvent_Keyboard, false);
|
---|
| 524 | }
|
---|
| 525 | break;
|
---|
| 526 |
|
---|
| 527 | case 10202: // 2eme Menu - Paste
|
---|
| 528 | if (mcurw == NULL) { printf("PITApp::Process()/Warning : Select a window for paste \n");
|
---|
| 529 | sprintf(strg, "Warning : Select a window for paste");
|
---|
| 530 | txt->SetText(strg);
|
---|
| 531 | }
|
---|
| 532 | else {
|
---|
| 533 | printf("Adding DrawHandler to Wdg %lx \n - Refreshing Wdg", (long)mcurw);
|
---|
| 534 | sprintf(strg, "Adding DrawHandler to Wdg %lx \n - Refreshing Wdg", (long)mcurw);
|
---|
| 535 | txt->SetText(strg);
|
---|
| 536 | mcurw->AddDrawHandler(evh, false);
|
---|
| 537 | mdrhw = mcurw;
|
---|
| 538 | ((PIBaseWdg*)mcurw)->Refresh();
|
---|
| 539 | }
|
---|
| 540 | break;
|
---|
| 541 |
|
---|
| 542 | default :
|
---|
| 543 | // printf("PITApp::Process() Msg= %d (%d - %d)??? \n",
|
---|
| 544 | // (int)msg, (int)UserMsg(msg),(int)ModMsg(msg));
|
---|
| 545 | break;
|
---|
| 546 |
|
---|
| 547 | }
|
---|
| 548 | return;
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 |
|
---|
| 552 | // ................................................................
|
---|
| 553 | // programme principal
|
---|
| 554 | // ................................................................
|
---|
| 555 |
|
---|
| 556 | int main(int narg, char *arg[])
|
---|
| 557 | {
|
---|
| 558 | if ( (narg > 1) && (strcmp(arg[1],"-h") == 0) ) {
|
---|
| 559 | printf("pit1 : ExBWdg (:PIBaseWdg) / ScSample (:PIScDrawWdg) test \n");
|
---|
| 560 | printf(" Usage : pit1 [Xt options] \n");
|
---|
| 561 | }
|
---|
| 562 | // Creation de l'objet application et appel de Run()
|
---|
| 563 | PITApp* app = new PITApp(narg, arg);
|
---|
| 564 | // puts("appel de Application.Run() ... ");
|
---|
| 565 | app->Run();
|
---|
| 566 |
|
---|
| 567 | delete app;
|
---|
| 568 | exit(0);
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 |
|
---|