public OSDGroup clone() { var group = new OSDGroup(); group.Name = this.Name; group.IsColor = this.IsColor; group.Color = Color.FromArgb(this.Color.R, this.Color.G, this.Color.B); group.Digit = this.Digit; for (int i = 0; i < mItemList.Count; i++) { group.ItemList.Add(mItemList[i].clone()); } return(group); }
private void onGroupAddButtonClick(object sender, EventArgs e) { var item = new ListViewItem(); item.Text = "Default"; item.SubItems.Add(mGroupAddTextBox.Text); item.UseItemStyleForSubItems = false; mGroupListView.Items.Add(item); var group = new OSDGroup(); group.Name = mGroupAddTextBox.Text; group.IsColor = false; mGroupList.Add(group); mGroupAddTextBox.Clear(); }
public void read() { Monitor.Enter(mLock); String jsonString; try { jsonString = File.ReadAllText(mOSDFileName); } catch { this.clear(); Monitor.Exit(mLock); this.write(); return; } try { var rootObject = JObject.Parse(jsonString); mIsEnable = (rootObject.ContainsKey("enable") == true) ? rootObject.Value <bool>("enable") : false; mIsTime = (rootObject.ContainsKey("time") == true) ? rootObject.Value <bool>("time") : false; if (rootObject.ContainsKey("group") == true) { var groupList = rootObject.Value <JArray>("group"); for (int i = 0; i < groupList.Count; i++) { var groupObject = (JObject)groupList[i]; string name = (groupObject.ContainsKey("name") == false) ? "" : groupObject.Value <string>("name"); bool isColor = (groupObject.ContainsKey("isColor") == false) ? false : groupObject.Value <bool>("isColor"); byte r = (groupObject.ContainsKey("r") == false) ? (byte)0xFF : groupObject.Value <byte>("r"); byte g = (groupObject.ContainsKey("g") == false) ? (byte)0xFF : groupObject.Value <byte>("g"); byte b = (groupObject.ContainsKey("b") == false) ? (byte)0xFF : groupObject.Value <byte>("b"); int digit = (groupObject.ContainsKey("digit") == false) ? 5 : groupObject.Value <int>("digit"); var group = new OSDGroup(); group.Name = name; group.IsColor = isColor; group.Color = Color.FromArgb(r, g, b); group.Digit = digit; if (groupObject.ContainsKey("item") == true) { var itemList = groupObject.Value <JArray>("item"); for (int j = 0; j < itemList.Count; j++) { var itemObject = (JObject)itemList[j]; var itemType = (itemObject.ContainsKey("itemType") == false) ? (int)OSDItemType.Unknown : itemObject.Value <int>("itemType"); var unitType = (itemObject.ContainsKey("unitType") == false) ? (int)OSDUnitType.Unknown : itemObject.Value <int>("unitType"); int index = (itemObject.ContainsKey("index") == false) ? 0 : itemObject.Value <int>("index"); isColor = (itemObject.ContainsKey("isColor") == false) ? false : itemObject.Value <bool>("isColor"); r = (itemObject.ContainsKey("r") == false) ? (byte)0xFF : itemObject.Value <byte>("r"); g = (itemObject.ContainsKey("g") == false) ? (byte)0xFF : itemObject.Value <byte>("g"); b = (itemObject.ContainsKey("b") == false) ? (byte)0xFF : itemObject.Value <byte>("b"); if (itemType >= (int)OSDItemType.Unknown || unitType >= (int)OSDUnitType.Unknown) { continue; } var item = new OSDItem(); item.ItemType = (OSDItemType)itemType; item.UnitType = (OSDUnitType)unitType; item.Index = index; item.IsColor = isColor; item.Color = Color.FromArgb(r, g, b); group.ItemList.Add(item); } } mGroupList.Add(group); } } } catch { this.clear(); Monitor.Exit(mLock); return; } Monitor.Exit(mLock); }