void BorderFrame::FramePaint(Draw& draw, const Rect& r) { Size sz = r.GetSize(); int n = (int)(intptr_t)*border; if(sz.cx >= 2 * n && sz.cy >= 2 * n) DrawBorder(draw, r.left, r.top, r.Width(), r.Height(), border); }
void SceneEditorScreenMain::CreateNode(ResourceEditor::eNodeType nodeType) { Rect rect = GetRect(); if(dialogBack->GetSize() != rect.GetSize()) { ReleaseResizedControl(dialogBack); ReleaseResizedControl(nodeDialog); dialogBack = ControlsFactory::CreatePanelControl(rect); ControlsFactory::CustomizeDialogFreeSpace(dialogBack); Rect r; r.dx = rect.dx / 2; r.dy = rect.dy / 2; r.x = rect.x + r.dx / 2; r.y = rect.y + r.dy / 2; nodeDialog = new CreateNodesDialog(r); nodeDialog->SetDelegate(this); } nodeDialog->CreateNode(nodeType); AddControl(dialogBack); AddControl(nodeDialog); }
void Painter::DrawEllipseOp(const Rect& r, Color color, int pen, Color pencolor) { Sizef sz = r.GetSize(); Ellipse(r.left + sz.cx / 2, r.top + sz.cy / 2, sz.cx / 2, sz.cy / 2); Fill(color); Stroke(max(pen, 0), pencolor); }
void BorderFrame::FrameLayout(Rect& r) { Size sz = r.GetSize(); int n = (int)(intptr_t)*border; if(sz.cx >= 2 * n && sz.cy >= 2 * n) r.Deflate(n); }
void SplitterFrame::FrameLayout(Rect& r) { Rect rr = r; parentsize = r.GetSize(); int sz = BoundSize(); switch(type) { case LEFT: r.left += sz; rr.right = r.left; break; case RIGHT: r.right -= sz; rr.left = r.right; break; case TOP: r.top += sz; rr.bottom = r.top; break; case BOTTOM: r.bottom -= sz; rr.top = r.bottom; break; } SetFrameRect(rr); }
NAMESPACE_UPP void SystemDraw::PutRect(const Rect& r, Color color) { LLOG("Ctrl::PutRect " << r << ", color " << color); Ctrl::stat_putrect++; Point p = r.TopLeft(); if(color == InvertColor()) { Ctrl::Put8(Ctrl::INVERTRECT); Ctrl::Put(r); } else { Size sz = r.GetSize(); Point dp = p - pos; if(abs(dp.x) < 256 && abs(dp.y) < 256 && sz.cx < 256 && sz.cy < 256 && 0) { Ctrl::Put8(dp.x < 0 ? dp.y < 0 ? Ctrl::RECTNN : Ctrl::RECTNP : dp.y < 0 ? Ctrl::RECTPN : Ctrl::RECTPP); Ctrl::Put8(abs(dp.x)); Ctrl::Put8(abs(dp.y)); Ctrl::Put8(sz.cx); Ctrl::Put8(sz.cy); } else { Ctrl::Put8(Ctrl::RECT); Ctrl::Put(r); } Ctrl::Put8(color.GetR()); Ctrl::Put8(color.GetG()); Ctrl::Put8(color.GetB()); } pos = p; }
void HeaderCtrl::LeftDrag(Point p, dword keyflags) { if(li < 0 || !moving) return; int n = 0; for(int i = 0; i < col.GetCount(); i++) if(col[i].visible) n++; if(n < 2) return; push = false; ti = li; pushi = -1; Refresh(); Rect r = GetTabRect(li).OffsetedHorz(-sb); Size sz = r.GetSize(); ImageDraw iw(sz.cx, sz.cy); bool first = true; col[li].Paint(first, iw, 0, 0, sz.cx, sz.cy, false, false, false); DrawFrame(iw, sz, SColorText()); dragtab = iw; dragx = p.x; dragd = r.left - p.x; ImageBuffer ib(dragtab); Unmultiply(ib); RGBA *s = ~ib; RGBA *e = s + ib.GetLength(); while(s < e) { s->a >>= 1; s++; } Premultiply(ib); dragtab = ib; isdrag = true; }
void Ctrl::UpdateArea0(SystemDraw& draw, const Rect& clip, int backpaint) { GuiLock __; LTIMING("UpdateArea"); LLOG("========== UPDATE AREA " << UPP::Name(this) << " =========="); if(globalbackbuffer) { CtrlPaint(draw, clip); LLOG("========== END (TARGET IS BACKBUFFER)"); return; } if(backpaint == FULLBACKPAINT || globalbackpaint && !hasdhctrl && !dynamic_cast<DHCtrl *>(this)) { ShowRepaintRect(draw, clip, LtRed()); BackDraw bw; bw.Create(draw, clip.GetSize()); bw.Offset(-clip.TopLeft()); bw.SetPaintingDraw(draw, clip.TopLeft()); CtrlPaint(bw, clip); bw.Put(draw, clip.TopLeft()); LLOG("========== END (FULLBACKPAINT)"); return; } if(backpaint == TRANSPARENTBACKPAINT) { LLOG("TransparentBackpaint"); Vector<Rect> area; GatherTransparentAreas(area, draw, GetRect().GetSize(), clip); for(int i = 0; i < area.GetCount(); i++) { Rect ar = area[i]; LLOG("Painting area: " << ar); ShowRepaintRect(draw, ar, LtBlue()); BackDraw bw; bw.Create(draw, ar.GetSize()); bw.Offset(-ar.TopLeft()); bw.SetPaintingDraw(draw, ar.TopLeft()); CtrlPaint(bw, ar); bw.Put(draw, ar.TopLeft()); if(!draw.ExcludeClip(ar)) { LLOG("========== END"); return; } } PaintOpaqueAreas(draw, GetRect().GetSize(), clip); LLOG("========== END"); return; } CtrlPaint(draw, clip); LLOG("========== END"); }
virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const { w.DrawRect(r, paper); Image m = q; if(!IsNull(m)) w.DrawImage(r.left, r.top, Rescale(m, r.GetSize())); }
void GLDraw::PutImage(Point p, const Image& img, const Rect& src) { LTIMING("PutImage"); FlushPutRect(); gl_image.Use(); Size isz = img.GetSize(); Rect s = src & isz; Rect r(p, s.GetSize()); PutImagePixels += isz.cx * isz.cy; GLshort vertex[] = { r.left, r.top, r.left, r.bottom, r.right, r.bottom, r.right, r.top, }; static GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; const float *tc; if(src == isz) { static float fixed[] = { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, }; tc = fixed; } else { Sizef iszf = isz; Rectf h; h.left = s.left / iszf.cx; h.right = s.right / iszf.cx; h.top = s.top / iszf.cy; h.bottom = s.bottom / iszf.cy; float partial[] = { (float)h.left, (float)h.top, (float)h.left, (float)h.bottom, (float)h.right, (float)h.bottom, (float)h.right, (float)h.top, }; tc = partial; } glEnableVertexAttribArray(ATTRIB_TEXPOS); glVertexAttribPointer(ATTRIB_TEXPOS, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), tc); glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_SHORT, GL_FALSE, 2 * sizeof(GLshort), vertex); glBindTexture(GL_TEXTURE_2D, GetTextureForImage(img)); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); glDisableVertexAttribArray(ATTRIB_TEXPOS); }
Vector2 LandscapeEditorDrawSystem::TranslatePoint(const Vector2& point, const Rect& fromRect, const Rect& toRect) { DVASSERT(fromRect.dx != 0.f && fromRect.dy != 0.f); Vector2 origRectSize = fromRect.GetSize(); Vector2 destRectSize = toRect.GetSize(); Vector2 scale(destRectSize.x / origRectSize.x, destRectSize.y / origRectSize.y); Vector2 relPos = point - fromRect.GetPosition(); Vector2 newRelPos(relPos.x * scale.x, relPos.y * scale.y); Vector2 newPos = newRelPos + toRect.GetPosition(); return newPos; }
void Painter::DrawPaintingOp(const Rect& target, const Painting& p) { Size sz = target.GetSize(); Sizef psz = p.GetSize(); Begin(); Translate(target.left, target.top); Scale(sz.cx / psz.cx, sz.cy / psz.cy); Paint(p); End(); }
void GLDraw::PutImage(Point p, const Image& img, const Rect& src) { if(img.GetLength() == 0) return; LLOG("PutImage " << img.GetSerialId() << ' ' << p.x << ", " << p.y << ", "<< img.GetSize()); LLOG("SysImage cache pixels " << sTextureCache.GetSize() << ", count " << sTextureCache.GetCount()); ImageGLDataMaker m; m.img = img; ImageGLData& sd = sTextureCache.Get(m); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, sd.texture_id); glColor3f(1.0f, 1.0f, 1.0f); if(src == img.GetSize()) { Rect r(p, img.GetSize()); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2i(r.left, r.top); glTexCoord2f(1, 0); glVertex2i(r.right, r.top); glTexCoord2f(0, 1); glVertex2i(r.left, r.bottom); glTexCoord2f(1, 1); glVertex2i(r.right, r.bottom); glEnd(); } else { Sizef iszf = img.GetSize(); Rect s = src & img.GetSize(); Rect r(p, s.GetSize()); Rectf h; h.left = (double)s.left / iszf.cx; h.right = (double)s.right / iszf.cx; h.top = (double)s.top / iszf.cy; h.bottom = (double)s.bottom / iszf.cy; glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(h.left, h.top); glVertex2i(r.left, r.top); glTexCoord2f(h.right, h.top); glVertex2i(r.right, r.top); glTexCoord2f(h.left, h.bottom); glVertex2i(r.left, r.bottom); glTexCoord2f(h.right, h.bottom); glVertex2i(r.right, r.bottom); glEnd(); } glDisable(GL_TEXTURE_2D); sTextureCache.Shrink(4 * 1024 * 768, 1000); }
bool Ctrl::PaintOpaqueAreas(SystemDraw& w, const Rect& r, const Rect& clip, bool nochild) { GuiLock __; LTIMING("PaintOpaqueAreas"); if(!IsShown() || r.IsEmpty() || !r.Intersects(clip) || !w.IsPainting(r)) return true; Point off = r.TopLeft(); Point viewpos = off + GetView().TopLeft(); if(backpaint == EXCLUDEPAINT) return w.ExcludeClip(r); Rect cview = clip & (GetView() + off); for(Ctrl *q = lastchild; q; q = q->prev) if(!q->PaintOpaqueAreas(w, q->GetRect() + (q->InView() ? viewpos : off), q->InView() ? cview : clip)) return false; if(nochild && (lastchild || GetNext())) return true; Rect opaque = (GetOpaqueRect() + viewpos) & clip; if(opaque.IsEmpty()) return true; #ifdef SYSTEMDRAW if(backpaint == FULLBACKPAINT && !dynamic_cast<BackDraw *>(&w)) #else if(backpaint == FULLBACKPAINT && !w.IsBack()) #endif { ShowRepaintRect(w, opaque, LtRed()); BackDraw bw; bw.Create(w, opaque.GetSize()); bw.Offset(viewpos - opaque.TopLeft()); bw.SetPaintingDraw(w, opaque.TopLeft()); { LEVELCHECK(bw, this); Paint(bw); PaintCaret(bw); } bw.Put(w, opaque.TopLeft()); } else { w.Clip(opaque); ShowRepaintRect(w, opaque, Green()); w.Offset(viewpos); { LEVELCHECK(w, this); Paint(w); PaintCaret(w); } w.End(); w.End(); } LLOG("Exclude " << opaque); return w.ExcludeClip(opaque); }
void TopWindow::Open(Ctrl *owner) { GuiLock __; Rect r = GetRect(); if(r.IsEmpty()) SetRect(GetDefaultWindowRect()); else if(r.left == 0 && r.top == 0) if(owner && center == 1) SetRect(owner->GetRect().CenterRect(r.GetSize())); else if(center) SetRect(GetWorkArea().CenterRect(r.GetSize())); frame->SetClient(GetRect()); frame->window = this; frame->PopUp(owner, false, true); PopUp(frame, false, true); popup = false; SetRect(frame->GetClient()); SyncCaption(); if(state == MAXIMIZED) frame->Maximize(); }
Rect LandscapeTestData::TranslateRect(const Rect &rect, const Rect& destPlane) const { DVASSERT(landscapeRect.dx != 0 && landscapeRect.dy !=0); Vector2 origPlaneSize = landscapeRect.GetSize(); Vector2 destPlaneSize = destPlane.GetSize(); Vector2 scale(destPlaneSize.x / origPlaneSize.x, destPlaneSize.y / origPlaneSize.y); Vector2 relPos = rect.GetPosition() - landscapeRect.GetPosition(); Vector2 newRelPos(relPos.x * scale.x, relPos.y * scale.y); Vector2 newPos = newRelPos + destPlane.GetPosition(); Vector2 newSize(rect.GetSize().x * scale.x, rect.GetSize().y * scale.y); return Rect(newPos, newSize); }
Rect Ctrl::GetDefaultWindowRect() { GuiLock __; Rect r = GetPrimaryWorkArea(); Size sz = r.GetSize(); static int pos = min(sz.cx / 10, 50); pos += 10; int cx = sz.cx * 2 / 3; int cy = sz.cy * 2 / 3; if(pos + cx + 50 > sz.cx || pos + cy + 50 > sz.cy) pos = 0; return RectC(r.left + pos + 20, r.top + pos + 20, cx, cy); }
Vector2 ResultScreen::GetVecInRect(const Rect & rect, float32 angleInRad) { Vector2 retVec; Matrix2 m; m.BuildRotation(angleInRad); angleInRad += DAVA::PI_05; while(angleInRad > DAVA::PI_05) angleInRad -= DAVA::PI_05; if(angleInRad > DAVA::PI_05 / 2) angleInRad = DAVA::PI_05 - angleInRad; Vector2 v = Vector2((Point2f(rect.GetSize().x / 2, 0) * m).data) / Abs(cosf(angleInRad)); retVec = v + rect.GetCenter(); return retVec; }
virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const { w.DrawRect(r, paper); Image m = q; if(IsNull(m)) return; Size isz = m.GetSize(); if(isz.cx > 200 || isz.cy > 200) m = IconDesImg::LargeImage(); else if(isz.cx > r.GetWidth() || isz.cy > r.GetHeight()) m = CachedRescale(m, GetFitSize(m.GetSize(), r.GetSize())); Point p = r.CenterPos(m.GetSize()); w.DrawImage(p.x, p.y, m); }
Image GetRect_(const Image& orig, const Rect &r) { if(r.IsEmpty()) return Image(); ImageBuffer ib(r.GetSize()); for(int y = r.top; y < r.bottom; y++) { const RGBA *s = orig[y] + r.left; const RGBA *e = orig[y] + r.right; RGBA *t = ib[y - r.top]; while(s < e) { *t = *s; t++; s++; } } return ib; }
void SDraw::SysDrawImageOp(int x, int y, const Image& img, const Rect& src, Color color) { Rect sr(Point(x, y) + cloff.Top().offset, (src & img.GetSize()).GetSize()); const Vector<Rect>& clip = cloff.Top().clip; for(int i = 0; i < clip.GetCount(); i++) { Rect cr = clip[i] & sr; if(!cr.IsEmpty()) { Point p = cr.TopLeft(); Rect r(cr.TopLeft() - sr.TopLeft() + src.TopLeft(), cr.GetSize()); if(IsNull(color)) PutImage(p, img, r); else PutImage(p, img, r, color); } } }
void DeviceInfoTest::LoadResources() { UITestTemplate::LoadResources(); Font *font = FTFont::Create("~res:/Fonts/korinna.ttf"); DVASSERT(font); font->SetSize(20); Rect textRect = GetRect(); textRect.SetPosition(textRect.GetPosition() + Vector2(1.0f, 31.0f)); textRect.SetSize(textRect.GetSize() - Vector2(1.0f, 31.0f)); deviceInfoText = new UIStaticText(textRect); deviceInfoText->SetMultiline(true); deviceInfoText->SetTextAlign(ALIGN_LEFT | ALIGN_TOP); deviceInfoText->SetFont(font); deviceInfoText->SetTextColor(Color::White); deviceInfoText->SetDebugDraw(true); AddControl(deviceInfoText); }
void InterpolateImage(Image& img, const Rect& _rc) { Rect rc = _rc & img.GetSize(); Image m = Crop(img, rc); TimeStop tm; Image imp = CreateImage(rc.GetSize(), Null); Over(imp, Point(0, 0), m, m.GetSize()); Progress pi("Interpolating..."); for(int qq = 0; qq < 2000; qq++) { InterpolateFilter f; f.todo = 0; imp = Filter(imp, f); Over(imp, Point(0, 0), m, m.GetSize()); if(f.todo == 0) break; if(pi.SetCanceled(qq, 2000)) break; } Copy(img, rc.TopLeft(), imp, imp.GetSize()); }
void AutoHideBar::HideAnimate(Ctrl *c) { ASSERT(ctrl); // If the popup has a child popup active then reset timer and keep the popup visible Vector<Ctrl *> wins = Ctrl::GetTopCtrls(); for(int i = 0; i < wins.GetCount(); i++) { if (wins[i]->IsPopUp() && wins[i]->GetOwner() == &popup) { KillSetTimeCallback(autohide_timeout, THISBACK1(HideAnimate, ctrl), TIMEID_HIDE_TIMEOUT); return; } } DockTabBar::KillCursor(); #ifdef PLATFORM_WIN32 Rect r = popup.GetRect(); AdjustSize(r, -r.GetSize()); Animate(popup, r, GUIEFFECT_SLIDE); #endif popup.Close(); ctrl->Remove(); ctrl = NULL; }
Image IconDes::Copy(const Rect& r) { if(!IsCurrent() || r.IsEmpty()) return Image(); ImageBuffer ib(r.GetSize()); Slot& c = Current(); for(int y = r.top; y < r.bottom; y++) { const RGBA *s = c.image[y] + r.left; const RGBA *e = c.image[y] + r.right; const RGBA *k = c.selection[y] + r.left; RGBA *t = ib[y - r.top]; while(s < e) { *t = *s; if(!k->r) *t = RGBAZero(); t++; k++; s++; } } return ib; }
void Draw::DrawPaintingOp(const Rect& target, const Painting& pw) { if(!HasPainter()) return; Size sz = target.GetSize(); if((sz.cx > 2000 || sz.cy > 1500) && IsPrinter()) { int yy = 0; while(yy < sz.cy) { int ccy = min(sz.cy - yy, 100); ImageBuffer ib(sz.cx, ccy); Fill(~ib, White(), ib.GetLength()); PaintImageBuffer(ib, pw, sz, Point(0, yy), true); DrawImageBandRLE(*this, target.left, target.top + yy, ib, 16); yy += ccy; } } else { ImageBuffer ib(sz); Fill(~ib, IsPrinter() ? White() : SColorPaper(), ib.GetLength()); PaintImageBuffer(ib, pw, sz, Point(0, 0), IsPrinter()); DrawImage(target.left, target.top, ib); } }
int DockWindow::GetPointAlign(const Point p, Rect r, bool center, bool allow_lr, bool allow_tb) { Size border = r.GetSize(); border.cx = allow_lr ? border.cx/4 : 0; border.cy = allow_tb ? border.cy/4 : 0; if (center && r.Deflated(border).Contains(p)) return DOCK_NONE; int q = GetQuad(p, r); int al = DOCK_NONE; if (q == 0 || q == 1) al = DOCK_TOP; else if (q == 2 || q == 3) al = DOCK_RIGHT; else if (q == 4 || q == 5) al = DOCK_BOTTOM; else if (q == 6 || q == 7) al = DOCK_LEFT; if (!allow_lr && (al == DOCK_LEFT || al == DOCK_RIGHT)) al = (q == 7 || q == 2) ? DOCK_TOP : DOCK_BOTTOM; else if (!allow_tb && (al == DOCK_TOP || al == DOCK_BOTTOM)) al = (q == 0 || q == 5) ? DOCK_LEFT : DOCK_RIGHT; return al; }
Rect DockWindow::GetAlignBounds(int al, Rect r, bool center, bool allow_lr, bool allow_tb) { Size border = r.GetSize()/4; switch (al) { case DOCK_LEFT: r.right = r.left + (center ? border.cx : (GHalf_(r.left + r.right))); return r; case DOCK_TOP: r.bottom = r.top + (center ? border.cy : (GHalf_(r.top + r.bottom))); return r; case DOCK_RIGHT: r.left = r.right - (center ? border.cx : (GHalf_(r.left + r.right))); return r; case DOCK_BOTTOM: r.top = r.bottom - (center ? border.cy : (GHalf_(r.top + r.bottom))); return r; } if (allow_lr) r.DeflateHorz(border.cx); if (allow_tb) r.DeflateVert(border.cy); return r; }
NAMESPACE_UPP #define LTIMING(x) // RTIMING(x) #define LLOG(x) void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff) { Size dsz = dest.GetSize(); cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dsz.cx, dsz.cy); cairo_surface_flush(surface); byte *a = (byte *)cairo_image_surface_get_data(surface); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, dsz.cx); for(int i = 0; i < dsz.cy; i++) { int sl = poff.y + i; if(i >= 0 && i < srcsz.cy) Copy((RGBA *)a, pixels + srcsz.cx * sl + poff.x, minmax(srcsz.cx - poff.x, 0, min(dsz.cx, srcsz.cx))); a += stride; } cairo_surface_mark_dirty(surface); cairo_set_source_surface(w, surface, dest.left, dest.top); cairo_paint(w); cairo_surface_destroy(surface); }
void Ctrl::CtrlPaint(SystemDraw& w, const Rect& clip) { GuiLock __; LEVELCHECK(w, this); LTIMING("CtrlPaint"); Rect rect = GetRect().GetSize(); Rect orect = rect.Inflated(overpaint); if(!IsShown() || orect.IsEmpty() || clip.IsEmpty() || !clip.Intersects(orect)) return; Ctrl *q; Rect view = rect; for(int i = 0; i < frame.GetCount(); i++) { LEVELCHECK(w, NULL); frame[i].frame->FramePaint(w, view); view = frame[i].view; } Rect oview = view.Inflated(overpaint); bool hasviewctrls = false; bool viewexcluded = false; for(q = firstchild; q; q = q->next) if(q->IsShown()) if(q->InFrame()) { if(!viewexcluded && IsTransparent() && q->GetRect().Intersects(view)) { w.Begin(); w.ExcludeClip(view); viewexcluded = true; } LEVELCHECK(w, q); Point off = q->GetRect().TopLeft(); w.Offset(off); q->CtrlPaint(w, clip - off); w.End(); } else hasviewctrls = true; if(viewexcluded) w.End(); DOLEVELCHECK; if(!oview.IsEmpty()) { if(oview.Intersects(clip) && w.IsPainting(oview)) { LEVELCHECK(w, this); if(overpaint) { w.Clip(oview); w.Offset(view.left, view.top); Paint(w); PaintCaret(w); w.End(); w.End(); } else { w.Clipoff(view); Paint(w); PaintCaret(w); w.End(); } } } if(hasviewctrls && !view.IsEmpty()) { Rect cl = clip & view; w.Clip(cl); for(q = firstchild; q; q = q->next) if(q->IsShown() && q->InView()) { LEVELCHECK(w, q); Rect qr = q->GetRect(); Point off = qr.TopLeft() + view.TopLeft(); Rect ocl = cl - off; if(ocl.Intersects(Rect(qr.GetSize()).Inflated(overpaint))) { w.Offset(off); q->CtrlPaint(w, cl - off); w.End(); } } w.End(); } }