// TODO: the position still seems a bit off wrt. padding void ButtonVector::RecalculateSize(bool repaintIfSizeDidntChange) { Size prevSize = desiredSize; CachedStyle *s = cachedStyle; desiredSize = GetBorderAndPaddingSize(s); Rect bbox; Brush *brStroke = BrushFromColorData(s->stroke, bbox); if (0.f == s->strokeWidth) { graphicsPath->GetBounds(&bbox); } else { Pen pen(brStroke, s->strokeWidth); // pen widith is multiplied by MiterLimit(), which is 10 by default // so set it explicitly to 1 for the size we expect pen.SetMiterLimit(1.f); pen.SetAlignment(PenAlignmentInset); graphicsPath->GetBounds(&bbox, NULL, &pen); } desiredSize.Width += bbox.Width; desiredSize.Height += bbox.Height; if (!prevSize.Equals(desiredSize)) RequestLayout(this); else if (repaintIfSizeDidntChange) RequestRepaint(this); }
void ProgressBar::SetRange(int nMin, int nMax) { m_nMin = nMin; m_nMax = nMax; CheckRange(); RequestRepaint(); }
void Control::Hide() { if (!IsVisible()) return; RequestRepaint(this); // request repaint before hiding, to trigger repaint bit::Set(stateBits, IsHiddenBit); }
void Control::Show() { if (IsVisible()) return; // perf: avoid unnecessary repaints bit::Clear(stateBits, IsHiddenBit); RequestRepaint(this); }
// Update desired size of the button. If the size changes, trigger layout // (which will in turn request repaints of affected areas) // To keep size of the button stable (to avoid re-layouts) we use font // line spacing to be the height of the button, even if text is empty. // Note: it might be that for some cases button with no text should collapse // in size but we don't have a need for that yet void Button::RecalculateSize(bool repaintIfSizeDidntChange) { Size prevSize = desiredSize; desiredSize = GetBorderAndPaddingSize(cachedStyle); Graphics *gfx = AllocGraphicsForMeasureText(); CachedStyle *s = cachedStyle; Font *font = GetCachedFont(s->fontName, s->fontSize, s->fontWeight); textDx = 0; float fontDy = font->GetHeight(gfx); RectF bbox; if (text) { bbox = MeasureText(gfx, font, text); textDx = (size_t)bbox.Width; // TODO: round up? // bbox shouldn't be bigger than fontDy. We apply magic adjustment because // bbox is bigger in n-th decimal point CrashIf(fontDy + .5f < bbox.Height); } desiredSize.Width += textDx; desiredSize.Height += (INT)fontDy; // TODO: round up? FreeGraphicsForMeasureText(gfx); if (!prevSize.Equals(desiredSize)) RequestLayout(this); else if (repaintIfSizeDidntChange) RequestRepaint(this); }
void ScrollBar::SetFilled(float perc) { CrashIf((perc < 0.f) || (perc > 1.f)); int prev = IntFromPerc(pos.Width, filledPerc); int curr = IntFromPerc(pos.Width, perc); filledPerc = perc; if (prev != curr) RequestRepaint(this); }
// This is just to test mouse move handling void PageControl::NotifyMouseMove(int x, int y) { #if 0 Rect r1 = RectForCircle(cursorX, cursorY, 10); Rect r2 = RectForCircle(x, y, 10); cursorX = x; cursorY = y; r1.Inflate(1,1); r2.Inflate(1,1); RequestRepaint(this, &r1, &r2); #endif }
// returns true if the style of control has changed bool Control::SetStyle(Style *style) { bool changed; CachedStyle *currStyle = cachedStyle; cachedStyle = CacheStyle(style, &changed); if (currStyle != cachedStyle) changed = true; if (changed) RequestRepaint(this); return changed; }
void Control::SetPosition(const Rect& p) { if (p.Equals(pos)) return; // perf optimization bool sizeChanged = (p.Width != pos.Width) || (p.Height != pos.Height); // when changing position we need to invalidate both // before and after position // TODO: not sure why I need this, but without it there // are drawing artifacts Rect p1(p); p1.Inflate(1,1); Rect p2(pos); p2.Inflate(1,1); RequestRepaint(this, &p1, &p2); pos = p; if (!sizeChanged) return; HwndWrapper *hwnd = GetRootHwndWnd(this); hwnd->evtMgr->NotifySizeChanged(this, p.Width, p.Height); }
// Update desired size of the button. If the size changes, trigger layout // (which will in turn request repaints of affected areas) // To keep size of the button stable (to avoid re-layouts) we use font // line spacing to be the height of the button, even if text is empty. // Note: it might be that for some cases button with no text should collapse // in size but we don't have a need for that yet void Button::RecalculateSize(bool repaintIfSizeDidntChange) { Size prevSize = desiredSize; desiredSize = GetBorderAndPaddingSize(cachedStyle); Graphics *gfx = AllocGraphicsForMeasureText(); CachedStyle *s = cachedStyle; Font *font = GetCachedFont(s->fontName, s->fontSize, s->fontWeight); textDx = 0; float fontDy = font->GetHeight(gfx); RectF bbox; if (text) { bbox = MeasureText(gfx, font, text); textDx = CeilI(bbox.Width); // I theorize that bbox shouldn't be bigger than fontDy. However, in practice // it is (e.g. for Lucida Grande and text "Page: 0 / 0", bbox.Dy is 19.00 // and fontDy is 18.11). I still want to know if the difference gets even bigger // than that float maxDiff = 1.f; if (bbox.Height > fontDy + maxDiff) { fontDy = bbox.Height; float diff = fontDy + maxDiff - bbox.Height; char *fontName = str::conv::ToUtf8(s->fontName); char *tmp = str::conv::ToUtf8(text); CrashLogFmt("fontDy=%.2f, bbox.Height=%.2f, diff=%.2f (should be > 0) font: %s, text='%s'\r\n", (float)fontDy, (float)bbox.Height, diff, fontName, tmp); CrashIf(diff < 0); } } desiredSize.Width += textDx; desiredSize.Height += CeilI(fontDy); FreeGraphicsForMeasureText(gfx); if (!prevSize.Equals(desiredSize)) RequestLayout(this); else if (repaintIfSizeDidntChange) RequestRepaint(this); }
void ProgressBar::SetMin(int nMin) { m_nMin = nMin; CheckRange(); RequestRepaint(); }
void ScrollBar::NotifyMouseLeave() { if (inactiveDy != onOverDy) RequestRepaint(this); }
void ProgressBar::StepPosition() { m_nPosition += m_nSetpSize; CheckRange(); RequestRepaint(); }
void ProgressBar::AdvancePosition(int nPos) { m_nPosition += nPos; CheckRange(); RequestRepaint(); }
void ProgressBar::SetPosition(int nPos) { m_nPosition = nPos; CheckRange(); RequestRepaint(); }
void ProgressBar::SetStepSize(int nSize) { m_nSetpSize = nSize; RequestRepaint(); }
void PageControl::SetPage(HtmlPage *newPage) { page = newPage; RequestRepaint(this); }
void ProgressBar::SetBarImage(CxImage* pImage) { m_pBarImage = pImage; RequestRepaint(); }
void ProgressBar::SetMax(int nMax) { m_nMax = nMax; CheckRange(); RequestRepaint(); }
void PageControl::SetPage(PageData *newPage) { page = newPage; RequestRepaint(this); }