From: Václav Slavík Date: Thu, 14 Sep 2006 14:36:12 +0000 (+0000) Subject: implemented wxBitmap::GetSubBitmap() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/4562386dc57b2aa65bbfa26c45561f5be57eba87 implemented wxBitmap::GetSubBitmap() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41212 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dfb/bitmap.h b/include/wx/dfb/bitmap.h index 7b64a06e96..8500bf435f 100644 --- a/include/wx/dfb/bitmap.h +++ b/include/wx/dfb/bitmap.h @@ -63,6 +63,7 @@ class WXDLLIMPEXP_CORE wxBitmap: public wxBitmapBase { public: wxBitmap() {} + wxBitmap(const wxIDirectFBSurfacePtr& surface) { Create(surface); } wxBitmap(int width, int height, int depth = -1); wxBitmap(const char bits[], int width, int height, int depth = 1); wxBitmap(const wxString &filename, wxBitmapType type = wxBITMAP_TYPE_RESOURCE); @@ -76,6 +77,7 @@ public: bool operator==(const wxBitmap& bmp) const; bool operator!=(const wxBitmap& bmp) const { return !(*this == bmp); } + bool Create(const wxIDirectFBSurfacePtr& surface); bool Create(int width, int height, int depth = -1); virtual int GetHeight() const; diff --git a/src/dfb/bitmap.cpp b/src/dfb/bitmap.cpp index 8ba352f12b..25d426dbeb 100644 --- a/src/dfb/bitmap.cpp +++ b/src/dfb/bitmap.cpp @@ -196,6 +196,17 @@ wxBitmap::wxBitmap(int width, int height, int depth) Create(width, height, depth); } +bool wxBitmap::Create(const wxIDirectFBSurfacePtr& surface) +{ + UnRef(); + + wxCHECK_MSG( surface, false, _T("invalid surface") ); + + m_refData = new wxBitmapRefData(); + M_BITMAP->m_surface = surface; + return true; +} + bool wxBitmap::Create(int width, int height, int depth) { UnRef(); @@ -209,14 +220,7 @@ bool wxBitmap::Create(int width, int height, int depth) desc.width = width; desc.height = height; - wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->CreateSurface(&desc)); - if ( !surface ) - return false; - - m_refData = new wxBitmapRefData(); - M_BITMAP->m_surface = surface; - - return true; + return Create(wxIDirectFB::Get()->CreateSurface(&desc)); } #warning "FIXME: move this to common code" @@ -328,6 +332,10 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect& rect) const wxNullBitmap, wxT("invalid bitmap or bitmap region") ); + // NB: DirectFB subsurfaces share the same pixels buffer, so we must + // clone the obtained subsurface + DFBRectangle r = { rect.x, rect.y, rect.width, rect.height }; + return wxBitmap(M_BITMAP->m_surface->GetSubSurface(&r)->Clone()); } #warning "to common code"