home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / RIFED / DEMO3.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-22  |  3.7 KB  |  101 lines

  1. // Demonstracni program pro Editor rastrovych fontu.
  2. // Toto demo nacita data fontu ze souboru. Je odladeno s prekladacem
  3. // BORLAND C++ 3.0, nastavuje graficky rezim VGA, pracuje s mysi.
  4. // Preklada se pod projektem, ve kterem je definicni soubor tridy
  5. // RIFONT.CPP a tento demonstracni program.
  6.  
  7. #include "rifont.h"
  8.  
  9. //pomocne promenne a funkce pro demo program:
  10.  
  11. // !!! POZOR !!!  nasledujici cestu k adresari s fonty, nastavte svou vlastni
  12. char cesta[]={"g:\\borlandc\\fed_11\\"};
  13.  
  14. char complcesta[65];         // cesta vc. nazvu souboru
  15. char names[256];             // pole nazvu souboru
  16. int  tento;                  // zvoleny soubor ke zobrazeni
  17. int  items, itmax=16;        // pocet souboru, max. pocet souboru
  18. int  read_names(void);       // precte max. 16 nazvu souboru typu .rif
  19. void names_show(void);       // zobrazi nazvy souboru
  20. void test_text (void);       // zobrazi zkusebni text zvoleneho fontu
  21. RIFONT myfont;                 // globalni instance tridy FONT
  22.  
  23. //------------------------------- MAIN -------------------------------------
  24.  
  25. void main(void) {
  26.   int mys_x, mys_y, mys_b;
  27.   GrInit();
  28.   // v souboru RIFONT.CPP je uvedena cesta "..\\bgi\\" a muze zpusobit chybu.
  29.   // Pri potizich udejte uplnou cestu k vasemu adresari bgi.              // graficky rezim VGA
  30.   setfillstyle(SOLID_FILL, LIGHTGRAY);
  31.   bar(0,0,639,479);
  32.   setcolor(BLACK);
  33.   if(read_names())
  34.     outtextxy(20, 400, "Kliknete mysi na vybrane jmeno fontu");
  35.   outtextxy(20, 420, "Program ukonci stisk nektere klavesy");
  36.   mouse_init();                       // inicializace mysi
  37.   mouse_show();
  38.  
  39.   do {
  40.     mouse_pos(&mys_x, &mys_y, &mys_b);
  41.     if (mys_b) {                     // zjenoduseny test kiknuti mysi
  42.        if(mys_x>10 && mys_x<120 && mys_y>50 && mys_y<(50+20*items)) {
  43.      tento=(mys_y-50)/20;        // vypocet vybrane polozky (jmena fontu)
  44.      sprintf(complcesta, "%s%s", cesta, &names[14*tento]);
  45.                      // vytvoreni cesty s nazvem souboru
  46.      myfont.load(complcesta);    // nacteni dat fontu
  47.      test_text();                // zkusebni vypis
  48.        }
  49.     }
  50.   }  while(kbhit()==0);              // cekaci smycka na stisk klavesy
  51.   getch();
  52.   closegraph();
  53.   return;
  54. }
  55.  
  56. //---------------------- pomocne funkce -----------------------------------
  57.  
  58. int read_names(void) {        // cteni dostupnych souboru s fontovymi daty
  59.   struct ffblk ffblk;
  60.   int done;
  61.   items=0;
  62.   sprintf(complcesta, "%s%s", cesta, "*.rif");  //
  63.   done=findfirst(complcesta, &ffblk, 0);
  64.   if(done!=0) {
  65.     outtextxy(10, 15, "nenalezen adresar s fonty");
  66.     return 0;
  67.   }
  68.   while( !done && items<itmax) {                //
  69.     strcpy(&names[14*items], ffblk.ff_name);    //
  70.     items++;
  71.     done=findnext(&ffblk);
  72.   }
  73.   names_show();
  74.   return 1;
  75. }
  76. void names_show(void) {
  77.   mouse_hide();
  78.   setfillstyle(SOLID_FILL, WHITE);
  79.   for(int i=0; i<items; i++) {
  80.     setcolor(WHITE);                       // simulovany obrazek tlacitka
  81.     line(10, 50+20*i, 120, 50+20*i);
  82.     line(10, 50+20*i, 10,  68+20*i);
  83.     setcolor(DARKGRAY);
  84.     line(10, 68+20*i, 120, 68+20*i);
  85.     line(120,50+20*i, 120, 68+20*i);
  86.     setcolor(BLACK);
  87.     outtextxy(20, 20*i+56, &names[14*i]);  // nazev souboru
  88.   }
  89.   mouse_show();
  90. }
  91. void test_text(void) {
  92.   mouse_hide();
  93.   setfillstyle(SOLID_FILL, WHITE);    // nehlida preteceni textu z ramecku
  94.   bar3d(150, 50, 500, 220, 0, 0);     // libovolne testovaci texty:
  95.   myfont.showtext(160, 60, "Ukßzkov² text zvolenΘho fontu :");
  96.   myfont.showtext(160, 100, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  97.   myfont.showtext(160, 124,"abcdefghijklmnopqrstuvwxyz");
  98.   myfont.showtext(160, 148,"0123456789+-*/@#$%^&()[]{}");
  99.   myfont.showtext(160, 172,"JeÜt∞ troÜiΦku ╚eÜtiny");
  100.   mouse_show();
  101. }