home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / games / gnuchess / src / popupch.cc < prev    next >
C/C++ Source or Header  |  1994-01-17  |  3KB  |  177 lines

  1. #include "popupch.h"
  2. #include <gemrubo.h>
  3.  
  4.  
  5. PopupList::PopupList(GEMrsc& rsc,
  6.     int RSCform,
  7.     int RSCchoice1,
  8.     int RSCchoicen,
  9.     int RSCscrollbar) :
  10.         GEMhotform(rsc,RSCform),
  11.         GEMslider(*this,RSCscrollbar+4,RSCscrollbar+3,RSCscrollbar+1,RSCscrollbar+2),
  12.         choice1(RSCchoice1),
  13.         choicen(RSCchoicen),
  14.         scrollbar(RSCscrollbar),
  15.         tell(0)
  16. {
  17. }
  18.  
  19. int PopupList::DoHot(int ob, bool inside)
  20. {
  21.     tell->SelectObject(ob-choice1+TopLine(),inside,Object(ob));
  22.     RedrawObject(ob);
  23.     return Ignore;
  24. }
  25.  
  26. int PopupList::Choose(int x, int y, PopupChoice* t)
  27. {
  28.     tell=t;
  29.  
  30.     for (int i=0; i<=choicen-choice1; i++) {
  31.         GEMrawobject& choice=Object(choice1+i);
  32.  
  33.         if (i<tell->NumberOfChoices()) {
  34.             choice.HideTree(FALSE);
  35.             tell->InitObject(choice);
  36.             tell->SetObject(i,choice);
  37.         } else {
  38.             choice.HideTree(TRUE);
  39.         }
  40.     }
  41.  
  42.     // Do we need a scrollbar?
  43.     if (tell->NumberOfChoices() > choicen-choice1+1) {
  44.         Object(scrollbar).HideTree(FALSE);
  45.         SetTopLine(0);
  46.         SetTotalLines(tell->NumberOfChoices());
  47.         SetVisibleLines(choicen-choice1+1);
  48.     } else {
  49.         SetTopLine(0);
  50.         Object(scrollbar).HideTree(TRUE);
  51.     }
  52.  
  53.     // Shrink outer box.
  54.     GEMrubberobject fullbox(*this,ROOT);
  55.     fullbox.Fit(0);
  56.  
  57.     int result=Do(x,y)-choice1+TopLine();
  58.  
  59.     tell=0;
  60.  
  61.     return result;
  62. }
  63.  
  64.  
  65. void PopupList::VFlush()
  66. {
  67.     if (tell) {
  68.         for (int i=0; i<=choicen-choice1 && i<tell->NumberOfChoices(); i++) {
  69.             tell->SetObject(i+TopLine(),Object(choice1+i));
  70.         }
  71.         RedrawObject(Parent(choice1));
  72.     }
  73. }
  74.  
  75.  
  76. PopupChoice::PopupChoice(GEMform& form, int RSCindex, PopupList& pop) :
  77.     GEMobject(form,RSCindex),
  78.     popup(pop),
  79.     lastchosen(0)
  80. {
  81. }
  82.  
  83. GEMfeedback PopupChoice::Touch(int x, int y, const GEMevent& e)
  84. {
  85.     int x,y;
  86.     GetAbsoluteXY(x,y);
  87.     int choice=popup.Choose(x,y,this);
  88.     if (choice>=0) Choose(choice);
  89.     return ContinueInteraction;
  90. }
  91.  
  92. void PopupChoice::Choose(int chosen)
  93. {
  94.     if (lastchosen!=chosen) {
  95.         lastchosen=chosen;
  96.         SetObject(chosen,form[myindex]); // Look like choice.
  97.         Redraw();
  98.         ChoiceChanged();
  99.     }
  100. }
  101.  
  102. void PopupChoice::InitObject(GEMrawobject& object)
  103. {
  104.     // Be my size.
  105.     object.Resize(Width(),Height());
  106. }
  107.  
  108. void PopupChoice::SelectObject(int choice, bool yes, GEMrawobject& object)
  109. {
  110.     object.Selected(yes);
  111. }
  112.  
  113. void PopupChoice::ChoiceChanged()
  114. {
  115. }
  116.  
  117. class Upper : public GEMobject {
  118. public:
  119.     Upper(GEMform& form, int RSCindex, ArrowablePopupChoice* tll) :
  120.         GEMobject(form,RSCindex),
  121.         tell(tll)
  122.     {
  123.     }
  124.  
  125.     virtual GEMfeedback Touch(int x, int y, const GEMevent& e)
  126.     {
  127.         tell->UpList();
  128.         return ContinueInteraction;
  129.     }
  130.  
  131. private:
  132.     ArrowablePopupChoice* tell;
  133. };
  134.  
  135. class Downer : public GEMobject {
  136. public:
  137.     Downer(GEMform& form, int RSCindex, ArrowablePopupChoice* tll) :
  138.         GEMobject(form,RSCindex),
  139.         tell(tll)
  140.     {
  141.     }
  142.  
  143.     virtual GEMfeedback Touch(int x, int y, const GEMevent& e)
  144.     {
  145.         tell->DownList();
  146.         return ContinueInteraction;
  147.     }
  148.  
  149. private:
  150.     ArrowablePopupChoice* tell;
  151. };
  152.  
  153. ArrowablePopupChoice::ArrowablePopupChoice(GEMform& form, int RSCindex, PopupList& popup) :
  154.     PopupChoice(form,RSCindex+2,popup),
  155.     upper(new Upper(form,RSCindex+1,this)),
  156.     downer(new Downer(form,RSCindex+3,this))
  157. {
  158. }
  159.  
  160. ArrowablePopupChoice::~ArrowablePopupChoice()
  161. {
  162.     delete upper;
  163.     delete downer;
  164. }
  165.  
  166. void ArrowablePopupChoice::UpList()
  167. {
  168.     int last=Choice();
  169.     if (last>0) Choose(last-1);
  170. }
  171.  
  172. void ArrowablePopupChoice::DownList()
  173. {
  174.     int last=Choice();
  175.     if (last<NumberOfChoices()-1) Choose(last+1);
  176. }
  177.