From 8f1c695124347ac6005f6df4081ee352962d7849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Mon, 10 Aug 2009 19:21:39 +0000 Subject: [PATCH] Use BWindow TabFrame property to find where to apply transparency. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32232 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/screenshot/ScreenshotWindow.cpp | 144 +++++++++++------------ src/apps/screenshot/ScreenshotWindow.h | 2 +- 2 files changed, 70 insertions(+), 76 deletions(-) diff --git a/src/apps/screenshot/ScreenshotWindow.cpp b/src/apps/screenshot/ScreenshotWindow.cpp index 8e9746062b..0022e295e4 100644 --- a/src/apps/screenshot/ScreenshotWindow.cpp +++ b/src/apps/screenshot/ScreenshotWindow.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -643,7 +645,7 @@ ScreenshotWindow::_TakeScreenshot() fScreenshot = new BBitmap(frame.OffsetToCopy(B_ORIGIN), B_RGBA32, true); BScreen(this).ReadBitmap(fScreenshot, fIncludeMouse, &frame); if (fIncludeBorder) - _MakeTabSpaceTransparent(); + _MakeTabSpaceTransparent(&frame); } else { BScreen(this).GetBitmap(&fScreenshot, fIncludeMouse); } @@ -791,96 +793,88 @@ ScreenshotWindow::_SaveScreenshotSilent() const void -ScreenshotWindow::_MakeTabSpaceTransparent() +ScreenshotWindow::_MakeTabSpaceTransparent(BRect* frame) { + if (!frame) + return; + if (fScreenshot->ColorSpace() != B_RGBA32) return; - - if (fTabHeight == 0) - return; - - // This method is fragile since it relies on the color scheme of the current - // window decorator. The code could be simplified a lot if there was a way - // to ask for, or to easily compute, the tab width of the target window. - - uint8* component = static_cast(fScreenshot->Bits()); - int32 bytesPerRow = fScreenshot->BytesPerRow(); - int32 pixelsPerRow = bytesPerRow / 4; - int32 tabHeight = static_cast(fTabHeight); - int32 tabStart = 0; - int32 tabEnd = 0; - bool foundTabStart = false; - bool foundTabEnd = false; - - // Find the top-left corner of the window tab, by color, and support - // this guess by following a one tab high column of pixels downwards. - for (int32 x = 0; x < pixelsPerRow; x++) { - if (component[0] == 152 && component[1] == 152 && component[2] == 152) { - foundTabStart = true; - - for (int32 y = 0; y < tabHeight; y++) { - component += bytesPerRow; - - if (!(component[0] == 152 && component[1] == 152 - && component[2] == 152)) { - foundTabStart = false; - } - } - component -= bytesPerRow * tabHeight; - - if (foundTabStart) { - tabStart = x; + BRect fullFrame = *frame; + + BMessage message; + BMessage reply; + + app_info appInfo; + if (be_roster->GetActiveAppInfo(&appInfo) != B_OK) + return; + + BMessenger messenger(appInfo.signature, appInfo.team); + if (!messenger.IsValid()) + return; + + bool foundActiveWindow = false; + int32 index = 0; + + while (true) { + message.MakeEmpty(); + message.what = B_GET_PROPERTY; + message.AddSpecifier("Active"); + message.AddSpecifier("Window", index); + + reply.MakeEmpty(); + messenger.SendMessage(&message, &reply); + + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD) + break; + + bool result; + if (reply.FindBool("result", &result) == B_OK) { + foundActiveWindow = result; + + if (foundActiveWindow) break; - } } - component += 4; + index++; } - - component = static_cast(fScreenshot->Bits()); - // Find the top-right corner of the window tab. - for (int32 x = 0; x < pixelsPerRow; x++) { - if (component[0] == 108 && component[1] == 108 && component[2] == 108) { - foundTabEnd = true; - - for (int32 y = 0; y < tabHeight; y++) { - component += bytesPerRow; - - if (!(component[0] == 108 && component[1] == 108 - && component[2] == 108)) { - foundTabEnd = false; - } - } - component -= bytesPerRow * tabHeight; - - if (foundTabEnd) { - tabEnd = x; - break; - } - } - component += 4; - } - - if (!foundTabEnd || !foundTabStart) - return; - - if (tabStart > tabEnd) + if (!foundActiveWindow) return; - BView view(fScreenshot->Bounds(), "bitmapView", B_FOLLOW_ALL_SIDES, 0); + message.MakeEmpty(); + message.what = B_GET_PROPERTY; + message.AddSpecifier("TabFrame"); + message.AddSpecifier("Window", index); + reply.MakeEmpty(); + messenger.SendMessage(&message, &reply); + + BRect tabFrame; + if (reply.FindRect("result", &tabFrame) != B_OK) + return; + + if (!fullFrame.Contains(tabFrame)) + return; + + BRegion tabSpace(fullFrame); + fullFrame.OffsetBy(0, fTabHeight); + tabSpace.Exclude(fullFrame); + tabSpace.Exclude(tabFrame); + fullFrame.OffsetBy(0, -fTabHeight); + tabSpace.OffsetBy(-fullFrame.left, -fullFrame.top); + BScreen screen; + BRect screenFrame = screen.Frame(); + tabSpace.OffsetBy(-screenFrame.left, -screenFrame.top); + + BView view(fScreenshot->Bounds(), "bitmap", B_FOLLOW_ALL_SIDES, 0); fScreenshot->AddChild(&view); if(view.Looper() && view.Looper()->Lock()) { view.SetDrawingMode(B_OP_COPY); view.SetHighColor(B_TRANSPARENT_32_BIT); - if (tabStart > 0) - view.FillRect(BRect(0, 0, tabStart - 1, tabHeight - 1)); + for (int i = 0; i < tabSpace.CountRects(); i++) + view.FillRect(tabSpace.RectAt(i)); - if (tabEnd < pixelsPerRow - 1) { - view.FillRect(BRect(tabEnd + 1, 0, pixelsPerRow - 1, - tabHeight - 1)); - } view.Sync(); view.Looper()->Unlock(); } diff --git a/src/apps/screenshot/ScreenshotWindow.h b/src/apps/screenshot/ScreenshotWindow.h index d4596353a0..fe520dd064 100644 --- a/src/apps/screenshot/ScreenshotWindow.h +++ b/src/apps/screenshot/ScreenshotWindow.h @@ -53,7 +53,7 @@ private: void _TakeScreenshot(); status_t _GetActiveWindowFrame(BRect* frame); - void _MakeTabSpaceTransparent(); + void _MakeTabSpaceTransparent(BRect* frame); status_t _SaveScreenshot(); void _SaveScreenshotSilent() const;