Beispiel #1
0
        //public static void SetStateForControl(ScoreProgress control, ScoreData data, int maxCount)
        //{
        //    try
        //    {
        //        control.BeginUpdate();
        //        control.Errors = data.CurErrors + data.PrevErrors;
        //        control.Hints = data.CurHints + data.PrevHints;
        //        control.Passes = data.CurPasses + data.PrevPasses;
        //        control.Maximum = maxCount + data.PrevErrors + data.PrevHints + data.PrevPasses;
        //    }
        //    finally
        //    {
        //        control.EndUpdate();
        //    }
        //}
        //public static void SetStateForControl(ScoreProgress control, ScoreData data)
        //{
        //    try
        //    {
        //        control.BeginUpdate();
        //        control.Errors = data.CurErrors + data.PrevErrors;
        //        control.Hints = data.CurHints + data.PrevHints;
        //        control.Passes = data.CurPasses + data.PrevPasses;
        //        control.GetDefaultMaximum();
        //    }
        //    finally
        //    {
        //        control.EndUpdate();
        //    }
        //}

        public static ScoreData GetScoreData(IEnumerable <IScoreUnit> units)
        {
            int unitCount              = 0;
            List <ScoreData> scores    = GetScores(units, ref unitCount);
            ScoreData        scoreData = new ScoreData("Global score", ScoreState.Unknown, unitCount);

            int p, h, e;

            p = h = e = 0;
            foreach (ScoreData state in scores)
            {
                if (state.PrevState == ScoreState.HasError)
                {
                    ++e;
                }
                else if (state.PrevState == ScoreState.Warning)
                {
                    ++h;
                }
                else if (state.PrevState == ScoreState.Complete)
                {
                    ++p;
                }
            }
            scoreData.PrevErrors = e;
            scoreData.PrevHints  = h;
            scoreData.PrevPasses = p;
            return(scoreData);
        }
