Example #1
0
static void sRenderRect(Painter& w, const Rect& r, int n, byte pattern)
{
	sRenderLine(w, r.left, r.top, 1, 0, 1, n, r.GetWidth(), pattern);
	sRenderLine(w, r.left, r.bottom - 1, 1, 0, 1, n, r.GetWidth(), pattern);
	sRenderLine(w, r.left, r.top, 0, 1, n, 1, r.GetHeight(), pattern);
	sRenderLine(w, r.right - 1, r.top, 0, 1, n, 1, r.GetHeight(), pattern);
}
Example #2
0
void DrawDragFrame(SystemDraw& w, const Rect& r, int n, int animation)
{
	DrawDragLine(w, true, r.left, r.top, r.GetWidth(), n, animation);
	DrawDragLine(w, false, r.left, r.top + n, r.GetHeight() - 2 * n, n, animation);
	DrawDragLine(w, false, r.right - n, r.top + n, r.GetHeight() - 2 * n, n, animation);
	DrawDragLine(w, true, r.left, r.bottom - n, r.GetWidth(), n, animation);
}
Example #3
0
void Ctrl::DragRectDraw0(const Vector<Rect>& clip, const Rect& rect, int n, const byte *pattern, int animation)
{
	int hn = min(rect.GetHeight(), n);
	int vn = min(rect.GetWidth(), n);
	DrawLine(clip, rect.left, rect.top, rect.GetWidth(), hn, true, pattern, animation);
	DrawLine(clip, rect.left, rect.top + hn, vn, rect.GetHeight() - hn, false, pattern, animation);
	DrawLine(clip, rect.right - vn, rect.top + hn, vn, rect.GetHeight() - hn, false, pattern, animation);
	DrawLine(clip, rect.left + vn, rect.bottom - hn, rect.GetWidth() - 2 * vn, hn, true, pattern, animation);
}
Example #4
0
void AutoHideBar::ShowWindow()
{
    DockWindow* hiddenwindow = reinterpret_cast<DockWindow*>(tabs[active].dock);
    if(!hiddenwindow->IsOpen())
    {
        Size s  = hiddenwindow->GetSizeHint();
        Rect r  = GetScreenRect();
        Rect rr = r;
        switch(layout)
        {
        case LAYOUT_LEFT:
            rr.left	= r.right;
            s.cy = r.GetHeight();
#if defined(PLATFORM_X11)
            rr.right += 1;
#endif
            break;
        case LAYOUT_TOP:
            rr.top = r.bottom;
            s.cx = r.GetWidth();
#if defined(PLATFORM_X11)
            rr.bottom += 1;
#endif
            break;
        case LAYOUT_RIGHT:
            rr.right = r.left;
            s.cy = r.GetHeight();
#if defined(PLATFORM_X11)
            rr.left -= 1;
#endif
            break;
        case LAYOUT_BOTTOM:
            rr.bottom = r.top;
            s.cx = r.GetWidth();
#if defined(PLATFORM_X11)
            rr.top -= 1;
#endif
            break;

        }
        popup.SetRect(rr);
        popup.Add(hiddenwindow->SizePos());
        hiddenwindow->Ctrl::Show();
        popup.PopUp(GetOwner(), false, true, false, false);
        ctrl = hiddenwindow;
        Ctrl::ProcessEvents();
        AdjustSize(rr, s);
        Animate(popup, rr, GUIEFFECT_SLIDE);
    }
}
void Bitmap::StretchBlt(Bitmap *src, const Rect &src_rc, const Rect &dst_rc, BitmapMaskOption mask)
{
	BITMAP *al_src_bmp = src->_alBitmap;
	if (mask == kBitmap_Transparency)
	{
		masked_stretch_blit(al_src_bmp, _alBitmap,
			src_rc.Left, src_rc.Top, src_rc.GetWidth(), src_rc.GetHeight(),
			dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
	}
	else
	{
		stretch_blit(al_src_bmp, _alBitmap,
			src_rc.Left, src_rc.Top, src_rc.GetWidth(), src_rc.GetHeight(),
			dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
	}
}
void Bitmap::AAStretchBlt(Bitmap *src, const Rect &dst_rc, BitmapMaskOption mask)
{
	BITMAP *al_src_bmp = src->_alBitmap;
	// WARNING: For some evil reason Allegro expects dest and src bitmaps in different order for blit and draw_sprite
	if (mask == kBitmap_Transparency)
	{
		aa_stretch_sprite(_alBitmap, al_src_bmp,
			dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
	}
	else
	{
		aa_stretch_blit(al_src_bmp, _alBitmap,
			0, 0, al_src_bmp->w, al_src_bmp->h,
			dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
	}
}
bool Bitmap::CreateSubBitmap(Bitmap *src, const Rect &rc)
{
    Destroy();
    _alBitmap = create_sub_bitmap(src->_alBitmap, rc.Left, rc.Top, rc.GetWidth(), rc.GetHeight());
    _isDataOwner = true;
    return _alBitmap != nullptr;
}
Example #8
0
Rect TrackBar::GetTrackBox(void) const
{
	Rect box = GetBoundingBox();

	Size size(8,box.GetHeight());

	return Rect(Point(box.left + box.GetWidth() * GetTrackValue() / GetTrackRange() - size.cx / 2,box.top + box.GetHeight() / 2 - size.cy / 2 + 2),size);
}
Example #9
0
void Painter::DrawImageOp(int x, int y, int cx, int cy, const Image& image, const Rect& src, Color color)
{
	Image img = IsNull(color) ? image : SetColorKeepAlpha(image, color);
	RectPath(x, y, cx, cy);
	double sw = (double)cx / src.GetWidth();
	double sh = (double)cy / src.GetHeight();
	Fill(img, Xform2D::Scale(sw, sh) * Xform2D::Translation(x - sw * src.left, y - sh * src.top));
}
Example #10
0
void Bitmap::AAStretchBlt(Bitmap *src, const Rect &src_rc, const Rect &dst_rc, BitmapMaskOption mask)
{
	BITMAP *al_src_bmp = src->_alBitmap;
	if (mask == kBitmap_Transparency)
	{
		// TODO: aastr lib does not expose method for masked stretch blit; should do that at some point since 
		// the source code is a gift-ware anyway
		// aa_masked_blit(_alBitmap, al_src_bmp, src_rc.Left, src_rc.Top, src_rc.GetWidth(), src_rc.GetHeight(), dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
		throw "aa_masked_blit is not yet supported!";
	}
	else
	{
		aa_stretch_blit(al_src_bmp, _alBitmap,
			src_rc.Left, src_rc.Top, src_rc.GetWidth(), src_rc.GetHeight(),
			dst_rc.Left, dst_rc.Top, dst_rc.GetWidth(), dst_rc.GetHeight());
	}
}
Example #11
0
void  Ctrl::WndScrollView0(const Rect& r, int dx, int dy)
{
	GuiLock __;
	if(dx == 0 && dy == 0)
		return;
	if(dx && dy) {
		Refresh(r);
		return;
	}
	RemoveCursor();
	RemoveCaret();
	Rect sr = r.Offseted(GetScreenRect().TopLeft());
	Vector<Rect> pr = Intersection(GetPaintRects(), sr);
	for(int i = 0; i < pr.GetCount(); i++) {
		Rect r = pr[i];
		if(dx) {
			int n = r.GetWidth() - abs(dx);
			if(n > 0) {
				int to = r.left + dx * (dx > 0);
				int from = r.left - dx * (dx < 0);
				for(int y = r.top; y < r.bottom; y++)
					memmove(framebuffer[y] + to, framebuffer[y] + from, n * sizeof(RGBA));
			}
			n = min(abs(dx), r.GetWidth());	
			Refresh(dx < 0 ? r.left : r.right - n, r.top, n, r.GetHeight());
		}
		else {
			int n = r.GetHeight() - abs(dy);
			for(int y = 0; y < n; y++)
				memmove(framebuffer[dy < 0 ? r.top + y : r.bottom - 1 - y] + r.left,
				        framebuffer[dy < 0 ? r.top + y - dy : r.bottom - 1 - y - dy] + r.left,
				        r.GetWidth() * sizeof(RGBA));
			n = min(abs(dy), r.GetHeight());	
			Refresh(r.left, dy < 0 ? r.bottom - n : r.top, r.GetWidth(), n);
		}
	}

	Vector<Rect> ur;
	for(int i = 0; i < invalid.GetCount(); i++)
		if(invalid[i].Intersects(sr))
			ur.Add(invalid[i]);
	for(int i = 0; i < ur.GetCount(); i++)
		AddInvalid(ur[i].Offseted(dx, dy));
}
Example #12
0
void GLController::SetScissorRect (const Rect& rect)
{
    if (mScissorRect != rect)
    {
        mScissorRect = rect;
        const Vector2i& size = GetActiveViewport();
        glScissor((GLint)rect.left, (GLint)size.y - (GLint)rect.bottom,
                  (GLsizei)rect.GetWidth(), (GLsizei)rect.GetHeight());
    }
}
Example #13
0
bool Print(const RichText& text, const Rect& page, int currentpage, const char *name)
{
	PrinterJob pj(name);
	pj.CurrentPage(currentpage);
	pj.PageCount(text.GetHeight(page).page + 1);
	pj.Landscape(page.GetWidth() > page.GetHeight());
	if(pj.Execute()) {
		Print(pj, text, page, pj.GetPages());
		return true;
	}
	return false;
}
void Graphics::DrawImage(Image* image, const Rect& rc, const ImageAttributes* attr) {
    Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private);
    Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(image->_private);

    if(attr!=0) {
        Gdiplus::ImageAttributes* ia = reinterpret_cast<Gdiplus::ImageAttributes*>(attr->_private);
        g->DrawImage(gdiImage, Gdiplus::Rect(rc.GetLeft(), rc.GetTop(), rc.GetWidth(), rc.GetHeight()), 0, 0, gdiImage->GetWidth(), gdiImage->GetHeight(), Gdiplus::UnitPixel, ia);
    }
    else {
        g->DrawImage(gdiImage, ToGDIRect<Rect, Gdiplus::Rect>(rc));
    }
}
Example #15
0
void Graphics::DrawRectangle(Pen* pen, const Rect& rc) {
	cairo_t* cg = reinterpret_cast<cairo_t*>(_private);
	cairo_save(cg);
	PenPrivate* pp = reinterpret_cast<PenPrivate*>(pen->_private);
	cairo_pattern_t* cp = pp->pattern;
	cairo_set_source(cg, cp);
	cairo_set_line_width(cg, pp->width);
	cairo_translate(cg, rc.GetLeft(), rc.GetTop());
	cairo_rectangle(cg, 0, 0, rc.GetWidth(), rc.GetHeight());
	cairo_stroke(cg);
	cairo_restore(cg);
}
Example #16
0
void Graphics::FillRectangle(Brush* brush, const Rect& rc) {
	cairo_t* cg = reinterpret_cast<cairo_t*>(_private);
	cairo_save(cg);
	if(cg!=0) {
		cairo_pattern_t* cp = reinterpret_cast<cairo_pattern_t*>(brush->_private);
		if(cp!=0) {
			cairo_set_source(cg, cp);
			cairo_translate(cg, rc.GetLeft(), rc.GetTop());
			cairo_rectangle(cg, 0, 0, rc.GetWidth(), rc.GetHeight());
			cairo_fill(cg);
		}
	}
	cairo_restore(cg);
}
Example #17
0
void SDLExample::Layout() {
	SDLCtrl::Layout();
	if (!IsReady())
		return;
	
	Rect r = GetRect();
	for(int i = 0; i < r.GetWidth(); i++)
		sintab[i] = sin(i * M_PI / 180.0);

	for(int i = 0; i < MAXPOINT; i++) {
		points[i].x   = rand() % (r.GetWidth() - 1);
		points[i].y   = rand() % (r.GetHeight() - 1);
		points[i].sx  = (rand() & 1) + 1;
		points[i].sy  = (rand() & 1) + 1;
		points[i].col = (rand() % 255);
	}
	
	if (!demoInitialized)
		return;
	
	int width = GetWidth();
	int height = GetHeight();
	
	surf.Resize(width, height);
	
	SetupPalette(surf.GetSurface());
	SetupPalette(GetSurface());
	
	j = 0;
	k = 0;
	len0 = LengthStr(scroll[j]);
	len1 = len0;
	xmax = (width - len1) / 2;
	x0 = width;
	x1 = -len0;	
}
Example #18
0
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);
}
Example #19
0
void Ctrl::DrawLine(const Vector<Rect>& clip, int x, int y, int cx, int cy, bool horz, const byte *pattern, int animation)
{
	if(cx <= 0 || cy <= 0)
		return;
	Vector<Rect> rr = Intersection(clip, RectC(x, y, cx, cy));
	for(int i = 0; i < rr.GetCount(); i++) {
		Rect r = rr[i];
		AddUpdate(r);
		if(horz)
			for(int y = r.top; y < r.bottom; y++)
				DDRect(framebuffer[y] + r.left, 1, pattern, r.left + animation, r.GetWidth());
		else
			for(int x = r.left; x < r.right; x++)
				DDRect(framebuffer[r.top] + x, framebuffer.GetWidth(), pattern, r.top + animation, r.GetHeight());
	}
}
Example #20
0
	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);
	}
