public void ArithmeticTest(int width, int height) { Size sz1 = new Size(width, height); Size sz2 = new Size(height, width); Size addExpected = new Size(width + height, height + width); Size subExpected = new Size(width - height, height - width); Assert.Equal(addExpected, sz1 + sz2); Assert.Equal(subExpected, sz1 - sz2); Assert.Equal(addExpected, Size.Add(sz1, sz2)); Assert.Equal(subExpected, Size.Subtract(sz1, sz2)); }
private void InitializeBody() { // queryTextBox this.queryTextBox = new TextBox(); this.queryTextBox.Name = "queryTextBox"; this.queryTextBox.Text = ""; this.queryTextBox.Location = new Point(20, 22); this.queryTextBox.Size = new Size(240, 25); this.queryTextBox.TabIndex = 0; this.queryTextBox.AcceptsReturn = false; this.queryTextBox.AcceptsTab = false; this.queryTextBox.Multiline = false; this.queryTextBox.KeyDown += new KeyEventHandler(this.queryTextBoxKeyDown); // searchButton this.searchButton = new Button(); this.searchButton.Name = "searchButton"; this.searchButton.Text = "Search"; this.searchButton.Location = new Point(280, 20); this.searchButton.Size = new Size(90, 25); this.searchButton.TabIndex = 2; this.searchButton.UseVisualStyleBackColor = true; this.searchButton.Click += new EventHandler(this.searchButtonClick); // resultLabel this.resultLabel = new Label(); this.resultLabel.Name = "resultLabel"; this.resultLabel.Text = ""; this.resultLabel.TabIndex = 4; this.resultLabel.AutoSize = true; // resultPanel this.resultPanel = new Panel(); this.resultPanel.Name = "resultPanel"; this.resultPanel.Location = new Point(20, 65); this.resultPanel.Size = new Size(450, 560); this.resultPanel.TabIndex = 3; this.resultPanel.BackColor = Color.White; this.resultPanel.ForeColor = Color.Black; this.resultPanel.BorderStyle = BorderStyle.FixedSingle; this.resultPanel.AutoScroll = true; this.resultPanel.Controls.Add(this.resultLabel); // final body this.Controls.Add(this.queryTextBox); this.Controls.Add(this.searchButton); this.Controls.Add(this.resultPanel); this.ClientSize = Size.Add(this.resultPanel.Size, panelSizeDiff); this.Resize += new EventHandler(this.FormNameDayRestClientResize); }
protected virtual Size CalcCanvasSize() { Rectangle a = Rectangle.Empty; foreach (RadElement child in this.GetChildren(ChildrenListOptions.Normal)) { if (!child.AutoSize || child.AutoSizeMode != RadAutoSizeMode.FitToAvailableSize) { Rectangle b = new Rectangle(child.BoundingRectangle.Location, Size.Add(child.BoundingRectangle.Size, child.Margin.Size)); a = !a.IsEmpty ? Rectangle.Union(a, b) : b; } } return(new Size(a.Left + a.Width, a.Top + a.Height)); }
private void InitMap() { gMapControl1.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance; GMaps.Instance.Mode = AccessMode.ServerOnly; gMapControl1.Position = new PointLatLng(35.0844, -106.6506); GMapOverlay overlay = new GMapOverlay(gMapControl1, "base"); GMapMarkerGoogleGreen home = new GMapMarkerGoogleGreen(new PointLatLng(35.0844, -106.6506)); home.Size = Size.Add(new System.Drawing.Size(20, 20), new System.Drawing.Size(20, 20)); home.ToolTipText = "This is my home locaiton"; gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick); overlay.Markers.Add(home); gMapControl1.Overlays.Add(overlay); }
private void initMap() { //gMapControl1.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance; gMapControl1.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance; GMaps.Instance.Mode = AccessMode.ServerOnly; gMapControl1.Position = new PointLatLng(37.3653964900001, -121.918542853); GMapOverlay overlay = new GMapOverlay("markers"); //GMapMarkerGoogleGreen home = new GMapMarkerGoogleGreen(new PointLatLng(35.0844, -106.6506)); GMarkerGoogle home = new GMarkerGoogle(new PointLatLng(35.0844, -106.6506), GMarkerGoogleType.green); home.Size = Size.Add(new System.Drawing.Size(20, 20), new System.Drawing.Size(20, 20)); home.ToolTipText = "This is my home locaiton"; gMapControl1.OnMarkerClick += new MarkerClick(gMapControl1_OnMarkerClick); overlay.Markers.Add(home); gMapControl1.Overlays.Add(overlay); }
/// <summary> /// Změří velikost textu this tabulky, uloží ji do <see cref="CurrentSize"/> /// </summary> /// <param name="graphics"></param> /// <param name="extendColumnWidth"></param> public void TextMeasure(Graphics graphics, bool extendColumnWidth = false) { Size currentSize = Size.Empty; if (this.Rows != null && this.Rows.Count > 0) { TableTextRow titleRow = this.Rows[0]; for (int i = 0; i < this.Rows.Count; i++) { this.Rows[i].TextMeasure(this, graphics, extendColumnWidth, i, titleRow, ref currentSize); } currentSize.Width = titleRow.PrepareColumnsWidth(); } this.CurrentSize = currentSize.Add(3, 3); }
private void putTruckOnMap(playBackRow row) { gMapControl1.Position = new PointLatLng(row.Lat, row.Lon); GMapOverlay overlay = new GMapOverlay(row.timeStamp.ToString()); //Image markerImage = Image.FromFile(currentDirectory + geticonName(row.Status)); Image markerImage = getImage(row.Status); markerImage = rotateImageByAngle(markerImage, row.Heading); GMapCustomImageMarker marker = new GMapCustomImageMarker(markerImage, new PointLatLng(row.Lat, row.Lon)); marker.Size = Size.Add(new System.Drawing.Size(markerImage.Height - 4, markerImage.Width - 4), new System.Drawing.Size(10, 10)); marker.ToolTipText = "Truck Number: " + row.TruckNumber + "|TimeStamp: " + row.timeStamp.ToString() + Environment.NewLine + "Click for more data"; overlay.Markers.Add(marker); gMapControl1.Overlays.Add(overlay); }
private void EnsureSpaceExists(TSize fromIndex, TSize toIndex) { TSize itemCount = Size.Subtract(toIndex, fromIndex); TSize newEndIndex = Size.Add(_count, itemCount); if (Size.Compare(newEndIndex, _capacity) > 0) { ExpandAndInsertSpace(fromIndex, toIndex); return; } if (Size.Compare(fromIndex, _count) < 0) { Size.CopyArray(_innerArray, fromIndex, _count, _innerArray, toIndex); } _count = newEndIndex; }
public List <Size> GetSizeList() { List <Size> sizes = new List <Size>(); while (Reader.Read()) { Size size = new Size(); size.Id = Convert.ToInt32(Reader["Id"]); size.ItemSize = Convert.ToInt32(Reader["ItemSize"]); size.Quentity = Convert.ToInt32(Reader["Quentity"]); size.ItemId = Convert.ToInt32(Reader["ItemId"]); size.Add(size); } Reader.Close(); Connection.Close(); return(sizes); }
/// <summary> /// Method to get an image of the decoration /// </summary> /// <param name="dpi">The dpi setting</param> /// <returns>An image of the decoration</returns> // TODO: MOVE TO MAPDECORATION, OR AS EXTENSIONMETHOD FOR IMAPDECORATION? public Image GetLegendImage(int dpi = 96) { var anchor = Anchor; Anchor = MapDecorationAnchor.LeftTop; var location = Location; Location = Point.Empty; Size requiredSize; using (var bmp = new Bitmap(1, 1)) { bmp.SetResolution(dpi, dpi); using (var g = Graphics.FromImage(bmp)) { requiredSize = InternalSize(g, _map); } requiredSize = Size.Add(Size.Add(BorderMargin, BorderMargin), requiredSize); requiredSize = Size.Add(Size.Add(BorderMargin, BorderMargin), requiredSize); requiredSize = Size.Add(new Size(BorderWidth, BorderWidth), requiredSize); } if (requiredSize.Width <= 0 || requiredSize.Height <= 0) { return(null); } var res = new Bitmap(requiredSize.Width, requiredSize.Height); res.SetResolution(dpi, dpi); using (var g = Graphics.FromImage(res)) { g.TranslateTransform(0.5f * BorderWidth + BorderMargin.Width, 0.5f * BorderWidth + BorderMargin.Height); g.Clear(Color.White); Render(g, _map); } Location = location; Anchor = anchor; return(res); }
private void AddShadow(Graphics g, Point ShadowPt, Size BoxToShadow, bool UseTextBuffer = true) { LinearGradientBrush br; GraphicsPath gp = new GraphicsPath(); Point[] pts; Size shadowsz; if (UseTextBuffer) { shadowsz = Size.Add(BoxToShadow, new Size(7, 7)); } else { shadowsz = BoxToShadow; } Color ShadowColor = Color.Black; pts = new Point[] { new Point(ShadowPt.X + shadowsz.Width, ShadowPt.Y + 5), new Point(ShadowPt.X + shadowsz.Width + 5, ShadowPt.Y + 5), new Point(ShadowPt.X + shadowsz.Width + 5, ShadowPt.Y + shadowsz.Height + 5), new Point(ShadowPt.X + shadowsz.Width, ShadowPt.Y + shadowsz.Height) }; gp.AddLines(pts); br = new LinearGradientBrush(new RectangleF((ShadowPt.X + shadowsz.Width - 1), (ShadowPt.Y + 5), 6, (shadowsz.Height)), ShadowColor, Color.Transparent, LinearGradientMode.Horizontal); g.FillPath(br, gp); gp.Reset(); pts = new Point[] { new Point(ShadowPt.X + 5, ShadowPt.Y + shadowsz.Height), new Point(ShadowPt.X + shadowsz.Width, ShadowPt.Y + shadowsz.Height), new Point(ShadowPt.X + shadowsz.Width + 5, ShadowPt.Y + shadowsz.Height + 5), new Point(ShadowPt.X + 5, ShadowPt.Y + shadowsz.Height + 5) }; gp.AddLines(pts); br = new LinearGradientBrush(new RectangleF((ShadowPt.X + 5), (ShadowPt.Y + shadowsz.Height + 5), (shadowsz.Width), 6), ShadowColor, Color.Transparent, LinearGradientMode.Vertical); g.FillPath(br, gp); br.Dispose(); gp.Dispose(); }
protected override SizeF MeasureOverride(SizeF availableSize) { // Ensure that Measure() is called for all children base.MeasureOverride(availableSize); Size res = Size.Empty; if (this.Direction == ArrowDirection.Left || this.Direction == ArrowDirection.Right) { res = MinHorizontalSize; } else { res = MinVerticalSize; } res = Size.Add(res, this.Padding.Size); return(res); }
protected int GetOffsetFromIndex(int topIndex) { if (this.Children.Count <= 0 || topIndex <= 0) { return(0); } int num1 = 0; int num2 = Math.Min(topIndex, this.Children.Count); for (int index = 0; index < num2; ++index) { RadElement child = this.Children[index]; if (child.Visibility != ElementVisibility.Collapsed) { Size size = Size.Add(child.BoundingRectangle.Size, child.Margin.Size); num1 += this.Orientation == Orientation.Vertical ? size.Height : size.Width; } } return(num1); }
private void ShowUserControl(string controlType) { this.Text = "Welcome, " + name_emp; switch (controlType) { case "Director": SetLogVisibility(false); if (dir == null) { dir = new Director(); } this.Size = new System.Drawing.Size(775, 525); this.FormBorderStyle = FormBorderStyle.Sizable; this.Controls.Add(dir); break; case "Seller": SetLogVisibility(false); if (sel == null) { sel = new Seller(); } this.Size = Size.Add(sel.Size, new Size(16, 38)); this.FormBorderStyle = FormBorderStyle.FixedSingle; this.Controls.Add(sel); break; case "StoreKeeper": SetLogVisibility(false); if (keep == null) { keep = new Storekeeper(); } this.Size = new System.Drawing.Size(800, 425); this.FormBorderStyle = FormBorderStyle.Sizable; this.Controls.Add(keep); break; } return; }
public void TestVisualState_ResizesCorrectly() { //---------------Set up test pack------------------- IDateTimePicker dateTimePicker = CreateDateTimePicker(); dateTimePicker.ShowCheckBox = false; dateTimePicker.ValueOrNull = null; IControlHabanero nullDisplayControl = GetNullDisplayControl(dateTimePicker); //-------------Assert Preconditions ------------- Assert.IsNotNull(nullDisplayControl, "DateTimePicker should have a null display control."); const int widthDifference = 24; const int heightDifference = 7; Assert.AreEqual(dateTimePicker.Width - widthDifference, nullDisplayControl.Width); Assert.AreEqual(dateTimePicker.Height - heightDifference, nullDisplayControl.Height); //---------------Execute Test ---------------------- dateTimePicker.Size = Size.Add(dateTimePicker.Size, new Size(10, 4)); //---------------Test Result ----------------------- Assert.AreEqual(dateTimePicker.Width - widthDifference, nullDisplayControl.Width); Assert.AreEqual(dateTimePicker.Height - heightDifference, nullDisplayControl.Height); }
Size ILegendItem.InternalSize(Graphics g, Map map) { if (Exclude) { return(Size.Empty); } var size = ComputeItemSize(g); foreach (var subItem in SubItems) { var subItemSize = subItem.InternalSize(g, map); subItemSize.Width += Indentation; if (subItem is MapDecoration) { var tmp = (MapDecoration)subItem; subItemSize = Size.Add(subItemSize, Size.Add(tmp.BorderMargin, tmp.BorderMargin)); } size = ComputeMergedSize(size, subItemSize); } return(size); }
private static void DrawWindow( Graphics g, SolidPenBrush color, Point start, Point end) { var dist = Point.Subtract(end, new Size(start)); var size = new Size(dist.X / 3, dist.Y / 3); var point2 = Point.Add(start, Size.Add(size, size)); g.DrawLine( color.Pen, start, Point.Add(start, size)); g.DrawLine( color.LightPen, Point.Add(start, size), point2); g.DrawLine( color.Pen, point2, end); }
private static void DrawWindow( Graphics g, ColorTools tool, Point start, Point end) { var pt = Point.Subtract(end, new Size(start)); var xy = new Size(pt.X / 3, pt.Y / 3); pt = Point.Add(start, Size.Add(xy, xy)); g.DrawLine( tool.Pen, start, Point.Add(start, xy)); g.DrawLine( tool.PenLight, Point.Add(start, xy), pt); g.DrawLine( tool.Pen, pt, end); }
protected override Size MeasureOverride(Size availableSize) { //Size actualSize = this.INTERNAL_GetActualWidthAndHeight(); //return actualSize; Size BorderThicknessSize = new Size(BorderThickness.Left + BorderThickness.Right, BorderThickness.Top + BorderThickness.Bottom); if (noWrapSize == Size.Empty) { noWrapSize = Application.Current.TextMeasurementService.MeasureTextBlock(Text ?? String.Empty, FontSize, FontFamily, FontStyle, FontWeight, /*FontStretch, */ TextWrapping.NoWrap, Padding, Double.PositiveInfinity); noWrapSize = noWrapSize.Add(BorderThicknessSize); } if (TextWrapping == TextWrapping.NoWrap || noWrapSize.Width <= availableSize.Width) { return(noWrapSize); } Size TextSize = Application.Current.TextMeasurementService.MeasureTextBlock(Text ?? String.Empty, FontSize, FontFamily, FontStyle, FontWeight, /*FontStretch, */ TextWrapping, Padding, (availableSize.Width - BorderThicknessSize.Width).Max(0)); TextSize = TextSize.Add(BorderThicknessSize); return(TextSize); }
public Size GetDesiredSize() { Size res = Size.Empty; if (this.UseNewLayoutSystem) { if (this.GetBitState(NeverMeasuredStateKey)) { this.Measure(new SizeF(float.PositiveInfinity, float.PositiveInfinity)); } res = Size.Round(this.DesiredSize); } else { //this.AssureElements(); Size borderSize = Size.Round(this.borderElement.BorderSize); Size ownOffset = Size.Add(this.Padding.Size, borderSize); ownOffset = Size.Add(this.Margin.Size, ownOffset); res = Size.Add(this.layoutPanel.FullSize, ownOffset); } return(res); }
protected override void OnInsertRange <TInputSize, TInput> (Iterator position, IHive <T, TInputSize, TInput> range, out Range <T, TSize, Iterator> insertedRange) { TSize beginIndex = position.Key; TSize endIndex; TInputSize itemCount; if (range.TryGetCount(out itemCount)) { endIndex = Size.Add(beginIndex, Size.From <TInputSize>(itemCount)); EnsureSpaceExists(beginIndex, endIndex); TSize targetIndex = beginIndex; for (TInput i = range.Begin; !i.Equals(range.End); i.Increment()) { Size.SetValueInArray(_innerArray, i.Read(), targetIndex); Size.Increment(ref targetIndex); } } else { StreamBuffer <T, TSize, TSizeOperations> snapshot = StreamBuffer <T, TSize, TSizeOperations> .Create(range); endIndex = Size.Add(beginIndex, snapshot.Count); if (Size.Compare(snapshot.Count, Size.Zero) > 0) { EnsureSpaceExists(beginIndex, endIndex); snapshot.CopyTo(_innerArray, beginIndex); } } insertedRange = new Range <T, TSize, Iterator>(position, new Iterator(this, endIndex)); }
protected virtual int GetLastFullVisibleItemsNum() { if (this.Children.Count <= 0) { return(0); } int num1 = this.Orientation == Orientation.Vertical ? this.Size.Height : this.Size.Width; int num2 = 0; for (int index = this.Children.Count - 1; index >= 0; --index) { RadElement child = this.Children[index]; if (child.Visibility != ElementVisibility.Collapsed) { Size size = Size.Add(child.BoundingRectangle.Size, child.Margin.Size); num2 += this.Orientation == Orientation.Vertical ? size.Height : size.Width; if (num2 > num1) { return(Math.Max(1, this.Children.Count - index - 1)); } } } return(this.Children.Count); }
public static int DrawMessage(Graphics g, Message msg, Message prevMsg, Font fnt, ControlState state, int y = 0, int width = 500, int cHeight = 400, MouseState mouse = default(MouseState)) { if (msg == null) { return(y); } int height = 0; const int padding = 10; const int avatarSz = 48; int hWidth = width - avatarSz - 3 * padding; int msgWidth = width / 100 * 80; User usr = msg.Author; if (usr == null) { return(y); } Size hSize = Size.Empty; if (prevMsg == null || prevMsg.Author != usr) { int aX = padding; if (msg.Out) { aX = width - padding - avatarSz; } Bitmap p = usr.GetPhoto(); if (p != null && y > -avatarSz) { g.DrawImage(p, new Rectangle(aX, y, avatarSz, avatarSz)); } hSize = Size.Ceiling(g.MeasureString(usr.FullName, fnt, hWidth)); int hX = 2 * padding + avatarSz; if (msg.Out) { hX = width - 2 * padding - avatarSz - hSize.Width; } if (y > -hSize.Height) { DrawString(g, usr.FullName, fnt, Brushes.DimGray, new Rectangle(new Point(hX, y), hSize)); } } height += padding / 2 + hSize.Height; Size msgSize = Size.Ceiling(g.MeasureString(msg.Body, fnt, msgWidth)); Size msgRectSize = Size.Add(msgSize, new Size(2 * padding, 2 * padding)); int rX = 2 * padding + avatarSz + 5; if (msg.Out) { rX = width - 2 * padding - avatarSz - msgRectSize.Width - 5; } int rY = y + padding / 2 + hSize.Height; if (msg.Attachments != null && msg.Attachments.Length > 0) { int ax = 0, ay = 0; int mw = 0, mh = 0; foreach (Attachment a in msg.Attachments) { Size asz = a.Measure(g, fnt, msgWidth - ax, true); if (mh < asz.Height) { mh = asz.Height; } if (ax + asz.Width > msgWidth) { ax = 0; ay += mh + padding; mh = 0; } else { ax += asz.Width + padding; } if (mw < ax) { mw = ax; } } msgRectSize = new Size(Math.Max(msgSize.Width, mw) + padding, msgSize.Height + ay + mh + 2 * padding); rX = 2 * padding + avatarSz + 5; if (msg.Out) { rX = width - 2 * padding - avatarSz - msgRectSize.Width - 5; } rY = y + padding / 2 + hSize.Height; } Color msgRectColor = Color.White; if (msg.Crypted) { msgRectColor = Color.Lime; } if (!msg.Read) { msgRectColor = Color.DodgerBlue; if (msg.Crypted) { msgRectColor = Color.LimeGreen; } } Brush msgRectBrush = new SolidBrush(Color.FromArgb(128, msgRectColor)); if (rY > -msgRectSize.Height && rY < cHeight) { g.FillRoundRectangle(msgRectBrush, new Rectangle(new Point(rX, rY), msgRectSize), padding / 2); } int tX = rX; int tY = rY + padding; if (msg.Out) { tX = rX + msgRectSize.Width; } g.FillPolygon(msgRectBrush, new[] { new Point(tX, tY), new Point(tX, tY + 16), new Point(((msg.Out) ? tX + 10 : tX - 10), tY + 8) }); if (y + padding + padding / 2 + hSize.Height > -msgSize.Height && y < cHeight) { Rectangle msgRectangle = new Rectangle(new Point(rX + padding, y + padding + padding / 2 + hSize.Height), msgSize); /*if (msg.Body.Length > 256) * { * DrawString(g, msg.Body, fnt, Brushes.Black, msgRectangle, StringAlignment.Near); * } * else * {*/ List <TextBlock> blocks; if (msg.RuntimeData.ContainsKey("TextBlocks")) { blocks = (List <TextBlock>)msg.RuntimeData["TextBlocks"]; } else { blocks = new List <TextBlock>(); int blkend = 0; MatchCollection matches = _URL.Matches(msg.Body); if (matches.Count > 0) { foreach (Match m in matches) { String url = m.ToString(); int idx = msg.Body.IndexOf(url, StringComparison.Ordinal); if (idx > blkend) { blocks.Add(new TextBlock(msg.Body, blkend, idx - blkend)); } TextBlock blk = new TextBlock(msg.Body, idx, url.Length, TextStyle.Link); blocks.Add(blk); blkend = blk.End; } } if (msg.Body.Length > blkend) { blocks.Add(new TextBlock(msg.Body, blkend, msg.Body.Length - blkend)); } if (Emoji.FindEmojis(msg.Body).Count > 0) { List <TextBlock> nbl = new List <TextBlock>(); foreach (TextBlock b in blocks) { foreach (String em in Emoji.FindEmojis(b.Fragment)) { int idx = b.Fragment.IndexOf(em, StringComparison.Ordinal); if (idx > 0) { nbl.Add(new TextBlock(msg.Body, b.Start, idx, b.Style, b.State)); } nbl.Add(new EmojiBlock(msg.Body, b.Start + idx, em.Length, b.State)); if (idx + em.Length < b.Length) { nbl.Add(new TextBlock(msg.Body, b.Start + idx + em.Length, b.Length - idx - em.Length, b.Style, b.State)); } } } blocks = nbl; } Console.WriteLine(((msg.Body.Length > 32) ? msg.Body.Substring(0, 32) + "..." : msg.Body) + ": " + blocks.Count + " block(s)"); blocks.Sort((blk, blk2) => blk.Start.CompareTo(blk2.Start)); msg.RuntimeData.Add("TextBlocks", blocks); } if (blocks.Count > 16) { DrawString(g, msg.Body, fnt, Brushes.Black, msgRectangle, StringAlignment.Near); } else { int sX = rX + padding, sY = y + padding + padding / 2 + hSize.Height, eX = msgSize.Width, eY = msgSize.Height; int cX = 0, cY = 0, cH = 0; CharacterRange[] ranges = { new CharacterRange(0, 1) }; String _c; Rectangle charRect = Rectangle.Empty; int cP = 0; using (StringFormat stringFormat = new StringFormat()) { stringFormat.Alignment = StringAlignment.Near; stringFormat.LineAlignment = StringAlignment.Center; foreach (TextBlock blk in blocks) { blk.StartPoint = new Point(cX, cY); if (blk is EmojiBlock) { Bitmap e = ((EmojiBlock)blk).Emoji; if (e != null) { g.DrawImage(e, new Rectangle(new Point(sX + cX + 2, sY + cY), new Size(16, 16))); if (cH < 16) { cH = 16; } cX += 20; if (cX > eX) { cX = 0; cY += cH; } } cP += blk.Length; } else { while (cP >= blk.Start && cP < blk.End) { ranges[0].First = cP; stringFormat.SetMeasurableCharacterRanges(ranges); _c = msg.Body.Substring(cP, 1); charRect = Rectangle.Round( g.MeasureCharacterRanges(msg.Body, fnt, msgRectangle, stringFormat)[0] .GetBounds(g)); if (cH < charRect.Height) { cH = charRect.Height; } Color c = Color.Black; if (blk.Style == TextStyle.Link) { c = Color.Blue; if (mouse != null) { int mpX = mouse.Position.X; int mpY = mouse.Position.Y; if (mpY >= sY + blk.StartPoint.Y && mpY <= sY + blk.EndPoint.Y && mpX >= sX + blk.StartPoint.X && mpX <= sX + blk.EndPoint.X) { blk.State = ControlState.Hover; if (mouse.Clicked) { blk.State = ControlState.Pressed; mouse.Clicked = false; } } else { blk.State = ControlState.Idle; } if (blk.State != ControlState.Idle) { if (blk.State == ControlState.Hover) { c = Color.DarkOrange; } if (blk.State == ControlState.Pressed) { c = Color.Red; App.Platform.OpenUrl(msg.Body.Substring(blk.Start, blk.Length)); } g.FillRectangle(Brushes.White, charRect); } } else { blk.State = ControlState.Idle; c = Color.Blue; } } g.DrawString(_c, fnt, new SolidBrush(c), sX + cX, sY + cY); if (blk.Style == TextStyle.Link) { g.DrawLine(new Pen(c), sX + cX + 2, sY + cY + cH, sX + cX + charRect.Width + 2, sY + cY + cH); } cX += charRect.Width; if (cX > eX || _c == "\n") { cX = 0; cY += cH; if (_c != "\n") { cH = 0; } } cP++; } } blk.EndPoint = new Point(cX + charRect.Width + 2, cY + cH); } } } } height += msgRectSize.Height + padding; if (msg.Attachments != null && msg.Attachments.Length > 0) { int ax = 0, ay = 0; int mh = 0; foreach (Attachment a in msg.Attachments) { Size asz = a.Measure(g, fnt, msgWidth - ax, true); Rectangle aRect = new Rectangle(new Point(rX + padding + ax, rY + msgSize.Height + padding + ay), asz); bool aHover = false, aClick = false; if (mouse != null && aRect.Contains(mouse.Position)) { aHover = true; if (mouse.Clicked) { aClick = true; mouse.Clicked = false; } } a.Draw(g, aRect, fnt, true, aHover, aClick); if (mh < asz.Height) { mh = asz.Height; } if (ax + asz.Width > msgWidth) { ax = 0; ay += mh + padding; mh = 0; } else { ax += asz.Width + padding; } } } return(height); }
public void AddTest() { Assert.AreEqual(sz1_1, Size.Add(sz1_0, sz0_1), "ADD#1"); Assert.AreEqual(sz1_1, Size.Add(sz1_1, new Size(0, 0)), "ADD#2"); }
public RectangleD Add(SizeD size) { return(new RectangleD(UpperLeft, Size.Add(size))); }
private static bool GetFromProcMemInfo(SmapsReader smapsReader, ref ProcMemInfoResults procMemInfoResults) { const string path = "/proc/meminfo"; // this is different then sysinfo freeram+buffered (and the closest to the real free memory) // MemFree is really different then MemAvailable (while free is usually lower then the real free, // and available is only estimated free which sometimes higher then the real free memory) // for some distros we have only MemFree try { using (var bufferedReader = new KernelVirtualFileSystemUtils.BufferedPosixKeyValueOutputValueReader(path)) { bufferedReader.ReadFileIntoBuffer(); var memAvailableInKb = bufferedReader.ExtractNumericValueFromKeyValuePairsFormattedFile(MemAvailable); var memFreeInKb = bufferedReader.ExtractNumericValueFromKeyValuePairsFormattedFile(MemFree); var totalMemInKb = bufferedReader.ExtractNumericValueFromKeyValuePairsFormattedFile(MemTotal); var swapTotalInKb = bufferedReader.ExtractNumericValueFromKeyValuePairsFormattedFile(SwapTotal); var commitedInKb = bufferedReader.ExtractNumericValueFromKeyValuePairsFormattedFile(Committed_AS); var totalClean = new Size(0, SizeUnit.Kilobytes); var totalDirty = new Size(0, SizeUnit.Bytes); var sharedCleanMemory = new Size(0, SizeUnit.Bytes); if (smapsReader != null) { var result = smapsReader.CalculateMemUsageFromSmaps <SmapsReaderNoAllocResults>(); totalClean.Add(result.SharedClean, SizeUnit.Bytes); totalClean.Add(result.PrivateClean, SizeUnit.Bytes); sharedCleanMemory.Set(result.SharedClean, SizeUnit.Bytes); totalDirty.Add(result.TotalDirty, SizeUnit.Bytes); } procMemInfoResults.AvailableMemory = new Size(memFreeInKb, SizeUnit.Kilobytes); procMemInfoResults.TotalMemory = new Size(totalMemInKb, SizeUnit.Kilobytes); procMemInfoResults.Commited = new Size(commitedInKb, SizeUnit.Kilobytes); // on Linux, we use the swap + ram as the commit limit, because the actual limit // is dependent on many different factors procMemInfoResults.CommitLimit = new Size(totalMemInKb + swapTotalInKb, SizeUnit.Kilobytes); // AvailableMemoryForProcessing: AvailableMemory actually does add reclaimable memory (divided by 2), so if AvailableMemory is equal or lower then the _real_ available memory // If it is lower the the real value because of RavenDB's Clean memory - then we use 'totalClean' as reference // Otherwise - either it is correct value, or it is lower because of (clean or dirty memory of) another process var availableMemoryForProcessing = new Size(Math.Max(memAvailableInKb, memFreeInKb), SizeUnit.Kilobytes); procMemInfoResults.AvailableMemoryForProcessing = Size.Max(availableMemoryForProcessing, totalClean); procMemInfoResults.SharedCleanMemory = sharedCleanMemory; procMemInfoResults.TotalDirty = totalDirty; } } catch (Exception ex) { if (Logger.IsInfoEnabled) { Logger.Info($"Failed to read value from {path}", ex); } return(false); } return(true); }
void ILayer.Render(Graphics g, MapViewport map) { // We don't need to regenerate the tiles if (map.Envelope.Equals(_lastViewport) && _numPendingDownloads == 0) { g.DrawImage(_bitmap, Point.Empty); return; } // Create a backbuffer lock (_renderLock) { if (_bitmap == null || _bitmap.Size != map.Size) { _bitmap = new Bitmap(map.Size.Width, map.Size.Height, PixelFormat.Format32bppArgb); using (var tmpGraphics = Graphics.FromImage(_bitmap)) tmpGraphics.Clear(Color.Transparent); } } // Save the last viewport _lastViewport = map.Envelope; // Cancel old rendercycle ((ITileAsyncLayer)this).Cancel(); var mapViewport = map.Envelope; var mapSize = map.Size; var mapColumnWidth = _cellSize.Width + _cellBuffer.Width; var mapColumnHeight = _cellSize.Height + _cellBuffer.Width; var columns = (int)Math.Ceiling((double)mapSize.Width / mapColumnWidth); var rows = (int)Math.Ceiling((double)mapSize.Height / mapColumnHeight); var renderMapSize = new Size(columns * _cellSize.Width + _cellBuffer.Width, rows * _cellSize.Height + _cellBuffer.Height); var horizontalFactor = (double)renderMapSize.Width / mapSize.Width; var verticalFactor = (double)renderMapSize.Height / mapSize.Height; var diffX = 0.5d * (horizontalFactor * mapViewport.Width - mapViewport.Width); var diffY = 0.5d * (verticalFactor * mapViewport.Height - mapViewport.Height); var totalRenderMapViewport = mapViewport.Grow(diffX, diffY); var columnWidth = totalRenderMapViewport.Width / columns; var rowHeight = totalRenderMapViewport.Height / rows; var rmdx = (int)((mapSize.Width - renderMapSize.Width) * 0.5f); var rmdy = (int)((mapSize.Height - renderMapSize.Height) * 0.5f); var tileSize = Size.Add(_cellSize, Size.Add(_cellBuffer, _cellBuffer)); var miny = totalRenderMapViewport.MinY; var pty = rmdy + renderMapSize.Height - tileSize.Height; for (var i = 0; i < rows; i++) { var minx = totalRenderMapViewport.MinX; var ptx = rmdx; for (var j = 0; j < columns; j++) { var tmpMap = new Map(_cellSize); tmpMap.Layers.Add(_baseLayer); tmpMap.DisposeLayersOnDispose = false; tmpMap.ZoomToBox(new Envelope(minx, minx + columnWidth, miny, miny + rowHeight)); var cancelToken = new System.Threading.CancellationTokenSource(); var token = cancelToken.Token; var pt = new Point(ptx, pty); var t = new System.Threading.Tasks.Task(delegate { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } var res = RenderCellOnThread(token, pt, tmpMap); if (res) { System.Threading.Interlocked.Decrement(ref _numPendingDownloads); var e = DownloadProgressChanged; if (e != null) { e(_numPendingDownloads); } } }, token); var dt = new RenderTask { CancellationToken = cancelToken, Task = t }; lock (_currentTasks) { _currentTasks.Add(dt); _numPendingDownloads++; } t.Start(); minx += columnWidth; ptx += _cellSize.Width; } miny += rowHeight; pty -= _cellSize.Height; } }
private IdentKey CreateViewForm(IView view, DialogFormOption options, DialogSetting settings) { _logger.Debug("CreateViewForm." + view.ToStringExt()); CheckView(view); IdentKey key = new IdentKey(); ViewData viewData = new ViewData(view); FormBase form = new FormBase(options); form.Owner = _parentForm; //TODO: разобраться на что может повлиять form.Tag = key; form.Text = view.Caption; form.Icon = Icon.FromHandle((view.Image as Bitmap).GetHicon()); Control control = viewData.View.UserControl as Control; Size size = Size.Add(control.Size, new Size(0, GetFormHeaderHeigth(form))); form.Size = size; if (settings != null) { if (settings.Position != null) { form.Location = settings.Position; } if (settings.Size != null) { form.Size = settings.Size; } } else { form.Location = new Point(_parentForm.Location.X + (_parentForm.Width - form.Width) / 2, _parentForm.Location.Y + (_parentForm.Height - form.Height) / 2); } view.DialogSetting = form.DialogSetting; try { form.Controls.Add(control); control.Dock = DockStyle.Fill; control.Parent = form; IDialogResult dialogButtons = view.UserControl as IDialogResult; if (dialogButtons != null) { IButtonControl okButton = dialogButtons.OkButton as IButtonControl; if (okButton != null) { form.AcceptButton = okButton; } IButtonControl cancelButton = dialogButtons.CancelButton as IButtonControl; if (cancelButton != null) { form.CancelButton = cancelButton; } } _statusBarButtonController.AddButton(key, viewData.View.Caption, viewData.View.Hint, viewData.View.Image); viewData.Form = form; _views.Add(key, viewData); viewData.View.Ident = key; SubscibeToForm(form); } catch (Exception ex) { ClearFormResourceSuppress(key, viewData); throw ex; } return(key); }
private void ResizeForm() { int topWidth = 0; int middleWidth = 0; int bottomWidth = 0; int width = 0; int height = 0; Font headerFont = default(Font); Font footerFont = default(Font); Size headerSize = default(Size); Size footerSize = default(Size); headerFont = (Font)this.KryptonManager.GlobalPalette.GetContentShortTextFont(PaletteContentStyle.LabelNormalControl, PaletteState.Normal); footerFont = (Font)this.KryptonManager.GlobalPalette.GetContentShortTextFont(PaletteContentStyle.LabelNormalControl, PaletteState.Normal); headerSize = (Size)this.MeasureString(this.lblHeader.Text, headerFont, (int)320); footerSize = (Size)this.MeasureString(this.lblFooter.Text, footerFont, (int)320); this.lblHeader.Size = Size.Add(headerSize, new Size(10, 0)); this.lblFooter.Size = Size.Add(footerSize, new Size(10, 0)); topWidth = this.pnlHeader.Width; if (this.ShowHeaderImage) { topWidth += this.pnlHeaderImage.Width; } middleWidth = this.pnlButtons.Width; if (this.ShowDetails) { middleWidth += this.pnlDetails.Width; } bottomWidth = this.pnlFooter.Width; if (this.ShowFooterImage) { bottomWidth += this.pnlFooterImage.Width; } width = Math.Max(Math.Max(topWidth, bottomWidth), middleWidth); this.PanelTop.Height = Math.Max(this.pnlHeaderImage.Height, this.pnlHeader.Height); this.PanelMiddle.Height = Math.Max(this.pnlDetails.Height, this.pnlButtons.Height); this.PanelBottom.Height = Math.Max(this.pnlFooterImage.Height, this.pnlFooter.Height); height = this.PanelTop.Height + this.PanelMiddle.Height; if (this.ShowFooter) { height += this.PanelBottom.Height; } this.pnlHeaderImage.Location = new Point(0, 0); if (this.ShowHeaderImage) { this.pnlHeader.Location = new Point(this.pnlHeaderImage.Width, 0); } else { this.pnlHeader.Location = new Point(0, 0); } this.pnlDetails.Location = new Point(0, 0); this.pnlButtons.Location = new Point(width - this.pnlButtons.Width, 0); this.pnlFooterImage.Location = new Point(0, 0); if (this.ShowFooterImage) { this.pnlFooter.Location = new Point(this.pnlFooterImage.Width, 0); } else { this.pnlFooter.Location = new Point(0, 0); } this.ClientSize = new Size(width, height); }
private void btnLoadData_Click(object sender, EventArgs e) { btnLoadData.Enabled = false; btnLoadData.BackColor = System.Drawing.Color.Red; btnPlayback.BackColor = System.Drawing.Color.Red; btnStopPlayback.BackColor = System.Drawing.Color.Red; btnPlayback.Enabled = false; btnStopPlayback.Enabled = false; Cursor = Cursors.WaitCursor; SQLCode sql = new SQLCode(); bool chkTime = checkTimeRange(); if (!chkTime) { return; } try { if (startDateTime == Convert.ToDateTime("1/1/0001") || endDateTime == Convert.ToDateTime("1/1/0001")) { MessageBox.Show("Missing Date/Time information, preload data first"); return; } if (string.IsNullOrEmpty(cboTrucks.Text)) { MessageBox.Show("Please select a truck first"); return; } bool check = true; if (cboTrucks.Text.ToUpper() != "SELECT" && check == true) { sql.loadTruckPlaybackData(cboTrucks.Text, startDateTime, endDateTime); check = false; } if (cboCallsigns.Text.ToUpper() != "SELECT" && check == true) { sql.loadCallSignPlayback(cboCallsigns.Text, startDateTime, endDateTime); check = false; } if (cboDrivers.Text.ToUpper() != "SELECT" && check == true) { sql.loadDriverPlayback(cboDrivers.Text, startDateTime, endDateTime); check = false; } /* Can't run a query by contractor or beat since that would return multiple trucks * Multiple truck completely bone up the graph */ if (cboContractors.Text.ToUpper() != "SELECT" && check == true) { /* * sql.loadContractorPlayback(cboContractors.Text, startDateTime, endDateTime); * check = false; * */ MessageBox.Show("This functionality has been disabled"); return; } if (cboBeats.Text.ToUpper() != "SELECT" && check == true) { /* * sql.loadBeatPlayback(cboBeats.Text, startDateTime, endDateTime); * check = false; * */ MessageBox.Show("This functionality has been disabled"); return; } gMapControl1.Overlays.Clear(); if (globalData.playbackData.Count > 0) { string beatNumber = "NOBEAT"; foreach (playBackRow row in globalData.playbackData) { if (row.Beat != "NOBEAT") { beatNumber = row.Beat; break; } } drawBeats(beatNumber); drawDrops(beatNumber); gMapControl1.Position = new PointLatLng(globalData.playbackData[0].Lat, globalData.playbackData[0].Lon); //chart data chartControl1.Series.Clear(); //find max speed in range int maxSpeed = 0; foreach (playBackRow row in globalData.playbackData) { if (row.Speed > maxSpeed) { maxSpeed = row.Speed; } } if (maxSpeed == 0) { maxSpeed = 1; } DevExpress.XtraCharts.Series series = new DevExpress.XtraCharts.Series("Speed Over Time", DevExpress.XtraCharts.ViewType.Line); DevExpress.XtraCharts.Series barSeries = new DevExpress.XtraCharts.Series("Max Speed", DevExpress.XtraCharts.ViewType.Bar); //Add Data to the chart foreach (playBackRow row in globalData.playbackData) { string st = string.Empty; string hour = row.timeStamp.Hour.ToString(); string minute = row.timeStamp.Minute.ToString(); string second = row.timeStamp.Second.ToString(); while (hour.Length < 2) { hour = "0" + hour; } while (minute.Length < 2) { minute = "0" + minute; } while (second.Length < 2) { second = "0" + second; } st = hour + "." + minute + "." + second; series.Points.Add(new DevExpress.XtraCharts.SeriesPoint(st, row.Speed)); DevExpress.XtraCharts.SeriesPoint barPoint = new DevExpress.XtraCharts.SeriesPoint(st, maxSpeed); barPoint.Tag = row.Status; //barPoint.DateTimeArgument = row.timeStamp; barPoint.ToolTipHint = row.Status; barSeries.Points.Add(barPoint); //add map data GMapOverlay overlay = new GMapOverlay(row.timeStamp.ToString()); //Image markerImage = Image.FromFile(currentDirectory + geticonName(row.Status)); Image markerImage = getImage(row.Status); markerImage = rotateImageByAngle(markerImage, row.Heading); GMapCustomImageMarker marker = new GMapCustomImageMarker(markerImage, new PointLatLng(row.Lat, row.Lon)); marker.Size = Size.Add(new System.Drawing.Size(markerImage.Height - 4, markerImage.Width - 4), new System.Drawing.Size(10, 10)); marker.ToolTipText = "Truck Number: " + row.TruckNumber + "|TimeStamp: " + row.timeStamp.ToString() + Environment.NewLine + "Click for more data"; overlay.Markers.Add(marker); gMapControl1.Overlays.Add(overlay); } gMapControl1.Refresh(); //barSeries.ToolTipHintDataMember = barSeries.Tag.ToString(); chartControl1.Series.Add(barSeries); chartControl1.Series.Add(series); //map data gvData.DataSource = globalData.playbackData; gvData.RefreshDataSource(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } try { List <statusData> status = sql.getStatusData(cboTrucks.Text, startDateTime, endDateTime); gvStatusData.DataSource = status; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } btnLoadData.Enabled = true; btnLoadData.BackColor = System.Drawing.Color.LightGreen; btnPlayback.BackColor = System.Drawing.Color.LightGreen; btnStopPlayback.BackColor = System.Drawing.Color.Red; btnPlayback.Enabled = true; btnStopPlayback.Enabled = false; btnExportData.BackColor = System.Drawing.Color.LightGreen; btnExportData.Enabled = true; Cursor = Cursors.Arrow; }