private void ExchangeData(TagBase newtag) { if (newtag == nowdata) { return; } if (nowdata.cv != null) { foreach (var item in nowdata.cv.Children) { if (item is Button) { ((Button)item).Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); } } } if (newtag.cv != null) { foreach (var item in newtag.cv.Children) { if (item is Button) { ((Button)item).Background = MainWindow.MakeBrush(SelectColor); } } } UpdateWindow(newtag); WindowRePosition(); }
private void GridAddButton(TagBase tag) { RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(CtrlButtonSize); tw_grid.RowDefinitions.Add(rd); Canvas cv = CreateButton(tag); tag.cv = cv; tw_grid.Children.Add(cv); Grid.SetRow(cv, tw_grid.RowDefinitions.Count - 1); }
public void SplitTag(TagBase tag) { CtrlButtonRemoveData(tag, false); POINT pt = new POINT(); GetCursorPos(out pt); TagWindow tagw = ((MainWindow)Application.Current.MainWindow).CreateTagWindow(pt.X - tag.Width / 2, pt.Y - tag.Height / 2); tag.OnTransfer(tagw); tagw.AddTag(tag, false); tagw.Window_MouseLeftButtonDown(null, null); }
private void CreateTagFromFile() { if (!File.Exists("data.dat")) { return; } using (StreamReader sr = new StreamReader("data.dat")) { ColorThemeIndex = Convert.ToInt32(sr.ReadLine()); ApplyColorTheme(); string strLine = string.Empty; Regex rex = new Regex(@"^\d+$"); while (true) { strLine = sr.ReadLine(); if (strLine == null) { break; } if (rex.IsMatch(strLine)) { int num = Convert.ToInt32(strLine); strLine = sr.ReadLine(); var pms = strLine.Split(' '); TagWindow t = CreateTagWindow(Convert.ToInt32(pms[0]), Convert.ToInt32(pms[1])); t.FullLoaded = false; int focustagindex = Convert.ToInt32(pms[2]); TagBase savedtag = null; for (int i = 0; i < num; ++i) { strLine = sr.ReadLine(); var name_data = strLine.Split(new char[] { ' ' }, 2); var datastr = Regex.Unescape(name_data[1]); TagBase tag = CreateAndAddTag(name_data[0], datastr, t); if (i == focustagindex) { savedtag = tag; } } if (pms[3] == "True") { t.NeedHide = true; t.tw_border.Visibility = Visibility.Collapsed; } t.FullLoaded = true; t.UpdateWindow(savedtag); } } } }
public void UpdateWindow(TagBase newtag) { if (nowdata != null) { ClearContent(); } nowdata = newtag; if (nowdata.IsCreated) { SetTagActive(false); nowdata.OnShow(); } else { SetTagActive(); nowdata.CreateButtonShow(); } }
public bool AddTag(TagBase tag, bool create = true) { try { if (nowdata != null) { ClearContent(); } if (create) { tag.OnInit(); } data.Add(tag); UpdateAll(tag); return(true); } catch { return(false); } }
private Canvas CreateButton(TagBase tag) { int tagindex = data.IndexOf(tag); Canvas cv = new Canvas(); cv.Height = CtrlButtonSize; cv.Width = CtrlButtonSize; cv.Background = new SolidColorBrush(Color.FromArgb(1, 1, 1, 1)); cv.Children.Add(CreatePath("M 1,10 L 1,1 L 10,1")); cv.Children.Add(CreatePath("M 40,1 L 49,1 L 49,10")); cv.Children.Add(CreatePath("M 49,40 L 49,49 L 40,49")); cv.Children.Add(CreatePath("M 1,40 L 1,49 L 10,49")); Button btn = new Button(); btn.Style = FindResource("btnstyle") as Style; btn.FontFamily = new FontFamily("Agency FB"); btn.FontSize = 18; btn.Width = CtrlButtonSize - 4; btn.Height = CtrlButtonSize - 4; btn.Margin = new Thickness(2, 2, 0, 0); btn.FontWeight = FontWeights.Bold; btn.Foreground = MainWindow.MakeBrush(FontColor); if (tag == nowdata) { btn.Background = MainWindow.MakeBrush(SelectColor); } btn.BorderBrush = null; btn.Content = tag.GetName(); btn.Click += (s, e) => { ExchangeData(tag); }; btn.MouseRightButtonUp += (s, e) => { CtrlButtonRemoveData(tag); }; cv.PreviewMouseLeftButtonDown += (s, e) => { if (nowdata == tag) { ((MainWindow)Application.Current.MainWindow).StartSplitBgWorker(this, tag, tagindex); } }; cv.Children.Add(btn); return(cv); }
public void StartSplitBgWorker(TagWindow t, TagBase tag, int tagindex) { if (splitbgworker == null) { double top = t.Top, left = t.Left; splitbgworker = new BackgroundWorker(); splitbgworker.WorkerSupportsCancellation = true; splitbgworker.DoWork += t.Check_MouseLeaveButton; splitbgworker.RunWorkerCompleted += (s1, e1) => { if (!FinishSplit) { FinishSplit = true; if (Mouse.LeftButton == MouseButtonState.Pressed) { t.SplitTag(tag); } } }; Rect arg = new Rect(left, top + TagWindow.CtrlButtonSize * (tagindex + 1), TagWindow.CtrlButtonSize, TagWindow.CtrlButtonSize); splitbgworker.RunWorkerAsync(arg); } }
private void CtrlButtonRemoveData(TagBase tag, bool destroy = true) { if (tag == nowdata) { ExchangeData(data.Find(x => { return(x != tag); })); } if (destroy) { tag.OnExit(); } data.Remove(tag); tw_grid.Children.Remove(tag.cv); if (data.Count == 1) { IsCtrlBtnFolded = true; FoldCtrlButton(); } else { UpdateRowConfig(); } UpdateCtrlBtnContent(); }
private void UpdateAll(TagBase newtag) { UpdateWindow(newtag); UpdateCtrlBtnContent(); }