Example #21
0
	void Window::FullScreen()
	{
		::GetClientRect(hWnd_, &restoreFullRect_);
		Point point;
		::ClientToScreen(hWnd_, &point);
		restoreFullRect_.left = point.x;
		restoreFullRect_.top = point.y;
		restoreFullRect_.right += point.x;
		restoreFullRect_.bottom += point.y;
		MONITORINFO oMonitor = {};
		oMonitor.cbSize = sizeof(oMonitor);
		::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTONEAREST), &oMonitor);
		Rect rcWork = oMonitor.rcWork;

		::SetWindowPos(hWnd_, nullptr, rcWork.left, rcWork.top, rcWork.GetWidth(), rcWork.GetHeight(), SWP_SHOWWINDOW | SWP_NOZORDER);
	}
Example #22
0
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();
		}
	}
}
Example #23
0
void DockWindow::HighlightCtrl::Paint(Draw &w)
{
	if (!img.IsEmpty())
		w.DrawImage(0, 0, img);
	bool nest = (GetMouseFlags() & nestedkey) ? !isnested : isnested;
	if (nest) {
		Rect r = GetSize();
		Rect t = r;
		const TabCtrl::Style &s = TabCtrl::StyleDefault();
		t.bottom -= s.tabheight + s.sel.top + 1;	// Nasty bodge! See TabBar::GetStyleHeight
		r.top = t.bottom-1;
		r.right = max(min(150, r.GetWidth()/3), 20);
		r.left += 10;
		ChPaint(w, r, *highlight);
		ChPaint(w, t, *highlight);
	}
	else
		ChPaint(w, GetSize(), *highlight);
}
Example #24
0
void Ctrl::WndSetPos(const Rect& rect)
{
	LLOG("WndSetPos0 " << rect);
	GuiLock __;
	if(!IsOpen())
		return;
	Ptr<Ctrl> this_ = this;
	SweepConfigure(false); // Remove any previous GDK_CONFIGURE for this window
	if(!this_ || !IsOpen())
		return;
//	gtk_window_move(gtk(), rect.left, rect.top);
//	gtk_window_resize(gtk(), rect.GetWidth(), rect.GetHeight());
	gdk_window_move_resize(gdk(), rect.left, rect.top, rect.GetWidth(), rect.GetHeight());
	int t0 = msecs();
	do { // Wait up to 500ms for corresponding GDK_CONFIGURE to arrive
		if(SweepConfigure(true))
			break;
	}
	while(msecs() - t0 < 500);
	LLOG("-- WndSetPos0 " << rect << " " << msecs() - t0);
}
Example #25
0
void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point srcoff)
{
	GuiLock __;
	XImage ximg;
	sInitXImage(ximg, srcsz);
	ximg.bitmap_pad = 32;
	ximg.bytes_per_line = sizeof(RGBA) * srcsz.cx;
	ximg.bits_per_pixel = 32;
	ximg.blue_mask = 0x00ff0000;
	ximg.green_mask = 0x0000ff00;
	ximg.red_mask = 0x000000ff;
	ximg.bitmap_unit = 32;
	ximg.depth = 24;
	ximg.data = (char *)pixels;
	XInitImage(&ximg);
	Drawable dw = w.GetDrawable();
	GC gc = XCreateGC(Xdisplay, dw, 0, 0);
	Point p = dest.TopLeft() + w.GetOffset();
	XPutImage(Xdisplay, dw, gc, &ximg, srcoff.x, srcoff.y,
	          p.x, p.y, dest.GetWidth(), dest.GetHeight());
	XFreeGC(Xdisplay, gc);
}
Example #26
0
void ViewContext::SetupViewport(const Rect &size, SCREEN_ORIENTATION_ANGLE screenOrientation)
{
	Rect viewport;
	
	if (m_viewportIsFixedSize)
	{
		viewport = m_viewport;
		m_screenOrientation = SCREEN_ANGLE_0;
	}
	else
	{
		// based on the orientation, we may need to swap the width/height
		// of the passed viewport dimensions
		// (we don't do viewport rotation if the viewport is fixed)
		if (!IgnoringScreenRotation() && (screenOrientation == SCREEN_ANGLE_90 || screenOrientation == SCREEN_ANGLE_270))
		{
			// swap width and height
			viewport.left = size.top;
			viewport.top = size.left;
			viewport.right = size.bottom;
			viewport.bottom = size.right;
		}
		else
			viewport = size;
		
		// we **don't** want this to be rotated
		m_viewport = size;
		
		m_screenOrientation = screenOrientation;
	}
	
	// we **do** obviously want this to be rotated (if there is a rotation)
	GL_CALL(glViewport(viewport.left, viewport.top, viewport.GetWidth(), viewport.GetHeight()));
		
	// we also **don't** want the camera to work with a rotated viewport
	if (m_camera != NULL)
		m_camera->OnResize(m_viewport);
}
Example #27
0
Size DrawLabel::Paint(Ctrl *ctrl, Draw& w, const Rect& r, bool visibleaccesskey) const
{
	int lspc = this->lspc;
	int rspc = this->rspc;
	Size sz1 = limg.GetSize();
	Size sz2 = rimg.GetSize();
	int txtcx = r.GetWidth() - sz1.cx - Nvl(lspc, 0) - sz2.cx - Nvl(rspc, 0);
	Size txtsz = *text ? GetSmartTextSize(text, font, txtcx) : paintrect.GetStdSize();
	if(txtsz.cx) {
		if(!rimg_never_hide && txtsz.cx + sz1.cx + sz2.cx + Nvl(lspc, 0) + Nvl(rspc, 0) > r.GetWidth()) {
			sz2.cx = 0;
			rspc = 0;
		}
		if(!limg_never_hide && txtsz.cx + sz1.cx + sz2.cx + Nvl(lspc, 0) + Nvl(rspc, 0) > r.GetWidth()) {
			sz1.cx = 0;
			lspc = 0;
		}
	}
	Size isz = GetSize(txtcx, sz1, lspc, sz2, rspc);
	Point p = r.TopLeft(), ip;
	if(align == ALIGN_LEFT)
		p.x = r.left;
	else
	if(align == ALIGN_RIGHT)
		p.x = r.right - isz.cx;
	else
	if(align == ALIGN_CENTER)
		p.x = (r.right + r.left - isz.cx) / 2;
	if(valign == ALIGN_TOP)
		p.y = r.top;
	else
	if(valign == ALIGN_BOTTOM)
		p.y = r.bottom - isz.cy;
	else
	if(valign == ALIGN_CENTER)
		p.y = (r.bottom + r.top - txtsz.cy) / 2;
	Color color = disabled && !IsNull(disabledink) ? disabledink : ink;
	if(IsNull(color))
		color = disabled ? SColorDisabled : GetLabelTextColor(ctrl);
	int ix;
	if(IsNull(lspc))
		ix = r.left + push;
	else {
		ix = p.x + push;
		p.x += sz1.cx;
		p.x += lspc;
	}
	int iy = push + (r.top + r.bottom - sz1.cy) / 2;

	if(sz1.cx)
		if(IsNull(lcolor))
			w.DrawImage(ix, iy, DisabledImage(limg, disabled));
		else
			w.DrawImage(ix, iy, limg, lcolor);

	iy = push + (r.top + r.bottom - sz2.cy) / 2;
	ix = (IsNull(rspc) ? r.right - sz2.cx : p.x + txtsz.cx + rspc) + push;
	if(sz2.cx)
		if(IsNull(rcolor))
			w.DrawImage(ix, iy, DisabledImage(rimg, disabled));
		else
			w.DrawImage(ix, iy, rimg, rcolor);
	paintrect.Paint(w, p.x + push, p.y + push, txtsz.cx, isz.cy, color, Null);
	if(*text) {
		if(disabled)
			DrawSmartText(w, p.x + push + 1, p.y + push + (isz.cy - txtsz.cy) / 2 + 1,
			              txtsz.cx, text, font, SColorPaper);
		DrawSmartText(w, p.x + push, p.y + push, txtcx,
		              text, font, color, visibleaccesskey ? accesskey : 0);
		if(focus)
			DrawFocus(w, p.x - 2, p.y, txtsz.cx + 5, isz.cy);
	}

	return isz;
}
Example #28
0
inline int Area(const Rect& r)
{
	return r.GetHeight() * r.GetWidth();
}
Example #29
0
			bool Mesh::InitSprite(HandleOrRid matId, HandleOrRid texId, const Rect &rect)
			{
				CoreManagers *res = CoreManagers::Get();

				if(matId.isHandle && matId.handle != HANDLE_NONE) {
					MaterialManager::AddRef(matId.handle);
					material = matId.handle;
				} else if(matId.rid != RID_NONE) {
					material = res->materialManager->Load(matId.rid);
				}

				Texture *tex = nullptr;
				if((texId.isHandle && texId.handle != HANDLE_NONE) || (!texId.isHandle && texId.rid != RID_NONE)) {
					
					// Get exclusive access to material
					material = MaterialManager::DuplicateIfShared(material);
					Material *mat = MaterialManager::Get(material);

					// Create a new texture set for this material
					TextureSetManager::Free(mat->textureSet);
					if(texId.isHandle) {
						tex = TextureManager::Get(texId.handle);
						TextureManager::AddRef(texId.handle);
						TextureSet ts;
						ts.textures[ts.textureCount] = texId.handle;
						ts.textures[ts.textureCount++] = tex->rid;
						mat->textureSet = res->textureSetManager->Add(Move(ts));
					} else {
						mat->SetTextures(1, &texId.rid);
						tex = TextureManager::Get(TextureSetManager::Get(mat->textureSet)->textures[0]);
					}
				} else {
					Material *mat = MaterialManager::Get(material);
					if(mat->textureSet != HANDLE_NONE) {
						TextureSet *ts = TextureSetManager::Get(mat->textureSet);
						if(ts->textureCount > 0) {
							tex = TextureManager::Get(ts->textures[0]);
						}
					}
				}

				if(tex == nullptr) {
					Console::Error("Sprite cannot be initialized without a texture (it has to know texture dimensions)");
					return false;
				}

				struct V
				{
					Vector3 pos;
					uint32 color;
					Vector2 uv;
				} verts[4];

				Core::Mesh m;
				m.SetIndexAttributes(3, 2);
				m.SetVertexAttributes(VertexFormat::AttributeFlag_Color|VertexFormat::AttributeFlag_TexCoord);
				m.SetMeshFlag(Core::Mesh::MeshFlag_HasTranslucency);

				// Draw a quad that is 1 pixel smaller than the sprite area would suggest.
				// Shrink the uv's by a half a texel on each side.
				// These two adjustments will let us put sprites next to eachother without
				// having visible seams between them (as long as you don't use mipmaps).
				float pw = rect.GetWidth();
				float w = (pw-1) / MAKI_PPU;
				float ph = rect.GetHeight();
				float h = (ph-1) / MAKI_PPU;

				float du = 0.5f / tex->width;
				float dv = 0.5f / tex->height;

				verts[0].pos = Vector3(0.0f, 0.0f, 0.0f);
				verts[0].color = 0xffffffff;
				verts[0].uv.x = rect.left / tex->width + du;
				verts[0].uv.y = rect.top / tex->height + dv;

				verts[1].pos = Vector3(0.0f, -h, 0.0f);
				verts[1].color = 0xffffffff;
				verts[1].uv.x = rect.left / tex->width + du;
				verts[1].uv.y = (rect.top + ph) / tex->height - dv;

				verts[2].pos = Vector3(w, -h, 0.0f);
				verts[2].color = 0xffffffff;
				verts[2].uv.x = (rect.left + pw) / tex->width - du;
				verts[2].uv.y = (rect.top + ph) / tex->height - dv;

				verts[3].pos = Vector3(w, 0.0f, 0.0f);
				verts[3].color = 0xffffffff;
				verts[3].uv.x = (rect.left + pw) / tex->width - du;
				verts[3].uv.y = rect.top / tex->height + dv;

				m.PushVertexData(sizeof(verts), (char *)verts);

				uint16 indices[6] = { 0, 1, 2, 0, 2, 3 };
				m.PushIndexData(sizeof(indices), (char *)indices);

				m.Upload();
				bounds.Merge(m.bounds);
		
				mesh = res->meshManager->Add(Move(m));

				// Allocate and initialize draw commands
				drawCommands.SetSize(1);
				DrawCommand *dc = &drawCommands[0];
				new(dc) DrawCommand();
				dc->SetMesh(mesh);
				dc->SetMaterial(material);
				
				return true;
			}
Example #30
0
void SystemDraw::RectPath(const Rect& r)
{
	cairo_rectangle(cr, r.left, r.top, r.GetWidth(), r.GetHeight());
}