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