Example #1
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && ((e.X >= PositionLeft) && (e.X <= PositionLeft + 10 * KeySizeSqu) && (e.Y <= PositionRight + 4 * KeySizeSqu) && (e.Y >= PositionRight)))
            {//first time button click
                CatchStart = true;//change state to start painting 
                top = -1;
                ColorCord tmp = new ColorCord("", -1, -1, -1, -1, false);
                Word = "";
                key_old = "";
                tmp = BoardKey1.ConvCoord2String(PositionLeft, PositionRight, e.X, e.Y, KeySizeSqu, Max_SquMinDistance);
                if (tmp.Flag)
                {
                    WordPosStack[++top] = tmp;
                    //CurvePointIndex[top] = 1;
                    Word += tmp.key;
                    key_old = tmp.key;
                    index_times = 1 ;
                    FontInfo KeyFontFormat1 = new FontInfo("Arial", 12f, FontStyle.Bold);
                    BoardKey1.KeyIndexPlus(WordPosStack[top], KeyFontFormat1, KeySizeSqu, index_times);
                }
            }
            if ( e.Button == MouseButtons.Right && CatchStart)
            {//right button which cause double
                ColorCord tmp = new ColorCord("", -1, -1, -1, -1, false);
                tmp = BoardKey1.ConvCoord2String(PositionLeft, PositionRight, e.X, e.Y, KeySizeSqu, Max_SquMinDistance);
                if (tmp.Flag && index_times<2)
                {//Comment: a restriction added: if you click the same key twice, then we only record the key for once 
                 //cause there is no English word that has trible same letters
                    WordPosStack[++top] = tmp;
                    Word += tmp.key;
                    key_old = tmp.key;
                    ++index_times;
                    //curve point cal:double letters
                    if (top > 1)
                    {
                        vectoriplus1.X = WordPosStack[top].RX - WordPosStack[top - 1].RX;
                        vectoriplus1.Y = WordPosStack[top].RY - WordPosStack[top - 1].RY;
                        CurvePointIndex[top - 1] = 1;
                        vectori = vectoriplus1;
                    }
                    else if (top == 1)
                    {
                        vectori.X = WordPosStack[top].RX - WordPosStack[top - 1].RX;
                        vectori.Y = WordPosStack[top].RY - WordPosStack[top - 1].RY;
                        CurvePointIndex[top - 1] = 1;
                    }
                    else
                    {//top=0, theorical, no possible this will happen

                    }
                }
            }
        }
Example #2
0
 public void KeyIndexPlus(ColorCord pos, FontInfo KeyFont, int KeySizeSqu, int times)
 {
     PointF pointF = new PointF(pos.pointF.X + KeySizeSqu - sizeF.Width,
                 pos.pointF.Y );
     dc.DrawString(times.ToString(), font, Brushes.Red, pointF);
 }
Example #3
0
 public ColorCord ConvCoord2String(int FormX, int FormY, int X, int Y, int KeySizeSqu, int SquMinDistance)
 {
     ColorCord Change0 = new ColorCord("",-1,-1,-1,-1,false);
     if (   ( (boundary[0, 0] <= X && X <= boundary[0, 1]) ||
             (boundary[1, 0] <= X && X <= boundary[1, 1]) ||
             (boundary[2, 0] <= X && X <= boundary[2, 1]) ||
             (boundary[3, 0] <= X && X <= boundary[3, 1])) &&
             (FormY <= Y && Y <= boundarybottom)
         )
     {//within the boundaries
         string s = "";
         int RX = (X - FormX) / KeySizeSqu, RY = (Y - FormY) / KeySizeSqu;
         int DeltaX = 0;
         int DeltaY = 0;
             switch (RY)
             {
                 case (0):
                     DeltaX = (int)(KeyPosition[RX].X) + KeySizeSqu/2 - X;
                     DeltaY = (int)(KeyPosition[RX].Y) + KeySizeSqu/2 - Y;
                     if ( DeltaX*DeltaX+DeltaY*DeltaY <= SquMinDistance ) 
                     {
                         Change0.SetVal(KeyName[RX], KeyPosition[RX].X, KeyPosition[RX].Y, RX, RY, true);
                     }
                     else
                     {
                         Change0.SetValFal();
                     }
                     break;
                 case (1):
                     if (RX < 9)
                     {
                         int index = RX + firline_KeyNumber;
                         DeltaX = (int)(KeyPosition[index].X) + KeySizeSqu / 2 - X;
                         DeltaY = (int)(KeyPosition[index].Y) + KeySizeSqu / 2 - Y;
                         if (DeltaX * DeltaX + DeltaY * DeltaY <= SquMinDistance)
                         {
                             Change0.SetVal(KeyName[index], KeyPosition[index].X, KeyPosition[index].Y, RX, RY, true);
                         }
                         else
                         {
                             Change0.SetValFal();
                         }
                     }
                     else
                     {
                         s = "";
                         Change0.SetValFal();
                     }
                     break;
                 case (2):
                     if (RX < 8 && RX > 0)
                     {
                         int index = RX + firline_KeyNumber + Secline_KeyNumber - 1;
                         DeltaX = (int)(KeyPosition[index].X) + KeySizeSqu/ 2 - X;
                         DeltaY = (int)(KeyPosition[index].Y) + KeySizeSqu/2 - Y;
                         if (DeltaX * DeltaX + DeltaY * DeltaY <= SquMinDistance)
                         {
                             Change0.SetVal(KeyName[index], KeyPosition[index].X, KeyPosition[index].Y, RX, RY, true);
                         }
                         else
                         {
                             Change0.SetValFal();
                         }
                     }
                     else
                     {
                         s = "";
                         Change0.SetValFal();
                     }
                     break;
                 case (3):
                     if (0 < RX && RX < 8)
                     {
                         s = " ";
                         Change0.SetVal(" ", KeyPosition[keyNumver].X, KeyPosition[keyNumver].Y, RX, RY, true);
                     }
                     else
                     {
                         s = "";
                         Change0.SetValFal();
                     }
                     break;
             }
     }
     else
     {
         Change0.SetValFal();
     }
     return Change0;
 }