void wxRIRefData::CreateRects( const wxRegion& region ) { if (m_rects) delete [] m_rects; m_rects = 0; m_numRects = 0; if (region.IsEmpty()) return; #if 0 Region r = (Region) region.GetX11Region(); if (r) { m_numRects = r->numRects; if (m_numRects) { m_rects = new wxRect[m_numRects]; for (size_t i=0; i < m_numRects; ++i) { _XBox &xr = r->rects[i]; wxRect &wr = m_rects[i]; wr.x = xr.x1; wr.y = xr.y1; wr.width = xr.x2-xr.x1; wr.height = xr.y2-xr.y1; } } } #endif }
bool wxTopLevelWindowMac::SetShape(const wxRegion& region) { wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); #if TARGET_CARBON // The empty region signifies that the shape should be removed from the // window. if ( region.IsEmpty() ) { wxSize sz = GetClientSize(); wxRegion rgn(0, 0, sz.x, sz.y); return SetShape(rgn); } // Make a copy of the region RgnHandle shapeRegion = NewRgn(); CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); // Dispose of any shape region we may already have RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); if ( oldRgn ) DisposeRgn(oldRgn); // Save the region so we can use it later SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); // Tell the window manager that the window has changed shape ReshapeCustomWindow((WindowRef)MacGetWindowRef()); return TRUE; #else return FALSE; #endif }
// workaround for 2.9 cocoa where the equality operator for region is currently (2011-03-09) not implemented bool ocpn_mac_region_compare(const wxRegion& r1, const wxRegion& r2) { wxCoord x1,x2,y1,y2,w1,w2,h1,h2; r1.GetBox(x1,y1,w1,h1); r2.GetBox(x2,y2,w2,h2); if(x1 == x2 && y1 == y2 && w1 == w2 && h1 && h2) return true; return false; }
void WxGraphs::DrawWindowInfo(wxDC * dc, const wxRegion & repainted_region) { if (repainted_region.IsEmpty()) return; int info_left_marg = m_screen_margins.leftmargin + 8; int param_name_shift = 5; if (m_draws.size() < 1) return; int w, h; dc->GetSize(&w, &h); DrawInfo *info = m_draws[0]->GetDrawInfo(); wxString name = info->GetSetName().c_str(); int namew, nameh; dc->GetTextExtent(name, &namew, &nameh); if (repainted_region.Contains(info_left_marg, m_screen_margins.infotopmargin, w - m_screen_margins.infotopmargin, nameh) == wxOutRegion) return; dc->SetTextForeground(*wxWHITE); dc->DrawText(name, info_left_marg, m_screen_margins.infotopmargin); wxColor color = dc->GetTextForeground(); int xpos = info_left_marg + namew + param_name_shift; for (int i = 0; i < (int)m_draws.size(); ++i) { if (!m_draws[i]->GetEnable()) continue; DrawInfo *info = m_draws[i]->GetDrawInfo(); dc->SetTextForeground(info->GetDrawColor()); name = info->GetShortName().c_str(); dc->GetTextExtent(name, &namew, &nameh); dc->DrawText(name, xpos, m_screen_margins.infotopmargin); xpos += namew + param_name_shift; } dc->SetTextForeground(color); }
void wxRegionIterator::CreateRects( const wxRegion& region ) { wxDELETEA(m_rects); m_numRects = 0; #ifdef __WXGTK3__ cairo_region_t* cairoRegion = region.GetRegion(); if (cairoRegion == NULL) return; m_numRects = cairo_region_num_rectangles(cairoRegion); if (m_numRects) { m_rects = new wxRect[m_numRects]; for (int i = 0; i < m_numRects; i++) { GdkRectangle gr; cairo_region_get_rectangle(cairoRegion, i, &gr); wxRect &wr = m_rects[i]; wr.x = gr.x; wr.y = gr.y; wr.width = gr.width; wr.height = gr.height; } } #else GdkRegion *gdkregion = region.GetRegion(); if (!gdkregion) return; GdkRectangle* gdkrects; gdk_region_get_rectangles(gdkregion, &gdkrects, &m_numRects); if (m_numRects) { m_rects = new wxRect[m_numRects]; for (int i = 0; i < m_numRects; ++i) { GdkRectangle &gr = gdkrects[i]; wxRect &wr = m_rects[i]; wr.x = gr.x; wr.y = gr.y; wr.width = gr.width; wr.height = gr.height; } } g_free( gdkrects ); #endif }
void wxRIRefData::CreateRects( const wxRegion& region ) { if (m_rects) delete [] m_rects; m_rects = 0; m_numRects = 0; if (region.IsEmpty()) return; Region r = (Region) region.GetX11Region(); if (r) { #if wxUSE_NANOX GR_RECT rect; GrGetRegionBox(r, & rect); m_numRects = 1; m_rects = new wxRect[1]; m_rects[0].x = rect.x; m_rects[0].y = rect.y; m_rects[0].width = rect.width; m_rects[0].height = rect.height; #else m_numRects = r->numRects; if (m_numRects) { m_rects = new wxRect[m_numRects]; #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for (size_t i=0; i < m_numRects; ++i) { _XBox &xr = r->rects[i]; wxRect &wr = m_rects[i]; wr.x = xr.x1; wr.y = xr.y1; wr.width = xr.x2-xr.x1; wr.height = xr.y2-xr.y1; } } #endif } }
bool wxRegion::DoXor( const wxRegion& region ) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { return false; } AllocExclusive(); gdk_region_xor( M_REGIONDATA->m_region, region.GetRegion() ); return true; }
void wxRIRefData::CreateRects( const wxRegion& region ) { delete [] m_rects; Init(); GdkRegion *gdkregion = region.GetRegion(); if (!gdkregion) return; Region r = ((GdkRegionPrivate *)gdkregion)->xregion; if (r) { m_numRects = r->numRects; if (m_numRects) { m_rects = new wxRect[m_numRects]; for (size_t i=0; i < m_numRects; ++i) { _XBox &xr = r->rects[i]; wxRect &wr = m_rects[i]; wr.x = xr.x1; wr.y = xr.y1; wr.width = xr.x2-xr.x1; wr.height = xr.y2-xr.y1; } } } }
bool wxRegion::DoIntersect( const wxRegion& region ) { wxCHECK_MSG( region.IsOk(), false, wxT("invalid region") ); if (!m_refData) { // intersecting with invalid region doesn't make sense return false; } AllocExclusive(); gdk_region_intersect( M_REGIONDATA->m_region, region.GetRegion() ); return true; }
// helper static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region) { if (window) { if (region.IsEmpty()) { gdk_window_shape_combine_mask(window, NULL, 0, 0); } else { gdk_window_shape_combine_region(window, region.GetRegion(), 0, 0); return true; } } return false; }
void wxGCDCImpl::DoSetDeviceClippingRegion( const wxRegion ®ion ) { // region is in device coordinates wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::DoSetDeviceClippingRegion - invalid DC") ); if (region.Empty()) { //DestroyClippingRegion(); return; } wxRegion logRegion( region ); wxCoord x, y, w, h; logRegion.Offset( DeviceToLogicalX(0), DeviceToLogicalY(0) ); logRegion.GetBox( x, y, w, h ); m_graphicContext->Clip( logRegion ); if ( m_clipping ) { m_clipX1 = wxMax( m_clipX1, x ); m_clipY1 = wxMax( m_clipY1, y ); m_clipX2 = wxMin( m_clipX2, (x + w) ); m_clipY2 = wxMin( m_clipY2, (y + h) ); } else { m_clipping = true; m_clipX1 = x; m_clipY1 = y; m_clipX2 = x + w; m_clipY2 = y + h; } }
bool wxRegion::DoSubtract( const wxRegion& region ) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { // subtracting from an invalid region doesn't make sense return false; } AllocExclusive(); gdk_region_subtract( M_REGIONDATA->m_region, region.GetRegion() ); return true; }
bool wxRegionBase::IsEqual(const wxRegion& region) const { if ( m_refData == region.GetRefData() ) { // regions are identical, hence equal return true; } if ( !m_refData || !region.GetRefData() ) { // one, but not both, of the regions is invalid return false; } return DoIsEqual(region); }
bool wxRegion::Intersect( const wxRegion& region ) { #if 0 if (region.IsNull()) return FALSE; if (!m_refData) { m_refData = new wxRegionRefData(); M_REGIONDATA->m_region = XCreateRegion(); // leave here return TRUE; } else { AllocExclusive(); } XIntersectRegion( M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region, M_REGIONDATA->m_region ); #endif return TRUE; }
void wxRegionIterator::CreateRects( const wxRegion& region ) { wxDELETEA(m_rects); m_numRects = 0; GdkRegion *gdkregion = region.GetRegion(); if (!gdkregion) return; GdkRectangle *gdkrects = NULL; gint numRects = 0; gdk_region_get_rectangles( gdkregion, &gdkrects, &numRects ); m_numRects = numRects; if (numRects) { m_rects = new wxRect[m_numRects]; for (size_t i=0; i < m_numRects; ++i) { GdkRectangle &gr = gdkrects[i]; wxRect &wr = m_rects[i]; wr.x = gr.x; wr.y = gr.y; wr.width = gr.width; wr.height = gr.height; } } g_free( gdkrects ); }
bool wxRegion::DoXor( const wxRegion& region ) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { return FALSE; } AllocExclusive(); GdkRegion *reg = gdk_regions_xor( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; return TRUE; }
bool wxRegion::DoSubtract( const wxRegion& region ) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { // subtracting from an invalid region doesn't make sense return FALSE; } AllocExclusive(); GdkRegion *reg = gdk_regions_subtract( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; return TRUE; }
bool wxRegion::DoUnionWithRegion( const wxRegion& region ) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { m_refData = new wxRegionRefData(); M_REGIONDATA->m_region = gdk_region_new(); } else { AllocExclusive(); } gdk_region_union( M_REGIONDATA->m_region, region.GetRegion() ); return true; }
bool wxRegion::DoIntersect( const wxRegion& region ) { wxCHECK_MSG( region.IsOk(), false, wxT("invalid region") ); if (!m_refData) { // intersecting with invalid region doesn't make sense return FALSE; } AllocExclusive(); GdkRegion *reg = gdk_regions_intersect( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; return TRUE; }
bool wxNonOwnedWindow::DoSetRegionShape(const wxRegion& region) { QPixmap pixmap(GetHandle()->size()); QPainter painter(&pixmap); painter.fillRect(pixmap.rect(), Qt::white); painter.setClipRegion(region.GetHandle()); painter.fillRect(pixmap.rect(), Qt::black); GetHandle()->setMask(pixmap.createMaskFromColor(Qt::white)); return true; }
// helper static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region) { if (window) { if (region.IsEmpty()) { gdk_window_shape_combine_mask(window, NULL, 0, 0); } else { wxBitmap bmp = region.ConvertToBitmap(); bmp.SetMask(new wxMask(bmp, *wxBLACK)); GdkBitmap* mask = bmp.GetMask()->GetBitmap(); gdk_window_shape_combine_mask(window, mask, 0, 0); return true; } } return false; }
bool wxRegion::DoUnionWithRegion( const wxRegion& region ) { if (region.IsNull()) return FALSE; if (!m_refData) { m_refData = new wxRegionRefData(); M_REGIONDATA->m_region = gdk_region_new(); } else { AllocExclusive(); } GdkRegion *reg = gdk_regions_union( M_REGIONDATA->m_region, region.GetRegion() ); gdk_region_destroy( M_REGIONDATA->m_region ); M_REGIONDATA->m_region = reg; return TRUE; }
void wxRIRefData::CreateRects( const wxRegion& region ) { if (m_rects) delete [] m_rects; m_rects = 0; m_numRects = 0; if (region.IsEmpty()) return; Region r = (Region) region.GetX11Region(); if (r) { #if wxUSE_NANOX GR_RECT rect; GrGetRegionBox(r, & rect); m_numRects = 1; m_rects = new wxRect[1]; m_rects[0].x = rect.x; m_rects[0].y = rect.y; m_rects[0].width = rect.width; m_rects[0].height = rect.height; #else m_numRects = r->numRects; if (m_numRects) { m_rects = new wxRect[m_numRects]; for (size_t i=0; i < m_numRects; ++i) { _XBox &xr = r->rects[i]; wxRect &wr = m_rects[i]; wr.x = xr.x1; wr.y = xr.y1; wr.width = xr.x2-xr.x1; wr.height = xr.y2-xr.y1; } } #endif } }
void wxQtDCImpl::DoSetDeviceClippingRegion(const wxRegion& region) { if ( region.IsEmpty() ) { DestroyClippingRegion(); } else { QRegion qregion = region.GetHandle(); // Save current origin / scale (logical coordinates) QTransform qtrans = m_qtPainter->worldTransform(); // Reset transofrmation to match device coordinates m_qtPainter->setWorldTransform( QTransform() ); wxLogDebug(wxT("wxQtDCImpl::DoSetDeviceClippingRegion rect %d %d %d %d"), qregion.boundingRect().x(), qregion.boundingRect().y(), qregion.boundingRect().width(), qregion.boundingRect().height()); // Set QPainter clipping (intersection if not the first one) m_qtPainter->setClipRegion( qregion, m_clipping ? Qt::IntersectClip : Qt::ReplaceClip ); // Restore the transformation (translation / scale): m_qtPainter->setWorldTransform( qtrans ); // Set internal state for getters /* Note: Qt states that QPainter::clipRegion() may be slow, so we * keep the region manually, which should be faster */ if ( m_clipping ) m_clippingRegion->Union( region ); else m_clippingRegion->Intersect( region ); wxRect clipRect = m_clippingRegion->GetBox(); m_clipX1 = clipRect.GetLeft(); m_clipX2 = clipRect.GetRight(); m_clipY1 = clipRect.GetTop(); m_clipY2 = clipRect.GetBottom(); m_clipping = true; } }
void wxPseudoDC::DrawToDCClippedRgn(wxDC *dc, const wxRegion& region) { pdcObjectList::Node *pt = m_objectlist.GetFirst(); pdcObject *obj; while (pt) { obj = pt->GetData(); if (!obj->IsBounded() || (region.Contains(obj->GetBounds()) != wxOutRegion)) obj->DrawToDC(dc); pt = pt->GetNext(); } }
//for some f****d up reason getright and get bottom return one less than needed. Fixed in newer wxWidgets :( wxBitmap ConvertRegionToBitmap(const wxRegion& r) { wxRect box = r.GetBox(); wxBitmap bmp(box.GetRight()+1, box.GetBottom()+1); wxMemoryDC dc; dc.SelectObject(bmp); dc.SetBackground(*wxBLACK_BRUSH); dc.Clear(); dc.SetDeviceClippingRegion(*static_cast<const wxRegion *>(&r)); dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); dc.SelectObject(wxNullBitmap); return bmp; }
static bool DoRegionUnion(wxRegion& region, const wxImage& image, unsigned char loR, unsigned char loG, unsigned char loB, int tolerance) { unsigned char hiR, hiG, hiB; hiR = (unsigned char)wxMin(0xFF, loR + tolerance); hiG = (unsigned char)wxMin(0xFF, loG + tolerance); hiB = (unsigned char)wxMin(0xFF, loB + tolerance); // Loop through the image row by row, pixel by pixel, building up // rectangles to add to the region. int width = image.GetWidth(); int height = image.GetHeight(); for (int y=0; y < height; y++) { wxRect rect; rect.y = y; rect.height = 1; for (int x=0; x < width; x++) { // search for a continuous range of non-transparent pixels int x0 = x; while ( x < width) { unsigned char R = image.GetRed(x,y); unsigned char G = image.GetGreen(x,y); unsigned char B = image.GetBlue(x,y); if (( R >= loR && R <= hiR) && ( G >= loG && G <= hiG) && ( B >= loB && B <= hiB)) // It's transparent break; x++; } // Add the run of non-transparent pixels (if any) to the region if (x > x0) { rect.x = x0; rect.width = x - x0; region.Union(rect); } } } return true; }
void wxDFBDCImpl::DoSetDeviceClippingRegion(const wxRegion& region) { // NB: this can be done because wxDFB only supports rectangular regions wxRect rect = region.AsRect(); // our parameter is in physical coordinates while DoSetClippingRegion() // takes logical ones rect.x = XDEV2LOG(rect.x); rect.y = YDEV2LOG(rect.y); rect.width = XDEV2LOG(rect.width); rect.height = YDEV2LOG(rect.height); DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
bool wxRegion::DoSubtract( const wxRegion& region ) { if (region.m_refData == NULL || m_refData == NULL) return false; AllocExclusive(); #ifdef __WXGTK3__ cairo_region_subtract(M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region); #else gdk_region_subtract( M_REGIONDATA->m_region, region.GetRegion() ); #endif return true; }
void VNCCanvas::onUpdateTimer(wxTimerEvent& event) { #ifdef __WXDEBUG__ wxLongLong t0 = wxGetLocalTimeMillis(); size_t nr_rects = 0; size_t nr_bytes = 0; #endif wxClientDC dc(this); // get the update rect list wxRegionIterator upd(updated_area); while(upd) { wxRect update_rect(upd.GetRect()); wxLogDebug(wxT("VNCCanvas %p: drawing updated rect: (%i,%i,%i,%i)"), this, update_rect.x, update_rect.y, update_rect.width, update_rect.height); #ifdef __WXDEBUG__ ++nr_rects; nr_bytes += update_rect.width * update_rect.height; #endif const wxBitmap& region = conn->getFrameBufferRegion(update_rect); if(region.IsOk()) dc.DrawBitmap(region, update_rect.x, update_rect.y); ++upd; } updated_area.Clear(); #ifdef __WXDEBUG__ wxLongLong t1 = wxGetLocalTimeMillis(); wxLogDebug(wxT("VNCCanvas %p: updating %zu rects (%zu bytes) took %lld ms"), this, nr_rects, nr_bytes, (t1-t0).GetValue()); #endif }