home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / fli106c / examples / plop.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-25  |  4.7 KB  |  228 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.02
  4. // Copyright (C) 1990, 1991
  5. // Software Dimensions
  6. //
  7. // Dialog Development System
  8. //
  9.  
  10. #include "fli.h"
  11. #include "elements.h"
  12. #include "colors.h"
  13. #include "fliwin.h"
  14. #include "dds.h"
  15.  
  16. #pragma warn -inl
  17.  
  18. //-------------------------------------------------------------------------
  19. //
  20. // Character plopping element
  21. //
  22. //-------------------------------------------------------------------------
  23.  
  24. class PlopChar : public DialogElement
  25. {
  26. private:
  27.  
  28.     int &CurrentItem;
  29.  
  30. public:
  31.  
  32.     PlopChar(int _X,int _Y,int &Item) : CurrentItem(Item)
  33.     {
  34.         X=_X;
  35.         Y=_Y;
  36.         Width=32;
  37.         Height=8;
  38.     }
  39.     void Show();
  40.     void HighLight();
  41.     void UnHighLight();
  42.     int EventHandler(int Event);
  43. };
  44.  
  45. //-------------------------------------------------------------------------
  46. //
  47. // Show the plop list
  48. //
  49. //-------------------------------------------------------------------------
  50.  
  51. void PlopChar::Show()
  52. {
  53.     MouseHide();
  54.     (*Blaze) << Colors.RadioText;
  55.  
  56.     for (int i=0;i<8;i++)
  57.         for (int j=0;j<32;j++)
  58.             (*Blaze)(X+j,Y+i) << (char)((i || j)?((i*32)+j):' ');
  59.  
  60.     HighLight();
  61.  
  62.     MouseShow();
  63. }
  64.  
  65. //-------------------------------------------------------------------------
  66. //
  67. // Highlight an entry on the plop list
  68. //
  69. //-------------------------------------------------------------------------
  70.  
  71. void PlopChar::HighLight()
  72. {
  73.     MouseHide();
  74.  
  75.     (*Blaze) << Colors.RadioHiLite;
  76.  
  77.     int YLoc=CurrentItem/32;
  78.     int XLoc=CurrentItem-(YLoc*32);
  79.  
  80.     (*Blaze) (X+XLoc,Y+YLoc) << (char)((CurrentItem)?(((YLoc*32))+XLoc):' ');
  81.  
  82.     Blaze->WindowGotoXY(X+XLoc,Y+YLoc);
  83.  
  84.     MouseShow();
  85. }
  86.  
  87. //-------------------------------------------------------------------------
  88. //
  89. // UnHighlight an entry on the plop list
  90. //
  91. //-------------------------------------------------------------------------
  92.  
  93. void PlopChar::UnHighLight()
  94. {
  95.     MouseHide();
  96.  
  97.     (*Blaze) << Colors.RadioText;
  98.  
  99.     int YLoc=CurrentItem/32;
  100.     int XLoc=CurrentItem-(YLoc*32);
  101.  
  102.     (*Blaze) (X+XLoc,Y+YLoc) << (char)((CurrentItem)?(((YLoc*32))+XLoc):' ');
  103.  
  104.     Blaze->WindowGotoXY(X+XLoc,Y+YLoc);
  105.  
  106.     MouseShow();
  107. }
  108.  
  109. //-------------------------------------------------------------------------
  110. //
  111. // Main event handler for plop element
  112. //
  113. //-------------------------------------------------------------------------
  114.  
  115. int PlopChar::EventHandler(int Event)
  116. {
  117.     if (Event==kbRight)
  118.     {
  119.         UnHighLight();
  120.         CurrentItem=(CurrentItem==255)?0:(++CurrentItem);
  121.         HighLight();
  122.         return CompleteEvent;
  123.     }
  124.  
  125.     if (Event==kbLeft)
  126.     {
  127.         UnHighLight();
  128.         CurrentItem=(!CurrentItem)?255:(--CurrentItem);
  129.         HighLight();
  130.         return CompleteEvent;
  131.     }
  132.  
  133.     if (Event==kbDown)
  134.     {
  135.         UnHighLight();
  136.         CurrentItem=(CurrentItem>=224)?(CurrentItem-224):(CurrentItem+32);
  137.         HighLight();
  138.         return CompleteEvent;
  139.     }
  140.  
  141.     if (Event==kbUp)
  142.     {
  143.         UnHighLight();
  144.         CurrentItem=(CurrentItem<33)?(CurrentItem+224):(CurrentItem-32);
  145.         HighLight();
  146.         return CompleteEvent;
  147.     }
  148.  
  149.     if (Event==ValidatedMousedEvent)
  150.     {
  151.         if (MouseButtonStatus&LeftButton)
  152.         {
  153.             UnHighLight();
  154.             CurrentItem=
  155.                 ((MouseVertical-DialogElement::Y)*32)+
  156.                 (MouseHorizontal-DialogElement::X);
  157.             HighLight();
  158.             return CompleteEvent;
  159.         }
  160.     }
  161.  
  162.     return Event;
  163. }
  164.  
  165. //-------------------------------------------------------------------------
  166. //
  167. // Main dialog that uses the plop element that we just invented
  168. //
  169. //-------------------------------------------------------------------------
  170.  
  171. const plopDrop=10000;
  172. const plopCancel=10001;
  173.  
  174. class PlopDialog : public DialogClass
  175. {
  176. public:
  177.  
  178.     PlopDialog() : DialogClass(56,14,"Plop")
  179.         {  }
  180.  
  181.     int EventHandler(int Event)
  182.     {
  183.         if (Event==kbEsc ||
  184.                 Event==kbCr ||
  185.                 Event==CloseEvent ||
  186.                 Event==OutsideEvent ||
  187.                 Event==plopDrop ||
  188.                 Event==plopCancel)
  189.             return StopEvent;
  190.         return CompleteEvent;
  191.     }
  192. };
  193.  
  194. //-------------------------------------------------------------------------
  195. //
  196. // Call up and display the character plopping dialog
  197. //
  198. //-------------------------------------------------------------------------
  199.  
  200. int DialogWindow::PlopCharacter()
  201. {
  202.   PlopDialog &Dialog=*new PlopDialog();
  203.  
  204.     int PlopCharacter=0;
  205.  
  206.     Dialog.Element(new PlopChar(3,2,PlopCharacter));
  207.     Dialog.HotKey(10,1,"~Character to Plop",kbAltC);
  208.     Dialog.Help("Select this foreground palette color");
  209.  
  210.   Dialog.Element(new DiaPushButton(41,4,"Plop It!",plopDrop,0,1));
  211.     Dialog.Help("Change to this palette color");
  212.  
  213.     Dialog.Element(new DiaPushButton(41,7," Cancel ",plopCancel));
  214.     Dialog.Help("Do not change the color");
  215.  
  216.     Dialog.Blaze.Box(1,1,36,10,Colors.DiaInterior);
  217.  
  218.     int Remember=Dialog.UseDialog();
  219.  
  220.     if (Remember!=kbCr && Remember!=plopDrop)
  221.         PlopCharacter=0;
  222.  
  223.   delete &Dialog;
  224.  
  225.     return PlopCharacter;
  226. }
  227.  
  228.