private void invalidate(IRenderContext context, IRenderer renderer) { /*this should only ever fail once when a font has been changed * because a font MUST be allocated on the main rendering thread.*/ IFont font = context.AllocateFont(p_Font); Size = renderer.MeasureString(p_Text, font); //update text information p_Lines = p_Text.Split('\n'); p_Invalidate = false; }
private void invalidate(IRenderContext context, IRenderer renderer) { //font null? if (p_Font == null) { return; } //allocate the current font onto //the rendering context IFont font = null; try { font = context.AllocateFont(p_Font); } catch { return; } //keep reducing the text until it all fits in the text box int maxWidth = Width - (p_TextXOffset * 2); while (renderer.MeasureString(p_Text, font).Width >= maxWidth) { p_Text = p_Text.Substring(0, p_Text.Length - 1); } //set the height to the height of the font + padding p_CaratHeight = renderer.GetFontHeight(font); Height = p_CaratHeight + (p_Padding << 1); //calculate the render x position of the Carat int renderX = p_TextXOffset; int textLength = p_Text.Length; if (p_CaratPosition >= textLength) { p_CaratPosition = textLength - 1; } for (int c = 0; c < p_CaratPosition + 1; c++) { char character = p_Text[c]; int width = renderer.GetCharWidth(character, font); renderX += width; } p_CaratRenderX = renderX; p_Invalidate = false; }