Beispiel #2
0
 static bool IsManyLettersAndFewErrors(ScoreData unit)
 {
     if (unit.CurErrors == 1)
     {
         return(unit.CurPasses > 9 && unit.CurHints < 1);
     }
     else if (unit.CurErrors == 2)
     {
         return(unit.CurPasses > 15 && unit.CurHints < 2);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
        public static void GetScoreState(ScoreData unit, bool strongRule)
        {
            ScoreState state = ScoreState.Unknown;

            // common rule
            if (unit.CurPasses == 0 && unit.CurErrors == 0)
            {
                state = ScoreState.Unknown;
            }
            // diveded by strongRule and not strong rule
            else
            {
                if (strongRule)
                {
                    if (unit.CurErrors > 0)
                    {
                        state = ScoreState.HasError;
                    }
                    else if (unit.CurHints > 0)
                    {
                        state = ScoreState.Warning;
                    }
                    // passed
                    else
                    {
                        if (unit.PrevState == ScoreState.HasError)
                        {
                            state = ScoreState.Warning;
                        }
                        else
                        {
                            state = ScoreState.Complete;
                        }
                    }
                }
                else
                {
                    //if (!unit.IsGuessed) return ScoreState.Unknown;
                    //else
                    if (unit.CurErrors > 0)
                    {
                        int allCount = unit.CurPasses + unit.CurHints + unit.CurErrors;
                        if (allCount > 10 && IsManyLettersAndFewErrors(unit))
                        {
                            state = ScoreState.Warning;
                        }
                        else
                        {
                            state = ScoreState.HasError;
                        }
                    }
                    else if (unit.CurHints > 0)
                    {
                        if (unit.PrevState == ScoreState.HasError)
                        {
                            if (unit.CurPasses == 0)
                            {
                                state = ScoreState.HasError;
                            }
                            else
                            {
                                state = ScoreState.Warning;
                            }
                        }
                        else
                        {
                            state = ScoreState.Warning;
                        }
                    }
                    else if (unit.CurPasses > 0) //&& unit.IsGuessed)
                    {
                        if (unit.PrevState == ScoreState.HasError)
                        {
                            state = ScoreState.Warning;
                        }
                        else // ScoreState.Complete or Unknown
                        {
                            state = ScoreState.Complete;
                        }
                    }
                }
            }
            unit.PrevState = state;
        }
Beispiel #4
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            #region для многострочного текста
            ///*chk if list box has any items*/
            //if(e.Index > -1)
            //{
            //    string s = Items[e.Index].ToString();

            //    /*Normal items*/
            //    if((e.State & DrawItemState.Focus)==0)
            //    {
            //        e.Graphics.FillRectangle(
            //            new SolidBrush(SystemColors.Window),
            //            e.Bounds);
            //        e.Graphics.DrawString(s,Font,
            //            new SolidBrush(SystemColors.WindowText),
            //            e.Bounds);
            //        e.Graphics.DrawRectangle(
            //            new Pen(SystemColors.Highlight),e.Bounds);
            //    }
            //    else /*Selected item, needs highlighting*/
            //    {
            //        e.Graphics.FillRectangle(
            //            new SolidBrush(SystemColors.Highlight),
            //            e.Bounds);
            //        e.Graphics.DrawString(s,Font,
            //            new SolidBrush(SystemColors.HighlightText),
            //            e.Bounds);
            //    }
            //}
            #endregion

            if (this.Items.Count == 0 || e.Index == -1)
            {
                return;
            }
            Rectangle rect = this.GetItemRectangle(e.Index);
            //  if( rect.Height == 13 )
            //      Console.WriteLine(this.Name + " draw " + rect.Height.ToString() + " (" + debugVar + ")");

            string text      = this.Items[e.Index].ToString();
            Brush  backRound = Brushes.White;
            #region DrawBorder
            if (this.SelectedIndex == e.Index)
            {
                if (this.Focused)
                {
                    backRound = brushSelected;
                }
                else
                {
                    backRound = Brushes.White;
                }

                e.Graphics.FillRectangle(backRound, rect);
                ControlPaint.DrawBorder(e.Graphics, rect, Color.Gray, ButtonBorderStyle.Solid);
            }
            else
            {
                e.Graphics.FillRectangle(backRound, rect);
            }
            #endregion

            ISentence  sentence  = this.Items[e.Index] as ISentence;
            IScoreUnit scoreUnit = this.Items[e.Index] as IScoreUnit;
            ScoreData  scoreData = null;
            if (scoreUnit != null && scoreUnit.IsHaveScore)
            {
                scoreData = scoreUnit.ScoreData;
            }

            if (sentence != null)
            {
                #region WordsToLearn
                if (sentence.WordsToLearn.Count > 0)
                {
                    string markedText = "";
                    int    startText  = -1;
                    // найдем ближайшее слово справа
                    foreach (string word in sentence.WordsToLearn)
                    {
                        startText = text.ToLower().IndexOf(word.ToLower());
                        if (startText == -1)
                        {
                            continue;
                        }
                        markedText = word;

                        int   markedTextLength = markedText.Length;
                        int   markedWidth      = TextRenderer.MeasureText(markedText, this.Font).Width - 7;
                        int   yLocation        = e.Bounds.Y + 1;
                        Point starForMarker    = new Point(0 + 2, yLocation);
                        if (startText != 0)
                        {
                            int widthText  = TextRenderer.MeasureText(text.Substring(0, startText), this.Font).Width;
                            int correction = 7;
                            if (this.Font.Size > 11)
                            {
                                correction += (int)(this.Font.Size - 11);
                            }
                            starForMarker = new Point(widthText - correction, yLocation + 2);
                        }
                        Rectangle boldedRect = new Rectangle(starForMarker, new Size(markedWidth, rect.Height - 2 - 3));
                        e.Graphics.FillRectangle(brushLight, boldedRect);
                        Ul.DoSmoothAngle(e.Graphics, backRound, boldedRect);

                        // Console.WriteLine(word);
                    }
                    e.Graphics.DrawLine(penLight, 0, rect.Y, 0, rect.Y + rect.Height);
                }
                #endregion

                #region ScoreState
                if (scoreData != null && scoreData.PrevState != ScoreState.Unknown)
                {
                    Point    starForMarker  = new Point(0 + 3, e.Bounds.Y + 1);
                    string   textForMeasure = "100";
                    string[] parts          = text.Split('-');
                    if (parts.Length > 1)
                    {
                        textForMeasure = parts[0];
                    }
                    int       markedWidth   = TextRenderer.MeasureText(textForMeasure, this.Font).Width - 9;
                    Rectangle areaForSelect = new Rectangle(starForMarker, new Size(markedWidth, rect.Height - 2));

                    if (scoreData.PrevState == ScoreState.HasError)
                    {
                        e.Graphics.FillRectangle(brErrors, areaForSelect);
                    }
                    else if (scoreData.PrevState == ScoreState.Warning)
                    {
                        e.Graphics.FillRectangle(brHints, areaForSelect);
                    }
                    else if (scoreData.PrevState == ScoreState.Complete)
                    {
                        e.Graphics.FillRectangle(brPasses, areaForSelect);
                    }

                    Ul.DoSmoothAngle(e.Graphics, backRound, areaForSelect);
                    //e.Graphics.DrawImage(im, rect.Location);
                }
                #endregion
            }

            #region отрисовка маркера выделяющего текст (старый (только для словаря) работающий механизм)
            if (this.MarkedItemIndex == e.Index && !string.IsNullOrEmpty(MarkedText) && text.IndexOf(this.MarkedText) != -1)
            {
                int   startText        = text.IndexOf(this.MarkedText);
                int   markedTextLength = this.MarkedText.Length;
                int   markedWidth      = TextRenderer.MeasureText(this.MarkedText, this.Font).Width - 3;
                Point starForMarker    = new Point(0 + 1, e.Bounds.Y + 1);
                if (startText != 0)
                {
                    starForMarker = new Point(TextRenderer.MeasureText(text.Substring(0, startText), this.Font).Width - 7, rect.Y + 1);
                }
                Rectangle boldedRect = new Rectangle(starForMarker, new Size(markedWidth, rect.Height - 2));
                e.Graphics.FillRectangle(brushLight, boldedRect);
            }
            #endregion

            Point pointStart = new Point(e.Bounds.X - 1, e.Bounds.Y - 1);
            if (text.StartsWith(SentenceTabSymbol))
            {
                pointStart = new Point(e.Bounds.X + 15, e.Bounds.Y - 2);
                text       = text.Replace(SentenceTabSymbol, "").TrimStart(' ');
            }
            TextRenderer.DrawText(e.Graphics, text, this.Font, pointStart, SystemColors.ControlText);
            // draw not black numbers
            string number = text.IndexOf('.') > 0 ? text.Substring(0, text.IndexOf('.') + 1) : ""; // this.Items[e.Index].ToString("#");
            if (!string.IsNullOrEmpty(number))
            {
                TextRenderer.DrawText(e.Graphics, number, this.Font, pointStart, Color.Gray);
            }
            //  base.OnDrawItem(e);
        }
Beispiel #5
0
 public void ClearScoreData()
 {
     m_ScoreData = null;
 }
Beispiel #6
0
 public void SetScoreData(ScoreData scoreData)
 {
     m_ScoreData           = scoreData;
     m_ScoreData.MaxScrore = CharHidedCount; // слова могли добавится
 }