public static bool TryGetPos(TjsValue pos, out Point p)
        {
            TjsArray xy = pos as TjsArray;

            if (xy != null && xy.val.Count == 2)
            {
                TjsNumber x = xy.val[0] as TjsNumber;
                TjsNumber y = xy.val[1] as TjsNumber;
                if (x != null && y != null)
                {
                    p = new Point((int)x.val, (int)y.val);
                    return(true);
                }
                else
                {
                    Debug.Assert(false, "invalid element in pos struct");
                }
            }
            else
            {
                Debug.Assert(false, "invalid pos struct");
            }

            p = Point.Empty;
            return(false);
        }
Example #2
0
        private void test()
        {
            return;

            string strTitle = ";System.title =\"模板工程\";";
            string strW     = ";scWidth =1024;";
            string strH     = ";scHeight =768;";

            Regex regTitle = new Regex(@"\s*;\s*System.title\s*=");
            Regex regW     = new Regex(@"\s*;\s*scWidth\s*=");
            Regex regH     = new Regex(@"\s*;\s*scHeight\s*=");

            bool ret = false;

            ret = regTitle.IsMatch(strTitle);
            ret = regW.IsMatch(strW);
            ret = regH.IsMatch(strH);

            string[] layouts = Directory.GetFiles(_curConfig.ThemeDataFolder, WizardConfig.UI_LAYOUT);

            // 测试tjs值读取
            foreach (string layout in layouts)
            {
                using (StreamReader r = new StreamReader(layout))
                {
                    TjsParser parser = new TjsParser();
                    TjsValue  val    = null;
                    do
                    {
                        val = parser.Parse(r);
                    } while (val != null);
                }
            }

            // 测试tjs符号读取
            using (StreamReader r = new StreamReader(layouts[0]))
            {
                TjsParser       parser = new TjsParser();
                TjsParser.Token token  = null;
                do
                {
                    token = parser.GetNext(r);
                } while (token != null && token.t != TjsParser.TokenType.Unknow);
            }

            // 资源转换器对象的测试用例
            ResConfig config = new ResConfig();

            config.files.Add(new ResFile(@"a.png"));
            config.files.Add(new ResFile(@"b.png"));
            config.name = "TestTest";
            config.path = @"c:\";

            config.Save(@"c:\test.xml");
            ResConfig newConfig = ResConfig.Load(@"c:\test.xml");

            ResConverter cov = new ResConverter();

            cov.Start(config, @"d:\", 1024, 768, 1920, 1080);
        }
        public static TjsArray ScaleButton(TjsDict dict, string name, double scaleX, double scaleY)
        {
            TjsValue v = null;

            if (dict.val.TryGetValue(name, out v))
            {
                // 按钮上多记录了一个是否显示: x, y, shown
                TjsArray xys = v as TjsArray;
                if (xys != null && xys.val.Count == 3)
                {
                    TjsNumber x = xys.val[0] as TjsNumber;
                    TjsNumber y = xys.val[1] as TjsNumber;
                    TjsNumber s = xys.val[2] as TjsNumber;

                    if (x != null && y != null && s != null)
                    {
                        TjsArray xysnew = CreatePos((int)(x.val * scaleX), (int)(y.val * scaleY));
                        xysnew.val.Add(new TjsNumber(s.val));
                        dict.val[name] = xysnew;
                        return(xysnew);
                    }
                    else
                    {
                        Debug.Assert(false, "invalid element in button struct");
                    }
                }
                else
                {
                    Debug.Assert(false, "invalid button struct");
                }
            }

            return(null);
        }
        public static TjsArray ScalePosArray(TjsDict dict, string name, double scaleX, double scaleY)
        {
            TjsValue v = null;

            if (dict.val.TryGetValue(name, out v))
            {
                // 检查是不是数组
                TjsArray arr = v as TjsArray;
                if (arr != null)
                {
                    // 从中读取两个元素的坐标数组
                    List <TjsValue> arraynew = new List <TjsValue>();
                    foreach (TjsValue pos in arr.val)
                    {
                        Point p = Point.Empty;
                        if (TryGetPos(pos, out p))
                        {
                            // 按比例缩放
                            TjsArray posnew = CreatePos((int)(p.X * scaleX), (int)(p.Y * scaleY));
                            arraynew.Add(posnew);
                        }
                        else
                        {
                            Debug.Assert(false, "invalid struct in pos array");
                        }
                    }

                    dict.val[name] = new TjsArray(arraynew);
                    return(arr);
                }
            }

            return(null);
        }
        // 修改UI布局文件
        static void ModifyLayout(string dataPath, int sw, int sh, int dh, int dw)
        {
            // 更新layout
            string[] layouts = Directory.GetFiles(dataPath, WizardConfig.UI_LAYOUT);
            foreach (string layout in layouts)
            {
                TjsDict setting = TjsValue.Load(layout) as TjsDict;

                if (setting != null)
                {
                    ModifyDict(setting, sw, sh, dw, dh);

                    // 对这个文件里的按钮作特殊处理
                    if (layout.ToLower().EndsWith("uislpos.tjs"))
                    {
                        double scaleX = (double)dw / sw;
                        double scaleY = (double)dh / sh;
                        TjsHelper.ScaleButton(setting, "back", scaleX, scaleY);
                        TjsHelper.ScaleButton(setting, "up", scaleX, scaleY);
                        TjsHelper.ScaleButton(setting, "down", scaleX, scaleY);
                    }
                }

                setting.Save(layout, Encoding.Unicode);
            }
        }
        public void LoadSetting(string file)
        {
            setting = null;

            if (File.Exists(file))
            {
                setting = TjsValue.Load(file) as TjsDict;
            }
        }
        public static double ScaleInteger(TjsDict dict, string name, double scale)
        {
            TjsValue val = dict.GetValue(name);
            double   num = (val != null) ? val.ToDouble() : double.NaN;

            if (!double.IsNaN(num))
            {
                num = num * scale;
                dict.SetNumber(name, Math.Floor(num));
                return(num);
            }

            string str = dict.GetString(name);

            if (double.TryParse(str, out num))
            {
                num = num * scale;
                dict.SetString(name, Math.Floor(num).ToString());
                return(num);
            }

            return(double.NaN);
        }