Skip to content

Instantly share code, notes, and snippets.

@kg
Created May 2, 2011 23:29
Show Gist options
  • Save kg/952566 to your computer and use it in GitHub Desktop.
Save kg/952566 to your computer and use it in GitHub Desktop.
public abstract class TooltipContentBase {
public Font Font;
public Point Location;
public Size Size;
public abstract void Render (Graphics g);
public abstract Size Measure (Graphics g);
}
public class DeltaInfoTooltipContent : TooltipContentBase {
public readonly DeltaInfo Delta;
public DeltaInfo.RenderParams RenderParams;
public DeltaInfoTooltipContent (DeltaInfo delta, DeltaInfo.RenderParams renderParams) {
Delta = delta;
RenderParams = renderParams;
}
public override void Render (Graphics g) {
RenderParams.ContentRegion = new Rectangle(
0, 0, Size.Width, Size.Height
);
RenderParams.Font = Font;
Delta.Render(g, ref RenderParams);
}
public override Size Measure (Graphics g) {
var sf = RenderParams.StringFormat;
var width = (int)Math.Ceiling(g.MeasureString(Delta.ToString(true), Font, 99999, sf).Width);
var lineHeight = g.MeasureString("AaBbYyZz", Font, width, sf).Height;
return new Size(
width, (int)Math.Ceiling(lineHeight * (Delta.Traceback.Frames.Count + 1))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment