home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / gempp15b / gemsl.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-23  |  7.1 KB  |  367 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1992,1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include "gemsl.h"
  12. #include "gemf.h"
  13. #include "contract.h"
  14. #include <aesbind.h>
  15. #include <minmax.h>
  16.  
  17. class SL_Knob : public GEMobject
  18. {
  19. public:
  20.     SL_Knob(GEMform& f, int RSCindex, GEMslider& tell) :
  21.         GEMobject(f, RSCindex),
  22.         Tell(tell)
  23.     { }
  24.  
  25.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  26.     {
  27.         int tx,ty;
  28.  
  29.         Tell.GetAbsoluteXY(tx,ty);
  30.  
  31.         int ox,oy,nx,ny;
  32.         ox=tx+X();
  33.         oy=ty+Y();
  34.  
  35.         graf_dragbox(Width(),Height(),ox,oy,
  36.             tx,ty,Tell.Width(),Tell.Height(),&nx,&ny);
  37.  
  38.         if (ox!=nx || oy!=ny) {
  39.             MoveTo(nx-tx,ny-ty);
  40.             Tell.GEMtoDOC();
  41.             Tell.Flush();
  42.         }
  43.  
  44.         return ContinueInteraction;
  45.     }
  46.  
  47. private:
  48.     GEMslider& Tell;
  49. };
  50.  
  51.  
  52. class SL_Left : public GEMobject
  53. {
  54. public:
  55.     SL_Left(GEMform& f, int RSCindex, GEMslider& tell) :
  56.         GEMobject(f, RSCindex),
  57.         Tell(tell)
  58.     { }
  59.  
  60.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  61.     {
  62.         Tell.ColumnLeft();
  63.         Tell.Flush();
  64.         return ContinueInteraction;
  65.     }
  66.  
  67. private:
  68.     GEMslider& Tell;
  69. };
  70.  
  71.  
  72. class SL_Right : public GEMobject
  73. {
  74. public:
  75.     SL_Right(GEMform& f, int RSCindex, GEMslider& tell) :
  76.         GEMobject(f, RSCindex),
  77.         Tell(tell)
  78.     { }
  79.  
  80.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  81.     {
  82.         Tell.ColumnRight();
  83.         Tell.Flush();
  84.         return ContinueInteraction;
  85.     }
  86.  
  87. private:
  88.     GEMslider& Tell;
  89. };
  90.  
  91.  
  92. class SL_Up : public GEMobject
  93. {
  94. public:
  95.     SL_Up(GEMform& f, int RSCindex, GEMslider& tell) :
  96.         GEMobject(f, RSCindex),
  97.         Tell(tell)
  98.     { }
  99.  
  100.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  101.     {
  102.         Tell.LineUp();
  103.         Tell.Flush();
  104.         return ContinueInteraction;
  105.     }
  106.  
  107. private:
  108.     GEMslider& Tell;
  109. };
  110.  
  111.  
  112. class SL_Down : public GEMobject
  113. {
  114. public:
  115.     SL_Down(GEMform& f, int RSCindex, GEMslider& tell) :
  116.         GEMobject(f, RSCindex),
  117.         Tell(tell)
  118.     { }
  119.  
  120.     virtual GEMfeedback Touch(int x, int y, const GEMevent&)
  121.     {
  122.         Tell.LineDown();
  123.         Tell.Flush();
  124.         return ContinueInteraction;
  125.     }
  126.  
  127. private:
  128.     GEMslider& Tell;
  129. };
  130.  
  131.  
  132.  
  133. GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack) :
  134.     GEMobject(f,RSCrack),
  135.     K(new SL_Knob(f,RSCknob,*this)),
  136.     U(0),D(0),L(0),R(0),
  137.     visibleLines(K->Height()),visibleColumns(K->Width()),
  138.     totalLines(Height()),totalColumns(Width())
  139. {
  140.     GEMtoDOC();
  141. }
  142.  
  143. GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack, int RSCminus, int RSCplus) :
  144.     GEMobject(f,RSCrack),
  145.     K(new SL_Knob(f,RSCknob,*this)),
  146.     U(0),D(0),L(0),R(0),
  147.     visibleLines(K->Height()),visibleColumns(K->Width()),
  148.     totalLines(Height()),totalColumns(Width())
  149. {
  150.     GEMtoDOC();
  151.     if (Width()-K->Width() > Height()-K->Height()) {
  152.         // Horizontal
  153.         L=new SL_Left(f,RSCminus,*this);
  154.         R=new SL_Right(f,RSCplus,*this);
  155.     } else {
  156.         // Vertical
  157.         U=new SL_Up(f,RSCminus,*this);
  158.         D=new SL_Down(f,RSCplus,*this);
  159.     }
  160. }
  161.  
  162. GEMslider::GEMslider(GEMform& f, int RSCknob, int RSCrack,
  163.         int RSChplus, int RSChminus,
  164.         int RSCvplus, int RSCvminus) :
  165.     GEMobject(f,RSCrack),
  166.     K(new SL_Knob(f,RSCknob,*this)),
  167.     L(new SL_Left(f,RSChminus,*this)),
  168.     R(new SL_Right(f,RSChplus,*this)),
  169.     U(new SL_Up(f,RSCvminus,*this)),
  170.     D(new SL_Down(f,RSCvplus,*this)),
  171.     visibleLines(K->Height()),visibleColumns(K->Width()),
  172.     totalLines(Height()),totalColumns(Width())
  173. {
  174.     GEMtoDOC();
  175. }
  176.  
  177. GEMslider::~GEMslider()
  178. {
  179.     delete K;
  180.     if (U) delete U;
  181.     if (D) delete D;
  182.     if (L) delete L;
  183.     if (R) delete R;
  184. }
  185.  
  186. GEMfeedback GEMslider::Touch(int x, int y, const GEMevent&)
  187. {
  188.     if (x<K->X()) PageLeft();
  189.     else if (x>=K->X()+K->Width()) PageRight();
  190.     if (y<K->Y()) PageUp();
  191.     else if (y>=K->Y()+K->Height()) PageDown();
  192.     Flush();
  193.     return ContinueInteraction;
  194. }
  195.  
  196. void GEMslider::DOCtoGEM()
  197. {
  198.     if (totalLines > 0) {
  199.         K->Resize(max(6,Width()*visibleColumns/totalColumns),
  200.             max(6,Height()*visibleLines/totalLines));
  201.         K->MoveTo(
  202.             totalColumns==visibleColumns ? 0
  203.                 : actualLeftColumn*(Width()-K->Width())/(totalColumns-visibleColumns),
  204.             totalLines==visibleLines ? 0
  205.                 : actualTopLine*(Height()-K->Height())/(totalLines-visibleLines)
  206.             );
  207.     }
  208. }
  209.  
  210. void GEMslider::GEMtoDOC()
  211. {
  212.     if (Height()>K->Height()) {
  213.         actualTopLine = K->Y()*(totalLines-visibleLines)/(Height()-K->Height());
  214.     }
  215.     if (Width()>K->Width()) {
  216.         actualLeftColumn = K->X()*(totalColumns-visibleColumns)/(Width()-K->Width());
  217.     }
  218. }
  219.  
  220. void GEMslider::Flush()
  221. {
  222.     DOCtoGEM();
  223.     Redraw();
  224. }
  225.  
  226. void GEMslider::SetVisibleLines( int noOfLines )
  227. {
  228.     Require(noOfLines >= 0);
  229.     Require(noOfLines <= totalLines);
  230.     
  231.     visibleLines = noOfLines;
  232.     
  233.     if (actualTopLine > totalLines - visibleLines)
  234.         actualTopLine = totalLines - visibleLines;
  235. }
  236.  
  237. void GEMslider::SetTotalLines( int noOfLines )
  238. {
  239.     Require(noOfLines >= 0);
  240.  
  241.     totalLines = noOfLines;
  242.  
  243.     if (noOfLines < visibleLines) {
  244.         visibleLines = totalLines;
  245.     }
  246.  
  247.     if (actualTopLine > totalLines - visibleLines) {
  248.         actualTopLine = totalLines - visibleLines;
  249.     }
  250. }
  251.  
  252. void GEMslider::SetTopLine( int noOfLine )
  253. {
  254.     Require(noOfLine >= 0);
  255.     Require(noOfLine <= totalLines - visibleLines);
  256.     
  257.     if (actualTopLine != noOfLine) {
  258.         actualTopLine = noOfLine;
  259.     }
  260. }
  261.  
  262. void GEMslider::SetVisibleColumns( int noOfColumns )
  263. {
  264.     Require(noOfColumns >= 0);
  265.     Require(noOfColumns <= totalColumns);
  266.  
  267.     if (visibleColumns != noOfColumns) {
  268.         visibleColumns = noOfColumns;
  269.         
  270.         if (actualLeftColumn > totalColumns - visibleColumns)
  271.             actualLeftColumn = totalColumns - visibleColumns;
  272.     }
  273. }
  274.  
  275. void GEMslider::SetTotalColumns( int noOfColumns )
  276. {
  277.     Require(noOfColumns >= 0);
  278.  
  279.     totalColumns = noOfColumns;
  280.  
  281.     if (noOfColumns < visibleColumns) {
  282.         visibleColumns = totalColumns;
  283.     }
  284.  
  285.     if (actualLeftColumn > totalColumns - visibleColumns) {
  286.         actualLeftColumn = totalColumns - visibleColumns;
  287.     }
  288. }
  289.  
  290. void GEMslider::SetLeftColumn( int noOfColumn )
  291. {
  292.     Require(noOfColumn >= 0);
  293.     Require(noOfColumn <= totalColumns - visibleColumns);
  294.     
  295.     if (actualLeftColumn != noOfColumn) {
  296.         actualLeftColumn = noOfColumn;
  297.     }
  298. }
  299.  
  300.  
  301. void GEMslider::LineUp()
  302. {
  303.     if (actualTopLine > 0) {
  304.         actualTopLine--;
  305.     }
  306. }
  307.  
  308. void GEMslider::LineDown()
  309. {
  310.     if (actualTopLine < totalLines - visibleLines) {
  311.         actualTopLine++;
  312.     }
  313. }
  314.  
  315. void GEMslider::PageUp()
  316. {
  317.     if (actualTopLine > 0) {
  318.         actualTopLine = (actualTopLine>=visibleLines)?
  319.                 actualTopLine-visibleLines : 0;
  320.     }
  321. }
  322.  
  323. void GEMslider::PageDown()
  324. {
  325.     if (actualTopLine < totalLines - visibleLines) {
  326.         actualTopLine =
  327.             (actualTopLine+visibleLines
  328.                 > totalLines-visibleLines)?
  329.             totalLines-visibleLines :
  330.             actualTopLine+visibleLines;
  331.     }
  332. }
  333.  
  334.     
  335. void GEMslider::ColumnLeft()
  336. {
  337.     if (actualLeftColumn > 0) {
  338.         actualLeftColumn--;
  339.     }
  340. }
  341.  
  342. void GEMslider::ColumnRight()
  343. {
  344.     if (actualLeftColumn < totalColumns - visibleColumns) {
  345.         actualLeftColumn++;
  346.     }
  347. }
  348.  
  349. void GEMslider::PageLeft()
  350. {
  351.     if (actualLeftColumn > 0) {
  352.         actualLeftColumn = (actualLeftColumn>=visibleColumns)?
  353.             actualLeftColumn-visibleColumns : 0;
  354.     }
  355. }
  356.  
  357. void GEMslider::PageRight()
  358. {
  359.     if (actualLeftColumn < totalColumns-visibleColumns) {
  360.         actualLeftColumn =
  361.             (actualLeftColumn+visibleColumns 
  362.                 > totalColumns-visibleColumns) ?
  363.             totalColumns - visibleColumns :
  364.             actualLeftColumn + visibleColumns;
  365.     }
  366. }
  367.