public UITree(String jsonFileName) { String jsonFilePath = ActionParamTemplate.FindResPath(jsonFileName); if (jsonFilePath == null) { throw new Exception("jsonFile not find in Res Path: " + jsonFileName); } StreamReader sr = new StreamReader(jsonFilePath); String tmpLine = null; String line2 = ""; String line1 = ""; while ((tmpLine = sr.ReadLine()) != null) { line1 = line2; line2 = tmpLine; if (!line1.Contains("classname") || !line2.Contains("name") || line1.Contains("null") || line2.Contains("null")) { continue; } String className = ""; String name = ""; { Match match = Regex.Match(line1.Trim(), "\"classname\": \"(.*)\".*"); if (match == null) { throw new Exception("Illegal classname Jason: line1=" + line1); } className = match.Groups[1].ToString(); } { Match match = Regex.Match(line2.Trim(), "\"name\": \"(.*)\".*"); if (match == null) { throw new Exception("Illegal name Jason: line1=" + line1); } name = match.Groups[1].ToString(); } Console.WriteLine("Widget: name=" + name + ",className=" + className); if (!widgets.ContainsKey(name)) { widgets.Add(name, new UIWidget(name, className)); } else { MessageBox.Show("jsonFileName:" + jsonFileName + " 里面有重复的控件名:" + name); } } }
private void OnPaint(Object sender, PaintEventArgs e) { BufferedGraphicsContext currentContext = BufferedGraphicsManager.Current; BufferedGraphics myBuffer = currentContext.Allocate(e.Graphics, e.ClipRectangle); Graphics g = myBuffer.Graphics; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighSpeed; if (ryData.testBackGround != "") { String path = ActionParamTemplate.FindResPath(ryData.testBackGround); if (path != null) { Image image = Image.FromFile(path); g.DrawImage(image, new Rectangle(0, 0, (int)(image.Width * scaleFactor), (int)(image.Height * scaleFactor)), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); } for (int i = 0; i < ryData.regionParams.Count; ++i) { RegionParam param = ryData.regionParams[i]; Color color = curMouseSelect_regionIndex == i && !curMouseSelect_isCenter ? Color.Red : Color.Black; g.DrawEllipse(new Pen(color, 2), (int)((param.center.x - param.radius.x) * scaleFactor), (int)((ryData.originalSize.y - param.center.y - param.radius.y) * scaleFactor), (int)(param.radius.x * 2 * scaleFactor), (int)(param.radius.y * 2 * scaleFactor)); color = curMouseSelect_regionIndex == i ? Color.Red : Color.Black; g.DrawEllipse(new Pen(color, 2), ((param.moveCenter.x - 2) * scaleFactor), ((ryData.originalSize.y - param.moveCenter.y - 2) * scaleFactor), 4, 4); if (param.dir >= 0) { float lineX = param.amplitude * (float)Math.Cos(param.dir / 180 * Math.PI); float lineY = param.amplitude * (float)Math.Sin(param.dir / 180 * Math.PI); g.DrawLine(new Pen(color, 2), new Point((int)(param.moveCenter.x * scaleFactor), (int)((ryData.originalSize.y - param.moveCenter.y) * scaleFactor)), new Point((int)((param.moveCenter.x + lineX) * scaleFactor), (int)((ryData.originalSize.y - param.moveCenter.y - lineY) * scaleFactor))); } } } myBuffer.Render(); myBuffer.Dispose();//释放资源 }
public void check() { try { switch (ePropType) { case EPropType.ePropType_Int: { int.Parse(tb.Text); break; } case EPropType.ePropType_Float: { float.Parse(tb.Text); break; } case EPropType.ePropType_Point: { new CCPoint(tb.Text); break; } case EPropType.ePropType_Bezier: { new Bezier(tb.Text); break; } case EPropType.ePropType_Str: { if (isFileName && tb.Text != "" && ActionParamTemplate.FindResPath(tb.Text) == null) { throw new Exception(); } break; } case EPropType.ePropType_Strs: { if (isFileName) { foreach (string str in Regex.Split(tb.Text, ",")) { if (str == "") { continue; } if (ActionParamTemplate.FindResPath(str) == null) { throw new Exception(); } } } break; } } tb.ForeColor = defaultForeColor; } catch (Exception) { tb.ForeColor = Color.Red; throw new Exception("错误的参数:" + tb.Text); } }