home *** CD-ROM | disk | FTP | other *** search
/ Hot Shareware 35 / hot35.iso / ficheros / LC / SIMPMO24.ZIP / SIMPMOUS.ZIP / MOUTUT.C < prev    next >
C/C++ Source or Header  |  1997-08-14  |  11KB  |  599 lines

  1. # include <dos.h>
  2. # include <string.h>
  3. # include <stdio.h>
  4. # include <bios.h>
  5. # include <stdlib.h>
  6. # include <conio.h>
  7. # include <mem.h>
  8. # include <dir.h>
  9.  
  10. # include "simpwin.h"
  11. # include "swskdef.h"
  12. # include "mouse23.h"
  13. # include "fontedit.h"
  14. # include "egacolor.h"
  15.  
  16. # define MAIN_WIN 1
  17. # define MAIN_MENU 0
  18. # define QUIT_WIN 4
  19. # define TUT_WIN 2
  20. # define TUT_MENU 1
  21. # define FUNC_WIN 3
  22. # define FUNC_MENU 2
  23. # define TXT_WIN 5
  24.  
  25.  
  26. int mou_switch;
  27. int display_switch = 1;
  28. int buttons;
  29.  
  30. int main_menu(void);
  31. int quit(void);
  32. int tutor_menu(void);
  33. int function_menu(void);
  34. int demo_menu(void);
  35. int file_screen(char *file_name);
  36. int text_screen(int file_num);
  37. int mouse_demo(void);
  38.  
  39. void main(void)
  40. {
  41.     int i,j,k;
  42.  
  43.     if(init_window(5,3,4,"",1) != 0)
  44.     {
  45.         cprintf("Can't init simple windows!");
  46.         exit(1);
  47.     }
  48.     system("cls");
  49.  
  50.     if((mouinit() == 0) | ((buttons = mouinstalled()) != 0))
  51.     {
  52.         simp_window(30,10,50,12,1,0,14,4,0,0,0,0,0);
  53.         if(loadcurs("moucurs.fnt") == 0)
  54.         {
  55.             mouhide();
  56.             mousetposition(1,1);
  57.             mou_switch = 1;
  58.             write_window(3,2,"Mouse Installed !");
  59.         }
  60.         else
  61.         {
  62.             mou_switch = 0;
  63.             write_window(3,2,"No cursor file !");
  64.             delay(1000);
  65.             uninit_window();
  66.             system("CLS");
  67.             exit(1);
  68.         }
  69.         delay(1000);
  70.     }
  71.     else
  72.     {
  73.         simp_window(23,10,57,12,1,0,14,4,0,0,0,0,0);
  74.         write_window(3,2,"NO mouse driver installed");
  75.         mou_switch = 0;
  76.         delay(1000);
  77.         uninit_window();
  78.         system("CLS");
  79.         exit(1);
  80.     }
  81.     if(load_menu_text("moutut.men") != 0)
  82.     {
  83.         system("cls");
  84.         cprintf("Can't find file MOUTUT.MEN !");
  85.         uninit_window();
  86.         exit(1);
  87.     }
  88.     if(load_win_data("moutut.win") != 0)
  89.     {
  90.         system("cls");
  91.         cprintf("Can't find file MOUTUT.WIN !");
  92.         uninit_window();
  93.         exit(1);
  94.     }
  95.     hide_cursor();
  96.     k= 3;
  97.     for(i = 0;i < 13;i++)
  98.     {
  99.         for(j = k - 3;j < k;j++)
  100.         {
  101.             simp_window(40 - j,13 - i,40 + j,13 + i,1,0,15,1,0,0,0,0,0);
  102.         }
  103.         k = k + 3;
  104.     }
  105.     simp_window(1,1,80,25,1,0,15,1,0,0,0,0,0);
  106.     k = 3;
  107.     for(i = 0;i < 13;i++)
  108.     {
  109.         for(j = k - 3;j < k;j++)
  110.         {
  111.             window(40 - j,13 - i,40 + j,13 + i);
  112.             load_screen_form(0,"moutut.scr");
  113.         }
  114.         k = k + 3;
  115.     }
  116.     window(1,1,80,25);
  117.     load_screen_form(0,"moutut.scr");
  118.     write_window(35,25," HIT ANY KEY ");
  119.     bioskey(0);
  120.     draw_horizontal_line(196,196,196,2,79,25);
  121.     save_screen(1);
  122.     moucursortype(0x01);
  123.     moushow();
  124.     while(main_menu())
  125.     {
  126.     }
  127.     uninit_window();
  128.     mouuninit();
  129.     show_cursor();
  130.     system("cls");
  131. }
  132.  
  133. int main_menu(void)
  134. {
  135.     int pick,choice,i = 0,old_i = 9,mousex = 0,mousey = 0;
  136.     char lable[3][13] = {"Demo","Tutor","eXit"};
  137.  
  138.  
  139.     if(display_switch)
  140.     {
  141.         load_screen(1);
  142.         call_window(MAIN_WIN);
  143.         call_menu(MAIN_MENU,3,2);
  144.         save_screen(2);
  145.     }
  146.     else
  147.     {
  148.         load_screen(2);
  149.     }
  150.     display_switch = 1;
  151.     textcolor(4);
  152.     write_window(3,2,"D");
  153.     write_window(22,2,"T");
  154.     write_window(41,2,"X");
  155.     save_screen_buff();
  156.     i = 0;
  157.     moushow();
  158.     for(;;)
  159.     {
  160.         choice = 0;
  161.         if(mouposition(&mousex,&mousey))
  162.         {
  163.             if(mousey == 4)
  164.             {
  165.                 if((mousex > 5) & (mousex < 12))
  166.                 {
  167.                     i = 0;
  168.                 }
  169.                 else if((mousex > 24) & (mousex < 31))
  170.                 {
  171.                     i = 1;
  172.                 }
  173.                 else if((mousex > 42) & (mousex < 49))
  174.                 {
  175.                     i = 2;
  176.                 }
  177.             }
  178.         }
  179.         if(bioskey(1) | (mou_switch == 0))
  180.         {
  181.             switch(bioskey(0))
  182.             {
  183.                 case ESC : choice = 4; break;
  184.                 case CURSOR_RIGHT : i = i + 1; break;
  185.                 case CURSOR_LEFT : i = i - 1; break;
  186.                 case ENTER : choice = 1; break;
  187.                 case ALT_D : choice = 2; break;
  188.                 case ALT_T : choice = 3; break;
  189.                 case ALT_X : choice = 4; break;
  190.             }
  191.         }
  192.         if(i < 0)
  193.         {
  194.             i = 0;
  195.         }
  196.         if(i > 2)
  197.         {
  198.             i = 2;
  199.         }
  200.         if(old_i != i)
  201.         {
  202.             mouhide();
  203.             old_i = i;
  204.             load_screen_buff();
  205.             switch(i)
  206.             {
  207.                 case 0 : simp_window(6,4,11,4,0,2,0,4,1,8,0,0,0); break;
  208.                 case 1 : simp_window(25,4,31,4,0,2,0,4,1,8,0,0,0); break;
  209.                 case 2 : simp_window(43,4,48,4,0,2,0,4,1,8,0,0,0); break;
  210.             }
  211.             write_window(2,1,"%s",lable[i]);
  212.             moushow();
  213.         }
  214.         if(moubuttonpressed(LEFTBUTTON))
  215.         {
  216.             if(mousey == 4)
  217.             {
  218.                 if(((mousex > 5) & (mousex < 12)) |
  219.                     ((mousex > 24) & (mousex < 31)) |
  220.                     ((mousex > 42) & (mousex < 49)))
  221.                 {
  222.                     choice = 1;
  223.                 }
  224.             }
  225.         }
  226.         if(choice != 0)
  227.         {
  228.             break;
  229.         }
  230.     }
  231.     mouhide();
  232.     load_screen_buff();
  233.     if(choice == 1)
  234.     {
  235.         choice = i + 2;
  236.     }
  237.     pick = 1;
  238.     switch(choice)
  239.     {
  240.         case 2 : mouse_demo(); break;
  241.         case 3 : while(tutor_menu()){} break;
  242.         case 4 : pick = quit(); break;
  243.     }
  244.     return(pick);
  245. }
  246.  
  247. int quit(void)
  248. {
  249.  
  250.     call_window(QUIT_WIN);
  251.     write_window(3,2,"Quit Y/N ?");
  252.     show_cursor();
  253.     if(get_choice(14,2,"N") == 1)
  254.     {
  255.         uncall_window(QUIT_WIN);
  256.         hide_cursor();
  257.         return(0);
  258.     }
  259.     uncall_window(QUIT_WIN);
  260.     hide_cursor();
  261.     return(1);
  262. }
  263.  
  264. int tutor_menu(void)
  265. {
  266.     int pick,choice,i = 0,old_i = 9,mousex = 0,mousey = 0;
  267.     char lable[4][19] = {"General","Support","Functions","A word"};
  268.  
  269.     if(display_switch)
  270.     {
  271.         if(display_switch == 1)
  272.         {
  273.             load_screen(2);
  274.         }
  275.         call_window(TUT_WIN);
  276.         call_menu(TUT_MENU,3,2);
  277.         save_screen(3);
  278.     }
  279.     else
  280.     {
  281.         load_screen(3);
  282.     }
  283.     display_switch = 1;
  284.     textcolor(4);
  285.     write_window(3,2,"G");
  286.     write_window(3,3,"S");
  287.     write_window(3,4,"F");
  288.     write_window(3,5,"A");
  289.     save_screen_buff();
  290.     i = 0;
  291.     moushow();
  292.     for(;;)
  293.     {
  294.         choice = 0;
  295.         if(mouposition(&mousex,&mousey))
  296.         {
  297.             if((mousex > 20) & (mousex < 30))
  298.             {
  299.                 i = mousey - 5;
  300.             }
  301.         }
  302.         if(bioskey(1) | (mou_switch == 0))
  303.         {
  304.             switch(bioskey(0))
  305.             {
  306.                 case ESC : choice = 7; break;
  307.                 case CURSOR_DN : i = i + 1; break;
  308.                 case CURSOR_UP : i = i - 1; break;
  309.                 case ENTER : choice = 1; break;
  310.                 case ALT_G : choice = 2; break;
  311.                 case ALT_S : choice = 3; break;
  312.                 case ALT_F : choice = 4; break;
  313.                 case ALT_A : choice = 5; break;
  314.             }
  315.         }
  316.         if(i < 0)
  317.         {
  318.             i = 0;
  319.         }
  320.         if(i > 3)
  321.         {
  322.             i = 3;
  323.         }
  324.         if(old_i != i)
  325.         {
  326.             old_i = i;
  327.             mouhide();
  328.             load_screen_buff();
  329.             simp_window(21,5 + i,31,5 + i,0,2,0,4,1,8,0,0,0);
  330.             write_window(2,1,"%s",lable[i]);
  331.             moushow();
  332.         }
  333.         if(moubuttonpressed(LEFTBUTTON))
  334.         {
  335.             if((mousex > 20) & (mousex < 30) & (mousey > 4) & (mousey < 9))
  336.             {
  337.                 choice = 1;
  338.             }
  339.             else
  340.             {
  341.                 choice = 7;
  342.             }
  343.         }
  344.         if(choice != 0)
  345.         {
  346.             break;
  347.         }
  348.     }
  349.     mouhide();
  350.     load_screen_buff();
  351.     pick = 1;
  352.     if(choice == 1)
  353.     {
  354.         choice = i + 2;
  355.     }
  356.     switch(choice)
  357.     {
  358.         case 2 : file_screen("mougenrl.txt"); break;
  359.         case 3 : text_screen(3); break;
  360.         case 4 : while(function_menu()){} break;
  361.         case 5 : text_screen(4);
  362.         case 7 : pick = 0; break;
  363.     }
  364.     display_switch = pick;
  365.     return(pick);
  366. }
  367.  
  368. int function_menu(void)
  369. {
  370.     int pick,choice,i = 0,old_i = 12,mousex = 0,mousey = 0;
  371.     char lable[15][29] = {"mouinstall\(\)","moureset\(\)","moubuttonpressed\(\)",
  372.                 "moubuttonrelease\(\)","mouposition\(\)","moupositionpix\(\)",
  373.                 "mousetposition\(\)","mousetmaxposition\(\)","mouhide\(\)",
  374.                 "moushow\(\)","loadcurs\(\)","mou_get_adapter\(\)",
  375.                 "mouinit\(\)","mouuninit\(\)","moucursortype\(\)"};
  376.  
  377.     if(display_switch)
  378.     {
  379.         load_screen(3);
  380.         call_window(FUNC_WIN);
  381.         call_menu(FUNC_MENU,3,2);
  382.         save_screen(4);
  383.     }
  384.     else
  385.     {
  386.         load_screen(4);
  387.     }
  388.     display_switch = 1;
  389.     save_screen_buff();
  390.     moushow();
  391.     i = 0;
  392.     for(;;)
  393.     {
  394.         choice = 0;
  395.         if(mouposition(&mousex,&mousey))
  396.         {
  397.             if((mousex > 22) & (mousex < 46))
  398.             {
  399.                 i = mousey - 6;
  400.             }
  401.         }
  402.         if(bioskey(1) | (mou_switch == 0))
  403.         {
  404.             switch(bioskey(0))
  405.             {
  406.                 case ESC : choice = 12; break;
  407.                 case CURSOR_DN : i = i + 1; break;
  408.                 case CURSOR_UP : i = i - 1; break;
  409.                 case ENTER: choice = 1; break;
  410.             }
  411.         }
  412.         if(i < 0)
  413.         {
  414.             i = 0;
  415.         }
  416.         if(i > 14)
  417.         {
  418.             i = 14;
  419.         }
  420.         if(old_i != i)
  421.         {
  422.             old_i = i;
  423.             mouhide();
  424.             load_screen_buff();
  425.             simp_window(23,6 + i,47,6 + i,0,2,0,4,1,8,0,0,0);
  426.             write_window(2,1,"%s",lable[i]);
  427.             moushow();
  428.         }
  429.         if(moubuttonpressed(LEFTBUTTON))
  430.         {
  431.             if((mousex > 22) & (mousex < 46) & (mousey > 5) & (mousey < 21))
  432.             {
  433.                 choice = 1;
  434.             }
  435.             else
  436.             {
  437.                 choice = 12;
  438.             }
  439.         }
  440.         if(choice != 0)
  441.         {
  442.             break;
  443.         }
  444.     }
  445.     mouhide();
  446.     load_screen_buff();
  447.     pick = 1;
  448.     if(choice == 1)
  449.     {
  450.         text_screen(i + 5);
  451.     }
  452.     else
  453.     {
  454.         if(choice == 12)
  455.         {
  456.             pick = 0;
  457.         }
  458.     }
  459.     display_switch = 0;
  460.     return(pick);
  461. }
  462.  
  463.  
  464. int text_screen(int file_num)
  465. {
  466.     call_window(TXT_WIN);
  467.     load_text(file_num,"moutut.men");
  468.     write_window((80 - strlen(" HIT ANY KEY ")) / 2,25," HIT ANY KEY ");
  469.     bioskey(0);
  470.     uncall_window(TXT_WIN);
  471.     return(0);
  472. }
  473.  
  474. int file_screen(char *file_name)
  475. {
  476.     call_window(TXT_WIN);
  477.     write_window((80 - strlen(" PgUp/PgDn ESC ")) / 2,25," PgUp/PgDn ESC ");
  478.     read_text(file_name,1);
  479.     uncall_window(TXT_WIN);
  480.     return(0);
  481. }
  482.  
  483. int mouse_demo(void)
  484. {
  485.     int type = 1,done = 0;
  486.     int moux,mouy,pix_x,pix_y;
  487.  
  488.     text_screen(20);
  489.     set_palette(8,0);
  490.     set_palette(15,7);
  491.     enable_double_font(1);
  492.     load_font("script.fnt",1);
  493.     load_emulate(1);
  494.     call_window(TXT_WIN);
  495.     write_window((80 - strlen(" Hit Any Key to exit ")) / 2,25," HIT ANY KEY TO EXIT ");
  496.     write_win_large(0,5,3,"Mouse v 2.3");
  497.     write_win_large(1,5,11,"Mouse v 2.3");
  498.     write_win_bank(0,55,9,"Mouse v 2.3");
  499.     write_win_bank(1,55,16,"Mouse v 2.3");
  500.     write_window(5,23,"Use LEFT and RIGHT button press to change cursor.");
  501.     moureset();
  502.     moushow();
  503.     while(done == 0)
  504.     {
  505.         mouposition(&moux,&mouy);
  506.         moupositionpix(&pix_x,&pix_y);
  507.         if(buttons == 2)
  508.         {
  509.             if(moubuttonpressed(LEFTBUTTON))
  510.             {
  511.                 write_window(40,20,"Left button pressed  ");
  512.                 type++;
  513.                 if(type > 8)
  514.                 {
  515.                     type = 8;
  516.                 }
  517.                 moucursortype(type);
  518.                 mouposition(&moux,&mouy);
  519.             }
  520.             if(moubuttonpressed(RIGHTBUTTON))
  521.             {
  522.                 write_window(40,20,"Right button pressed ");
  523.                 type--;
  524.                 if(type < 1)
  525.                 {
  526.                     type = 1;
  527.                 }
  528.                 moucursortype(type);
  529.                 mouposition(&moux,&mouy);
  530.             }
  531.             if(moubuttonrelease(LEFTBUTTON))
  532.             {
  533.                 write_window(40,20,"Left button released ");
  534.             }
  535.             if(moubuttonrelease(RIGHTBUTTON))
  536.             {
  537.                 write_window(40,20,"Rigth button released");
  538.             }
  539.         }
  540.         else
  541.         {
  542.             if(moubuttonpressed(LEFTBUTTON))
  543.             {
  544.                 write_window(40,20,"Left button pressed   ");
  545.                 type++;
  546.                 if(type > 32)
  547.                 {
  548.                     type = 32;
  549.                 }
  550.                 moucursortype(type);
  551.                 mouposition(&moux,&mouy);
  552.             }
  553.             if(moubuttonpressed(RIGHTBUTTON))
  554.             {
  555.                 write_window(40,20,"Right button pressed  ");
  556.                 type--;
  557.                 if(type < 1)
  558.                 {
  559.                     type = 1;
  560.                 }
  561.                 moucursortype(type);
  562.                 mouposition(&moux,&mouy);
  563.             }
  564.             if(moubuttonrelease(LEFTBUTTON))
  565.             {
  566.                 write_window(40,20,"Left button released  ");
  567.             }
  568.             if(moubuttonrelease(RIGHTBUTTON))
  569.             {
  570.                 write_window(40,20,"Rigth button released ");
  571.             }
  572.             if(moubuttonpressed(MIDBUTTON))
  573.             {
  574.                 write_window(40,20,"Middle button pressed ");
  575.             }
  576.             if(moubuttonrelease(MIDBUTTON))
  577.             {
  578.                 write_window(40,20,"Middle button released");
  579.             }
  580.         }
  581.         write_window(5,19,"Number of buttons = %1d",buttons);
  582.         write_window(5,21,"Pix X = %3d Pix Y = %3d",pix_x,pix_y);
  583.         write_window(5,22,"    X = %2d     Y = %2d",moux,mouy);
  584.         if(bioskey(1))
  585.         {
  586.             done = 1;
  587.         }
  588.         write_window(5,20,"Cursor type number %2d",type);
  589.     }
  590.     enable_double_font(0);
  591.     set_palette(8,56);
  592.     set_palette(15,63);
  593.     moucursortype(1);
  594.     mouhide();
  595.     uncall_window(TXT_WIN);
  596.     return(0);
  597. }
  598.  
  599.