예제 #1
0
        //private void DrawBackground(Graphics g){

        //	g.DrawRectangle()
        //}
        #endregion Painting

        ///<summary>This will clear the buttons, reset buttons to the specified list, reset the buttonstates, layout the rows, and invalidate for repaint.</summary>
        public void SetButtons(SigButDef[] butDefs)
        {
            if (butDefs.Length == 0)
            {
                sigButStates = new SignalButtonState[0];
                Invalidate();
                return;
            }
            List <SignalButtonState> listSigButStates = null;

            if (sigButStates != null)
            {
                listSigButStates = sigButStates.Select(x => x.Copy()).ToList();
            }
            //since defs are ordered by buttonIndex, the last def will contain the max number of buttons
            sigButStates = new SignalButtonState[butDefs[butDefs.Length - 1].ButtonIndex + 1];
            for (int i = 0; i < sigButStates.Length; i++)
            {
                sigButStates[i]        = new SignalButtonState();
                sigButStates[i].ButDef = SigButDefs.GetByIndex(i, butDefs);             //might be null
                if (sigButStates[i].ButDef != null)
                {
                    sigButStates[i].Text = sigButStates[i].ButDef.ButtonText;
                }
                sigButStates[i].CurrentColor = Color.White;
                if (listSigButStates != null && sigButStates[i].ButDef != null &&
                    listSigButStates.Any(x => x.ButDef != null && x.ButDef.SigButDefNum == sigButStates[i].ButDef.SigButDefNum))
                {
                    sigButStates[i].ActiveSignal = listSigButStates
                                                   .FirstOrDefault(x => x.ButDef != null && x.ButDef.SigButDefNum == sigButStates[i].ButDef.SigButDefNum).ActiveSignal;
                }
            }
            Invalidate();
        }
예제 #2
0
        //private void DrawBackground(Graphics g){

        //	g.DrawRectangle()
        //}
        #endregion Painting

        ///<summary>This will clear the buttons, reset buttons to the specified list, reset the buttonstates, layout the rows, and invalidate for repaint.</summary>
        public void SetButtons(SigButDef[] butDefs)
        {
            if (butDefs.Length == 0)
            {
                sigButStates = new SignalButtonState[0];
                LayoutButtons();
                Invalidate();
                return;
            }
            //since defs are ordered by buttonIndex, the last def will contain the max number of buttons
            sigButStates = new SignalButtonState[butDefs[butDefs.Length - 1].ButtonIndex + 1];
            for (int i = 0; i < sigButStates.Length; i++)
            {
                sigButStates[i]        = new SignalButtonState();
                sigButStates[i].ButDef = SigButDefs.GetByIndex(i, butDefs);             //might be null
                if (sigButStates[i].ButDef != null)
                {
                    sigButStates[i].Text = sigButStates[i].ButDef.ButtonText;
                }
                sigButStates[i].CurrentColor = Color.White;
            }
            LayoutButtons();
            Invalidate();
        }