예제 #1
0
 protected void drawValue(double value)
 {
     if (ControlPanel.ChkShowValues.Checked)
     {
         var s = Utils.UnitText(value);
         if (mNameV)
         {
             Context.DrawCenteredVText(s, mValuePos.X, mValuePos.Y);
         }
         else
         {
             Context.DrawLeftText(s, mValuePos.X, mValuePos.Y);
         }
     }
 }
예제 #2
0
        public override void Draw(CustomGraphics g)
        {
            setBbox(mPoint1, mPoint2, 16);

            /* draw collector */
            drawLead(mColl[0], mColl[1]);
            /* draw emitter */
            drawLead(mEmit[0], mEmit[1]);
            /* draw arrow */
            g.FillPolygon(NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor, mArrowPoly);
            /* draw base */
            drawLead(mPoint1, mTbase);

            /* draw dots */
            mCurCount_b = updateDotCount(-mIb, mCurCount_b);
            drawDots(mTbase, mPoint1, mCurCount_b);
            mCurCount_c = updateDotCount(-mIc, mCurCount_c);
            drawDots(mColl[1], mColl[0], mCurCount_c);
            mCurCount_e = updateDotCount(-mIe, mCurCount_e);
            drawDots(mEmit[1], mEmit[0], mCurCount_e);

            /* draw base rectangle */
            g.FillPolygon(NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor, mRectPoly);

            drawPosts();

            if (ControlPanel.ChkShowName.Checked)
            {
                if (mNameV)
                {
                    g.DrawCenteredVText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
                else
                {
                    g.DrawLeftText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
            }
        }
예제 #3
0
        public override void Draw(CustomGraphics g)
        {
            double vl = Volts[V_L];
            double vr = Volts[V_R];
            double vs = Volts[V_S];

            setBbox(mPoint1, mPoint2, HS);
            draw2Leads();

            int divide = (int)(SEGMENTS * mPosition);

            if (ControlPanel.ChkUseAnsiSymbols.Checked)
            {
                /* draw zigzag */
                for (int i = 0; i != SEGMENTS; i++)
                {
                    double v = vl + (vs - vl) * i / divide;
                    if (i >= divide)
                    {
                        v = vs + (vr - vs) * (i - divide) / (SEGMENTS - divide);
                    }
                    drawLead(mPs1[i], mPs2[i]);
                }
            }
            else
            {
                /* draw rectangle */
                drawLead(mRect1[0], mRect2[0]);
                for (int i = 0, j = 1; i != SEGMENTS; i++, j++)
                {
                    double v = vl + (vs - vl) * i / divide;
                    if (i >= divide)
                    {
                        v = vs + (vr - vs) * (i - divide) / (SEGMENTS - divide);
                    }
                    drawLead(mRect1[j], mRect3[j]);
                    drawLead(mRect2[j], mRect4[j]);
                }
                drawLead(mRect1[SEGMENTS + 1], mRect2[SEGMENTS + 1]);
            }

            /* draw slider */
            drawLead(mPost3, mCorner2);
            drawLead(mCorner2, mArrowPoint);
            drawLead(mArrow1, mArrowPoint);
            drawLead(mArrow2, mArrowPoint);

            /* draw dot */
            mCurCount1 = updateDotCount(mCurrent1, mCurCount1);
            mCurCount2 = updateDotCount(mCurrent2, mCurCount2);
            mCurCount3 = updateDotCount(mCurrent3, mCurCount3);
            if (CirSim.Sim.DragElm != this)
            {
                drawDots(mPoint1, mMidPoint, mCurCount1);
                drawDots(mPoint2, mMidPoint, mCurCount2);
                drawDots(mPost3, mCorner2, mCurCount3);
                drawDots(mCorner2, mMidPoint, mCurCount3 + Utils.Distance(mPost3, mCorner2));
            }
            drawPosts();

            if (ControlPanel.ChkShowValues.Checked && mResistance1 > 0 && (mFlags & FLAG_SHOW_VALUES) != 0)
            {
                /* check for vertical pot with 3rd terminal on left */
                bool reverseY = (mPost3.X < mLead1.X && mLead1.X == mLead2.X);
                /* check for horizontal pot with 3rd terminal on top */
                bool reverseX = (mPost3.Y < mLead1.Y && mLead1.X != mLead2.X);
                /* check if we need to swap texts (if leads are reversed, e.g. drawn right to left) */
                bool rev = (mLead1.X == mLead2.X && mLead1.Y < mLead2.Y) || (mLead1.Y == mLead2.Y && mLead1.X > mLead2.X);

                /* draw units */
                string s1         = Utils.UnitText(rev ? mResistance2 : mResistance1, "");
                string s2         = Utils.UnitText(rev ? mResistance1 : mResistance2, "");
                int    txtHeightH = CustomGraphics.FontText.Height / 2;
                int    txtWidth1  = (int)g.GetTextSize(s1).Width;
                int    txtWidth2  = (int)g.GetTextSize(s2).Width;

                /* vertical? */
                if (mLead1.X == mLead2.X)
                {
                    g.DrawLeftTopText(s1, !reverseY ? mArrowPoint.X : mArrowPoint.X - txtWidth1, Math.Min(mArrow1.Y, mArrow2.Y) + 4 * txtHeightH);
                    g.DrawLeftTopText(s2, !reverseY ? mArrowPoint.X : mArrowPoint.X - txtWidth2, Math.Max(mArrow1.Y, mArrow2.Y) - txtHeightH);
                }
                else
                {
                    g.DrawLeftTopText(s1, Math.Min(mArrow1.X, mArrow2.X) - txtWidth1, !reverseX ? (mArrowPoint.Y + txtHeightH + 10) : mArrowPoint.Y);
                    g.DrawLeftTopText(s2, Math.Max(mArrow1.X, mArrow2.X), !reverseX ? (mArrowPoint.Y + txtHeightH + 10) : mArrowPoint.Y);
                }
            }
            if (ControlPanel.ChkShowName.Checked)
            {
                if (mNameV)
                {
                    g.DrawCenteredVText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
                else
                {
                    g.DrawLeftText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
            }
        }
예제 #4
0
        public override void Draw(CustomGraphics g)
        {
            /* pick up global flags changes */
            if ((mFlags & FLAGS_GLOBAL) != mGlobalFlags)
            {
                SetPoints();
            }

            setBbox(mPoint1, mPoint2, HS);

            /* draw source/drain terminals */
            drawLead(mSrc[0], mSrc[1]);
            drawLead(mDrn[0], mDrn[1]);

            /* draw line connecting source and drain */
            bool enhancement = mVt > 0 && ShowBulk;

            for (int i = 0; i != SEGMENTS; i++)
            {
                if ((i == 1 || i == 4) && enhancement)
                {
                    continue;
                }
                double v = Volts[V_S] + (Volts[V_D] - Volts[V_S]) * i / SEGMENTS;
                drawLead(mPs1[i], mPs2[i]);
            }

            /* draw little extensions of that line */
            drawLead(mSrc[1], mSrc[2]);
            drawLead(mDrn[1], mDrn[2]);

            /* draw bulk connection */
            if (ShowBulk)
            {
                drawLead(mPnp == -1 ? mDrn[0] : mSrc[0], mBody[0]);
                drawLead(mBody[0], mBody[1]);
            }

            /* draw arrow */
            if (!DrawDigital)
            {
                g.FillPolygon(NeedsHighlight ? CustomGraphics.SelectColor : CustomGraphics.GrayColor, mArrowPoly);
            }

            /* draw gate */
            drawLead(mPoint1, mGate[1]);
            drawLead(mGate[0], mGate[2]);
            if (DrawDigital && mPnp == -1)
            {
                g.DrawCircle(mPcircle, mPcircler);
            }

            if ((mFlags & FLAG_SHOWVT) != 0)
            {
                string s = "" + (mVt * mPnp);
                drawCenteredLText(s, P2, false);
            }
            mCurCount = updateDotCount(-mIds, mCurCount);
            drawDots(mSrc[0], mSrc[1], mCurCount);
            drawDots(mDrn[1], mDrn[0], mCurCount);
            drawDots(mSrc[1], mDrn[1], mCurCount);

            if (ShowBulk)
            {
                mCurcountBody1 = updateDotCount(mDiodeCurrent1, mCurcountBody1);
                mCurcountBody2 = updateDotCount(mDiodeCurrent2, mCurcountBody2);
                drawDots(mSrc[0], mBody[0], -mCurcountBody1);
                drawDots(mBody[0], mDrn[0], mCurcountBody2);
            }

            drawPosts();

            if (ControlPanel.ChkShowName.Checked)
            {
                if (mNameV)
                {
                    g.DrawCenteredVText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
                else
                {
                    g.DrawLeftText(ReferenceName, mNamePos.X, mNamePos.Y);
                }
            }
        }