Rectangle and Ellipse Selection Colour

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

Slxe wrote at 2014-05-16 18:40:

Hello again, just figured I'd mention something I noticed while playing around:

It seems like both RectangleAnnotation and EllipseAnnotation aren't checking if they're selected and changing the fill colour if they are. Noticed the slight difference when reviewing the source if it helps (in each's render methods):

PolygonAnnotation:
 rc.DrawClippedPolygon(
    this.screenPoints,
    clipping,
    MinimumSegmentLength * MinimumSegmentLength,
    this.GetSelectableFillColor(this.Fill),
    this.GetSelectableColor(this.Color),
    this.StrokeThickness,
    this.LineStyle,
    this.LineJoin);
and in PathAnnotation:
rc.DrawClippedLine(
   this.screenPoints,
   clippingRectangle,
   MinimumSegmentLength * MinimumSegmentLength,
   this.GetSelectableColor(this.Color),
   this.StrokeThickness,
   dashArray,
   this.LineJoin,
   this.aliased,
   null,
   clippedPoints.AddRange);
vs

RectangleAnnotation:
rc.DrawClippedRectangle(this.screenRectangle, clipping, this.Fill, this.Stroke, this.StrokeThickness);
and in EllipseAnnotation:
rc.DrawClippedEllipse(clipping, this.screenRectangle, this.Fill, this.Stroke, this.StrokeThickness);
Not sure if this is intended, but figured I'd point it out.

objo wrote at 2014-05-16 19:53:

thanks for the bug report! this should be easy to fix :-)

objo wrote at 2014-05-17 06:24:

This should be corrected now. We should add some examples, I don´t think I have ever tried if this works!
I also aligned the DrawClipped* methods, now the clipping rectangle is the first parameter in all these methods.

Slxe wrote at 2014-05-17 15:42:

Nice! Thanks for the quick replies =) this really helps. I'm at home right now, and don't have VS installed (since I only really do C#/.Net at work right now, Java/Clojure/Python at home), or my code, but here's basically what I'm using it for in the drawing toolbar demo I'm almost done:
private void Annotation_OnMouseDown(object sender, OxyMouseDownEventArgs args) 
{
    if (((Annotation) sender).IsSelected())
        ((Annotation) sender).UnSelect();
    else
        ((Annotation) sender).Select();
}

private void uiSelectAnnotsButton_OnCheckedChanged(object sender, EventArgs args) 
{
    foreach (Annotation a in ChartModel.Annotations)
    {
        if (((ToolStripButton) sender).Checked)
            a.MouseDown += Annotation_OnMouseDown;
        else
            a.MouseDown -= Annotation_OnMouseDown;
    }

    foreach (Annotation a in ChartModel.Annotations)
        a.Unselect();
}

private void uiEditTextTextBox_OnKeyDown(object sender, EventArgs args)
{
    if (args.KeyCode != Keys.Enter)
        return;

    foreach (Annotation a in ChartModel.Annotations.Where(a => a.IsSelected()))
        ((TextualAnnotation) a).Text = ((ToolStripTextBox) sender).Text;

    ChartModel.InvalidatePlot(false);
}
lol keep in mind this is off the top of my head in Sublime Text, so there might be errors, but hopefully this gives you ideas! Also if you've got any tips, suggestions or corrections I'm all ears. Being wrong just means I can learn better ways of doing things =).

Edit; you could also make them update as the text is entered, looks kinda cool. I opted for the enter key over it in the demo though:
private void uiEditTextTextBox_OnTextChanged(object sender, EventArgs args) 
{
    foreach (Annotation a in ChartModel.Annotations.Where(a => a.IsSelected()))
        ((TextualAnnotation) a).Text = ((ToolStripTextBox) sender).Text;

    ChartModel.InvalidatePlot(false);
}
Also, no idea why the minus symbol is showing up weird in the actual post O_o not doing that in editing/preview.