home *** CD-ROM | disk | FTP | other *** search
Java Source | 2017-09-21 | 2.0 KB | 66 lines |
- import java.awt.*;
-
- public class RectSlider extends RectButton
- {
- double m_fValue; // between 0 and 1, inclusive
- boolean m_bVert = true; // Vertical?
- boolean m_bBottomLeft = true; // 0 is at bottom/left?
- //--------------------------------
- public RectSlider (int iXPos, int iYPos, int iWidth, int iHeight)
- { super(iXPos, iYPos, iWidth, iHeight);
- }
- //--------------------------------
- public boolean bMouseOver (int x, int y)
- {
- if (super.bMouseOver(x,y)) {
- if (m_bVert) {
- m_fValue = (double)(y-m_iYPos) / (double)m_iHeight;
- if (m_bBottomLeft) m_fValue = 1.0 - m_fValue;
- } else {
- m_fValue = (double)(x-m_iXPos) / (double)m_iWidth;
- if (!m_bBottomLeft) m_fValue = 1.0 - m_fValue;
- }
- return true;
- } else return false;
- }
-
- //--------------------------------
- public void paint (Graphics g, Color cMain, Color cBorder)
- { if (cMain != null) m_cMain = cMain;
- if (cBorder != null) m_cBorder = cBorder;
- g.setColor(m_cBorder);
- for (int C=0; C<m_iBorderWidth; C++)
- g.draw3DRect(m_iXPos + C, m_iYPos + C,
- m_iWidth -1-2*C, m_iHeight -1-2*C, true);
-
- int iX = m_iXPos + m_iBorderWidth, iY = m_iYPos + m_iBorderWidth;
- int iW = m_iWidth - 2*m_iBorderWidth, iH = m_iHeight - 2*m_iBorderWidth;
- int iBorderVal;
- if (m_bVert) {
- if (m_bBottomLeft) {
- iBorderVal = (int)((1.0-m_fValue)*iH);
- g.fillRect(iX, iY, iW, iBorderVal);
- g.setColor(m_cMain);
- g.fillRect(iX, iY+iBorderVal, iW, iH-iBorderVal);
- } else {
- iBorderVal = (int)((m_fValue)*iH);
- g.fillRect(iX, iY+iBorderVal, iW, iH-iBorderVal);
- g.setColor(m_cMain);
- g.fillRect(iX, iY, iW, iBorderVal);
- }
- } else {
- if (!m_bBottomLeft) {
- iBorderVal = (int)((1.0-m_fValue)*iW);
- g.fillRect(iX, iY, iBorderVal, iH);
- g.setColor(m_cMain);
- g.fillRect(iX+iBorderVal, iY, iW-iBorderVal, iH);
- } else {
- iBorderVal = (int)((m_fValue)*iW);
- g.fillRect(iX+iBorderVal, iY, iW-iBorderVal, iH);
- g.setColor(m_cMain);
- g.fillRect(iX, iY, iBorderVal, iH);
- }
- }
- }
-
- } // end RectSlider