예제 #1
0
        // draw the bar and the arrow
        private void DrawVBar(SpriteBatch batch, ButtonSprite btn,
            float value, float min)
        {
            // determine the X of the arrow
            // NOTE: btn.RectNormal describes the bounds of the image
            // btn.RectPressed describes the bounds of the bar itself
            m_btnVBarArrow.Location.X =
                btn.Location.X +
                btn.RectPressed.X +
                btn.RectPressed.Width / 2 -
                m_btnVBarArrow.RectNormal.Width / 2;

            if (min < 0.0f)
            {
                // value is between -1.0f and 1.0f. offset value
                // so that value is between 0.0f and 2.0f
                value += 1.0f;
                // then scale so that so that value is
                // between 0.0f and 1.0f
                value /= 2.0f;
            }

            // since value is now between 0 and 1, we can treat it
            // like a percentage. so, Y becomes value percent of
            // Height. NOTE: need to invert value since Y values
            // increase as you move down the screen. (see line with
            // "// bottommost" comment)
            m_btnVBarArrow.Location.Y =
               btn.Location.Y + btn.RectPressed.Y +  // topmost pixel
               btn.RectPressed.Height -              // bottommost
               btn.RectPressed.Height * value -      // scaled value
               m_btnVBarArrow.RectNormal.Height / 2; // arrow midpoint

            // draw bar
            batch.Draw(btn.TextureNormal, btn.Location,
                btn.RectNormal, Color.White);
            // draw arrow
            DrawButton(batch, m_btnVBarArrow, false);
        }
예제 #2
0
 // overload for DrawVBar, with default min
 private void DrawVBar(SpriteBatch batch, ButtonSprite btn,
     float value)
 {
     DrawVBar(batch, btn, value, -1.0f);
 }
예제 #3
0
        // draw the bar and the arrow
        private void DrawHBar(SpriteBatch batch, ButtonSprite btn, float value, float min)
        {
            // determine the Y of the arrow
            // NOTE: btn.RectNormal describes the bounds of the image
            // btn.RectPressed describes the bounds of the bar itself
            m_btnHBarArrow.Location.Y =
                btn.Location.Y + btn.RectPressed.Y +
                btn.RectPressed.Height / 2 -
                m_btnHBarArrow.RectNormal.Height / 2;

            if (min < 0.0f)
            {
                // value is between -1.0f and 1.0f. offset value
                // so that value is between 0.0f and 2.0f
                value += 1.0f;
                // then scale so that so that value is
                // between 0.0f and 1.0f
                value /= 2.0f;
            }

            // since value is now between 0 and 1, we can treat it
            // like a percentage. so, X becomes value percent of
            // Height.
            m_btnHBarArrow.Location.X =
               btn.Location.X + btn.RectPressed.X + // leftmost pixel
               btn.RectPressed.Width * value -      // scaled value
               m_btnHBarArrow.RectNormal.Width / 2; // arrow midpoint

            // draw bar
            batch.Draw(btn.TextureNormal, btn.Location,
                btn.RectNormal, Color.White);
            // draw arrow
            DrawButton(batch, m_btnHBarArrow, false);
        }
예제 #4
0
 // draw the active port indicators
 private void DrawPort(SpriteBatch batch, ButtonSprite btn, int index, bool active)
 {
     // gray (inactive) or green (active) circle
     DrawButton(batch, btn, active);
     // port number
     batch.Draw(btn.TextureNormal, btn.Location, m_rectPortNum[index], Color.White);
 }
예제 #5
0
 // draw the button at its current location in its current state
 private void DrawButton(SpriteBatch batch, ButtonSprite btn,
     bool pressed)
 {
     if (pressed)
     {
         batch.Draw(btn.TexturePressed, btn.Location,
             btn.RectPressed, Color.White);
     }
     else
     {
         batch.Draw(btn.TextureNormal, btn.Location,
             btn.RectNormal, Color.White);
     }
 }