home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Cdrom / Pavilions / BrainOpera / online / net-music / net-instrument / RectSlider.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  2.0 KB  |  66 lines

  1. import java.awt.*;
  2.  
  3. public class RectSlider extends RectButton
  4. {
  5.     double m_fValue;    // between 0 and 1, inclusive
  6.     boolean m_bVert = true;    // Vertical?
  7.     boolean m_bBottomLeft = true;    // 0 is at bottom/left?
  8. //--------------------------------
  9. public RectSlider (int iXPos, int iYPos, int iWidth, int iHeight)
  10. {    super(iXPos, iYPos, iWidth, iHeight);
  11. }
  12. //--------------------------------
  13. public boolean bMouseOver (int x, int y)
  14. {
  15.     if (super.bMouseOver(x,y)) {
  16.         if (m_bVert) {
  17.             m_fValue = (double)(y-m_iYPos) / (double)m_iHeight;
  18.             if (m_bBottomLeft) m_fValue = 1.0 - m_fValue;
  19.         } else {
  20.             m_fValue = (double)(x-m_iXPos) / (double)m_iWidth;
  21.             if (!m_bBottomLeft) m_fValue = 1.0 - m_fValue;
  22.         }
  23.         return true;
  24.     } else return false;
  25. }
  26.  
  27. //--------------------------------
  28. public void paint (Graphics g, Color cMain, Color cBorder)
  29. {    if (cMain != null) m_cMain = cMain;
  30.     if (cBorder != null) m_cBorder = cBorder;
  31.     g.setColor(m_cBorder);
  32.     for (int C=0; C<m_iBorderWidth; C++)
  33.         g.draw3DRect(m_iXPos + C, m_iYPos + C, 
  34.             m_iWidth -1-2*C, m_iHeight -1-2*C, true);
  35.     
  36.     int iX = m_iXPos + m_iBorderWidth, iY = m_iYPos + m_iBorderWidth;
  37.     int iW = m_iWidth - 2*m_iBorderWidth, iH = m_iHeight - 2*m_iBorderWidth;
  38.     int iBorderVal;
  39.     if (m_bVert) {
  40.         if (m_bBottomLeft) {
  41.             iBorderVal = (int)((1.0-m_fValue)*iH);
  42.             g.fillRect(iX, iY, iW, iBorderVal);
  43.             g.setColor(m_cMain);
  44.             g.fillRect(iX, iY+iBorderVal, iW, iH-iBorderVal);
  45.         } else {
  46.             iBorderVal = (int)((m_fValue)*iH);
  47.             g.fillRect(iX, iY+iBorderVal, iW, iH-iBorderVal);
  48.             g.setColor(m_cMain);
  49.             g.fillRect(iX, iY, iW, iBorderVal);
  50.         }
  51.     } else {
  52.         if (!m_bBottomLeft) {
  53.             iBorderVal = (int)((1.0-m_fValue)*iW);
  54.             g.fillRect(iX, iY, iBorderVal, iH);
  55.             g.setColor(m_cMain);
  56.             g.fillRect(iX+iBorderVal, iY, iW-iBorderVal, iH);
  57.         } else {
  58.             iBorderVal = (int)((m_fValue)*iW);
  59.             g.fillRect(iX+iBorderVal, iY, iW-iBorderVal, iH);
  60.             g.setColor(m_cMain);
  61.             g.fillRect(iX, iY, iBorderVal, iH);
  62.         }
  63.     }
  64. }
  65.  
  66. }    // end RectSlider