public void addTab(string name) { Tab t = new Tab(-bounds.Height + spacing, new List<Text>(), name, this); addTab(t); /* tabs.Add(name, t); t.tabRect.Alpha = 0; t.tabRect.fade(1, .25); t.tabText.Alpha = 0; t.tabText.fade(1, .25); addLine("Type /close to close this tab.", Color.SteelBlue, name); */ }
public void addLine(string s, Dictionary<Pair<int, int>, Color> ccc, string target) { bool multiline = false; Dictionary<Pair<int, int>, Color> newcolors = null; string rest = ""; if (Pulse.Text.getStringSizePBox(s, boxFont).Width > Bounds.Width) { int cutpos = 0; string temp = s; int lastcutpos = 0; int lowerbound = 0; int upperbound = s.Length; while (true) { lastcutpos = cutpos; if (cutpos == 0) { cutpos = temp.Length / 2; } else { // cutpos = temp.Substring(0, cutpos).Length / 2; } if (Pulse.Text.getStringSizePBox(temp.Substring(0, cutpos), boxFont).Width + 10 > Bounds.Width) { upperbound = cutpos; cutpos = (lowerbound + upperbound) / 2; } else { lowerbound = cutpos; cutpos = (lowerbound + upperbound) / 2; } // Console.WriteLine("cutpos " + cutpos + " " + s); if (lastcutpos == cutpos) { Console.WriteLine("cutpos " + cutpos + " " + s); break; } } multiline = true; newcolors = new Dictionary<Pair<int, int>, Color>(); Dictionary<Pair<int, int>, Color> toremove = new Dictionary<Pair<int, int>, Color>(); Dictionary<Pair<int, int>, Color> toadd = new Dictionary<Pair<int, int>, Color>(); foreach (var i in ccc) { if (i.Key.key >= cutpos) //if it's greater or equal then we it goes on next string no questions asked { toremove.Add(i.Key, i.Value); newcolors.Add(new Pair<int, int>(i.Key.key - cutpos, i.Key.value - cutpos), i.Value); } else if (i.Key.value > cutpos && i.Key.key < cutpos) //split the coloring into two { toremove.Add(i.Key, i.Value); toadd.Add(new Pair<int, int>(i.Key.key, cutpos), i.Value); newcolors.Add(new Pair<int, int>(0, i.Key.value - cutpos), i.Value); } } foreach (var i in toremove) { ccc.Remove(i.Key); } foreach (var i in toadd) { ccc.Add(i.Key, i.Value); } rest = s.Substring(cutpos, s.Length - cutpos); s = s.Substring(0, cutpos); // var hack = ccc.ElementAt(ccc.Count - 1); //ccc.Add(new Pair<int, int>(hack.Key.key, s.Length), hack.Value); // ccc.Remove(hack.Key); } LinkText t = new LinkText(new Size(bounds.Width, spacing), new Point(bounds.Location.X + 5, bounds.Location.Y + (tabs.ContainsKey(target) ? tabs[target] : activeTab).lineCounter * spacing)); t.Update(s); t.Colour = Color.White; t.customcol = true; t.colors = ccc; // t.colors.Add() if (!expanded && target == activeTab.Title) { t.Alpha = 0; } t.TextFont = boxFont; t.Shadow = false; t.parse(); //parse after font set if (tabs.ContainsKey(target)) { tabs[target].lineCounter++; tabs[target].Lines.Add(t); tabs[target].Scrollpos += spacing; if (tabs[target].Lines.Count > maxSize) { tabs[target].Lines.RemoveAt(0); // tabs[target].Scrollpos -= spacing; //t.Location = new Point(bounds.Location.X + 5, bounds.Location.Y + (tabs[target].Lines.Count + 1) * spacing); //adding tab may not have succeeded // calcPos(tabs[target].Lines); } } else if (target == "") { activeTab.lineCounter++; activeTab.Lines.Add(t); activeTab.Scrollpos += spacing; if (activeTab.Lines.Count > maxSize) { activeTab.Lines.RemoveAt(0); } } else { //not worried the tab will be full ^^ Tab toAdd = new Tab(-bounds.Height + spacing, new List<Text>(), target, this); addTab(toAdd); t.Location = new Point(bounds.Location.X + 5, bounds.Location.Y + (tabs.ContainsKey(target) ? tabs[target] : activeTab).lineCounter * spacing); //adding tab may not have succeeded toAdd.Lines.Add(t); toAdd.Scrollpos += spacing; toAdd.lineCounter++; /* if (!expanded) { toAdd.tabRect.Alpha = 0; //.Colour = new OpenTK.Graphics.Color4(toAdd.tabRect.Colour.R, toAdd.tabRect.Colour.G, toAdd.tabRect.Colour.B, 0); toAdd.tabText.Alpha = 0; }*/ /*foreach (Text tb in toAdd.Lines) { Console.WriteLine(tb.Line); }*/ } if (multiline) { addLine(rest, newcolors, target); } }
public void addTab(Tab t) { if (!tabs.ContainsKey(t.Title)) { t.tabRect.Alpha = 0; t.tabText.Alpha = 0; if (expanded) { t.tabRect.fade(1, .25); t.tabText.fade(1, .25); } tabs.Add(t.Title, t); addLine("Type /close to close this tab.", Color.SteelBlue, t.Title); } else { addLine("Tab already open", Color.Red); } }
List<Tab> toRemove = new List<Tab>(); //for closed tabs, a queue for them to be on until they finish transitioning #endregion Fields #region Constructors public PTextBox(Game game, Rectangle bounds, string text, IrcClient client) : base(game, bounds, text) { OnLoad(null); bg = new Rect(new Rectangle(bounds.Location, new Size(bounds.Size.Width, bounds.Size.Height + 10))); bg.Colour = Color.FromArgb(200, 20, 20, 20); origpos = bg.Bounds.Y; Tab pulse = new Tab(0, new List<Text>(), baseChannel, this); pulse.Scrollpos = -bounds.Height + spacing; activeTab = pulse; addTab(pulse); ic = client; chatLine = new Text(game.ClientSize, new Size(game.Bounds.Width, 50), new Point(bounds.X + 5, this.bounds.Y + this.bounds.Height - spacing)); chatLine.textFont = boxFont; chatLine.Shadow = false; caret = new Rect(new Rectangle(0, 0, 2, 15)); caret.Colour = Color.White; selectBox = new Rect(new Rectangle(bounds.X + 5, chatLine.Location.Y + 3, 20, 19)); selectBox.Colour = Color.FromArgb(100, Color.LightGray); //activeTab.Scrollpos = addLine("Welcome to pulse chat! Press F2 to maximize/minimize chat.", Color.SteelBlue); Game.lua.RegisterFunction("show", this, this.GetType().GetMethod("show", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)); // Game.lua["pbox"] = this; updateCaret(); //try /lua pbox.bg.Bounds = test(0,300,1024,500) //Game.lua["cm"] = System.Drawing.Rectangle // game.Keyboard.KeyRepeat = false; /* foreach (string s in Game.lua.Globals) { Console.WriteLine(s); }*/ }