public string HitTest(Point p, out IBlock[] defaultArgs) { string ret = ""; int i = 0; foreach (Rectangle r in tabRects) { if (r.Contains(p)) { currentCategory = tabTexts[i]; Rectangle oldRect = new Rectangle(Location, Size); LayoutTools(currentCategory); defaultArgs = null; if (Modified != null) { Modified(this, oldRect); } return(""); } i++; } if (needScroll) { //textMetrics.FillRectangle(Brushes.Fuchsia, leftScrollRect.Offseted(Location.X, Location.Y)); if (leftScrollRect.Contains(p)) { ScrollBig(-1); defaultArgs = null; return(""); } // textMetrics.FillRectangle(Brushes.Fuchsia, rightScrollRect.Offseted(Location.X, Location.Y)); if (rightScrollRect.Contains(p)) { ScrollBig(1); defaultArgs = null; return(""); } } int startPos = ScrollPositionStart(); int endPos = ScrollPositionEnd(); for (i = startPos; i < endPos; ++i) { ToolSpec ts = currentTab[i]; if (ts.rectangle.Contains(p)) { defaultArgs = ts.defaultArgs; return(ts.funcName); } } defaultArgs = new IBlock[] { }; return(ret); }
public void UpdateBitmap(string category, int tabWidth, int tabHeight) { using (Graphics g = Graphics.FromImage(bitmap)) { g.FastSettings(); g.Clear(Color.Transparent); g.FillRectangle(new SolidBrush(Color.FromArgb(150, 150, 150)), 0, tabHeight, bitmap.Width, bitmap.Height - tabHeight); int catX = 10; Brush text, bg; tabRects.Clear(); tabTexts.Clear(); int pullY; // pull the tab up a bit so as not to intersect with the toolbox foreach (string cat in categories) { tabTexts.Add(cat); if (cat == category) { text = Brushes.White; bg = Brushes.Black; pullY = 0; } else { text = Brushes.Black; bg = Brushes.DarkGray; pullY = 1; } Size sz = g.MeasureString(cat, tabFont).ToSize(); Rectangle r = new Rectangle(catX, 0, sz.Width + tabPadding * 2, sz.Height + tabPadding * 2 - pullY); g.FillRectangle(bg, r); tabRects.Add(r); g.DrawString(cat, tabFont, text, catX + tabPadding, tabPadding); g.DrawRectangle(Pens.Black, r); catX += tabSpacing + r.Width; } int startPos = ScrollPositionStart(); int endPos = ScrollPositionEnd(); for (int i = startPos; i < endPos; ++i) { ToolSpec ts = currentTab[i]; Rectangle r = ts.rectangle; g.DrawImageUnscaled(ts.bmp, r.Location); } Color c1 = Color.FromArgb(20, 20, 20); g.FillRectangle(new SolidBrush(c1), 0, tabHeight, bitmap.Width, 5); g.FillRectangle(new SolidBrush(c1), 0, tabHeight, 5, bitmap.Height - tabHeight); //Color c2 = Color.FromArgb(220, 220, 220); Color c2 = Color.FromArgb(20, 20, 20); g.FillRectangle(new SolidBrush(c2), bitmap.Width - 5, tabHeight, 5, bitmap.Height - tabHeight); g.FillRectangle(new SolidBrush(c2), 0, bitmap.Height - 5, bitmap.Width, 5); if (needScroll) { using (Pen p = new Pen(Color.Black, 1.5f)) { Point[] scroll1 = new Point[] { new Point(5 + scrollArrowWidth / 2, tabHeight + 5), new Point(5 + scrollArrowWidth / 2, tabHeight + initialSize.Height - 5), new Point(5, tabHeight + initialSize.Height / 2 - 5), }; leftScrollRect = new Rectangle(5, tabHeight + 5, scrollArrowWidth, initialSize.Height - 10); g.FillPolygon(Brushes.LightGray, scroll1); g.DrawPolygon(p, scroll1); Point[] scroll2 = new Point[] { new Point(initialSize.Width - 5 - scrollArrowWidth / 2, tabHeight + 5), new Point(initialSize.Width - 5 - scrollArrowWidth / 2, tabHeight + initialSize.Height - 5), new Point(initialSize.Width - 5, tabHeight + initialSize.Height / 2 - 5), }; rightScrollRect = new Rectangle(initialSize.Width - 5 - scrollArrowWidth, tabHeight + 5, scrollArrowWidth, initialSize.Height - 10); g.FillPolygon(Brushes.LightGray, scroll2); g.DrawPolygon(p, scroll2); } } } }