What olive bullet on breakpoint means in SharpDevelop - c#

Sometimes when I set a breakpoint and start debugging its color changes from red to olive:
When it happens debugging doesn't stop at all - breakpoint is ignored.
I want to know why this happens and how to avoid it in the future.
Edit:
It does not happens only when breakpoint is set on commented line of code:

It's open source. Downloading it and finding the relevant code took me about 5 minutes:
public void DrawBreakpoint(Graphics g, int y, bool isEnabled, bool isHealthy)
{
int diameter = Math.Min(iconBarWidth - 2, textArea.TextView.FontHeight);
Rectangle rect = new Rectangle(1,
y + (textArea.TextView.FontHeight -
diameter) / 2,
diameter,
diameter);
using (GraphicsPath path = new GraphicsPath()) {
path.AddEllipse(rect);
using (PathGradientBrush pthGrBrush = new PathGradientBrush(path)) {
pthGrBrush.CenterPoint = new PointF(rect.Left + rect.Width / 3 ,
rect.Top + rect.Height / 3);
pthGrBrush.CenterColor = Color.MistyRose;
Color[] colors = {isHealthy ? Color.Firebrick : Color.Olive};
pthGrBrush.SurroundColors = colors;
if (isEnabled) {
g.FillEllipse(pthGrBrush, rect);
} else {
g.FillEllipse(SystemBrushes.Control, rect);
using (Pen pen = new Pen(pthGrBrush)) {
g.DrawEllipse(pen, new Rectangle(rect.X + 1, rect.Y + 1,
rect.Width - 2,
rect.Height - 2));
}
}
}
}
}
That circle color is "Color.Olive". If you want to know why isHealthy is false, use the source. There's a couple of reasons I could find quickly: the source file has changed or the module isn't loaded, There may be more.

This occurs if you compile the programm as "release".

Your line is commented where the breakpoint is set.

Related

Refresh the canvas only for certain brushes

I'm trying to graph some circles and lines etc but I only want some lines to refresh on the canvas and the others not to, is there any way around this?
For example the mypen, mypen2 and mypen3, I want them to refresh on canvas but the graphics "g" a little further down I don't want to refresh, I want all the instances to show. How do I do this? Here is my code
private void drawlines()
{
canvas.Refresh();
int j = Int32.Parse(ivalue.Text);
float position1 = canvas.Width / 2;
float position2 = canvas.Height / 2;
float XX = (float)(Math.Round(position1 + Math.Sin(DegreeToRadian(j)) * 100));
float XY = (float)(Math.Round(position2 - Math.Cos(DegreeToRadian(j)) * 100));
float X2 = (position1 + XX);
float XY2 = XY;
System.Drawing.Pen myPen;
System.Drawing.Pen myPen2;
System.Drawing.Pen myPen3;
System.Drawing.Pen myPen4;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
myPen2 = new System.Drawing.Pen(System.Drawing.Color.Blue);
myPen3 = new System.Drawing.Pen(System.Drawing.Color.Black);
myPen4 = new System.Drawing.Pen(System.Drawing.Color.Green);
System.Drawing.Graphics formGraphics = canvas.CreateGraphics();
formGraphics.DrawRectangle(myPen,XX, XY,3,3);
formGraphics.DrawRectangle(myPen2, canvas.Width / 2, XY, 3, 3);
formGraphics.DrawRectangle(myPen3, position1, position2, 3, 3);
formGraphics.DrawRectangle(myPen4, position1, XY2, 3, 3);
label1.Text = Convert.ToString(XY);
label1.Refresh();
listBox1.Items.Clear();
listBox1.Items.Add("XX=[" + XX + "] XY=[" + XY + "]");
}
private void Go_Click(object sender, EventArgs e)
{
for (int i = 0; i <= 360; i = i + 1)
{
drawlines();
int linearm = (canvas.Width / 2) - i;
ivalue.Text = Convert.ToString(i);
ivalue.Refresh();
int testx = Int32.Parse(label1.Text);
Graphics g;
g = canvas.CreateGraphics();
Pen p;
Rectangle r;
p = new Pen(Brushes.Green);
r = new Rectangle(linearm,testx, 1, 1);
g.DrawRectangle(p, r);
System.Threading.Thread.Sleep(15);
}
}
I assume you are using winforms? If so you need to change your code to work like this:
To be persistant everything need to be drawin in the Paint event and using its e.Graphics object. (This is the Golden Rule! Corollary: Never use System.Drawing.Graphics formGraphics = canvas.CreateGraphics();)
Everything you want to be drawn must be stored in Lists of classes, sufficient to hold all info you need.
If you were to draw only Rectangles in only one pen a List<Rectangle> would be enough, but for other shapes and pens you will want to create a class to hold those data.
Now you can:
Draw them all in the Paint event, iterating the List<your DrawItemClass>
Remove or set inactive those items in the List you don't want to be drawn any longer..

