void HeaderCtrl::Column::Paint(bool& first, Draw& w, int x, int y, int cx, int cy, bool disabled, bool push, bool hl) { const HeaderCtrl::Style *style = header ? header->style : &HeaderCtrl::StyleDefault();; if(first) { if(cx >= -style->gridadjustment) { cx -= style->gridadjustment; if(cx < 0) cx = 0; first = false; } } else x -= style->gridadjustment; bool p = push && style->pressoffset; int q = CTRL_NORMAL; if(hl) q = CTRL_HOT; if(push) q = CTRL_PRESSED; if(disabled) q = CTRL_DISABLED; ChPaint(w, x, y, cx, cy, IsNull(paper) ? style->look[q] : paper.operator Value()); x += margin; cx -= 2 * margin; w.Clip(x + 2, y, cx - 4, cy); PaintLabel(w, x + 2, y + 1, cx - 4, cy - 4, disabled, p); w.End(); }
virtual void Paint(Draw& w) { w.DrawRect(GetSize(), White()); DoPainting(w); w.Offset(30, 50); DoPainting(w); w.End(); w.Offset(20, 100); w.Clip(5, 5, 40, 20); DoPainting(w); w.End(); w.End(); w.Clipoff(10, 150, 60, 20); DoPainting(w); w.End(); }
void StdDisplayClass::Paint0(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword s) const { LLOG("StdDisplay::Paint0: " << q << " ink:" << ink << " paper:" << paper); WString txt; Font font = StdFont(); int a = align; int x = r.left; int width = r.GetWidth(); if(IsType<AttrText>(q)) { const AttrText& t = ValueTo<AttrText>(q); txt = t.text; font = t.font; if(!IsNull(t.paper)) paper = t.paper; if(!IsNull(t.ink)) ink = t.ink; if(!IsNull(t.normalink) && !(s & (CURSOR|SELECT|READONLY))) ink = t.normalink; if(!IsNull(t.normalpaper) && !(s & (CURSOR|SELECT|READONLY))) paper = t.normalpaper; if(!IsNull(t.align)) a = t.align; if(!IsNull(t.img)) { Size isz = t.img.GetSize(); w.DrawImage(x, r.top + max((r.Height() - isz.cy) / 2, 0), t.img); x += isz.cx + t.imgspc; } } else txt = IsString(q) ? q : StdConvert().Format(q); Size tsz = GetTLTextSize(txt, font); if(a == ALIGN_RIGHT) x = r.right - tsz.cx; if(a == ALIGN_CENTER) x += (width - tsz.cx) / 2; int tcy = GetTLTextHeight(txt, font); int tt = r.top + max((r.Height() - tcy) / 2, 0); if(tsz.cx > width) { Size isz = DrawImg::threedots().GetSize(); int wd = width - isz.cx; w.Clip(r.left, r.top, wd, r.GetHeight()); DrawTLText(w, x, tt, width, txt, font, ink); w.End(); w.DrawImage(r.left + wd, tt + font.Info().GetAscent() - isz.cy, DrawImg::threedots(), ink); } else DrawTLText(w, x, tt, width, txt, font, ink); }
void Ctrl::DrawCtrlWithParent(Draw& w, int x, int y) { GuiLock __; if(parent) { Rect r = GetRect(); Ctrl *top = parent->GetTopRect(r, inframe); w.Clip(x, y, r.Width(), r.Height()); w.Offset(x - r.left, y - r.top); SystemDraw *ws = dynamic_cast<SystemDraw *>(&w); if(ws) top->UpdateArea(*ws, r); w.End(); w.End(); } else DrawCtrl(w, x, y); }
void DockCont::Handle::Paint(Draw& w) { if (IsShown() && dc) { const DockableCtrl::Style &s = dc->GetStyle(); Rect r = GetSize(); const Rect &m = s.handle_margins; Point p; if (s.handle_vert) p = Point(r.left-1 + m.left, r.bottom - m.bottom); else p = Point(r.left + m.left, r.top + m.top); ChPaint(w, r, s.handle[focus]); Image img = dc->GetIcon(); if (!img.IsEmpty()) { if (s.handle_vert) { int isz = r.GetWidth(); p.y -= isz; isz -= (m.left + m.right); ChPaint(w, max(p.x+m.left, r.left), p.y, isz, isz, img); p.y -= 2; } else { int isz = r.GetHeight(); isz -= (m.top + m.bottom); ChPaint(w, p.x, max(p.y, r.top), isz, isz, img); p.x += isz + 2; } } if (!s.title_font.IsNull()) { Ctrl *c = GetLastChild(); while (c && !c->IsShown() && c->GetParent()) c = c->GetNext(); if (s.handle_vert) r.top = c ? c->GetRect().bottom + m.top : m.top; else r.right = c ? c->GetRect().left + m.right : m.right; w.Clip(r); WString text = IsNull(dc->GetGroup()) ? dc->GetTitle() : (WString)Format("%s (%s)", dc->GetTitle(), dc->GetGroup()); w.DrawText(p.x, p.y, s.handle_vert ? 900 : 0, text, s.title_font, s.title_ink[focus]); w.End(); } } }
void ScrollBar::Paint(Draw& w) { w.DrawRect(GetSize(), SColorPaper()); int cc; Size sz = style->through ? GetSize() : Slider(cc).GetSize(); light = GetMousePart(); int p = push; if(!HasCapture()) p = -1; const Value *hl[] = { style->hlower, style->hupper, style->hthumb }; const Value *vl[] = { style->vupper, style->vlower, style->vthumb }; const Value **l = IsHorz() ? hl : vl; if(prev.IsShowEnabled()) { for(int i = 0; i < 3; i++) { Rect pr = GetPartRect(i); if(i != 2) { w.Clip(pr); pr = style->through ? GetSize() : Slider(); } if(i != 2 || thumbsize >= style->thumbmin) ChPaint(w, pr, l[i][p == i ? CTRL_PRESSED : light == i ? CTRL_HOT : CTRL_NORMAL]); if(i != 2) w.End(); } } else if(style->through) ChPaint(w, sz, l[0][CTRL_DISABLED]); else if(IsHorz()) { ChPaint(w, cc, 0, sz.cx / 2, sz.cy, l[0][CTRL_DISABLED]); ChPaint(w, cc + sz.cx / 2, 0, sz.cx - sz.cx / 2, sz.cy, l[1][CTRL_DISABLED]); } else { ChPaint(w, 0, cc, sz.cx, sz.cy / 2, l[0][CTRL_DISABLED]); ChPaint(w, 0, cc + sz.cy / 2, sz.cx, sz.cy - sz.cy / 2, l[1][CTRL_DISABLED]); // w.DrawRect(0, cc, sz.cx, sz.cy / 2, Red()); _DBG_ // w.DrawRect(0, cc + sz.cy / 2, sz.cx, sz.cy - sz.cy / 2, Green()); _DBG_ } }
void MultiButton::Paint(Draw& w) { Size sz = GetSize(); int border, lx, rx; bool frm = Metrics(border, lx, rx); int mst = ChState(MAIN); if(frm && !nobg) ChPaint(w, sz, style->edge[style->activeedge ? mst : 0]); bool left = false; bool right = false; for(int i = 0; i < button.GetCount(); i++) { SubButton& b = button[i]; int st = ChState(i); int x = 0, cx = 0; GetPos(b, lx, rx, x, cx); bool dopaint = true; Value v = b.left ? left ? style->lmiddle[st] : style->left[st] : right ? style->rmiddle[st] : style->right[st]; if(!nobg) { if(ComplexFrame()) ChPaint(w, x, border, cx, sz.cy - 2 * border, style->simple[st]); else if(frm) { if(IsTrivial() && style->usetrivial) dopaint = false; ChPaint(w, x, border, cx, sz.cy - 2 * border, dopaint ? v : style->trivial[st]); } else { w.Clip(x, 0, cx, sz.cy); ChPaint(w, sz, style->look[Frame() ? mst : st]); if(IsNull(v) || !Frame()) { if((!IsTrivial() || style->trivialsep) && IsEnabled()) { if(b.left) { if(left) ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); } else { ChPaint(w, x, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); if(right) ChPaint(w, x + cx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); } } } else ChPaint(w, x, 0, cx, sz.cy, v); w.End(); } } if(dopaint) { Size tsz = GetTextSize(b.label, StdFont()); Image m = tsz.cx > 0 ? b.img : (Image)Nvl(b.img, CtrlsImg::DA()); Size isz = m.GetSize(); Point p = (st == CTRL_PRESSED) * style->pressoffset; p.x += x + (cx - isz.cx - tsz.cx - (tsz.cx > 0 && isz.cx > 0 ? LB_IMAGE : 0)) / 2; p.y += (sz.cy - isz.cy) / 2; if(b.left) { if(!left) p.x += style->loff; } else if(!right) p.x += style->roff; if(b.monoimg || IsNull(b.img)) w.DrawImage(p.x, p.y, m, frm ? style->fmonocolor[st] : style->monocolor[st]); else w.DrawImage(p.x, p.y, m); if(tsz.cx > 0) { if(isz.cx > 0) p.x += isz.cx + LB_IMAGE; w.DrawText(p.x, (sz.cy - tsz.cy) / 2, b.label); } } (b.left ? left : right) = true; } Rect r, cr; cr = GetSize(); cr.left = lx; cr.right = rx; Color text = SColorLabel(); Color paper = Null; if(!nobg) { if(ComplexFrame()) { r = cr; paper = HasFocus() ? SColorHighlight() : SColorPaper(); if(HasFocus()) text = SColorHighlightText(); w.DrawRect(r, paper); } else if(frm) { Rect m = GetMargin(); r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom); Color paper; if(mst == CTRL_HOT && !IsTrivial()) paper = Blend(SColorHighlight, SColorPaper, 235); else if(mst == CTRL_PRESSED && !IsTrivial()) paper = Blend(SColorHighlight, SColorFace, 235); else if(HasFocus()) { paper = SColorHighlight(); text = SColorHighlightText(); } else paper = SColorPaper(); w.DrawRect(r, paper); cr = r; } else { w.Clip(lx, 0, rx - lx, sz.cy); ChPaint(w, sz, style->look[mst]); Rect m = style->margin; r = Rect(max(lx, m.left), m.top, min(rx, sz.cx - m.right), sz.cy - m.bottom); if(!IsTrivial() || style->trivialsep) { if(left) { r.left++; if(IsEnabled()) ChPaint(w, lx, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep1); } if(right) { if(IsEnabled()) ChPaint(w, rx - 1, style->sepm, 1, sz.cy - 2 * style->sepm, style->sep2); r.right--; } } w.End(); cr = r; } } cr.left++; Rect clr = cr; if(!IsNull(valuecy)) { cr.top += (cr.GetHeight() - valuecy + 1) / 2; cr.bottom = cr.top + valuecy; } Value v = convert->Format(value); bool f = HasFocus() && !push && frm; if(cr.left < cr.right && display) { w.Clip(clr); display->Paint(w, cr, v, IsShowEnabled() ? text : SColorDisabled, paper, f ? Display::CURSOR : Display::FOCUS|Display::CURSOR); w.End(); } if(!frm && HasFocus()) DrawFocus(w, r); }
bool TableCell::Paint(int zoom, Draw& w, int x, int y, int cx, int cy, int pcy, Color color, PaintInfo& pi) const { if(pcy > cy) pcy = cy; w.DrawRect(x, y, cx, cy, style.paper); int lw = DocZoom(zoom, style.leftwidth); int tw = DocZoom(zoom, style.topwidth); int rw = DocZoomLn(zoom, style.rightwidth); int bw = DocZoomLn(zoom, style.bottomwidth); int ls = DocZoom(zoom, style.leftspace); int ts = DocZoom(zoom, style.topspace); int rs = DocZoom(zoom, style.rightspace); int bs = DocZoom(zoom, style.bottomspace); Rect r(x + lw + ls, y + tw + ts, x + cx - rw - rs, y + cy - bw - bs); if(paintrect) { w.Clip(r); paintrect.Paint(w, r, color, style.paper); w.End(); } w.DrawRect(x, y, lw, cy, color); w.DrawRect(x, y, cx, tw, color); w.DrawRect(x + cx - rw, y, rw, cy, color); w.DrawRect(x, y + cy - bw, cx, bw, color); x = r.left; cx = r.Width(); switch(style.align) { case ALIGN_TOP: y = y + tw + ts; break; case ALIGN_CENTER: y = y + (cy - pcy) / 2 + tw + ts; break; case ALIGN_BOTTOM: y = y + cy - pcy - bw - bs; break; } int ymax = y + cy - bw - bs; int ypos = 0; for(int i = 0; i < par.GetCount(); i++) { const Paragraph& p = par[i]; int bef = DocZoom(zoom, p.GetBefore()); int aft = DocZoom(zoom, p.GetAfter()); if(ypos + bef - pi.yl + y > ymax) { pi.yl = ypos; return true; } ypos += bef; Paragraph::PaintInfo ppi; if(ypos >= pi.yl) { int py = y + ypos - pi.yl; if(p.Paint(zoom, w, x, py, cx, ymax, ppi, style.paper)) { pi.yl = ypos + ppi.yl; return true; } ypos += ppi.ypos - py; } else { int h = ypos < pi.yl ? p.GetHeight(zoom, cx) : 0; if(ypos + h > pi.yl) { ppi.yl = pi.yl - ypos; if(p.Paint(zoom, w, x, y, cx, ymax, ppi, style.paper)) { pi.yl = ypos + ppi.yl; return true; } } ypos += h; } ypos += aft; if(ypos - pi.yl + y > ymax) { pi.yl = ypos; return true; } } pi.yl = ypos; return false; }
void RulerCtrl::Paint(Draw& draw) { Size client = GetSize(); int csize = is_vert ? client.cy : client.cx; int cheight = is_vert ? client.cx : client.cy; Rect clip = GetSize(); int cy = font.Info().GetHeight(); double pos1 = FromClient(0); double pos2 = FromClient(csize); if(pos1 > pos2) Swap(pos1, pos2); double lrange = min_range, rrange = max_range; if(!IsNull(min_range) && pos1 < min_range) pos1 = min_range; if(!IsNull(max_range) && pos2 > max_range) pos2 = max_range; int cli1 = 0, cli2 = csize; if(scale < 0) Swap(lrange, rrange); if(!IsNull(lrange)) cli1 = max<int>(cli1, ToClient(lrange)); if(!IsNull(rrange)) cli2 = min<int>(cli2, ToClient(rrange)); Rect nclip; if(is_vert) { draw.DrawRect(0, 0, client.cx, cli1, outer_color); if(!IsNull(lrange)) draw.DrawRect(0, cli1++, client.cx, 1, SBlack); draw.DrawRect(0, cli2, client.cx, client.cy - cli2, outer_color); if(!IsNull(rrange)) draw.DrawRect(0, --cli2, client.cx, 1, SBlack); draw.DrawRect(0, cli1, 1, cli2 - cli1, SGray); // draw.DrawRect(0, cli1, 1, cli2 - cli1, SBlack); draw.DrawRect(client.cx - 1, cli1, 1, cli2 - cli1, SBlack); nclip = RectC(1, cli1, client.cx - 2, cli2 - cli1); } else { draw.DrawRect(0, 0, cli1, client.cy, outer_color); if(!IsNull(lrange)) draw.DrawRect(cli1++, 0, 1, client.cy, SBlack); draw.DrawRect(cli2, 0, client.cx - cli2, client.cy, outer_color); if(!IsNull(rrange)) draw.DrawRect(--cli2, 0, 1, client.cy, SBlack); draw.DrawRect(cli1, 0, cli2 - cli1, 1, SGray); draw.DrawRect(cli1, client.cy - 1, cli2 - cli1, 1, SBlack); nclip = RectC(cli1, 1, cli2 - cli1, client.cy - 2); } draw.DrawRect(nclip, background); draw.Clip(nclip); enum { SMALL_LIMIT = 100, // TEXT_LIMIT = 50, TGAP = 3, HGAP = 2, VGAP = 0, HXGAP = 3, VXGAP = 2, SMALL_SIZE = 5, }; double rep_count = 1; double rep_delta = 0; if(!IsNull(small_repeat)) { rep_delta = small_repeat * floor(pos1 / small_repeat); rep_count = ceil(pos2 / small_repeat) - floor(pos1 / small_repeat); } if(!small_step.IsEmpty() && rep_count > 0 && rep_count * small_step.GetCount() <= cli2 - cli1) { int ix = BinFindIndex(small_step, pos1 - rep_delta); int ppos = (is_right ? 0 : cheight - SMALL_SIZE); for(int c = fround(rep_count); --c >= 0; ix = 0, rep_delta += small_repeat) { int lim = small_step.GetCount(); if(small_step.Top() > pos2 - rep_delta) lim = BinFindIndex(small_step, pos2 - rep_delta); for(; ix < lim; ix++) { int cli = ToClient(small_step[ix] + rep_delta); if(is_vert) draw.DrawRect(ppos, cli, SMALL_SIZE, 1, Gray()); else draw.DrawRect(cli, ppos, 1, SMALL_SIZE, Gray()); } } } rep_count = 1; double rep_index = 0; if(!IsNull(text_repeat)) { rep_index = floor(pos1 / text_repeat); rep_count = ceil(pos2 / text_repeat) - floor(pos1 / text_repeat) + 1; } if(!text_step.IsEmpty() && (!text_value.IsEmpty() || text_convert) && rep_count > 0 /*&& rep_count * text_step.GetCount() <= TEXT_LIMIT*/) { int ix = BinFindIndex(text_step, pos1 - rep_index * text_repeat); int ppos = (is_right ? SMALL_SIZE : cheight - cy - SMALL_SIZE); int rpos = (is_right ? 0 : cheight - SMALL_SIZE - 1); for(int c = fround(rep_count); --c >= 0; ix = 0, rep_index++) { int lim = text_step.GetCount(); double dp2 = pos2 - rep_index * text_repeat; if(text_step.Top() > dp2) { lim = BinFindIndex(text_step, dp2); if(lim + 1 < text_step.GetCount() && text_step[lim + 1] - dp2 < dp2 - text_step[lim]) lim++; } for(; ix < lim; ix++) { double value = text_step[ix] + rep_index * text_repeat; int cli = ToClient(value); String text; if(ix < text_value.GetCount()) text = text_value[ix]; else if(text_convert) text = StdFormat(text_convert -> Format(value)); else text = StdFormat(value); Size tsize = GetTextSize(text, font); int half = tsize.cx >> 1; if(is_vert) { draw.DrawRect(0, cli, ppos, 1, Black()); draw.DrawRect(rpos, cli, SMALL_SIZE + 1, 1, Black()); // draw.DrawRect(ppos - VGAP, cli - half - HGAP, tsize.cy + 2 * VGAP, tsize.cx + 2 * HGAP, background); draw.DrawText(ppos, cli + half, 900, text, font, Gray()); } else { draw.DrawRect(cli, 0, 1, ppos, Black()); draw.DrawRect(cli, rpos, 1, SMALL_SIZE + 1, Black()); // draw.DrawRect(cli - half - HGAP, ppos - VGAP, tsize.cx + 2 * HGAP, tsize.cy + 2 * VGAP, background); draw.DrawText(cli - half, ppos, text, font, Gray()); } } } }
void ProgressIndicator::Paint(Draw& w) { Size sz = GetSize(); Size msz = GetMsz(); int p0 = 0; int p = pxp; if(total <= 0) { int l = max(msz.cx, msz.cy) & ~7; p0 = pxp - l / 4; p = min(p - p0, max(msz.cx, msz.cy) - p0); if(style->bound && p0 < 0) { p += p0; p0 = 0; } } if(style->classic || percent || !IsNull(color)) { ChPaintEdge(w, sz, EditFieldEdge()); Rect mg = ChMargins(EditFieldEdge()); sz -= Size(mg.left + mg.right, mg.top + mg.bottom); Rect r1, r2, r3; r1 = r2 = r3 = RectC(mg.left, mg.top, sz.cx, sz.cy); w.Clip(r1); if(sz.cx > sz.cy) { r1.right = r2.left = min(p, sz.cx) + mg.left + p0; r3.right = mg.left + p0; r3.bottom = r1.bottom; } else { r2.bottom = r1.top = sz.cy - min(p, sz.cy) + mg.left + p0; r3.bottom = mg.top + p0; r3.right = r1.right; } w.DrawRect(r1, Nvl(color, SColorHighlight())); w.DrawRect(r2, SColorPaper); w.DrawRect(r3, SColorPaper); if(percent) { String pt = Format("%d %%", 100 * actual / max(total, 1)); Size psz = GetTextSize(pt, StdFont()); int px = (sz.cx - psz.cx) / 2 + 2; int py = (sz.cy - psz.cy) / 2 + 2; w.Clip(r1); w.DrawText(px, py, pt, StdFont(), SColorLight); w.End(); w.Clip(r2); w.DrawText(px, py, pt, StdFont(), SColorText); w.End(); } w.End(); } else { if(sz.cy > sz.cx) { ChPaint(w, sz, style->vlook); Rect r = ChMargins(style->vlook); w.Clip(r.left, r.top, sz.cx - r.left - r.right, sz.cy - r.top - r.bottom); ChPaint(w, r.left, sz.cy - r.bottom - p - p0, sz.cx - r.left - r.right, p, style->vchunk); } else { ChPaint(w, sz, style->hlook); Rect r = ChMargins(style->hlook); w.Clip(r.left, r.top, sz.cx - r.left - r.right, sz.cy - r.top - r.bottom); ChPaint(w, r.left + p0, r.top, p, sz.cy - r.top - r.bottom, style->hchunk); } w.End(); } }
void StreamCtrl::Paint(Draw &w) { Size sz = GetSize(); Color fill = Color(245, 245, 255); int width = sz.cx - info_width; int height = sz.cy - progress_height; /* black border */ w.DrawRect(0, 0, sz.cx, 1, Black); w.DrawRect(0, sz.cy - 1, sz.cx, 1, Black); w.DrawRect(0, 0, 1, sz.cy, Black); w.DrawRect(sz.cx - 1, 0, 1, sz.cy, Black); /* progress separator */ w.DrawRect(1, progress_height, width - 1, 1, Gray); /* info separator */ w.DrawRect(width, 1, 1, sz.cy - 2, Gray); int t = max(1, fceil((pos * width) / 100.0f)); //if(t < 1) t = 1; //if(t > width) t = width; if(shaded) { for(int i = 1; i < t; i++) w.DrawRect(i, 1, 1, progress_height - 1, Blend(src, dst, 256 * i / (width - 1))); } else { w.DrawRect(Rect(1, 1, t, progress_height), dst); } w.DrawRect(Rect(t, 1, width, progress_height), fill); String s = Format("%s : %d %%", postext, (int) pos); Size psz = GetTextSize(s, StdFont()); w.DrawText((width - psz.cx) / 2, 1 + (progress_height - psz.cy) / 2, s); /* Title */ //WString text = name; Font fnt = Arial(18); Size nsz = GetTextSize(name, fnt); w.DrawRect(1, progress_height + 1, width - 1, height - 2, fill); w.Clip(5, progress_height, width - 10, height); w.DrawText(noname ? (width - nsz.cx) / 2 : 5, progress_height + (height - nsz.cy) / 2 + 1, name, fnt); w.End(); /* Time */ w.DrawRect(width + 1, 1, info_width - 2, sz.cy - 2, fill); String ts; if(time_direction > 0) { int tms = time_total - time; int min = tms / 1000 / 60; int sec = tms / 1000 % 60; if(min == 0 && sec == 0) ts = "00:00"; else ts = ::Format("-%02d:%02d", min, sec); } else { int tms = time; ts = ::Format("%02d:%02d", tms / 1000 / 60, tms / 1000 % 60); } Size tsz = GetTextSize(ts, fnt); w.DrawText(width + (info_width - tsz.cx) / 2, sz.cy - (sz.cy - progress_height + tsz.cy) / 2, ts, fnt); /* Bitrate */ fnt = Arial(11); String inf = bitrate + " / stereo"; Size isz = GetTextSize(inf, fnt); w.DrawText(width + (info_width - isz.cx) / 2, 3, inf, fnt); //w.DrawText(width + 5, 3, bitrate, fnt); //w.DrawText(width + 5 + bsz.cx + 5, 3, "stereo", fnt); }
void GridDisplay::Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style, Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe) { real_size.cx = 0; real_size.cy = 0; if(cx == 0 || cy == 0) return; Color mg = bg; int al = style & GD::ALIGN ? style & GD::ALIGN : align; if(cx > lm + rm && cy > tm + bm) { int nx = x + lm; int ny = y + tm; int ncx = cx - lm - rm; int ncy = cy - tm - bm; if(IsNull(bgImg)) { if(lm > 0) w.DrawRect(x, y, lm, cy, mg); if(rm > 0) w.DrawRect(x + cx - rm, y, rm, cy, mg); if(tm > 0) w.DrawRect(x, y, cx, tm, mg); if(bm > 0) w.DrawRect(x, y + cy - bm, cx, bm, mg); w.DrawRect(nx, ny, ncx, ncy, bg); } else w.DrawImage(x, y, cx, cy, bgImg); w.Clip(nx, ny, ncx, ncy); if(!leftImg.IsEmpty()) { Size isz = leftImg.GetSize(); w.DrawImage(nx, ny + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(leftImg) : leftImg); nx += isz.cx + 3; ncx -= isz.cx + 3; } if(!rightImg.IsEmpty()) { Size isz = rightImg.GetSize(); w.DrawImage(nx + ncx - isz.cx, y + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(rightImg) : rightImg); } if(!centerImg.IsEmpty()) { Size isz = centerImg.GetSize(); w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(centerImg) : centerImg); } if(!(style & GD::NOTEXT)) { DrawText(w, nx, nx, ny, ncx, ncy, al, GetStdConvertedValue(val), fnt, fg, bg, found, fs, fe, style & GD::WRAP); } w.End(); } else w.DrawRect(x, y, cx, cy, bg); }
void GridDisplay::DrawText(Draw &w, int mx, int x, int y, int cx, int cy, int align, const wchar *s, const Font &font, const Color &fg, const Color &bg, bool found, int fs, int fe, bool wrap) { if(*s == 0) return; int tcy = font.Info().GetHeight(); const wchar *p = s; const wchar *t = s; int lines = 0; // int enters = 0; int ty = y; Size tsz; if((align & GD::VCENTER) || (align & GD::BOTTOM)) { lines = GetLinesCount(cx, s, font, wrap); if(align & GD::VCENTER) ty = max(ty, y + (cy - tcy * lines) / 2); else ty = y + cy - tcy * lines; } //w.DrawText(x, y, Format("lines: %d, cx:%d, cy%d", lines, cx, cy)); Size isz = GridImg::Dots2().GetSize(); int gcx = cx - (wrap ? 0 : isz.cx); real_size.cy = lines > 1 ? lines * tcy : 0; while(true) { bool nextline = *p == '\n'; bool caret = *p == '\r'; bool endtext = *p == '\0'; const wchar * pp = p; bool textbreak = false; if(nextline || endtext) { /*int kk = p - t; if(p - t <= 1) { //break; kk = 0; }*/ int tx = x; tsz = GetTextSize(t, font, int(p - t)); if(tsz.cx > gcx) { int size = 0; const wchar *e = t; while(e < p) { int tcx = GetTextSize(e, font, 1).cx; size += tcx; if(size > gcx) break; e++; } p = e; if(wrap) { textbreak = true; if(p == t) p = t + 1; } } if(align & GD::RIGHT) tx = x + cx - tsz.cx; else if(align & GD::HCENTER) tx = x + (cx - tsz.cx) / 2; Color tfg = fg; if(found) { int chs = int(t - s); int che = int(p - s - 1); if(fs <= che && fe >= chs) { int scx = GetTextSize(t, font, max(chs, fs) - chs).cx; int ecx = GetTextSize(t, font, min(che, fe) - chs + 1).cx; Color nbg(255 - fg.GetR(), 255 - fg.GetG(), 255 - fg.GetB()); w.DrawRect(max(mx, tx) + scx, ty, ecx - scx, tcy, Blend(nbg, bg, 100)); } } bool dots = !wrap && tsz.cx > gcx; if(dots) { real_size.cx = max(real_size.cx, tsz.cx); w.Clip(x, y, cx, cy); w.DrawImage(x + cx - isz.cx, ty + font.Info().GetAscent() - isz.cy, GridImg::Dots2, tfg); w.End(); if(p > t) { w.Clip(x, y, cx - isz.cx , cy); w.DrawText(max(mx, tx), ty, t, font, tfg, int(p - t)); w.End(); } } else w.DrawText(max(mx, tx), ty, t, font, tfg, int(p - t)); ty += tcy; t = textbreak ? p : (p = pp + 1); } if(caret) *(char *) p = ' '; if(!textbreak) { if(endtext) break; else p++; } } }
void GridDisplay::PaintFixed(Draw &w, bool firstx, bool firsty, int x, int y, int cx, int cy, const Value &val, dword style, Font &fnt, bool indicator, bool moved, int sortmode, int sortcol, int sortcnt, bool horizontal) { real_size.cx = 0; real_size.cy = 0; bool chameleon = style & GD::CHAMELEON; bool highlight = style & GD::HIGHLIGHT; bool readonly = style & GD::READONLY; if(chameleon) { int ncx = cx; int nx = x; int ht = HeaderCtrl::StyleDefault().gridadjustment; if(firstx) { if(ncx >= -ht) { ncx -= ht; if(ncx < 0) ncx = 0; } } else nx -= ht; int q = CTRL_NORMAL; if(highlight) q = CTRL_HOT; if(readonly) q = CTRL_DISABLED; ChPaint(w, nx, y, ncx, cy, HeaderCtrl::StyleDefault().look[q]); } else { if(theme < 0) w.DrawRect(x, y, cx, cy, highlight ? Blend(SColorFace(), White, 128) : SColorFace()); else { int sx = cx > 1 ? cx : 1; int sy = cy - 1; if(sx > 0 && sy > 0) w.DrawImage(x, y, sx, sy, highlight ? hdrhigh : vhdr[theme]()); } //Color dark(76, 83, 92); Color dark(155, 154, 153); //Color dark(155, 154, 153); Color bright(White); if(!firstx) w.DrawRect(x, y, 1, cy, bright); if(!firsty) w.DrawRect(x, y, cx, 1, bright); if(firstx) w.DrawRect(x, y, 1, cy, dark); if(firsty) w.DrawRect(x, y, cx, 1, dark); w.DrawRect(x + cx - 1, y, 1, cy, dark); w.DrawRect(x, y + cy - 1, cx, 1, dark); } int tx = x + lm; if(firsty) { if(!leftImg.IsEmpty()) { Size isz = leftImg.GetSize(); w.DrawImage(tx, y + (cy - isz.cy) / 2, leftImg); tx += isz.cx + 3; } if(!rightImg.IsEmpty()) { Size isz = rightImg.GetSize(); w.DrawImage(x + cx - isz.cx - 3, y + (cy - isz.cy) / 2, rightImg); } if(!centerImg.IsEmpty()) { Size isz = centerImg.GetSize(); w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, centerImg); } } if(moved) DrawBorder(w, x, y, cx, cy, BlackBorder); Color col = style & GD::READONLY ? Gray : Black; if(sortmode > 0) { Size isz = GridImg::SortAsc().GetSize(); int yf = y + (cy - isz.cy) / 2; int xf = tx + 2; tx = xf + isz.cx + 1; if(sortcol > 0 && sortcnt > 1) { String tcol = AsString(sortcol); Size tsz = GetTextSize(tcol, fnt); w.DrawText(tx, y + (cy - tsz.cy) / 2, tcol, fnt); tx += tsz.cx; } bool asc = sortmode == 1; if(reverse_sort_icon) asc = !asc; w.DrawImage(xf, yf, asc ? GridImg::SortAsc() : GridImg::SortDsc(), col); tx += 3; } if(indicator) { w.Clip(x, y, cx, cy); Image img; if((style & GD::CURSOR) && (style & GD::SELECT)) { img = GridImg::FocSel(); } else if(style & GD::CURSOR) { img = GridImg::Focused(); } else if(style & GD::SELECT) { img = GridImg::Selected(); } if(!img.IsEmpty()) { Size isz = img.GetSize(); int xp = IsNull(val) ? x + (cx - isz.cx) / 2 : tx; w.DrawImage(xp, y + (cy - isz.cy) / 2, img, col); if(!IsNull(val)) tx += isz.cx + 3; } w.End(); } if(cx > lm + rm && cy > tm + bm) { int nx = x + lm; int ny = y + tm; int ncx = cx - lm - rm; int ncy = cy - tm - bm; w.Clip(nx, ny, ncx, ncy); int al = style & GD::ALIGN ? style & GD::ALIGN : align; Color fg = style & GD::READONLY ? SColorDisabled() : SColorText(); DrawText(w, tx, nx, ny, ncx, ncy, al, GetStdConvertedValue(val), fnt, fg, SColorPaper, 0, 0, 0, style & GD::WRAP); w.End(); } }