Exemple #1
0
 public static int GetLine(Spec.Type type)
 {
     if (Spec.line.ContainsKey(type))
     {
         return((int)line[type]);
     }
     else
     {
         return(-1);
     }
 }
Exemple #2
0
 public static Spec.Type GetLayout(Spec.Type type)
 {
     foreach (Spec.Type layout in Spec.Layout)
     {
         if ((type & layout) != 0)
         {
             return(layout);
         }
     }
     return(Spec.Type.NULL);
 }
Exemple #3
0
 public static Spec.Type GetClass(Spec.Type type)
 {
     foreach (Spec.Type clss in Spec.Classes)
     {
         if ((type & clss) != 0)
         {
             return(clss);
         }
     }
     return(Spec.Type.NULL);
 }
Exemple #4
0
 public static int GetCapacity(Spec.Type type)
 {
     Spec.Type pure = Spec.GetPureType(type);
     if (Spec.capacity.ContainsKey(pure))
     {
         return((int)Spec.capacity[pure]);
     }
     else
     {
         return(-1);
     }
 }
Exemple #5
0
 public static Spec.Type GetType(int[] signal)
 {
     if (signal.Length == 5)
     {
         Spec.Type clss       = (Type)(1 << (signal[1] * 2 + signal[0]));
         Spec.Type layout     = (Type)(16 * (1 << (signal[3] * 2 + signal[2])));
         Spec.Type handwriter = signal[4] == 1 ? Type.X : Type.NULL;
         return(clss | layout | handwriter);
     }
     else
     {
         return(Type.NULL);
     }
 }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static HqRegion GetHqRegions(Spec.Type type)
        {
            HqRegion r           = new HqRegion();
            Type     layout      = GetLayout(type);
            int      ques_line   = GetLine(GetClass(type));
            int      choice_line = GetLine(layout);

            r.Skin = new RectangleF(0, 0,
                                    Spec.Width, (ques_line + choice_line) * Spec.Line);
            r.Question = new RectangleF(0, 0,
                                        Spec.Width, ques_line * Spec.Line);
            for (int i = 0; i < 4; i++)
            {
                switch (layout)
                {
                case Type._0:
                    r[i] = new RectangleF(
                        i * Spec.Width / 4, r.Question.Height,
                        Spec.Width / 4, Spec.Line);
                    break;

                case Type._1:
                    r[i] = new RectangleF(
                        (i % 2) * Spec.Width / 2, r.Question.Height + (i / 2) * Spec.Line,
                        Spec.Width / 2, Spec.Line);
                    break;

                case Type._2:
                    r[i] = new RectangleF(
                        0, r.Question.Height + i * Spec.Line,
                        Spec.Width, Spec.Line);
                    break;

                case Type._3:
                    r[i] = new RectangleF(
                        0, r.Question.Height + i * Spec.Line,
                        Spec.Width, 2 * Spec.Line);
                    break;
                }
            }
            return(r);
        }
Exemple #7
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Spec.Type type = value as Spec.Type ?? throw new ArgumentException($"{value} is not a jsii Type", nameof(value));

            switch (type.Kind)
            {
            case TypeKind.Enum:
            {
                EnumType derivedType = value as EnumType ?? throw new ArgumentException($"Value has type kind '{type.Kind}', but is not an instance of {nameof(EnumType)}", nameof(value));
                string   json        = JsonConvert.SerializeObject(derivedType, SerializerSettings);
                writer.WriteRawValue(json);
                break;
            }

            case TypeKind.Class:
            {
                ClassType derivedType = value as ClassType ?? throw new ArgumentException($"Value has type kind '{type.Kind}', but is not an instance of {nameof(ClassType)}", nameof(value));
                string    json        = JsonConvert.SerializeObject(derivedType, SerializerSettings);
                writer.WriteRawValue(json);
                break;
            }

            case TypeKind.Interface:
            {
                InterfaceType derivedType = value as InterfaceType ?? throw new ArgumentException($"Value has type kind '{type.Kind}', but is not an instance of {nameof(InterfaceType)}", nameof(value));
                string        json        = JsonConvert.SerializeObject(derivedType, SerializerSettings);
                writer.WriteRawValue(json);
                break;
            }

            default:
            {
                throw new ArgumentException($"Unexpected type kind '{type.Kind}' on type '{value}'", nameof(value));
            }
            }
        }
Exemple #8
0
 public static int GetLineTag(Spec.Type type)
 {
     return(GetLine(GetClass(type)) + GetLine(GetLayout(type)));
 }
Exemple #9
0
 public static bool GetHandWriting(Spec.Type type)
 {
     return((type & Type.X) != 0 ? true : false);
 }
Exemple #10
0
 /// <summary>
 /// Lấy tên của một Spec.Type
 /// </summary>
 /// <param name="obj">Tổ hợp của các Spec.Type</param>
 /// <returns></returns>
 public static string GetName(Spec.Type type)
 {
     return(string.Format("{0}{2}{1}",
                          GetClass(type), GetLayout(type), GetHandWriting(type) ? "X" : ""));
 }
Exemple #11
0
 public static Spec.Type GetPureType(Spec.Type type)
 {
     return(Spec.GetClass(type) | Spec.GetLayout(type));
 }