GraphicsPath.AddString not as clear as Graphics.DrawString

My text and font looks good for most of my application; however, when I do .DrawPath() and the path has a string / text in the GraphicsPath it always looks fussy or blurry.
Can someone tell me how to get the .DrawPath with a string in to look as nice as a GrahpicsPath.DrawString?
//Bay Symbol
dc.DrawImage(Symbols.GetSymbol(SymbolType.Bay, (i + 1).ToString()), (x + (wPx / 2)) - 10, Constants.ELEVATION_START_Y - 35);
public static Bitmap GetSymbol(SymbolType symType, string text = "", bool attachLeg = true)
{
var sym = new Bitmap(50, 50);
sym.SetResolution(150, 150);
using (Graphics dc = Graphics.FromImage(sym))
{
dc.SmoothingMode = SmoothingMode.AntiAlias;
switch (symType)
{
//code removed for clarity
case SymbolType.Bay:
dc.DrawPath(ShopDrawing.Pens.GetSymbolPen(), CreateBaySymbol(text));
if (attachLeg)
AttachSymbolLeg(dc, Constants.BAY_SYMBOL);
break;
};
dc.SmoothingMode = SmoothingMode.Default;
return sym;
}
}
internal static GraphicsPath CreateBaySymbol(string text = "")
{
GraphicsPath myPath = new GraphicsPath();
myPath.AddRectangle(Constants.BAY_SYMBOL);
if (!string.IsNullOrEmpty(text)) { Util.AddStringToPath(myPath, text); }
return myPath;
}
internal static void AddStringToPath(GraphicsPath path, string text)
{
var textSize = TextRenderer.MeasureText(text, Constants.DETAIL_BOX_FONT);
float centerX = (path.GetBounds().Width / 2) - (textSize.Width / 2),
centerY = (path.GetBounds().Height / 2) - (textSize.Height / 2);
//Add the string to the path.
path.AddString(text,
Constants.DETAIL_BOX_FONT.FontFamily,
(int)Constants.DETAIL_BOX_FONT.Style,
Constants.DETAIL_BOX_FONT.Size,
new PointF(centerX + 2, centerY + 2),
StringFormat.GenericDefault)
Symbols = a symbol that numbers each part of the elevation below. You can see how the numbering will start at 1 then 2 then 3 and so on.
Here is an snapshot that shows how all the font / text looks good, as in the numbers for the width and height, but the numbering inside the symbols look horrible.

Thick Line Drawing problem in C#.NET

I wanted to draw thick lines using Graphics.Lines() method. But it looks like the API has some bugs. If you try to render the user control with the following code, you would get weird looking image. I was wondering if there is some smoothing mode or something similar that could take care of this line drawing glitch.
private void UserControl1_Paint(object sender, PaintEventArgs e)
{
int n = 100;
Point[] points = new Point[n];
double x = 2;
int y = 50;
for (int i = 0; i < n; i++)
{
Point p = new Point();
p.X = 200 + (int)(i * x);
p.Y = 200 + (int)(Math.Sin(i * 0.2) * y);
points[i] = p;
}
Pen pen = new Pen(new SolidBrush(Color.Blue));
//Pen pen = new Pen(new LinearGradientBrush(new Point(0, 0), new Point(0, 100), Color.Black, Color.Red));
pen.Width = 200;
e.Graphics.DrawLines(pen, points);
}
You see the effect of GDI+ trying to draw end-caps on the line. That's not going to come to a good end with such a thick pen. About what you'd imagine from daVinci painting the Mona Lisa with a broom. Fix:
Pen pen = new Pen(new SolidBrush(Color.Blue));
pen.EndCap = System.Drawing.Drawing2D.LineCap.Square;
pen.StartCap = System.Drawing.Drawing2D.LineCap.Square;
Or draw a polygon instead so that GDI+ has a better idea what is front and back:
e.Graphics.DrawPolygon(pen, points);
Well, it doesn't look like a devil anymore. Keep the line width proportional to the details in the line.
Here is the result of your code drawing using a pen of width 200 (pixels):
And here it is at a width of 2:
The pen width property is usually pixels, but it is based on the Graphics object's PageUnit property (itself a GraphicsUnit property). Check to make sure you've set these values to what you want.

Texture on 3D object in C#

I'm using VS 2008 - C# Express. I want to reflect a text block onto 3D mesh object. I found a sample code snippet in a website. I added into my project and then ran it, unfortunately the debugger sent the error message "The type or namespace name "Run" could not be found...". What am I doing wrong ? Is there a missing namespace ?
Could you help me.
Regards.
The code snippet :
public static ModelVisual3D CreateTextLabel3D(string text, Brush textColor, bool bDoubleSided, double height, Point3D center, Vector3D over, Vector3D up)
{
// First we need a textblock containing the text of our label
TextBlock tb = new TextBlock(new Run(text));
tb.Foreground = textColor;
tb.FontFamily = new FontFamily("Arial");
// Now use that TextBlock as the brush for a material
DiffuseMaterial mat = new DiffuseMaterial();
mat.Brush = new VisualBrush(tb);
// We just assume the characters are square
double width = text.Length * height;
// Since the parameter coming in was the center of the label,
// we need to find the four corners
// p0 is the lower left corner
// p1 is the upper left
// p2 is the lower right
// p3 is the upper right
Point3D p0 = center - width / 2 * over - height / 2 * up;
Point3D p1 = p0 + up * 1 * height;
Point3D p2 = p0 + over * width;
Point3D p3 = p0 + up * 1 * height + over * width;
// Now build the geometry for the sign. It's just a
// rectangle made of two triangles, on each side.
MeshGeometry3D mg = new MeshGeometry3D();
mg.Positions = new Point3DCollection();
mg.Positions.Add(p0); // 0
mg.Positions.Add(p1); // 1
mg.Positions.Add(p2); // 2
mg.Positions.Add(p3); // 3
if (bDoubleSided)
{
mg.Positions.Add(p0); // 4
mg.Positions.Add(p1); // 5
mg.Positions.Add(p2); // 6
mg.Positions.Add(p3); // 7
}
mg.TriangleIndices.Add(0);
mg.TriangleIndices.Add(3);
mg.TriangleIndices.Add(1);
mg.TriangleIndices.Add(0);
mg.TriangleIndices.Add(2);
mg.TriangleIndices.Add(3);
if (bDoubleSided)
{
mg.TriangleIndices.Add(4);
mg.TriangleIndices.Add(5);
mg.TriangleIndices.Add(7);
mg.TriangleIndices.Add(4);
mg.TriangleIndices.Add(7);
mg.TriangleIndices.Add(6);
}
// These texture coordinates basically stretch the
// TextBox brush to cover the full side of the label.
mg.TextureCoordinates.Add(new Point(0, 1));
mg.TextureCoordinates.Add(new Point(0, 0));
mg.TextureCoordinates.Add(new Point(1, 1));
mg.TextureCoordinates.Add(new Point(1, 0));
if (bDoubleSided)
{
mg.TextureCoordinates.Add(new Point(1, 1));
mg.TextureCoordinates.Add(new Point(1, 0));
mg.TextureCoordinates.Add(new Point(0, 1));
mg.TextureCoordinates.Add(new Point(0, 0));
}
// And that's all. Return the result.
ModelVisual3D mv3d = new ModelVisual3D();
mv3d.Content = new GeometryModel3D(mg, mat);;
return mv3d;
}
You need to make sure you've got:
using System.Windows.Documents;
in your code, which is where the Run class resides.
You might need to add a reference to PresentationFramework.dll as well.
Make sure to add, at the top of your file:
using System.Windows.Documents;
The Run class is System.Windows.Documents.Run - not part of System.Windows.

Windows Forms / C#: only one object instance out of many will paint

Here's the problem:
I've been working on a little game where monsters bounce off the walls (edges) of the main form, and it's going swimmingly, but it only paints one of each type of monster when it should be iterating through a list of each of them and calling their OnPaint and Move methods:
private void Pacmen_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = e.ClipRectangle;
g.Clear(backgroundColor);
foreach (Hydra h in hydraList) {
h.OnPaint(e);
h.Move(e);
} // end foreach
foreach (Ghost gh in ghostList) {
gh.OnPaint(e);
gh.Move(e);
} // end foreach
}
Here's the ghost's methods:
public void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
GraphicsPath path = new GraphicsPath();
SolidBrush fillBrush = new SolidBrush(color);
SolidBrush eyeBrush = new SolidBrush(Color.Black);
path.AddArc(pos, (float)180, (float)180);
path.AddLine((float)pos.Right, (float)(pos.Y + pos.Height / 2),
(float)pos.Right, (float)pos.Bottom);
path.AddLine((float)pos.Right, (float)pos.Bottom,
(float)(pos.X + pos.Width / 2), (float)(pos.Bottom - radius / 2));
path.AddLine((float)(pos.X + pos.Width / 2), (float)(pos.Bottom - radius / 2),
(float)pos.Left, (float)pos.Bottom);
path.AddLine((float)pos.Left, (float)pos.Bottom,
(float)pos.Left, (float)(pos.Y + pos.Height / 2));
g.FillPath(fillBrush, path);
g.FillEllipse(eyeBrush, new Rectangle(pos.X + pos.Width / 4, pos.Y + pos.Height / 4, radius / 4, radius / 5));
g.FillEllipse(eyeBrush, new Rectangle(pos.X + 3 * pos.Width / 4, pos.Y + pos.Height / 4, radius / 4, radius / 5));
} // end OnPaint
public void Move(PaintEventArgs e)
{
pos.Offset(xSpeed, ySpeed);
}
Any ideas why only one would show up? Thanks!
Are you sure you're giving the characters individual starting positions and speed? Maybe they are all painting, but on exactly the same spot?
You are calling the OnPaint for each hydra and ghost by using the same PaintEventArgs passed to Pacmen_Paint. Maybe the OnPaint methods are not using the correct Graphics object then.
Try replacing the body of your Ghost method with simple:
Console.WriteLine("Ghost at " + pos.X + ", " + pos.Y);
Then run the app and check the Output window in VS to see where they are drawn exactly.
Other notes (others may have commented already):
Use the using construct to dispose Brushes and other disposable graphics objects inside the Paint method, or cache them and make your Ghost and Hydra objects implement IDisposable to dispose them when they are not needed anymore.
You may get some speed improvements if you simply create a Bitmap field containg an already drawn ghost, and then simply draw it inside Paint. That way you only need to create your graphic objects once (inside using construct, again).

Categories